| 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 |
#ifndef __VCGLIB_EXPORT_PLY |
| 131 |
#define __VCGLIB_EXPORT_PLY |
| 132 |
|
| 133 |
|
| 134 |
#include<wrap/io_trimesh/io_mask.h> |
| 135 |
#include<wrap/io_trimesh/io_ply.h> |
| 136 |
#include<vcg/container/simple_temporary_data.h> |
| 137 |
|
| 138 |
|
| 139 |
#include <stdio.h> |
| 140 |
|
| 141 |
namespace vcg { |
| 142 |
namespace tri { |
| 143 |
namespace io { |
| 144 |
|
| 145 |
|
| 146 |
template <class SaveMeshType> |
| 147 |
class ExporterPLY |
| 148 |
{ |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
template <class StoType> |
| 156 |
static void PlyConv(int mem_type, void *src, StoType &dest) |
| 157 |
{ |
| 158 |
switch (mem_type){ |
| 159 |
case ply::T_FLOAT : dest = (StoType) (* ((float *) src)); break; |
| 160 |
case ply::T_DOUBLE: dest = (StoType) (* ((double *) src)); break; |
| 161 |
case ply::T_INT : dest = (StoType) (* ((int *) src)); break; |
| 162 |
case ply::T_SHORT : dest = (StoType) (* ((short *) src)); break; |
| 163 |
case ply::T_CHAR : dest = (StoType) (* ((char *) src)); break; |
| 164 |
case ply::T_UCHAR : dest = (StoType) (* ((unsigned char *)src)); break; |
| 165 |
default : assert(0); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
public: |
| 170 |
typedef ::vcg::ply::PropDescriptor PropDescriptor ; |
| 171 |
typedef typename SaveMeshType::VertexPointer VertexPointer; |
| 172 |
typedef typename SaveMeshType::ScalarType ScalarType; |
| 173 |
typedef typename SaveMeshType::VertexType VertexType; |
| 174 |
typedef typename SaveMeshType::FaceType FaceType; |
| 175 |
typedef typename SaveMeshType::FacePointer FacePointer; |
| 176 |
typedef typename SaveMeshType::VertexIterator VertexIterator; |
| 177 |
typedef typename SaveMeshType::FaceIterator FaceIterator; |
| 178 |
|
| 179 |
static int Save(SaveMeshType &m, const char * filename, bool binary=true) |
| 180 |
{ |
| 181 |
PlyInfo pi; |
| 182 |
return Save(m,filename,binary,pi); |
| 183 |
} |
| 184 |
|
| 185 |
static int Save(SaveMeshType &m, const char * filename, int savemask, CallBackPos *cb=0 ) |
| 186 |
{ |
| 187 |
PlyInfo pi; |
| 188 |
pi.mask=savemask; |
| 189 |
return Save(m,filename,true,pi,cb); |
| 190 |
} |
| 191 |
|
| 192 |
static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &pi, CallBackPos *cb=0) |
| 193 |
{ |
| 194 |
FILE * fpout; |
| 195 |
int i; |
| 196 |
|
| 197 |
const char * hbin = "binary_little_endian"; |
| 198 |
const char * hasc = "ascii"; |
| 199 |
const char * h; |
| 200 |
|
| 201 |
bool multit = false; |
| 202 |
|
| 203 |
if(binary) h=hbin; |
| 204 |
else h=hasc; |
| 205 |
|
| 206 |
fpout = fopen(filename,"wb"); |
| 207 |
if(fpout==NULL) { |
| 208 |
pi.status=::vcg::ply::E_CANTOPEN; |
| 209 |
return ::vcg::ply::E_CANTOPEN; |
| 210 |
} |
| 211 |
fprintf(fpout, |
| 212 |
"ply\n" |
| 213 |
"format %s 1.0\n" |
| 214 |
"comment VCGLIB generated\n" |
| 215 |
,h |
| 216 |
); |
| 217 |
|
| 218 |
if( pi.mask & Mask::IOM_WEDGTEXCOORD ) |
| 219 |
{ |
| 220 |
const char * TFILE = "TextureFile"; |
| 221 |
|
| 222 |
for(i=0; i < static_cast<int>(m.textures.size()); ++i) |
| 223 |
fprintf(fpout,"comment %s %s\n", TFILE, (const char *)(m.textures[i].c_str()) ); |
| 224 |
|
| 225 |
if(m.textures.size()>1 && (m.HasPerWedgeTexCoord() || m.HasPerVertexTexCoord())) multit = true; |
| 226 |
} |
| 227 |
|
| 228 |
if((pi.mask & Mask::IOM_CAMERA)) |
| 229 |
{ |
| 230 |
fprintf(fpout, |
| 231 |
"element camera 1\n" |
| 232 |
"property float view_px\n" |
| 233 |
"property float view_py\n" |
| 234 |
"property float view_pz\n" |
| 235 |
"property float x_axisx\n" |
| 236 |
"property float x_axisy\n" |
| 237 |
"property float x_axisz\n" |
| 238 |
"property float y_axisx\n" |
| 239 |
"property float y_axisy\n" |
| 240 |
"property float y_axisz\n" |
| 241 |
"property float z_axisx\n" |
| 242 |
"property float z_axisy\n" |
| 243 |
"property float z_axisz\n" |
| 244 |
"property float focal\n" |
| 245 |
"property float scalex\n" |
| 246 |
"property float scaley\n" |
| 247 |
"property float centerx\n" |
| 248 |
"property float centery\n" |
| 249 |
"property int viewportx\n" |
| 250 |
"property int viewporty\n" |
| 251 |
"property float k1\n" |
| 252 |
"property float k2\n" |
| 253 |
"property float k3\n" |
| 254 |
"property float k4\n" |
| 255 |
); |
| 256 |
} |
| 257 |
|
| 258 |
fprintf(fpout, |
| 259 |
"element vertex %d\n" |
| 260 |
"property float x\n" |
| 261 |
"property float y\n" |
| 262 |
"property float z\n" |
| 263 |
,m.vn |
| 264 |
); |
| 265 |
|
| 266 |
if( m.HasPerVertexNormal() &&( pi.mask & Mask::IOM_VERTNORMAL) ) |
| 267 |
{ |
| 268 |
fprintf(fpout, |
| 269 |
"property float nx\n" |
| 270 |
"property float ny\n" |
| 271 |
"property float nz\n" |
| 272 |
); |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
if( m.HasPerVertexFlags() &&( pi.mask & Mask::IOM_VERTFLAGS) ) |
| 277 |
{ |
| 278 |
fprintf(fpout, |
| 279 |
"property int flags\n" |
| 280 |
); |
| 281 |
} |
| 282 |
|
| 283 |
if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) ) |
| 284 |
{ |
| 285 |
fprintf(fpout, |
| 286 |
"property uchar red\n" |
| 287 |
"property uchar green\n" |
| 288 |
"property uchar blue\n" |
| 289 |
"property uchar alpha\n" |
| 290 |
); |
| 291 |
} |
| 292 |
|
| 293 |
if( m.HasPerVertexQuality() && (pi.mask & Mask::IOM_VERTQUALITY) ) |
| 294 |
{ |
| 295 |
fprintf(fpout, |
| 296 |
"property float quality\n" |
| 297 |
); |
| 298 |
} |
| 299 |
|
| 300 |
for(i=0;i<pi.vdn;i++) |
| 301 |
fprintf(fpout,"property %s %s\n",pi.VertexData[i].stotypename(),pi.VertexData[i].propname); |
| 302 |
|
| 303 |
fprintf(fpout, |
| 304 |
"element face %d\n" |
| 305 |
"property list uchar int vertex_indices\n" |
| 306 |
,m.fn |
| 307 |
); |
| 308 |
|
| 309 |
if(m.HasPerFaceFlags() && (pi.mask & Mask::IOM_FACEFLAGS) ) |
| 310 |
{ |
| 311 |
fprintf(fpout, |
| 312 |
"property int flags\n" |
| 313 |
); |
| 314 |
} |
| 315 |
|
| 316 |
if( ( m.HasPerVertexTexCoord() && pi.mask & Mask::IOM_VERTTEXCOORD ) || |
| 317 |
( m.HasPerWedgeTexCoord() && pi.mask & Mask::IOM_WEDGTEXCOORD ) ) |
| 318 |
{ |
| 319 |
fprintf(fpout, |
| 320 |
"property list uchar float texcoord\n" |
| 321 |
); |
| 322 |
|
| 323 |
if(multit) |
| 324 |
fprintf(fpout, |
| 325 |
"property int texnumber\n" |
| 326 |
); |
| 327 |
} |
| 328 |
|
| 329 |
if( m.HasPerFaceColor() && (pi.mask & Mask::IOM_FACECOLOR) ) |
| 330 |
{ |
| 331 |
fprintf(fpout, |
| 332 |
"property uchar red\n" |
| 333 |
"property uchar green\n" |
| 334 |
"property uchar blue\n" |
| 335 |
"property uchar alpha\n" |
| 336 |
); |
| 337 |
} |
| 338 |
|
| 339 |
if ( m.HasPerWedgeColor() && (pi.mask & Mask::IOM_WEDGCOLOR) ) |
| 340 |
{ |
| 341 |
fprintf(fpout, |
| 342 |
"property list uchar float color\n" |
| 343 |
); |
| 344 |
} |
| 345 |
|
| 346 |
if( m.HasPerFaceQuality() && (pi.mask & Mask::IOM_FACEQUALITY) ) |
| 347 |
{ |
| 348 |
fprintf(fpout, |
| 349 |
"property float quality\n" |
| 350 |
); |
| 351 |
} |
| 352 |
|
| 353 |
for(i=0;i<pi.fdn;i++) |
| 354 |
fprintf(fpout,"property %s %s\n",pi.FaceData[i].stotypename(),pi.FaceData[i].propname); |
| 355 |
|
| 356 |
fprintf(fpout, "end_header\n" ); |
| 357 |
|
| 358 |
|
| 359 |
if((pi.mask & Mask::IOM_CAMERA)) |
| 360 |
{ |
| 361 |
if(binary) |
| 362 |
{ |
| 363 |
float t[17]; |
| 364 |
|
| 365 |
t[ 0] = (float)-m.shot.Extrinsics.tra[0]; |
| 366 |
t[ 1] = (float)-m.shot.Extrinsics.tra[1]; |
| 367 |
t[ 2] = (float)-m.shot.Extrinsics.tra[2]; |
| 368 |
t[ 3] = (float)m.shot.Extrinsics.rot[0][0]; |
| 369 |
t[ 4] = (float)m.shot.Extrinsics.rot[0][1]; |
| 370 |
t[ 5] = (float)m.shot.Extrinsics.rot[0][2]; |
| 371 |
t[ 6] = (float)m.shot.Extrinsics.rot[1][0]; |
| 372 |
t[ 7] = (float)m.shot.Extrinsics.rot[1][1]; |
| 373 |
t[ 8] = (float)m.shot.Extrinsics.rot[1][2]; |
| 374 |
t[ 9] = (float)m.shot.Extrinsics.rot[2][0]; |
| 375 |
t[10] = (float)m.shot.Extrinsics.rot[2][1]; |
| 376 |
t[11] = (float)m.shot.Extrinsics.rot[2][2]; |
| 377 |
t[12] = (float)m.shot.Intrinsics.FocalMm; |
| 378 |
t[13] = (float)m.shot.Intrinsics.PixelSizeMm[0]; |
| 379 |
t[14] = (float)m.shot.Intrinsics.PixelSizeMm[1]; |
| 380 |
t[15] = (float)m.shot.Intrinsics.CenterPx[0]; |
| 381 |
t[16] = (float)m.shot.Intrinsics.CenterPx[1]; |
| 382 |
fwrite(t,sizeof(float),17,fpout); |
| 383 |
|
| 384 |
fwrite( &m.shot.Intrinsics.ViewportPx[0],sizeof(int),2,fpout ); |
| 385 |
|
| 386 |
t[ 0] = (float)m.shot.Intrinsics.k[0]; |
| 387 |
t[ 1] = (float)m.shot.Intrinsics.k[1]; |
| 388 |
t[ 2] = (float)m.shot.Intrinsics.k[2]; |
| 389 |
t[ 3] = (float)m.shot.Intrinsics.k[3]; |
| 390 |
fwrite(t,sizeof(float),4,fpout); |
| 391 |
} |
| 392 |
else |
| 393 |
{ |
| 394 |
fprintf(fpout,"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %g %g %g %g\n" |
| 395 |
,-m.shot.Extrinsics.tra[0] |
| 396 |
,-m.shot.Extrinsics.tra[1] |
| 397 |
,-m.shot.Extrinsics.tra[2] |
| 398 |
,m.shot.Extrinsics.rot[0][0] |
| 399 |
,m.shot.Extrinsics.rot[0][1] |
| 400 |
,m.shot.Extrinsics.rot[0][2] |
| 401 |
,m.shot.Extrinsics.rot[1][0] |
| 402 |
,m.shot.Extrinsics.rot[1][1] |
| 403 |
,m.shot.Extrinsics.rot[1][2] |
| 404 |
,m.shot.Extrinsics.rot[2][0] |
| 405 |
,m.shot.Extrinsics.rot[2][1] |
| 406 |
,m.shot.Extrinsics.rot[2][2] |
| 407 |
,m.shot.Intrinsics.FocalMm |
| 408 |
,m.shot.Intrinsics.PixelSizeMm[0] |
| 409 |
,m.shot.Intrinsics.PixelSizeMm[1] |
| 410 |
,m.shot.Intrinsics.CenterPx[0] |
| 411 |
,m.shot.Intrinsics.CenterPx[1] |
| 412 |
,m.shot.Intrinsics.ViewportPx[0] |
| 413 |
,m.shot.Intrinsics.ViewportPx[1] |
| 414 |
,m.shot.Intrinsics.k[0] |
| 415 |
,m.shot.Intrinsics.k[1] |
| 416 |
,m.shot.Intrinsics.k[2] |
| 417 |
,m.shot.Intrinsics.k[3] |
| 418 |
); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
int j; |
| 424 |
std::vector<int> FlagV; |
| 425 |
VertexPointer vp; |
| 426 |
VertexIterator vi; |
| 427 |
SimpleTempData<typename SaveMeshType::VertContainer,int> indices(m.vert); |
| 428 |
|
| 429 |
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi){ |
| 430 |
vp=&(*vi); |
| 431 |
indices[j] = j; |
| 432 |
|
| 433 |
if( !m.HasPerVertexFlags() || !vp->IsD() ) |
| 434 |
{ |
| 435 |
if(binary) |
| 436 |
{ |
| 437 |
float t; |
| 438 |
|
| 439 |
t = float(vp->UberP()[0]); fwrite(&t,sizeof(float),1,fpout); |
| 440 |
t = float(vp->UberP()[1]); fwrite(&t,sizeof(float),1,fpout); |
| 441 |
t = float(vp->UberP()[2]); fwrite(&t,sizeof(float),1,fpout); |
| 442 |
|
| 443 |
if( m.HasPerVertexNormal() && (pi.mask & Mask::IOM_VERTNORMAL) ) |
| 444 |
{ |
| 445 |
t = float(vp->N()[0]); fwrite(&t,sizeof(float),1,fpout); |
| 446 |
t = float(vp->N()[1]); fwrite(&t,sizeof(float),1,fpout); |
| 447 |
t = float(vp->N()[2]); fwrite(&t,sizeof(float),1,fpout); |
| 448 |
} |
| 449 |
if( m.HasPerVertexFlags() && (pi.mask & Mask::IOM_VERTFLAGS) ) |
| 450 |
fwrite(&(vp->UberFlags()),sizeof(int),1,fpout); |
| 451 |
|
| 452 |
if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) ) |
| 453 |
fwrite(&( vp->C() ),sizeof(char),4,fpout); |
| 454 |
|
| 455 |
if( m.HasPerVertexQuality() && (pi.mask & Mask::IOM_VERTQUALITY) ) |
| 456 |
fwrite(&( vp->Q() ),sizeof(float),1,fpout); |
| 457 |
|
| 458 |
|
| 459 |
for(i=0;i<pi.vdn;i++) |
| 460 |
{ |
| 461 |
double td(0); float tf(0);int ti;short ts; char tc; unsigned char tuc; |
| 462 |
switch (pi.VertexData[i].stotype1) |
| 463 |
{ |
| 464 |
case ply::T_FLOAT : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, tf ); fwrite(&tf, sizeof(float),1,fpout); break; |
| 465 |
case ply::T_DOUBLE : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, td ); fwrite(&td, sizeof(double),1,fpout); break; |
| 466 |
case ply::T_INT : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, ti ); fwrite(&ti, sizeof(int),1,fpout); break; |
| 467 |
case ply::T_SHORT : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, ts ); fwrite(&ts, sizeof(short),1,fpout); break; |
| 468 |
case ply::T_CHAR : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, tc ); fwrite(&tc, sizeof(char),1,fpout); break; |
| 469 |
case ply::T_UCHAR : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, tuc); fwrite(&tuc,sizeof(unsigned char),1,fpout); break; |
| 470 |
default : assert(0); |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
else |
| 475 |
{ |
| 476 |
fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]); |
| 477 |
|
| 478 |
if( m.HasPerVertexNormal() && (pi.mask & Mask::IOM_VERTNORMAL) ) |
| 479 |
fprintf(fpout,"%g %g %g " ,double(vp->N()[0]),double(vp->N()[1]),double(vp->N()[2])); |
| 480 |
|
| 481 |
if( m.HasPerVertexFlags() && (pi.mask & Mask::IOM_VERTFLAGS)) |
| 482 |
fprintf(fpout,"%d ",vp->UberFlags()); |
| 483 |
|
| 484 |
if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) ) |
| 485 |
fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); |
| 486 |
|
| 487 |
if( m.HasPerVertexQuality() && (pi.mask & Mask::IOM_VERTQUALITY) ) |
| 488 |
fprintf(fpout,"%g ",vp->Q()); |
| 489 |
|
| 490 |
for(i=0;i<pi.vdn;i++) |
| 491 |
{ |
| 492 |
float tf(0); double td(0); |
| 493 |
int ti; |
| 494 |
switch (pi.VertexData[i].memtype1) |
| 495 |
{ |
| 496 |
case ply::T_FLOAT : tf=*( (float *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%g ",tf); break; |
| 497 |
case ply::T_DOUBLE : td=*( (double *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%g ",tf); break; |
| 498 |
case ply::T_INT : ti=*( (int *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 499 |
case ply::T_SHORT : ti=*( (short *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 500 |
case ply::T_CHAR : ti=*( (char *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 501 |
case ply::T_UCHAR : ti=*( (unsigned char *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 502 |
default : assert(0); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
fprintf(fpout,"\n"); |
| 507 |
} |
| 508 |
j++; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
assert(j==m.vn); |
| 513 |
|
| 514 |
char c = 3; |
| 515 |
unsigned char b9 = 9; |
| 516 |
unsigned char b6 = 6; |
| 517 |
FacePointer fp; |
| 518 |
int vv[3]; |
| 519 |
FaceIterator fi; |
| 520 |
int fcnt=0; |
| 521 |
for(j=0,fi=m.face.begin();fi!=m.face.end();++fi) |
| 522 |
{ |
| 523 |
fp=&(*fi); |
| 524 |
if( ! fp->IsD() ) |
| 525 |
{ fcnt++; |
| 526 |
if(binary) |
| 527 |
{ |
| 528 |
vv[0]=indices[fp->cV(0)]; |
| 529 |
vv[1]=indices[fp->cV(1)]; |
| 530 |
vv[2]=indices[fp->cV(2)]; |
| 531 |
fwrite(&c,1,1,fpout); |
| 532 |
fwrite(vv,sizeof(int),3,fpout); |
| 533 |
|
| 534 |
if(m.HasPerFaceFlags()&&( pi.mask & Mask::IOM_FACEFLAGS) ) |
| 535 |
fwrite(&(fp->Flags()),sizeof(int),1,fpout); |
| 536 |
|
| 537 |
if( m.HasPerVertexTexCoord() && (pi.mask & Mask::IOM_VERTTEXCOORD) ) |
| 538 |
{ |
| 539 |
fwrite(&b6,sizeof(char),1,fpout); |
| 540 |
float t[6]; |
| 541 |
for(int k=0;k<3;++k) |
| 542 |
{ |
| 543 |
t[k*2+0] = fp->V(k)->T().u(); |
| 544 |
t[k*2+1] = fp->V(k)->T().v(); |
| 545 |
} |
| 546 |
fwrite(t,sizeof(float),6,fpout); |
| 547 |
} |
| 548 |
else if( m.HasPerWedgeTexCoord() && (pi.mask & Mask::IOM_WEDGTEXCOORD) ) |
| 549 |
{ |
| 550 |
fwrite(&b6,sizeof(char),1,fpout); |
| 551 |
float t[6]; |
| 552 |
for(int k=0;k<3;++k) |
| 553 |
{ |
| 554 |
t[k*2+0] = fp->WT(k).u(); |
| 555 |
t[k*2+1] = fp->WT(k).v(); |
| 556 |
} |
| 557 |
fwrite(t,sizeof(float),6,fpout); |
| 558 |
} |
| 559 |
|
| 560 |
if(multit) |
| 561 |
{ |
| 562 |
int t = fp->WT(0).n(); |
| 563 |
fwrite(&t,sizeof(int),1,fpout); |
| 564 |
} |
| 565 |
|
| 566 |
if( m.HasPerFaceColor() && (pi.mask & Mask::IOM_FACECOLOR) ) |
| 567 |
fwrite(&( fp->C() ),sizeof(char),4,fpout); |
| 568 |
|
| 569 |
|
| 570 |
if( m.HasPerWedgeColor() && (pi.mask & Mask::IOM_WEDGCOLOR) ) |
| 571 |
{ |
| 572 |
fwrite(&b9,sizeof(char),1,fpout); |
| 573 |
float t[3]; |
| 574 |
for(int z=0;z<3;++z) |
| 575 |
{ |
| 576 |
t[0] = float(fp->WC(z)[0])/255; |
| 577 |
t[1] = float(fp->WC(z)[1])/255; |
| 578 |
t[2] = float(fp->WC(z)[2])/255; |
| 579 |
fwrite( t,sizeof(float),3,fpout); |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
if( m.HasPerFaceQuality() && (pi.mask & Mask::IOM_FACEQUALITY) ) |
| 584 |
fwrite( &(fp->Q()),sizeof(float),1,fpout); |
| 585 |
|
| 586 |
|
| 587 |
for(i=0;i<pi.fdn;i++) |
| 588 |
{ |
| 589 |
double td(0); float tf(0);int ti;short ts; char tc; unsigned char tuc; |
| 590 |
switch (pi.FaceData[i].stotype1){ |
| 591 |
case ply::T_FLOAT : PlyConv(pi.FaceData[i].memtype1, ((char *)fp)+pi.FaceData[i].offset1, tf ); fwrite(&tf, sizeof(float),1,fpout); break; |
| 592 |
case ply::T_DOUBLE : PlyConv(pi.FaceData[i].memtype1, ((char *)fp)+pi.FaceData[i].offset1, td ); fwrite(&td, sizeof(double),1,fpout); break; |
| 593 |
case ply::T_INT : PlyConv(pi.FaceData[i].memtype1, ((char *)fp)+pi.FaceData[i].offset1, ti ); fwrite(&ti, sizeof(int),1,fpout); break; |
| 594 |
case ply::T_SHORT : PlyConv(pi.FaceData[i].memtype1, ((char *)fp)+pi.FaceData[i].offset1, ts ); fwrite(&ts, sizeof(short),1,fpout); break; |
| 595 |
case ply::T_CHAR : PlyConv(pi.FaceData[i].memtype1, ((char *)fp)+pi.FaceData[i].offset1, tc ); fwrite(&tc, sizeof(char),1,fpout); break; |
| 596 |
case ply::T_UCHAR : PlyConv(pi.FaceData[i].memtype1, ((char *)fp)+pi.FaceData[i].offset1, tuc); fwrite(&tuc,sizeof(unsigned char),1,fpout); break; |
| 597 |
default : assert(0); |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
else |
| 602 |
{ |
| 603 |
fprintf(fpout,"3 %d %d %d ", |
| 604 |
indices[fp->cV(0)], indices[fp->cV(1)], indices[fp->cV(2)] ); |
| 605 |
|
| 606 |
if(m.HasPerFaceFlags()&&( pi.mask & Mask::IOM_FACEFLAGS )) |
| 607 |
fprintf(fpout,"%d ",fp->Flags()); |
| 608 |
|
| 609 |
if( m.HasPerVertexTexCoord() && (pi.mask & Mask::IOM_VERTTEXCOORD) ) |
| 610 |
{ |
| 611 |
fprintf(fpout,"6 "); |
| 612 |
for(int k=0;k<3;++k) |
| 613 |
fprintf(fpout,"%g %g " |
| 614 |
,fp->V(k)->T().u() |
| 615 |
,fp->V(k)->T().v() |
| 616 |
); |
| 617 |
} |
| 618 |
else if( m.HasPerWedgeTexCoord() && (pi.mask & Mask::IOM_WEDGTEXCOORD) ) |
| 619 |
{ |
| 620 |
fprintf(fpout,"6 "); |
| 621 |
for(int k=0;k<3;++k) |
| 622 |
fprintf(fpout,"%g %g " |
| 623 |
,fp->WT(k).u() |
| 624 |
,fp->WT(k).v() |
| 625 |
); |
| 626 |
} |
| 627 |
|
| 628 |
if(multit) |
| 629 |
{ |
| 630 |
fprintf(fpout,"%d ",fp->WT(0).n()); |
| 631 |
} |
| 632 |
|
| 633 |
if( m.HasPerFaceColor() && (pi.mask & Mask::IOM_FACECOLOR) ) |
| 634 |
{ |
| 635 |
float t[3]; |
| 636 |
t[0] = float(fp->C()[0])/255; |
| 637 |
t[1] = float(fp->C()[1])/255; |
| 638 |
t[2] = float(fp->C()[2])/255; |
| 639 |
fprintf(fpout,"9 "); |
| 640 |
fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]); |
| 641 |
fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]); |
| 642 |
fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]); |
| 643 |
} |
| 644 |
else if( m.HasPerWedgeColor() && (pi.mask & Mask::IOM_WEDGCOLOR) ) |
| 645 |
{ |
| 646 |
fprintf(fpout,"9 "); |
| 647 |
for(int z=0;z<3;++z) |
| 648 |
fprintf(fpout,"%g %g %g " |
| 649 |
,double(fp->WC(z)[0])/255 |
| 650 |
,double(fp->WC(z)[1])/255 |
| 651 |
,double(fp->WC(z)[2])/255 |
| 652 |
); |
| 653 |
} |
| 654 |
|
| 655 |
if( m.HasPerFaceQuality() && (pi.mask & Mask::IOM_FACEQUALITY) ) |
| 656 |
fprintf(fpout,"%g ",fp->Q()); |
| 657 |
|
| 658 |
for(i=0;i<pi.fdn;i++) |
| 659 |
{ |
| 660 |
float tf(0); double td(0); |
| 661 |
int ti; |
| 662 |
switch (pi.FaceData[i].memtype1) |
| 663 |
{ |
| 664 |
case ply::T_FLOAT : tf=*( (float *) (((char *)fp)+pi.FaceData[i].offset1)); fprintf(fpout,"%g ",tf); break; |
| 665 |
case ply::T_DOUBLE : td=*( (double *) (((char *)fp)+pi.FaceData[i].offset1)); fprintf(fpout,"%g ",tf); break; |
| 666 |
case ply::T_INT : ti=*( (int *) (((char *)fp)+pi.FaceData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 667 |
case ply::T_SHORT : ti=*( (short *) (((char *)fp)+pi.FaceData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 668 |
case ply::T_CHAR : ti=*( (char *) (((char *)fp)+pi.FaceData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 669 |
case ply::T_UCHAR : ti=*( (unsigned char *) (((char *)fp)+pi.FaceData[i].offset1)); fprintf(fpout,"%i ",ti); break; |
| 670 |
default : assert(0); |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
fprintf(fpout,"\n"); |
| 675 |
} |
| 676 |
} |
| 677 |
} |
| 678 |
assert(fcnt==m.fn); |
| 679 |
fclose(fpout); |
| 680 |
return 0; |
| 681 |
} |
| 682 |
|
| 683 |
static const char *ErrorMsg(int error) |
| 684 |
{ |
| 685 |
static std::vector<std::string> ply_error_msg; |
| 686 |
if(ply_error_msg.empty()) |
| 687 |
{ |
| 688 |
ply_error_msg.resize(PlyInfo::E_MAXPLYINFOERRORS ); |
| 689 |
ply_error_msg[ply::E_NOERROR ]="No errors"; |
| 690 |
ply_error_msg[ply::E_CANTOPEN ]="Can't open file"; |
| 691 |
ply_error_msg[ply::E_NOTHEADER ]="Header not found"; |
| 692 |
ply_error_msg[ply::E_UNESPECTEDEOF ]="Eof in header"; |
| 693 |
ply_error_msg[ply::E_NOFORMAT ]="Format not found"; |
| 694 |
ply_error_msg[ply::E_SYNTAX ]="Syntax error on header"; |
| 695 |
ply_error_msg[ply::E_PROPOUTOFELEMENT]="Property without element"; |
| 696 |
ply_error_msg[ply::E_BADTYPENAME ]="Bad type name"; |
| 697 |
ply_error_msg[ply::E_ELEMNOTFOUND ]="Element not found"; |
| 698 |
ply_error_msg[ply::E_PROPNOTFOUND ]="Property not found"; |
| 699 |
ply_error_msg[ply::E_BADTYPE ]="Bad type on addtoread"; |
| 700 |
ply_error_msg[ply::E_INCOMPATIBLETYPE]="Incompatible type"; |
| 701 |
ply_error_msg[ply::E_BADCAST ]="Bad cast"; |
| 702 |
|
| 703 |
ply_error_msg[PlyInfo::E_NO_VERTEX ]="No vertex field found"; |
| 704 |
ply_error_msg[PlyInfo::E_NO_FACE ]="No face field found"; |
| 705 |
ply_error_msg[PlyInfo::E_SHORTFILE ]="Unespected eof"; |
| 706 |
ply_error_msg[PlyInfo::E_NO_3VERTINFACE ]="Face with more than 3 vertices"; |
| 707 |
ply_error_msg[PlyInfo::E_BAD_VERT_INDEX ]="Bad vertex index in face"; |
| 708 |
ply_error_msg[PlyInfo::E_NO_6TCOORD ]="Face with no 6 texture coordinates"; |
| 709 |
ply_error_msg[PlyInfo::E_DIFFER_COLORS ]="Number of color differ from vertices"; |
| 710 |
} |
| 711 |
|
| 712 |
if(error>PlyInfo::E_MAXPLYINFOERRORS || error<0) return "Unknown error"; |
| 713 |
else return ply_error_msg[error].c_str(); |
| 714 |
}; |
| 715 |
|
| 716 |
static int GetExportMaskCapability() |
| 717 |
{ |
| 718 |
int capability = 0; |
| 719 |
capability |= vcg::tri::io::Mask::IOM_VERTCOORD ; |
| 720 |
capability |= vcg::tri::io::Mask::IOM_VERTFLAGS ; |
| 721 |
capability |= vcg::tri::io::Mask::IOM_VERTCOLOR ; |
| 722 |
capability |= vcg::tri::io::Mask::IOM_VERTQUALITY ; |
| 723 |
capability |= vcg::tri::io::Mask::IOM_VERTNORMAL ; |
| 724 |
capability |= vcg::tri::io::Mask::IOM_VERTTEXCOORD ; |
| 725 |
capability |= vcg::tri::io::Mask::IOM_FACEINDEX ; |
| 726 |
capability |= vcg::tri::io::Mask::IOM_FACEFLAGS ; |
| 727 |
capability |= vcg::tri::io::Mask::IOM_FACECOLOR ; |
| 728 |
capability |= vcg::tri::io::Mask::IOM_FACEQUALITY ; |
| 729 |
|
| 730 |
capability |= vcg::tri::io::Mask::IOM_WEDGCOLOR ; |
| 731 |
capability |= vcg::tri::io::Mask::IOM_WEDGTEXCOORD ; |
| 732 |
capability |= vcg::tri::io::Mask::IOM_WEDGTEXMULTI ; |
| 733 |
capability |= vcg::tri::io::Mask::IOM_WEDGNORMAL ; |
| 734 |
return capability; |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
}; |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
#endif |