export_ply.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *   
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 
00028 ****************************************************************************/
00029 
00034 
00035 #ifndef __VCGLIB_TETRAEXPORT_PLY
00036 #define __VCGLIB_TETRAEXPORT_PLY
00037 
00038 #include<wrap/ply/io_mask.h>
00039 #include<wrap/io_tetramesh/io_ply.h>
00040 
00041 #include <stdio.h>
00042 
00043 namespace vcg {
00044 namespace tetra {
00045 namespace io {
00046 
00047 
00048 template <class SaveMeshType>
00049 class ExporterPLY
00050 {
00051   // Si occupa di convertire da un tipo all'altro.
00052 // usata nella saveply per matchare i tipi tra stotype e memtype.
00053 // Ad es se in memoria c'e' un int e voglio salvare un float
00054 // src sara in effetti un puntatore a int il cui valore deve 
00055 // essere convertito al tipo di ritorno desiderato (stotype)
00056 
00057 template <class StoType> 
00058 static void PlyConv(int mem_type, void *src, StoType &dest)
00059 {
00060                 switch (mem_type){
00061                                 case ply::T_FLOAT       :               dest = (StoType) (*  ((float  *) src)); break;
00062                                 case ply::T_DOUBLE:             dest = (StoType) (*  ((double *) src)); break;
00063                                 case ply::T_INT         :               dest = (StoType) (*  ((int    *) src)); break;
00064                                 case ply::T_SHORT       :               dest = (StoType) (*  ((short  *) src)); break;
00065                                 case ply::T_CHAR        :               dest = (StoType) (*  ((char   *) src)); break;
00066                                 case ply::T_UCHAR       :               dest = (StoType) (*  ((unsigned char *)src)); break;
00067                                 default : assert(0);
00068                 }
00069 }
00070 
00071 public:
00072 typedef ::vcg::ply::PropDescriptor PropDescriptor ;
00073 typedef typename SaveMeshType::VertexPointer VertexPointer;
00074 typedef typename SaveMeshType::ScalarType ScalarType;
00075 typedef typename SaveMeshType::VertexType VertexType;
00076 typedef typename SaveMeshType::TetraType TetraType;
00077 typedef typename SaveMeshType::TetraPointer TetraPointer;
00078 typedef typename SaveMeshType::VertexIterator VertexIterator;
00079 typedef typename SaveMeshType::TetraIterator TetraIterator;
00080 
00081 static bool Save(SaveMeshType &m, const char * filename, bool binary=true)
00082 {
00083   PlyInfo pi;
00084   return Save(m,filename,binary,pi);
00085 }
00086 
00087 static bool Save(SaveMeshType &m,  const char * filename, int savemask )
00088 {
00089         PlyInfo pi;
00090   pi.mask=savemask;
00091   return Save(m,filename,true,pi);
00092 }
00093 
00094 static bool Save(SaveMeshType &m,  const char * filename, bool binary, PlyInfo &pi )    // V1.0
00095 {
00096         FILE * fpout;
00097         int i;
00098   
00099         const char * hbin = "binary_little_endian";
00100         const char * hasc = "ascii";
00101         const char * h;
00102 
00103         bool multit = false;
00104 
00105         if(binary) h=hbin;
00106         else       h=hasc;
00107 
00108         fpout = fopen(filename,"wb");
00109   if(fpout==NULL)               {
00110     pi.status=::vcg::ply::E_CANTOPEN;
00111     return false;
00112   }
00113         fprintf(fpout,
00114                 "ply\n"
00115                 "format %s 1.0\n"
00116                 "comment VCGLIB generated\n"
00117                 ,h
00118         );
00119 
00120         //if( pi.mask & ply::PLYMask::PM_WEDGTEXCOORD )
00121         //{
00122         //      //const char * TFILE = "TextureFile";
00123 
00124         //      //for(i=0;i<textures.size();++i)
00125         //      //      fprintf(fpout,"comment %s %s\n", TFILE, (const char *)(textures[i]) );
00126 
00127         //      //if(textures.size()>1 && (HasPerWedgeTexture() || HasPerVertexTexture())) multit = true;
00128         //}
00129 
00130         //if( (pi.mask & PLYMask::PM_CAMERA) && camera.IsValid() )
00131         /*{
00132                 fprintf(fpout,
00133                         "element camera 1\n"
00134                         "property float view_px\n"
00135                         "property float view_py\n"
00136                         "property float view_pz\n"
00137                         "property float x_axisx\n"
00138                         "property float x_axisy\n"
00139                         "property float x_axisz\n"
00140                         "property float y_axisx\n"
00141                         "property float y_axisy\n"
00142                         "property float y_axisz\n"
00143                         "property float z_axisx\n"
00144                         "property float z_axisy\n"
00145                         "property float z_axisz\n"
00146                         "property float focal\n"
00147                         "property float scalex\n"
00148                         "property float scaley\n"
00149                         "property float centerx\n"
00150                         "property float centery\n"
00151                         "property int viewportx\n"
00152                         "property int viewporty\n"
00153                         "property float k1\n"
00154                         "property float k2\n"
00155                         "property float k3\n"
00156                         "property float k4\n"
00157                 );
00158         }*/
00159 
00160         fprintf(fpout,
00161                 "element vertex %d\n"
00162                 "property float x\n"
00163                 "property float y\n"
00164                 "property float z\n"
00165                 ,m.vn
00166         );
00167 
00168 
00169         if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
00170         {
00171                 fprintf(fpout,
00172                         "property int flags\n"
00173                 );
00174         }
00175         
00176         if( HasPerVertexColor(m)  && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
00177         {
00178                 fprintf(fpout,
00179                         "property uchar red\n"
00180                         "property uchar green\n"
00181                         "property uchar blue\n"
00182                         "property uchar alpha\n"
00183                 );
00184         }
00185 
00186         if( m.HasPerVertexQuality() && (pi.mask & ply::PLYMask::PM_VERTQUALITY) )
00187         {
00188                 fprintf(fpout,
00189                         "property float quality\n"
00190                 );
00191         }
00192 
00193         for(i=0;i<pi.vdn;i++)
00194                         fprintf(fpout,"property %s %s\n",pi.VertexData[i].stotypename(),pi.VertexData[i].propname);
00195         
00196         fprintf(fpout,
00197                 "element tetra %d\n"
00198                 "property list uchar int vertex_indices\n"
00199                 ,m.tn
00200         );
00201 
00202         if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
00203         {
00204                 fprintf(fpout,
00205                         "property int flags\n"
00206                 );
00207         }
00208 
00209         if(  VertexType::HasTexture() /*|| VertexType::HasPerWedgeTexture()*/  )
00210         {
00211                 fprintf(fpout,
00212                         "property list uchar float texcoord\n"
00213                 );
00214 
00215                 if(multit)
00216                         fprintf(fpout,
00217                                 "property int texnumber\n"
00218                         );
00219         }
00220 
00221         if( TetraType::HasTetraColor() && (pi.mask & ply::PLYMask::PM_TETRACOLOR) )
00222         {
00223                 fprintf(fpout,
00224                         "property uchar red\n"
00225                         "property uchar green\n"
00226                         "property uchar blue\n"
00227                         "property uchar alpha\n"
00228                 );
00229         }
00230         
00231         //if ( m.HasPerWedgeColor() && (pi.mask & ply::PLYMask::PM_WEDGCOLOR)  )
00232         //{
00233         //      fprintf(fpout,
00234         //              "property list uchar float color\n"
00235         //      );
00236         //}
00237 
00238         if( m.HasPerTetraQuality() && (pi.mask & ply::PLYMask::PM_TETRAQUALITY) )
00239         {
00240                 fprintf(fpout,
00241                         "property float quality\n"
00242                 );
00243         }
00244 
00245         for(i=0;i<pi.fdn;i++)
00246                         fprintf(fpout,"property %s %s\n",pi.TetraData[i].stotypename(),pi.TetraData[i].propname);
00247 
00248         fprintf(fpout, "end_header\n"   );
00249 
00250                 // Salvataggio camera
00251         //if( (pi.mask & ply::PLYMask::PM_CAMERA) && camera.IsValid() )
00252         //{
00253                 //if(binary)
00254                 //{
00255                 //      float t[17];
00256 
00257                 //      t[ 0] = camera.view_p[0];
00258                 //      t[ 1] = camera.view_p[1];
00259                 //      t[ 2] = camera.view_p[2];
00260                 //      t[ 3] = camera.x_axis[0];
00261                 //      t[ 4] = camera.x_axis[1];
00262                 //      t[ 5] = camera.x_axis[2];
00263                 //      t[ 6] = camera.y_axis[0];
00264                 //      t[ 7] = camera.y_axis[1];
00265                 //      t[ 8] = camera.y_axis[2];
00266                 //      t[ 9] = camera.z_axis[0];
00267                 //      t[10] = camera.z_axis[1];
00268                 //      t[11] = camera.z_axis[2];
00269                 //      t[12] = camera.f;
00270                 //      t[13] = camera.s[0];
00271                 //      t[14] = camera.s[1];
00272                 //      t[15] = camera.c[0];
00273                 //      t[16] = camera.c[1];
00274                 //      fwrite(t,sizeof(float),17,fpout);
00275 
00276                 //      fwrite( camera.viewport,sizeof(int),2,fpout );
00277 
00278                 //      t[ 0] = camera.k[0];
00279                 //      t[ 1] = camera.k[1];
00280                 //      t[ 2] = camera.k[2];
00281                 //      t[ 3] = camera.k[3];
00282                 //      fwrite(t,sizeof(float),4,fpout);
00283                 //}
00284                 //else
00285                 //{
00286                 //      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"
00287                 //              ,camera.view_p[0]
00288                 //              ,camera.view_p[1]
00289                 //              ,camera.view_p[2]
00290                 //              ,camera.x_axis[0]
00291                 //              ,camera.x_axis[1]
00292                 //              ,camera.x_axis[2]
00293                 //              ,camera.y_axis[0]
00294                 //              ,camera.y_axis[1]
00295                 //              ,camera.y_axis[2]
00296                 //              ,camera.z_axis[0]
00297                 //              ,camera.z_axis[1]
00298                 //              ,camera.z_axis[2]
00299                 //              ,camera.f
00300                 //              ,camera.s[0]
00301                 //              ,camera.s[1]
00302                 //              ,camera.c[0]
00303                 //              ,camera.c[1]
00304                 //              ,camera.viewport[0]
00305                 //              ,camera.viewport[1]
00306                 //              ,camera.k[0]
00307                 //              ,camera.k[1]
00308                 //              ,camera.k[2]
00309                 //              ,camera.k[3]
00310                 //      );
00311                 //}             
00312         //}
00313 
00314 
00315         int j;
00316         std::vector<int> FlagV; 
00317         VertexPointer  vp;
00318         VertexIterator vi;
00319         for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
00320         {
00321                 vp=&(*vi);
00322                 FlagV.push_back(vp->Flags()); // Salva in ogni caso flag del vertice
00323                 if( ! vp->IsD() )
00324                 {
00325                         if(binary)
00326                         {
00327                                 float t;
00328 
00329                                 t = float(vp->P()[0]); fwrite(&t,sizeof(float),1,fpout);
00330                                 t = float(vp->P()[1]); fwrite(&t,sizeof(float),1,fpout);
00331                                 t = float(vp->P()[2]); fwrite(&t,sizeof(float),1,fpout);
00332                                 
00333                                 if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
00334                                         fwrite(&(vp->Flags()),sizeof(int),1,fpout);
00335 
00336                                 if( HasPerVertexColor(m) && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
00337                                         fwrite(&( vp->C() ),sizeof(char),4,fpout);
00338 
00339                                 if( m.HasPerVertexQuality() && (pi.mask & ply::PLYMask::PM_VERTQUALITY) )
00340                                         fwrite(&( vp->Q() ),sizeof(float),1,fpout);
00341 
00342 
00343                                 for(i=0;i<pi.vdn;i++)
00344                                 {
00345                                         double td; float tf;int ti;short ts; char tc; unsigned char tuc;
00346                                         switch (pi.VertexData[i].stotype1)
00347                                         {
00348           case ply::T_FLOAT      :              PlyConv(pi.VertexData[i].memtype1,  ((char *)vp)+pi.VertexData[i].offset1, tf );        fwrite(&tf, sizeof(float),1,fpout); break;
00349                                         case ply::T_DOUBLE :            PlyConv(pi.VertexData[i].memtype1,  ((char *)vp)+pi.VertexData[i].offset1, td );        fwrite(&td, sizeof(double),1,fpout); break;
00350                                         case ply::T_INT          :              PlyConv(pi.VertexData[i].memtype1,  ((char *)vp)+pi.VertexData[i].offset1, ti );        fwrite(&ti, sizeof(int),1,fpout); break;
00351                                         case ply::T_SHORT        :              PlyConv(pi.VertexData[i].memtype1,  ((char *)vp)+pi.VertexData[i].offset1, ts );        fwrite(&ts, sizeof(short),1,fpout); break;
00352                                         case ply::T_CHAR         :              PlyConv(pi.VertexData[i].memtype1,  ((char *)vp)+pi.VertexData[i].offset1, tc );        fwrite(&tc, sizeof(char),1,fpout); break;
00353                                         case ply::T_UCHAR        :              PlyConv(pi.VertexData[i].memtype1,  ((char *)vp)+pi.VertexData[i].offset1, tuc);        fwrite(&tuc,sizeof(unsigned char),1,fpout); break;
00354                                         default : assert(0);
00355                                         }
00356                                 }
00357                         }
00358                         else    // ***** ASCII *****
00359                         {
00360                                 fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]);
00361 
00362                                 if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
00363                                         fprintf(fpout,"%d ",vp->Flags());
00364 
00365                                 if( HasPerVertexColor(m) && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
00366                                         fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] );
00367 
00368                                 if( m.HasPerVertexQuality() && (pi.mask & ply::PLYMask::PM_VERTQUALITY) )
00369                                         fprintf(fpout,"%g ",vp->Q());
00370 
00371                                 for(i=0;i<pi.vdn;i++)
00372                                 {
00373                                         float tf; double td;
00374                                         int ti;
00375                                         switch (pi.VertexData[i].memtype1)
00376                                         {
00377                                         case ply::T_FLOAT        :              tf=*( (float  *)        (((char *)vp)+pi.VertexData[i].offset1));       fprintf(fpout,"%g ",tf); break;
00378                                         case ply::T_DOUBLE :    td=*( (double *)        (((char *)vp)+pi.VertexData[i].offset1));       fprintf(fpout,"%g ",tf); break;
00379                                         case ply::T_INT          :              ti=*( (int    *)        (((char *)vp)+pi.VertexData[i].offset1));       fprintf(fpout,"%i ",ti); break;
00380                                         case ply::T_SHORT        :              ti=*( (short  *)        (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break;
00381                                         case ply::T_CHAR         :              ti=*( (char   *)        (((char *)vp)+pi.VertexData[i].offset1));       fprintf(fpout,"%i ",ti); break;
00382                                         case ply::T_UCHAR        :              ti=*( (unsigned char *) (((char *)vp)+pi.VertexData[i].offset1));       fprintf(fpout,"%i ",ti); break;
00383                                         default : assert(0);
00384                                         }
00385                                 }
00386 
00387                                 fprintf(fpout,"\n");
00388                         }
00389 
00390                         vp->Flags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato!
00391                         j++;
00392                 }
00393         }
00394         assert(j==m.vn);
00395 
00396         char c = 4;
00397         unsigned char b9 = 9;
00398         unsigned char b6 = 6;
00399         TetraPointer fp;
00400         int vv[4];
00401         TetraIterator fi;
00402         int fcnt=0;
00403         for(j=0,fi=m.tetra.begin();fi!=m.tetra.end();++fi)
00404                 {
00405                         fp=&(*fi);
00406                         if( ! fp->IsD() )
00407                         { fcnt++;
00408                                 if(binary)
00409                                 {
00410                                         vv[0]=fp->cV(0)->Flags();
00411                                         vv[1]=fp->cV(1)->Flags();
00412                                         vv[2]=fp->cV(2)->Flags();
00413                                         vv[3]=fp->cV(2)->Flags();
00414                                         fwrite(&c,1,1,fpout);
00415                                         fwrite(vv,sizeof(int),4,fpout);
00416 
00417                                         if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
00418                                                 fwrite(&(fp->Flags()),sizeof(int),1,fpout);
00419 
00420                                         if( m.HasPerVertexTexture() && (pi.mask & ply::PLYMask::PM_VERTTEXCOORD) )
00421                                         {
00422                                                 fwrite(&b6,sizeof(char),1,fpout);
00423                                                 float t[6];
00424                                                 for(int k=0;k<4;++k)
00425                                                 {
00426                                                         t[k*2+0] = fp->V(k)->T().u();
00427                                                         t[k*2+1] = fp->V(k)->T().v();
00428                                                 }
00429                                                 fwrite(t,sizeof(float),6,fpout);
00430                                         }
00431                                         //else if( m.HasPerWedgeTexture() && (pi.mask & ply::PLYMask::PM_WEDGTEXCOORD)  )
00432                                         //{
00433                                         //      fwrite(&b6,sizeof(char),1,fpout);
00434                                         //      float t[6];
00435                                         //      for(int k=0;k<3;++k)
00436                                         //      {
00437                                         //              t[k*2+0] = fp->WT(k).u();
00438                                         //              t[k*2+1] = fp->WT(k).v();
00439                                         //      }
00440                                         //      fwrite(t,sizeof(float),6,fpout);
00441                                         //}
00442 
00443         /*                              if(multit)
00444                                         {
00445                                                 int t = fp->WT(0).n();
00446                                                 fwrite(&t,sizeof(int),1,fpout);
00447                                         }
00448           
00449                                         if( m.HasPerTetraColor() && (pi.mask & ply::PLYMask::PM_TETRACOLOR) )
00450                                            fwrite(&( fp->C() ),sizeof(char),4,fpout);*/
00451 
00452 
00453                                         //if( m.HasPerWedgeColor() && (pi.mask & ply::PLYMask::PM_WEDGCOLOR)  )
00454                                         //{
00455                                         //      fwrite(&b9,sizeof(char),1,fpout);
00456                                         //      float t[3];
00457                                         //      for(int z=0;z<3;++z)
00458                                         //      {
00459                                         //              t[0] = float(fp->WC(z)[0])/255;
00460                                         //              t[1] = float(fp->WC(z)[1])/255;
00461                                         //              t[2] = float(fp->WC(z)[2])/255;
00462                                         //              fwrite( t,sizeof(float),3,fpout);
00463                                         //      }
00464                                         //}
00465 
00466                                 if( TetraType::HasTetraQuality() && (pi.mask & ply::PLYMask::PM_TETRAQUALITY) )
00467                                                 fwrite( &(fp->Q()),sizeof(float),1,fpout);
00468 
00469 
00470                                         for(i=0;i<pi.fdn;i++)
00471                                                 {
00472                                                 double td; float tf;int ti;short ts; char tc; unsigned char tuc;
00473                                                 switch (pi.TetraData[i].stotype1){
00474                                                                 case ply::T_FLOAT        :              PlyConv(pi.TetraData[i].memtype1,  ((char *)fp)+pi.TetraData[i].offset1, tf );  fwrite(&tf, sizeof(float),1,fpout); break;
00475                                                                 case ply::T_DOUBLE :            PlyConv(pi.TetraData[i].memtype1,  ((char *)fp)+pi.TetraData[i].offset1, td );  fwrite(&td, sizeof(double),1,fpout); break;
00476                                                                 case ply::T_INT          :              PlyConv(pi.TetraData[i].memtype1,  ((char *)fp)+pi.TetraData[i].offset1, ti );  fwrite(&ti, sizeof(int),1,fpout); break;
00477                                                                 case ply::T_SHORT        :              PlyConv(pi.TetraData[i].memtype1,  ((char *)fp)+pi.TetraData[i].offset1, ts );  fwrite(&ts, sizeof(short),1,fpout); break;
00478                                                                 case ply::T_CHAR         :              PlyConv(pi.TetraData[i].memtype1,  ((char *)fp)+pi.TetraData[i].offset1, tc );  fwrite(&tc, sizeof(char),1,fpout); break;
00479                                                                 case ply::T_UCHAR        :              PlyConv(pi.TetraData[i].memtype1,  ((char *)fp)+pi.TetraData[i].offset1, tuc);  fwrite(&tuc,sizeof(unsigned char),1,fpout); break;
00480                                                                 default : assert(0);
00481                                                 }
00482                                         }
00483                                 }
00484                                 else    // ***** ASCII *****
00485                                 {
00486                                         fprintf(fpout,"3 %d %d %d ",
00487                                                 fp->cV(0)->Flags(),     fp->cV(1)->Flags(), fp->cV(2)->Flags() );
00488 
00489                                         if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
00490                                                 fprintf(fpout,"%d ",fp->Flags());
00491 
00492                                         if( m.HasPerVertexTexture() && (pi.mask & ply::PLYMask::PM_VERTTEXCOORD) )
00493                                         {
00494                                                 fprintf(fpout,"6 ");
00495                                                 for(int k=0;k<4;++k)
00496                                                         fprintf(fpout,"%g %g "
00497                                                                 ,fp->V(k)->T().u()
00498                                                                 ,fp->V(k)->T().v()
00499                                                         );
00500                                         }
00501                                         //else if( m.HasPerWedgeTexture() && (pi.mask & ply::PLYMask::PM_WEDGTEXCOORD)  )
00502                                         //{
00503                                         //      fprintf(fpout,"6 ");
00504                                         //      for(int k=0;k<3;++k)
00505                                         //              fprintf(fpout,"%g %g "
00506                                         //                      ,fp->WT(k).u()
00507                                         //                      ,fp->WT(k).v()
00508                                         //              );
00509                                         //}
00510 
00511         /*                              if(multit)
00512                                         {
00513                                                 fprintf(fpout,"%d ",fp->WT(0).n());
00514                                         }*/
00515 
00516                                 if( TetraType::HasTetraColor() && (pi.mask & ply::PLYMask::PM_TETRACOLOR)  )
00517                                         {
00518                                                 float t[3];
00519                                                 t[0] = float(fp->C()[0])/255;
00520                                                 t[1] = float(fp->C()[1])/255;
00521                                                 t[2] = float(fp->C()[2])/255;
00522                                                 fprintf(fpout,"9 ");
00523                                                 fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]);
00524                                                 fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]);
00525                                                 fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]);
00526                                         }
00527                                         //else if( m.HasPerWedgeColor() && (pi.mask & ply::PLYMask::PM_WEDGCOLOR)  )
00528                                         //{
00529                                         //      fprintf(fpout,"9 ");
00530                                         //      for(int z=0;z<3;++z)
00531                                         //              fprintf(fpout,"%g %g %g "
00532                                         //                      ,double(fp->WC(z)[0])/255
00533                                         //                      ,double(fp->WC(z)[1])/255
00534                                         //                      ,double(fp->WC(z)[2])/255
00535                                         //              );
00536                                         //}
00537 
00538                                         if( m.HasPerTetraQuality() && (pi.mask & ply::PLYMask::PM_TETRAQUALITY) )
00539                                                 fprintf(fpout,"%g ",fp->Q());
00540 
00541                                         for(i=0;i<pi.fdn;i++)
00542                                         {
00543                                                 float tf; double td;
00544                                                 int ti;
00545                                                 switch (pi.TetraData[i].memtype1)
00546                                                 {
00547                                                 case  ply::T_FLOAT      :               tf=*( (float  *)        (((char *)fp)+pi.TetraData[i].offset1));        fprintf(fpout,"%g ",tf); break;
00548                                                 case  ply::T_DOUBLE :           td=*( (double *)        (((char *)fp)+pi.TetraData[i].offset1));        fprintf(fpout,"%g ",tf); break;
00549                                                 case  ply::T_INT                :               ti=*( (int    *)        (((char *)fp)+pi.TetraData[i].offset1));        fprintf(fpout,"%i ",ti); break;
00550                                                 case  ply::T_SHORT      :               ti=*( (short  *)        (((char *)fp)+pi.TetraData[i].offset1));        fprintf(fpout,"%i ",ti); break;
00551                                                 case  ply::T_CHAR               :               ti=*( (char   *)        (((char *)fp)+pi.TetraData[i].offset1));        fprintf(fpout,"%i ",ti); break;
00552                                                 case  ply::T_UCHAR      :               ti=*( (unsigned char *) (((char *)fp)+pi.TetraData[i].offset1));        fprintf(fpout,"%i ",ti); break;
00553                                                 default : assert(0);
00554                                                 }
00555                                         }
00556 
00557                                         fprintf(fpout,"\n");
00558                                 }                         
00559                         }
00560                 }
00561         assert(fcnt==m.tn);
00562         fclose(fpout); 
00563         
00564         // Recupera i flag originali
00565         for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
00566                 (*vi).Flags()=FlagV[j++];
00567         
00568         return 0;
00569 }
00570 
00571 
00572 
00573 
00574 }; // end class
00575 
00576 
00577 
00578 } // end namespace tri
00579 } // end namespace io
00580 } // end namespace vcg
00581 
00582 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:30:52