1 #ifndef DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_CAMERA_H_ // NOLINT 2 #define DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_CAMERA_H_ // NOLINT 3 4 #include <memory> 5 #include <string> 6 #include <unordered_map> 7 #include <utility> 8 9 #include "dynamic_depth/app_info.h" 10 #include "dynamic_depth/depth_map.h" 11 #include "dynamic_depth/element.h" 12 #include "dynamic_depth/image.h" 13 #include "dynamic_depth/imaging_model.h" 14 #include "dynamic_depth/light_estimate.h" 15 #include "dynamic_depth/point_cloud.h" 16 #include "dynamic_depth/pose.h" 17 #include "dynamic_depth/vendor_info.h" 18 #include "xmpmeta/xml/deserializer.h" 19 #include "xmpmeta/xml/serializer.h" 20 21 namespace dynamic_depth { 22 23 // The camera trait is serialized only if it is one of PHYSICAL or LOGICAL. 24 // NONE signifies an undefined trait. 25 enum CameraTrait { NONE = 0, PHYSICAL = 1, LOGICAL = 2 }; 26 27 struct CameraParams { 28 // The Image must be present. 29 std::unique_ptr<Image> image; 30 31 // Optional elements. 32 std::unique_ptr<DepthMap> depth_map; 33 std::unique_ptr<LightEstimate> light_estimate; 34 std::unique_ptr<Pose> pose; 35 std::unique_ptr<ImagingModel> imaging_model; 36 std::unique_ptr<PointCloud> point_cloud; 37 std::unique_ptr<VendorInfo> vendor_info; 38 std::unique_ptr<AppInfo> app_info; 39 CameraTrait trait; 40 CameraParamsCameraParams41 explicit CameraParams(std::unique_ptr<Image> img) 42 : depth_map(nullptr), 43 light_estimate(nullptr), 44 pose(nullptr), 45 imaging_model(nullptr), 46 point_cloud(nullptr), 47 vendor_info(nullptr), 48 app_info(nullptr), 49 trait(CameraTrait::PHYSICAL) { 50 image = std::move(img); 51 } 52 53 inline bool operator==(const CameraParams& other) const { 54 return image.get() == other.image.get() && 55 light_estimate.get() == other.light_estimate.get() && 56 pose.get() == other.pose.get() && 57 depth_map.get() == other.depth_map.get() && 58 imaging_model.get() == other.imaging_model.get() && 59 point_cloud.get() == other.point_cloud.get() && 60 vendor_info.get() == other.vendor_info.get() && 61 app_info.get() == other.app_info.get(); 62 } 63 64 inline bool operator!=(const CameraParams& other) const { 65 return !(*this == other); 66 } 67 }; 68 69 // Implements the Camera element from the Dynamic Depth specification, with 70 // serialization and deserialization. 71 class Camera : public Element { 72 public: 73 void GetNamespaces( 74 std::unordered_map<string, string>* ns_name_href_map) override; 75 76 bool Serialize( 77 ::dynamic_depth::xmpmeta::xml::Serializer* serializer) const override; 78 79 // Creates a Camera from the given objects in params. 80 // Aside from the Image element, all other elements are optional and can be 81 // null. 82 static std::unique_ptr<Camera> FromData(std::unique_ptr<CameraParams> params); 83 84 // Same as above, but allows the Image element to be null. This should be used 85 // only for Camera 0, since the lack of an Image element indicates that it 86 // refers to the JPEG container image. An Item element is generated for the 87 // container image, and populated into items. 88 // Currently supports only image/jpeg. 89 // The items parameter may be null if params->image is not null. 90 // TODO(miraleung): Add other mime types as args when needed. 91 static std::unique_ptr<Camera> FromDataForCamera0( 92 std::unique_ptr<CameraParams> params, 93 std::vector<std::unique_ptr<Item>>* items); 94 95 // Returns the deserialized Camera object, null if parsing fails. 96 // Not sensitive to case when parsing a camera's trait. 97 static std::unique_ptr<Camera> FromDeserializer( 98 const ::dynamic_depth::xmpmeta::xml::Deserializer& parent_deserializer); 99 100 // Getters. Except for Imaeg (which should never be null), these will return 101 // null if the corresponding fields are not present. 102 // which should never be null. 103 const Image* GetImage() const; 104 const LightEstimate* GetLightEstimate() const; 105 const Pose* GetPose() const; 106 const DepthMap* GetDepthMap() const; 107 const ImagingModel* GetImagingModel() const; 108 const PointCloud* GetPointCloud() const; 109 const VendorInfo* GetVendorInfo() const; 110 const AppInfo* GetAppInfo() const; 111 CameraTrait GetTrait() const; 112 113 // Disallow copying. 114 Camera(const Camera&) = delete; 115 void operator=(const Camera&) = delete; 116 117 private: 118 explicit Camera(std::unique_ptr<CameraParams> params); 119 120 std::unique_ptr<CameraParams> params_; 121 }; 122 123 } // namespace dynamic_depth 124 125 #endif // DYNAMIC_DEPTH_INCLUDES_DYNAMIC_DEPTH_CAMERA_H_ // NOLINT 126