int main(int argc, char** argv) { char filename[BUFFERSIZE]; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("render_cad_model"); /* filename of the off file */ sprintf(filename, "%s/%02d.off", argv[1], atoi(argv[2])); /* load off file */ load_off_file(&Nvertice, &Vertices, &Nface, &Faces, filename); printf("load off file done\n"); /* compute face normals */ Fnormals = compute_face_normals(Nvertice, Vertices, Nface, Faces); /* compute vertex normals */ Vnormals = compute_vertex_normals(Nvertice, Vertices, Nface, Faces, Fnormals); /* draw the CAD model */ glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }
/* matlab interface */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i; double *p; int argc = 1; char* argv[1]; argv[0] = ""; glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); glutInitWindowPosition(100, 100); glutCreateWindow("render_cad_model"); if (nrhs != 2) mexErrMsgTxt("Wrong number of inputs"); /* parse vertices and faces */ p = (double*)mxGetPr(prhs[0]); Nvertice = mxGetN(prhs[0]); Vertices = (GLdouble*)malloc(sizeof(GLdouble)*Nvertice*3); for(i = 0; i < 3*Nvertice; i++) Vertices[i] = (GLdouble)p[i]; p = (double*)mxGetPr(prhs[1]); Nface = mxGetN(prhs[1]); Faces = (GLuint*)malloc(sizeof(GLuint)*Nface*3); for(i = 0; i < 3*Nface; i++) Faces[i] = (GLuint)p[i]; /* compute face normals */ Fnormals = compute_face_normals(Nvertice, Vertices, Nface, Faces); /* compute vertex normals */ Vnormals = compute_vertex_normals(Nvertice, Vertices, Nface, Faces, Fnormals); /* draw the CAD model */ glutDisplayFunc(display); glutReshapeFunc(reshape); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); glutMainLoop(); return; }
void refine(std::vector<shape_ref_t> &triangles) { refine_to_triangles(triangles); compute_vertex_normals(triangles); }