1 // This file is part of OpenMVG, an Open Multiple View Geometry C++ library.
2 
3 // Copyright (c) 2015 Pierre Moulon.
4 
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #ifndef OPENMVG_SFM_SFM_DATA_HPP
10 #define OPENMVG_SFM_SFM_DATA_HPP
11 
12 #include <string>
13 
14 #include "openMVG/cameras/Camera_Intrinsics.hpp"
15 #include "openMVG/geometry/pose3.hpp"
16 #include "openMVG/sfm/sfm_landmark.hpp"
17 #include "openMVG/sfm/sfm_view.hpp"
18 #include "openMVG/sfm/sfm_view_priors.hpp"
19 #include "openMVG/types.hpp"
20 
21 namespace openMVG {
22 namespace sfm {
23 
24 /// Define a collection of IntrinsicParameter (indexed by View::id_intrinsic)
25 using Intrinsics = Hash_Map<IndexT, std::shared_ptr<cameras::IntrinsicBase>>;
26 
27 /// Define a collection of Pose (indexed by View::id_pose)
28 using Poses = Hash_Map<IndexT, geometry::Pose3>;
29 
30 /// Define a collection of View (indexed by View::id_view)
31 using Views = Hash_Map<IndexT, std::shared_ptr<View>>;
32 
33 /// Generic SfM data container
34 /// Store structure and camera properties:
35 struct SfM_Data
36 {
37   /// Considered views
38   Views views;
39   /// Considered poses (indexed by view.id_pose)
40   Poses poses;
41   /// Considered camera intrinsics (indexed by view.id_intrinsic)
42   Intrinsics intrinsics;
43   /// Structure (3D points with their 2D observations)
44   Landmarks structure;
45   /// Controls points (stored as Landmarks (id_feat has no meaning here))
46   Landmarks control_points;
47 
48   /// Root Views path
49   std::string s_root_path;
50 
51   //--
52   // Accessors
53   //--
GetViewsopenMVG::sfm::SfM_Data54   const Views & GetViews() const {return views;}
GetPosesopenMVG::sfm::SfM_Data55   const Poses & GetPoses() const {return poses;}
GetIntrinsicsopenMVG::sfm::SfM_Data56   const Intrinsics & GetIntrinsics() const {return intrinsics;}
GetLandmarksopenMVG::sfm::SfM_Data57   const Landmarks & GetLandmarks() const {return structure;}
GetControl_PointsopenMVG::sfm::SfM_Data58   const Landmarks & GetControl_Points() const {return control_points;}
59 
60   /// Check if the View have defined intrinsic and pose
IsPoseAndIntrinsicDefinedopenMVG::sfm::SfM_Data61   bool IsPoseAndIntrinsicDefined(const View * view) const
62   {
63     if (!view) return false;
64     return (
65       view->id_intrinsic != UndefinedIndexT &&
66       view->id_pose != UndefinedIndexT &&
67       intrinsics.find(view->id_intrinsic) != intrinsics.end() &&
68       poses.find(view->id_pose) != poses.end());
69   }
70 
71   /// Get the pose associated to a view
GetPoseOrDieopenMVG::sfm::SfM_Data72   const geometry::Pose3 GetPoseOrDie(const View * view) const
73   {
74     return poses.at(view->id_pose);
75   }
76 };
77 
78 } // namespace sfm
79 } // namespace openMVG
80 
81 #endif // OPENMVG_SFM_SFM_DATA_HPP
82