#include using namespace std; #include #include #include "PlyParser.h" #include "SceneGraph.h" #include "Mesh.h" namespace GtpVisibilityPreprocessor { // int facesPerMesh = 100000000; int facesPerMesh = 30; bool useRandomMaterial = false; bool indexVertices = true; /* user's vertex and face definitions for a polygonal object */ typedef struct Vertex { int id; float x,y,z; void *other_props; /* other properties */ } Vertex; typedef struct PlyFace { int id; unsigned char nverts; /* number of vertex indices in list */ int *verts; /* vertex index list */ void *other_props; /* other properties */ } PlyFace; char *elem_names[] = { /* list of the kinds of elements in the user's object */ "vertex", "face" }; PlyProperty vert_props[] = { /* list of property information for a vertex */ {"x", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,x), 0, 0, 0, 0}, {"y", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,y), 0, 0, 0, 0}, {"z", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,z), 0, 0, 0, 0} }; PlyProperty face_props[] = { /* list of property information for a face */ {"vertex_indices", PLY_INT, PLY_INT, offsetof(PlyFace,verts), 1, PLY_UCHAR, PLY_UCHAR, offsetof(PlyFace,nverts)} }; unsigned char has_fverts; static PlyFace **flist; bool PlyParser::ParseSingleFile(const string filename, SceneGraphNode *root) { /*** the PLY object ***/ int nverts; Vertex **vlist; PlyOtherElems *other_elements = NULL; PlyOtherProp *vert_other; int nelems; char **elist; int num_comments; char **comments; int num_obj_info; char **obj_info; int file_type; int i,j; PlyFile *ply; int nprops; int num_elems; PlyProperty **plist; char *elem_name; float version; /*** Read in the original PLY object ***/ FILE *file = fopen(filename.c_str(), "rb"); ply = ply_read (file, &nelems, &elist); ply_get_info (ply, &version, &file_type); int nfaces; for (i = 0; i < nelems; i++) { /* get the description of the first element */ elem_name = elist[i]; plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops); if (equal_strings ("vertex", elem_name)) { /* create a vertex list to hold all the vertices */ vlist = (Vertex **) malloc (sizeof (Vertex *) * num_elems); nverts = num_elems; /* set up for getting vertex elements */ ply_get_property (ply, elem_name, &vert_props[0]); ply_get_property (ply, elem_name, &vert_props[1]); ply_get_property (ply, elem_name, &vert_props[2]); vert_other = ply_get_other_properties (ply, elem_name, offsetof(Vertex,other_props)); /* grab all the vertex elements */ for (j = 0; j < num_elems; j++) { vlist[j] = (Vertex *) malloc (sizeof (Vertex)); ply_get_element (ply, (void *) vlist[j]); vlist[j]->id = j; // cout<<"("<x<<","<y<<","<z<<")"<name)) { ply_get_property (ply, elem_name, &face_props[0]); has_fverts = true; } } // face_other = ply_get_other_properties (ply, elem_name, // offsetof(Face,other_props)); /* test for necessary properties */ if (!has_fverts) { fprintf(stderr,"Faces must have vertex indices\n"); exit(-1); } /* grab all the face elements */ for (j = 0; j < num_elems; j++) { ALLOCN(flist[j], PlyFace, 1); ply_get_element (ply, (void *) flist[j]); flist[j]->id = j; // for (int k = 0; k < flist[j]->nverts; k++) // cout<verts[k]<<" "; // cout<