diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index 3874c5fc..ca097e96 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -211,7 +211,7 @@ namespace vcg { ); } for(size_t i=0;i0 && (pi.mask & Mask::IOM_EDGEINDEX) ) fprintf(fpout, diff --git a/wrap/io_trimesh/io_ply.h b/wrap/io_trimesh/io_ply.h index f52547e8..d939d610 100644 --- a/wrap/io_trimesh/io_ply.h +++ b/wrap/io_trimesh/io_ply.h @@ -41,6 +41,8 @@ Initial commit #define __VCGLIB_IOTRIMESH_IO_PLY +#include + /** @name Load and Save in Ply format */ @@ -64,37 +66,65 @@ This class can be passed to the ImporterPLY::Open() function for class PlyInfo { public: - typedef ::vcg::ply::PropDescriptor PropDescriptor ; + typedef ::vcg::ply::PropDescriptor PropDescriptor ; - void AddPerElemFloatAttribute(int elemType, const char *attrName, const char * propName=0) - { - static const char *elemStr[2]={"vertex","face"}; - std::vector *elemDescVec[2]={&(this->VertDescriptorVec), &(this->FaceDescriptorVec)}; - std::vector *elemNameVec[2]={&(this->VertAttrNameVec), &(this->FaceAttrNameVec)}; + void addPerElemScalarAttribute(int elemType, vcg::ply::PlyTypes propertyType, const std::string& attrName, std::string propName="") + { + if(propName=="") + propName=attrName; - if(propName==0) propName=attrName; - elemDescVec[elemType]->push_back(PropDescriptor()); - elemNameVec[elemType]->push_back(attrName); - elemDescVec[elemType]->back().elemname=elemStr[elemType]; - elemDescVec[elemType]->back().propname=strdup(propName); - elemDescVec[elemType]->back().stotype1 = vcg::ply::T_FLOAT; - elemDescVec[elemType]->back().memtype1 = vcg::ply::T_FLOAT; - } + if (elemType == 0){ //vertex + VertDescriptorVec.push_back(PropDescriptor()); + VertAttrNameVec.push_back(attrName); + VertDescriptorVec.back().elemname="vertex"; + VertDescriptorVec.back().propname=propName; + VertDescriptorVec.back().stotype1 = propertyType; + VertDescriptorVec.back().memtype1 = propertyType; + } + else if (elemType == 1){ //face + FaceDescriptorVec.push_back(PropDescriptor()); + FaceAttrNameVec.push_back(attrName); + FaceDescriptorVec.back().elemname="face"; + FaceDescriptorVec.back().propname=propName; + FaceDescriptorVec.back().stotype1 = propertyType; + FaceDescriptorVec.back().memtype1 = propertyType; + } + } - void AddPerVertexFloatAttribute(const char *attrName, const char *propName=0) { - AddPerElemFloatAttribute(0,attrName,propName); - } - void AddPerFaceFloatAttribute(const char *attrName, const char *propName=0) { - AddPerElemFloatAttribute(1,attrName,propName); - } + void AddPerElemFloatAttribute(int elemType, const std::string& attrName, std::string propName="") + { + addPerElemScalarAttribute(elemType, vcg::ply::T_FLOAT, attrName, propName); + } + + void AddPerElemDoubleAttribute(int elemType, const std::string& attrName, std::string propName="") + { + addPerElemScalarAttribute(elemType, vcg::ply::T_DOUBLE, attrName, propName); + } + + void addPerVertexScalarAttribute(const std::string& attrName, vcg::ply::PlyTypes attrType, std::string propName="") { + addPerElemScalarAttribute(0,attrType, attrName,propName); + } + + void AddPerVertexFloatAttribute(const std::string& attrName, std::string propName="") { + AddPerElemFloatAttribute(0,attrName,propName); + } + + void addPerFaceScalarAttribute(const std::string& attrName, vcg::ply::PlyTypes attrType, std::string propName="") { + addPerElemScalarAttribute(1,attrType, attrName,propName); + } + + void AddPerFaceFloatAttribute(const std::string& attrName, std::string propName="") { + AddPerElemFloatAttribute(1,attrName,propName); + } /* Note that saving a per vertex point3 attribute is a mess. * Actually require to allocate 3 float attribute and save them. And they are never deallocated... */ template - void AddPerVertexPoint3fAttribute(MeshType &m, const char *attrName, const char *propName="") + void AddPerVertexPoint3fAttribute(MeshType &m, const std::string& attrName, std::string propName="") { - if(propName==0) propName=attrName; + if(propName=="") + propName=attrName; const char *attrxyz[3] = { strdup((std::string(attrName)+std::string("_x")).c_str()), @@ -151,7 +181,7 @@ public: enum Error { - // Funzioni superiori + // Funzioni superiori E_NO_VERTEX = ply::E_MAXPLYERRORS+1, // 15 E_NO_FACE = ply::E_MAXPLYERRORS+2, // 16 E_SHORTFILE = ply::E_MAXPLYERRORS+3, // 17 diff --git a/wrap/ply/plylib.h b/wrap/ply/plylib.h index 59e5eddd..88470b20 100644 --- a/wrap/ply/plylib.h +++ b/wrap/ply/plylib.h @@ -112,33 +112,27 @@ typedef FILE * GZFILE; #endif - // Messaggio di errore -//extern const char * ply_error_msg[]; - - // TIPO FILE - - -// Descrittore esterno di propieta' +// Ply Property descriptor class PropDescriptor { public: - const char * elemname; // Nome dell'elemento - const char * propname; // Nome della propieta' - int stotype1; // Tipo dell'elemento su file (se lista tipo degli elementi della lista) - int memtype1; // Tipo dell'elemento in memoria (se lista tipo degli elementi della lista) - size_t offset1; // Offset del valore in memoria - int islist; // 1 se lista, 0 altrimenti - int alloclist; // 1 se alloca lista, 0 se preallocata - int stotype2; // Tipo del numero di elementi della lista su file - int memtype2; // Tipo del numero di elementi della lista in memoria - size_t offset2; // Offset valore memoria + std::string elemname; // name of the element (e.g. vertex) + std::string propname; // name of the property (e.g. x, y, red...) + int stotype1; // Type of the property in the file + int memtype1; // Type of the property in memory + size_t offset1; // Offset in memory + bool islist; // true if the property is a list + bool alloclist; // 1 se alloca lista, 0 se preallocata + int stotype2; // Type of the number of elements of the list in the file + int memtype2; // Type of the number of elements of the list in memory + size_t offset2; // Offset valore memoria - int format; // duplicazione del formato + int format; // duplicazione del formato - size_t stotypesize() const; // per sapere quanto e'grande un dato descrittore sul file - size_t memtypesize() const; // per sapere quanto e'grande un dato descrittore in memoria - const char *memtypename() const; - const char *stotypename() const; + size_t stotypesize() const; // per sapere quanto e'grande un dato descrittore sul file + size_t memtypesize() const; // per sapere quanto e'grande un dato descrittore in memoria + const char* memtypename() const; + const char* stotypename() const; }; // Reading Callback (used to copy a data prop) @@ -231,7 +225,7 @@ public: std::string name; // Nome dell'elemento int number; // Numero di elementi di questo tipo - std::vector props; // Vettore dinamico delle property + std::vector props; // Vettore dinamico delle property }; @@ -273,7 +267,7 @@ public: // Come sopra ma con descrittore inline int AddToRead( const PropDescriptor & p ) { - return AddToRead(p.elemname,p.propname,p.stotype1, + return AddToRead(p.elemname.c_str(),p.propname.c_str(),p.stotype1, p.memtype1,p.offset1,p.islist,p.alloclist,p.stotype2, p.memtype2,p.offset2 );