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,8 +974,8 @@ 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;
} }
} }
} }

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,33 +69,41 @@ 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,
int savemask,
bool binary = true,
CallBackPos *cb = 0)
{ {
PlyInfo pi; PlyInfo pi;
pi.mask=savemask; pi.mask = savemask;
return Save(m,filename,binary,pi,cb); 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,
bool binary,
const PlyInfo &pi,
CallBackPos *cb = 0) // V1.0
{ {
FILE * fpout; FILE *fpout;
const char * hbin = "binary_little_endian"; const char * hbin = "binary_little_endian";
const char * hasc = "ascii"; const char * hasc = "ascii";
const char * h; const char * h;
@ -630,27 +638,25 @@ 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;
for(j=0,fi=m.face.begin();fi!=m.face.end();++fi) j = 0;
{ 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);
@ -769,10 +775,9 @@ public:
} }
} }
} }
} } 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)]);
@ -861,24 +866,22 @@ 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()) {
{
if( ! ei->IsD() )
{
++ecnt; ++ecnt;
if(binary) if(binary)
{ {
@ -887,13 +890,14 @@ public:
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))
result = ply::E_STREAMERROR;
fclose(fpout); fclose(fpout);
return result; return result;
} }