?? ply.c
字號:
case Int8: case Int16: case Int32: fprintf (fp, "%d ", int_val); break; case Uint8: case Uint16: case Uint32: fprintf (fp, "%u ", uint_val); break; case Float32: case Float64: fprintf (fp, "%g ", double_val); break; default: fprintf (stderr, "write_ascii_item: bad type = %d\n", type); exit (-1); }}/******************************************************************************Get the value of an item that is in memory, and place the resultinto an integer, an unsigned integer and a double.Entry: ptr - pointer to the item type - data type supposedly in the itemExit: int_val - integer value uint_val - unsigned integer value double_val - double-precision floating point value******************************************************************************/void get_stored_item( void *ptr, int type, int *int_val, unsigned int *uint_val, double *double_val){ switch (type) { case Int8: *int_val = *((char *) ptr); *uint_val = *int_val; *double_val = *int_val; break; case Uint8: *uint_val = *((unsigned char *) ptr); *int_val = *uint_val; *double_val = *uint_val; break; case Int16: *int_val = *((short int *) ptr); *uint_val = *int_val; *double_val = *int_val; break; case Uint16: *uint_val = *((unsigned short int *) ptr); *int_val = *uint_val; *double_val = *uint_val; break; case Int32: *int_val = *((int *) ptr); *uint_val = *int_val; *double_val = *int_val; break; case Uint32: *uint_val = *((unsigned int *) ptr); *int_val = *uint_val; *double_val = *uint_val; break; case Float32: *double_val = *((float *) ptr); *int_val = *double_val; *uint_val = *double_val; break; case Float64: *double_val = *((double *) ptr); *int_val = *double_val; *uint_val = *double_val; break; default: fprintf (stderr, "get_stored_item: bad type = %d\n", type); exit (-1); }}/******************************************************************************Get the value of an item from a binary file, and place the resultinto an integer, an unsigned integer and a double.Entry: fp - file to get item from type - data type supposedly in the wordExit: int_val - integer value uint_val - unsigned integer value double_val - double-precision floating point value******************************************************************************/void get_binary_item( FILE *fp, int type, int *int_val, unsigned int *uint_val, double *double_val){ char c[8]; void *ptr; ptr = (void *) c; switch (type) { case Int8: fread (ptr, 1, 1, fp); *int_val = *((char *) ptr); *uint_val = *int_val; *double_val = *int_val; break; case Uint8: fread (ptr, 1, 1, fp); *uint_val = *((unsigned char *) ptr); *int_val = *uint_val; *double_val = *uint_val; break; case Int16: fread (ptr, 2, 1, fp); *int_val = *((short int *) ptr); *uint_val = *int_val; *double_val = *int_val; break; case Uint16: fread (ptr, 2, 1, fp); *uint_val = *((unsigned short int *) ptr); *int_val = *uint_val; *double_val = *uint_val; break; case Int32: fread (ptr, 4, 1, fp); *int_val = *((int *) ptr); *uint_val = *int_val; *double_val = *int_val; break; case Uint32: fread (ptr, 4, 1, fp); *uint_val = *((unsigned int *) ptr); *int_val = *uint_val; *double_val = *uint_val; break; case Float32: fread (ptr, 4, 1, fp); *double_val = *((float *) ptr); *int_val = *double_val; *uint_val = *double_val; break; case Float64: fread (ptr, 8, 1, fp); *double_val = *((double *) ptr); *int_val = *double_val; *uint_val = *double_val; break; default: fprintf (stderr, "get_binary_item: bad type = %d\n", type); exit (-1); }}/******************************************************************************Extract the value of an item from an ascii word, and place the resultinto an integer, an unsigned integer and a double.Entry: word - word to extract value from type - data type supposedly in the wordExit: int_val - integer value uint_val - unsigned integer value double_val - double-precision floating point value******************************************************************************/void get_ascii_item( char *word, int type, int *int_val, unsigned int *uint_val, double *double_val){ switch (type) { case Int8: case Uint8: case Int16: case Uint16: case Int32: *int_val = atoi (word); *uint_val = *int_val; *double_val = *int_val; break; case Uint32: *uint_val = strtoul (word, (char **) NULL, 10); *int_val = *uint_val; *double_val = *uint_val; break; case Float32: case Float64: *double_val = atof (word); *int_val = (int) *double_val; *uint_val = (unsigned int) *double_val; break; default: fprintf (stderr, "get_ascii_item: bad type = %d\n", type); exit (-1); }}/******************************************************************************Store a value into a place being pointed to, guided by a data type.Entry: item - place to store value type - data type int_val - integer version of value uint_val - unsigned integer version of value double_val - double version of valueExit: item - pointer to stored value******************************************************************************/void store_item ( char *item, int type, int int_val, unsigned int uint_val, double double_val){ unsigned char *puchar; short int *pshort; unsigned short int *pushort; int *pint; unsigned int *puint; float *pfloat; double *pdouble; switch (type) { case Int8: *item = int_val; break; case Uint8: puchar = (unsigned char *) item; *puchar = uint_val; break; case Int16: pshort = (short *) item; *pshort = int_val; break; case Uint16: pushort = (unsigned short *) item; *pushort = uint_val; break; case Int32: pint = (int *) item; *pint = int_val; break; case Uint32: puint = (unsigned int *) item; *puint = uint_val; break; case Float32: pfloat = (float *) item; *pfloat = double_val; break; case Float64: pdouble = (double *) item; *pdouble = double_val; break; default: fprintf (stderr, "store_item: bad type = %d\n", type); exit (-1); }}/******************************************************************************Add an element to a PLY file descriptor.Entry: plyfile - PLY file descriptor words - list of words describing the element nwords - number of words in the list******************************************************************************/void add_element (PlyFile *plyfile, char **words, int nwords){ PlyElement *elem; /* create the new element */ elem = (PlyElement *) myalloc (sizeof (PlyElement)); elem->name = strdup (words[1]); elem->num = atoi (words[2]); elem->nprops = 0; /* make room for new element in the object's list of elements */ if (plyfile->num_elem_types == 0) plyfile->elems = (PlyElement **) myalloc (sizeof (PlyElement *)); else plyfile->elems = (PlyElement **) realloc (plyfile->elems, sizeof (PlyElement *) * (plyfile->num_elem_types + 1)); /* add the new element to the object's list */ plyfile->elems[plyfile->num_elem_types] = elem; plyfile->num_elem_types++;}/******************************************************************************Return the type of a property, given the name of the property.Entry: name - name of property typeExit: returns integer code for property, or 0 if not found******************************************************************************/int get_prop_type(char *type_name){ int i; /* try to match the type name */ for (i = StartType + 1; i < EndType; i++) if (equal_strings (type_name, type_names[i])) return (i); /* see if we can match an old type name */ for (i = StartType + 1; i < EndType; i++) if (equal_strings (type_name, old_type_names[i])) return (i); /* if we get here, we didn't find the type */ return (0);}/******************************************************************************Add a property to a PLY file descriptor.Entry: plyfile - PLY file descriptor words - list of words describing the property nwords - number of words in the list******************************************************************************/void add_property (PlyFile *plyfile, char **words, int nwords){ int prop_type; int count_type; PlyProperty *prop; PlyElement *elem; /* create the new property */ prop = (PlyProperty *) myalloc (sizeof (PlyProperty)); if (equal_strings (words[1], "list")) { /* list */ prop->count_external = get_prop_type (words[2]); prop->external_type = get_prop_type (words[3]); prop->name = strdup (words[4]); prop->is_list = PLY_LIST; } else if (equal_strings (words[1], "string")) { /* string */ prop->count_external = Int8; prop->external_type = Int8; prop->name = strdup (words[2]); prop->is_list = PLY_STRING; } else { /* scalar */ prop->external_type = get_prop_type (words[1]); prop->name = strdup (words[2]); prop->is_list = PLY_SCALAR; } /* add this property to the list of properties of the current element */ elem = plyfile->elems[plyfile->num_elem_types - 1]; if (elem->nprops == 0) elem->props = (PlyProperty **) myalloc (sizeof (PlyProperty *)); else elem->props = (PlyProperty **) realloc (elem->props, sizeof (PlyProperty *) * (elem->nprops + 1)); elem->props[elem->nprops] = prop; elem->nprops++;}/******************************************************************************Add a comment to a PLY file descriptor.Entry: plyfile - PLY file descriptor line - line containing comment******************************************************************************/void add_comment (PlyFile *plyfile, char *line){ int i; /* skip over "comment" and leading spaces and tabs */ i = 7; while (line[i] == ' ' || line[i] == '\t') i++; append_comment_ply (plyfile, &line[i]);}/******************************************************************************Add a some object information to a PLY file descriptor.Entry: plyfile - PLY file descriptor line - line containing text info******************************************************************************/void add_obj_info (PlyFile *plyfile, char *line){ int i; /* skip over "obj_info" and leading spaces and tabs */ i = 8; while (line[i] == ' ' || line[i] == '\t') i++; append_obj_info_ply (plyfile, &line[i]);}/******************************************************************************Copy a property.******************************************************************************/void copy_property(PlyProperty *dest, PlyProperty *src){ dest->name = strdup (src->name); dest->external_type = src->external_type; dest->internal_type = src->internal_type; dest->offset = src->offset; dest->is_list = src->is_list; dest->count_external = src->count_external; dest->count_internal = src->count_internal; dest->count_offset = src->count_offset;}/******************************************************************************Allocate some memory.Entry: size - amount of memory requested (in bytes) lnum - line number from which memory was requested fname - file name from which memory was requested******************************************************************************/static char *my_alloc(int size, int lnum, char *fname){ char *ptr; ptr = (char *) malloc (size)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -