1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_IMAGING_MODEL_H_ // NOLINT 2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_IMAGING_MODEL_H_ // NOLINT 3 4 #include <memory> 5 #include <unordered_map> 6 7 #include "dynamic_depth/dimension.h" 8 #include "dynamic_depth/element.h" 9 #include "dynamic_depth/point.h" 10 #include "xmpmeta/xml/deserializer.h" 11 #include "xmpmeta/xml/serializer.h" 12 13 namespace dynamic_depth { 14 struct ImagingModelParams { 15 // Required. The order of numbers is (x, y), in pixels. 16 Point<double> focal_length; 17 18 // Required. The order of numbers is (width, height), in pixels. 19 Dimension image_size; 20 21 // Optional. Set to (0.5, 0.5) if not present. 22 // The order of numbers is (x, y). 23 Point<double> principal_point; 24 25 // Optional. 26 std::vector<float> distortion; // Distortion parameters. 27 double skew; 28 double pixel_aspect_ratio; 29 ImagingModelParamsImagingModelParams30 ImagingModelParams(const Point<double>& focal_len, 31 const Dimension& image_size) 32 : focal_length(focal_len), 33 image_size(image_size), 34 principal_point(Point<double>(0.5, 0.5)), 35 distortion(std::vector<float>()), 36 skew(0), 37 pixel_aspect_ratio(1) {} 38 39 inline bool operator==(const ImagingModelParams& other) const { 40 return focal_length == other.focal_length && 41 image_size == other.image_size && 42 principal_point == other.principal_point && 43 distortion == other.distortion && skew == other.skew && 44 pixel_aspect_ratio == other.pixel_aspect_ratio; 45 } 46 47 inline bool operator!=(const ImagingModelParams& other) const { 48 return !(*this == other); 49 } 50 }; 51 52 class ImagingModel : public Element { 53 public: 54 void GetNamespaces( 55 std::unordered_map<string, string>* ns_name_href_map) override; 56 57 bool Serialize( 58 ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override; 59 60 // Creates an ImagingModel from the given params. 61 static std::unique_ptr<ImagingModel> FromData( 62 const ImagingModelParams& params); 63 64 // Returns the deserialized equirect model, null if parsing fails. 65 static std::unique_ptr<ImagingModel> FromDeserializer( 66 const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer); 67 68 // Getters. 69 Point<double> GetFocalLength() const; 70 Point<double> GetPrincipalPoint() const; 71 Dimension GetImageSize() const; 72 double GetSkew() const; 73 double GetPixelAspectRatio() const; 74 const std::vector<float>& GetDistortion() const; 75 int GetDistortionCount() const; 76 77 // Disallow copying. 78 ImagingModel(const ImagingModel&) = delete; 79 void operator=(const ImagingModel&) = delete; 80 81 private: 82 ImagingModel(const ImagingModelParams& params); 83 84 ImagingModelParams params_; 85 }; 86 87 } // namespace dynamic_depth 88 89 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_IMAGING_MODEL_H_ // NOLINT 90