Subversion Repositories gelsvn

Rev

Rev 333 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 333 Rev 373
Line 202... Line 202...
202
  char **elem_names,
202
  char **elem_names,
203
  int file_type,
203
  int file_type,
204
  float *version
204
  float *version
205
)
205
)
206
{
206
{
207
  int i;
-
 
208
  PlyFile *plyfile;
207
  PlyFile *plyfile;
209
  PlyElement *elem;
-
 
210
  char *name;
208
  char *name;
211
  FILE *fp;
209
  FILE *fp;
212
 
210
 
213
  /* tack on the extension .ply, if necessary */
211
  /* tack on the extension .ply, if necessary */
214
 
212
 
Line 406... Line 404...
406
  PlyFile *plyfile,
404
  PlyFile *plyfile,
407
  char *elem_name,
405
  char *elem_name,
408
  int nelems
406
  int nelems
409
)
407
)
410
{
408
{
411
  int i;
-
 
412
  PlyElement *elem;
409
  PlyElement *elem;
413
  PlyProperty *prop;
-
 
414
 
410
 
415
  /* look for appropriate element */
411
  /* look for appropriate element */
416
  elem = find_element (plyfile, elem_name);
412
  elem = find_element (plyfile, elem_name);
417
  if (elem == NULL) {
413
  if (elem == NULL) {
418
    fprintf(stderr,"ply_element_count: can't find element '%s'\n",elem_name);
414
    fprintf(stderr,"ply_element_count: can't find element '%s'\n",elem_name);
Line 528... Line 524...
528
  elem_ptr - pointer to the element
524
  elem_ptr - pointer to the element
529
******************************************************************************/
525
******************************************************************************/
530
 
526
 
531
void ply_put_element(PlyFile *plyfile, void *elem_ptr)
527
void ply_put_element(PlyFile *plyfile, void *elem_ptr)
532
{
528
{
533
  int i,j,k;
529
  int j,k;
534
  FILE *fp = plyfile->fp;
530
  FILE *fp = plyfile->fp;
535
  PlyElement *elem;
531
  PlyElement *elem;
536
  PlyProperty *prop;
532
  PlyProperty *prop;
537
  char *elem_data,*item;
533
  char *elem_data,*item;
538
  char **item_ptr;
534
  char **item_ptr;
Line 753... Line 749...
753
        plyfile->file_type = PLY_BINARY_BE;
749
        plyfile->file_type = PLY_BINARY_BE;
754
      else if (equal_strings (words[1], "binary_little_endian"))
750
      else if (equal_strings (words[1], "binary_little_endian"))
755
        plyfile->file_type = PLY_BINARY_LE;
751
        plyfile->file_type = PLY_BINARY_LE;
756
      else
752
      else
757
        return (NULL);
753
        return (NULL);
758
      plyfile->version = atof (words[2]);
754
      plyfile->version = (float)atof(words[2]);
759
      found_format = 1;
755
      found_format = 1;
760
    }
756
    }
761
    else if (equal_strings (words[0], "element"))
757
    else if (equal_strings (words[0], "element"))
762
      add_element (plyfile, words, nwords);
758
      add_element (plyfile, words, nwords);
763
    else if (equal_strings (words[0], "property"))
759
    else if (equal_strings (words[0], "property"))
Line 1251... Line 1247...
1251
{
1247
{
1252
  int i;
1248
  int i;
1253
  PlyElement *elem;
1249
  PlyElement *elem;
1254
  PlyOtherElems *other_elems;
1250
  PlyOtherElems *other_elems;
1255
  OtherElem *other;
1251
  OtherElem *other;
1256
  int num_elems;
-
 
1257
 
1252
 
1258
  /* look for appropriate element */
1253
  /* look for appropriate element */
1259
  elem = find_element (plyfile, elem_name);
1254
  elem = find_element (plyfile, elem_name);
1260
  if (elem == NULL) {
1255
  if (elem == NULL) {
1261
    fprintf (stderr,
1256
    fprintf (stderr,
Line 1433... Line 1428...
1433
Compare two strings.  Returns 1 if they are the same, 0 if not.
1428
Compare two strings.  Returns 1 if they are the same, 0 if not.
1434
******************************************************************************/
1429
******************************************************************************/
1435
 
1430
 
1436
int equal_strings(char *s1, char *s2)
1431
int equal_strings(char *s1, char *s2)
1437
{
1432
{
1438
  int i;
-
 
1439
 
-
 
1440
  while (*s1 && *s2)
1433
  while (*s1 && *s2)
1441
    if (*s1++ != *s2++)
1434
    if (*s1++ != *s2++)
1442
      return (0);
1435
      return (0);
1443
 
1436
 
1444
  if (*s1 != *s2)
1437
  if (*s1 != *s2)
Line 1507... Line 1500...
1507
******************************************************************************/
1500
******************************************************************************/
1508
 
1501
 
1509
void ascii_get_element(PlyFile *plyfile, char *elem_ptr, 
1502
void ascii_get_element(PlyFile *plyfile, char *elem_ptr, 
1510
		       int use_provided_storage)
1503
		       int use_provided_storage)
1511
{
1504
{
1512
  int i,j,k;
1505
  int j,k;
1513
  PlyElement *elem;
1506
  PlyElement *elem;
1514
  PlyProperty *prop;
1507
  PlyProperty *prop;
1515
  char **words;
1508
  char **words;
1516
  int nwords;
1509
  int nwords;
1517
  int which_word;
1510
  int which_word;
Line 1636... Line 1629...
1636
******************************************************************************/
1629
******************************************************************************/
1637
 
1630
 
1638
void binary_get_element(PlyFile *plyfile, char *elem_ptr, 
1631
void binary_get_element(PlyFile *plyfile, char *elem_ptr, 
1639
			int use_provided_storage)
1632
			int use_provided_storage)
1640
{
1633
{
1641
  int i,j,k;
1634
  int j,k;
1642
  PlyElement *elem;
1635
  PlyElement *elem;
1643
  PlyProperty *prop;
1636
  PlyProperty *prop;
1644
  FILE *fp = plyfile->fp;
1637
  FILE *fp = plyfile->fp;
1645
  char *elem_data,*item;
1638
  char *elem_data,*item;
1646
  char *item_ptr;
1639
  char *item_ptr;
Line 1787... Line 1780...
1787
******************************************************************************/
1780
******************************************************************************/
1788
 
1781
 
1789
char **get_words(FILE *fp, int *nwords, char **orig_line)
1782
char **get_words(FILE *fp, int *nwords, char **orig_line)
1790
{
1783
{
1791
#define BIG_STRING 4096
1784
#define BIG_STRING 4096
1792
  int i,j;
-
 
1793
  static char str[BIG_STRING];
1785
  static char str[BIG_STRING];
1794
  static char str_copy[BIG_STRING];
1786
  static char str_copy[BIG_STRING];
1795
  char **words;
1787
  char **words;
1796
  int max_words = 10;
1788
  int max_words = 10;
1797
  int num_words = 0;
1789
  int num_words = 0;
Line 1984... Line 1976...
1984
    case PLY_UINT:
1976
    case PLY_UINT:
1985
      SWAP_TO_ENDIAN4(&uint_val, file_type);
1977
      SWAP_TO_ENDIAN4(&uint_val, file_type);
1986
      fwrite (&uint_val, 4, 1, fp);
1978
      fwrite (&uint_val, 4, 1, fp);
1987
      break;
1979
      break;
1988
    case PLY_FLOAT:
1980
    case PLY_FLOAT:
1989
      float_val = double_val;
1981
      float_val = (float)double_val;
1990
      SWAP_TO_ENDIAN4(&float_val, file_type);
1982
      SWAP_TO_ENDIAN4(&float_val, file_type);
1991
      fwrite (&float_val, 4, 1, fp);
1983
      fwrite (&float_val, 4, 1, fp);
1992
      break;
1984
      break;
1993
    case PLY_DOUBLE:
1985
    case PLY_DOUBLE:
1994
      SWAP_TO_ENDIAN8(&double_val, file_type);
1986
      SWAP_TO_ENDIAN8(&double_val, file_type);
Line 2172... Line 2164...
2172
      *int_val = *uint_val;
2164
      *int_val = *uint_val;
2173
      *double_val = *uint_val;
2165
      *double_val = *uint_val;
2174
      break;
2166
      break;
2175
    case PLY_FLOAT:
2167
    case PLY_FLOAT:
2176
      *double_val = *((float *) ptr);
2168
      *double_val = *((float *) ptr);
2177
      *int_val = *double_val;
2169
      *int_val = (int)*double_val;
2178
      *uint_val = *double_val;
2170
      *uint_val = (unsigned int)*double_val;
2179
      break;
2171
      break;
2180
    case PLY_DOUBLE:
2172
    case PLY_DOUBLE:
2181
      *double_val = *((double *) ptr);
2173
      *double_val = *((double *) ptr);
2182
      *int_val = *double_val;
2174
      *int_val = (int)*double_val;
2183
      *uint_val = *double_val;
2175
      *uint_val = (unsigned int)*double_val;
2184
      break;
2176
      break;
2185
    default:
2177
    default:
2186
      fprintf (stderr, "get_stored_item: bad type = %d\n", type);
2178
      fprintf (stderr, "get_stored_item: bad type = %d\n", type);
2187
      exit (-1);
2179
      exit (-1);
2188
  }
2180
  }
Line 2260... Line 2252...
2260
      break;
2252
      break;
2261
    case PLY_FLOAT:
2253
    case PLY_FLOAT:
2262
      fread (ptr, 4, 1, fp);
2254
      fread (ptr, 4, 1, fp);
2263
      SWAP_TO_ENDIAN4(ptr, file_type);
2255
      SWAP_TO_ENDIAN4(ptr, file_type);
2264
      *double_val = *((float *) ptr);
2256
      *double_val = *((float *) ptr);
2265
      *int_val = *double_val;
2257
      *int_val = (int)*double_val;
2266
      *uint_val = *double_val;
2258
      *uint_val = (unsigned int)*double_val;
2267
      break;
2259
      break;
2268
    case PLY_DOUBLE:
2260
    case PLY_DOUBLE:
2269
      fread (ptr, 8, 1, fp);
2261
      fread (ptr, 8, 1, fp);
2270
      SWAP_TO_ENDIAN8(ptr, file_type);
2262
      SWAP_TO_ENDIAN8(ptr, file_type);
2271
      *double_val = *((double *) ptr);
2263
      *double_val = *((double *) ptr);
2272
      *int_val = *double_val;
2264
      *int_val = (int)*double_val;
2273
      *uint_val = *double_val;
2265
      *uint_val = (unsigned int)*double_val;
2274
      break;
2266
      break;
2275
    default:
2267
    default:
2276
      fprintf (stderr, "get_binary_item: bad type = %d\n", type);
2268
      fprintf (stderr, "get_binary_item: bad type = %d\n", type);
2277
      exit (-1);
2269
      exit (-1);
2278
  }
2270
  }
Line 2386... Line 2378...
2386
      puint = (unsigned int *) item;
2378
      puint = (unsigned int *) item;
2387
      *puint = uint_val;
2379
      *puint = uint_val;
2388
      break;
2380
      break;
2389
    case PLY_FLOAT:
2381
    case PLY_FLOAT:
2390
      pfloat = (float *) item;
2382
      pfloat = (float *) item;
2391
      *pfloat = double_val;
2383
      *pfloat = (float)double_val;
2392
      break;
2384
      break;
2393
    case PLY_DOUBLE:
2385
    case PLY_DOUBLE:
2394
      pdouble = (double *) item;
2386
      pdouble = (double *) item;
2395
      *pdouble = double_val;
2387
      *pdouble = double_val;
2396
      break;
2388
      break;
Line 2465... Line 2457...
2465
  nwords  - number of words in the list
2457
  nwords  - number of words in the list
2466
******************************************************************************/
2458
******************************************************************************/
2467
 
2459
 
2468
void add_property (PlyFile *plyfile, char **words, int nwords)
2460
void add_property (PlyFile *plyfile, char **words, int nwords)
2469
{
2461
{
2470
  int prop_type;
-
 
2471
  int count_type;
-
 
2472
  PlyProperty *prop;
2462
  PlyProperty *prop;
2473
  PlyElement *elem;
2463
  PlyElement *elem;
2474
 
2464
 
2475
  /* create the new property */
2465
  /* create the new property */
2476
 
2466
 
Line 2596... Line 2586...
2596
******************************************************************************/
2586
******************************************************************************/
2597
 
2587
 
2598
int 
2588
int 
2599
ply_is_valid_property(PlyFile *plyfile, char *elem_name, char *prop_name)
2589
ply_is_valid_property(PlyFile *plyfile, char *elem_name, char *prop_name)
2600
{
2590
{
2601
  int i;
-
 
2602
  PlyElement *elem;
2591
  PlyElement *elem;
2603
  PlyProperty *prop;
2592
  PlyProperty *prop;
2604
  int index;
2593
  int index;
2605
 
2594
 
2606
  /* find information about the element */
2595
  /* find information about the element */