@@ -169,7 +169,8 @@ void NormalsTask::run() {
169
169
bool proceed = progressed (" Adaptive mesh normal integration..." , 50 );
170
170
if (!proceed)
171
171
return ;
172
- QString filename = output.left (output.size () -4 ) + " .obj" ;
172
+ // TODO move to saveply
173
+ QString filename = output.left (output.size () -4 ) + " .ply" ;
173
174
174
175
assm (filename, normals, parameters.assm_error );
175
176
@@ -198,6 +199,56 @@ void NormalsTask::run() {
198
199
progressed (" Done" , 100 );
199
200
}
200
201
202
+ bool savePly (const char *filename, pmp::SurfaceMesh &mesh) {
203
+ QFile file (filename);
204
+ bool success = file.open (QFile::WriteOnly);
205
+ if (!success)
206
+ return false ;
207
+
208
+
209
+ std::vector<float > vertices;
210
+ for (auto vertex: mesh.vertices ()) {
211
+ auto p = mesh.position (vertex);
212
+ vertices.push_back (p[0 ]);
213
+ vertices.push_back (p[1 ]);
214
+ vertices.push_back (p[2 ]);
215
+ }
216
+ std::vector<uint8_t > indices;
217
+
218
+ int count =0 ;
219
+ for (auto face : mesh.faces ()) {
220
+ indices.resize (13 *(count+1 ));
221
+ uint8_t *start = &indices[13 *count];
222
+ start[0 ] = 3 ;
223
+ int *triangle = (int *)(start + 1 );
224
+
225
+ int i = 0 ;
226
+ for (auto vertex : mesh.vertices (face)) {
227
+ triangle[i++] = vertex.idx () + 1 ;
228
+ }
229
+ }
230
+
231
+ {
232
+ QTextStream stream (&file);
233
+
234
+ stream << " ply\n " ;
235
+ stream << " format binary_little_endian 1.0\n " ;
236
+ stream << " element vertex " << vertices.size ()/3 << " \n " ;
237
+ stream << " property float x\n " ;
238
+ stream << " property float y\n " ;
239
+ stream << " property float z\n " ;
240
+ stream << " element face " << indices.size ()/13 << " \n " ;
241
+ stream << " property list uchar int vertex_index\n " ;
242
+ stream << " end_header\n " ;
243
+ }
244
+
245
+
246
+ file.write ((const char *)vertices.data (), vertices.size ()*4 );
247
+ file.write ((const char *)indices.data (), indices.size ());
248
+ file.close ();
249
+ return true ;
250
+ }
251
+
201
252
bool saveObj (const char *filename, pmp::SurfaceMesh &mesh) {
202
253
FILE *fp = fopen (filename, " wb" );
203
254
if (!fp) {
@@ -244,7 +295,7 @@ void NormalsTask::assm(QString filename, vector<float> &_normals, float approx_e
244
295
pmp::Integration<double , pmp::Orthographic> integrator (remesher.mesh (), normals, mask);
245
296
integrator.run ();
246
297
247
- saveObj (filename.toStdString ().c_str (), remesher.mesh ());
298
+ savePly (filename.toStdString ().c_str (), remesher.mesh ());
248
299
}
249
300
250
301
0 commit comments