2525using namespace aliceVision ;
2626namespace po = boost::program_options;
2727
28- struct poseInput
28+ struct PoseInput
2929{
3030 IndexT frameId;
3131 Eigen::Matrix4d T;
3232};
3333
3434/* *
3535 * I/O for Rotation format choice
36- */
36+ */
3737
3838enum class ERotationFormat
3939{
@@ -62,9 +62,9 @@ inline ERotationFormat ERotationFormat_stringToEnum(const std::string& format)
6262 throw std::out_of_range (" Invalid RotationFormat type Enum: " + format);
6363}
6464
65- inline std::ostream& operator <<(std::ostream& os, ERotationFormat s)
66- {
67- return os << ERotationFormat_enumToString (s);
65+ inline std::ostream& operator <<(std::ostream& os, ERotationFormat s)
66+ {
67+ return os << ERotationFormat_enumToString (s);
6868}
6969
7070inline std::istream& operator >>(std::istream& in, ERotationFormat& s)
@@ -74,21 +74,20 @@ inline std::istream& operator>>(std::istream& in, ERotationFormat& s)
7474 return in;
7575}
7676
77-
7877/* *
7978 * @brief get a pose from a boost json object (assume the file format is ok)
8079 * @param obj the input json object
8180 * @param format the required rotation format to transform to rotation matrix
8281 * @param readPose the output pose information
8382 * @return false if the process failed
84- */
85- bool getPoseFromJson (const boost::json::object& obj, ERotationFormat format, poseInput & readPose)
83+ */
84+ bool getPoseFromJson (const boost::json::object& obj, ERotationFormat format, PoseInput & readPose)
8685{
8786 Eigen::Matrix3d R = Eigen::Matrix3d::Identity ();
8887
8988 if (format == ERotationFormat::EulerZXY)
9089 {
91- // Reading information from lineup
90+ // Reading information from lineup
9291 const double rx = degreeToRadian (boost::json::value_to<double >(obj.at (" rx" )));
9392 const double ry = degreeToRadian (boost::json::value_to<double >(obj.at (" ry" )));
9493 const double rz = degreeToRadian (boost::json::value_to<double >(obj.at (" rz" )));
@@ -97,9 +96,9 @@ bool getPoseFromJson(const boost::json::object& obj, ERotationFormat format, pos
9796 Eigen::AngleAxisd Ry (ry, Eigen::Vector3d::UnitY ());
9897 Eigen::AngleAxisd Rz (rz, Eigen::Vector3d::UnitZ ());
9998
100- R = Ry.toRotationMatrix () * Rx.toRotationMatrix () * Rz.toRotationMatrix ();
99+ R = Ry.toRotationMatrix () * Rx.toRotationMatrix () * Rz.toRotationMatrix ();
101100 }
102- else
101+ else
103102 {
104103 return false ;
105104 }
@@ -114,19 +113,19 @@ bool getPoseFromJson(const boost::json::object& obj, ERotationFormat format, pos
114113 readPose.T = Eigen::Matrix4d::Identity ();
115114 readPose.T .block <3 , 3 >(0 , 0 ) = R;
116115 readPose.T .block <3 , 1 >(0 , 3 ) = t;
117-
116+
118117 return true ;
119118}
120119
121120/* *
122- * @brief get a set of poses from a json file (assume the file format is ok)
123- * Json file contains an array of objects. Each object describes a frameId, a rotation and a translation.
124- * @param obj the input json filename
121+ * @brief Get a set of poses from a JSON file (assumes the file format is ok).
122+ * The JSON file contains an array of objects. Each object describes a frameId, a rotation and a translation.
123+ * @param posesFilename the input JSON filename
125124 * @param format the required rotation format to transform to rotation matrix
126125 * @param readPose the output poses vector
127- * @return false if the process failed
128- */
129- bool getPosesFromJson (const std::string & posesFilename, ERotationFormat format, std::vector<poseInput> & readPoses)
126+ * @return false if the process failed, true otherwise
127+ */
128+ bool getPosesFromJson (const std::string& posesFilename, ERotationFormat format, std::vector<PoseInput> & readPoses)
130129{
131130 std::ifstream inputfile (posesFilename);
132131 if (!inputfile.is_open ())
@@ -149,7 +148,7 @@ bool getPosesFromJson(const std::string & posesFilename, ERotationFormat format,
149148 {
150149 const boost::json::object& obj = item.as_object ();
151150
152- poseInput input;
151+ PoseInput input;
153152 if (getPoseFromJson (obj, format, input))
154153 {
155154 readPoses.push_back (input);
@@ -166,48 +165,51 @@ int aliceVision_main(int argc, char** argv)
166165 std::string sfmDataOutputFilename;
167166 std::string posesFilename;
168167 ERotationFormat format;
169-
170168
169+ // clang-format off
171170 po::options_description requiredParams (" Required parameters" );
172171 requiredParams.add_options ()
173- (" input,i" , po::value<std::string>(&sfmDataFilename)->required (), " SfMData file." )
174- (" output,o" , po::value<std::string>(&sfmDataOutputFilename)->required (), " SfMData output file." )
175- (" posesFilename,p" , po::value<std::string>(&posesFilename)->required (), " Poses file." )
176- (" rotationFormat,r" , po::value<ERotationFormat>(&format)->required (), " Poses file." );
177-
172+ (" input,i" , po::value<std::string>(&sfmDataFilename)->required (),
173+ " Input SfMData file." )
174+ (" output,o" , po::value<std::string>(&sfmDataOutputFilename)->required (),
175+ " SfMData output file with the injected poses." )
176+ (" posesFilename,p" , po::value<std::string>(&posesFilename)->required (),
177+ " JSON file containing the poses to inject." )
178+ (" rotationFormat,r" , po::value<ERotationFormat>(&format)->required (),
179+ " Rotation format for the input poses: EulerZXY." );
180+ // clang-format on
178181
179182 CmdLine cmdline (" AliceVision SfM Pose injecting" );
180183
181184 cmdline.add (requiredParams);
182- if (!cmdline.execute (argc, argv))
185+ if (!cmdline.execute (argc, argv))
183186 {
184187 return EXIT_FAILURE;
185188 }
186189
187- // set maxThreads
190+ // Set maxThreads
188191 HardwareContext hwc = cmdline.getHardwareContext ();
189192 omp_set_num_threads (hwc.getMaxThreads ());
190-
191- // load input SfMData scene
193+
194+ // Load input SfMData scene
192195 sfmData::SfMData sfmData;
193- if (!sfmDataIO::load (sfmData, sfmDataFilename, sfmDataIO::ESfMData::ALL))
196+ if (!sfmDataIO::load (sfmData, sfmDataFilename, sfmDataIO::ESfMData::ALL))
194197 {
195198 ALICEVISION_LOG_ERROR (" The input SfMData file '" + sfmDataFilename + " ' cannot be read." );
196199 return EXIT_FAILURE;
197200 }
198201
199- std::vector<poseInput > readPoses;
202+ std::vector<PoseInput > readPoses;
200203 if (!getPosesFromJson (posesFilename, format, readPoses))
201204 {
202205 ALICEVISION_LOG_ERROR (" Cannot read the poses" );
203206 return EXIT_FAILURE;
204207 }
205208
206-
207- // Set the pose for all views with frame Ids found in the json file
208- for (const auto & [id, pview] : sfmData.getViews ())
209+ // Set the pose for all the views with frame IDs found in the JSON file
210+ for (const auto & [id, pview] : sfmData.getViews ())
209211 {
210- for (const auto & rpose : readPoses)
212+ for (const auto & rpose : readPoses)
211213 {
212214 if (pview->getFrameId () == rpose.frameId )
213215 {
0 commit comments