support export per face point custom attributes on ply

This commit is contained in:
alemuntoni 2021-04-02 17:02:03 +02:00
parent 702c139108
commit c1d9732381
2 changed files with 108 additions and 35 deletions

View File

@ -284,8 +284,24 @@ public:
fprintf(fpout,"property %s quality\n",fqtp); fprintf(fpout,"property %s quality\n",fqtp);
} }
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.c_str()); if (!pi.FaceDescriptorVec[i].islist){
fprintf(
fpout,
"property %s %s\n",
pi.FaceDescriptorVec[i].stotypename(),
pi.FaceDescriptorVec[i].propname.c_str());
}
else {
fprintf(
fpout,
"property list %s %s %s\n",
pi.FaceDescriptorVec[i].stotype2name(),
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( fprintf(
@ -406,12 +422,15 @@ public:
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<short > > thsf(pi.FaceDescriptorVec.size()); std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<short > > thsf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<char > > thcf(pi.FaceDescriptorVec.size()); std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<char > > thcf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<unsigned char> > thuf(pi.FaceDescriptorVec.size()); std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<unsigned char> > thuf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<vcg::Point3f> > thp3ff(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<vcg::Point3d> > thp3df(pi.FaceDescriptorVec.size());
for(size_t i=0;i<pi.FaceDescriptorVec.size();i++) for(size_t i=0;i<pi.FaceDescriptorVec.size();i++)
{ {
if(!pi.FaceAttrNameVec.empty() && !pi.FaceAttrNameVec[i].empty()) if(!pi.FaceAttrNameVec.empty() && !pi.FaceAttrNameVec[i].empty())
{ // trying to use named attribute to retrieve the value to store { // trying to use named attribute to retrieve the value to store
assert(vcg::tri::HasPerFaceAttribute(m,pi.FaceAttrNameVec[i])); assert(vcg::tri::HasPerFaceAttribute(m,pi.FaceAttrNameVec[i]));
if (!pi.FaceDescriptorVec[i].islist) {
switch (pi.FaceDescriptorVec[i].stotype1) switch (pi.FaceDescriptorVec[i].stotype1)
{ {
case ply::T_FLOAT : thff[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerFaceAttribute<float>(m,pi.FaceAttrNameVec[i]); break; case ply::T_FLOAT : thff[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerFaceAttribute<float>(m,pi.FaceAttrNameVec[i]); break;
@ -423,6 +442,15 @@ public:
default : assert(0); default : assert(0);
} }
} }
else {
switch (pi.FaceDescriptorVec[i].stotype1)
{
case ply::T_FLOAT : thp3ff[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerFaceAttribute<vcg::Point3f>(m,pi.FaceAttrNameVec[i]); break;
case ply::T_DOUBLE : thp3df[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerFaceAttribute<vcg::Point3d>(m,pi.FaceAttrNameVec[i]); break;
default : assert(0);
}
}
}
} }
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi){ for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi){
@ -692,6 +720,7 @@ public:
if(!pi.FaceAttrNameVec.empty() && !pi.FaceAttrNameVec[i].empty()) if(!pi.FaceAttrNameVec.empty() && !pi.FaceAttrNameVec[i].empty())
{ // trying to use named attribute to retrieve the value to store { // trying to use named attribute to retrieve the value to store
assert(vcg::tri::HasPerFaceAttribute(m,pi.FaceAttrNameVec[i])); assert(vcg::tri::HasPerFaceAttribute(m,pi.FaceAttrNameVec[i]));
if (!pi.FaceDescriptorVec[i].islist){
switch (pi.FaceDescriptorVec[i].stotype1) switch (pi.FaceDescriptorVec[i].stotype1)
{ {
case ply::T_FLOAT : tf=thff[i][fp]; fwrite(&tf, sizeof(float),1,fpout); break; case ply::T_FLOAT : tf=thff[i][fp]; fwrite(&tf, sizeof(float),1,fpout); break;
@ -703,6 +732,25 @@ public:
default : assert(0); default : assert(0);
} }
} }
else {
static const unsigned char psize = 3;
switch (pi.FaceDescriptorVec[i].stotype1)
{
case ply::T_FLOAT :
fwrite(&psize, sizeof(unsigned char), 1,fpout);
fwrite(&thp3ff[i][fp][0], sizeof(float), 1,fpout);
fwrite(&thp3ff[i][fp][1], sizeof(float), 1,fpout);
fwrite(&thp3ff[i][fp][2], sizeof(float), 1,fpout);
break;
case ply::T_DOUBLE :
fwrite(&psize, sizeof(unsigned char), 1,fpout);
fwrite(&thp3df[i][fp][0], sizeof(double), 1,fpout);
fwrite(&thp3df[i][fp][1], sizeof(double), 1,fpout);
fwrite(&thp3df[i][fp][2], sizeof(double), 1,fpout);
default : assert(0);
}
}
}
else else
{ {
switch (pi.FaceDescriptorVec[i].stotype1){ switch (pi.FaceDescriptorVec[i].stotype1){
@ -777,6 +825,7 @@ public:
if(!pi.FaceAttrNameVec.empty() && !pi.FaceAttrNameVec[i].empty()) if(!pi.FaceAttrNameVec.empty() && !pi.FaceAttrNameVec[i].empty())
{ // trying to use named attribute to retrieve the value to store { // trying to use named attribute to retrieve the value to store
assert(vcg::tri::HasPerFaceAttribute(m,pi.FaceAttrNameVec[i])); assert(vcg::tri::HasPerFaceAttribute(m,pi.FaceAttrNameVec[i]));
if(!pi.FaceDescriptorVec[i].islist) {
switch (pi.FaceDescriptorVec[i].stotype1) switch (pi.FaceDescriptorVec[i].stotype1)
{ {
case ply::T_FLOAT : tf=thff[i][fp]; fprintf(fpout,"%f ",tf); break; case ply::T_FLOAT : tf=thff[i][fp]; fprintf(fpout,"%f ",tf); break;
@ -788,6 +837,15 @@ public:
default : assert(0); default : assert(0);
} }
} }
else {
switch (pi.FaceDescriptorVec[i].stotype1)
{
case ply::T_FLOAT : fprintf(fpout,"%d %f %f %f", 3, thp3ff[i][fp][0], thp3ff[i][fp][1], thp3ff[i][fp][2]); break;
case ply::T_DOUBLE : fprintf(fpout,"%d %lf %lf %lf", 3, thp3df[i][fp][0], thp3df[i][fp][1], thp3df[i][fp][2]); break;
default : assert(0);
}
}
}
else else
{ {
switch (pi.FaceDescriptorVec[i].memtype1) switch (pi.FaceDescriptorVec[i].memtype1)

View File

@ -160,6 +160,21 @@ public:
addPerElemPointAttribute(0,vcg::ply::PlyTypes::T_DOUBLE, attrName,propName); addPerElemPointAttribute(0,vcg::ply::PlyTypes::T_DOUBLE, attrName,propName);
} }
void addPerFacePoint3mAttribute(const std::string& attrName, vcg::ply::PlyTypes attrType, std::string propName="")
{
addPerElemPointAttribute(1,attrType, attrName,propName);
}
void addPerFacePoint3fAttribute(const std::string& attrName, std::string propName="")
{
addPerElemPointAttribute(1,vcg::ply::PlyTypes::T_FLOAT, attrName,propName);
}
void addPerFacePoint3dAttribute(const std::string& attrName, std::string propName="")
{
addPerElemPointAttribute(1,vcg::ply::PlyTypes::T_DOUBLE, 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>