-
-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sfm] New sfmFilter software: split sfm based on filenames regex #1769
Open
jmelou
wants to merge
1
commit into
develop
Choose a base branch
from
dev/sfmFilter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// This file is part of the AliceVision project. | ||
// Copyright (c) 2024 AliceVision contributors. | ||
// This Source Code Form is subject to the terms of the Mozilla Public License, | ||
// v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include <aliceVision/sfmData/SfMData.hpp> | ||
#include <aliceVision/sfmDataIO/sfmDataIO.hpp> | ||
#include <aliceVision/sfm/utils/alignment.hpp> | ||
|
||
#include <aliceVision/cmdline/cmdline.hpp> | ||
#include <aliceVision/system/main.hpp> | ||
#include <aliceVision/system/Logger.hpp> | ||
#include <aliceVision/stl/regex.hpp> | ||
|
||
#include <boost/program_options.hpp> | ||
|
||
#include <string> | ||
#include <sstream> | ||
|
||
// These constants define the current software version. | ||
// They must be updated when the command line is changed. | ||
#define ALICEVISION_SOFTWARE_VERSION_MAJOR 1 | ||
#define ALICEVISION_SOFTWARE_VERSION_MINOR 0 | ||
|
||
using namespace aliceVision; | ||
using namespace aliceVision::sfm; | ||
|
||
namespace po = boost::program_options; | ||
|
||
int aliceVision_main(int argc, char** argv) | ||
{ | ||
system::Timer timer; | ||
|
||
// command-line parameters | ||
std::string sfmDataFilename; | ||
std::string outputSfMFilenameSelected; | ||
std::string outputSfMFilenameUnselected; | ||
std::string fileMatchingPattern; | ||
|
||
// clang-format off | ||
po::options_description requiredParams("Required parameters"); | ||
requiredParams.add_options() | ||
("inputFile,i", po::value<std::string>(&sfmDataFilename)->required(), | ||
"Path to the input SfMData file.\n") | ||
("fileMatchingPattern,m", po::value<std::string>(&fileMatchingPattern)->required(), | ||
"Matching pattern for the from_filepath method.\n") | ||
("outputSfMData_selected,o", po::value<std::string>(&outputSfMFilenameSelected)->required(), | ||
"Path to the output SfMData file.\n") | ||
("outputSfMData_unselected,o", po::value<std::string>(&outputSfMFilenameUnselected)->required(), | ||
"Path to the output SfMData file.\n"); | ||
|
||
CmdLine cmdline("AliceVision sfmFilter"); | ||
cmdline.add(requiredParams); | ||
//cmdline.add(optionalParams); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused line, to be removed. |
||
|
||
if (!cmdline.execute(argc, argv)) | ||
{ | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// Load input scene | ||
sfmData::SfMData sfmData; | ||
if (!sfmDataIO::load(sfmData, sfmDataFilename, sfmDataIO::ESfMData::ALL)) | ||
{ | ||
ALICEVISION_LOG_ERROR("The input SfMData file '" << sfmDataFilename << "' cannot be read"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
std::regex re(fileMatchingPattern); | ||
std::vector<IndexT> selectedViews; | ||
|
||
for (auto& viewIt : sfmData.getViews()) | ||
{ | ||
const std::string& imagePath = viewIt.second->getImage().getImagePath(); | ||
std::smatch matches; | ||
if (std::regex_search(imagePath, matches, re)) | ||
{ | ||
selectedViews.push_back(viewIt.first); | ||
} | ||
} | ||
|
||
sfmData::SfMData outputSfMData_selected = sfmData; | ||
sfmData::SfMData outputSfMData_unselected = sfmData; | ||
std::set<IndexT> viewIdsToRemove; | ||
std::set<IndexT> viewIdsToKeep; | ||
|
||
for (auto& viewIt : outputSfMData_selected.getViews()) | ||
{ | ||
const IndexT viewId = viewIt.first; | ||
auto it = std::find(selectedViews.begin(), selectedViews.end(), viewId); | ||
if (it == selectedViews.end()) | ||
{ | ||
viewIdsToRemove.insert(viewId); | ||
} | ||
else | ||
{ | ||
viewIdsToKeep.insert(viewId); | ||
} | ||
} | ||
|
||
for (auto r : viewIdsToRemove) | ||
{ | ||
outputSfMData_selected.getViews().erase(r); | ||
} | ||
|
||
for (auto r : viewIdsToKeep) | ||
{ | ||
outputSfMData_unselected.getViews().erase(r); | ||
} | ||
|
||
|
||
ALICEVISION_LOG_INFO("Save into '" << outputSfMFilenameSelected << "'"); | ||
// Export the SfMData scene in the expected format | ||
if (!sfmDataIO::save(outputSfMData_selected, outputSfMFilenameSelected, sfmDataIO::ESfMData::ALL)) | ||
{ | ||
ALICEVISION_LOG_ERROR("An error occurred while trying to save '" << outputSfMFilenameSelected << "'"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ALICEVISION_LOG_INFO("Save into '" << outputSfMFilenameUnselected << "'"); | ||
// Export the SfMData scene in the expected format | ||
if (!sfmDataIO::save(outputSfMData_unselected, outputSfMFilenameUnselected, sfmDataIO::ESfMData::ALL)) | ||
{ | ||
ALICEVISION_LOG_ERROR("An error occurred while trying to save '" << outputSfMFilenameUnselected << "'"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ALICEVISION_LOG_INFO("Task done in (s): " + std::to_string(timer.elapsed())); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format is disabled at the beginning of the parameters listing but it is never re-enabled. It should be re-enabled as soon as the parameters have been described.