geometryDef.hpp 9.36 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 410 411 412 413 414 415 416 417 418 419 420 421
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm

#pragma once

#include "config.hpp"
#include "status.hpp"
#include "object.hpp"

namespace VideoStitch {
namespace Core {

class InputDefinition;

/**
 * Input Geometry definition
 */
class VS_EXPORT GeometryDefinition {
 public:
  /**
   * Build with the mandatory fields. The others take default values.
   */
  GeometryDefinition();

  virtual ~GeometryDefinition();

  /**
   * @brief serialize
   * @param value A ptv value object to fill
   */
  void serialize(Ptv::Value& value) const;

  /**
   * Comparison operator.
   */
  bool operator==(const GeometryDefinition& other) const;
  bool hasSameExtrinsics(const GeometryDefinition& other) const;

  /**
   * Parse from the given ptv. Values not specified are not overridden.
   * @param diff Input diff.
   * @param enforceMandatoryFields If false, ignore missing mandatory values.
   */
  Status applyDiff(const Ptv::Value& diff, bool enforceMandatoryFields);

  /**
   * @brief getDistortA
   * @return first radial distortion parameter
   */
  double getDistortA() const;

  /**
   * @brief setDistortA
   * @param distortA first radial distortion parameter
   */
  void setDistortA(const double distortA);

  /**
   * @brief getDistortB
   * @return second radial distortion parameter
   */
  double getDistortB() const;

  /**
   * @brief setDistortB
   * @param distortB second radial distortion parameter
   */
  void setDistortB(const double distortB);

  /**
   * @brief getDistortC
   * @return third radial distortion parameter
   */
  double getDistortC() const;

  /**
   * @brief setDistortC
   * @param distortC third radial distortion parameter
   */
  void setDistortC(const double distortC);

  /**
   * @brief getDistortP1
   * @return first tangential distortion parameter
   */
  double getDistortP1() const;

  /**
   * @brief setDistortP1
   * @param distortP1 first tangential distortion parameter
   */
  void setDistortP1(const double distortP1);

  /**
   * @brief getDistortP2
   * @return second tangential distortion parameter
   */
  double getDistortP2() const;

  /**
   * @brief setDistortP2
   * @param distortP2 second tangential distortion parameter
   */
  void setDistortP2(const double distortP2);

  /**
   * @brief getDistortS1
   * @return first thin-prism distortion parameter
   */
  double getDistortS1() const;

  /**
   * @brief setDistortS1
   * @param distortS1 first thin-prism distortion parameter
   */
  void setDistortS1(const double distortS1);

  /**
   * @brief getDistortS2
   * @return second thin-prism distortion parameter
   */
  double getDistortS2() const;

  /**
   * @brief setDistortS2
   * @param distortS2 second thin-prism distortion parameter
   */
  void setDistortS2(const double distortS2);

  /**
   * @brief getDistortS3
   * @return third thin-prism distortion parameter
   */
  double getDistortS3() const;

  /**
   * @brief setDistortS3
   * @param distortS3 third thin-prism distortion parameter
   */
  void setDistortS3(const double distortS3);

  /**
   * @brief getDistortS4
   * @return fourth thin-prism distortion parameter
   */
  double getDistortS4() const;

  /**
   * @brief setDistortS4
   * @param distortS4 fourth thin-prism distortion parameter
   */
  void setDistortS4(const double distortS4);

  /**
   * @brief getDistortTau1
   * @return first Scheimpflug distortion angle parameter in radians
   */
  double getDistortTau1() const;

  /**
   * @brief setDistortTau1
   * @param distortTau1 first Scheimpflug distortion angle parameter in radians
   */
  void setDistortTau1(const double distortTau1);

  /**
   * @brief getDistortTau2
   * @return second Scheimpflug distortion angle parameter in radians
   */
  double getDistortTau2() const;

  /**
   * @brief setDistortTau2
   * @param distortTau2 second Scheimpflug distortion angle parameter in radians
   */
  void setDistortTau2(const double distortTau2);

  /**
   * @brief hasNonRadialDistortion
   * @return true if any radial or non-radial distortion is not zero
   */
  bool hasDistortion() const;

  /**
   * @brief hasRadialDistortion
   * @return true if any radial distortion is not zero
   */
  bool hasRadialDistortion() const;

  /**
   * @brief hasNonRadialDistortion
   * @return true if any non-radial distortion is not zero
   */
  bool hasNonRadialDistortion() const;

  /**
   * @brief getHorizontalFocal
   * @return the horizontal focal in pixels
   */
  double getHorizontalFocal() const;

  /**
   * @brief setHorizontalFocal
   * @param focal horizontal focal in pixels to set
   */
  void setHorizontalFocal(const double focal);

  /**
   * @brief getEstimatedHorizontalFov
   * @param input input definition (used to get the lens type and image width)
   * @return the fov value estimated
   */
  double getEstimatedHorizontalFov(const InputDefinition& input) const;

  /**
   * @brief setEstimatedHorizontalFov set the focal according to the given fov
   * @param input input definition (used to get the lens type and image width)
   * @param fov new fov to set
   */
  void setEstimatedHorizontalFov(const InputDefinition& input, double fov);

  /**
   * @brief getVerticalFocal
   * @return the vertical focal in pixels
   */
  double getVerticalFocal() const;

  /**
   * @brief setVerticalFocal
   * @param focal vertical focal in pixels to set
   */
  void setVerticalFocal(const double focal);

  /**
   * @brief hasVerticalFov
   * @return true if vertical focal in pixels is defined
   */
  bool hasVerticalFocal() const;

  /**
   * @brief getCenterX
   * @return the center x coordinates
   */
  double getCenterX() const;

  /**
   * @brief setCenterX
   * @param centerx The x coordinate to update
   */
  void setCenterX(const double centerx);

  /**
   * @brief getCenterX
   * @return the center x coordinates
   */
  double getCenterY() const;

  /**
   * @brief setCenterY
   * @param centery The y coordinate to update
   */
  void setCenterY(const double centery);

  /**
   * @brief getYaw
   * @return The yaw rotation parameter in degrees
   */
  double getYaw() const;

  /**
   * @brief setYaw
   * @param yaw The yaw rotation parameter in degrees
   */
  void setYaw(const double yaw);

  /**
   * @brief getPitch
   * @return return Pitch rotation parameter in degrees
   */
  double getPitch() const;

  /**
   * @brief setPitch
   * @param pitch Pitch rotation parameter in degrees
   */
  void setPitch(const double pitch);

  /**
   * @brief getRoll
   * @return return Roll rotation parameter in degrees
   */
  double getRoll() const;

  /**
   * @brief setRoll
   * @param roll The Roll rotation parameter in degrees
   */
  void setRoll(const double roll);

  /**
   * @brief hasTranslation
   * @return true if translation is defined
   */
  bool hasTranslation() const;

  /**
   * @brief getTranslationX
   * @return return X component of the camera translation
   */
  double getTranslationX() const;

  /**
   * @brief setRoll
   * @param X X component of the camera translation
   */
  void setTranslationX(const double X);

  /**
   * @brief getTranslationX
   * @return return Y component of the camera translation
   */
  double getTranslationY() const;

  /**
   * @brief setRoll
   * @param Y Y component of the camera translation
   */
  void setTranslationY(const double Y);

  /**
   * @brief getTranslationZ
   * @return return Z component of the camera translation
   */
  double getTranslationZ() const;

  /**
   * @brief setRoll
   * @param Z Z component of the camera translation
   */
  void setTranslationZ(const double Z);

  /**
   * Gets a geometric value using its id
   * Valid ids are 'y' (yaw), 'p' (pitch), 'r' (roll), 'f' (hfov), 'a' (lensDistA), 'b' (lensDistB), 'c' (lensDistC),
   * 'd' (distCenterX), 'e' (distCenterY) Returns 0.0 if the id is not valid
   * @param id of the parameter to retrieve
   */
  double getGeoParamFromId(const char id) const;

  /**
   * Sets a geometric value using its id
   * Valid ids are 'y' (yaw), 'p' (pitch), 'r' (roll), 'f' (hfov), 'a' (lensDistA), 'b' (lensDistB), 'c' (lensDistC),
   * 'd' (distCenterX), 'e' (distCenterY) No operation is performed if id is not valid
   * @param id
   * @param val A value to set for the given parameter
   */
  void setGeoParamFromId(const char id, const double val);

  /**
   * Applies a global orientation to Yaw/Pitch/Roll angles
   * @param orientation quaternion of the global orientation
   */
  void applyGlobalOrientation(const Quaternion<double>& orientation);

  /**
   * Reset to 0 all parameters except the focal parameters
   */
  void resetAllButFocal();

  /**
   * Reset to 0 all extrinsic parameters
   */
  void resetExtrinsics();

  /**
   * Resets all distortion parameters and the center to 0
   */
  void resetDistortion();

  /**
   * Convert loaded fov if it exists to focal length in pixels
   * @param input definition (to know the lens type)
   */
  void convertLoadedFovToFocal(const InputDefinition& input);

 private:
  double horizontalFocal;

  bool doesHaveVerticalFocal;
  double verticalFocal;

  double center_x;
  double center_y;

  double distort_a;
  double distort_b;
  double distort_c;

  double distort_p1;
  double distort_p2;
  double distort_s1;
  double distort_s2;
  double distort_s3;
  double distort_s4;
  double distort_tau1;
  double distort_tau2;

  double yaw;
  double pitch;
  double roll;

  bool doesHaveTranslation;
  double translation_x;
  double translation_y;
  double translation_z;

  bool hasFovLoaded;
};

}  // namespace Core
}  // namespace VideoStitch