86 char byte_values[
sizeof(int)];
93 #define NO_OTHER_PROPS -1
95 #define DONT_STORE_PROP 0
115 char **
get_words(FILE *,
int *,
char **);
133 void store_item(
char *,
int,
int,
unsigned int,
double);
142 void get_ascii_item(
char *,
int,
int *,
unsigned int *,
double *);
143 void get_binary_item(FILE *,
int,
int,
int *,
unsigned int *,
double *);
150 char *
my_alloc(
int,
int,
const char *);
179 const char **elem_names,
213 for (i = 0; i < nelems; i++) {
215 plyfile->
elems[i] = elem;
243 const char **elem_names,
256 if (strlen (
name) < 4 ||
257 strcmp (
name + strlen (
name) - 4,
".ply") != 0)
258 strcat (
name,
".ply");
262 fp = fopen (
name,
"wb");
309 fprintf(stderr,
"ply_describe_element: can't find element '%s'\n",elem_name);
321 for (i = 0; i < nprops; i++) {
323 elem->
props[i] = prop;
341 const char *elem_name,
351 fprintf(stderr,
"ply_describe_property: can't find element '%s'\n",
398 fprintf(stderr,
"ply_describe_other_properties: can't find element '%s'\n",
417 realloc (elem->
store_prop, sizeof (
char) * newsize);
422 for (i = 0; i < other->
nprops; i++) {
447 const char *elem_name,
456 fprintf(stderr,
"ply_element_count: can't find element '%s'\n",elem_name);
475 FILE *fp = plyfile->
fp;
479 fprintf (fp,
"ply\n");
483 fprintf (fp,
"format ascii 1.0\n");
486 fprintf (fp,
"format binary_big_endian 1.0\n");
489 fprintf (fp,
"format binary_little_endian 1.0\n");
492 fprintf (stderr,
"ply_header_complete: bad file type = %d\n",
500 fprintf (fp,
"comment %s\n", plyfile->
comments[i]);
505 fprintf (fp,
"obj_info %s\n", plyfile->
obj_info[i]);
509 for (i = 0; i < plyfile->
nelems; i++) {
511 elem = plyfile->
elems[i];
512 fprintf (fp,
"element %s %d\n", elem->
name, elem->
num);
515 for (j = 0; j < elem->
nprops; j++) {
516 prop = elem->
props[j];
518 fprintf (fp,
"property list ");
522 fprintf (fp,
" %s\n", prop->
name);
525 fprintf (fp,
"property ");
527 fprintf (fp,
" %s\n", prop->
name);
532 fprintf (fp,
"end_header\n");
551 fprintf(stderr,
"ply_elements_setup: can't find element '%s'\n", elem_name);
572 FILE *fp = plyfile->
fp;
575 char *elem_data,*item;
580 unsigned int uint_val;
585 elem_data = (
char *)elem_ptr;
586 other_ptr = (
char **) (((
char *) elem_ptr) + elem->
other_offset);
595 for (j = 0; j < elem->
nprops; j++) {
596 prop = elem->
props[j];
598 elem_data = *other_ptr;
600 elem_data = (
char *)elem_ptr;
604 &int_val, &uint_val, &double_val);
607 list_count = uint_val;
608 item_ptr = (
char **) (elem_data + prop->
offset);
611 for (k = 0; k < list_count; k++) {
613 &int_val, &uint_val, &double_val);
620 item = elem_data + prop->
offset;
622 &int_val, &uint_val, &double_val);
635 for (j = 0; j < elem->
nprops; j++) {
636 prop = elem->
props[j];
638 elem_data = *other_ptr;
640 elem_data = (
char *)elem_ptr;
645 &int_val, &uint_val, &double_val);
648 list_count = uint_val;
649 item_ptr = (
char **) (elem_data + prop->
offset);
652 for (k = 0; k < list_count; k++) {
654 &int_val, &uint_val, &double_val);
661 item = elem_data + prop->
offset;
664 &int_val, &uint_val, &double_val);
774 words =
get_words (plyfile->
fp, &nwords, &orig_line);
799 plyfile->
version = (float)atof (words[2]);
817 words =
get_words (plyfile->
fp, &nwords, &orig_line);
823 for (i = 0; i < plyfile->
nelems; i++) {
824 elem = plyfile->
elems[i];
826 for (j = 0; j < elem->
nprops; j++)
833 elist = (
char **)
myalloc (
sizeof (
char *) * plyfile->
nelems);
834 for (i = 0; i < plyfile->
nelems; i++)
838 *nelems = plyfile->
nelems;
876 if (strlen (
name) < 4 ||
877 strcmp (
name + strlen (
name) - 4,
".ply") != 0)
878 strcat (
name,
".ply");
882 fp = fopen (
name,
"rb");
937 for (i = 0; i < elem->
nprops; i++) {
976 for (i = 0; i < nprops; i++) {
981 fprintf (stderr,
"Warning: Can't find property '%s' in element '%s'\n",
982 prop_list[i].
name, elem_name);
1027 if (prop_ptr ==
NULL) {
1122 for (type_size = 8; type_size > 0; type_size /= 2) {
1127 for (i = 0; i < elem->
nprops; i++) {
1133 prop = elem->
props[i];
1143 if (type_size ==
sizeof (
void *)) {
1145 size +=
sizeof (
void *);
1197 fprintf (stderr,
"ply_get_other_properties: Can't find element '%s'\n",
1219 for (i = 0; i < elem->
nprops; i++) {
1224 other->
props[nprops] = prop;
1230 if (other->
nprops == 0) {
1276 "ply_get_other_element: can't find element '%s'\n", elem_name);
1320 return (other_elems);
1343 if (other_elems ==
NULL)
1355 for (i = 0; i < other_elems->
num_elems; i++) {
1407 other_elems = other_elems;
1427 fclose (plyfile->
fp);
1488 for (i = 0; i < plyfile->
nelems; i++)
1490 return (plyfile->
elems[i]);
1512 for (i = 0; i < elem->
nprops; i++)
1515 return (elem->
props[i]);
1539 char *elem_data,*item=
NULL;
1543 unsigned int uint_val;
1549 char *other_data=
NULL;
1571 words =
get_words (plyfile->
fp, &nwords, &orig_line);
1572 if (words ==
NULL) {
1573 fprintf (stderr,
"ply_get_element: unexpected end of file\n");
1579 for (j = 0; j < elem->
nprops; j++) {
1581 prop = elem->
props[j];
1582 store_it = (elem->
store_prop[j] | other_flag);
1586 elem_data = elem_ptr;
1588 elem_data = other_data;
1594 &int_val, &uint_val, &double_val);
1601 list_count = int_val;
1603 store_array = (
char **) (elem_data + prop->
offset);
1605 if (list_count == 0) {
1607 *store_array =
NULL;
1611 item_ptr = (
char *)
myalloc (
sizeof (
char) * item_size * list_count);
1613 *store_array = item_ptr;
1617 for (k = 0; k < list_count; k++) {
1619 &int_val, &uint_val, &double_val);
1622 int_val, uint_val, double_val);
1631 &int_val, &uint_val, &double_val);
1633 item = elem_data + prop->
offset;
1657 FILE *fp = plyfile->
fp;
1658 char *elem_data,*item=
NULL;
1662 unsigned int uint_val;
1667 char *other_data=
NULL;
1689 for (j = 0; j < elem->
nprops; j++) {
1691 prop = elem->
props[j];
1692 store_it = (elem->
store_prop[j] | other_flag);
1696 elem_data = elem_ptr;
1698 elem_data = other_data;
1704 &int_val, &uint_val, &double_val);
1711 list_count = int_val;
1713 store_array = (
char **) (elem_data + prop->
offset);
1714 if (list_count == 0) {
1716 *store_array =
NULL;
1720 item_ptr = (
char *)
myalloc (
sizeof (
char) * item_size * list_count);
1722 *store_array = item_ptr;
1726 for (k = 0; k < list_count; k++) {
1728 &int_val, &uint_val, &double_val);
1731 int_val, uint_val, double_val);
1740 &int_val, &uint_val, &double_val);
1742 item = elem_data + prop->
offset;
1764 fprintf (stderr,
"write_scalar_type: bad data code = %d\n", code);
1787 for (i=0; i < num_bytes/2; i++)
1791 bytes[(num_bytes-1)-i] = temp;
1816 fprintf(stderr,
"ply: Couldn't determine machine endianness.\n");
1817 fprintf(stderr,
"ply: Exiting...\n");
1839 fprintf(stderr,
"ply: Type sizes do not match built-in types\n");
1840 fprintf(stderr,
"ply: Exiting...\n");
1864 #define BIG_STRING 4096
1873 words = (
char **)
myalloc (
sizeof (
char *) * max_words);
1890 for (ptr = str, ptr2 = str_copy; *ptr !=
'\0'; ptr++, ptr2++) {
1893 if (*ptr ==
'\t' || *ptr ==
'\r') {
1897 else if (*ptr ==
'\n') {
1907 while (*ptr !=
'\0') {
1918 if (num_words >= max_words) {
1920 words = (
char **) realloc (words,
sizeof (
char *) * max_words);
1922 words[num_words++] = ptr;
1933 *nwords = num_words;
1934 *orig_line = str_copy;
1952 unsigned char *puchar;
1955 unsigned short int *pushort;
1957 unsigned int *puint;
1961 unsigned int uint_value;
1962 double double_value;
1967 pchar = (
char *) item;
1969 return ((
double) int_value);
1972 puchar = (
unsigned char *) item;
1973 int_value = *puchar;
1974 return ((
double) int_value);
1977 pshort = (
short int *) item;
1978 int_value = *pshort;
1979 return ((
double) int_value);
1982 pushort = (
unsigned short int *) item;
1983 int_value = *pushort;
1984 return ((
double) int_value);
1987 pint = (
int *) item;
1989 return ((
double) int_value);
1992 puint = (
unsigned int *) item;
1993 uint_value = *puint;
1994 return ((
double) uint_value);
1997 pfloat = (
float *) item;
1998 double_value = *pfloat;
1999 return (double_value);
2002 pdouble = (
double *) item;
2003 double_value = *pdouble;
2004 return (double_value);
2006 fprintf (stderr,
"get_item_value: bad type = %d\n",
type);
2027 unsigned int uint_val,
2032 unsigned char uchar_val;
2034 unsigned short ushort_val;
2042 char_val = char(int_val);
2047 short_val = short(int_val);
2056 uchar_val = (
unsigned char)(uint_val);
2061 ushort_val = (
unsigned short)(uint_val);
2062 value = &ushort_val;
2070 float_val = (float)double_val;
2075 value = &double_val;
2078 fprintf (stderr,
"write_binary_item: bad type = %d\n",
type);
2088 fprintf(stderr,
"PLY ERROR: fwrite() failed -- aborting.\n");
2108 unsigned int uint_val,
2120 if (fprintf (fp,
"%d ", int_val) <= 0)
2122 fprintf(stderr,
"PLY ERROR: fprintf() failed -- aborting.\n");
2133 if (fprintf (fp,
"%u ", uint_val) <= 0)
2135 fprintf(stderr,
"PLY ERROR: fprintf() failed -- aborting.\n");
2143 if (fprintf (fp,
"%g ", double_val) <= 0)
2145 fprintf(stderr,
"PLY ERROR: fprintf() failed -- aborting.\n");
2150 fprintf (stderr,
"write_ascii_item: bad type = %d\n",
type);
2170 unsigned char *puchar;
2173 unsigned short int *pushort;
2175 unsigned int *puint;
2179 unsigned int uint_value;
2180 double double_value;
2185 pchar = (
char *) item;
2187 fprintf (fp,
"%d ", int_value);
2188 return ((
double) int_value);
2191 puchar = (
unsigned char *) item;
2192 int_value = *puchar;
2193 fprintf (fp,
"%d ", int_value);
2194 return ((
double) int_value);
2197 pshort = (
short int *) item;
2198 int_value = *pshort;
2199 fprintf (fp,
"%d ", int_value);
2200 return ((
double) int_value);
2203 pushort = (
unsigned short int *) item;
2204 int_value = *pushort;
2205 fprintf (fp,
"%d ", int_value);
2206 return ((
double) int_value);
2209 pint = (
int *) item;
2211 fprintf (fp,
"%d ", int_value);
2212 return ((
double) int_value);
2215 puint = (
unsigned int *) item;
2216 uint_value = *puint;
2217 fprintf (fp,
"%u ", uint_value);
2218 return ((
double) uint_value);
2221 pfloat = (
float *) item;
2222 double_value = *pfloat;
2223 fprintf (fp,
"%g ", double_value);
2224 return (double_value);
2227 pdouble = (
double *) item;
2228 double_value = *pdouble;
2229 fprintf (fp,
"%g ", double_value);
2230 return (double_value);
2232 fprintf (stderr,
"old_write_ascii_item: bad type = %d\n",
type);
2256 unsigned int *uint_val,
2263 *int_val = *((
char *) ptr);
2264 *uint_val = *int_val;
2265 *double_val = *int_val;
2269 *uint_val = *((
unsigned char *) ptr);
2270 *int_val = *uint_val;
2271 *double_val = *uint_val;
2275 *int_val = *((
short int *) ptr);
2276 *uint_val = *int_val;
2277 *double_val = *int_val;
2281 *uint_val = *((
unsigned short int *) ptr);
2282 *int_val = *uint_val;
2283 *double_val = *uint_val;
2287 *int_val = *((
int *) ptr);
2288 *uint_val = *int_val;
2289 *double_val = *int_val;
2293 *uint_val = *((
unsigned int *) ptr);
2294 *int_val = *uint_val;
2295 *double_val = *uint_val;
2299 *double_val = *((
float *) ptr);
2300 *int_val = (int) *double_val;
2301 *uint_val = (
unsigned int) *double_val;
2305 *double_val = *((
double *) ptr);
2306 *int_val = (int) *double_val;
2307 *uint_val = (
unsigned int) *double_val;
2310 fprintf (stderr,
"get_stored_item: bad type = %d\n",
type);
2335 unsigned int *uint_val,
2346 fprintf(stderr,
"PLY ERROR: fread() failed -- aborting.\n");
2357 *int_val = *((
char *) ptr);
2358 *uint_val = *int_val;
2359 *double_val = *int_val;
2363 *uint_val = *((
unsigned char *) ptr);
2364 *int_val = *uint_val;
2365 *double_val = *uint_val;
2369 *int_val = *((
short int *) ptr);
2370 *uint_val = *int_val;
2371 *double_val = *int_val;
2375 *uint_val = *((
unsigned short int *) ptr);
2376 *int_val = *uint_val;
2377 *double_val = *uint_val;
2381 *int_val = *((
int *) ptr);
2382 *uint_val = *int_val;
2383 *double_val = *int_val;
2387 *uint_val = *((
unsigned int *) ptr);
2388 *int_val = *uint_val;
2389 *double_val = *uint_val;
2393 *double_val = *((
float *) ptr);
2394 *int_val = (int) *double_val;
2395 *uint_val = (
unsigned int) *double_val;
2399 *double_val = *((
double *) ptr);
2400 *int_val = (int) *double_val;
2401 *uint_val = (
unsigned int) *double_val;
2404 fprintf (stderr,
"get_binary_item: bad type = %d\n",
type);
2428 unsigned int *uint_val,
2443 *int_val = atoi (word);
2444 *uint_val = (
unsigned int) *int_val;
2445 *double_val = (double) *int_val;
2450 *uint_val = strtol (word, (
char **)
NULL, 10);
2451 *int_val = (int) *uint_val;
2452 *double_val = (double) *uint_val;
2459 *double_val = atof (word);
2460 *int_val = (int) *double_val;
2461 *uint_val = (
unsigned int) *double_val;
2465 fprintf (stderr,
"get_ascii_item: bad type = %d\n",
type);
2489 unsigned int uint_val,
2493 unsigned char *puchar;
2495 unsigned short int *pushort;
2497 unsigned int *puint;
2505 *item = char(int_val);
2509 puchar = (
unsigned char *) item;
2510 *puchar = (
unsigned char)(uint_val);
2514 pshort = (
short *) item;
2515 *pshort = short(int_val);
2519 pushort = (
unsigned short *) item;
2520 *pushort = (
unsigned short)(uint_val);
2524 pint = (
int *) item;
2529 puint = (
unsigned int *) item;
2534 pfloat = (
float *) item;
2535 *pfloat = (float)double_val;
2539 pdouble = (
double *) item;
2540 *pdouble = double_val;
2543 fprintf (stderr,
"store_item: bad type = %d\n",
type);
2565 elem->
num = atoi (words[2]);
2569 if (plyfile->
nelems == 0)
2663 while (line[i] ==
' ' || line[i] ==
'\t')
2684 while (line[i] ==
' ' || line[i] ==
'\t')
2722 ptr = (
char *) malloc (
size);
2725 fprintf(stderr,
"Memory allocation bombed on line %d in %s\n", lnum, fname);
void store_item(char *, int, int, unsigned int, double)
void write_ascii_item(FILE *, int, unsigned int, double, int)
void swap_bytes(char *, int)
void ply_free_other_elements(PlyOtherElems *other_elems)
PlyFile * ply_open_for_writing(char *filename, int nelems, const char **elem_names, int file_type, float *version)
void ply_element_count(PlyFile *plyfile, const char *elem_name, int nelems)
void ply_describe_element(PlyFile *plyfile, char *elem_name, int nelems, int nprops, PlyProperty *prop_list)
char ** get_words(FILE *, int *, char **)
char ** ply_get_obj_info(PlyFile *plyfile, int *num_obj_info)
void ply_put_element(PlyFile *plyfile, void *elem_ptr)
void ply_describe_other_properties(PlyFile *plyfile, PlyOtherProp *other, int offset)
PlyElement * find_element(PlyFile *, const char *)
void ply_describe_other_elements(PlyFile *plyfile, PlyOtherElems *other_elems)
PlyOtherElems * ply_get_other_element(PlyFile *plyfile, char *elem_name, int elem_count)
void ply_put_obj_info(PlyFile *plyfile, char *obj_info)
int get_prop_type(char *type_name)
void get_native_binary_type()
void get_stored_item(void *, int, int *, unsigned int *, double *)
int ply_get_property(PlyFile *plyfile, char *elem_name, PlyProperty *prop)
void ply_get_element_setup(PlyFile *plyfile, char *elem_name, int nprops, PlyProperty *prop_list)
void write_scalar_type(FILE *, int)
double get_item_value(char *, int)
void ply_close_custom(PlyFile *plyfile)
PlyOtherProp * ply_get_other_properties(PlyFile *plyfile, char *elem_name, int offset)
void write_binary_item(FILE *, int, int, unsigned int, double, int)
PlyFile * ply_read_custom(FILE *fp, int *nelems, char ***elem_names)
void copy_property(PlyProperty *, PlyProperty *)
void add_element(PlyFile *, char **)
PlyFile * ply_write_custom(FILE *fp, int nelems, const char **elem_names, int file_type)
void ply_put_other_elements(PlyFile *plyfile)
void ascii_get_element(PlyFile *, char *)
void ply_header_complete(PlyFile *plyfile)
void add_comment(PlyFile *, char *)
void ply_describe_property(PlyFile *plyfile, const char *elem_name, PlyProperty *prop)
void ply_put_comment(PlyFile *plyfile, char *comment)
void ply_get_info(PlyFile *ply, float *version, int *file_type)
void add_obj_info(PlyFile *, char *)
void setup_other_props(PlyElement *elem)
int equal_strings(const char *, const char *)
void binary_get_element(PlyFile *, char *)
void ply_get_element(PlyFile *plyfile, void *elem_ptr)
PlyProperty * find_property(PlyElement *, const char *, int *)
void get_ascii_item(char *, int, int *, unsigned int *, double *)
char * my_alloc(int, int, const char *)
static int native_binary_type
const char * type_names[]
void add_property(PlyFile *, char **)
double old_write_ascii_item(FILE *, char *, int)
void get_binary_item(FILE *, int, int, int *, unsigned int *, double *)
char ** old_get_words(FILE *, int *)
char ** ply_get_comments(PlyFile *plyfile, int *num_comments)
PlyFile * ply_open_for_reading(char *filename, int *nelems, char ***elem_names, int *file_type, float *version)
void ply_put_element_setup(PlyFile *plyfile, const char *elem_name)
PlyProperty ** ply_get_element_description(PlyFile *plyfile, char *elem_name, int *nelems, int *nprops)
#define myalloc(mem_size)
#define REALLOCN(PTR, TYPE, OLD_N, NEW_N)
#define PLY_BINARY_NATIVE
#define offsetof(STRUCTURE, FIELD)
PlyOtherProp * other_props
PlyOtherElems * other_elems
char byte_values[sizeof(int)]