-
-
Notifications
You must be signed in to change notification settings - Fork 830
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
Add mesh utilities softwares #969
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fbaa73f
[software] Add `mergeMeshes` software
gregoire-dl fbac460
[software] Add `convertMesh` software
gregoire-dl d7c997e
[software] MergeMeshes: Fix missing include / useless block
gregoire-dl a83cb82
[software] MergeMeshes: Add description
gregoire-dl 882cef8
[software] ConvertMesh: Add description
gregoire-dl 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// This file is part of the AliceVision project. | ||
// Copyright (c) 2021 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/system/Logger.hpp> | ||
#include <aliceVision/system/cmdline.hpp> | ||
#include <aliceVision/system/main.hpp> | ||
#include <aliceVision/system/Timer.hpp> | ||
|
||
#include <boost/program_options.hpp> | ||
#include <boost/filesystem.hpp> | ||
|
||
#include <geogram/mesh/mesh.h> | ||
#include <geogram/mesh/mesh_io.h> | ||
|
||
#include <geogram/basic/command_line.h> | ||
#include <geogram/basic/command_line_args.h> | ||
|
||
#include <iostream> | ||
#include <fstream> | ||
#include <ostream> | ||
#include <string> | ||
|
||
// 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; | ||
|
||
namespace po = boost::program_options; | ||
namespace fs = boost::filesystem; | ||
|
||
/** | ||
* @brief Convert Mesh | ||
*/ | ||
int aliceVision_main(int argc, char** argv) | ||
{ | ||
// timer initialization | ||
|
||
system::Timer timer; | ||
|
||
// command-line parameters | ||
|
||
std::string verboseLevel = system::EVerboseLevel_enumToString(system::Logger::getDefaultVerboseLevel()); | ||
std::string inputMeshPath; | ||
std::string outputFilePath; | ||
|
||
po::options_description allParams("AliceVision convertMesh\n" | ||
"The program allows to convert a mesh to another mesh format."); | ||
|
||
po::options_description requiredParams("Required parameters"); | ||
requiredParams.add_options() | ||
("inputMesh", po::value<std::string>(&inputMeshPath)->default_value(inputMeshPath), | ||
"Mesh file path (*.obj, *.mesh, *.meshb, *.ply, *.off, *.stl).") | ||
("output,o", po::value<std::string>(&outputFilePath)->default_value(outputFilePath), | ||
"Output file path for the new mesh file (*.obj, *.mesh, *.meshb, *.ply, *.off, *.stl)"); | ||
|
||
po::options_description optionalParams("Optional parameters"); | ||
|
||
po::options_description logParams("Log parameters"); | ||
logParams.add_options() | ||
("verboseLevel,v", po::value<std::string>(&verboseLevel)->default_value(verboseLevel), | ||
"verbosity level (fatal, error, warning, info, debug, trace)."); | ||
|
||
allParams.add(requiredParams).add(optionalParams).add(logParams); | ||
|
||
po::variables_map vm; | ||
try | ||
{ | ||
po::store(po::parse_command_line(argc, argv, allParams), vm); | ||
|
||
if(vm.count("help") || (argc == 1)) | ||
{ | ||
ALICEVISION_COUT(allParams); | ||
return EXIT_SUCCESS; | ||
} | ||
po::notify(vm); | ||
} | ||
catch(boost::program_options::required_option& e) | ||
{ | ||
ALICEVISION_CERR("ERROR: " << e.what()); | ||
ALICEVISION_COUT("Usage:\n\n" << allParams); | ||
return EXIT_FAILURE; | ||
} | ||
catch(boost::program_options::error& e) | ||
{ | ||
ALICEVISION_CERR("ERROR: " << e.what()); | ||
ALICEVISION_COUT("Usage:\n\n" << allParams); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ALICEVISION_COUT("Program called with the following parameters:"); | ||
ALICEVISION_COUT(vm); | ||
|
||
// set verbose level | ||
system::Logger::get()->setLogLevel(verboseLevel); | ||
|
||
// check first mesh file path | ||
if(!inputMeshPath.empty() && !fs::exists(inputMeshPath) && !fs::is_regular_file(inputMeshPath)) | ||
{ | ||
ALICEVISION_LOG_ERROR("The input mesh file doesn't exist"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// check output file path | ||
if(outputFilePath.empty()) | ||
{ | ||
ALICEVISION_LOG_ERROR("Invalid output"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// ensure output folder exists | ||
{ | ||
const std::string outputFolderPart = fs::path(outputFilePath).parent_path().string(); | ||
|
||
if(!outputFolderPart.empty() && !fs::exists(outputFolderPart)) | ||
{ | ||
if(!fs::create_directory(outputFolderPart)) | ||
{ | ||
ALICEVISION_LOG_ERROR("Cannot create output folder"); | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
} | ||
|
||
GEO::initialize(); | ||
GEO::CmdLine::import_arg_group("standard"); | ||
GEO::CmdLine::import_arg_group("algo"); | ||
|
||
ALICEVISION_LOG_INFO("Geogram initialized."); | ||
|
||
GEO::Mesh inputMesh; | ||
|
||
// load input mesh | ||
if(!GEO::mesh_load(inputMeshPath, inputMesh)) | ||
{ | ||
ALICEVISION_LOG_ERROR("Failed to load mesh file: \"" << inputMeshPath << "\"."); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// save output mesh | ||
ALICEVISION_LOG_INFO("Convert mesh."); | ||
if(!GEO::mesh_save(inputMesh, outputFilePath)) | ||
{ | ||
ALICEVISION_LOG_ERROR("Failed to save mesh file: \"" << outputFilePath << "\"."); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
ALICEVISION_LOG_INFO("Mesh file: \"" << outputFilePath << "\" saved."); | ||
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.
maybe we can refactor in function inside alicevision_system to be used in all the other exe
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.
It's a good idea. But maybe it's better to do that in another PR with a larger scope ?
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.
we can start with this one creating the function in the library and replacing the code in these 2.
I don't know how many other blocks are there like this one in the other binaries but it's a matter of search and replace