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

pull from upstream #2

Merged
merged 9 commits into from Mar 19, 2024
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
591 changes: 521 additions & 70 deletions .idea/workspace.xml

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions cmake/FindGlew.cmake
@@ -0,0 +1,65 @@
#
# Try to find GLEW library and include path.
# Once done this will define
#
# GLEW_FOUND
# GLEW_INCLUDE_PATH
# GLEW_LIBRARY
#

IF (WIN32)
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
$ENV{PROGRAMFILES}/GLEW/include
${GLEW_ROOT_DIR}/include
DOC "The directory where GL/glew.h resides")

IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
FIND_LIBRARY( GLEW_LIBRARY
NAMES glew64 glew64s
PATHS
$ENV{PROGRAMFILES}/GLEW/lib
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
DOC "The GLEW library (64-bit)"
)
ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
FIND_LIBRARY( GLEW_LIBRARY
NAMES glew GLEW glew32 glew32s
PATHS
$ENV{PROGRAMFILES}/GLEW/lib
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
DOC "The GLEW library"
)
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
ELSE (WIN32)
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
/usr/include
/usr/local/include
/sw/include
/opt/local/include
${GLEW_ROOT_DIR}/include
DOC "The directory where GL/glew.h resides")

FIND_LIBRARY( GLEW_LIBRARY
NAMES GLEW glew
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
${GLEW_ROOT_DIR}/lib
DOC "The GLEW library")
ENDIF (WIN32)

SET(GLEW_FOUND "NO")
IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
SET(GLEW_LIBRARIES ${GLEW_LIBRARY})
SET(GLEW_FOUND "YES")
ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)


include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GLEW DEFAULT_MSG GLEW_LIBRARY GLEW_INCLUDE_PATH)
7 changes: 3 additions & 4 deletions core/camera.cc
Expand Up @@ -178,13 +178,12 @@ CameraInfo::fill_gl_projection (float* mat, float width, float height,

void
CameraInfo::fill_inverse_calibration (float* mat,
float width, float height) const
{
float width, float height) const{

float dim_aspect = width / height;
float image_aspect = dim_aspect * this->paspect;
float ax, ay;
if (image_aspect < 1.0f) /* Portrait. */
{
if (image_aspect < 1.0f) /* Portrait. */{
ax = this->flen * height / this->paspect;
ay = this->flen * height;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Expand Up @@ -3,3 +3,6 @@ add_subdirectory(task1)
add_subdirectory(task2)
add_subdirectory(task3)
add_subdirectory(task4)
add_subdirectory(task6)
add_subdirectory(task7)
add_subdirectory(task8)
3 changes: 1 addition & 2 deletions examples/task1/CMakeLists.txt
Expand Up @@ -6,8 +6,7 @@ include_directories("../..")

#test math basic
set(MATH_BASIC_FILE
task1-1_test_math_basic.cc
)
task1-1_test_math_basic.cc)
add_executable(task1_test_math_basic ${MATH_BASIC_FILE} )
target_link_libraries(task1_test_math_basic util core )

Expand Down
2 changes: 1 addition & 1 deletion examples/task4/task4-1_scene2pset_single_view.cc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/task4/task4-2_scene2pset_multi_views.cc
Expand Up @@ -15,6 +15,7 @@
#include <cstring>
#include <cerrno>
#include <cstdlib>
#include <assert.h>

#include "core/depthmap.h"
#include "core/mesh_info.h"
Expand Down
18 changes: 18 additions & 0 deletions examples/task6/CMakeLists.txt
@@ -0,0 +1,18 @@
project(class6)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-fPIC")

include_directories("../..")


set(SURFACE_RECONSTRUCTION_SOURCES
task6-1_surface_reconstruction.cc)

set(MESH_CLEAN_SOURCES
task6-2_meshclean.cc)

add_executable(task6-1_surface_reconstruction ${SURFACE_RECONSTRUCTION_SOURCES})
target_link_libraries(task6-1_surface_reconstruction mvs util core surface)

add_executable(task6-2_meshclean ${MESH_CLEAN_SOURCES})
target_link_libraries(task6-2_meshclean mvs util core surface)
1 change: 1 addition & 0 deletions examples/task6/task6-1_surface_reconstruction.cc
@@ -0,0 +1 @@
/* * Copyright (C) 2015, Simon Fuhrmann * TU Darmstadt - Graphics, Capture and Massively Parallel Computing * All rights reserved. * * This software may be modified and distributed under the terms * of the BSD 3-Clause license. See the LICENSE.txt file for details. * * The surface reconstruction approach implemented here is described in: * * Floating Scale Surface Reconstruction * Simon Fuhrmann and Michael Goesele * In: ACM ToG (Proceedings of ACM SIGGRAPH 2014). * http://tinyurl.com/floating-scale-surface-recon */#include <cstdlib>#include <iostream>#include <string>#include "core/mesh.h"#include "core/mesh_io_ply.h"#include "util/timer.h"#include "util/arguments.h"#include "util/system.h"#include "surface/sample_io.h"#include "surface/iso_octree.h"#include "surface/iso_surface.h"#include "surface/hermite.h"#include "surface/defines.h"struct AppOptions{ std::vector<std::string> in_files; std::string out_mesh; int refine_octree = 0; fssr::InterpolationType interp_type = fssr::INTERPOLATION_CUBIC;};voidfssrecon (AppOptions const& app_opts, fssr::SampleIO::Options const& pset_opts){ /* Load input point set and insert samples in the octree. */ fssr::IsoOctree octree; for (std::size_t i = 0; i < app_opts.in_files.size(); ++i) { std::cout << "Loading: " << app_opts.in_files[i] << "..." << std::endl; util::WallTimer timer; fssr::SampleIO loader(pset_opts); loader.open_file(app_opts.in_files[i]); fssr::Sample sample; while (loader.next_sample(&sample)) { octree.insert_sample(sample); } std::cout << "Loading samples took " << timer.get_elapsed() << "ms." << std::endl; } /* Exit if no samples have been inserted. */ if (octree.get_num_samples() == 0) { std::cerr << "Octree does not contain any samples, exiting." << std::endl; std::exit(EXIT_FAILURE); } /* Refine octree if requested. Each iteration adds one level. */ if (app_opts.refine_octree > 0) { std::cout << "Refining octree..." << std::flush; util::WallTimer timer; for (int i = 0; i < app_opts.refine_octree; ++i) { octree.refine_octree(); } std::cout << " took " << timer.get_elapsed() << "ms" << std::endl; } /* Compute voxels. */ octree.limit_octree_level(); octree.print_stats(std::cout); octree.compute_voxels(); octree.clear_samples(); /* * TODO print out signed distance function values * */ /* Extract isosurface. */ core::TriangleMesh::Ptr mesh; { std::cout << "Extracting isosurface..." << std::endl; util::WallTimer timer; fssr::IsoSurface iso_surface(&octree, app_opts.interp_type); mesh = iso_surface.extract_mesh(); std::cout << " Done. Surface extraction took " << timer.get_elapsed() << "ms." << std::endl; } octree.clear(); /* Check if anything has been extracted. */ if (mesh->get_vertices().empty()) { std::cerr << "Isosurface does not contain any vertices, exiting." << std::endl; std::exit(EXIT_FAILURE); } /* Surfaces between voxels with zero confidence are ghosts. */ { std::cout << "Deleting zero confidence vertices..." << std::flush; util::WallTimer timer; std::size_t num_vertices = mesh->get_vertices().size(); core::TriangleMesh::DeleteList delete_verts(num_vertices, false); for (std::size_t i = 0; i < num_vertices; ++i) if (mesh->get_vertex_confidences()[i] == 0.0f) delete_verts[i] = true; mesh->delete_vertices_fix_faces(delete_verts); std::cout << " took " << timer.get_elapsed() << "ms." << std::endl; } /* Check for color and delete if not existing. */ core::TriangleMesh::ColorList& colors = mesh->get_vertex_colors(); if (!colors.empty() && colors[0].minimum() < 0.0f) { std::cout << "Removing dummy mesh coloring..." << std::endl; colors.clear(); } /* Write output mesh. */ core::geom::SavePLYOptions ply_opts; ply_opts.write_vertex_colors = true; ply_opts.write_vertex_confidences = true; ply_opts.write_vertex_values = true; std::cout << "Mesh output file: " << app_opts.out_mesh << std::endl; core::geom::save_ply_mesh(mesh, app_opts.out_mesh, ply_opts);}intmain (int argc, char** argv){ util::system::register_segfault_handler(); util::system::print_build_timestamp("Floating Scale Surface Reconstruction"); /* Setup argument parser. */ util::Arguments args; args.set_exit_on_error(true); args.set_nonopt_minnum(2); args.set_helptext_indent(25); args.set_usage(argv[0], "[ OPTS ] IN_PLY [ IN_PLY ... ] OUT_PLY"); args.add_option('s', "scale-factor", true, "Multiply sample scale with factor [1.0]"); args.add_option('r', "refine-octree", true, "Refines octree with N levels [0]"); args.add_option('\0', "min-scale", true, "Minimum scale, smaller samples are clamped"); args.add_option('\0', "max-scale", true, "Maximum scale, larger samples are ignored");#if FSSR_USE_DERIVATIVES args.add_option('\0', "interpolation", true, "Interpolation: linear, scaling, lsderiv, [cubic]");#endif // FSSR_USE_DERIVATIVES args.set_description("Samples the implicit function defined by the input " "samples and produces a surface mesh. The input samples must have " "normals and the \"values\" PLY attribute (the scale of the samples). " "Both confidence values and vertex colors are optional. The final " "surface should be cleaned (sliver triangles, isolated components, " "low-confidence vertices) afterwards."); args.parse(argc, argv); /* Init default settings. */ AppOptions app_opts; fssr::SampleIO::Options pset_opts; /* Scan arguments. */ while (util::ArgResult const* arg = args.next_result()) { if (arg->opt == nullptr) { app_opts.in_files.push_back(arg->arg); continue; } if (arg->opt->lopt == "scale-factor") pset_opts.scale_factor = arg->get_arg<float>(); else if (arg->opt->lopt == "refine-octree") app_opts.refine_octree = arg->get_arg<int>(); else if (arg->opt->lopt == "min-scale") pset_opts.min_scale = arg->get_arg<float>(); else if (arg->opt->lopt == "max-scale") pset_opts.max_scale = arg->get_arg<float>(); else if (arg->opt->lopt == "interpolation") { if (arg->arg == "linear") app_opts.interp_type = fssr::INTERPOLATION_LINEAR; else if (arg->arg == "scaling") app_opts.interp_type = fssr::INTERPOLATION_SCALING; else if (arg->arg == "lsderiv") app_opts.interp_type = fssr::INTERPOLATION_LSDERIV; else if (arg->arg == "cubic") app_opts.interp_type = fssr::INTERPOLATION_CUBIC; else { args.generate_helptext(std::cerr); std::cerr << std::endl << "Error: Invalid interpolation: " << arg->arg << std::endl; return 1; } } else { std::cerr << "Invalid option: " << arg->opt->sopt << std::endl; return EXIT_FAILURE; } } if (app_opts.in_files.size() < 2) { args.generate_helptext(std::cerr); return EXIT_FAILURE; } app_opts.out_mesh = app_opts.in_files.back(); app_opts.in_files.pop_back(); if (app_opts.refine_octree < 0 || app_opts.refine_octree > 3) { std::cerr << "Unreasonable refine level of " << app_opts.refine_octree << ", exiting." << std::endl; return EXIT_FAILURE; } try { fssrecon(app_opts, pset_opts); } catch (std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return EXIT_FAILURE; } std::cout << "All done. Remember to clean the output mesh." << std::endl; return EXIT_SUCCESS;}
Expand Down
189 changes: 189 additions & 0 deletions examples/task6/task6-2_meshclean.cc
@@ -0,0 +1,189 @@
/*
* Copyright (C) 2015, Simon Fuhrmann
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
*/

#include <cstdlib>
#include <iostream>
#include <string>

#include "util/system.h"
#include "util/timer.h"
#include "util/arguments.h"
#include "core/mesh.h"
#include "core/mesh_io.h"
#include "core/mesh_io_ply.h"
#include "core/mesh_tools.h"
#include "surface/mesh_clean.h"

struct AppSettings
{
std::string in_mesh;
std::string out_mesh;
bool clean_degenerated;
bool delete_scale;
bool delete_conf;
bool delete_colors;
float conf_threshold;
int component_size;
};

void
remove_low_conf_vertices (core::TriangleMesh::Ptr mesh, float const thres)
{
core::TriangleMesh::ConfidenceList const& confs = mesh->get_vertex_confidences();
std::vector<bool> delete_list(confs.size(), false);
for (std::size_t i = 0; i < confs.size(); ++i)
{
if (confs[i] > thres)
continue;
delete_list[i] = true;
}
mesh->delete_vertices_fix_faces(delete_list);
}

int
main (int argc, char** argv)
{
util::system::register_segfault_handler();
util::system::print_build_timestamp("MVE FSSR Mesh Cleaning");

/* Setup argument parser. */
util::Arguments args;
args.set_exit_on_error(true);
args.set_nonopt_minnum(2);
args.set_nonopt_maxnum(2);
args.set_helptext_indent(25);
args.set_usage(argv[0], "[ OPTS ] IN_MESH OUT_MESH");
args.add_option('t', "threshold", true, "Threshold on the geometry confidence [1.0]");
args.add_option('c', "component-size", true, "Minimum number of vertices per component [1000]");
args.add_option('n', "no-clean", false, "Prevents cleanup of degenerated faces");
args.add_option('\0', "delete-scale", false, "Delete scale attribute from mesh");
args.add_option('\0', "delete-conf", false, "Delete confidence attribute from mesh");
args.add_option('\0', "delete-color", false, "Delete color attribute from mesh");
args.set_description("The application cleans degenerated faces resulting "
"from MC-like algorithms. Vertices below a confidence threshold and "
"vertices in small isolated components are deleted as well.");
args.parse(argc, argv);

/* Init default settings. */
AppSettings conf;
conf.in_mesh = args.get_nth_nonopt(0);
conf.out_mesh = args.get_nth_nonopt(1);
conf.conf_threshold = 1.0f;
conf.component_size = 1000;
conf.clean_degenerated = true;
conf.delete_scale = false;
conf.delete_conf = false;
conf.delete_colors = false;

/* Scan arguments. */
while (util::ArgResult const* arg = args.next_option())
{
if (arg->opt->lopt == "threshold")
conf.conf_threshold = arg->get_arg<float>();
else if (arg->opt->lopt == "component-size")
conf.component_size = arg->get_arg<int>();
else if (arg->opt->lopt == "no-clean")
conf.clean_degenerated = false;
else if (arg->opt->lopt == "delete-scale")
conf.delete_scale = true;
else if (arg->opt->lopt == "delete-conf")
conf.delete_conf = true;
else if (arg->opt->lopt == "delete-color")
conf.delete_colors = true;
else
{
std::cerr << "Invalid option: " << arg->opt->sopt << std::endl;
return EXIT_FAILURE;
}
}

/* Load input mesh. */
core::TriangleMesh::Ptr mesh;
try
{
std::cout << "Loading mesh: " << conf.in_mesh << std::endl;
mesh = core::geom::load_mesh(conf.in_mesh);
}
catch (std::exception& e)
{
std::cerr << "Error loading mesh: " << e.what() << std::endl;
return EXIT_FAILURE;
}

/* Sanity checks. */
if (mesh->get_vertices().empty())
{
std::cerr << "Error: Mesh is empty!" << std::endl;
return EXIT_FAILURE;
}

if (!mesh->has_vertex_confidences() && conf.conf_threshold > 0.0f)
{
std::cerr << "Error: Confidence cleanup requested, but mesh "
"has no confidence values." << std::endl;
return EXIT_FAILURE;
}

if (mesh->get_faces().empty()
&& (conf.clean_degenerated || conf.component_size > 0))
{
std::cerr << "Error: Components/faces cleanup "
"requested, but mesh has no faces." << std::endl;
return EXIT_FAILURE;
}

/* Remove low-confidence geometry. */
if (conf.conf_threshold > 0.0f)
{
std::cout << "Removing low-confidence geometry (threshold "
<< conf.conf_threshold << ")..." << std::endl;
std::size_t num_verts = mesh->get_vertices().size();
remove_low_conf_vertices(mesh, conf.conf_threshold);
std::size_t new_num_verts = mesh->get_vertices().size();
std::cout << " Deleted " << (num_verts - new_num_verts)
<< " low-confidence vertices." << std::endl;
}

/* Remove isolated components if requested. */
if (conf.component_size > 0)
{
std::cout << "Removing isolated components below "
<< conf.component_size << " vertices..." << std::endl;
std::size_t num_verts = mesh->get_vertices().size();
core::geom::mesh_components(mesh, conf.component_size);
std::size_t new_num_verts = mesh->get_vertices().size();
std::cout << " Deleted " << (num_verts - new_num_verts)
<< " vertices in isolated regions." << std::endl;
}

/* Remove degenerated faces from the mesh. */
if (conf.clean_degenerated)
{
std::cout << "Removing degenerated faces..." << std::endl;
std::size_t num_collapsed = fssr::clean_mc_mesh(mesh);
std::cout << " Collapsed " << num_collapsed << " edges." << std::endl;
}

/* Write output mesh. */
std::cout << "Writing mesh: " << conf.out_mesh << std::endl;
if (util::string::right(conf.out_mesh, 4) == ".ply")
{
core::geom::SavePLYOptions ply_opts;
ply_opts.write_vertex_colors = !conf.delete_colors;
ply_opts.write_vertex_confidences = !conf.delete_conf;
ply_opts.write_vertex_values = !conf.delete_scale;
core::geom::save_ply_mesh(mesh, conf.out_mesh, ply_opts);
}
else
{
core::geom::save_mesh(mesh, conf.out_mesh);
}

return EXIT_SUCCESS;
}
27 changes: 27 additions & 0 deletions examples/task7/CMakeLists.txt
@@ -0,0 +1,27 @@
project(class7)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-fPIC")

include_directories("../..")
include_directories(../../3rdParty/eigen)

#set(TBB_INCLUDE_DIRS "/usr/local/Cellar/tbb/2019_U1/include" CACHE PATH "Path to where the TBB include files (tbb/) reside")
#set(TBB_LIBRARY "/usr/local/Cellar/tbb/2019_U1/lib" CACHE PATH "Path to where the TBB library files (libtbb.so etc.) reside")
#list(APPEND CMAKE_MODULE_PATH "../../cmake")
###find_package(TBB COMPONENTS tbbmalloc tbbmalloc_proxy tbb_preview)


####find_package(OpenGL REQUIRED)

set(MESH_CLEAN_SOURCES
task7_1_meshclean.cc)

add_executable(task7_1_mesh_clean ${MESH_CLEAN_SOURCES})
target_link_libraries(task7_1_mesh_clean util core surface)

set(TEXTURING_SOURCES
arguments.h
arguments.cpp
task7_2_texrecon.cpp)
add_executable(task7_2_texturing ${TEXTURING_SOURCES})
target_link_libraries(task7_2_texturing mvs util core texturing coldet mrf gco)