Mercurial > hg > forks > gldragon
annotate ply2bin.cpp @ 63:d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 14 Dec 2019 20:13:32 +0200 |
parents | 7b138613e2fc |
children | 03aa729a9e90 |
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> |
35 | 9 |
10 // Get rid of the SDL_main mess for some commandline tools | |
11 #define _SDL_main_h | |
12 #define SDL_main main | |
13 | |
30
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include "dmutil.h" |
61
7b138613e2fc
Rename dmmodel.* to dmscene.*
Matti Hamalainen <ccr@tnsp.org>
parents:
35
diff
changeset
|
15 #include "dmscene.h" |
30
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
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 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
|
19 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 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
|
21 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
|
22 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
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 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
|
26 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 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
|
28 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
|
29 } |
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 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
|
33 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 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
|
35 } |
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 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 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
|
39 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 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
|
41 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 fprintf(fh, |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 "ply\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 "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
|
45 "element vertex %d\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 "property float x\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 "property float y\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 "property float z\n", |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 model.nvertices); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 if (writeNormals) |
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 fprintf(fh, |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 "property float nx\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 "property float ny\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 "property float nz\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 ); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 fprintf(fh, |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 "element face %d\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 "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
|
63 "end_header\n", |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 model.nfaces); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 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
|
67 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 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
|
69 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 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
|
71 !dmFWriteFloatLE(fh, vert.y) || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 !dmFWriteFloatLE(fh, vert.z)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 return false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 if (writeNormals) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 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
|
78 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
|
79 !dmFWriteFloatLE(fh, vert.y) || |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 !dmFWriteFloatLE(fh, vert.z)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 return false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 } |
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 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
|
86 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 if (!dmFWriteU8(fh, 3)) |
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 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
|
91 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 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
|
93 return false; |
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 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 return true; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 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
|
102 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 bool |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 optShowHelp = false; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 std::string optInputFilename, optOutputFilename; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 FILE *outFile = NULL; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 DMModel model; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 // 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
|
110 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
|
111 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 char *arg = argv[narg]; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 if (arg[0] == '-') |
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 char *opt = arg + 1; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 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
|
118 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
|
119 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 optShowHelp = true; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 break; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 if (opt[0] == '-') |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 opt++; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 switch (opt[0]) |
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 default: |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 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
|
131 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 } |
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 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 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
|
137 if (tmp.empty()) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 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
|
140 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 if (optInputFilename.empty()) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 optInputFilename = tmp; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 else |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 if (optOutputFilename.empty()) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 optOutputFilename = tmp; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 else |
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 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
|
151 goto exit; |
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 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 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
|
157 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 printf( |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 "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
|
160 "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
|
161 "-? Show this help\n" |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 "\n", |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 argv[0] |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 ); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 } |
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 if (!model.loadFromPLY(optInputFilename)) |
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 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
|
173 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 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
|
175 goto exit; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 } |
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 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
|
179 if (!dmFWriteBINPLY(outFile, model)) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 { |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 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
|
182 } |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 exit: |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 if (outFile != NULL) |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 fclose(outFile); |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 return 0; |
1a0e823283e4
Add simple converter for converting ASCII ply files into binary format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 } |