Skip to content

Commit cfa6fd4

Browse files
author
swayfreeda
committed
add task7
1 parent 39578eb commit cfa6fd4

File tree

11 files changed

+671
-37
lines changed

11 files changed

+671
-37
lines changed

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
cmake_minimum_required(VERSION 3.5)
22
project(ImageBasedModellingEdu)
3+
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
4+
5+
# Eigen (required)
6+
find_package(Eigen REQUIRED)
7+
include_directories(${EIGEN_INCLUDE_DIRS})
8+
add_definitions(-DEIGEN_USE_NEW_STDVECTOR -DEIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET)
9+
310

411
set(CMAKE_CXX_STANDARD 11)
512
set(CMAKE_CXX_FLAGS "-fPIC")
613

714
add_subdirectory(core)
8-
#add_subdirectory(math)
915
add_subdirectory(util)
1016
add_subdirectory(features)
1117
add_subdirectory(sfm)
1218
add_subdirectory(mvs)
1319
add_subdirectory(examples)
1420
add_subdirectory(surface)
21+
add_subdirectory(texturing)
22+
add_subdirectory(3rdParty/rayint)
23+
#add_subdirectory(3rdParty/eigen)
24+
#add_subdirectory(3rdParty/mapmap)

core/image_color.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#define MVE_IMAGE_COLOR_HEADER
1212

1313
#include "math/functions.h"
14-
#include "mve/image.h"
15-
#include "mve/defines.h"
14+
#include "core/image.h"
15+
#include "core/defines.h"
1616

17-
MVE_NAMESPACE_BEGIN
18-
MVE_IMAGE_NAMESPACE_BEGIN
17+
CORE_NAMESPACE_BEGIN
18+
CORE_IMAGE_NAMESPACE_BEGIN
1919

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

328-
MVE_IMAGE_NAMESPACE_END
329-
MVE_NAMESPACE_END
328+
CORE_IMAGE_NAMESPACE_END
329+
CORE_NAMESPACE_END
330330

331331
#endif /* MVE_IMAGE_COLOR_HEADER */

core/mesh_info.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,27 @@ CORE_NAMESPACE_BEGIN
1818
void
1919
MeshInfo::initialize (TriangleMesh::ConstPtr mesh)
2020
{
21+
// vertices of the mesh
2122
TriangleMesh::VertexList const& verts = mesh->get_vertices();
23+
// facets of the mesh
2224
TriangleMesh::FaceList const& faces = mesh->get_faces();
25+
// number of facets
2326
std::size_t face_amount = faces.size() / 3;
2427

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

2831
/* Add faces to their three vertices. */
29-
for (std::size_t i = 0, i3 = 0; i < face_amount; ++i)
30-
for (std::size_t j = 0; j < 3; ++j, ++i3)
32+
for (std::size_t i = 0, i3 = 0; i < face_amount; ++i) {
33+
for (std::size_t j = 0; j < 3; ++j, ++i3) {
3134
this->vertex_info[faces[i3]].faces.push_back(i);
35+
}
36+
}
3237

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

3844
/* ---------------------------------------------------------------- */

core/mesh_info.h

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ class MeshInfo
4141
/** Per-vertex classification and adjacency information. */
4242
struct VertexInfo
4343
{
44+
// vertex class
4445
VertexClass vclass;
46+
47+
// indices of adjacent vertices
4548
AdjacentVertices verts;
49+
50+
// indices of adjacent facets
4651
AdjacentFaces faces;
4752

4853
void remove_adjacent_face (std::size_t face_id);
@@ -101,66 +106,54 @@ MeshInfo::MeshInfo (TriangleMesh::ConstPtr mesh)
101106
}
102107

103108
inline MeshInfo::VertexInfo&
104-
MeshInfo::operator[] (std::size_t id)
105-
{
109+
MeshInfo::operator[] (std::size_t id) {
106110
return this->vertex_info[id];
107111
}
108112

109113
inline MeshInfo::VertexInfo const&
110-
MeshInfo::operator[] (std::size_t id) const
111-
{
114+
MeshInfo::operator[] (std::size_t id) const {
112115
return this->vertex_info[id];
113116
}
114117

115118
inline MeshInfo::VertexInfo&
116-
MeshInfo::at (std::size_t id)
117-
{
119+
MeshInfo::at (std::size_t id) {
118120
return this->vertex_info[id];
119121
}
120122

121123
inline MeshInfo::VertexInfo const&
122-
MeshInfo::at (std::size_t id) const
123-
{
124+
MeshInfo::at (std::size_t id) const {
124125
return this->vertex_info[id];
125126
}
126127

127128
inline std::size_t
128-
MeshInfo::size (void) const
129-
{
129+
MeshInfo::size (void) const {
130130
return this->vertex_info.size();
131131
}
132132

133133
inline void
134-
MeshInfo::clear (void)
135-
{
134+
MeshInfo::clear (void) {
136135
std::vector<VertexInfo>().swap(this->vertex_info);
137136
}
138137

139138
inline void
140-
MeshInfo::VertexInfo::remove_adjacent_face (std::size_t face_id)
141-
{
142-
this->faces.erase(std::remove(this->faces.begin(), this->faces.end(),
143-
face_id), this->faces.end());
139+
MeshInfo::VertexInfo::remove_adjacent_face (std::size_t face_id) {
140+
this->faces.erase(std::remove(this->faces.begin(), this->faces.end(), face_id), this->faces.end());
144141
}
145142

146143
inline void
147-
MeshInfo::VertexInfo::remove_adjacent_vertex (std::size_t vertex_id)
148-
{
149-
this->verts.erase(std::remove(this->verts.begin(), this->verts.end(),
150-
vertex_id), this->verts.end());
144+
MeshInfo::VertexInfo::remove_adjacent_vertex (std::size_t vertex_id) {
145+
this->verts.erase(std::remove(this->verts.begin(), this->verts.end(), vertex_id), this->verts.end());
151146
}
152147

153148
inline void
154149
MeshInfo::VertexInfo::replace_adjacent_face (std::size_t old_id,
155-
std::size_t new_id)
156-
{
150+
std::size_t new_id) {
157151
std::replace(this->faces.begin(), this->faces.end(), old_id, new_id);
158152
}
159153

160154
inline void
161155
MeshInfo::VertexInfo::replace_adjacent_vertex (std::size_t old_id,
162-
std::size_t new_id)
163-
{
156+
std::size_t new_id) {
164157
std::replace(this->verts.begin(), this->verts.end(), old_id, new_id);
165158
}
166159

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ add_subdirectory(task3)
44
add_subdirectory(task4)
55
add_subdirectory(task5)
66
add_subdirectory(task6)
7+
add_subdirectory(task7)

examples/task7/CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
project(class7)
2+
set(CMAKE_CXX_STANDARD 11)
3+
set(CMAKE_CXX_FLAGS "-fPIC")
4+
5+
include_directories("../..")
6+
include_directories(../../3rdParty/eigen)
7+
8+
#set(TBB_INCLUDE_DIRS "/usr/local/Cellar/tbb/2019_U1/include" CACHE PATH "Path to where the TBB include files (tbb/) reside")
9+
#set(TBB_LIBRARY "/usr/local/Cellar/tbb/2019_U1/lib" CACHE PATH "Path to where the TBB library files (libtbb.so etc.) reside")
10+
#list(APPEND CMAKE_MODULE_PATH "../../cmake")
11+
find_package(TBB COMPONENTS tbbmalloc tbbmalloc_proxy tbb_preview)
12+
13+
14+
find_package(OpenGL REQUIRED)
15+
16+
find_package(GLFW REQUIRED glfw3)
17+
18+
set(MESH_CLEAN_SOURCES
19+
class7_meshclean.cc)
20+
21+
add_executable(task7_mesh_clean ${MESH_CLEAN_SOURCES})
22+
target_link_libraries(task7_mesh_clean util core surface)
23+
24+
set(TEXTURING_SOURCES
25+
arguments.h
26+
arguments.cpp
27+
class7_texrecon.cpp)
28+
add_executable(task7_texturing ${TEXTURING_SOURCES})
29+
target_link_libraries(task7_texturing mvs util core texturing tbb)

examples/task7/arguments.cpp

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright (C) 2015, Nils Moehrle, Michael Waechter
3+
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4+
* All rights reserved.
5+
*
6+
* This software may be modified and distributed under the terms
7+
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
8+
*/
9+
10+
#include "arguments.h"
11+
#include "util/file_system.h"
12+
13+
#define SKIP_GLOBAL_SEAM_LEVELING "skip_global_seam_leveling"
14+
#define SKIP_GEOMETRIC_VISIBILITY_TEST "skip_geometric_visibility_test"
15+
#define SKIP_LOCAL_SEAM_LEVELING "skip_local_seam_leveling"
16+
#define NO_INTERMEDIATE_RESULTS "no_intermediate_results"
17+
#define WRITE_TIMINGS "write_timings"
18+
#define SKIP_HOLE_FILLING "skip_hole_filling"
19+
#define KEEP_UNSEEN_FACES "keep_unseen_faces"
20+
21+
Arguments parse_args(int argc, char **argv) {
22+
util::Arguments args;
23+
args.set_exit_on_error(true);
24+
args.set_nonopt_maxnum(3);
25+
args.set_nonopt_minnum(3);
26+
args.set_helptext_indent(34);
27+
args.set_description("Textures a mesh given images in form of a 3D scene.");
28+
args.set_usage("Usage: " + std::string(argv[0]) + " [options] IN_SCENE IN_MESH OUT_PREFIX"
29+
"\n\nIN_SCENE := (SCENE_FOLDER | BUNDLE_FILE | MVE_SCENE::EMBEDDING)"
30+
"\n\nSCENE_FOLDER:"
31+
"\nWithin a scene folder a .cam file has to be given for each image."
32+
"\nA .cam file is structured as follows:"
33+
"\n tx ty tz R00 R01 R02 R10 R11 R12 R20 R21 R22"
34+
"\n f d0 d1 paspect ppx ppy"
35+
"\nFirst line: Extrinsics - translation vector and rotation matrix"
36+
"\nSecond line: Intrinsics - focal length, distortion coefficients, pixel aspect ratio and principal point"
37+
"\nThe focal length is the distance between camera center and image plane normalized by dividing with the larger image dimension."
38+
"\nFor non zero distortion coefficients the image will be undistorted prior to the texturing process."
39+
" If only d0 is non zero the Noah Snavely's distortion model is assumed otherwise the distortion model of VSFM is assumed."
40+
"\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."
41+
"\nThe principal point has to be given in unit dimensions (e.g. 0.5 0.5)."
42+
"\n\nBUNDLE_FILE:"
43+
"\nCurrently only NVM bundle files (from VisualSFM, http://ccwu.me/vsfm/) are supported."
44+
"\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."
45+
"\n\nMVE_SCENE::EMBEDDING:"
46+
"\nThis is the scene representation we use in our research group: http://www.gris.tu-darmstadt.de/projects/multiview-environment/."
47+
"\n\nIN_MESH:"
48+
"\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/"
49+
"\n\nOUT_PREFIX:"
50+
"\nA path and name for the output files, e.g. <path>/<to>/my_textured_mesh"
51+
"\nDon't append an obj extension. The application does that itself because it outputs multiple files (mesh, material file, texture files)."
52+
"\n");
53+
args.add_option('D',"data_cost_file", true,
54+
"Skip calculation of data costs and use the ones provided in the given file");
55+
args.add_option('L',"labeling_file", true,
56+
"Skip view selection and use the labeling provided in the given file");
57+
args.add_option('d',"data_term", true,
58+
"Data term: {" +
59+
choices<tex::DataTerm>() + "} [" +
60+
choice_string<tex::DataTerm>(tex::DATA_TERM_GMI) + "]");
61+
args.add_option('s',"smoothness_term", true,
62+
"Smoothness term: {" +
63+
choices<tex::SmoothnessTerm>() + "} [" +
64+
choice_string<tex::SmoothnessTerm>(tex::SMOOTHNESS_TERM_POTTS) + "]");
65+
args.add_option('o',"outlier_removal", true,
66+
"Photometric outlier (pedestrians etc.) removal method: {" +
67+
choices<tex::OutlierRemoval>() + "} [" +
68+
choice_string<tex::OutlierRemoval>(tex::OUTLIER_REMOVAL_NONE) + "]");
69+
args.add_option('t',"tone_mapping", true,
70+
"Tone mapping method: {" +
71+
choices<tex::ToneMapping>() + "} [" +
72+
choice_string<tex::ToneMapping>(tex::TONE_MAPPING_NONE) + "]");
73+
args.add_option('v',"view_selection_model", false,
74+
"Write out view selection model [false]");
75+
args.add_option('\0', SKIP_GEOMETRIC_VISIBILITY_TEST, false,
76+
"Skip geometric visibility test based on ray intersection [false]");
77+
args.add_option('\0', SKIP_GLOBAL_SEAM_LEVELING, false,
78+
"Skip global seam leveling [false]");
79+
args.add_option('\0', SKIP_LOCAL_SEAM_LEVELING, false,
80+
"Skip local seam leveling (Poisson editing) [false]");
81+
args.add_option('\0', SKIP_HOLE_FILLING, false,
82+
"Skip hole filling [false]");
83+
args.add_option('\0', KEEP_UNSEEN_FACES, false,
84+
"Keep unseen faces [false]");
85+
args.add_option('\0', WRITE_TIMINGS, false,
86+
"Write out timings for each algorithm step (OUT_PREFIX + _timings.csv)");
87+
args.add_option('\0', NO_INTERMEDIATE_RESULTS, false,
88+
"Do not write out intermediate results");
89+
args.parse(argc, argv);
90+
91+
Arguments conf;
92+
conf.in_scene = args.get_nth_nonopt(0);
93+
conf.in_mesh = args.get_nth_nonopt(1);
94+
conf.out_prefix = util::fs::sanitize_path(args.get_nth_nonopt(2));
95+
96+
/* Set defaults for optional arguments. */
97+
conf.data_cost_file = "";
98+
conf.labeling_file = "";
99+
100+
conf.write_timings = false;
101+
conf.write_intermediate_results = true;
102+
conf.write_view_selection_model = false;
103+
104+
/* Handle optional arguments. */
105+
for (util::ArgResult const* i = args.next_option();
106+
i != 0; i = args.next_option()) {
107+
switch (i->opt->sopt) {
108+
case 'v':
109+
conf.write_view_selection_model = true;
110+
break;
111+
case 'D':
112+
conf.data_cost_file = i->arg;
113+
break;
114+
case 'L':
115+
conf.labeling_file = i->arg;
116+
break;
117+
case 'd':
118+
conf.settings.data_term = parse_choice<tex::DataTerm>(i->arg);
119+
break;
120+
case 's':
121+
conf.settings.smoothness_term = parse_choice<tex::SmoothnessTerm>(i->arg);
122+
break;
123+
case 'o':
124+
conf.settings.outlier_removal = parse_choice<tex::OutlierRemoval>(i->arg);
125+
break;
126+
case 't':
127+
conf.settings.tone_mapping = parse_choice<tex::ToneMapping>(i->arg);
128+
break;
129+
case '\0':
130+
if (i->opt->lopt == SKIP_GEOMETRIC_VISIBILITY_TEST) {
131+
conf.settings.geometric_visibility_test = false;
132+
} else if (i->opt->lopt == SKIP_GLOBAL_SEAM_LEVELING) {
133+
conf.settings.global_seam_leveling = false;
134+
} else if (i->opt->lopt == SKIP_LOCAL_SEAM_LEVELING) {
135+
conf.settings.local_seam_leveling = false;
136+
} else if (i->opt->lopt == SKIP_HOLE_FILLING) {
137+
conf.settings.hole_filling = false;
138+
} else if (i->opt->lopt == KEEP_UNSEEN_FACES) {
139+
conf.settings.keep_unseen_faces = true;
140+
} else if (i->opt->lopt == WRITE_TIMINGS) {
141+
conf.write_timings = true;
142+
} else if (i->opt->lopt == NO_INTERMEDIATE_RESULTS) {
143+
conf.write_intermediate_results = false;
144+
} else {
145+
throw std::invalid_argument("Invalid long option");
146+
}
147+
break;
148+
default:
149+
throw std::invalid_argument("Invalid short option");
150+
}
151+
}
152+
153+
return conf;
154+
}
155+
156+
std::string
157+
bool_to_string(bool b){
158+
return b ? "True" : "False";
159+
}
160+
161+
std::string
162+
Arguments::to_string(){
163+
std::stringstream out;
164+
out << "Input scene: \t" << in_scene << std::endl
165+
<< "Input mesh: \t" << in_mesh << std::endl
166+
<< "Output prefix: \t" << out_prefix << std::endl
167+
<< "Datacost file: \t" << data_cost_file << std::endl
168+
<< "Labeling file: \t" << labeling_file << std::endl
169+
<< "Data term: \t" << choice_string<tex::DataTerm>(settings.data_term) << std::endl
170+
<< "Smoothness term: \t" << choice_string<tex::SmoothnessTerm>(settings.smoothness_term) << std::endl
171+
<< "Outlier removal method: \t" << choice_string<tex::OutlierRemoval>(settings.outlier_removal) << std::endl
172+
<< "Tone mapping: \t" << choice_string<tex::ToneMapping>(settings.tone_mapping) << std::endl
173+
<< "Apply global seam leveling: \t" << bool_to_string(settings.global_seam_leveling) << std::endl
174+
<< "Apply local seam leveling: \t" << bool_to_string(settings.local_seam_leveling) << std::endl;
175+
176+
return out.str();
177+
}

0 commit comments

Comments
 (0)