Builder/Builder/Common/plyfile.c
/******************************************************************************
Grab all the data for an element that a user does not want to explicitly
read in.

Entry:
  plyfile    - pointer to file
  elem_name  - name of element whose data is to be read in
  elem_count - number of instances of this element stored in the file

Exit:
  returns pointer to ALL the "other" element data for this PLY file
******************************************************************************/
Grab all the data for an element that a user does not want to explicitly
read in.

plyfile    - pointer to file
elem_name  - name of element whose data is to be read in
elem_count - number of instances of this element stored in the file

returns pointer to ALL the "other" element data for this PLY file
Grab all the data for an element that a user does not want to explicitly read in . plyfile - pointer to file elem_name - name of element whose data is to be read in elem_count - number of instances of this element stored in the file returns pointer to ALL the " other " element data for this PLY file
PlyOtherElems *ply_get_other_element (
  PlyFile *plyfile,
  char *elem_name,
  int elem_count
)
{
  int i;
  PlyElement *elem;
  PlyOtherElems *other_elems;
  OtherElem *other;
  elem = find_element (plyfile, elem_name);
  if (elem == NULL) {
    fprintf (stderr,
             "ply_get_other_element: can't find element '%s'\n", elem_name);
    exit (-1);
  }
  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++;
  }
  other->elem_count = elem_count;
  other->elem_name = _strdup (elem_name);
  other->other_data = (OtherData **)
                  malloc (sizeof (OtherData *) * other->elem_count);
  other->other_props = ply_get_other_properties (plyfile, elem_name,
                         offsetof(OtherData,other_props));
  for (i = 0; i < other->elem_count; i++) {
    other->other_data[i] = (OtherData *) malloc (sizeof (OtherData));
    ply_get_element (plyfile, (void *) other->other_data[i]);
  }
  return (other_elems);
}
PlyOtherElems * ply_get_other_element ( PlyFile * plyfile , char * elem_name , int elem_count ) { int i ; PlyElement * elem ; PlyOtherElems * other_elems ; OtherElem * other ; elem = find_element ( plyfile , elem_name ) ; if ( elem == NULL ) { fprintf ( stderr , " \n " , elem_name ) ; exit ( -1 ) ; } 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 ++ ; } other -> elem_count = elem_count ; other -> elem_name = _strdup ( elem_name ) ; other -> other_data = ( OtherData * * ) malloc ( sizeof ( OtherData * ) * other -> elem_count ) ; other -> other_props = ply_get_other_properties ( plyfile , elem_name , offsetof ( OtherData , other_props ) ) ; for ( i = 0 ; i < other -> elem_count ; i ++ ) { other -> other_data [ i ] = ( OtherData * ) malloc ( sizeof ( OtherData ) ) ; ply_get_element ( plyfile , ( void * ) other -> other_data [ i ] ) ; } return ( other_elems ) ; }
Grab all the data for an element that a user does not want to explicitly
read in.
Grab all the data for an element that a user does not want to explicitly read in .
/* look for appropriate element */ /* create room for the new "other" element, initializing the */ /* other data structure if necessary */ /* count of element instances in file */ /* save name of element */ /* create a list to hold all the current elements */ /* set up for getting elements */ /* grab all these elements */ /* grab and element from the file */ /* return pointer to the other elements data */