This repository has been archived on 2024-12-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2024CG-project-render/quad_subdivision.cpp
github-classroom[bot] 5985bb8445
Initial commit
2024-10-24 10:26:51 +00:00

81 lines
2 KiB
C++

#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();
}