Builder/Builder/Common/plyfile.c
/******************************************************************************
Write an element to the file.  This routine assumes that we're
writing the type of element specified in the last call to the routine
ply_put_element_setup().

Entry:
  plyfile  - file identifier
  elem_ptr - pointer to the element
******************************************************************************/
Write an element to the file.  This routine assumes that we're
writing the type of element specified in the last call to the routine
ply_put_element_setup().

plyfile  - file identifier
elem_ptr - pointer to the element
Write an element to the file . This routine assumes that we ' re writing the type of element specified in the last call to the routine ply_put_element_setup () . plyfile - file identifier elem_ptr - pointer to the element
void ply_put_element(PlyFile *plyfile, void *elem_ptr)
{
  int j,k;
  FILE *fp = plyfile->fp;
  PlyElement *elem;
  PlyProperty *prop;
  char *elem_data,*item;
  char **item_ptr;
  int list_count;
  int item_size;
  int int_val;
  unsigned int uint_val;
  double double_val;
  char **other_ptr;
  elem = plyfile->which_elem;
  elem_data = (char *)elem_ptr;
  other_ptr = (char **) (((char *) elem_ptr) + elem->other_offset);
  if (plyfile->file_type == PLY_ASCII) {
    for (j = 0; j < elem->nprops; j++) {
      prop = elem->props[j];
      if (elem->store_prop[j] == OTHER_PROP)
        elem_data = *other_ptr;
      else
        elem_data = (char *)elem_ptr;
      if (prop->is_list) {
        item = elem_data + prop->count_offset;
        get_stored_item ((void *) item, prop->count_internal,
                         &int_val, &uint_val, &double_val);
        write_ascii_item (fp, int_val, uint_val, double_val,
                          prop->count_external);
        list_count = uint_val;
        item_ptr = (char **) (elem_data + prop->offset);
        item = item_ptr[0];
        item_size = ply_type_size[prop->internal_type];
        for (k = 0; k < list_count; k++) {
          get_stored_item ((void *) item, prop->internal_type,
                           &int_val, &uint_val, &double_val);
          write_ascii_item (fp, int_val, uint_val, double_val,
                            prop->external_type);
          item += item_size;
        }
      }
      else {
        item = elem_data + prop->offset;
        get_stored_item ((void *) item, prop->internal_type,
                         &int_val, &uint_val, &double_val);
        write_ascii_item (fp, int_val, uint_val, double_val,
                          prop->external_type);
      }
    }
    fprintf (fp, "\n");
  }
  else {
    for (j = 0; j < elem->nprops; j++) {
      prop = elem->props[j];
      if (elem->store_prop[j] == OTHER_PROP)
        elem_data = *other_ptr;
      else
        elem_data = (char *)elem_ptr;
      if (prop->is_list) {
        item = elem_data + prop->count_offset;
        item_size = ply_type_size[prop->count_internal];
        get_stored_item ((void *) item, prop->count_internal,
                         &int_val, &uint_val, &double_val);
        write_binary_item (fp, plyfile->file_type, int_val, uint_val,
			   double_val, prop->count_external);
        list_count = uint_val;
        item_ptr = (char **) (elem_data + prop->offset);
        item = item_ptr[0];
        item_size = ply_type_size[prop->internal_type];
        for (k = 0; k < list_count; k++) {
          get_stored_item ((void *) item, prop->internal_type,
                           &int_val, &uint_val, &double_val);
          write_binary_item (fp, plyfile->file_type, int_val, uint_val,
			     double_val, prop->external_type);
          item += item_size;
        }
      }
      else {
        item = elem_data + prop->offset;
        item_size = ply_type_size[prop->internal_type];
        get_stored_item ((void *) item, prop->internal_type,
                         &int_val, &uint_val, &double_val);
        write_binary_item (fp, plyfile->file_type, int_val, uint_val,
			   double_val, prop->external_type);
      }
    }
  }
}
void ply_put_element ( PlyFile * plyfile , void * elem_ptr ) { int j , k ; FILE * fp = plyfile -> fp ; PlyElement * elem ; PlyProperty * prop ; char * elem_data , * item ; char * * item_ptr ; int list_count ; int item_size ; int int_val ; unsigned int uint_val ; double double_val ; char * * other_ptr ; elem = plyfile -> which_elem ; elem_data = ( char * ) elem_ptr ; other_ptr = ( char * * ) ( ( ( char * ) elem_ptr ) + elem -> other_offset ) ; if ( plyfile -> file_type == PLY_ASCII ) { for ( j = 0 ; j < elem -> nprops ; j ++ ) { prop = elem -> props [ j ] ; if ( elem -> store_prop [ j ] == OTHER_PROP ) elem_data = * other_ptr ; else elem_data = ( char * ) elem_ptr ; if ( prop -> is_list ) { item = elem_data + prop -> count_offset ; get_stored_item ( ( void * ) item , prop -> count_internal , & int_val , & uint_val , & double_val ) ; write_ascii_item ( fp , int_val , uint_val , double_val , prop -> count_external ) ; list_count = uint_val ; item_ptr = ( char * * ) ( elem_data + prop -> offset ) ; item = item_ptr [ 0 ] ; item_size = ply_type_size [ prop -> internal_type ] ; for ( k = 0 ; k < list_count ; k ++ ) { get_stored_item ( ( void * ) item , prop -> internal_type , & int_val , & uint_val , & double_val ) ; write_ascii_item ( fp , int_val , uint_val , double_val , prop -> external_type ) ; item += item_size ; } } else { item = elem_data + prop -> offset ; get_stored_item ( ( void * ) item , prop -> internal_type , & int_val , & uint_val , & double_val ) ; write_ascii_item ( fp , int_val , uint_val , double_val , prop -> external_type ) ; } } fprintf ( fp , " \n " ) ; } else { for ( j = 0 ; j < elem -> nprops ; j ++ ) { prop = elem -> props [ j ] ; if ( elem -> store_prop [ j ] == OTHER_PROP ) elem_data = * other_ptr ; else elem_data = ( char * ) elem_ptr ; if ( prop -> is_list ) { item = elem_data + prop -> count_offset ; item_size = ply_type_size [ prop -> count_internal ] ; get_stored_item ( ( void * ) item , prop -> count_internal , & int_val , & uint_val , & double_val ) ; write_binary_item ( fp , plyfile -> file_type , int_val , uint_val , double_val , prop -> count_external ) ; list_count = uint_val ; item_ptr = ( char * * ) ( elem_data + prop -> offset ) ; item = item_ptr [ 0 ] ; item_size = ply_type_size [ prop -> internal_type ] ; for ( k = 0 ; k < list_count ; k ++ ) { get_stored_item ( ( void * ) item , prop -> internal_type , & int_val , & uint_val , & double_val ) ; write_binary_item ( fp , plyfile -> file_type , int_val , uint_val , double_val , prop -> external_type ) ; item += item_size ; } } else { item = elem_data + prop -> offset ; item_size = ply_type_size [ prop -> internal_type ] ; get_stored_item ( ( void * ) item , prop -> internal_type , & int_val , & uint_val , & double_val ) ; write_binary_item ( fp , plyfile -> file_type , int_val , uint_val , double_val , prop -> external_type ) ; } } } }
Write an element to the file.
Write an element to the file .
/* write out either to an ascii or binary file */ /* write an ascii file */ /* write out each property of the element */ /* write a binary file */ /* write out each property of the element */