Mercurial > hg > forks > gldragon
annotate ply2bin.cpp @ 30:1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 22 Nov 2019 09:49:06 +0200 |
parents | |
children | d0cd281934a3 |
rev | line source |
---|---|
30
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // ply2bin - Convert ASCII PLY file to binary PLY |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // (C) Copyright 2019 Tecnic Software productions (TNSP) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // See file "COPYING" for license information. |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 // |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include <SDL.h> |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmutil.h" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmmodel.h" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 bool dmFWriteFloatLE(FILE *fh, const float val) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 float tmp = SDL_SwapFloatLE(val); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 return fwrite(&tmp, sizeof(tmp), 1, fh) == 1; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 bool dmFWriteU32LE(FILE *fh, const Uint32 val) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 Uint32 tmp = SDL_SwapLE32(val); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 return fwrite(&tmp, sizeof(tmp), 1, fh) == 1; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 bool dmFWriteU8(FILE *fh, const Uint8 val) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 return fwrite(&val, sizeof(val), 1, fh) == 1; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 bool dmFWriteBINPLY(FILE *fh, const DMModel &model) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 bool writeNormals = model.normals.size() == (unsigned int) model.nvertices; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 fprintf(fh, |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 "ply\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 "format binary_little_endian 1.0\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 "element vertex %d\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 "property float x\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 "property float y\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 "property float z\n", |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 model.nvertices); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 if (writeNormals) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 fprintf(fh, |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 "property float nx\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 "property float ny\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 "property float nz\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 ); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 fprintf(fh, |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 "element face %d\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 "property list uchar uint vertex_indices\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 "end_header\n", |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 model.nfaces); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 for (int nvert = 0; nvert < model.nvertices; nvert++) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 const DMVector3 &vert = model.vertices[nvert]; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 if (!dmFWriteFloatLE(fh, vert.x) || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 !dmFWriteFloatLE(fh, vert.y) || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 !dmFWriteFloatLE(fh, vert.z)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 return false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 if (writeNormals) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 const DMVector3 &vert = model.normals[nvert]; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 if (!dmFWriteFloatLE(fh, vert.x) || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 !dmFWriteFloatLE(fh, vert.y) || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 !dmFWriteFloatLE(fh, vert.z)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 return false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 for (int nface = 0, offs = 0; nface < model.nfaces; nface++) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 if (!dmFWriteU8(fh, 3)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 return false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 for (int nvert = 0; nvert < 3; nvert++) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 if (!dmFWriteU32LE(fh, model.faces[offs++])) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 return false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 return true; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 int main(int argc, char *argv[]) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 bool |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 optShowHelp = false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 std::string optInputFilename, optOutputFilename; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 FILE *outFile = NULL; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 DMModel model; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 // Check commandline argument for enabling shaders |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 for (int narg = 1; narg < argc; narg++) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 char *arg = argv[narg]; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 if (arg[0] == '-') |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 char *opt = arg + 1; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 if ((opt[0] == '-' && opt[1] == 'h' && opt[2] == 'e') || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 opt[0] == '?' || (opt[0] == '-' && opt[1] == '?')) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 optShowHelp = true; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 break; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 if (opt[0] == '-') |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 opt++; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 switch (opt[0]) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 default: |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 printf("Unknown option '%s'.\n", opt); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 std::string tmp = std::string(arg); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 if (tmp.empty()) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 printf("ERROR: Invalid empty filename.\n"); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 if (optInputFilename.empty()) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 optInputFilename = tmp; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 if (optOutputFilename.empty()) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 optOutputFilename = tmp; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 printf("ERROR: Too many filenames specified.\n"); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 if (optInputFilename.empty() || optOutputFilename.empty() || optShowHelp) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 printf( |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 "ply2bin - Convert ASCII PLY file to binary format PLY\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 "Usage: %s [options] <input.ply> <output.ply>\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 "-? Show this help\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 "\n", |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 argv[0] |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 ); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 if (!model.loadFromPLY(optInputFilename)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 if ((outFile = fopen(optOutputFilename.c_str(), "wb")) == NULL) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 printf("ERROR: Could not create output file.\n"); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 printf("Writing output PLY ..\n"); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 if (!dmFWriteBINPLY(outFile, model)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 printf("ERROR: Error writing output PLY file.\n"); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 exit: |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 if (outFile != NULL) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 fclose(outFile); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 return 0; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 } |