Doxygen Source Code Documentation
plytest.c File Reference
#include <stdio.h>
#include <math.h>
#include <ply.h>
Go to the source code of this file.
Data Structures | |
struct | Face |
struct | Vertex |
Typedefs | |
typedef Vertex | Vertex |
typedef Face | Face |
typedef int | Vertex_Indices [4] |
Functions | |
main () | |
write_test () | |
read_test () | |
Variables | |
Vertex | verts [] |
Face | faces [] |
Vertex_Indices | vert_ptrs [] |
char * | elem_names [] |
PlyProperty | vert_props [] |
PlyProperty | face_props [] |
Typedef Documentation
|
|
|
|
|
|
Function Documentation
|
Definition at line 84 of file plytest.c. References read_test(), and write_test().
00085 { 00086 00087 #if 1 00088 /* write a PLY file */ 00089 write_test(); 00090 #endif 00091 00092 #if 1 00093 /* read a PLY file */ 00094 read_test(); 00095 #endif 00096 00097 } |
|
Definition at line 167 of file plytest.c. References equal_strings(), i, malloc, name, Face::nverts, ply_close(), ply_get_comments(), ply_get_element(), ply_get_element_description(), ply_get_obj_info(), ply_get_property(), and ply_open_for_reading(). Referenced by main().
00168 { 00169 int i,j,k; 00170 PlyFile *ply; 00171 int nelems; 00172 char **elist; 00173 int file_type; 00174 float version; 00175 int nprops; 00176 int num_elems; 00177 PlyProperty **plist; 00178 Vertex **vlist; 00179 Face **flist; 00180 char *elem_name; 00181 int num_comments; 00182 char **comments; 00183 int num_obj_info; 00184 char **obj_info; 00185 00186 /* open a PLY file for reading */ 00187 ply = ply_open_for_reading("test", &nelems, &elist, &file_type, &version); 00188 00189 /* print what we found out about the file */ 00190 printf ("version %f\n", version); 00191 printf ("type %d\n", file_type); 00192 00193 /* go through each kind of element that we learned is in the file */ 00194 /* and read them */ 00195 00196 for (i = 0; i < nelems; i++) { 00197 00198 /* get the description of the first element */ 00199 elem_name = elist[i]; 00200 plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops); 00201 00202 /* print the name of the element, for debugging */ 00203 printf ("element %s %d\n", elem_name, num_elems); 00204 00205 /* if we're on vertex elements, read them in */ 00206 if (equal_strings ("vertex", elem_name)) { 00207 00208 /* create a vertex list to hold all the vertices */ 00209 vlist = (Vertex **) malloc (sizeof (Vertex *) * num_elems); 00210 00211 /* set up for getting vertex elements */ 00212 00213 ply_get_property (ply, elem_name, &vert_props[0]); 00214 ply_get_property (ply, elem_name, &vert_props[1]); 00215 ply_get_property (ply, elem_name, &vert_props[2]); 00216 00217 /* grab all the vertex elements */ 00218 for (j = 0; j < num_elems; j++) { 00219 00220 /* grab and element from the file */ 00221 vlist[j] = (Vertex *) malloc (sizeof (Vertex)); 00222 ply_get_element (ply, (void *) vlist[j]); 00223 00224 /* print out vertex x,y,z for debugging */ 00225 printf ("vertex: %g %g %g\n", vlist[j]->x, vlist[j]->y, vlist[j]->z); 00226 } 00227 } 00228 00229 /* if we're on face elements, read them in */ 00230 if (equal_strings ("face", elem_name)) { 00231 00232 /* create a list to hold all the face elements */ 00233 flist = (Face **) malloc (sizeof (Face *) * num_elems); 00234 00235 /* set up for getting face elements */ 00236 00237 ply_get_property (ply, elem_name, &face_props[0]); 00238 ply_get_property (ply, elem_name, &face_props[1]); 00239 00240 /* grab all the face elements */ 00241 for (j = 0; j < num_elems; j++) { 00242 00243 /* grab and element from the file */ 00244 flist[j] = (Face *) malloc (sizeof (Face)); 00245 ply_get_element (ply, (void *) flist[j]); 00246 00247 /* print out face info, for debugging */ 00248 printf ("face: %d, list = ", flist[j]->intensity); 00249 for (k = 0; k < flist[j]->nverts; k++) 00250 printf ("%d ", flist[j]->verts[k]); 00251 printf ("\n"); 00252 } 00253 } 00254 00255 /* print out the properties we got, for debugging */ 00256 for (j = 0; j < nprops; j++) 00257 printf ("property %s\n", plist[j]->name); 00258 } 00259 00260 /* grab and print out the comments in the file */ 00261 comments = ply_get_comments (ply, &num_comments); 00262 for (i = 0; i < num_comments; i++) 00263 printf ("comment = '%s'\n", comments[i]); 00264 00265 /* grab and print out the object information */ 00266 obj_info = ply_get_obj_info (ply, &num_obj_info); 00267 for (i = 0; i < num_obj_info; i++) 00268 printf ("obj_info = '%s'\n", obj_info[i]); 00269 00270 /* close the PLY file */ 00271 ply_close (ply); 00272 } |
|
Definition at line 104 of file plytest.c. References elem_names, i, PLY_ASCII, PLY_BINARY_BE, ply_close(), ply_describe_property(), ply_element_count(), ply_header_complete(), ply_open_for_writing(), ply_put_comment(), ply_put_element(), ply_put_element_setup(), ply_put_obj_info(), and vert_ptrs. Referenced by main().
00105 { 00106 int i,j; 00107 PlyFile *ply; 00108 int nelems; 00109 char **elist; 00110 int file_type; 00111 float version; 00112 int nverts = sizeof (verts) / sizeof (Vertex); 00113 int nfaces = sizeof (faces) / sizeof (Face); 00114 00115 /* create the vertex index lists for the faces */ 00116 for (i = 0; i < nfaces; i++) 00117 faces[i].verts = vert_ptrs[i]; 00118 00119 /* open either a binary or ascii PLY file for writing */ 00120 /* (the file will be called "test.ply" because the routines */ 00121 /* enforce the .ply filename extension) */ 00122 00123 #if 1 00124 ply = ply_open_for_writing("test", 2, elem_names, PLY_ASCII, &version); 00125 #else 00126 ply = ply_open_for_writing("test", 2, elem_names, PLY_BINARY_BE, &version); 00127 #endif 00128 00129 /* describe what properties go into the vertex and face elements */ 00130 00131 ply_element_count (ply, "vertex", nverts); 00132 ply_describe_property (ply, "vertex", &vert_props[0]); 00133 ply_describe_property (ply, "vertex", &vert_props[1]); 00134 ply_describe_property (ply, "vertex", &vert_props[2]); 00135 00136 ply_element_count (ply, "face", nfaces); 00137 ply_describe_property (ply, "face", &face_props[0]); 00138 ply_describe_property (ply, "face", &face_props[1]); 00139 00140 /* write a comment and an object information field */ 00141 ply_put_comment (ply, "author: Greg Turk"); 00142 ply_put_obj_info (ply, "random information"); 00143 00144 /* we have described exactly what we will put in the file, so */ 00145 /* we are now done with the header info */ 00146 ply_header_complete (ply); 00147 00148 /* set up and write the vertex elements */ 00149 ply_put_element_setup (ply, "vertex"); 00150 for (i = 0; i < nverts; i++) 00151 ply_put_element (ply, (void *) &verts[i]); 00152 00153 /* set up and write the face elements */ 00154 ply_put_element_setup (ply, "face"); 00155 for (i = 0; i < nfaces; i++) 00156 ply_put_element (ply, (void *) &faces[i]); 00157 00158 /* close the PLY file */ 00159 ply_close (ply); 00160 } |
Variable Documentation
|
Initial value: { "vertex", "face" } Definition at line 62 of file plytest.c. Referenced by ply_open_for_reading(), ply_open_for_writing(), ply_read(), ply_write(), SUMA_Ply_Write(), and write_test(). |
|
Initial value: |
|
Initial value: { { '\001', 4, NULL }, { '\004', 4, NULL }, { '\010', 4, NULL }, { '\020', 4, NULL }, { '\144', 4, NULL }, { '\377', 4, NULL }, } Definition at line 38 of file plytest.c. Referenced by drawBox(), and SUMA_Ply_Write(). |
|
Initial value: |
|
Initial value: { { 0, 1, 2, 3 }, { 7, 6, 5, 4 }, { 0, 4, 5, 1 }, { 1, 5, 6, 2 }, { 2, 6, 7, 3 }, { 3, 7, 4, 0 }, } Definition at line 51 of file plytest.c. Referenced by write_test(). |
|
Initial value: { { 0.0, 0.0, 0.0}, { 1.0, 0.0, 0.0}, { 1.0, 1.0, 0.0}, { 0.0, 1.0, 0.0}, { 0.0, 0.0, 1.0}, { 1.0, 0.0, 1.0}, { 1.0, 1.0, 1.0}, { 0.0, 1.0, 1.0}, } Definition at line 27 of file plytest.c. Referenced by SUMA_Ply_Read(), and SUMA_Ply_Write(). |