Initial commit
This commit is contained in:
commit
5985bb8445
64 changed files with 33142 additions and 0 deletions
81
quad_subdivision.cpp
Normal file
81
quad_subdivision.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "catmull_clark.h"
|
||||
#include "QuadViewer.h"
|
||||
#include <igl/readOBJ.h>
|
||||
//#include <igl/opengl/glfw/Viewer.h>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
// parse command line arguments
|
||||
std::string path_to_obj;
|
||||
if (argc == 2) {
|
||||
std::string args = argv[1];
|
||||
// check if ends with .obj
|
||||
if (args.size() > 4 && args.substr(args.size() - 3, 3) == "obj") {
|
||||
path_to_obj = args;
|
||||
}
|
||||
}
|
||||
if (argc != 2 || path_to_obj.empty()) {
|
||||
printf(
|
||||
"Error: received unexpected command line arguments. \n"
|
||||
"Correct usage: \n"
|
||||
" Linux: ./quad_subdivision <path to obj file> \n"
|
||||
" Windows: quad_subdivision.exe <path to obj file> \n"
|
||||
"For example: \n"
|
||||
" Linux: ./quad_subdivision ../data/cube.obj \n"
|
||||
" Windows: quad_subdivision.exe ../../../data/cube.obj \n"
|
||||
);
|
||||
return -1;
|
||||
}
|
||||
Eigen::MatrixXd V;
|
||||
Eigen::MatrixXi F;
|
||||
igl::readOBJ(path_to_obj,V,F);
|
||||
if(F.cols() != 4 || F.minCoeff()<0)
|
||||
{
|
||||
std::cerr<<"Error: only pure quad meshes supported."<<std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Remember original mesh
|
||||
Eigen::MatrixXd OV = V;
|
||||
Eigen::MatrixXi OF = F;
|
||||
bool show_lines = true;
|
||||
|
||||
QuadViewer v;
|
||||
std::cout<<R"(Usage:
|
||||
[space] apply Catmull-Clark subdivision
|
||||
3 apply Catmull-Clark subdivision 3 times
|
||||
R,r Reset to original mesh
|
||||
|
||||
)";
|
||||
v.set_mesh(V,F);
|
||||
v.callback_key_pressed = [&v,&V,&F,&OV,&OF,&show_lines](
|
||||
igl::opengl::glfw::Viewer & /*viewer*/,
|
||||
unsigned int key,
|
||||
int /*modifier*/
|
||||
)->bool
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
default:
|
||||
return false;
|
||||
case 'R':
|
||||
case 'r':
|
||||
// reset to input mesh
|
||||
V = OV;
|
||||
F = OF;
|
||||
v.set_mesh(V,F);
|
||||
break;
|
||||
case '3':
|
||||
// carry out three subdivisions
|
||||
catmull_clark(Eigen::MatrixXd(V),Eigen::MatrixXi(F),3,V,F);
|
||||
v.set_mesh(V,F);
|
||||
break;
|
||||
case ' ':
|
||||
// carry out one subdivision
|
||||
catmull_clark(Eigen::MatrixXd(V),Eigen::MatrixXi(F),1,V,F);
|
||||
v.set_mesh(V,F);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
v.launch();
|
||||
}
|
Reference in a new issue