panoInputDefsPimpl.hpp 10.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm

#pragma once

#include "libvideostitch/config.hpp"
#include "libvideostitch/inputDef.hpp"
#include "libvideostitch/geometryDef.hpp"
#include "libvideostitch/panoDef.hpp"
#include "libvideostitch/stereoRigDef.hpp"
#include "libvideostitch/cameraDef.hpp"
#include "libvideostitch/rigDef.hpp"
#include "libvideostitch/rigCameraDef.hpp"
#include "libvideostitch/mergerMaskDef.hpp"
#include "libvideostitch/curves.hpp"
#include "libvideostitch/parse.hpp"
#include "libvideostitch/overlayInputDef.hpp"

#include <memory>
#include <string>
#include <vector>
#include <memory>
#include <map>

namespace VideoStitch {
namespace Core {

/**
 * RAII for non-null curve pointer.
 */
template <typename CurveT>
class NonNullCurve : public std::unique_ptr<CurveT> {
 public:
  explicit NonNullCurve(CurveT* curve) : std::unique_ptr<CurveT>(curve) {}

 private:
  NonNullCurve();
};

/**
 * Pimpl holder for ControlPointListDefinition.
 */
class ControlPointListDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  friend class ControlPointListDefinition;

  ControlPointList list;
};

/**
 * Pimpl holder for ReaderInputDefinition.
 */
class ReaderInputDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  friend class ReaderInputDefinition;
  friend class PanoDefinition;

  Ptv::Value* readerConfig;
  int64_t width;
  int64_t height;
  /**
   * These parameters are the direct or inverse parameters depending on the reponse type.
   */
  int frameOffset;
  bool isVideoEnabled;
  bool isAudioEnabled;
};

/**
 * Pimpl holder for InputDefinition.
 */
class InputDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  friend class InputDefinition;
  friend class PanoDefinition;

  std::string maskData;
  bool deleteMaskedPixels;
  // Cache for the decompressed pixel data in maskData.
  mutable MaskPixelData maskPixelDataCache;
  mutable bool maskPixelDataCacheValid;
  group_t group;
  int64_t cropLeft;
  int64_t cropRight;
  int64_t cropTop;
  int64_t cropBottom;
  Format format;
  NonNullCurve<Curve> redCB;
  NonNullCurve<Curve> greenCB;
  NonNullCurve<Curve> blueCB;
  NonNullCurve<Curve> exposureValue;
  NonNullCurve<GeometryDefinitionCurve> geometries;
  PhotoResponse photoResponse;
  bool useMeterDistortion;

  /**
   * These parameters are the direct or inverse parameters depending on the reponse type.
   */
  double emorA;
  double emorB;
  double emorC;
  double emorD;
  double emorE;
  double gamma;
  std::unique_ptr<std::array<uint16_t, 256>> valueBasedResponseCurve;
  double vignettingCoeff0;
  double vignettingCoeff1;
  double vignettingCoeff2;
  double vignettingCoeff3;
  double vignettingCenterX;
  double vignettingCenterY;
  double synchroCost;
  int stack;
  Ptv::Value* preprocessors;
  double huginTranslationPlaneYaw;    // Not handled.
  double huginTranslationPlanePitch;  // Not handled.
  LensModelCategory lensModelCategory;
};

/**
 * Pimpl holder for MergerMaskDefinition.
 */
class MergerMaskDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif
  friend class MergerMaskDefinition;
  // Cache for the decompressed pixel data in maskData.
  mutable InputIndexPixelData inputIndexPixelDataCache;
  std::vector<size_t> maskOrders;
  int64_t width;
  int64_t height;
  int inputScaleFactor;
  bool enabled;
  bool interpolationEnabled;
};

/**
 * Pimpl holder for PanoDefinition.
 */
class PanoDefinition::Pimpl {
 public:
  ~Pimpl();

 private:
  /**
   * Create with default values.
   */
  Pimpl();
#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  // Not taking ownership of the pointers
  static Potential<PanoDefinition> mergeCalibrationIntoPano(const PanoDefinition* calibration,
                                                            const PanoDefinition* pano);

  friend class PanoDefinition;
  std::vector<InputDefinition*> inputs;
  MergerMaskDefinition* mergerMask;
  ControlPointListDefinition* controlPointList;
  RigDefinition* rigDefinition;
  InputDefinition* audioInput;
  Ptv::Value* postprocessors;
  int64_t width;
  int64_t height;
  int64_t length;
  int64_t cropLeft;
  int64_t cropRight;
  int64_t cropTop;
  int64_t cropBottom;
  double hFOV;
  NonNullCurve<Curve> exposureValue;
  NonNullCurve<Curve> redCB;
  NonNullCurve<Curve> greenCB;
  NonNullCurve<Curve> blueCB;
  bool wrap;
  PanoProjection projection;
  NonNullCurve<QuaternionCurve> orientationCurve;
  NonNullCurve<QuaternionCurve> stabilizationCurve;
  NonNullCurve<Curve> stabilizationYawCurve;
  NonNullCurve<Curve> stabilizationPitchCurve;
  NonNullCurve<Curve> stabilizationRollCurve;
  double sphereScale;
  double calibrationCost;
  double calibrationInitialHFOV;
  bool calibrationDeshuffled;
  bool precomputedCoodinateBuffer;
  double precomputedCoodinateShrinkFactor;
  bool inputsMapInterpolationEnabled;
  std::vector<OverlayInputDefinition*> overlays;
};

/**
 * Pimpl holder for StereoRigDefinition.
 */
class StereoRigDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();
#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  friend class StereoRigDefinition;
  Orientation orientation;
  Geometry geometry;
  double diameter;
  double ipd;
  std::vector<int> leftInputs;
  std::vector<int> rightInputs;
};

/**
 * Pimpl holder for CameraDefinition.
 */
class CameraDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  friend class CameraDefinition;

  std::string name;
  size_t width;
  size_t height;
  NormalDouble fu;
  NormalDouble fv;
  NormalDouble cu;
  NormalDouble cv;
  NormalDouble distortion[3];
  InputDefinition::Format format;
};

/**
 * Pimpl holder for RigCameraDefinition.
 */
class RigCameraDefinition::Pimpl {
 public:
  Pimpl();
  ~Pimpl();
  Pimpl(const Pimpl& other);

 private:
  NormalDouble yaw;
  NormalDouble pitch;
  NormalDouble roll;
  NormalDouble translation_x;
  NormalDouble translation_y;
  NormalDouble translation_z;
  std::shared_ptr<CameraDefinition> camera;

  friend class RigCameraDefinition;
};

/**
 * Pimpl holder for RigDefinition.
 */
class RigDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif

  std::string name;
  std::vector<RigCameraDefinition> cameras;

  friend class RigDefinition;
};

class OverlayInputDefinition::Pimpl {
 private:
  /**
   * Create with default values.
   */
  Pimpl();
  ~Pimpl();

#ifdef __GNUC__
  Pimpl(const Pimpl& other) = delete;
  bool operator==(const Pimpl& other) const = delete;
  Pimpl& operator=(const Pimpl& other) = delete;
#endif
  bool globalOrientationApplied;
  NonNullCurve<Curve> scaleCurve;
  NonNullCurve<Curve> alphaCurve;
  NonNullCurve<Curve> transXCurve;
  NonNullCurve<Curve> transYCurve;
  NonNullCurve<Curve> transZCurve;
  NonNullCurve<QuaternionCurve> rotationCurve;

  friend class OverlayInputDefinition;
};
}  // namespace Core
}  // namespace VideoStitch

#define GENPOINTERGETTER(class, type, exportName, member) \
  const type& class ::get##exportName() const { return *pimpl->member; }

#define GENREFGETTER(class, type, exportName, member) \
  const type& class ::get##exportName() const { return pimpl->member; }

#define GENGETTER(class, type, exportName, member) \
  type class ::get##exportName() const { return pimpl->member; }

#define GENSETTER(class, type, exportName, member) \
  void class ::set##exportName(type member) { pimpl->member = member; }

#define GENREFSETTER(class, type, exportName, member) \
  void class ::set##exportName(const type& member) { pimpl->member = member; }

#define GENGETREFSETTER(class, type, exportName, member) \
  GENGETTER(class, type, exportName, member)             \
  GENREFSETTER(class, type, exportName, member)

#define GENGETSETTER(class, type, exportName, member) \
  GENGETTER(class, type, exportName, member)          \
  GENSETTER(class, type, exportName, member)

#define GENCURVESETTER(class, type, exportName, member) \
  void class ::replace##exportName(type* newCurve) { pimpl->member.reset(newCurve); }

#define GENCURVEDISPLACER(class, type, exportName, member) \
  type* class ::displace##exportName(type* newCurve) {     \
    type* tmp = pimpl->member.release();                   \
    pimpl->member.reset(newCurve);                         \
    return tmp;                                            \
  }

#define GENCURVERESETER(class, type, exportName, member, defaultValue) \
  void class ::reset##exportName() { pimpl->member.reset(new type(defaultValue)); }

#define GENCURVEFUNCTIONS_WITHOUT_RESETER(class, type, exportName, member) \
  GENPOINTERGETTER(class, type, exportName, member)                        \
  GENCURVESETTER(class, type, exportName, member)                          \
  GENCURVEDISPLACER(class, type, exportName, member)

#define GENCURVEFUNCTIONS(class, type, exportName, member, defaultValue) \
  GENCURVEFUNCTIONS_WITHOUT_RESETER(class, type, exportName, member)     \
  GENCURVERESETER(class, type, exportName, member, defaultValue)