00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef NANOPLY_WRAPPER_VCG_H
00016 #define NANOPLY_WRAPPER_VCG_H
00017
00018 #include <wrap/nanoply/include/nanoply.hpp>
00019 #include <vcg/space/point.h>
00020 #include <map>
00021
00022 namespace nanoply
00023 {
00024
00025 template <class MeshType>
00026 class NanoPlyWrapper{
00027
00028
00029 private:
00030
00031 typedef typename MeshType::PointerToAttribute PointerToAttribute;
00032 typedef typename MeshType::ScalarType ScalarType;
00033
00034 typedef typename MeshType::VertexType VertexType;
00035 typedef typename MeshType::VertexType::ScalarType VertexCoordScalar;
00036 typedef typename MeshType::VertexType::NormalType::ScalarType VertexNormScalar;
00037 typedef typename MeshType::VertexType::ColorType::ScalarType VertexColorScalar;
00038 typedef typename MeshType::VertexType::QualityType VertexQuality;
00039 typedef typename MeshType::VertexType::RadiusType VertexRadius;
00040 typedef typename MeshType::VertexType::FlagType VertexFlag;
00041 typedef typename MeshType::VertexType::TexCoordType::ScalarType VertexTexScalar;
00042 typedef typename MeshType::VertexType::CurvatureType::ScalarType VertexCurScalar;
00043 typedef typename MeshType::VertexType::CurScalarType VertexDirCurScalar;
00044 typedef typename MeshType::VertexType::CurVecType::ScalarType VertexDirCurVecScalar;
00045
00046 typedef typename MeshType::EdgeType EdgeType;
00047 typedef typename MeshType::EdgeType::ColorType::ScalarType EdgeColorScalar;
00048 typedef typename MeshType::EdgeType::QualityType EdgeQuality;
00049 typedef typename MeshType::EdgeType::FlagType EdgeFlag;
00050
00051 typedef typename MeshType::FaceType FaceType;
00052 typedef typename MeshType::FaceType::NormalType::ScalarType FaceNormScalar;
00053 typedef typename MeshType::FaceType::ColorType::ScalarType FaceColorScalar;
00054 typedef typename MeshType::FaceType::QualityType FaceQuality;
00055 typedef typename MeshType::FaceType::FlagType FaceFlag;
00056 typedef typename MeshType::FaceType::TexCoordType::ScalarType FaceTexScalar;
00057 typedef typename MeshType::FaceType::CurScalarType FaceDirCurScalar;
00058 typedef typename MeshType::FaceType::CurVecType::ScalarType FaceDirCurVecScalar;
00059 typedef typename MeshType::FaceType::WedgeColorType::ScalarType WedgeColorScalar;
00060 typedef typename MeshType::FaceType::WedgeNormalType::ScalarType WedgeNormalScalar;
00061
00062
00063
00064 template<class T> static PlyType getEntity() { return NNP_UNKNOWN_TYPE };
00065 template<> static PlyType getEntity<unsigned char>(){ return NNP_UINT8; };
00066 template<> static PlyType getEntity<char>(){ return NNP_INT8; };
00067 template<> static PlyType getEntity<unsigned short>(){ return NNP_UINT16; };
00068 template<> static PlyType getEntity<short>(){ return NNP_INT16; };
00069 template<> static PlyType getEntity<unsigned int>(){ return NNP_UINT32; };
00070 template<> static PlyType getEntity<int>(){ return NNP_INT32; };
00071 template<> static PlyType getEntity<float>(){ return NNP_FLOAT32; };
00072 template<> static PlyType getEntity<double>(){ return NNP_FLOAT64; };
00073
00074 template<class T> static PlyType getEntityList() { return NNP_UNKNOWN_TYPE; };
00075 template<> static PlyType getEntityList<unsigned char>(){ return NNP_LIST_UINT8_UINT8; };
00076 template<> static PlyType getEntityList<char>(){ return NNP_LIST_UINT8_INT8; };
00077 template<> static PlyType getEntityList<unsigned short>(){ return NNP_LIST_UINT8_UINT16; };
00078 template<> static PlyType getEntityList<short>(){ return NNP_LIST_UINT8_INT16; };
00079 template<> static PlyType getEntityList<unsigned int>(){ return NNP_LIST_UINT8_UINT32; };
00080 template<> static PlyType getEntityList<int>(){ return NNP_LIST_UINT8_INT32; };
00081 template<> static PlyType getEntityList<float>(){ return NNP_LIST_UINT8_FLOAT32; };
00082 template<> static PlyType getEntityList<double>(){ return NNP_LIST_UINT8_FLOAT64; };
00083
00084
00085 template<class Container, class Type, int n>
00086 inline static void PushDescriport(std::vector<PlyProperty>& prop, ElementDescriptor& elem, PlyEntity entity, void* ptr)
00087 {
00088 prop.push_back(PlyProperty(getEntity<Type>(), entity));
00089 DescriptorInterface* di = new DataDescriptor<Container, n, Type>(entity, ptr);
00090 elem.dataDescriptor.push_back(di);
00091 }
00092
00093
00094 template<class Container, class Type, int n>
00095 inline static void PushDescriportList(std::vector<PlyProperty>& prop, ElementDescriptor& elem, PlyEntity entity, void* ptr)
00096 {
00097 prop.push_back(PlyProperty(getEntityList<Type>(), entity));
00098 DescriptorInterface* di = new DataDescriptor<Container, n, Type>(entity, ptr);
00099 elem.dataDescriptor.push_back(di);
00100 }
00101
00102
00103 template<class Container, class Type, int n>
00104 inline static void PushDescriport(std::vector<PlyProperty>& prop, ElementDescriptor& elem, std::string& name, void* ptr)
00105 {
00106 prop.push_back(PlyProperty(getEntity<Type>(), name));
00107 DescriptorInterface* di = new DataDescriptor<Container, n, Type>(name, ptr);
00108 elem.dataDescriptor.push_back(di);
00109 }
00110
00111
00112 template<class Container, class Type, int n>
00113 inline static void PushDescriportList(std::vector<PlyProperty>& prop, ElementDescriptor& elem, std::string& name, void* ptr)
00114 {
00115 prop.push_back(PlyProperty(getEntityList<Type>(), name));
00116 DescriptorInterface* di = new DataDescriptor<Container, n, Type>(name, ptr);
00117 elem.dataDescriptor.push_back(di);
00118 }
00119
00120 public:
00121
00122
00123 typedef enum {
00124 IO_NONE = 0x00000000,
00125
00126 IO_VERTCOORD = 0x00000001,
00127 IO_VERTFLAGS = 0x00000002,
00128 IO_VERTCOLOR = 0x00000004,
00129 IO_VERTQUALITY = 0x00000008,
00130 IO_VERTNORMAL = 0x00000010,
00131 IO_VERTTEXCOORD = 0x00000020,
00132 IO_VERTRADIUS = 0x00000040,
00133 IO_VERTCURV = 0x00000080,
00134 IO_VERTCURVDIR = 0x00000100,
00135 IO_VERTATTRIB = 0x00000200,
00136
00137 IO_FACEINDEX = 0x00000400,
00138 IO_FACEFLAGS = 0x00000800,
00139 IO_FACECOLOR = 0x00001000,
00140 IO_FACEQUALITY = 0x00002000,
00141 IO_FACENORMAL = 0x00004000,
00142 IO_FACECURVDIR = 0x00008000,
00143 IO_FACEATTRIB = 0x00010000,
00144
00145 IO_EDGEINDEX = 0x00020000,
00146 IO_EDGEQUALITY = 0x00040000,
00147 IO_EDGECOLOR = 0x00080000,
00148 IO_EDGEFLAGS = 0x00100000,
00149 IO_EDGEATTRIB = 0x00200000,
00150
00151 IO_WEDGCOLOR = 0x00400000,
00152 IO_WEDGTEXCOORD = 0x00800000,
00153 IO_WEDGTEXMULTI = 0x01000000,
00154 IO_WEDGNORMAL = 0x02000000,
00155
00156 IO_BITPOLYGONAL = 0x04000000,
00157
00158 IO_CAMERA = 0x08000000,
00159 IO_MESHATTRIB = 0x10000000,
00160
00161 IO_FLAGS = IO_VERTFLAGS | IO_FACEFLAGS,
00162
00163 IO_ALL = 0xFFFFFFFF
00164 }BitMask;
00165
00166
00167
00168 class CustomAttributeDescriptor
00169 {
00170 public:
00171
00172 typedef std::map<std::string, ElementDescriptor::PropertyDescriptor> MapMeshAttrib;
00173 typedef std::map<std::string, ElementDescriptor::PropertyDescriptor>::iterator MapMeshAttribIter;
00174 typedef std::map<std::string, std::vector<PlyProperty>> MapMeshAttribProp;
00175 typedef std::map<std::string, std::vector<PlyProperty>>::iterator MapMeshAttribPropIter;
00176
00177 ElementDescriptor::PropertyDescriptor vertexAttrib;
00178 ElementDescriptor::PropertyDescriptor faceAttrib;
00179 ElementDescriptor::PropertyDescriptor edgeAttrib;
00180 std::vector<PlyProperty> vertexAttribProp;
00181 std::vector<PlyProperty> faceAttribProp;
00182 std::vector<PlyProperty> edgeAttribProp;
00183
00184 MapMeshAttrib meshAttrib;
00185 MapMeshAttribProp meshAttribProp;
00186 std::map<std::string, int> meshAttribCnt;
00187
00188
00189 CustomAttributeDescriptor::~CustomAttributeDescriptor()
00190 {
00191 for (int i = 0; i < vertexAttrib.size(); i++)
00192 delete vertexAttrib[i];
00193 for (int i = 0; i < edgeAttrib.size(); i++)
00194 delete edgeAttrib[i];
00195 for (int i = 0; i < faceAttrib.size(); i++)
00196 delete faceAttrib[i];
00197 CustomAttributeDescriptor::MapMeshAttribIter iter = meshAttrib.begin();
00198 for (; iter != meshAttrib.end(); iter++)
00199 for (int i = 0; i < (*iter).second.size(); i++)
00200 delete (*iter).second[i];
00201 }
00202
00203
00204 template<class Container, class Type, int n>
00205 void AddVertexAttribDescriptor(std::string& name, PlyType type, void* ptr)
00206 {
00207 vertexAttrib.push_back(new DataDescriptor<Container, n, Type>(name, ptr));
00208 vertexAttribProp.push_back(PlyProperty(type, name));
00209 }
00210
00211 template<class Container, class Type, int n>
00212 void AddEdgeAttribDescriptor(std::string& name, PlyType type, void* ptr)
00213 {
00214 edgeAttrib.push_back(new DataDescriptor<Container, n, Type>(name, ptr));
00215 edgeAttribProp.push_back(PlyProperty(type, name));
00216 }
00217
00218 template<class Container, class Type, int n>
00219 void AddFaceAttribDescriptor(std::string& name, PlyType type, void* ptr)
00220 {
00221 faceAttrib.push_back(new DataDescriptor<Container, n, Type>(name, ptr));
00222 faceAttribProp.push_back(PlyProperty(type, name));
00223 }
00224
00225 template<class Container, class Type, int n>
00226 void AddMeshAttribDescriptor(std::string& nameAttrib, std::string& nameProp, PlyType type, void* ptr)
00227 {
00228 meshAttrib[nameAttrib].push_back(new DataDescriptor<Container, n, Type>(nameProp, ptr));
00229 meshAttribProp[nameAttrib].push_back(PlyProperty(type, nameProp));
00230 }
00231
00232 void AddMeshAttrib(std::string& name, int cnt)
00233 {
00234 meshAttribCnt[name] = cnt;
00235 }
00236
00237 void GetMeshAttrib(std::string filename)
00238 {
00239 nanoply::Info info(filename);
00240 if (info.errInfo == nanoply::NNP_OK)
00241 {
00242 for (int i = 0; i < info.elemVec.size(); i++)
00243 {
00244 if (info.elemVec[i].plyElem == NNP_UNKNOWN_ELEM && info.elemVec[i].name != "camera")
00245 meshAttribCnt[info.elemVec[i].name] = info.elemVec[i].cnt;
00246 }
00247 }
00248 }
00249
00250 };
00251
00252
00253
00254 static int LoadModel(const char* filename, MeshType& mesh, unsigned int bitMask, CustomAttributeDescriptor& custom)
00255 {
00256 nanoply::Info info(filename);
00257 if (info.errInfo != nanoply::NNP_OK)
00258 return info.errInfo;
00259
00260
00261 ElementDescriptor cameraDescr(std::string("camera"));
00262 vcg::Point3<ScalarType> tra;
00263 vcg::Matrix44<ScalarType> rot;
00264 size_t count = info.GetElementCount(std::string("camera"));
00265 if (count > 0 && (bitMask & BitMask::IO_CAMERA))
00266 {
00267 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("view_px"), &tra[0]));
00268 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("view_py"), &tra[1]));
00269 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("view_pz"), &tra[2]));
00270 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("x_axisx"), &rot[0][0]));
00271 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("x_axisy"), &rot[0][1]));
00272 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("x_axisz"), &rot[0][2]));
00273 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("y_axisx"), &rot[1][0]));
00274 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("y_axisy"), &rot[1][1]));
00275 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("y_axisz"), &rot[1][2]));
00276 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("z_axisx"), &rot[2][0]));
00277 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("z_axisy"), &rot[2][1]));
00278 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("z_axisz"), &rot[2][2]));
00279 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("focal"), &mesh.shot.Intrinsics.FocalMm));
00280 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("scalex"), &mesh.shot.Intrinsics.PixelSizeMm[0]));
00281 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("scaley"), &mesh.shot.Intrinsics.PixelSizeMm[1]));
00282 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("centerx"), &mesh.shot.Intrinsics.CenterPx[0]));
00283 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("centery"), &mesh.shot.Intrinsics.CenterPx[1]));
00284 cameraDescr.dataDescriptor.push_back(new DataDescriptor<int, 1, int>(std::string("viewportx"), &mesh.shot.Intrinsics.ViewportPx[0]));
00285 cameraDescr.dataDescriptor.push_back(new DataDescriptor<int, 1, int>(std::string("viewporty"), &mesh.shot.Intrinsics.ViewportPx[1]));
00286 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k1"), &mesh.shot.Intrinsics.k[0]));
00287 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k2"), &mesh.shot.Intrinsics.k[1]));
00288 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k3"), &mesh.shot.Intrinsics.k[2]));
00289 cameraDescr.dataDescriptor.push_back(new DataDescriptor<ScalarType, 1, ScalarType>(std::string("k4"), &mesh.shot.Intrinsics.k[3]));
00290 }
00291
00292
00293 std::vector<std::string> nameList;
00294 VertexType::Name(nameList);
00295 ElementDescriptor vertexDescr(NNP_VERTEX_ELEM);
00296 count = info.GetVertexCount();
00297 if (nameList.size() > 0 && count > 0)
00298 {
00299 vcg::tri::Allocator<MeshType>::AddVertices(mesh, count);
00300 if ((bitMask & BitMask::IO_VERTCOORD) && VertexType::HasCoord())
00301 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexCoordScalar>(NNP_PXYZ, (*mesh.vert.begin()).P().V()));
00302 if ((bitMask & BitMask::IO_VERTNORMAL) && vcg::tri::HasPerVertexNormal(mesh))
00303 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexNormScalar>(NNP_NXYZ, (*mesh.vert.begin()).N().V()));
00304 if ((bitMask & BitMask::IO_VERTCOLOR) && vcg::tri::HasPerVertexColor(mesh))
00305 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 4, VertexColorScalar>(NNP_CRGBA, (*mesh.vert.begin()).C().V()));
00306 if ((bitMask & BitMask::IO_VERTQUALITY) && vcg::tri::HasPerVertexQuality(mesh))
00307 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexQuality>(NNP_QUALITY, &(*mesh.vert.begin()).Q()));
00308 if ((bitMask & BitMask::IO_VERTFLAGS) && vcg::tri::HasPerVertexFlags(mesh))
00309 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexFlag>(NNP_BITFLAG, &(*mesh.vert.begin()).Flags()));
00310 if ((bitMask & BitMask::IO_VERTRADIUS) && vcg::tri::HasPerVertexRadius(mesh))
00311 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexRadius>(NNP_DENSITY, &(*mesh.vert.begin()).R()));
00312 if ((bitMask & BitMask::IO_VERTTEXCOORD) && vcg::tri::HasPerVertexTexCoord(mesh))
00313 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 2, VertexTexScalar>(NNP_TEXTURE2D, (*mesh.vert.begin()).T().P().V()));
00314 if ((bitMask & BitMask::IO_VERTCURV) && vcg::tri::HasPerVertexCurvature(mesh))
00315 {
00316 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexCurScalar>(NNP_KG, &(*mesh.vert.begin()).Kg()));
00317 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexCurScalar>(NNP_KH, &(*mesh.vert.begin()).Kh()));
00318 }
00319 if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerVertexCurvatureDir(mesh))
00320 {
00321 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexDirCurScalar>(NNP_K1, &(*mesh.vert.begin()).K1()));
00322 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 1, VertexDirCurScalar>(NNP_K2, &(*mesh.vert.begin()).K2()));
00323 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexDirCurVecScalar>(NNP_K1DIR, (*mesh.vert.begin()).PD1().V()));
00324 vertexDescr.dataDescriptor.push_back(new DataDescriptor<VertexType, 3, VertexDirCurVecScalar>(NNP_K2DIR, (*mesh.vert.begin()).PD2().V()));
00325 }
00326 if ((bitMask & BitMask::IO_VERTATTRIB) && custom.vertexAttrib.size() > 0)
00327 {
00328 for (int i = 0; i < custom.vertexAttrib.size(); i++)
00329 {
00330 std::set<PointerToAttribute>::iterator ai;
00331 for (ai = mesh.vert_attr.begin(); ai != mesh.vert_attr.end(); ++ai)
00332 {
00333 if ((*custom.vertexAttrib[i]).name == (*ai)._name)
00334 {
00335 custom.vertexAttrib[i]->base = ai->_handle->DataBegin();
00336 break;
00337 }
00338 }
00339 vertexDescr.dataDescriptor.push_back(custom.vertexAttrib[i]);
00340 }
00341 }
00342 }
00343
00344
00345 nameList.clear();
00346 EdgeType::Name(nameList);
00347 ElementDescriptor edgeDescr(NNP_EDGE_ELEM);
00348 count = info.GetEdgeCount();
00349 std::vector<vcg::Point2i> edgeIndex;
00350 if (nameList.size() > 0 && count > 0)
00351 {
00352 vcg::tri::Allocator<MeshType>::AddEdges(mesh, count);
00353 if ((bitMask & BitMask::IO_EDGEINDEX) && MeshType::EdgeType::HasVertexRef())
00354 {
00355 edgeIndex.resize(count);
00356 edgeDescr.dataDescriptor.push_back(new DataDescriptor<vcg::Point2i, 1, int>(NNP_EDGE_V1, &(*edgeIndex.begin()).V()[0]));
00357 edgeDescr.dataDescriptor.push_back(new DataDescriptor<vcg::Point2i, 1, int>(NNP_EDGE_V2, &(*edgeIndex.begin()).V()[1]));
00358 }
00359 if ((bitMask & BitMask::IO_EDGEQUALITY) && vcg::tri::HasPerEdgeQuality(mesh))
00360 edgeDescr.dataDescriptor.push_back(new DataDescriptor<EdgeType, 1, EdgeQuality>(NNP_QUALITY, &(*mesh.edge.begin()).Q()));
00361 if ((bitMask & BitMask::IO_EDGECOLOR) && vcg::tri::HasPerEdgeColor(mesh))
00362 edgeDescr.dataDescriptor.push_back(new DataDescriptor<EdgeType, 4, EdgeColorScalar>(NNP_CRGBA, (*mesh.edge.begin()).C().V()));
00363 if ((bitMask & BitMask::IO_EDGEFLAGS) && vcg::tri::HasPerEdgeFlags(mesh))
00364 edgeDescr.dataDescriptor.push_back(new DataDescriptor<EdgeType, 1, EdgeFlag>(NNP_BITFLAG, &(*mesh.edge.begin()).Flags()));
00365 if ((bitMask & BitMask::IO_EDGEATTRIB) && custom.edgeAttrib.size() > 0)
00366 {
00367 for (int i = 0; i < custom.edgeAttrib.size(); i++)
00368 {
00369 std::set<PointerToAttribute>::iterator ai;
00370 for (ai = mesh.edge_attr.begin(); ai != mesh.edge_attr.end(); ++ai)
00371 {
00372 if ((*custom.edgeAttrib[i]).name == (*ai)._name)
00373 {
00374 custom.edgeAttrib[i]->base = ai->_handle->DataBegin();
00375 break;
00376 }
00377 }
00378 edgeDescr.dataDescriptor.push_back(custom.edgeAttrib[i]);
00379 }
00380 }
00381 }
00382
00383
00384 nameList.clear();
00385 FaceType::Name(nameList);
00386 ElementDescriptor faceDescr(NNP_FACE_ELEM);
00387 count = info.GetFaceCount();
00388 std::vector<vcg::Point3i> faceIndex;
00389 std::vector<vcg::ndim::Point<6, FaceTexScalar>> wedgeTexCoord;
00390 if (nameList.size() > 0 && count > 0)
00391 {
00392 vcg::tri::Allocator<MeshType>::AddFaces(mesh, count);
00393 if ((bitMask & BitMask::IO_FACEINDEX) && FaceType::HasVertexRef())
00394 {
00395 faceIndex.resize(count);
00396 faceDescr.dataDescriptor.push_back(new DataDescriptor<vcg::Point3i, 3, int>(NNP_FACE_VERTEX_LIST, (*faceIndex.begin()).V()));
00397 }
00398 if ((bitMask & BitMask::IO_FACEFLAGS) && vcg::tri::HasPerFaceFlags(mesh))
00399 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceFlag>(NNP_BITFLAG, &(*mesh.face.begin()).Flags()));
00400 if ((bitMask & BitMask::IO_FACECOLOR) && vcg::tri::HasPerFaceColor(mesh))
00401 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 4, FaceColorScalar>(NNP_CRGBA, (*mesh.face.begin()).C().V()));
00402 if ((bitMask & BitMask::IO_FACEQUALITY) && vcg::tri::HasPerFaceQuality(mesh))
00403 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceQuality>(NNP_QUALITY, &(*mesh.face.begin()).Q()));
00404 if ((bitMask & BitMask::IO_FACENORMAL) && vcg::tri::HasPerFaceNormal(mesh))
00405 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 3, FaceNormScalar>(NNP_NXYZ, (*mesh.face.begin()).N().V()));
00406 if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerFaceCurvatureDir(mesh))
00407 {
00408 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceDirCurScalar>(NNP_K1, &(*mesh.face.begin()).K1()));
00409 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, FaceDirCurScalar>(NNP_K2, &(*mesh.face.begin()).K2()));
00410 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 3, FaceDirCurVecScalar>(NNP_K1DIR, (*mesh.face.begin()).PD1().V()));
00411 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 3, FaceDirCurVecScalar>(NNP_K2DIR, (*mesh.face.begin()).PD2().V()));
00412 }
00413 if (((bitMask & BitMask::IO_WEDGTEXCOORD) || (bitMask & BitMask::IO_WEDGTEXMULTI)) && vcg::tri::HasPerWedgeTexCoord(mesh))
00414 {
00415 wedgeTexCoord.resize(count);
00416 faceDescr.dataDescriptor.push_back(new DataDescriptor<vcg::ndim::Point<6, FaceTexScalar>, 6, FaceTexScalar>(NNP_FACE_WEDGE_TEX, (*wedgeTexCoord.begin()).V()));
00417 }
00418 if ((bitMask & BitMask::IO_WEDGTEXMULTI) && vcg::tri::HasPerWedgeTexCoord(mesh))
00419 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 1, short>(NNP_TEXTUREINDEX, &(*mesh.face.begin()).WT(0).N()));
00420 if ((bitMask & BitMask::IO_WEDGCOLOR) && vcg::tri::HasPerWedgeColor(mesh))
00421 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 12, WedgeColorScalar>(NNP_FACE_WEDGE_COLOR, (*mesh.face.begin()).WC(0).V()));
00422 if ((bitMask & BitMask::IO_WEDGNORMAL) && vcg::tri::HasPerWedgeNormal(mesh))
00423 faceDescr.dataDescriptor.push_back(new DataDescriptor<FaceType, 9, WedgeNormalScalar>(NNP_FACE_WEDGE_NORMAL, (*mesh.face.begin()).WN(0).V()));
00424 if ((bitMask & BitMask::IO_FACEATTRIB) && custom.faceAttrib.size() > 0)
00425 {
00426 for (int i = 0; i < custom.faceAttrib.size(); i++)
00427 {
00428 std::set<PointerToAttribute>::iterator ai;
00429 for (ai = mesh.face_attr.begin(); ai != mesh.face_attr.end(); ++ai)
00430 {
00431 if ((*custom.faceAttrib[i]).name == (*ai)._name)
00432 {
00433 custom.faceAttrib[i]->base = ai->_handle->DataBegin();
00434 break;
00435 }
00436 }
00437 faceDescr.dataDescriptor.push_back(custom.faceAttrib[i]);
00438
00439 }
00440 }
00441
00442 }
00443
00444 std::vector<ElementDescriptor*> meshDescr;
00445 meshDescr.push_back(&cameraDescr);
00446 meshDescr.push_back(&vertexDescr);
00447 meshDescr.push_back(&edgeDescr);
00448 meshDescr.push_back(&faceDescr);
00449
00450
00451 if ((bitMask & BitMask::IO_MESHATTRIB))
00452 {
00453 CustomAttributeDescriptor::MapMeshAttribIter iter = custom.meshAttrib.begin();
00454 for (; iter != custom.meshAttrib.end(); iter++)
00455 {
00456 std::string name((*iter).first);
00457 meshDescr.push_back(new ElementDescriptor(name));
00458 count = info.GetElementCount(name);
00459 if (count > 1)
00460 {
00461 meshDescr.back()->dataDescriptor = (*iter).second;
00462 }
00463 }
00464
00465 }
00466 if (!OpenModel(info, meshDescr))
00467 return info.errInfo;
00468
00469 mesh.shot.SetViewPoint(tra);
00470 mesh.shot.Extrinsics.SetRot(rot);
00471 for (int i = 0; i < faceIndex.size(); i++)
00472 for (int j = 0; j < 3; j++)
00473 mesh.face[i].V(j) = &mesh.vert[faceIndex[i][j]];
00474 for (int i = 0; i < wedgeTexCoord.size(); i++)
00475 {
00476 for (int j = 0; j < 3; j++)
00477 {
00478 mesh.face[i].WT(j).U() = wedgeTexCoord[i][j * 2];
00479 mesh.face[i].WT(j).V() = wedgeTexCoord[i][j * 2 + 1];
00480 }
00481 }
00482 for (int i = 0; i < edgeIndex.size(); i++)
00483 {
00484 mesh.edge[i].V(0) = &mesh.vert[edgeIndex[i].X()];
00485 mesh.edge[i].V(1) = &mesh.vert[edgeIndex[i].Y()];
00486 }
00487
00488 for (int i = 0; i < cameraDescr.dataDescriptor.size(); i++)
00489 delete cameraDescr.dataDescriptor[i];
00490 for (int i = 0; i < vertexDescr.dataDescriptor.size(); i++)
00491 if (vertexDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY)
00492 delete vertexDescr.dataDescriptor[i];
00493 for (int i = 0; i < edgeDescr.dataDescriptor.size(); i++)
00494 if (edgeDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY)
00495 delete edgeDescr.dataDescriptor[i];
00496 for (int i = 0; i < faceDescr.dataDescriptor.size(); i++)
00497 if (faceDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY)
00498 delete faceDescr.dataDescriptor[i];
00499
00500 return info.errInfo;
00501 }
00502
00503
00504 static int LoadModel(const char* filename, MeshType& mesh, unsigned int bitMask)
00505 {
00506 CustomAttributeDescriptor custom;
00507 return LoadModel(filename, mesh, bitMask, custom);
00508 }
00509
00510
00511 static bool SaveModel(const char* filename, MeshType& mesh, unsigned int bitMask, CustomAttributeDescriptor& custom, bool binary)
00512 {
00513
00514 std::vector<PlyProperty> cameraProp;
00515 ElementDescriptor cameraDescr(std::string("camera"));
00516 vcg::Point3<ScalarType> tra = mesh.shot.Extrinsics.Tra();
00517 vcg::Matrix44<ScalarType> rot = mesh.shot.Extrinsics.Rot();
00518 if (bitMask & BitMask::IO_CAMERA)
00519 {
00520 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("view_px"), &tra[0]);
00521 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("view_py"), &tra[1]);
00522 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("view_pz"), &tra[2]);
00523 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("x_axisx"), &rot[0][0]);
00524 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("x_axisy"), &rot[0][1]);
00525 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("x_axisz"), &rot[0][2]);
00526 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("y_axisx"), &rot[1][0]);
00527 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("y_axisy"), &rot[1][1]);
00528 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("y_axisz"), &rot[1][2]);
00529 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("z_axisx"), &rot[2][0]);
00530 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("z_axisy"), &rot[2][1]);
00531 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("z_axisz"), &rot[2][2]);
00532 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("focal"), &mesh.shot.Intrinsics.FocalMm);
00533 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("scalex"), &mesh.shot.Intrinsics.PixelSizeMm[0]);
00534 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("scaley"), &mesh.shot.Intrinsics.PixelSizeMm[1]);
00535 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("centerx"), &mesh.shot.Intrinsics.CenterPx[0]);
00536 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("centery"), &mesh.shot.Intrinsics.CenterPx[1]);
00537 PushDescriport<int, int, 1>(cameraProp, cameraDescr, std::string("viewportx"), &mesh.shot.Intrinsics.ViewportPx[0]);
00538 PushDescriport<int, int, 1>(cameraProp, cameraDescr, std::string("viewporty"), &mesh.shot.Intrinsics.ViewportPx[1]);
00539 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k1"), &mesh.shot.Intrinsics.k[0]);
00540 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k2"), &mesh.shot.Intrinsics.k[1]);
00541 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k3"), &mesh.shot.Intrinsics.k[2]);
00542 PushDescriport<ScalarType, ScalarType, 1>(cameraProp, cameraDescr, std::string("k4"), &mesh.shot.Intrinsics.k[3]);
00543 }
00544
00545
00546 std::vector<std::string> nameList;
00547 VertexType::Name(nameList);
00548 std::vector<PlyProperty> vertexProp;
00549 ElementDescriptor vertexDescr(NNP_VERTEX_ELEM);
00550 if (nameList.size() > 0 && mesh.vert.size() > 0)
00551 {
00552 if ((bitMask & BitMask::IO_VERTCOORD) && VertexType::HasCoord())
00553 PushDescriport<VertexType, VertexCoordScalar, 3>(vertexProp, vertexDescr, NNP_PXYZ, (*mesh.vert.begin()).P().V());
00554 if ((bitMask & BitMask::IO_VERTNORMAL) && vcg::tri::HasPerVertexNormal(mesh))
00555 PushDescriport<VertexType, VertexNormScalar, 3>(vertexProp, vertexDescr, NNP_NXYZ, (*mesh.vert.begin()).N().V());
00556 if ((bitMask & BitMask::IO_VERTCOLOR) && vcg::tri::HasPerVertexColor(mesh))
00557 PushDescriport<VertexType, VertexColorScalar, 4>(vertexProp, vertexDescr, NNP_CRGBA, (*mesh.vert.begin()).C().V());
00558 if ((bitMask & BitMask::IO_VERTQUALITY) && vcg::tri::HasPerVertexQuality(mesh))
00559 PushDescriport<VertexType, VertexQuality, 1>(vertexProp, vertexDescr, NNP_QUALITY, &(*mesh.vert.begin()).Q());
00560 if ((bitMask & BitMask::IO_VERTFLAGS) && vcg::tri::HasPerVertexFlags(mesh))
00561 PushDescriport<VertexType, VertexFlag, 1>(vertexProp, vertexDescr, NNP_BITFLAG, &(*mesh.vert.begin()).Flags());
00562 if ((bitMask & BitMask::IO_VERTRADIUS) && vcg::tri::HasPerVertexRadius(mesh))
00563 PushDescriport<VertexType, VertexRadius, 1>(vertexProp, vertexDescr, NNP_DENSITY, &(*mesh.vert.begin()).R());
00564 if ((bitMask & BitMask::IO_VERTTEXCOORD) && vcg::tri::HasPerVertexTexCoord(mesh))
00565 PushDescriport<VertexType, VertexTexScalar, 2>(vertexProp, vertexDescr, NNP_TEXTURE2D, (*mesh.vert.begin()).T().P().V());
00566 if ((bitMask & BitMask::IO_VERTCURV) && vcg::tri::HasPerVertexCurvature(mesh))
00567 {
00568 PushDescriport<VertexType, VertexCurScalar, 1>(vertexProp, vertexDescr, NNP_KG, &(*mesh.vert.begin()).Kg());
00569 PushDescriport<VertexType, VertexCurScalar, 1>(vertexProp, vertexDescr, NNP_KH, &(*mesh.vert.begin()).Kh());
00570 }
00571 if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerVertexCurvatureDir(mesh))
00572 {
00573 PushDescriport<VertexType, VertexDirCurScalar, 1>(vertexProp, vertexDescr, NNP_K1, &(*mesh.vert.begin()).K1());
00574 PushDescriport<VertexType, VertexDirCurScalar, 1>(vertexProp, vertexDescr, NNP_K2, &(*mesh.vert.begin()).K2());
00575 PushDescriportList<VertexType, VertexDirCurVecScalar, 3>(vertexProp, vertexDescr, NNP_K1DIR, (*mesh.vert.begin()).PD1().V());
00576 PushDescriportList<VertexType, VertexDirCurVecScalar, 3>(vertexProp, vertexDescr, NNP_K2DIR, (*mesh.vert.begin()).PD2().V());
00577 }
00578 if ((bitMask & BitMask::IO_VERTATTRIB) && custom.vertexAttrib.size() > 0)
00579 {
00580 for (int i = 0; i < custom.vertexAttrib.size(); i++)
00581 {
00582 vertexProp.push_back(custom.vertexAttribProp[i]);
00583 vertexDescr.dataDescriptor.push_back(custom.vertexAttrib[i]);
00584 }
00585 }
00586 }
00587
00588
00589 nameList.clear();
00590 EdgeType::Name(nameList);
00591 std::vector<PlyProperty> edgeProp;
00592 ElementDescriptor edgeDescr(NNP_VERTEX_ELEM);
00593 std::vector<vcg::Point2i> edgeIndex;
00594 for (int i = 0; i < mesh.edge.size(); i++)
00595 edgeIndex.push_back(vcg::Point2i(vcg::tri::Index(mesh, mesh.edge[i].V(0)), vcg::tri::Index(mesh, mesh.edge[i].V(1))));
00596 if (nameList.size() > 0 && mesh.edge.size() > 0)
00597 {
00598 if ((bitMask & BitMask::IO_EDGEINDEX) && EdgeType::HasVertexRef())
00599 {
00600 PushDescriport<vcg::Point2i, int, 1>(edgeProp, edgeDescr, NNP_EDGE_V1, &(*edgeIndex.begin()).V()[0]);
00601 PushDescriport<vcg::Point2i, int, 1>(edgeProp, edgeDescr, NNP_EDGE_V2, &(*edgeIndex.begin()).V()[1]);
00602 }
00603 if ((bitMask & BitMask::IO_EDGEQUALITY) && vcg::tri::HasPerEdgeQuality(mesh))
00604 PushDescriport<EdgeType, EdgeQuality, 1>(edgeProp, edgeDescr, NNP_QUALITY, &(*mesh.edge.begin()).Q());
00605 if ((bitMask & BitMask::IO_EDGECOLOR) && vcg::tri::HasPerEdgeColor(mesh))
00606 PushDescriport<EdgeType, EdgeColorScalar, 4>(edgeProp, edgeDescr, NNP_CRGBA, (*mesh.edge.begin()).C().V());
00607 if ((bitMask & BitMask::IO_EDGEFLAGS) && vcg::tri::HasPerEdgeFlags(mesh))
00608 PushDescriport<EdgeType, EdgeFlag, 1>(edgeProp, edgeDescr, NNP_BITFLAG, &(*mesh.edge.begin()).Flags());
00609 if ((bitMask & BitMask::IO_EDGEATTRIB) && custom.edgeAttrib.size() > 0)
00610 {
00611 for (int i = 0; i < custom.edgeAttrib.size(); i++)
00612 {
00613 edgeProp.push_back(custom.edgeAttribProp[i]);
00614 edgeDescr.dataDescriptor.push_back(custom.edgeAttrib[i]);
00615 }
00616 }
00617 }
00618
00619
00620 nameList.clear();
00621 FaceType::Name(nameList);
00622 std::vector<PlyProperty> faceProp;
00623 ElementDescriptor faceDescr(NNP_FACE_ELEM);
00624 std::vector<vcg::Point3i> faceIndex;
00625 std::vector<vcg::ndim::Point<6, FaceTexScalar>> wedgeTexCoord;
00626 for (int i = 0; i < mesh.face.size(); i++)
00627 faceIndex.push_back(vcg::Point3i(vcg::tri::Index(mesh, mesh.face[i].V(0)), vcg::tri::Index(mesh, mesh.face[i].V(1)), vcg::tri::Index(mesh, mesh.face[i].V(2))));
00628
00629 if (((bitMask & BitMask::IO_WEDGTEXCOORD) || (bitMask & BitMask::IO_WEDGTEXMULTI)) && vcg::tri::HasPerWedgeTexCoord(mesh))
00630 {
00631 for (int i = 0; i < mesh.face.size(); i++)
00632 {
00633 wedgeTexCoord.push_back(vcg::ndim::Point<6, FaceTexScalar>());
00634 for (int j = 0; j < 3; j++)
00635 {
00636 wedgeTexCoord.back()[j * 2] = mesh.face[i].WT(j).U();
00637 wedgeTexCoord.back()[j * 2 + 1] = mesh.face[i].WT(j).V();
00638 }
00639 }
00640 }
00641 if (nameList.size() > 0 && mesh.face.size() > 0)
00642 {
00643 if ((bitMask & BitMask::IO_FACEINDEX) && FaceType::HasVertexRef())
00644 PushDescriportList<vcg::Point3i, int, 3>(faceProp, faceDescr, NNP_FACE_VERTEX_LIST, (*faceIndex.begin()).V());
00645 if ((bitMask & BitMask::IO_FACEFLAGS) && vcg::tri::HasPerFaceFlags(mesh))
00646 PushDescriport<FaceType, FaceFlag, 1>(faceProp, faceDescr, NNP_BITFLAG, &(*mesh.face.begin()).Flags());
00647 if ((bitMask & BitMask::IO_FACECOLOR) && vcg::tri::HasPerFaceColor(mesh))
00648 PushDescriport<FaceType, FaceColorScalar, 4>(faceProp, faceDescr, NNP_CRGBA, (*mesh.face.begin()).C().V());
00649 if ((bitMask & BitMask::IO_FACEQUALITY) && vcg::tri::HasPerFaceQuality(mesh))
00650 PushDescriport<FaceType, FaceQuality, 1>(faceProp, faceDescr, NNP_QUALITY, &(*mesh.face.begin()).Q());
00651 if ((bitMask & BitMask::IO_FACENORMAL) && vcg::tri::HasPerFaceNormal(mesh))
00652 PushDescriport<FaceType, FaceNormScalar, 3>(faceProp, faceDescr, NNP_NXYZ, (*mesh.face.begin()).N().V());
00653 if ((bitMask & BitMask::IO_VERTCURVDIR) && vcg::tri::HasPerFaceCurvatureDir(mesh))
00654 {
00655 PushDescriport<FaceType, FaceDirCurScalar, 1>(faceProp, faceDescr, NNP_K1, &(*mesh.face.begin()).K1());
00656 PushDescriport<FaceType, FaceDirCurScalar, 1>(faceProp, faceDescr, NNP_K2, &(*mesh.face.begin()).K2());
00657 PushDescriportList<FaceType, FaceDirCurVecScalar, 3>(faceProp, faceDescr, NNP_K1DIR, (*mesh.face.begin()).PD1().V());
00658 PushDescriportList<FaceType, FaceDirCurVecScalar, 3>(faceProp, faceDescr, NNP_K2DIR, (*mesh.face.begin()).PD2().V());
00659 }
00660 if (((bitMask & BitMask::IO_WEDGTEXCOORD) || (bitMask & BitMask::IO_WEDGTEXMULTI)) && vcg::tri::HasPerWedgeTexCoord(mesh))
00661 PushDescriportList<vcg::ndim::Point<6, FaceTexScalar>, FaceTexScalar, 6>(faceProp, faceDescr, NNP_FACE_WEDGE_TEX, (*wedgeTexCoord.begin()).V());
00662 if ((bitMask & BitMask::IO_WEDGTEXMULTI) && vcg::tri::HasPerWedgeTexCoord(mesh))
00663 PushDescriport<FaceType, short, 1>(faceProp, faceDescr, NNP_TEXTUREINDEX, &(*mesh.face.begin()).WT(0).N());
00664 if ((bitMask & BitMask::IO_WEDGCOLOR) && vcg::tri::HasPerWedgeColor(mesh))
00665 PushDescriportList<FaceType, WedgeColorScalar, 12>(faceProp, faceDescr, NNP_FACE_WEDGE_COLOR, (*mesh.face.begin()).WC(0).V());
00666 if ((bitMask & BitMask::IO_WEDGNORMAL) && vcg::tri::HasPerWedgeNormal(mesh))
00667 PushDescriportList<FaceType, WedgeNormalScalar, 9>(faceProp, faceDescr, NNP_FACE_WEDGE_NORMAL, (*mesh.face.begin()).WN(0).V());
00668 if ((bitMask & BitMask::IO_FACEATTRIB) && custom.faceAttrib.size() > 0)
00669 {
00670 for (int i = 0; i < custom.faceAttrib.size(); i++)
00671 {
00672 faceProp.push_back(custom.faceAttribProp[i]);
00673 faceDescr.dataDescriptor.push_back(custom.faceAttrib[i]);
00674 }
00675 }
00676
00677 }
00678
00679 Info infoSave;
00680 infoSave.filename = filename;
00681 infoSave.binary = binary;
00682 PlyElement cameraElem(std::string("camera"), cameraProp, 1);
00683 PlyElement vertexElem(NNP_VERTEX_ELEM, vertexProp, mesh.vert.size());
00684 PlyElement edgeElem(NNP_EDGE_ELEM, edgeProp, mesh.edge.size());
00685 PlyElement faceElem(NNP_FACE_ELEM, faceProp, mesh.face.size());
00686 infoSave.AddPlyElement(cameraElem);
00687 infoSave.AddPlyElement(vertexElem);
00688 infoSave.AddPlyElement(edgeElem);
00689 infoSave.AddPlyElement(faceElem);
00690 std::vector<ElementDescriptor*> meshDescr;
00691 meshDescr.push_back(&cameraDescr);
00692 meshDescr.push_back(&vertexDescr);
00693 meshDescr.push_back(&edgeDescr);
00694 meshDescr.push_back(&faceDescr);
00695
00696
00697 if ((bitMask & BitMask::IO_MESHATTRIB))
00698 {
00699 CustomAttributeDescriptor::MapMeshAttribIter iter = custom.meshAttrib.begin();
00700 CustomAttributeDescriptor::MapMeshAttribPropIter iterProp = custom.meshAttribProp.begin();
00701 for (; iter != custom.meshAttrib.end(); iter++, iterProp++)
00702 {
00703 std::string name((*iter).first);
00704 PlyElement customElem(name, (*iterProp).second, custom.meshAttribCnt[(*iter).first]);
00705 infoSave.AddPlyElement(customElem);
00706 meshDescr.push_back(new ElementDescriptor(name));
00707 meshDescr.back()->dataDescriptor = (*iter).second;
00708 }
00709 }
00710
00711 bool flag = nanoply::SaveModel(infoSave.filename, meshDescr, infoSave);
00712
00713 for (int i = 0; i < cameraDescr.dataDescriptor.size(); i++)
00714 delete cameraDescr.dataDescriptor[i];
00715 for (int i = 0; i < vertexDescr.dataDescriptor.size(); i++)
00716 if (vertexDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY)
00717 delete vertexDescr.dataDescriptor[i];
00718 for (int i = 0; i < edgeDescr.dataDescriptor.size(); i++)
00719 if (edgeDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY)
00720 delete edgeDescr.dataDescriptor[i];
00721 for (int i = 0; i < faceDescr.dataDescriptor.size(); i++)
00722 if (faceDescr.dataDescriptor[i]->elem != NNP_UNKNOWN_ENTITY)
00723 delete faceDescr.dataDescriptor[i];
00724
00725 return flag;
00726 }
00727
00728
00729 static bool SaveModel(const char* filename, MeshType& mesh, unsigned int bitMask, bool binary)
00730 {
00731 CustomAttributeDescriptor custom;
00732 return SaveModel(filename, mesh, bitMask, custom, binary);
00733 }
00734
00735
00736 };
00737
00738 }
00739
00740 #endif