Skip to content

Commit

Permalink
add task7
Browse files Browse the repository at this point in the history
  • Loading branch information
swayfreeda committed Nov 3, 2018
1 parent 39578eb commit cfa6fd4
Show file tree
Hide file tree
Showing 11 changed files with 671 additions and 37 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
cmake_minimum_required(VERSION 3.5)
project(ImageBasedModellingEdu)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})

# Eigen (required)
find_package(Eigen REQUIRED)
include_directories(${EIGEN_INCLUDE_DIRS})
add_definitions(-DEIGEN_USE_NEW_STDVECTOR -DEIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET)


set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-fPIC")

add_subdirectory(core)
#add_subdirectory(math)
add_subdirectory(util)
add_subdirectory(features)
add_subdirectory(sfm)
add_subdirectory(mvs)
add_subdirectory(examples)
add_subdirectory(surface)
add_subdirectory(texturing)
add_subdirectory(3rdParty/rayint)
#add_subdirectory(3rdParty/eigen)
#add_subdirectory(3rdParty/mapmap)
12 changes: 6 additions & 6 deletions core/image_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#define MVE_IMAGE_COLOR_HEADER

#include "math/functions.h"
#include "mve/image.h"
#include "mve/defines.h"
#include "core/image.h"
#include "core/defines.h"

MVE_NAMESPACE_BEGIN
MVE_IMAGE_NAMESPACE_BEGIN
CORE_NAMESPACE_BEGIN
CORE_IMAGE_NAMESPACE_BEGIN

/**
* Applies an in-place color conversion to the given image. The conversion
Expand Down Expand Up @@ -325,7 +325,7 @@ color_ycbcr_to_rgb<uint8_t> (uint8_t* v)
v[2] = std::max(0.0, std::min(255.0, math::round(out[2])));
}

MVE_IMAGE_NAMESPACE_END
MVE_NAMESPACE_END
CORE_IMAGE_NAMESPACE_END
CORE_NAMESPACE_END

#endif /* MVE_IMAGE_COLOR_HEADER */
12 changes: 9 additions & 3 deletions core/mesh_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ CORE_NAMESPACE_BEGIN
void
MeshInfo::initialize (TriangleMesh::ConstPtr mesh)
{
// vertices of the mesh
TriangleMesh::VertexList const& verts = mesh->get_vertices();
// facets of the mesh
TriangleMesh::FaceList const& faces = mesh->get_faces();
// number of facets
std::size_t face_amount = faces.size() / 3;

this->vertex_info.clear();
this->vertex_info.resize(verts.size());

/* Add faces to their three vertices. */
for (std::size_t i = 0, i3 = 0; i < face_amount; ++i)
for (std::size_t j = 0; j < 3; ++j, ++i3)
for (std::size_t i = 0, i3 = 0; i < face_amount; ++i) {
for (std::size_t j = 0; j < 3; ++j, ++i3) {
this->vertex_info[faces[i3]].faces.push_back(i);
}
}

/* Classify each vertex and compute adjacenty info. */
for (std::size_t i = 0; i < this->vertex_info.size(); ++i)
for (std::size_t i = 0; i < this->vertex_info.size(); ++i){
this->update_vertex(*mesh, i);
}
}

/* ---------------------------------------------------------------- */
Expand Down
41 changes: 17 additions & 24 deletions core/mesh_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ class MeshInfo
/** Per-vertex classification and adjacency information. */
struct VertexInfo
{
// vertex class
VertexClass vclass;

// indices of adjacent vertices
AdjacentVertices verts;

// indices of adjacent facets
AdjacentFaces faces;

void remove_adjacent_face (std::size_t face_id);
Expand Down Expand Up @@ -101,66 +106,54 @@ MeshInfo::MeshInfo (TriangleMesh::ConstPtr mesh)
}

inline MeshInfo::VertexInfo&
MeshInfo::operator[] (std::size_t id)
{
MeshInfo::operator[] (std::size_t id) {
return this->vertex_info[id];
}

inline MeshInfo::VertexInfo const&
MeshInfo::operator[] (std::size_t id) const
{
MeshInfo::operator[] (std::size_t id) const {
return this->vertex_info[id];
}

inline MeshInfo::VertexInfo&
MeshInfo::at (std::size_t id)
{
MeshInfo::at (std::size_t id) {
return this->vertex_info[id];
}

inline MeshInfo::VertexInfo const&
MeshInfo::at (std::size_t id) const
{
MeshInfo::at (std::size_t id) const {
return this->vertex_info[id];
}

inline std::size_t
MeshInfo::size (void) const
{
MeshInfo::size (void) const {
return this->vertex_info.size();
}

inline void
MeshInfo::clear (void)
{
MeshInfo::clear (void) {
std::vector<VertexInfo>().swap(this->vertex_info);
}

inline void
MeshInfo::VertexInfo::remove_adjacent_face (std::size_t face_id)
{
this->faces.erase(std::remove(this->faces.begin(), this->faces.end(),
face_id), this->faces.end());
MeshInfo::VertexInfo::remove_adjacent_face (std::size_t face_id) {
this->faces.erase(std::remove(this->faces.begin(), this->faces.end(), face_id), this->faces.end());
}

inline void
MeshInfo::VertexInfo::remove_adjacent_vertex (std::size_t vertex_id)
{
this->verts.erase(std::remove(this->verts.begin(), this->verts.end(),
vertex_id), this->verts.end());
MeshInfo::VertexInfo::remove_adjacent_vertex (std::size_t vertex_id) {
this->verts.erase(std::remove(this->verts.begin(), this->verts.end(), vertex_id), this->verts.end());
}

inline void
MeshInfo::VertexInfo::replace_adjacent_face (std::size_t old_id,
std::size_t new_id)
{
std::size_t new_id) {
std::replace(this->faces.begin(), this->faces.end(), old_id, new_id);
}

inline void
MeshInfo::VertexInfo::replace_adjacent_vertex (std::size_t old_id,
std::size_t new_id)
{
std::size_t new_id) {
std::replace(this->verts.begin(), this->verts.end(), old_id, new_id);
}

Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ add_subdirectory(task3)
add_subdirectory(task4)
add_subdirectory(task5)
add_subdirectory(task6)
add_subdirectory(task7)
29 changes: 29 additions & 0 deletions examples/task7/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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)

find_package(GLFW REQUIRED glfw3)

set(MESH_CLEAN_SOURCES
class7_meshclean.cc)

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

set(TEXTURING_SOURCES
arguments.h
arguments.cpp
class7_texrecon.cpp)
add_executable(task7_texturing ${TEXTURING_SOURCES})
target_link_libraries(task7_texturing mvs util core texturing tbb)
177 changes: 177 additions & 0 deletions examples/task7/arguments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/*
* Copyright (C) 2015, Nils Moehrle, Michael Waechter
* 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 "arguments.h"
#include "util/file_system.h"

#define SKIP_GLOBAL_SEAM_LEVELING "skip_global_seam_leveling"
#define SKIP_GEOMETRIC_VISIBILITY_TEST "skip_geometric_visibility_test"
#define SKIP_LOCAL_SEAM_LEVELING "skip_local_seam_leveling"
#define NO_INTERMEDIATE_RESULTS "no_intermediate_results"
#define WRITE_TIMINGS "write_timings"
#define SKIP_HOLE_FILLING "skip_hole_filling"
#define KEEP_UNSEEN_FACES "keep_unseen_faces"

Arguments parse_args(int argc, char **argv) {
util::Arguments args;
args.set_exit_on_error(true);
args.set_nonopt_maxnum(3);
args.set_nonopt_minnum(3);
args.set_helptext_indent(34);
args.set_description("Textures a mesh given images in form of a 3D scene.");
args.set_usage("Usage: " + std::string(argv[0]) + " [options] IN_SCENE IN_MESH OUT_PREFIX"
"\n\nIN_SCENE := (SCENE_FOLDER | BUNDLE_FILE | MVE_SCENE::EMBEDDING)"
"\n\nSCENE_FOLDER:"
"\nWithin a scene folder a .cam file has to be given for each image."
"\nA .cam file is structured as follows:"
"\n tx ty tz R00 R01 R02 R10 R11 R12 R20 R21 R22"
"\n f d0 d1 paspect ppx ppy"
"\nFirst line: Extrinsics - translation vector and rotation matrix"
"\nSecond line: Intrinsics - focal length, distortion coefficients, pixel aspect ratio and principal point"
"\nThe focal length is the distance between camera center and image plane normalized by dividing with the larger image dimension."
"\nFor non zero distortion coefficients the image will be undistorted prior to the texturing process."
" If only d0 is non zero the Noah Snavely's distortion model is assumed otherwise the distortion model of VSFM is assumed."
"\nThe pixel aspect ratio is usually 1 or close to 1. If your SfM system doesn't output it, but outputs a different focal length in x and y direction, you have to encode this here."
"\nThe principal point has to be given in unit dimensions (e.g. 0.5 0.5)."
"\n\nBUNDLE_FILE:"
"\nCurrently only NVM bundle files (from VisualSFM, http://ccwu.me/vsfm/) are supported."
"\nSince the bundle file contains relative paths to the images please make sure you did not move them (relative to the bundle) or rename them after the bundling process."
"\n\nMVE_SCENE::EMBEDDING:"
"\nThis is the scene representation we use in our research group: http://www.gris.tu-darmstadt.de/projects/multiview-environment/."
"\n\nIN_MESH:"
"\nThe mesh that you want to texture and which needs to be in the same coordinate frame as the camera parameters. You can reconstruct one, e.g. with CMVS: http://www.di.ens.fr/cmvs/"
"\n\nOUT_PREFIX:"
"\nA path and name for the output files, e.g. <path>/<to>/my_textured_mesh"
"\nDon't append an obj extension. The application does that itself because it outputs multiple files (mesh, material file, texture files)."
"\n");
args.add_option('D',"data_cost_file", true,
"Skip calculation of data costs and use the ones provided in the given file");
args.add_option('L',"labeling_file", true,
"Skip view selection and use the labeling provided in the given file");
args.add_option('d',"data_term", true,
"Data term: {" +
choices<tex::DataTerm>() + "} [" +
choice_string<tex::DataTerm>(tex::DATA_TERM_GMI) + "]");
args.add_option('s',"smoothness_term", true,
"Smoothness term: {" +
choices<tex::SmoothnessTerm>() + "} [" +
choice_string<tex::SmoothnessTerm>(tex::SMOOTHNESS_TERM_POTTS) + "]");
args.add_option('o',"outlier_removal", true,
"Photometric outlier (pedestrians etc.) removal method: {" +
choices<tex::OutlierRemoval>() + "} [" +
choice_string<tex::OutlierRemoval>(tex::OUTLIER_REMOVAL_NONE) + "]");
args.add_option('t',"tone_mapping", true,
"Tone mapping method: {" +
choices<tex::ToneMapping>() + "} [" +
choice_string<tex::ToneMapping>(tex::TONE_MAPPING_NONE) + "]");
args.add_option('v',"view_selection_model", false,
"Write out view selection model [false]");
args.add_option('\0', SKIP_GEOMETRIC_VISIBILITY_TEST, false,
"Skip geometric visibility test based on ray intersection [false]");
args.add_option('\0', SKIP_GLOBAL_SEAM_LEVELING, false,
"Skip global seam leveling [false]");
args.add_option('\0', SKIP_LOCAL_SEAM_LEVELING, false,
"Skip local seam leveling (Poisson editing) [false]");
args.add_option('\0', SKIP_HOLE_FILLING, false,
"Skip hole filling [false]");
args.add_option('\0', KEEP_UNSEEN_FACES, false,
"Keep unseen faces [false]");
args.add_option('\0', WRITE_TIMINGS, false,
"Write out timings for each algorithm step (OUT_PREFIX + _timings.csv)");
args.add_option('\0', NO_INTERMEDIATE_RESULTS, false,
"Do not write out intermediate results");
args.parse(argc, argv);

Arguments conf;
conf.in_scene = args.get_nth_nonopt(0);
conf.in_mesh = args.get_nth_nonopt(1);
conf.out_prefix = util::fs::sanitize_path(args.get_nth_nonopt(2));

/* Set defaults for optional arguments. */
conf.data_cost_file = "";
conf.labeling_file = "";

conf.write_timings = false;
conf.write_intermediate_results = true;
conf.write_view_selection_model = false;

/* Handle optional arguments. */
for (util::ArgResult const* i = args.next_option();
i != 0; i = args.next_option()) {
switch (i->opt->sopt) {
case 'v':
conf.write_view_selection_model = true;
break;
case 'D':
conf.data_cost_file = i->arg;
break;
case 'L':
conf.labeling_file = i->arg;
break;
case 'd':
conf.settings.data_term = parse_choice<tex::DataTerm>(i->arg);
break;
case 's':
conf.settings.smoothness_term = parse_choice<tex::SmoothnessTerm>(i->arg);
break;
case 'o':
conf.settings.outlier_removal = parse_choice<tex::OutlierRemoval>(i->arg);
break;
case 't':
conf.settings.tone_mapping = parse_choice<tex::ToneMapping>(i->arg);
break;
case '\0':
if (i->opt->lopt == SKIP_GEOMETRIC_VISIBILITY_TEST) {
conf.settings.geometric_visibility_test = false;
} else if (i->opt->lopt == SKIP_GLOBAL_SEAM_LEVELING) {
conf.settings.global_seam_leveling = false;
} else if (i->opt->lopt == SKIP_LOCAL_SEAM_LEVELING) {
conf.settings.local_seam_leveling = false;
} else if (i->opt->lopt == SKIP_HOLE_FILLING) {
conf.settings.hole_filling = false;
} else if (i->opt->lopt == KEEP_UNSEEN_FACES) {
conf.settings.keep_unseen_faces = true;
} else if (i->opt->lopt == WRITE_TIMINGS) {
conf.write_timings = true;
} else if (i->opt->lopt == NO_INTERMEDIATE_RESULTS) {
conf.write_intermediate_results = false;
} else {
throw std::invalid_argument("Invalid long option");
}
break;
default:
throw std::invalid_argument("Invalid short option");
}
}

return conf;
}

std::string
bool_to_string(bool b){
return b ? "True" : "False";
}

std::string
Arguments::to_string(){
std::stringstream out;
out << "Input scene: \t" << in_scene << std::endl
<< "Input mesh: \t" << in_mesh << std::endl
<< "Output prefix: \t" << out_prefix << std::endl
<< "Datacost file: \t" << data_cost_file << std::endl
<< "Labeling file: \t" << labeling_file << std::endl
<< "Data term: \t" << choice_string<tex::DataTerm>(settings.data_term) << std::endl
<< "Smoothness term: \t" << choice_string<tex::SmoothnessTerm>(settings.smoothness_term) << std::endl
<< "Outlier removal method: \t" << choice_string<tex::OutlierRemoval>(settings.outlier_removal) << std::endl
<< "Tone mapping: \t" << choice_string<tex::ToneMapping>(settings.tone_mapping) << std::endl
<< "Apply global seam leveling: \t" << bool_to_string(settings.global_seam_leveling) << std::endl
<< "Apply local seam leveling: \t" << bool_to_string(settings.local_seam_leveling) << std::endl;

return out.str();
}
Loading

0 comments on commit cfa6fd4

Please sign in to comment.