write_test() { int i,j; PlyFile *ply; int nelems; char **elist; int file_type; float version; int nverts = sizeof (verts) / sizeof (Vertex); int nfaces = sizeof (faces) / sizeof (Face); /* create the vertex index lists for the faces */ for (i = 0; i < nfaces; i++) faces[i].verts = vert_ptrs[i]; /* open either a binary or ascii PLY file for writing */ /* (the file will be called "test.ply" because the routines */ /* enforce the .ply filename extension) */ #if 1 ply = ply_open_for_writing("test", 2, elem_names, PLY_ASCII, &version); #else ply = ply_open_for_writing("test", 2, elem_names, PLY_BINARY_BE, &version); #endif /* describe what properties go into the vertex and face elements */ ply_element_count (ply, "vertex", nverts); ply_describe_property (ply, "vertex", &vert_props[0]); ply_describe_property (ply, "vertex", &vert_props[1]); ply_describe_property (ply, "vertex", &vert_props[2]); ply_element_count (ply, "face", nfaces); ply_describe_property (ply, "face", &face_props[0]); ply_describe_property (ply, "face", &face_props[1]); /* write a comment and an object information field */ ply_put_comment (ply, "author: Greg Turk"); ply_put_obj_info (ply, "random information"); /* we have described exactly what we will put in the file, so */ /* we are now done with the header info */ ply_header_complete (ply); /* set up and write the vertex elements */ ply_put_element_setup (ply, "vertex"); for (i = 0; i < nverts; i++) ply_put_element (ply, (void *) &verts[i]); /* set up and write the face elements */ ply_put_element_setup (ply, "face"); for (i = 0; i < nfaces; i++) ply_put_element (ply, (void *) &faces[i]); /* close the PLY file */ ply_close (ply); }
void write_file() { int i,j,k; PlyFile *ply; int num_elems; char *elem_name; /*** Write out the final PLY object ***/ ply = ply_write (stdout, nelems, elist, file_type); /* describe what properties go into the vertex and face elements */ ply_element_count (ply, "vertex", nverts); ply_describe_property (ply, "vertex", &vert_props[0]); ply_describe_property (ply, "vertex", &vert_props[1]); ply_describe_property (ply, "vertex", &vert_props[2]); ply_describe_property (ply, "vertex", &vert_props[3]); ply_describe_property (ply, "vertex", &vert_props[4]); ply_describe_property (ply, "vertex", &vert_props[5]); ply_describe_other_properties (ply, vert_other, offsetof(Vertex,other_props)); ply_element_count (ply, "face", nfaces); ply_describe_property (ply, "face", &face_props[0]); ply_describe_other_properties (ply, face_other, offsetof(Face,other_props)); ply_describe_other_elements (ply, other_elements); for (i = 0; i < num_comments; i++) ply_put_comment (ply, comments[i]); for (i = 0; i < num_obj_info; i++) ply_put_obj_info (ply, obj_info[i]); ply_header_complete (ply); /* set up and write the vertex elements */ ply_put_element_setup (ply, "vertex"); for (i = 0; i < nverts; i++) ply_put_element (ply, (void *) vlist[i]); /* set up and write the face elements */ ply_put_element_setup (ply, "face"); for (i = 0; i < nfaces; i++) ply_put_element (ply, (void *) flist[i]); ply_put_other_elements (ply); /* close the PLY file */ ply_close (ply); }