-
Notifications
You must be signed in to change notification settings - Fork 69
/
main.cpp
113 lines (109 loc) · 2.9 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "smooth.h"
#include <igl/read_triangle_mesh.h>
#include <igl/readDMAT.h>
#include <igl/parula.h>
#include <igl/opengl/glfw/Viewer.h>
#include <Eigen/Core>
#include <string>
#include <iostream>
int main(int argc, char *argv[])
{
// Load input meshes
Eigen::MatrixXd OV,V,U;
Eigen::MatrixXi F;
double lambda = 1e-5;
igl::read_triangle_mesh(
(argc>1?argv[1]:"../data/sphere-noisy.obj"),OV,F);
// Load data into MatrixXd rather than VectorXd for simpler `smooth` API
// Just use y-coordinates as data to be smoothed
Eigen::MatrixXd G = OV.col(1);
if(argc>2)
{
if(argv[2][0] == 'n')
{
// Corrupt with a bit of noise
G += 0.1*(G.maxCoeff()-G.minCoeff())*
Eigen::MatrixXd::Random(G.rows(),G.cols());
}else
{
igl::readDMAT(argv[2],G);
}
}
igl::opengl::glfw::Viewer viewer;
std::cout<<R"(
D,d smooth data
K decamate(?) lambda
k decimate lambda
L Toggle lighting
M,m smooth mesh geometry
R,r reset mesh geometry and data
L lighting
)";
const auto & update = [&]()
{
if((V.array() != V.array()).any())
{
std::cout<<"Too degenerate to keep smoothing. Better reset"<<std::endl;
}
viewer.data().set_mesh(V,F);
viewer.data().compute_normals();
Eigen::MatrixXd C;
igl::parula(U,G.minCoeff(),G.maxCoeff(),C);
viewer.data().set_colors(C);
};
const auto & reset = [&]()
{
V = OV;
U = G;
};
viewer.callback_key_pressed =
[&](igl::opengl::glfw::Viewer &, unsigned int key, int)
{
switch(key)
{
case 'D':
case 'd':
//////////////////////////////////////////////////////////////////////
// Smooth data
//////////////////////////////////////////////////////////////////////
// Use copy constructor to fake in-place API (may be overly
// conservative depending on your implementation)
smooth(V,F,Eigen::MatrixXd(U),lambda,U);
break;
case 'K':
case 'k':
lambda = (key=='K'?10.0:0.1)*lambda;
std::cout<<"lambda: "<<lambda<<std::endl;
break;
case 'L':
// Toggle lighting
viewer.core().lighting_factor = 1.0- viewer.core().lighting_factor;
break;
case 'M':
case 'm':
{
//////////////////////////////////////////////////////////////////////
// Smooth mesh geometry.
//////////////////////////////////////////////////////////////////////
// "Linearize" simply by conducting smooth step assuming that vertex
// data is a signal defined over current surface: copy is needed to
// prevent memory "aliasing"
Eigen::MatrixXd Vcpy(V);
smooth(Vcpy,F,Vcpy,lambda,V);
break;
}
case 'R':
case 'r':
reset();
break;
default:
return false;
}
update();
return true;
};
reset();
update();
viewer.launch();
return EXIT_SUCCESS;
}