@@ -160,56 +160,68 @@ bool eraseUnstablePoses(sfmData::SfMData& sfmData, const IndexT minPointsPerPose
160160 // Count the observation poses occurrence
161161 std::map<IndexT, IndexT> posesCount;
162162
163- // Init with 0 count, undefined rig id (in order to be able to remove non referenced elements)
164- for (sfmData::Poses::const_iterator itPoses = sfmData.getPoses ().begin (); itPoses != sfmData.getPoses ().end (); ++itPoses)
165- posesCount[itPoses->first ] = 0 ;
163+ // Loop over all poses
164+ for (auto & [poseId, pose] : sfmData.getPoses ())
165+ {
166+ if (!pose.isRemovable ())
167+ {
168+ continue ;
169+ }
170+
171+ posesCount[poseId] = 0 ;
172+ }
166173
167174 // Count occurrence of the poses in the Landmark observations
168- for (sfmData::Landmarks::const_iterator itLandmarks = landmarks. begin (); itLandmarks != landmarks. end (); ++itLandmarks )
175+ for (const auto & [idLandmark, landmark] : landmarks)
169176 {
170- const sfmData::Observations& observations = itLandmarks->second .getObservations ();
171- for (sfmData::Observations::const_iterator itObs = observations.begin (); itObs != observations.end (); ++itObs)
172- {
173- const IndexT viewId = itObs->first ;
174- const sfmData::View* v = sfmData.getViews ().at (viewId).get ();
175- const auto poseInfoIt = posesCount.find (v->getPoseId ());
177+ const sfmData::Observations& observations = landmark.getObservations ();
176178
179+ for (const auto & [viewId, obs] : observations)
180+ {
181+ const sfmData::View & v = sfmData.getView (viewId);
182+
183+ const auto poseInfoIt = posesCount.find (v.getPoseId ());
177184 if (poseInfoIt != posesCount.end ())
185+ {
178186 poseInfoIt->second ++;
179- else // all pose should be defined in map_PoseId_Count
180- throw std::runtime_error (std::string (" eraseUnstablePoses: found unknown pose id referenced by a view.\n\t - view id: " ) +
181- std::to_string (v->getViewId ()) + std::string (" \n\t - pose id: " ) + std::to_string (v->getPoseId ()));
187+ }
182188 }
183189 }
184190
185191 // If usage count is smaller than the threshold, remove the Pose
186- for (std::map<IndexT, IndexT>::const_iterator it = posesCount. begin (); it != posesCount. end (); ++it )
192+ for (const auto & [idPose, count] : posesCount)
187193 {
188- if (it-> second < minPointsPerPose)
194+ if (count < minPointsPerPose)
189195 {
190- sfmData.erasePose (it-> first , true ); // no throw
196+ sfmData.erasePose (idPose , true ); // no throw
191197
192- for (auto & viewPair : sfmData.getViews ())
198+ for (auto & [viewId, view] : sfmData.getViews ())
193199 {
194- if (viewPair. second ->getPoseId () == it-> first )
200+ if (view ->getPoseId () == idPose )
195201 {
196- if (viewPair. second ->isPartOfRig ())
202+ if (view ->isPartOfRig ())
197203 {
198- // the pose is now independent
199- viewPair. second ->setPoseId (viewPair. first );
200- viewPair. second ->setIndependantPose (true );
204+ // the pose is now independant
205+ view ->setPoseId (idPose );
206+ view ->setIndependantPose (true );
201207 }
202208
203209 // add view id to the removedViewsId set
204210 if (outRemovedViewsId != NULL )
205- outRemovedViewsId->insert (viewPair.first );
211+ {
212+ outRemovedViewsId->insert (viewId);
213+ }
206214 }
207215 }
208216 ++removedElements;
209217 }
210218 }
219+
211220 if (removedElements)
221+ {
212222 ALICEVISION_LOG_DEBUG (" eraseUnstablePoses: " << removedElements);
223+ }
224+
213225 return removedElements > 0 ;
214226}
215227
0 commit comments