| 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 |
#ifndef __VCGLIB_EXPORT_OFF |
| 47 |
#define __VCGLIB_EXPORT_OFF |
| 48 |
|
| 49 |
#include <stdio.h> |
| 50 |
#include <wrap/io_trimesh/io_mask.h> |
| 51 |
|
| 52 |
|
| 53 |
namespace vcg { |
| 54 |
namespace tri { |
| 55 |
namespace io { |
| 56 |
template <class SaveMeshType> |
| 57 |
class ExporterOFF |
| 58 |
{ |
| 59 |
|
| 60 |
public: |
| 61 |
typedef typename SaveMeshType::VertexPointer VertexPointer; |
| 62 |
typedef typename SaveMeshType::ScalarType ScalarType; |
| 63 |
typedef typename SaveMeshType::VertexType VertexType; |
| 64 |
typedef typename SaveMeshType::FaceType FaceType; |
| 65 |
typedef typename SaveMeshType::FacePointer FacePointer; |
| 66 |
typedef typename SaveMeshType::VertexIterator VertexIterator; |
| 67 |
typedef typename SaveMeshType::FaceIterator FaceIterator; |
| 68 |
|
| 69 |
static int Save(SaveMeshType &m, const char * filename, int mask=0 ) |
| 70 |
{ |
| 71 |
vcg::face::Pos<FaceType> he; |
| 72 |
vcg::face::Pos<FaceType> hei; |
| 73 |
FILE * fpout = fopen(filename,"w"); |
| 74 |
if(fpout==NULL) return 1; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
if( m.HasPerVertexNormal() && (mask & io::Mask::IOM_VERTNORMAL)) fprintf(fpout,"N"); |
| 79 |
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR)) fprintf(fpout,"C"); |
| 80 |
if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD)) fprintf(fpout,"ST"); |
| 81 |
fprintf(fpout,"OFF\n"); |
| 82 |
fprintf(fpout,"%d %d 0\n", m.vn, m.fn); |
| 83 |
typename SaveMeshType::FaceIterator fi; |
| 84 |
|
| 85 |
|
| 86 |
int j; |
| 87 |
std::vector<int> FlagV; |
| 88 |
VertexPointer vp; |
| 89 |
VertexIterator vi; |
| 90 |
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) |
| 91 |
{ |
| 92 |
vp=&(*vi); |
| 93 |
FlagV.push_back(vp->UberFlags()); |
| 94 |
if( ! vp->IsD() ) |
| 95 |
{ |
| 96 |
|
| 97 |
fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]); |
| 98 |
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR) ) |
| 99 |
fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); |
| 100 |
|
| 101 |
if( m.HasPerVertexNormal() && (mask & io::Mask::IOM_VERTNORMAL) ) |
| 102 |
fprintf(fpout,"%g %g %g ", vp->N()[0],vp->N()[1],vp->N()[2]); |
| 103 |
|
| 104 |
if( m.HasPerVertexTexCoord() && (mask & io::Mask::IOM_VERTTEXCOORD) ) |
| 105 |
fprintf(fpout,"%g %g ",vp->T().u(),vp->T().v()); |
| 106 |
|
| 107 |
fprintf(fpout,"\n"); |
| 108 |
|
| 109 |
|
| 110 |
vp->UberFlags()=j; |
| 111 |
j++; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
assert(j==m.vn); |
| 116 |
FacePointer fp; |
| 117 |
|
| 118 |
|
| 119 |
int fcnt=0; |
| 120 |
for(j=0,fi=m.face.begin();fi!=m.face.end();++fi) |
| 121 |
{ |
| 122 |
fp=&(*fi); |
| 123 |
if( ! fp->IsD() ) |
| 124 |
{ fcnt++; |
| 125 |
|
| 126 |
|
| 127 |
fprintf(fpout,"3 %d %d %d\n", |
| 128 |
fp->cV(0)->UberFlags(), fp->cV(1)->UberFlags(), fp->cV(2)->UberFlags() ); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
fclose(fpout); |
| 134 |
|
| 135 |
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) |
| 136 |
(*vi).UberFlags()=FlagV[j++]; |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |
| 140 |
|
| 141 |
static const char *ErrorMsg(int error) |
| 142 |
{ |
| 143 |
static std::vector<std::string> off_error_msg; |
| 144 |
if(off_error_msg.empty()) |
| 145 |
{ |
| 146 |
off_error_msg.resize(2 ); |
| 147 |
off_error_msg[0]="No errors"; |
| 148 |
off_error_msg[1]="Can't open file"; |
| 149 |
} |
| 150 |
|
| 151 |
if(error>1 || error<0) return "Unknown error"; |
| 152 |
else return off_error_msg[error].c_str(); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
static int GetExportMaskCapability() |
| 158 |
{ |
| 159 |
int capability = 0; |
| 160 |
capability |= vcg::tri::io::Mask::IOM_VERTCOORD; |
| 161 |
capability |= vcg::tri::io::Mask::IOM_VERTCOLOR; |
| 162 |
capability |= vcg::tri::io::Mask::IOM_FACEINDEX; |
| 163 |
return capability; |
| 164 |
} |
| 165 |
|
| 166 |
}; |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
#endif |