-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (41 loc) · 1.19 KB
/
main.cpp
File metadata and controls
45 lines (41 loc) · 1.19 KB
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
#include <igl/readOFF.h>
#include <igl/unproject_onto_mesh.h>
#include <igl/opengl/glfw/Viewer.h>
#include <iostream>
int main(int argc, char *argv[])
{
// Mesh with per-face color
Eigen::MatrixXd V, C;
Eigen::MatrixXi F;
// Load a mesh in OFF format
igl::readOFF(TUTORIAL_SHARED_PATH "/fertility.off", V, F);
// Initialize white
C = Eigen::MatrixXd::Constant(F.rows(),3,1);
igl::opengl::glfw::Viewer viewer;
viewer.callback_mouse_down =
[&V,&F,&C](igl::opengl::glfw::Viewer& viewer, int, int)->bool
{
int fid;
Eigen::Vector3f bc;
// Cast a ray in the view direction starting from the mouse position
double x = viewer.current_mouse_x;
double y = viewer.core().viewport(3) - viewer.current_mouse_y;
if(igl::unproject_onto_mesh(Eigen::Vector2f(x,y), viewer.core().view,
viewer.core().proj, viewer.core().viewport, V, F, fid, bc))
{
// paint hit red
C.row(fid)<<1,0,0;
viewer.data().set_colors(C);
return true;
}
return false;
};
std::cout<<R"(Usage:
[click] Pick face on shape
)";
// Show mesh
viewer.data().set_mesh(V, F);
viewer.data().set_colors(C);
viewer.data().show_lines = false;
viewer.launch();
}