File: manual.html

package info (click to toggle)
rply 1.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: ansic: 1,549; makefile: 24
file content (1137 lines) | stat: -rw-r--r-- 37,736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
<html>

<head>
<meta name="description" content="The RPly Homepage">
<meta name="keywords" content="open source, C, Library, PLY, file format,
input, output, tools">
<title>
RPly: ANSI C library for PLY file format input and output
</title>
<link rel="stylesheet" href="reference.css" type="text/css">
</head>

<body>

<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<div class=header>
<hr>
<center>
<table summary="RPly logo">
<tr><td align=center>
<img border=0 alt="RPly" src="rply.png">
</td></tr>
<tr><td align=center valign=top>ANSI C Library for PLY file format input and output
</td></tr>
</table>
</center>
<hr>
</div>


<!-- Introduction +++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<h1>Introduction</h1>

<p>RPly is a library that lets applications read and write PLY files.  The
PLY file format is widely used to store geometric information, such as 3D
models, but is general enough to be useful for other purposes.
</p>

<p>There are other libraries out there, of course. I tried using them and
finally decided to write my own. The result is RPly, and I
hope you are as happy with it as I am. </p>

<p>RPly is easy to use, well documented, small, free,
open-source, ANSI C, efficient, and well tested. I will keep supporting it
for a while because all my tools use the library for input/output. The highlights are: </p>
<ul>
<li> A callback mechanism that makes PLY file input straightforward;
<li> Support for the full range of numeric formats though the user only
deals with doubles;
<li> Binary (big and little endian) and text modes are fully supported;
<li> Input and output are buffered for efficiency;
<li> Available under the
<a href=http://www.opensource.org/licenses/mit-license.html>MIT license</a>
for added freedom.
</ul>

<p>
The format was developed at <a
href=http://graphics.stanford.edu/data/3Dscanrep/>Stanford University</a>
for use with their 3D scanning projects. Greg Turk's PLY library, available
from <a href=http://www.cc.gatech.edu/projects/large_models>
Georgia Institute of Technology</a>, seems to be the standard reference
to the PLY file format, although there are some variations out there.
</p>

<p> Whatever documentation and examples were found, were taken into
consideration to create RPly. In theory, since RPly doesn't try to interpret
the meaning of the data in a PLY file, it should be able to read any PLY file.
In practice, the library works with all PLY files that I could find.  </p>

<h2>Download</h2>

<p>
Version 1.1.4 of RPly is available for download in source
code from <a href=rply-1.1.4.tar.gz>this link</a>. Examples and documentation
are packed inside the tarball. Have fun!
</p>

<p>
Copyright &copy; 2003-2015 Diego Nehab. All rights reserved. <br>
Author: <A href="http://www.impa.br/~diego">Diego Nehab</a>
</p>

<h2>What's new?</h2>

<ul>
<li> Fixed bug that prevented reading of ASCII files that
are not terminated by a whitespace;
<li> Added <tt>ply_open_from_file</tt> and
<tt>ply_create_to_file</tt> variants to <tt>ply_open</tt>
and <tt>ply_create</tt>, respectively, that receive file
pointers instead of file names.
</ul>

<h2> RPly's idea of what a PLY file is </h2>

<p> A PLY file contains the description of one object. This object is
composed by <em>elements</em>, each element type
being defined by a group of <em>properties</em>.  The PLY file
format specifies a syntax for the description of element types and the
properties that compose them, as well as comments and meta-information.
</p>

<p> The element type descriptions come in a header, which is followed by
element instances. Element instances come grouped by their type, in the
order of declaration. Each element instance is defined by the value
of its properties. Properties values also appear in the order of their
declaration. Here is a sample PLY file describing a triangle: </p>

<pre class=example>
ply
format ascii 1.0
comment this is a simple file
obj_info any data, in one line of free form text
element vertex 3
property float x
property float y
property float z
element face 1
property list uchar int vertex_indices
end_header
-1 0 0
 0 1 0
 1 0 0
3 0 1 2
</pre>

<p> The header goes from the first line to the line marked by
<tt>end_header</tt>.  The first line contains only <tt>ply\n</tt> and is
used to detect whether a file is in PLY format or not (RPly
also accepts files that start with <tt>ply\r\n</tt>, in
which case the end-of-line terminator is assumed to be
<tt>\r\n</tt> throughout.)  The second line
specifies the <tt>format</tt> number (which is always <tt>1.0</tt>) and the
storage mode (<tt>ascii</tt>, <tt>binary_big_endian</tt> or
<tt>binary_little_endian</tt>).  </p>

<p> Lines that start with <tt>comment</tt> are just comments, of course.
Lines that start with <tt>obj_info</tt> contain meta-information about the
object.  <tt>Comment</tt>s and <tt>obj_info</tt>s are optional and their
relative order in the header is irrelevant. </p>

<p> In the sample PLY file, the first element type is declared with name
<tt>vertex</tt>, and on the same line we learn that there will be 3
instances of this element type.  The properties following describe what a
<tt>vertex</tt> element looks like.  Each <tt>vertex</tt> is declared to
consist of 3 scalar properties, named <tt>x</tt>, <tt>y</tt> and
<tt>z</tt>.  Each scalar property is declared to be of type <tt>float</tt>.
</p>

<p> Scalar types can be any of the following: <tt>int8</tt>,
<tt>uint8</tt>, <tt>int16</tt>, <tt>uint16</tt>, <tt>int32</tt>,
<tt>uint32</tt>, <tt>float32</tt>, <tt>float64</tt>, <tt>char</tt>,
<tt>uchar</tt>, <tt>short</tt>, <tt>ushort</tt>, <tt>int</tt>,
<tt>uint</tt>, <tt>float</tt>, <tt>double</tt>. They consist of signed
and unsigned integer types of sizes 8, 16 and 32 bits, as well as floating
point types of 32 and 64bits.

<p> Next, the <tt>face</tt> element type is declared, of which only 1
instance will be given. This element consists of a <tt>list</tt> property,
named <tt>vertex_indices</tt>. Lists are sequences on which the
first value, the <em>length</em>, gives the number of remaining values. List properties are described by the scalar
type of their length field and the scalar type of the remaining fields.
In the case of <tt>vertex_indices</tt>, the length field
is of type <tt>uchar</tt> and the remaining values are of type
<tt>int</tt>. </p>

<p> Following the header, come the elements, in the order they were
declared in the header.  First come the 3 elements of type <tt>vertex</tt>,
each represented by the value of their properties <tt>x</tt>, <tt>y</tt>
and <tt>z</tt>. Then comes the single <tt>face</tt> element, composed by a
single list of type <tt>vertex_indices</tt> containing 3 values
(0 1 2).</p>

<h2> How to read a file with RPly </h2>

<p> Most users that want to read a PLY file already know which elements and
properties they are interested in. In the following example, we will
implement a simple program that dumps the contents of a PLY file to the
terminal, in a different, simpler format that only works for triangles.
</p>

<p> This simple format has a header that gives the number of vertices in the
first line and the number of triangles in the second line. Following the
header come the vertices, and finally the triangles. Here is the sample
code for the program:</p>

<pre class=example>
#include &lt;stdio.h&gt;
#include "rply.h"

static int vertex_cb(p_ply_argument argument) {
    long eol;
    ply_get_argument_user_data(argument, NULL, &amp;eol);
    printf("%g", ply_get_argument_value(argument));
    if (eol) printf("\n");
    else printf(" ");
    return 1;
}

static int face_cb(p_ply_argument argument) {
    long length, value_index;
    ply_get_argument_property(argument, NULL, &amp;length, &amp;value_index);
    switch (value_index) {
        case 0:
        case 1:
            printf("%g ", ply_get_argument_value(argument));
            break;
        case 2:
            printf("%g\n", ply_get_argument_value(argument));
            break;
        default:
            break;
    }
    return 1;
}

int main(void) {
    long nvertices, ntriangles;
    p_ply ply = ply_open("input.ply", NULL, 0, NULL);
    if (!ply) return 1;
    if (!ply_read_header(ply)) return 1;
    nvertices = ply_set_read_cb(ply, "vertex", "x", vertex_cb, NULL, 0);
    ply_set_read_cb(ply, "vertex", "y", vertex_cb, NULL, 0);
    ply_set_read_cb(ply, "vertex", "z", vertex_cb, NULL, 1);
    ntriangles = ply_set_read_cb(ply, "face", "vertex_indices", face_cb, NULL, 0);
    printf("%ld\n%ld\n", nvertices, ntriangles);
    if (!ply_read(ply)) return 1;
    ply_close(ply);
    return 0;
}
</pre>

<p> RPly uses callbacks to pass data to an application. Independent callbacks
can be  associated with each property of each element. For scalar
properties, the callback is invoked once for each instance. For list
properties, the callback is invoked first with the number of
entries in the instance, and then once for each of the data entries.
<em>This is exactly the order in which the data items appear in the
file.</em></p>

<p> To keep things simple, values are always passed as <tt>double</tt>,
regardless of how they are stored in the file. From its parameters,
callbacks can find out exactly which part of the file is being processed
(including the actual type of the value), plus access custom information
provided by the user in the form of a pointer and an integer constant. </p>

<p> In our example, we start with a call to <tt>ply_open</tt> to open a
file for reading. Then we get RPly to parse it's header, with a call to
<tt>ply_read_header</tt>.  After the header is parsed, RPly knows which
element types and properties are available. We then set callbacks for each
of the <tt>vertex</tt> element properties and the <tt>face</tt> property
(using <tt>ply_set_read_cb</tt>). Finally, we invoke the main RPly reading
function, <tt>ply_read</tt>. This function reads all data in the file,
passing the data to the appropriate callbacks.  After all reading is done,
we call <tt>ply_close</tt> to release any resources used by RPly.</p>

<p>There are some details, of course. <tt>Ply_set_read_cb</tt> returns the
number of instances of the target property (which is the same as the number
of element instances).  This is how the program obtains the number of
vertices and faces in the file. </p>

<p>RPly lets us associate one pointer <em>and</em> one integer to each
callback.  We are free to use either or both to link some context to our
callbacks. Our example uses the integer placeholder to tell
<tt>vertex_cb</tt> that it has to break the line after the <tt>z</tt>
property (notice the last argument of <tt>ply_set_read_cb</tt>).</p>

<p><tt>Vertex_cb</tt> gets the user data and the property value from it's
argument and prints accordingly.  The <tt>face_cb</tt> callback is a bit
more complicated because lists are more complicated.  Since the
simple file format only supports triangles, it only prints the first
3 list values, after which it breaks the line. </p>

<p> The output of the program, as expected, is: </p>

<pre class=example>
3
1
-1 0 0
0 1 0
1 0 0
0 1 2
</pre>

<h2> Writing files with RPly </h2>

<p> The next example is somewhat more involved. We will create a program
that converts our simple PLY file to binary mode. Besides showing how to
write a PLY file, this example also illustrates the query functions. We
do not know a priori which elements and properties, comments and obj_infos
will be in the input file, so we need a way to find out. Although our simple
program would work on any PLY file, a better version of this program is
available from the RPly distribution. For simplicity, the simple version
omits error messages and command line parameter processing. </p>

<p> In practice, writing a file is even easier than reading one. First we
create a file in binary mode, with a call to <tt>ply_create</tt> (notice
the argument <tt>PLY_LITTLE_ENDIAN</tt> that gives the storage mode).  Then,
we define the elements using <tt>ply_add_element</tt>. After each element, we
define its properties using <tt>ply_add_scalar_property</tt> or
<tt>ply_add_list_property</tt>. When we are done with elements and
properties, we add comments and obj_infos. We then write the header with
<tt>ply_write_header</tt> and send all data items. The data items are sent
one by one, with calls to <tt>ply_write</tt>, <em>in the same order they
are to appear in the file</em>.  Again, to simplify things, this function
receives data as <tt>double</tt> and performs the needed conversion. Here
is the code for the example: </p>

<pre class=example>
#include &lt;stdio.h&gt;
#include "rply.h"

static int callback(p_ply_argument argument) {
    void *pdata;
    /* just pass the value from the input file to the output file */
    ply_get_argument_user_data(argument, &amp;pdata, NULL);
    ply_write((p_ply) pdata, ply_get_argument_value(argument));
    return 1;
}

static int setup_callbacks(p_ply iply, p_ply oply) {
    p_ply_element element = NULL;
    /* iterate over all elements in input file */
    while ((element = ply_get_next_element(iply, element))) {
        p_ply_property property = NULL;
        long ninstances = 0;
        const char *element_name;
        ply_get_element_info(element, &amp;element_name, &amp;ninstances);
        /* add this element to output file */
        if (!ply_add_element(oply, element_name, ninstances)) return 0;
        /* iterate over all properties of current element */
        while ((property = ply_get_next_property(element, property))) {
            const char *property_name;
            e_ply_type type, length_type, value_type;
            ply_get_property_info(property, &amp;property_name, &amp;type,
                    &amp;length_type, &amp;value_type);
            /* setup input callback for this property */
            if (!ply_set_read_cb(iply, element_name, property_name, callback,
                    oply, 0)) return 0;
            /* add this property to output file */
            if (!ply_add_property(oply, property_name, type, length_type,
                    value_type)) return 0;
        }
    }
    return 1;
}

int main(int argc, char *argv[]) {
    const char *value;
    p_ply iply, oply;
    iply = ply_open("input.ply", NULL, 0, NULL);
    if (!iply) return 1;
    if (!ply_read_header(iply)) return 1;
    oply = ply_create("output.ply", PLY_LITTLE_ENDIAN, NULL, 0, NULL);
    if (!oply) return 1;
    if (!setup_callbacks(iply, oply)) return 1;
    /* pass comments and obj_infos from input to output */
    value = NULL;
    while ((value = ply_get_next_comment(iply, value)))
        if (!ply_add_comment(oply, value)) return 1;
    value = NULL;
    while ((value = ply_get_next_obj_info(iply, value)))
        if (!ply_add_obj_info(oply, value)) return 1;;
    /* write output header */
    if (!ply_write_header(oply)) return 1;
    /* read input file generating callbacks that pass data to output file */
    if (!ply_read(iply)) return 1;
    /* close up, we are done */
    if (!ply_close(iply)) return 1;
    if (!ply_close(oply)) return 1;
    return 0;
}
</pre>

<p> RPly uses iterators to let the user loop over a PLY file header. A
function is used to  get the first item of a given class (element, property
etc). Passing the last returned item to the same function produces the next
item, until there are no more items. Examples of iterator use can be seen
in the <tt>main</tt> function, which uses them to loop over comments and
obj_infos, and in the <tt>setup_callbacks</tt> function, which loops over
elements and properties. </p>

<p> In the <tt>setup_callbacks</tt> function, for each element in the
input, an equivalent element is defined in the output. For each property in
each element, an equivalent property is defined in the output. Notice that
the same callback is specified for all properties. It is given the output
PLY handle as the context pointer. Each time it is called, it  passes the
received value to <tt>ply_write</tt> on the output handle. It is as simple
as that. </p>

<h2> A note on locale </h2>

<p> ASCII PLY files are supposed to use the <tt>C</tt>
locale for numeric formatting. RPly relies on library
functions (such as <tt>fprintf</tt> and <tt>strtod</tt>)
that are affected by the current locale. If your software
modifies the locale (or if it uses another library/toolkit that
does) and you use RPly under the modified locale, you may be
unable to read or write properly formatted ASCII PLY files.
</p>

<p> Modifying RPly internally to hedge against different
locales would be complicated, particularly in multi-threaded
applications.  Therefore, RPly leaves this as your
responsibility. To protect against locale problems in the
simplest scenario, you should bracket RPly I/O as follows: </p>

<pre class="example">
#include &lt;locale.h&gt;
/* Save application locale */
const char *old_locale = setlocale(LC_NUMERIC, NULL);
/* Change to PLY standard */
setlocale(LC_NUMERIC, "C");
/* Use the RPly library */
...

/* Restore application locale when done */
setlocale(LC_NUMERIC, old_locale);
</pre>

<h1>Reference Manual</h1>

<!-- ply_open ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_open>
p_ply <b>ply_open</b>(const char *name, p_ply_error_cb error_cb, long idata, void *pdata)
</p>

<p class=description>
Opens a PLY file for reading, checks if it is a valid PLY file
and returns a handle to it.
</p>

<p class=arguments>
<tt>Name</tt> is the file name, and <tt>error_cb</tt> is a function to
be called when an error is found.
Arguments <tt>idata</tt>
and <tt>pdata</tt> are available to the error callback via the
<a href=#ply_get_ply_user_data><tt>ply_get_ply_user_data</tt></a>
function.
If <tt>error_cb</tt> is NULL, the default
error callback is used. It prints a message to the standard error stream.
</p>

<p class=return>
Returns a handle to the file or NULL on error.
</p>

<p class=note>
Note: <tt>Error_cb</tt> is of type <tt>void
    (*p_ply_error_cb)(p_ply ply, const char *message)</tt>.
</p>

<!-- ply_open_from_file ++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_open_from_file>
p_ply <b>ply_open_from_file</b>(FILE *file_pointer, p_ply_error_cb error_cb, long idata, void *pdata)
</p>

<p class=description>
Checks if the FILE pointer points to a valid PLY file and returns a
handle to it. The handle can be used wherever a handle returned by <a
href=#ply_open><tt>ply_open</tt></a> is accepted.
</p>

<p class=arguments>
<tt>File_pointer</tt> is the FILE pointer open for reading, and <tt>error_cb</tt> is a function to be called when an error is found.
Arguments <tt>idata</tt>
and <tt>pdata</tt> are available to the error callback via the
<a href=#ply_get_ply_user_data><tt>ply_get_ply_user_data</tt></a>
function.
If <tt>error_cb</tt> is NULL, the default
error callback is used. It prints a message to the standard error stream.
</p>

<p class=return>
Returns a handle to the file or NULL on error.
</p>

<p class=note>
Note: <tt>Error_cb</tt> is of type <tt>void
    (*p_ply_error_cb)(p_ply ply, const char *message)</tt>.
</p>

<p class=note>
Note: This function is declared in header <tt>rplyfile.h</tt>.
</p>

<!-- ply_get_ply_user_data ++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_ply_user_data>
int <b>ply_get_ply_user_data</b>(p_ply_ply ply, void *pdata, long *idata)
</p>

<p class=description>
Retrieves user data from the ply handle.
</p>

<p class=arguments>
<tt>Ply</tt> is the handle passed to the error callback.
<tt>Pdata</tt> receives the user data pointer.
<tt>Idata</tt> receives the user data integer.
<tt>Pdata</tt> and <tt>idata</tt> can be NULL.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>


<!-- ply_read_header +++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_read_header>
int <b>ply_read_header</b>(p_ply ply)
</p>

<p class=description>
Reads and parses the header of a PLY file.
After a call to this function, the query functions
<a href=#ply_get_next_element><tt>ply_get_next_element</tt></a>,
<a href=#ply_get_next_property><tt>ply_get_next_property</tt></a>,
<a href=#ply_get_next_comment><tt>ply_get_next_comment</tt></a>, and
<a href=#ply_get_next_obj_info><tt>ply_get_next_obj_info</tt></a> can be
called. Callbacks can also be set with the
<a href=#ply_set_read_cb><tt>ply_set_read_cb</tt></a> function.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by <a
href=#ply_open><tt>ply_open</tt></a>.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_set_read_cb +++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_set_read_cb>
long <b>ply_set_read_cb</b>(<br>
&nbsp;&nbsp; p_ply ply,<br>
&nbsp;&nbsp; const char *element_name,<br>
&nbsp;&nbsp; const char *property_name,<br>
&nbsp;&nbsp; p_ply_read_cb read_cb,<br>
&nbsp;&nbsp; void *pdata,<br>
&nbsp;&nbsp; long idata<br>
)
</p>

<p class=description>
Sets up the callback to be invoked when the value of a property is read.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<tt>Element_name</tt> and <tt>property_name</tt> are the names of the
element and property of interest. <tt>Read_cb</tt> is the callback
function.  <tt>Pdata</tt> and <tt>idata</tt> are user data to be passed to
the callback function.
</p>

<p class=return>
Returns the number of instances of the element of interest.
</p>

<p class=note>
Note: <tt>Read_cb</tt> is of type
<tt>int (*p_ply_read_cb)(p_ply_argument argument)</tt>.
The callback should return 1 to continue the reading process,
or return 0 to abort.

<!-- ply_get_argument_element ++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_argument_element>
int <b>ply_get_argument_element</b>(<br>
&nbsp;&nbsp; p_ply_argument argument,<br>
&nbsp;&nbsp; p_ply_element *element,<br>
&nbsp;&nbsp; long *instance_index<br>
)
</p>

<p class=description>
Retrieves element information from the callback argument.
</p>

<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
<tt>Element</tt> receives a handle to the element
originating the callback. <tt>Instance_index</tt> receives
the index of the instance of the element
being read. <tt>Element</tt> and <tt>instance_index</tt> can be NULL.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<p class=note>
Note: further information can be obtained from <tt>element</tt> with a
call to <a href=#ply_get_element_info>ply_get_element_info</a>.
</p>

<!-- ply_get_argument_property +++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_argument_property>
int <b>ply_get_argument_property</b>(<br>
&nbsp;&nbsp; p_ply_argument argument,<br>
&nbsp;&nbsp; p_ply_property *property,<br>
&nbsp;&nbsp; long *length,<br>
&nbsp;&nbsp; long *value_index<br>
)
</p>

<p class=description>
Retrieves property information from the callback argument.
</p>

<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
<tt>Property</tt> receives a handle to the property
originating the callback. <tt>Length</tt> receives the number
of values in the list property (1 for scalar properties).
<tt>Value_index</tt> receives the index of the current property entry (0 for
scalar properties, -1 for the first value of a list property, the one that
gives the number of entries). <tt>Property</tt>, <tt>length</tt> and
<tt>value_index</tt> can be NULL.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<p class=note>
Note: further information can be obtained from <tt>property</tt> with a
call to <a href=#ply_get_property_info>ply_get_property_info</a>.
</p>

<!-- ply_get_argument_user_data +++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_argument_user_data>
int <b>ply_get_argument_user_data</b>(p_ply_argument argument, void *pdata,
        long *idata)
</p>

<p class=description>
Retrieves the user data from the callback argument.
</p>

<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
<tt>Pdata</tt> receives the user data pointer.
<tt>Idata</tt> receives the user data integer.
<tt>Pdata</tt> and <tt>idata</tt> can be NULL.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_get_argument_value +++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_argument_value>
double <b>ply_get_argument_value</b>(p_ply_argument argument)
</p>

<p class=description>
Retrieves the property value from the callback argument.
</p>

<p class=arguments>
<tt>Argument</tt> is the handle passed to the callback.
</p>

<p class=return>
Returns the property value.
</p>

<!-- ply_read +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_read>
int <b>ply_read</b>(p_ply ply)
</p>

<p class=description>
Reads all data in file, calling appropriate callbacks.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_get_next_element ++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_next_element>
p_ply_element <b>ply_get_next_element</b>(p_ply ply, p_ply_element last)
</p>

<p class=description>
Iterates over all elements on the header of a PLY file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<a href=#ply_read_header><tt>Ply_read_header</tt></a> must have been called
on the handle otherwise no elements will be found.
<tt>Last</tt> is NULL to retrieve the first element, and an element to
retrieve the next element.
</p>

<p class=return>
Returns the next element, or NULL if no more elements.
</p>

<p class=note>
Note: further information can be obtained from an element with a
call to <a href=#ply_get_element_info>ply_get_element_info</a>.
</p>

<!-- ply_get_next_property +++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_next_property>
p_ply_property <b>ply_get_next_property</b>(p_ply_element element, p_ply_property last)
</p>

<p class=description>
Iterates over all properties of an element.
</p>

<p class=arguments>
<tt>Element</tt> is an element handle.
<tt>Last</tt> is NULL to retrieve the first property, and a property to
retrieve the next property.
</p>

<p class=return>
Returns the next property, or NULL if no more properties.
</p>

<p class=note>
Note: further information can be obtained from a property with a
call to <a href=#ply_get_property_info>ply_get_property_info</a>.
</p>

<!-- ply_get_next_comment ++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_next_comment>
const char *<b>ply_get_next_comment</b>(p_ply ply, const char *last)
</p>

<p class=description>
Iterates over all comments on the header of a PLY file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<a href=#ply_read_header><tt>Ply_read_header</tt></a> must have been called
on the handle otherwise no comments will be found.
<tt>Last</tt> is NULL to retrieve the first comment, and a comment to
retrieve the next comment.
</p>

<p class=return>
Returns the next comment, or NULL if no more comments.
</p>

<!-- ply_get_next_obj_info +++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_next_obj_info>
const char *<b>ply_get_next_obj_info</b>(p_ply ply, const char *last)
</p>

<p class=description>
Iterates over all obj_infos on the header of a PLY file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by <a href=#ply_open><tt>ply_open</tt></a>.
<a href=#ply_read_header><tt>Ply_read_header</tt></a> must have been called
on the handle otherwise no obj_infos will be found.
<tt>Last</tt> is NULL to retrieve the first obj_info, and a obj_info to
retrieve the next obj_info.
</p>

<p class=return>
Returns the next obj_info, or NULL if no more obj_infos.
</p>

<!-- ply_get_element_info ++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_element_info>
int <b>ply_get_element_info</b>(p_ply_element element, const char** name,
        long *ninstances)
</p>

<p class=description>
Retrieves information from an element handle.
</p>

<p class=arguments>
<tt>Element</tt> is the handle of the element of interest.
<tt>Name</tt> receives the internal copy of the element name.
<tt>Ninstances</tt> receives the number of instances of this element
in the file. Both <tt>name</tt> and <tt>ninstances</tt> can be NULL.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_get_property_info +++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_get_property_info>
int <b>ply_get_property_info</b>(<br>
&nbsp;&nbsp; p_ply_property property,<br>
&nbsp;&nbsp; const char** name,<br>
&nbsp;&nbsp; e_ply_type *type,<br>
&nbsp;&nbsp; e_ply_type *length_type,<br>
&nbsp;&nbsp; e_ply_type *value_type<br>
)
</p>

<p class=description>
Retrieves information from a property handle.
</p>

<p class=arguments>
<tt>Property</tt> is the handle of the property of interest.
<tt>Name</tt> receives the internal copy of the property name.
<tt>Type</tt> receives the property type.
<tt>Length_type</tt> receives the scalar type of the first entry
in a list property (the one that gives the number of entries).
<tt>Value_type</tt> receives the scalar type of the remaining list entries.
<tt>Name</tt>, <tt>type</tt>, <tt>length_type</tt>, and
<tt>value_type</tt> can be NULL.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<p class=note>
Note: <tt>Length_type</tt> and <tt>value_type</tt> can
receive any of the constants for scalar types defined in
<tt>e_ply_type</tt>. <tt>Type</tt> can, in addition, be <tt>PLY_LIST</tt>,
in which case the property is a list property and the fields
<tt>length_type</tt> and <tt>value_type</tt> become meaningful.
</p>

<!-- ply_create ++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_create>
p_ply <b>ply_create</b>(const char *name, e_ply_storage_mode storage_mode,
        p_ply_error_cb error_cb)
</p>

<p class=description>
Creates a PLY file for writing.
</p>

<p class=arguments>
<tt>Name</tt> is the file name, <tt>storage_mode</tt> is the file storage mode
(<tt>PLY_ASCII</tt>, <tt>PLY_LITTLE_ENDIAN</tt>,
<tt>PLY_BIG_ENDIAN</tt>, or <tt>PLY_DEFAULT</tt> to
automatically detect host endianess).
<tt>Error_cb</tt> is a function to be called when an error is found.
Arguments <tt>idata</tt>
and <tt>pdata</tt> are available to the error callback via the
<a href=#ply_get_ply_user_data><tt>ply_get_ply_user_data</tt></a>
function.
If <tt>error_cb</tt> is NULL, the default
error callback is used. It prints a message to the standard error stream.
</p>

<p class=return>
Returns a handle to the file or NULL on error.
</p>

<p class=note>
Note: <tt>Error_cb</tt> is of type <tt>void
    (*p_ply_error_cb)(const char *message)</tt>
</p>

<!-- ply_create_to_file ++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_create_to_file>
p_ply <b>ply_create_to_file</b>(FILE *file_pointer, e_ply_storage_mode storage_mode, p_ply_error_cb error_cb)
</p>

<p class=description>
Creates a PLY file to be written to a FILE pointer and
returns a handle to it.
The handle can be used wherever a handle returned by <a
href=#ply_create><tt>ply_create</tt></a> is accepted.
</p>

<p class=arguments>
<tt>File_pointer</tt> a pointer to a file open for writing, <tt>storage_mode</tt> is the file storage mode
(<tt>PLY_ASCII</tt>, <tt>PLY_LITTLE_ENDIAN</tt>,
<tt>PLY_BIG_ENDIAN</tt>, or <tt>PLY_DEFAULT</tt> to
automatically detect host endianess).
<tt>Error_cb</tt> is a function to be called when an error is found.
Arguments <tt>idata</tt>
and <tt>pdata</tt> are available to the error callback via the
<a href=#ply_get_ply_user_data><tt>ply_get_ply_user_data</tt></a>
function.
If <tt>error_cb</tt> is NULL, the default
error callback is used. It prints a message to the standard error stream.
</p>

<p class=return>
Returns a handle to the file or NULL on error.
</p>

<p class=note>
Note: <tt>Error_cb</tt> is of type <tt>void
    (*p_ply_error_cb)(const char *message)</tt>
</p>

<p class=note>
Note: This function is declared in header <tt>rplyfile.h</tt>.
</p>

<!-- ply_add_element +++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_add_element>
int <b>ply_add_element</b>(p_ply ply, const char *name, long ninstances)
</p>

<p class=description>
Adds a new element to the ply file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a>, <tt>name</tt> is the element
name and <tt>ninstances</tt> is the number of instances of this element that
will be written to the file.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_add_property ++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_add_property>
int <b>ply_add_property</b>(<br>
&nbsp;&nbsp; p_ply ply,<br>
&nbsp;&nbsp; const char *name,<br>
&nbsp;&nbsp; e_ply_type type,<br>
&nbsp;&nbsp; e_ply_type length_type,<br>
&nbsp;&nbsp; e_ply_type value_type<br>
)
</p>

<p class=description>
Adds a new property to the last element added to the ply file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>name</tt> is the
property name.
<tt>Type</tt> is the property type.
<tt>Length_type</tt> is the scalar type of the first entry
in a list property (the one that gives the number of entries).
<tt>Value_type</tt> is the scalar type of the remaining list entries.
If <tt>type</tt> is not <tt>PLY_LIST</tt>, <tt>length_type</tt> and
<tt>value_type</tt> are ignored.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<p class=note>
Note: <tt>Length_type</tt> and <tt>value_type</tt> can
be any of the constants for scalar types defined in
<tt>e_ply_type</tt>. <tt>Type</tt> can, in addition, be <tt>PLY_LIST</tt>,
in which case the property is a list property and the fields
<tt>length_type</tt> and <tt>value_type</tt> become meaningful.
</p>

<!-- ply_add_list_property ++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_add_list_property>
int <b>ply_add_list_property</b>(<br>
&nbsp;&nbsp; p_ply ply,<br>
&nbsp;&nbsp; const char *name,<br>
&nbsp;&nbsp; e_ply_type length_type,<br>
&nbsp;&nbsp; e_ply_type value_type<br>
)
</p>

<p class=description>
Same as <a href=#ply_add_property><tt>ply_add_property</tt></a> if
<tt>type</tt> is <tt>PLY_LIST</tt>.
</p>

<!-- ply_add_scalar_property +++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_add_scalar_property>
int <b>ply_add_scalar_property</b>(p_ply ply, const char *name, e_ply_type type)
</p>

<p class=description>
Same as <a href=#ply_add_property><tt>ply_add_property</tt></a> if
<tt>type</tt> is <em>not</em> <tt>PLY_LIST</tt>.
</p>

<!-- ply_add_comment +++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_add_comment>
int <b>ply_add_comment</b>(p_ply ply, const char *comment);
</p>

<p class=description>
Adds a comment to a PLY file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>comment</tt> is the
comment text.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_add_obj_info ++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_add_obj_info>
int <b>ply_add_obj_info</b>(p_ply ply, const char *obj_info);
</p>

<p class=description>
Adds a obj_info to a PLY file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>obj_info</tt> is the
obj_info text.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_write_header ++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_write_header>
int <b>ply_write_header</b>(p_ply ply);
</p>

<p class=description>
Writes the PLY file header to disk, after all elements, properties,
comments and obj_infos have been added to the handle.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>comment</tt> is the
comment text.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_write +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_write>
int <b>ply_write</b>(p_ply ply, double value);
</p>

<p class=description>
Passes a value to be stored in the PLY file.
Values must be passed in the order they will appear in the file.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> and <tt>value</tt> is the
value to be stored.  For simplicity, values are always passed as
<tt>double</tt> and conversion is performed as needed.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- ply_close +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<p class=name id=ply_close>
int <b>ply_close</b>(p_ply ply);
</p>

<p class=description>
Closes the handle and ensures that all resources have been freed and data
have been written.
</p>

<p class=arguments>
<tt>Ply</tt> is a handle returned by
<a href=#ply_create><tt>ply_create</tt></a> or by
<a href=#ply_open><tt>ply_open</tt></a>.
</p>

<p class=return>
Returns 1 in case of success, 0 otherwise.
</p>

<!-- footer ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

<div class=footer>
<hr>
<center>
<p>
<small>
Last modified by Diego Nehab on <br>
Fri Aug 21 17:11:09 BRT 2015
</small>
</p>
</center>
</div>

</body>
</html>