Skip to content
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 5 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/software/convert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ alicevision_add_software(aliceVision_convertFloatDescriptorToUchar
Boost::boost
Boost::timer
)
endif()
endif() # ALICEVISION_BUILD_SFM

# Convert image to EXR
alicevision_add_software(aliceVision_convertRAW
Expand All @@ -41,3 +41,16 @@ alicevision_add_software(aliceVision_convertRAW
Boost::filesystem
)

if(ALICEVISION_BUILD_MVS)

# Merge two meshes
alicevision_add_software(aliceVision_convertMesh
SOURCE main_convertMesh.cpp
FOLDER ${FOLDER_SOFTWARE_CONVERT}
LINKS aliceVision_system
aliceVision_numeric
Geogram::geogram
${Boost_LIBRARIES}
)

endif() # ALICEVISION_BUILD_MVS
156 changes: 156 additions & 0 deletions src/software/convert/main_convertMesh.cpp
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;
}
}
}
Comment on lines +116 to +127
Copy link
Member

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

Copy link
Member Author

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 ?

Copy link
Member

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


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;
}
14 changes: 14 additions & 0 deletions src/software/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,17 @@ alicevision_add_software(aliceVision_utils_lightingEstimation
)

endif() # ALICEVISION_BUILD_SFM

if(ALICEVISION_BUILD_MVS)

# Merge two meshes
alicevision_add_software(aliceVision_utils_mergeMeshes
SOURCE main_mergeMeshes.cpp
FOLDER ${FOLDER_SOFTWARE_UTILS}
LINKS aliceVision_system
aliceVision_numeric
Geogram::geogram
${Boost_LIBRARIES}
)

endif() # ALICEVISION_BUILD_MVS
Loading