#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define IGL_HEADER_ONLY #include #ifdef __APPLE__ # include #else # include #endif #include #include #include // Width and height of window int width,height; // Rotation of scene float scene_rot[4] = {0,0,0,1}; // information at mouse down float down_scene_rot[4] = {0,0,0,1}; bool trackball_on = false; int down_mouse_x,down_mouse_y; // Position of light float light_pos[4] = {0.1,0.1,-0.9,0}; // Vertex positions, normals, colors and centroid Eigen::MatrixXd V,N,sorted_N,C,mid; Eigen::VectorXi I; // Bounding box diagonal length double bbd; // Faces Eigen::MatrixXi F,sorted_F; // alpha double alpha = 0.2; #define REBAR_NAME "temp.rbr" igl::ReTwBar rebar; // Pointer to the tweak bar void reshape(int width,int height) { using namespace std; // Save width and height ::width = width; ::height = height; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0,0,width,height); } // Set up double-sided lights void lights() { using namespace std; glEnable(GL_LIGHTING); glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); float ones[4] = {1.0,1.0,1.0,1.0}; float zeros[4] = {0.0,0.0,0.0,0.0}; float pos[4]; copy(light_pos,light_pos+4,pos); glLightfv(GL_LIGHT0,GL_AMBIENT,zeros); glLightfv(GL_LIGHT0,GL_DIFFUSE,ones); glLightfv(GL_LIGHT0,GL_SPECULAR,zeros); glLightfv(GL_LIGHT0,GL_POSITION,pos); pos[0] *= -1; pos[1] *= -1; pos[2] *= -1; glLightfv(GL_LIGHT1,GL_AMBIENT,zeros); glLightfv(GL_LIGHT1,GL_DIFFUSE,ones); glLightfv(GL_LIGHT1,GL_SPECULAR,zeros); glLightfv(GL_LIGHT1,GL_POSITION,pos); } // Set up projection and model view of scene void push_scene() { using namespace igl; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPerspective(45,(double)width/(double)height,1e-2,20); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluLookAt(0,0,3,0,0,0,0,1,0); glPushMatrix(); float mat[4*4]; quat_to_mat(scene_rot,mat); glMultMatrixf(mat); } void pop_scene() { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopMatrix(); } // Scale and shift for object void push_object() { glPushMatrix(); glScaled(2./bbd,2./bbd,2./bbd); glTranslated(-mid(0,0),-mid(0,1),-mid(0,2)); } void pop_object() { glPopMatrix(); } void init_C(const Eigen::MatrixXi & F) { using namespace Eigen; using namespace igl; using namespace std; C.resize(F.rows(),3); for(int c = 0;c( width, height, 2, down_scene_rot, down_mouse_x, down_mouse_y, mouse_x, mouse_y, scene_rot); } } void key(unsigned char key, int mouse_x, int mouse_y) { using namespace Eigen; using namespace igl; using namespace std; switch(key) { // Ctrl-c and esc exit case char(3): case char(27): rebar.save(REBAR_NAME); exit(0); default: cout<<"Unknown key command: "< 1) { filename = argv[1]; } if(!read_triangle_mesh(filename,V,F)) { return 1; } // Compute normals, centroid, colors, bounding box diagonal per_face_normals(V,F,N); normalize_row_lengths(N,N); mid = 0.5*(V.colwise().maxCoeff() + V.colwise().minCoeff()); bbd = (V.colwise().maxCoeff() - V.colwise().minCoeff()).maxCoeff(); // Init glut glutInit(&argc,argv); if( !TwInit(TW_OPENGL, NULL) ) { // A fatal error occured fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError()); return 1; } // Create a tweak bar rebar.TwNewBar("TweakBar"); rebar.TwAddVarRW("scene_rot", TW_TYPE_QUAT4F, &scene_rot, ""); rebar.load(REBAR_NAME); glutInitDisplayString( "rgba depth double samples>=8 "); glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)); glutCreateWindow("sorted primitives transparency"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutMouseFunc(mouse); glutMotionFunc(mouse_drag); glutMainLoop(); return 0; }