Builder/Builder/Common/plyfile.c
/******************************************************************************
Given a file pointer, get ready to read PLY data from the file.

Entry:
  fp - the given file pointer

Exit:
  nelems     - number of elements in object
  elem_names - list of element names
  returns a pointer to a PlyFile, used to refer to this file, or NULL if error
******************************************************************************/
Given a file pointer, get ready to read PLY data from the file.
Entry:
fp - the given file pointer

nelems     - number of elements in object
elem_names - list of element names
returns a pointer to a PlyFile, used to refer to this file, or NULL if error
Given a file pointer get ready to read PLY data from the file . Entry : fp - the given file pointer nelems - number of elements in object elem_names - list of element names returns a pointer to a PlyFile used to refer to this file or NULL if error
PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names)
{
  int i,j;
  PlyFile *plyfile;
  int nwords;
  char **words;
  char **elist;
  PlyElement *elem;
  char *orig_line;
  if (fp == NULL)
    return (NULL);
  if (native_binary_type == -1)
     get_native_binary_type();
  if (!types_checked)
     check_types();
  plyfile = (PlyFile *) myalloc (sizeof (PlyFile));
  plyfile->nelems = 0;
  plyfile->comments = NULL;
  plyfile->num_comments = 0;
  plyfile->obj_info = NULL;
  plyfile->num_obj_info = 0;
  plyfile->fp = fp;
  plyfile->other_elems = NULL;
  words = get_words (plyfile->fp, &nwords, &orig_line);
  if (!words || !equal_strings (words[0], "ply"))
  {
      if (words)
	 free(words);
      return (NULL);
  }
  while (words) {
    if (equal_strings (words[0], "format")) {
      if (nwords != 3) {
	free(words);
	return (NULL);
      }
      if (equal_strings (words[1], "ascii"))
        plyfile->file_type = PLY_ASCII;
      else if (equal_strings (words[1], "binary_big_endian"))
        plyfile->file_type = PLY_BINARY_BE;
      else if (equal_strings (words[1], "binary_little_endian"))
        plyfile->file_type = PLY_BINARY_LE;
      else {
	free(words);
        return (NULL);
      }
      plyfile->version = atof (words[2]);
    }
    else if (equal_strings (words[0], "element"))
      add_element (plyfile, words);
    else if (equal_strings (words[0], "property"))
      add_property (plyfile, words);
    else if (equal_strings (words[0], "comment"))
      add_comment (plyfile, orig_line);
    else if (equal_strings (words[0], "obj_info"))
      add_obj_info (plyfile, orig_line);
    else if (equal_strings (words[0], "end_header")) {
      free(words);
      break;
    }
    free (words);
    words = get_words (plyfile->fp, &nwords, &orig_line);
  }
  for (i = 0; i < plyfile->nelems; i++) {
    elem = plyfile->elems[i];
    elem->store_prop = (char *) myalloc (sizeof (char) * elem->nprops);
    for (j = 0; j < elem->nprops; j++)
      elem->store_prop[j] = DONT_STORE_PROP;
    elem->other_offset = NO_OTHER_PROPS; 
  }
  elist = (char **) myalloc (sizeof (char *) * plyfile->nelems);
  for (i = 0; i < plyfile->nelems; i++)
    elist[i] = _strdup (plyfile->elems[i]->name);
  *elem_names = elist;
  *nelems = plyfile->nelems;
  return (plyfile);
}
PlyFile * ply_read ( FILE * fp , int * nelems , char * * * elem_names ) { int i , j ; PlyFile * plyfile ; int nwords ; char * * words ; char * * elist ; PlyElement * elem ; char * orig_line ; if ( fp == NULL ) return ( NULL ) ; if ( native_binary_type == -1 ) get_native_binary_type ( ) ; if ( ! types_checked ) check_types ( ) ; plyfile = ( PlyFile * ) myalloc ( sizeof ( PlyFile ) ) ; plyfile -> nelems = 0 ; plyfile -> comments = NULL ; plyfile -> num_comments = 0 ; plyfile -> obj_info = NULL ; plyfile -> num_obj_info = 0 ; plyfile -> fp = fp ; plyfile -> other_elems = NULL ; words = get_words ( plyfile -> fp , & nwords , & orig_line ) ; if ( ! words || ! equal_strings ( words [ 0 ] , " " ) ) { if ( words ) free ( words ) ; return ( NULL ) ; } while ( words ) { if ( equal_strings ( words [ 0 ] , " " ) ) { if ( nwords != 3 ) { free ( words ) ; return ( NULL ) ; } if ( equal_strings ( words [ 1 ] , " " ) ) plyfile -> file_type = PLY_ASCII ; else if ( equal_strings ( words [ 1 ] , " " ) ) plyfile -> file_type = PLY_BINARY_BE ; else if ( equal_strings ( words [ 1 ] , " " ) ) plyfile -> file_type = PLY_BINARY_LE ; else { free ( words ) ; return ( NULL ) ; } plyfile -> version = atof ( words [ 2 ] ) ; } else if ( equal_strings ( words [ 0 ] , " " ) ) add_element ( plyfile , words ) ; else if ( equal_strings ( words [ 0 ] , " " ) ) add_property ( plyfile , words ) ; else if ( equal_strings ( words [ 0 ] , " " ) ) add_comment ( plyfile , orig_line ) ; else if ( equal_strings ( words [ 0 ] , " " ) ) add_obj_info ( plyfile , orig_line ) ; else if ( equal_strings ( words [ 0 ] , " " ) ) { free ( words ) ; break ; } free ( words ) ; words = get_words ( plyfile -> fp , & nwords , & orig_line ) ; } for ( i = 0 ; i < plyfile -> nelems ; i ++ ) { elem = plyfile -> elems [ i ] ; elem -> store_prop = ( char * ) myalloc ( sizeof ( char ) * elem -> nprops ) ; for ( j = 0 ; j < elem -> nprops ; j ++ ) elem -> store_prop [ j ] = DONT_STORE_PROP ; elem -> other_offset = NO_OTHER_PROPS ; } elist = ( char * * ) myalloc ( sizeof ( char * ) * plyfile -> nelems ) ; for ( i = 0 ; i < plyfile -> nelems ; i ++ ) elist [ i ] = _strdup ( plyfile -> elems [ i ] -> name ) ; * elem_names = elist ; * nelems = plyfile -> nelems ; return ( plyfile ) ; }
Given a file pointer, get ready to read PLY data from the file.
Given a file pointer get ready to read PLY data from the file .
/* check for NULL file pointer */ /* create record for this object */ /* read and parse the file's header */ /* parse words */ /* free up words space */ /* create tags for each property of each element, to be used */ /* later to say whether or not to store each property for the user */ /* no "other" props by default */ /* set return values about the elements */ /* return a pointer to the file's information */