⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ply.c

📁 C语言滤波程序
💻 C
📖 第 1 页 / 共 5 页
字号:
  /* Examine each property in decreasing order of size. */  /* We do this so that all data types will be aligned by */  /* word, half-word, or whatever within the structure. */  for (type_size = 8; type_size > 0; type_size /= 2) {    /* add up the space taken by each property, and save this information */    /* away in the property descriptor */    for (i = 0; i < elem->nprops; i++) {      /* don't bother with properties we've been asked to store explicitly */      if (elem->store_prop[i])        continue;      prop = elem->props[i];      /* internal types will be same as external */      prop->internal_type = prop->external_type;      prop->count_internal = prop->count_external;      /* list case */      if (prop->is_list == PLY_LIST) {        /* pointer to list */        if (type_size == sizeof (void *)) {          prop->offset = size;          size += sizeof (void *);    /* always use size of a pointer here */        }        /* count of number of list elements */        if (type_size == ply_type_size[prop->count_external]) {          prop->count_offset = size;          size += ply_type_size[prop->count_external];        }      }      /* string */      else if (prop->is_list == PLY_STRING) {        /* pointer to string */        if (type_size == sizeof (char *)) {          prop->offset = size;          size += sizeof (char *);        }      }      /* scalar */      else if (type_size == ply_type_size[prop->external_type]) {        prop->offset = size;        size += ply_type_size[prop->external_type];      }    }  }  /* save the size for the other_props structure */  elem->other_size = size;}/******************************************************************************Specify that we want the "other" properties of an element to be tuckedaway within the user's structure.Entry:  plyfile - file identifier  elem    - the element that we want to store other_props in  offset  - offset to where other_props will be stored inside user's structureExit:  returns pointer to structure containing description of other_props******************************************************************************/static PlyOtherProp *get_other_properties(  PlyFile *plyfile,  PlyElement *elem,  int offset){  int i;  PlyOtherProp *other;  PlyProperty *prop;  int nprops;  /* remember that this is the "current" element */  plyfile->which_elem = elem;  /* save the offset to where to store the other_props */  elem->other_offset = offset;  /* place the appropriate pointers, etc. in the element's property list */  setup_other_props (plyfile, elem);  /* create structure for describing other_props */  other = (PlyOtherProp *) myalloc (sizeof (PlyOtherProp));  other->name = strdup (elem->name);#if 0  if (elem->other_offset == NO_OTHER_PROPS) {    other->size = 0;    other->props = NULL;    other->nprops = 0;    return (other);  }#endif  other->size = elem->other_size;  other->props = (PlyProperty **) myalloc (sizeof(PlyProperty) * elem->nprops);    /* save descriptions of each "other" property */  nprops = 0;  for (i = 0; i < elem->nprops; i++) {    if (elem->store_prop[i])      continue;    prop = (PlyProperty *) myalloc (sizeof (PlyProperty));    copy_property (prop, elem->props[i]);    other->props[nprops] = prop;    nprops++;  }  other->nprops = nprops;  /* set other_offset pointer appropriately if there are NO other properties */  if (other->nprops == 0) {    elem->other_offset = NO_OTHER_PROPS;  }   /* return structure */  return (other);}/******************************************************************************Specify that we want the "other" properties of an element to be tuckedaway within the user's structure.  The user needn't be concerned for howthese properties are stored.Entry:  plyfile   - file identifier  elem_name - name of element that we want to store other_props in  offset    - offset to where other_props will be stored inside user's structureExit:  returns pointer to structure containing description of other_props******************************************************************************/PlyOtherProp *ply_get_other_properties(  PlyFile *plyfile,  char *elem_name,  int offset){  PlyElement *elem;  PlyOtherProp *other;  /* find information about the element */  elem = find_element (plyfile, elem_name);  if (elem == NULL) {    fprintf (stderr, "ply_get_other_properties: Can't find element '%s'\n",             elem_name);    return (NULL);  }  other = get_other_properties (plyfile, elem, offset);  return (other);}/*************************//*  Other Element Stuff  *//*************************//******************************************************************************Grab all the data for the current element that a user does not want toexplicitly read in.  Stores this in the PLY object's data structure.Entry:  plyfile - pointer to fileExit:  returns pointer to ALL the "other" element data for this PLY file******************************************************************************/PlyOtherElems *get_other_element_ply (PlyFile *plyfile){  int i;  PlyElement *elem;  char *elem_name;  int elem_count;  PlyOtherElems *other_elems;  OtherElem *other;  elem = plyfile->which_elem;  elem_name = elem->name;  elem_count = elem->num;  /* create room for the new "other" element, initializing the */  /* other data structure if necessary */  if (plyfile->other_elems == NULL) {    plyfile->other_elems = (PlyOtherElems *) myalloc (sizeof (PlyOtherElems));    other_elems = plyfile->other_elems;    other_elems->other_list = (OtherElem *) myalloc (sizeof (OtherElem));    other = &(other_elems->other_list[0]);    other_elems->num_elems = 1;  }  else {    other_elems = plyfile->other_elems;    other_elems->other_list = (OtherElem *) realloc (other_elems->other_list,                              sizeof (OtherElem) * other_elems->num_elems + 1);    other = &(other_elems->other_list[other_elems->num_elems]);    other_elems->num_elems++;  }  /* count of element instances in file */  other->elem_count = elem_count;  /* save name of element */  other->elem_name = strdup (elem_name);  /* create a list to hold all the current elements */  other->other_data = (OtherData **)                  malloc (sizeof (OtherData *) * other->elem_count);  /* set up for getting elements */  other->other_props = ply_get_other_properties (plyfile, elem_name,                         offsetof(OtherData,other_props));  /* grab all these elements */  for (i = 0; i < other->elem_count; i++) {    /* grab and element from the file */    other->other_data[i] = (OtherData *) malloc (sizeof (OtherData));    ply_get_element (plyfile, (void *) other->other_data[i]);  }  /* return pointer to the other elements data */  return (other_elems);}/******************************************************************************Write out the "other" elements specified for this PLY file.Entry:  plyfile - pointer to PLY file to write out other elements for******************************************************************************/void put_other_elements_ply (PlyFile *plyfile){  int i,j;  OtherElem *other;  /* make sure we have other elements to write */  if (plyfile->other_elems == NULL)    return;  /* write out the data for each "other" element */  for (i = 0; i < plyfile->other_elems->num_elems; i++) {    other = &(plyfile->other_elems->other_list[i]);    put_element_setup_ply (plyfile, other->elem_name);    /* write out each instance of the current element */    for (j = 0; j < other->elem_count; j++)      put_element_ply (plyfile, (void *) other->other_data[j]);  }}/******************************************************************************Free up storage used by an "other" elements data structure.Entry:  other_elems - data structure to free up******************************************************************************/void free_other_elements_ply (PlyOtherElems *other_elems){}/*******************//*  Miscellaneous  *//*******************//******************************************************************************Close a PLY file.Entry:  plyfile - identifier of file to close******************************************************************************/void ply_close(PlyFile *plyfile){  fclose (plyfile->fp);  /* free up memory associated with the PLY file */  free (plyfile);}/******************************************************************************Get version number and file type of a PlyFile.Entry:  ply - pointer to PLY fileExit:  version - version of the file  file_type - PLY_ASCII, PLY_BINARY_BE, or PLY_BINARY_LE******************************************************************************/void get_info_ply(PlyFile *ply, float *version, int *file_type){  if (ply == NULL)    return;  *version = ply->version;  *file_type = ply->file_type;}/******************************************************************************Compare two strings.  Returns 1 if they are the same, 0 if not.******************************************************************************/int equal_strings(char *s1, char *s2){  int i;  while (*s1 && *s2)    if (*s1++ != *s2++)      return (0);  if (*s1 != *s2)    return (0);  else    return (1);}/******************************************************************************Re-create the command line that was used to invoke this program.Entry:  argc - number of words in argv  argv - array of words in command line******************************************************************************/char *recreate_command_line (int argc, char *argv[]){  int i;  char *line;  int len = 0;  /* count total number of characters needed, including separating spaces */  for (i = 0; i < argc; i++)    len += strlen(argv[i]) + 1;  /* create empty line */  line = (char *) malloc (sizeof(char) * len);  line[0] = '\0';  /* repeatedly append argv */  for (i = 0; i < argc; i++) {    strcat (line, argv[i]);    if (i != argc - 1)      strcat (line, " ");  }  return (line);}/******************************************************************************Find an element from the element list of a given PLY object.Entry:  plyfile - file id for PLY file  element - name of element we're looking forExit:  returns the element, or NULL if not found******************************************************************************/PlyElement *find_element(PlyFile *plyfile, char *element){  int i;  for (i = 0; i < plyfile->num_elem_types; i++)    if (equal_strings (element, plyfile->elems[i]->name))      return (plyfile->elems[i]);  return (NULL);}/******************************************************************************Find a property in the list of properties of a given element.Entry:  elem      - pointer to element in which we want to find the property  prop_name - name of property to findExit:  index - index to position in list  returns a pointer to the property, or NULL if not found******************************************************************************/PlyProperty *find_property(PlyElement *elem, char *prop_name, int *index){  int i;  for (i = 0; i < elem->nprops; i++)    if (equal_strings (prop_name, elem->props[i]->name)) {      *index = i;      return (elem->props[i]);    }  *index = -1;  return (NULL);}/******************************************************************************Read an element from an ascii file.Entry:  plyfile  - file identifier  elem_ptr - pointer to element******************************************************************************/void ascii_get_element(PlyFile *plyfile, char *elem_ptr){  int i,j,k;  PlyElement *elem;  PlyProperty *prop;  char **words;  int nwords;  int which_word;  FILE *fp = plyfile->fp;  char *elem_data,*item;  char *item_ptr;  int item_size;  int int_val;  unsigned int uint_val;  double double_val;  int list_count;  int store_it;  char **store_array;  char *orig_line;  char *other_data;  int other_flag;  /* the kind of element we're reading currently */  elem = plyfile->which_elem;  /* do we need to setup for other_props? */  if (elem->other_offset != NO_OTHER_PROPS) {    char **ptr;    other_flag = 1;    /* make room for other_props */    other_data = (char *) myalloc (elem->other_size);    /* store pointer in user's structure to the other_props */    ptr = (char **) (elem_ptr + elem->other_offset);    *ptr = other_data;  }  else    other_flag = 0;  /* read in the element */  words = get_words (plyfile->fp, &nwords, &orig_line);  if (words == NULL) {    fprintf (stderr, "ply_get_element: unexpected end of file\n");    exit (-1);  }  which_word = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -