Skip to content

Commit cbec642

Browse files
committed
[node] sfmFilter : Add new removeUnselectedPoses option
1 parent a2c32bd commit cbec642

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

meshroom/aliceVision/SfMFilter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class SfMFilter(desc.CommandLineNode):
3030
r'".*\/(.*?)_.*\.\w{3}"',
3131
value=r'.*\/(.*?)\.\w{3}',
3232
),
33+
desc.BoolParam(
34+
name="prunePoses",
35+
label="Remove unselected poses",
36+
description="Set to True to prune poses related to views that are not selected.",
37+
value=False,
38+
),
3339
desc.ChoiceParam(
3440
name="verboseLevel",
3541
label="Verbose Level",

src/software/utils/main_sfmFilter.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)