refactoring

This commit is contained in:
iasonmanolas 2021-12-30 17:29:34 +02:00
parent 3770720fb8
commit 86495cdb6f
3 changed files with 90 additions and 86 deletions

View File

@ -974,9 +974,9 @@ public:
countE++; countE++;
else else
{ {
vertVisited[fi->V0(i)] = true; vertVisited[fi->V(i)] = true;
vertVisited[fi->V1(i)] = true; vertVisited[fi->V(i)] = true;
} }
} }
} }
// Third Loop, count the number of referenced vertexes that are completely surrounded by faux edges. // Third Loop, count the number of referenced vertexes that are completely surrounded by faux edges.

View File

@ -77,7 +77,7 @@ public:
Pos(FaceType * fp, int zp, VertexType * vp) Pos(FaceType * fp, int zp, VertexType * vp)
{ {
f=fp; z=zp; v=vp; f=fp; z=zp; v=vp;
assert((vp==fp->V0(zp))||(vp==fp->V1(zp))); assert((vp == fp->V(zp)) || (vp == fp->V(zp)));
} }
Pos(FaceType * fp, int zp){f=fp; z=zp; v=f->V(zp);} Pos(FaceType * fp, int zp){f=fp; z=zp; v=f->V(zp);}
Pos(FaceType * fp, VertexType * vp) Pos(FaceType * fp, VertexType * vp)

View File

@ -69,34 +69,42 @@ class ExporterPLY
} }
public: public:
typedef ::vcg::ply::PropDescriptor PropDescriptor ; typedef ::vcg::ply::PropDescriptor PropDescriptor;
typedef typename SaveMeshType::ConstVertexPointer VertexPointer; typedef typename SaveMeshType::ConstVertexPointer VertexPointer;
typedef typename SaveMeshType::ScalarType ScalarType; typedef typename SaveMeshType::ScalarType ScalarType;
typedef typename SaveMeshType::VertexType VertexType; typedef typename SaveMeshType::VertexType VertexType;
typedef typename SaveMeshType::FaceType FaceType; typedef typename SaveMeshType::FaceType FaceType;
typedef typename SaveMeshType::ConstFacePointer FacePointer; typedef typename SaveMeshType::FacePointer FacePointer;
typedef typename SaveMeshType::ConstVertexIterator VertexIterator; typedef typename SaveMeshType::ConstVertexIterator VertexIterator;
typedef typename SaveMeshType::ConstFaceIterator FaceIterator; typedef typename SaveMeshType::ConstFaceIterator FaceIterator;
typedef typename SaveMeshType::ConstEdgeIterator EdgeIterator; typedef typename SaveMeshType::ConstEdgeIterator EdgeIterator;
typedef typename vcg::Shot<ScalarType>::ScalarType ShotScalarType; typedef typename vcg::Shot<ScalarType>::ScalarType ShotScalarType;
static int Save(const SaveMeshType &m, const char * filename, bool binary=true) static int Save(const SaveMeshType &m, const char *filename, bool binary = true)
{ {
PlyInfo pi; PlyInfo pi;
return Save(m,filename,binary,pi); return Save(m, filename, binary, pi);
} }
static int Save(const SaveMeshType &m, const char * filename, int savemask, bool binary = true, CallBackPos *cb=0 ) static int Save(const SaveMeshType &m,
{ const char *filename,
PlyInfo pi; int savemask,
pi.mask=savemask; bool binary = true,
return Save(m,filename,binary,pi,cb); CallBackPos *cb = 0)
} {
PlyInfo pi;
pi.mask = savemask;
return Save(m, filename, binary, pi, cb);
}
static int Save(const SaveMeshType &m, const char * filename, bool binary, const PlyInfo &pi, CallBackPos *cb=0) // V1.0 static int Save(const SaveMeshType &m,
{ const char *filename,
FILE * fpout; bool binary,
const char * hbin = "binary_little_endian"; const PlyInfo &pi,
CallBackPos *cb = 0) // V1.0
{
FILE *fpout;
const char * hbin = "binary_little_endian";
const char * hasc = "ascii"; const char * hasc = "ascii";
const char * h; const char * h;
//Coord ScalarType //Coord ScalarType
@ -630,28 +638,26 @@ public:
} }
/*vcg::tri::*/ /*vcg::tri::*/
// this assert triggers when the vn != number of vertexes in vert that are not deleted. // this assert triggers when the vn != number of vertexes in vert that are not deleted.
assert(j==m.vn); assert(j == m.vn);
unsigned char b3char = 3; unsigned char b3char = 3;
unsigned char b9char = 9; unsigned char b9char = 9;
unsigned char b6char = 6; unsigned char b6char = 6;
FacePointer fp; int vv[3];
int vv[3]; FaceIterator fi;
FaceIterator fi; int fcnt = 0;
int fcnt=0; j = 0;
for(j=0,fi=m.face.begin();fi!=m.face.end();++fi) for (fi = m.face.begin(); fi != m.face.end(); ++fi) {
{ //((m.vn+m.fn) != 0) all vertices and faces have been marked as deleted but the are still in the vert/face vectors
//((m.vn+m.fn) != 0) all vertices and faces have been marked as deleted but the are still in the vert/face vectors if (cb && ((j % 1000) == 0) && ((m.vn + m.fn) != 0))
if(cb && ((j%1000)==0) && ((m.vn+m.fn) != 0)) (*cb)(100 * (m.vn + j) / (m.vn + m.fn), "Saving Vertices");
(*cb)( 100*(m.vn+j)/(m.vn+m.fn), "Saving Vertices");
fp=&(*fi); auto fp = &(*fi);
if( ! fp->IsD() ) if (!fp->IsD()) {
{ fcnt++; fcnt++;
if(binary) if (binary) {
{ vv[0] = indices[fp->cV(0)];
vv[0]=indices[fp->cV(0)]; vv[1]=indices[fp->cV(1)];
vv[1]=indices[fp->cV(1)];
vv[2]=indices[fp->cV(2)]; vv[2]=indices[fp->cV(2)];
fwrite(&b3char,sizeof(char),1,fpout); fwrite(&b3char,sizeof(char),1,fpout);
fwrite(vv,sizeof(int),3,fpout); fwrite(vv,sizeof(int),3,fpout);
@ -768,12 +774,11 @@ public:
default : assert(0); default : assert(0);
} }
} }
} }
} } else // ***** ASCII *****
else // ***** ASCII ***** {
{ fprintf(fpout, "%d ", fp->VN());
fprintf(fpout,"%d " ,fp->VN()); for(int k=0;k<fp->VN();++k)
for(int k=0;k<fp->VN();++k)
fprintf(fpout,"%d ",indices[fp->cV(k)]); fprintf(fpout,"%d ",indices[fp->cV(k)]);
if(HasPerFaceFlags(m)&&( pi.mask & Mask::IOM_FACEFLAGS )) if(HasPerFaceFlags(m)&&( pi.mask & Mask::IOM_FACEFLAGS ))
@ -861,45 +866,44 @@ public:
case ply::T_SHORT : ti=*( (short *) (((char *)fp)+pi.FaceDescriptorVec[i].offset1)); fprintf(fpout,"%i ",ti); break; case ply::T_SHORT : ti=*( (short *) (((char *)fp)+pi.FaceDescriptorVec[i].offset1)); fprintf(fpout,"%i ",ti); break;
case ply::T_CHAR : ti=*( (char *) (((char *)fp)+pi.FaceDescriptorVec[i].offset1)); fprintf(fpout,"%i ",ti); break; case ply::T_CHAR : ti=*( (char *) (((char *)fp)+pi.FaceDescriptorVec[i].offset1)); fprintf(fpout,"%i ",ti); break;
case ply::T_UCHAR : ti=*( (unsigned char *) (((char *)fp)+pi.FaceDescriptorVec[i].offset1)); fprintf(fpout,"%i ",ti); break; case ply::T_UCHAR : ti=*( (unsigned char *) (((char *)fp)+pi.FaceDescriptorVec[i].offset1)); fprintf(fpout,"%i ",ti); break;
default : assert(0); default:
} assert(0);
} }
} }
}
fprintf(fpout,"\n"); fprintf(fpout, "\n");
} }
} }
} }
assert(fcnt==m.fn); assert(fcnt == m.fn);
int eauxvv[2]; int eauxvv[2];
if( pi.mask & Mask::IOM_EDGEINDEX ) if (pi.mask & Mask::IOM_EDGEINDEX) {
{ int ecnt = 0;
int ecnt=0; for (EdgeIterator ei = m.edge.begin(); ei != m.edge.end(); ++ei) {
for(EdgeIterator ei=m.edge.begin();ei!=m.edge.end();++ei) if (!ei->IsD()) {
{ ++ecnt;
if( ! ei->IsD() ) if(binary)
{
++ecnt;
if(binary)
{ {
eauxvv[0]=indices[ei->cV(0)]; eauxvv[0]=indices[ei->cV(0)];
eauxvv[1]=indices[ei->cV(1)]; eauxvv[1]=indices[ei->cV(1)];
fwrite(eauxvv,sizeof(int),2,fpout); fwrite(eauxvv,sizeof(int),2,fpout);
} }
else // ***** ASCII ***** else // ***** ASCII *****
fprintf(fpout,"%d %d \n", indices[ei->cV(0)], indices[ei->cV(1)]); fprintf(fpout, "%d %d \n", indices[ei->cV(0)], indices[ei->cV(1)]);
} }
} }
assert(ecnt==m.en); assert(ecnt == m.en);
} }
int result = 0; int result = 0;
if (ferror(fpout)) result = ply::E_STREAMERROR; if (ferror(fpout))
fclose(fpout); result = ply::E_STREAMERROR;
return result; fclose(fpout);
} return result;
}
static const char *ErrorMsg(int error) static const char *ErrorMsg(int error)
{ {
static std::vector<std::string> ply_error_msg; static std::vector<std::string> ply_error_msg;
if(ply_error_msg.empty()) if(ply_error_msg.empty())
{ {