Doxygen Source Code Documentation
ply.h File Reference
#include <stdio.h>
#include <stddef.h>
Go to the source code of this file.
Data Structures | |
struct | OtherData |
struct | OtherElem |
struct | PlyElement |
struct | PlyFile |
struct | PlyOtherElems |
struct | PlyOtherProp |
struct | PlyProperty |
Defines | |
#define | PLY_ASCII 1 |
#define | PLY_BINARY_BE 2 |
#define | PLY_BINARY_LE 3 |
#define | PLY_OKAY 0 |
#define | PLY_ERROR -1 |
#define | PLY_START_TYPE 0 |
#define | PLY_CHAR 1 |
#define | PLY_SHORT 2 |
#define | PLY_INT 3 |
#define | PLY_UCHAR 4 |
#define | PLY_USHORT 5 |
#define | PLY_UINT 6 |
#define | PLY_FLOAT 7 |
#define | PLY_DOUBLE 8 |
#define | PLY_END_TYPE 9 |
#define | PLY_SCALAR 0 |
#define | PLY_LIST 1 |
#define | myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__) |
Typedefs | |
typedef PlyProperty | PlyProperty |
typedef PlyElement | PlyElement |
typedef PlyOtherProp | PlyOtherProp |
typedef OtherData | OtherData |
typedef OtherElem | OtherElem |
typedef PlyOtherElems | PlyOtherElems |
typedef PlyFile | PlyFile |
Functions | |
PlyFile * | ply_write (FILE *, int, char **, int) |
PlyFile * | ply_open_for_writing (char *, int, char **, int, float *) |
void | ply_describe_element (PlyFile *, char *, int, int, PlyProperty *) |
void | ply_describe_property (PlyFile *, char *, PlyProperty *) |
void | ply_element_count (PlyFile *, char *, int) |
void | ply_header_complete (PlyFile *) |
void | ply_put_element_setup (PlyFile *, char *) |
void | ply_put_element (PlyFile *, void *) |
void | ply_put_comment (PlyFile *, char *) |
void | ply_put_obj_info (PlyFile *, char *) |
PlyFile * | ply_read (FILE *, int *, char ***) |
PlyFile * | ply_open_for_reading (char *, int *, char ***, int *, float *) |
PlyProperty ** | ply_get_element_description (PlyFile *, char *, int *, int *) |
void | ply_get_element_setup (PlyFile *, char *, int, PlyProperty *) |
void | ply_get_property (PlyFile *, char *, PlyProperty *) |
PlyOtherProp * | ply_get_other_properties (PlyFile *, char *, int) |
void | ply_get_element (PlyFile *, void *) |
char ** | ply_get_comments (PlyFile *, int *) |
char ** | ply_get_obj_info (PlyFile *, int *) |
void | ply_close (PlyFile *) |
void | ply_get_info (PlyFile *, float *, int *) |
PlyOtherElems * | ply_get_other_element (PlyFile *, char *, int) |
void | ply_describe_other_elements (PlyFile *, PlyOtherElems *) |
void | ply_put_other_elements (PlyFile *) |
void | ply_free_other_elements (PlyOtherElems *) |
int | equal_strings (char *, char *) |
Define Documentation
|
|
Definition at line 43 of file ply.h. Referenced by ply_get_element(), ply_header_complete(), ply_put_element(), ply_read(), SUMA_Ply_Read(), SUMA_Ply_Write(), and write_test(). |
|
Definition at line 44 of file ply.h. Referenced by ply_header_complete(), ply_read(), SUMA_Ply_Read(), SUMA_Ply_Write(), and write_test(). |
|
Definition at line 45 of file ply.h. Referenced by ply_header_complete(), ply_read(), SUMA_Ply_Read(), and SUMA_Ply_Write(). |
|
Definition at line 53 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
Definition at line 60 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
Definition at line 61 of file ply.h. Referenced by get_prop_type(), and write_scalar_type(). |
|
|
|
Definition at line 59 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
Definition at line 55 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
|
|
|
|
|
|
Definition at line 54 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
Definition at line 52 of file ply.h. Referenced by get_prop_type(). |
|
Definition at line 56 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
Definition at line 58 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
|
Definition at line 57 of file ply.h. Referenced by get_ascii_item(), get_binary_item(), get_item_value(), get_stored_item(), old_write_ascii_item(), store_item(), write_ascii_item(), and write_binary_item(). |
Typedef Documentation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function Documentation
|
Definition at line 1398 of file plyfile.c.
|
|
Definition at line 1364 of file plyfile.c. References PlyFile::fp, and free. Referenced by read_test(), SUMA_Ply_Read(), SUMA_Ply_Write(), and write_test().
01365 { 01366 fclose (plyfile->fp); 01367 01368 /* free up memory associated with the PLY file */ 01369 free (plyfile); 01370 } |
|
Definition at line 241 of file plyfile.c. References copy_property(), find_element(), i, myalloc, NAMED_PROP, PlyElement::nprops, PlyElement::num, PlyElement::props, and PlyElement::store_prop.
00248 { 00249 int i; 00250 PlyElement *elem; 00251 PlyProperty *prop; 00252 00253 /* look for appropriate element */ 00254 elem = find_element (plyfile, elem_name); 00255 if (elem == NULL) { 00256 fprintf(stderr,"ply_describe_element: can't find element '%s'\n",elem_name); 00257 exit (-1); 00258 } 00259 00260 elem->num = nelems; 00261 00262 /* copy the list of properties */ 00263 00264 elem->nprops = nprops; 00265 elem->props = (PlyProperty **) myalloc (sizeof (PlyProperty *) * nprops); 00266 elem->store_prop = (char *) myalloc (sizeof (char) * nprops); 00267 00268 for (i = 0; i < nprops; i++) { 00269 prop = (PlyProperty *) myalloc (sizeof (PlyProperty)); 00270 elem->props[i] = prop; 00271 elem->store_prop[i] = NAMED_PROP; 00272 copy_property (prop, &prop_list[i]); 00273 } 00274 } |
|
Definition at line 1281 of file plyfile.c. References OtherElem::elem_count, OtherElem::elem_name, i, PlyOtherElems::num_elems, offsetof, PlyFile::other_elems, PlyOtherElems::other_list, OtherElem::other_props, ply_describe_other_properties(), and ply_element_count().
01285 { 01286 int i; 01287 OtherElem *other; 01288 01289 /* ignore this call if there is no other element */ 01290 if (other_elems == NULL) 01291 return; 01292 01293 /* save pointer to this information */ 01294 plyfile->other_elems = other_elems; 01295 01296 /* describe the other properties of this element */ 01297 01298 for (i = 0; i < other_elems->num_elems; i++) { 01299 other = &(other_elems->other_list[i]); 01300 ply_element_count (plyfile, other->elem_name, other->elem_count); 01301 ply_describe_other_properties (plyfile, other->other_props, 01302 offsetof(OtherData,other_props)); 01303 } 01304 } |
|
Definition at line 286 of file plyfile.c. References copy_property(), find_element(), myalloc, NAMED_PROP, PlyElement::nprops, PlyElement::props, realloc, and PlyElement::store_prop. Referenced by SUMA_Ply_Write(), and write_test().
00291 { 00292 PlyElement *elem; 00293 PlyProperty *elem_prop; 00294 00295 /* look for appropriate element */ 00296 elem = find_element (plyfile, elem_name); 00297 if (elem == NULL) { 00298 fprintf(stderr, "ply_describe_property: can't find element '%s'\n", 00299 elem_name); 00300 return; 00301 } 00302 00303 /* create room for new property */ 00304 00305 if (elem->nprops == 0) { 00306 elem->props = (PlyProperty **) myalloc (sizeof (PlyProperty *)); 00307 elem->store_prop = (char *) myalloc (sizeof (char)); 00308 elem->nprops = 1; 00309 } 00310 else { 00311 elem->nprops++; 00312 elem->props = (PlyProperty **) 00313 realloc (elem->props, sizeof (PlyProperty *) * elem->nprops); 00314 elem->store_prop = (char *) 00315 realloc (elem->store_prop, sizeof (char) * elem->nprops); 00316 } 00317 00318 /* copy the new property */ 00319 00320 elem_prop = (PlyProperty *) myalloc (sizeof (PlyProperty)); 00321 elem->props[elem->nprops - 1] = elem_prop; 00322 elem->store_prop[elem->nprops - 1] = NAMED_PROP; 00323 copy_property (elem_prop, prop); 00324 } |
|
Definition at line 392 of file plyfile.c. References find_element(), i, and PlyElement::num. Referenced by ply_describe_other_elements(), SUMA_Ply_Write(), and write_test().
00397 { 00398 int i; 00399 PlyElement *elem; 00400 PlyProperty *prop; 00401 00402 /* look for appropriate element */ 00403 elem = find_element (plyfile, elem_name); 00404 if (elem == NULL) { 00405 fprintf(stderr,"ply_element_count: can't find element '%s'\n",elem_name); 00406 exit (-1); 00407 } 00408 00409 elem->num = nelems; 00410 } |
|
Definition at line 1344 of file plyfile.c.
01345 { 01346 01347 } |
|
Definition at line 1011 of file plyfile.c. References PlyFile::comments, and PlyFile::num_comments. Referenced by read_test(), and SUMA_Ply_Read().
01012 {
01013 *num_comments = plyfile->num_comments;
01014 return (plyfile->comments);
01015 }
|
|
Definition at line 991 of file plyfile.c. References ascii_get_element(), binary_get_element(), PlyFile::file_type, and PLY_ASCII. Referenced by ply_get_other_element(), read_test(), and SUMA_Ply_Read().
00992 { 00993 if (plyfile->file_type == PLY_ASCII) 00994 ascii_get_element (plyfile, (char *) elem_ptr); 00995 else 00996 binary_get_element (plyfile, (char *) elem_ptr); 00997 } |
|
Definition at line 854 of file plyfile.c. References copy_property(), find_element(), i, myalloc, PlyElement::nprops, PlyElement::num, and PlyElement::props. Referenced by read_test(), and SUMA_Ply_Read().
00860 { 00861 int i; 00862 PlyElement *elem; 00863 PlyProperty *prop; 00864 PlyProperty **prop_list; 00865 00866 /* find information about the element */ 00867 elem = find_element (plyfile, elem_name); 00868 if (elem == NULL) 00869 return (NULL); 00870 00871 *nelems = elem->num; 00872 *nprops = elem->nprops; 00873 00874 /* make a copy of the element's property list */ 00875 prop_list = (PlyProperty **) myalloc (sizeof (PlyProperty *) * elem->nprops); 00876 for (i = 0; i < elem->nprops; i++) { 00877 prop = (PlyProperty *) myalloc (sizeof (PlyProperty)); 00878 copy_property (prop, elem->props[i]); 00879 prop_list[i] = prop; 00880 } 00881 00882 /* return this duplicate property list */ 00883 return (prop_list); 00884 } |
|
Definition at line 898 of file plyfile.c. References PlyProperty::count_internal, PlyProperty::count_offset, find_element(), find_property(), i, PlyProperty::internal_type, name, PlyProperty::offset, PlyElement::store_prop, STORE_PROP, and PlyFile::which_elem.
00904 { 00905 int i; 00906 PlyElement *elem; 00907 PlyProperty *prop; 00908 int index; 00909 00910 /* find information about the element */ 00911 elem = find_element (plyfile, elem_name); 00912 plyfile->which_elem = elem; 00913 00914 /* deposit the property information into the element's description */ 00915 for (i = 0; i < nprops; i++) { 00916 00917 /* look for actual property */ 00918 prop = find_property (elem, prop_list[i].name, &index); 00919 if (prop == NULL) { 00920 fprintf (stderr, "Warning: Can't find property '%s' in element '%s'\n", 00921 prop_list[i].name, elem_name); 00922 continue; 00923 } 00924 00925 /* store its description */ 00926 prop->internal_type = prop_list[i].internal_type; 00927 prop->offset = prop_list[i].offset; 00928 prop->count_internal = prop_list[i].count_internal; 00929 prop->count_offset = prop_list[i].count_offset; 00930 00931 /* specify that the user wants this property */ 00932 elem->store_prop[index] = STORE_PROP; 00933 } 00934 } |
|
Definition at line 1384 of file plyfile.c. References PlyFile::file_type, and PlyFile::version.
01385 { 01386 if (ply == NULL) 01387 return; 01388 01389 *version = ply->version; 01390 *file_type = ply->file_type; 01391 } |
|
Definition at line 1030 of file plyfile.c. References PlyFile::num_obj_info, and PlyFile::obj_info. Referenced by read_test(), and SUMA_Ply_Read().
01031 {
01032 *num_obj_info = plyfile->num_obj_info;
01033 return (plyfile->obj_info);
01034 }
|
|
Definition at line 1208 of file plyfile.c. References OtherElem::elem_count, OtherElem::elem_name, find_element(), i, malloc, myalloc, PlyOtherElems::num_elems, offsetof, OtherElem::other_data, PlyFile::other_elems, PlyOtherElems::other_list, OtherElem::other_props, ply_get_element(), ply_get_other_properties(), and realloc.
01213 { 01214 int i; 01215 PlyElement *elem; 01216 PlyOtherElems *other_elems; 01217 OtherElem *other; 01218 int num_elems; 01219 01220 /* look for appropriate element */ 01221 elem = find_element (plyfile, elem_name); 01222 if (elem == NULL) { 01223 fprintf (stderr, 01224 "ply_get_other_element: can't find element '%s'\n", elem_name); 01225 exit (-1); 01226 } 01227 01228 /* create room for the new "other" element, initializing the */ 01229 /* other data structure if necessary */ 01230 01231 if (plyfile->other_elems == NULL) { 01232 plyfile->other_elems = (PlyOtherElems *) myalloc (sizeof (PlyOtherElems)); 01233 other_elems = plyfile->other_elems; 01234 other_elems->other_list = (OtherElem *) myalloc (sizeof (OtherElem)); 01235 other = &(other_elems->other_list[0]); 01236 other_elems->num_elems = 1; 01237 } 01238 else { 01239 other_elems = plyfile->other_elems; 01240 other_elems->other_list = (OtherElem *) realloc (other_elems->other_list, 01241 sizeof (OtherElem) * other_elems->num_elems + 1); 01242 other = &(other_elems->other_list[other_elems->num_elems]); 01243 other_elems->num_elems++; 01244 } 01245 01246 /* count of element instances in file */ 01247 other->elem_count = elem_count; 01248 01249 /* save name of element */ 01250 other->elem_name = strdup (elem_name); 01251 01252 /* create a list to hold all the current elements */ 01253 other->other_data = (OtherData **) 01254 malloc (sizeof (OtherData *) * other->elem_count); 01255 01256 /* set up for getting elements */ 01257 other->other_props = ply_get_other_properties (plyfile, elem_name, 01258 offsetof(OtherData,other_props)); 01259 01260 /* grab all these elements */ 01261 for (i = 0; i < other->elem_count; i++) { 01262 /* grab and element from the file */ 01263 other->other_data[i] = (OtherData *) malloc (sizeof (OtherData)); 01264 ply_get_element (plyfile, (void *) other->other_data[i]); 01265 } 01266 01267 /* return pointer to the other elements data */ 01268 return (other_elems); 01269 } |
|
Definition at line 1119 of file plyfile.c. References copy_property(), find_element(), i, myalloc, PlyOtherProp::name, NO_OTHER_PROPS, PlyOtherProp::nprops, PlyElement::nprops, offset, PlyElement::other_offset, PlyElement::other_size, PlyOtherProp::props, PlyElement::props, setup_other_props(), PlyOtherProp::size, PlyElement::store_prop, and PlyFile::which_elem. Referenced by ply_get_other_element().
01124 { 01125 int i; 01126 PlyElement *elem; 01127 PlyOtherProp *other; 01128 PlyProperty *prop; 01129 int nprops; 01130 01131 /* find information about the element */ 01132 elem = find_element (plyfile, elem_name); 01133 if (elem == NULL) { 01134 fprintf (stderr, "ply_get_other_properties: Can't find element '%s'\n", 01135 elem_name); 01136 return (NULL); 01137 } 01138 01139 /* remember that this is the "current" element */ 01140 plyfile->which_elem = elem; 01141 01142 /* save the offset to where to store the other_props */ 01143 elem->other_offset = offset; 01144 01145 /* place the appropriate pointers, etc. in the element's property list */ 01146 setup_other_props (plyfile, elem); 01147 01148 /* create structure for describing other_props */ 01149 other = (PlyOtherProp *) myalloc (sizeof (PlyOtherProp)); 01150 other->name = strdup (elem_name); 01151 #if 0 01152 if (elem->other_offset == NO_OTHER_PROPS) { 01153 other->size = 0; 01154 other->props = NULL; 01155 other->nprops = 0; 01156 return (other); 01157 } 01158 #endif 01159 other->size = elem->other_size; 01160 other->props = (PlyProperty **) myalloc (sizeof(PlyProperty) * elem->nprops); 01161 01162 /* save descriptions of each "other" property */ 01163 nprops = 0; 01164 for (i = 0; i < elem->nprops; i++) { 01165 if (elem->store_prop[i]) 01166 continue; 01167 prop = (PlyProperty *) myalloc (sizeof (PlyProperty)); 01168 copy_property (prop, elem->props[i]); 01169 other->props[nprops] = prop; 01170 nprops++; 01171 } 01172 other->nprops = nprops; 01173 01174 #if 1 01175 /* set other_offset pointer appropriately if there are NO other properties */ 01176 if (other->nprops == 0) { 01177 elem->other_offset = NO_OTHER_PROPS; 01178 } 01179 #endif 01180 01181 /* return structure */ 01182 return (other); 01183 } |
|
Definition at line 949 of file plyfile.c. References PlyProperty::count_internal, PlyProperty::count_offset, find_element(), find_property(), PlyProperty::internal_type, PlyProperty::name, PlyProperty::offset, PlyElement::store_prop, STORE_PROP, and PlyFile::which_elem. Referenced by read_test(), and SUMA_Ply_Read().
00954 { 00955 PlyElement *elem; 00956 PlyProperty *prop_ptr; 00957 int index; 00958 00959 /* find information about the element */ 00960 elem = find_element (plyfile, elem_name); 00961 plyfile->which_elem = elem; 00962 00963 /* deposit the property information into the element's description */ 00964 00965 prop_ptr = find_property (elem, prop->name, &index); 00966 if (prop_ptr == NULL) { 00967 fprintf (stderr, "Warning: Can't find property '%s' in element '%s'\n", 00968 prop->name, elem_name); 00969 return; 00970 } 00971 prop_ptr->internal_type = prop->internal_type; 00972 prop_ptr->offset = prop->offset; 00973 prop_ptr->count_internal = prop->count_internal; 00974 prop_ptr->count_offset = prop->count_offset; 00975 00976 /* specify that the user wants this property */ 00977 elem->store_prop[index] = STORE_PROP; 00978 } |
|
Definition at line 421 of file plyfile.c. References PlyFile::comments, PlyProperty::count_external, PlyFile::elems, PlyProperty::external_type, PlyFile::file_type, PlyFile::fp, i, PlyProperty::is_list, PlyElement::name, PlyProperty::name, PlyFile::nelems, PlyElement::nprops, PlyElement::num, PlyFile::num_comments, PlyFile::num_obj_info, PlyFile::obj_info, PLY_ASCII, PLY_BINARY_BE, PLY_BINARY_LE, PlyElement::props, and write_scalar_type(). Referenced by SUMA_Ply_Write(), and write_test().
00422 { 00423 int i,j; 00424 FILE *fp = plyfile->fp; 00425 PlyElement *elem; 00426 PlyProperty *prop; 00427 00428 fprintf (fp, "ply\n"); 00429 00430 switch (plyfile->file_type) { 00431 case PLY_ASCII: 00432 fprintf (fp, "format ascii 1.0\n"); 00433 break; 00434 case PLY_BINARY_BE: 00435 fprintf (fp, "format binary_big_endian 1.0\n"); 00436 break; 00437 case PLY_BINARY_LE: 00438 fprintf (fp, "format binary_little_endian 1.0\n"); 00439 break; 00440 default: 00441 fprintf (stderr, "ply_header_complete: bad file type = %d\n", 00442 plyfile->file_type); 00443 exit (-1); 00444 } 00445 00446 /* write out the comments */ 00447 00448 for (i = 0; i < plyfile->num_comments; i++) 00449 fprintf (fp, "comment %s\n", plyfile->comments[i]); 00450 00451 /* write out object information */ 00452 00453 for (i = 0; i < plyfile->num_obj_info; i++) 00454 fprintf (fp, "obj_info %s\n", plyfile->obj_info[i]); 00455 00456 /* write out information about each element */ 00457 00458 for (i = 0; i < plyfile->nelems; i++) { 00459 00460 elem = plyfile->elems[i]; 00461 fprintf (fp, "element %s %d\n", elem->name, elem->num); 00462 00463 /* write out each property */ 00464 for (j = 0; j < elem->nprops; j++) { 00465 prop = elem->props[j]; 00466 if (prop->is_list) { 00467 fprintf (fp, "property list "); 00468 write_scalar_type (fp, prop->count_external); 00469 fprintf (fp, " "); 00470 write_scalar_type (fp, prop->external_type); 00471 fprintf (fp, " %s\n", prop->name); 00472 } 00473 else { 00474 fprintf (fp, "property "); 00475 write_scalar_type (fp, prop->external_type); 00476 fprintf (fp, " %s\n", prop->name); 00477 } 00478 } 00479 } 00480 00481 fprintf (fp, "end_header\n"); 00482 } |
|
Definition at line 800 of file plyfile.c. References elem_names, PlyFile::file_type, myalloc, name, ply_read(), and PlyFile::version. Referenced by read_test(), and SUMA_Ply_Read().
00807 { 00808 FILE *fp; 00809 PlyFile *plyfile; 00810 char *name; 00811 00812 /* tack on the extension .ply, if necessary */ 00813 00814 name = (char *) myalloc (sizeof (char) * (strlen (filename) + 5)); 00815 strcpy (name, filename); 00816 if (strlen (name) < 4 || 00817 strcmp (name + strlen (name) - 4, ".ply") != 0) 00818 strcat (name, ".ply"); 00819 00820 /* open the file for reading */ 00821 00822 fp = fopen (name, "r"); 00823 if (fp == NULL) 00824 return (NULL); 00825 00826 /* create the PlyFile data structure */ 00827 00828 plyfile = ply_read (fp, nelems, elem_names); 00829 00830 /* determine the file type and version */ 00831 00832 *file_type = plyfile->file_type; 00833 *version = plyfile->version; 00834 00835 /* return a pointer to the file's information */ 00836 00837 return (plyfile); 00838 } |
|
Definition at line 186 of file plyfile.c. References elem_names, i, myalloc, name, ply_write(), and PlyFile::version. Referenced by SUMA_Ply_Write(), and write_test().
00193 { 00194 int i; 00195 PlyFile *plyfile; 00196 PlyElement *elem; 00197 char *name; 00198 FILE *fp; 00199 00200 /* tack on the extension .ply, if necessary */ 00201 00202 name = (char *) myalloc (sizeof (char) * (strlen (filename) + 5)); 00203 strcpy (name, filename); 00204 if (strlen (name) < 4 || 00205 strcmp (name + strlen (name) - 4, ".ply") != 0) 00206 strcat (name, ".ply"); 00207 00208 /* open the file for writing */ 00209 00210 fp = fopen (name, "w"); 00211 if (fp == NULL) { 00212 return (NULL); 00213 } 00214 00215 /* create the actual PlyFile structure */ 00216 00217 plyfile = ply_write (fp, nelems, elem_names, file_type); 00218 if (plyfile == NULL) 00219 return (NULL); 00220 00221 /* say what PLY file version number we're writing */ 00222 *version = plyfile->version; 00223 00224 /* return pointer to the file descriptor */ 00225 return (plyfile); 00226 } |
|
Definition at line 631 of file plyfile.c. References PlyFile::comments, myalloc, PlyFile::num_comments, and realloc. Referenced by add_comment(), SUMA_Ply_Write(), and write_test().
00632 { 00633 /* (re)allocate space for new comment */ 00634 if (plyfile->num_comments == 0) 00635 plyfile->comments = (char **) myalloc (sizeof (char *)); 00636 else 00637 plyfile->comments = (char **) realloc (plyfile->comments, 00638 sizeof (char *) * (plyfile->num_comments + 1)); 00639 00640 /* add comment to list */ 00641 plyfile->comments[plyfile->num_comments] = strdup (comment); 00642 plyfile->num_comments++; 00643 } |
|
Definition at line 518 of file plyfile.c. References PlyProperty::count_external, PlyProperty::count_internal, PlyProperty::count_offset, PlyProperty::external_type, PlyFile::file_type, PlyFile::fp, get_stored_item(), i, PlyProperty::internal_type, PlyProperty::is_list, PlyElement::nprops, PlyProperty::offset, PlyElement::other_offset, OTHER_PROP, PLY_ASCII, ply_type_size, PlyElement::props, PlyElement::store_prop, PlyFile::which_elem, write_ascii_item(), and write_binary_item(). Referenced by ply_put_other_elements(), SUMA_Ply_Write(), and write_test().
00519 { 00520 int i,j,k; 00521 FILE *fp = plyfile->fp; 00522 PlyElement *elem; 00523 PlyProperty *prop; 00524 char *elem_data,*item; 00525 char **item_ptr; 00526 int list_count; 00527 int item_size; 00528 int int_val; 00529 unsigned int uint_val; 00530 double double_val; 00531 char **other_ptr; 00532 00533 elem = plyfile->which_elem; 00534 elem_data = elem_ptr; 00535 other_ptr = (char **) (((char *) elem_ptr) + elem->other_offset); 00536 00537 /* write out either to an ascii or binary file */ 00538 00539 if (plyfile->file_type == PLY_ASCII) { 00540 00541 /* write an ascii file */ 00542 00543 /* write out each property of the element */ 00544 for (j = 0; j < elem->nprops; j++) { 00545 prop = elem->props[j]; 00546 if (elem->store_prop[j] == OTHER_PROP) 00547 elem_data = *other_ptr; 00548 else 00549 elem_data = elem_ptr; 00550 if (prop->is_list) { 00551 item = elem_data + prop->count_offset; 00552 get_stored_item ((void *) item, prop->count_internal, 00553 &int_val, &uint_val, &double_val); 00554 write_ascii_item (fp, int_val, uint_val, double_val, 00555 prop->count_external); 00556 list_count = uint_val; 00557 item_ptr = (char **) (elem_data + prop->offset); 00558 item = item_ptr[0]; 00559 item_size = ply_type_size[prop->internal_type]; 00560 for (k = 0; k < list_count; k++) { 00561 get_stored_item ((void *) item, prop->internal_type, 00562 &int_val, &uint_val, &double_val); 00563 write_ascii_item (fp, int_val, uint_val, double_val, 00564 prop->external_type); 00565 item += item_size; 00566 } 00567 } 00568 else { 00569 item = elem_data + prop->offset; 00570 get_stored_item ((void *) item, prop->internal_type, 00571 &int_val, &uint_val, &double_val); 00572 write_ascii_item (fp, int_val, uint_val, double_val, 00573 prop->external_type); 00574 } 00575 } 00576 00577 fprintf (fp, "\n"); 00578 } 00579 else { 00580 00581 /* write a binary file */ 00582 00583 /* write out each property of the element */ 00584 for (j = 0; j < elem->nprops; j++) { 00585 prop = elem->props[j]; 00586 if (elem->store_prop[j] == OTHER_PROP) 00587 elem_data = *other_ptr; 00588 else 00589 elem_data = elem_ptr; 00590 if (prop->is_list) { 00591 item = elem_data + prop->count_offset; 00592 item_size = ply_type_size[prop->count_internal]; 00593 get_stored_item ((void *) item, prop->count_internal, 00594 &int_val, &uint_val, &double_val); 00595 write_binary_item (fp, int_val, uint_val, double_val, 00596 prop->count_external); 00597 list_count = uint_val; 00598 item_ptr = (char **) (elem_data + prop->offset); 00599 item = item_ptr[0]; 00600 item_size = ply_type_size[prop->internal_type]; 00601 for (k = 0; k < list_count; k++) { 00602 get_stored_item ((void *) item, prop->internal_type, 00603 &int_val, &uint_val, &double_val); 00604 write_binary_item (fp, int_val, uint_val, double_val, 00605 prop->external_type); 00606 item += item_size; 00607 } 00608 } 00609 else { 00610 item = elem_data + prop->offset; 00611 item_size = ply_type_size[prop->internal_type]; 00612 get_stored_item ((void *) item, prop->internal_type, 00613 &int_val, &uint_val, &double_val); 00614 write_binary_item (fp, int_val, uint_val, double_val, 00615 prop->external_type); 00616 } 00617 } 00618 00619 } 00620 } |
|
Definition at line 494 of file plyfile.c. References find_element(), and PlyFile::which_elem. Referenced by ply_put_other_elements(), SUMA_Ply_Write(), and write_test().
00495 { 00496 PlyElement *elem; 00497 00498 elem = find_element (plyfile, elem_name); 00499 if (elem == NULL) { 00500 fprintf(stderr, "ply_elements_setup: can't find element '%s'\n", elem_name); 00501 exit (-1); 00502 } 00503 00504 plyfile->which_elem = elem; 00505 } |
|
Definition at line 655 of file plyfile.c. References myalloc, PlyFile::num_obj_info, PlyFile::obj_info, and realloc. Referenced by add_obj_info(), SUMA_Ply_Write(), and write_test().
00656 { 00657 /* (re)allocate space for new info */ 00658 if (plyfile->num_obj_info == 0) 00659 plyfile->obj_info = (char **) myalloc (sizeof (char *)); 00660 else 00661 plyfile->obj_info = (char **) realloc (plyfile->obj_info, 00662 sizeof (char *) * (plyfile->num_obj_info + 1)); 00663 00664 /* add info to list */ 00665 plyfile->obj_info[plyfile->num_obj_info] = strdup (obj_info); 00666 plyfile->num_obj_info++; 00667 } |
|
Definition at line 1314 of file plyfile.c. References OtherElem::elem_count, OtherElem::elem_name, i, PlyOtherElems::num_elems, OtherElem::other_data, PlyFile::other_elems, PlyOtherElems::other_list, ply_put_element(), and ply_put_element_setup().
01315 { 01316 int i,j; 01317 OtherElem *other; 01318 01319 /* make sure we have other elements to write */ 01320 if (plyfile->other_elems == NULL) 01321 return; 01322 01323 /* write out the data for each "other" element */ 01324 01325 for (i = 0; i < plyfile->other_elems->num_elems; i++) { 01326 01327 other = &(plyfile->other_elems->other_list[i]); 01328 ply_put_element_setup (plyfile, other->elem_name); 01329 01330 /* write out each instance of the current element */ 01331 for (j = 0; j < other->elem_count; j++) 01332 ply_put_element (plyfile, (void *) other->other_data[j]); 01333 } 01334 } |
|
Definition at line 693 of file plyfile.c. References add_comment(), add_element(), add_obj_info(), add_property(), PlyFile::comments, DONT_STORE_PROP, elem_names, PlyFile::elems, equal_strings(), PlyFile::file_type, PlyFile::fp, free, get_words(), i, myalloc, PlyFile::nelems, NO_OTHER_PROPS, PlyElement::nprops, PlyFile::num_comments, PlyFile::num_obj_info, PlyFile::obj_info, PlyFile::other_elems, PlyElement::other_offset, PLY_ASCII, PLY_BINARY_BE, PLY_BINARY_LE, PlyElement::store_prop, and PlyFile::version. Referenced by ply_open_for_reading().
00694 { 00695 int i,j; 00696 PlyFile *plyfile; 00697 int nwords; 00698 char **words; 00699 int found_format = 0; 00700 char **elist; 00701 PlyElement *elem; 00702 char *orig_line; 00703 00704 /* check for NULL file pointer */ 00705 if (fp == NULL) 00706 return (NULL); 00707 00708 /* create record for this object */ 00709 00710 plyfile = (PlyFile *) myalloc (sizeof (PlyFile)); 00711 plyfile->nelems = 0; 00712 plyfile->comments = NULL; 00713 plyfile->num_comments = 0; 00714 plyfile->obj_info = NULL; 00715 plyfile->num_obj_info = 0; 00716 plyfile->fp = fp; 00717 plyfile->other_elems = NULL; 00718 00719 /* read and parse the file's header */ 00720 00721 words = get_words (plyfile->fp, &nwords, &orig_line); 00722 if (!words || !equal_strings (words[0], "ply")) 00723 return (NULL); 00724 00725 while (words) { 00726 00727 /* parse words */ 00728 00729 if (equal_strings (words[0], "format")) { 00730 if (nwords != 3) 00731 return (NULL); 00732 if (equal_strings (words[1], "ascii")) 00733 plyfile->file_type = PLY_ASCII; 00734 else if (equal_strings (words[1], "binary_big_endian")) 00735 plyfile->file_type = PLY_BINARY_BE; 00736 else if (equal_strings (words[1], "binary_little_endian")) 00737 plyfile->file_type = PLY_BINARY_LE; 00738 else 00739 return (NULL); 00740 plyfile->version = atof (words[2]); 00741 found_format = 1; 00742 } 00743 else if (equal_strings (words[0], "element")) 00744 add_element (plyfile, words, nwords); 00745 else if (equal_strings (words[0], "property")) 00746 add_property (plyfile, words, nwords); 00747 else if (equal_strings (words[0], "comment")) 00748 add_comment (plyfile, orig_line); 00749 else if (equal_strings (words[0], "obj_info")) 00750 add_obj_info (plyfile, orig_line); 00751 else if (equal_strings (words[0], "end_header")) 00752 break; 00753 00754 /* free up words space */ 00755 free (words); 00756 00757 words = get_words (plyfile->fp, &nwords, &orig_line); 00758 } 00759 00760 /* create tags for each property of each element, to be used */ 00761 /* later to say whether or not to store each property for the user */ 00762 00763 for (i = 0; i < plyfile->nelems; i++) { 00764 elem = plyfile->elems[i]; 00765 elem->store_prop = (char *) myalloc (sizeof (char) * elem->nprops); 00766 for (j = 0; j < elem->nprops; j++) 00767 elem->store_prop[j] = DONT_STORE_PROP; 00768 elem->other_offset = NO_OTHER_PROPS; /* no "other" props by default */ 00769 } 00770 00771 /* set return values about the elements */ 00772 00773 elist = (char **) myalloc (sizeof (char *) * plyfile->nelems); 00774 for (i = 0; i < plyfile->nelems; i++) 00775 elist[i] = strdup (plyfile->elems[i]->name); 00776 00777 *elem_names = elist; 00778 *nelems = plyfile->nelems; 00779 00780 /* return a pointer to the file's information */ 00781 00782 return (plyfile); 00783 } |
|
Definition at line 130 of file plyfile.c. References elem_names, PlyFile::elems, PlyFile::file_type, PlyFile::fp, i, myalloc, PlyElement::name, PlyFile::nelems, PlyElement::nprops, PlyElement::num, PlyFile::num_comments, PlyFile::num_obj_info, PlyFile::other_elems, and PlyFile::version. Referenced by ply_open_for_writing().
00136 { 00137 int i; 00138 PlyFile *plyfile; 00139 PlyElement *elem; 00140 00141 /* check for NULL file pointer */ 00142 if (fp == NULL) 00143 return (NULL); 00144 00145 /* create a record for this object */ 00146 00147 plyfile = (PlyFile *) myalloc (sizeof (PlyFile)); 00148 plyfile->file_type = file_type; 00149 plyfile->num_comments = 0; 00150 plyfile->num_obj_info = 0; 00151 plyfile->nelems = nelems; 00152 plyfile->version = 1.0; 00153 plyfile->fp = fp; 00154 plyfile->other_elems = NULL; 00155 00156 /* tuck aside the names of the elements */ 00157 00158 plyfile->elems = (PlyElement **) myalloc (sizeof (PlyElement *) * nelems); 00159 for (i = 0; i < nelems; i++) { 00160 elem = (PlyElement *) myalloc (sizeof (PlyElement)); 00161 plyfile->elems[i] = elem; 00162 elem->name = strdup (elem_names[i]); 00163 elem->num = 0; 00164 elem->nprops = 0; 00165 } 00166 00167 /* return pointer to the file descriptor */ 00168 return (plyfile); 00169 } |