@@ -37,6 +37,7 @@ int aliceVision_main(int argc, char** argv)
3737 std::string outputSfMFilenameSelected;
3838 std::string outputSfMFilenameUnselected;
3939 std::string fileMatchingPattern;
40+ bool prunePoses;
4041
4142 // clang-format off
4243 po::options_description requiredParams (" Required parameters" );
@@ -45,6 +46,7 @@ int aliceVision_main(int argc, char** argv)
4546 " Path to the input SfMData file.\n " )
4647 (" fileMatchingPattern,m" , po::value<std::string>(&fileMatchingPattern)->required (),
4748 " Matching pattern for the from_filepath method.\n " )
49+ (" prunePoses,p" , po::value<bool >(&prunePoses)->required (), " Prune unselected poses.\n " )
4850 (" outputSfMData_selected,o" , po::value<std::string>(&outputSfMFilenameSelected)->required (),
4951 " Path to the output SfMData file.\n " )
5052 (" outputSfMData_unselected,o" , po::value<std::string>(&outputSfMFilenameUnselected)->required (),
@@ -69,6 +71,7 @@ int aliceVision_main(int argc, char** argv)
6971
7072 std::regex re (fileMatchingPattern);
7173 std::vector<IndexT> selectedViews;
74+ std::vector<IndexT> selectedPoses;
7275
7376 for (auto & viewIt : sfmData.getViews ())
7477 {
@@ -77,9 +80,13 @@ int aliceVision_main(int argc, char** argv)
7780 if (std::regex_search (imagePath, matches, re))
7881 {
7982 selectedViews.push_back (viewIt.first );
83+ if (prunePoses)
84+ selectedPoses.push_back (viewIt.second ->getPoseId ());
8085 }
8186 }
8287
88+ // Split views into the selected and unselected SfmData
89+
8390 sfmData::SfMData outputSfMData_selected = sfmData;
8491 sfmData::SfMData outputSfMData_unselected = sfmData;
8592 std::set<IndexT> viewIdsToRemove;
@@ -109,6 +116,38 @@ int aliceVision_main(int argc, char** argv)
109116 outputSfMData_unselected.getViews ().erase (r);
110117 }
111118
119+ // Split poses into the selected and unselected SfmData
120+
121+ if (prunePoses)
122+ {
123+ std::set<IndexT> poseIdsToRemove;
124+ std::set<IndexT> poseIdsToKeep;
125+
126+ for (auto & viewIt : outputSfMData_selected.getPoses ())
127+ {
128+ const IndexT viewId = viewIt.first ;
129+ auto it = std::find (selectedPoses.begin (), selectedPoses.end (), viewId);
130+ if (it == selectedPoses.end ())
131+ {
132+ poseIdsToRemove.insert (viewId);
133+ }
134+ else
135+ {
136+ poseIdsToKeep.insert (viewId);
137+ }
138+ }
139+
140+ for (auto r : poseIdsToRemove)
141+ {
142+ outputSfMData_selected.getPoses ().erase (r);
143+ }
144+
145+ for (auto r : poseIdsToKeep)
146+ {
147+ outputSfMData_unselected.getPoses ().erase (r);
148+ }
149+ }
150+
112151
113152 ALICEVISION_LOG_INFO (" Save into '" << outputSfMFilenameSelected << " '" );
114153 // Export the SfMData scene in the expected format
0 commit comments