possibility to export double attributes in ply
This commit is contained in:
parent
23082f1994
commit
d4718bde6a
|
|
@ -211,7 +211,7 @@ namespace vcg {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
for(size_t i=0;i<pi.VertDescriptorVec.size();i++)
|
for(size_t i=0;i<pi.VertDescriptorVec.size();i++)
|
||||||
fprintf(fpout,"property %s %s\n",pi.VertDescriptorVec[i].stotypename(),pi.VertDescriptorVec[i].propname);
|
fprintf(fpout,"property %s %s\n",pi.VertDescriptorVec[i].stotypename(),pi.VertDescriptorVec[i].propname.c_str());
|
||||||
|
|
||||||
fprintf(fpout,
|
fprintf(fpout,
|
||||||
"element face %d\n"
|
"element face %d\n"
|
||||||
|
|
@ -278,7 +278,7 @@ namespace vcg {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(size_t i=0;i<pi.FaceDescriptorVec.size();i++)
|
for(size_t i=0;i<pi.FaceDescriptorVec.size();i++)
|
||||||
fprintf(fpout,"property %s %s\n",pi.FaceDescriptorVec[i].stotypename(),pi.FaceDescriptorVec[i].propname);
|
fprintf(fpout,"property %s %s\n",pi.FaceDescriptorVec[i].stotypename(),pi.FaceDescriptorVec[i].propname.c_str());
|
||||||
// Saving of edges is enabled if requested
|
// Saving of edges is enabled if requested
|
||||||
if( m.en>0 && (pi.mask & Mask::IOM_EDGEINDEX) )
|
if( m.en>0 && (pi.mask & Mask::IOM_EDGEINDEX) )
|
||||||
fprintf(fpout,
|
fprintf(fpout,
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,8 @@ Initial commit
|
||||||
#define __VCGLIB_IOTRIMESH_IO_PLY
|
#define __VCGLIB_IOTRIMESH_IO_PLY
|
||||||
|
|
||||||
|
|
||||||
|
#include <vcg/complex/allocate.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@name Load and Save in Ply format
|
@name Load and Save in Ply format
|
||||||
*/
|
*/
|
||||||
|
|
@ -64,37 +66,65 @@ This class can be passed to the ImporterPLY::Open() function for
|
||||||
class PlyInfo
|
class PlyInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef ::vcg::ply::PropDescriptor PropDescriptor ;
|
typedef ::vcg::ply::PropDescriptor PropDescriptor ;
|
||||||
|
|
||||||
void AddPerElemFloatAttribute(int elemType, const char *attrName, const char * propName=0)
|
void addPerElemScalarAttribute(int elemType, vcg::ply::PlyTypes propertyType, const std::string& attrName, std::string propName="")
|
||||||
{
|
{
|
||||||
static const char *elemStr[2]={"vertex","face"};
|
if(propName=="")
|
||||||
std::vector<PropDescriptor> *elemDescVec[2]={&(this->VertDescriptorVec), &(this->FaceDescriptorVec)};
|
propName=attrName;
|
||||||
std::vector<std::string > *elemNameVec[2]={&(this->VertAttrNameVec), &(this->FaceAttrNameVec)};
|
|
||||||
|
|
||||||
if(propName==0) propName=attrName;
|
if (elemType == 0){ //vertex
|
||||||
elemDescVec[elemType]->push_back(PropDescriptor());
|
VertDescriptorVec.push_back(PropDescriptor());
|
||||||
elemNameVec[elemType]->push_back(attrName);
|
VertAttrNameVec.push_back(attrName);
|
||||||
elemDescVec[elemType]->back().elemname=elemStr[elemType];
|
VertDescriptorVec.back().elemname="vertex";
|
||||||
elemDescVec[elemType]->back().propname=strdup(propName);
|
VertDescriptorVec.back().propname=propName;
|
||||||
elemDescVec[elemType]->back().stotype1 = vcg::ply::T_FLOAT;
|
VertDescriptorVec.back().stotype1 = propertyType;
|
||||||
elemDescVec[elemType]->back().memtype1 = vcg::ply::T_FLOAT;
|
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) {
|
void AddPerElemFloatAttribute(int elemType, const std::string& attrName, std::string propName="")
|
||||||
AddPerElemFloatAttribute(0,attrName,propName);
|
{
|
||||||
}
|
addPerElemScalarAttribute(elemType, vcg::ply::T_FLOAT, attrName, propName);
|
||||||
void AddPerFaceFloatAttribute(const char *attrName, const char *propName=0) {
|
}
|
||||||
AddPerElemFloatAttribute(1,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.
|
/* 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... */
|
* Actually require to allocate 3 float attribute and save them. And they are never deallocated... */
|
||||||
template<class MeshType>
|
template<class MeshType>
|
||||||
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] = {
|
const char *attrxyz[3] = {
|
||||||
strdup((std::string(attrName)+std::string("_x")).c_str()),
|
strdup((std::string(attrName)+std::string("_x")).c_str()),
|
||||||
|
|
@ -151,7 +181,7 @@ public:
|
||||||
|
|
||||||
enum Error
|
enum Error
|
||||||
{
|
{
|
||||||
// Funzioni superiori
|
// Funzioni superiori
|
||||||
E_NO_VERTEX = ply::E_MAXPLYERRORS+1, // 15
|
E_NO_VERTEX = ply::E_MAXPLYERRORS+1, // 15
|
||||||
E_NO_FACE = ply::E_MAXPLYERRORS+2, // 16
|
E_NO_FACE = ply::E_MAXPLYERRORS+2, // 16
|
||||||
E_SHORTFILE = ply::E_MAXPLYERRORS+3, // 17
|
E_SHORTFILE = ply::E_MAXPLYERRORS+3, // 17
|
||||||
|
|
|
||||||
|
|
@ -112,33 +112,27 @@ typedef FILE * GZFILE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Messaggio di errore
|
// Ply Property descriptor
|
||||||
//extern const char * ply_error_msg[];
|
|
||||||
|
|
||||||
// TIPO FILE
|
|
||||||
|
|
||||||
|
|
||||||
// Descrittore esterno di propieta'
|
|
||||||
class PropDescriptor
|
class PropDescriptor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
const char * elemname; // Nome dell'elemento
|
std::string elemname; // name of the element (e.g. vertex)
|
||||||
const char * propname; // Nome della propieta'
|
std::string propname; // name of the property (e.g. x, y, red...)
|
||||||
int stotype1; // Tipo dell'elemento su file (se lista tipo degli elementi della lista)
|
int stotype1; // Type of the property in the file
|
||||||
int memtype1; // Tipo dell'elemento in memoria (se lista tipo degli elementi della lista)
|
int memtype1; // Type of the property in memory
|
||||||
size_t offset1; // Offset del valore in memoria
|
size_t offset1; // Offset in memory
|
||||||
int islist; // 1 se lista, 0 altrimenti
|
bool islist; // true if the property is a list
|
||||||
int alloclist; // 1 se alloca lista, 0 se preallocata
|
bool alloclist; // 1 se alloca lista, 0 se preallocata
|
||||||
int stotype2; // Tipo del numero di elementi della lista su file
|
int stotype2; // Type of the number of elements of the list in the file
|
||||||
int memtype2; // Tipo del numero di elementi della lista in memoria
|
int memtype2; // Type of the number of elements of the list in memory
|
||||||
size_t offset2; // Offset valore memoria
|
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 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
|
size_t memtypesize() const; // per sapere quanto e'grande un dato descrittore in memoria
|
||||||
const char *memtypename() const;
|
const char* memtypename() const;
|
||||||
const char *stotypename() const;
|
const char* stotypename() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reading Callback (used to copy a data prop)
|
// Reading Callback (used to copy a data prop)
|
||||||
|
|
@ -231,7 +225,7 @@ public:
|
||||||
std::string name; // Nome dell'elemento
|
std::string name; // Nome dell'elemento
|
||||||
int number; // Numero di elementi di questo tipo
|
int number; // Numero di elementi di questo tipo
|
||||||
|
|
||||||
std::vector<PlyProperty> props; // Vettore dinamico delle property
|
std::vector<PlyProperty> props; // Vettore dinamico delle property
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -273,7 +267,7 @@ public:
|
||||||
// Come sopra ma con descrittore
|
// Come sopra ma con descrittore
|
||||||
inline int AddToRead( const PropDescriptor & p )
|
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.memtype1,p.offset1,p.islist,p.alloclist,p.stotype2,
|
||||||
p.memtype2,p.offset2
|
p.memtype2,p.offset2
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue