diff --git a/wrap/gl/tetramesh.h b/wrap/gl/tetramesh.h index e0cc5331..45e7b28f 100644 --- a/wrap/gl/tetramesh.h +++ b/wrap/gl/tetramesh.h @@ -19,443 +19,455 @@ * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * -****************************************************************************/ - -#ifndef __GLWRAPTETRA__ -#define __GLWRAPTETRA__ -#include -#include -#include -#include -#include -#include -#include - -namespace vcg { - -namespace tetra { - -class GLW { -public: - enum DrawMode {DMNone, DMSmallTetra,DMFlat,DMWire, DMHidden,DMTransparent,DMFlatWire} ; - enum NormalMode{NMFlat,NMSmooth, NMUser, NMPerMesh}; - enum ColorMode {CMNone, CMPerMesh,CMUser,CMPerTetraF,CMPerVertexF,CMPerVertex}; - enum Hint {HShrinkFactor}; -}; - -template -class GlTetramesh:public GLW{ - - -public: - - typedef typename CONT_TETRA::value_type TetraType; - typedef typename TetraType::VertexType VertexType; - typedef typename VertexType::ScalarType ScalarType; - typedef typename VertexType::CoordType Point3x; - - //subclass for clipping planes - class ClipPlane - { - private: - Point3x D; - Point3x D0; - GLdouble eqn[4]; - vcg::Matrix44 TR; - - Point3x pp0; - Point3x pp1; - Point3x pp2; - Point3x pp3; - - public: - - bool active; - - Point3x P; - - ClipPlane (){active=false;} - - ~ClipPlane (){} - - ClipPlane(Point3x p0, Point3x p1,Point3x p2) - { - Point3x N=((p1-p0)^(p2-p0)).Normalize(); - N.Normalize(); - D=N; - D0=D; - P=(p0+p1+p2)/3.f; - - Point3x v0=N; - Point3x v1=(P-p0); - v1.Normalize(); - Point3x v2=(v0^v1); - v2.Normalize(); - - v0=v0*2; - v1=v1*2; - v2=v2*2; - - pp0=-v1-v2; - pp1=-v1+v2; - pp2=v1+v2; - pp3=v1-v2; - - } - //set normal of the clipping plane - void SetD(Point3x d) - { - D=d; - } - //set the point of the clipping plane - void SetP(Point3x p) - { - P=p; - } - - void GlClip() - { - if (active){ - GLdouble d=-(D.V(0)*P.V(0)+D.V(1)*P.V(1)+D.V(2)*P.V(2)); - eqn[0]=-D.V(0); - eqn[1]=-D.V(1); - eqn[2]=-D.V(2); - eqn[3]=-d; - glClipPlane(GL_CLIP_PLANE0, eqn); - glEnable(GL_CLIP_PLANE0); - } - } - - void GlDraw() - { - glPushMatrix(); - glPushAttrib(0xffffffff); - glDisable(GL_CLIP_PLANE0); - - glEnable(GL_LIGHTING); - glEnable(GL_NORMALIZE); - - glTranslate(P); - glMultMatrix(TR); - glLineWidth(0.5); - glColor3d(0.7,0,0.7); - glBegin(GL_LINE_LOOP); - glVertex(pp0); - glVertex(pp1); - glVertex(pp2); - glVertex(pp3); - glEnd(); - - glPopAttrib(); - glPopMatrix(); - - } - - void Transform(vcg::Matrix44 Tr) - { - //thath's for casting in case of trackball using - //float to double and vice-versa - Point3f p=Point3f((float)D0.V(0),(float)D0.V(1),(float)D0.V(2)); - TR=Tr; - p=TR*p; - D=Point3x((ScalarType) p.V(0),(ScalarType) p.V(1),(ScalarType) p.V(2)); - } - - void Translate(float L) - { - Point3x D1=D*L; - P+=D1; - } - - - }; - - GlTetramesh(CONT_TETRA * _t):tetra(_t){} - GlTetramesh( ) {} - - CONT_TETRA * tetra; - ClipPlane section; - - private: - ScalarType shrink_factor; - - - public: - - void SetHint(Hint h, double value){ - switch(h){ - case HShrinkFactor: shrink_factor = value; break; - } - } - - void AddClipSection(Point3x p0,Point3x p1,Point3x p2) - { - section=ClipPlane(p0,p1,p2); - section.active=true; - } - - void ClearClipSection() - { - section.active=false; - } - - typedef Color4b (*color_func_vertex)(VertexType&v); - color_func_vertex color_vertex; - - typedef Color4b (*color_func_tetra)(TetraType&v); - color_func_tetra color_tetra; - - - template - - void Draw(){ - switch (dm){ - case DMNone: break; - case DMSmallTetra:_DrawSmallTetra();break; - case DMFlat:_DrawSurface();break; - case DMWire:_DrawSurface();break; - case DMHidden:_DrawSurface();break; - case DMFlatWire:_DrawFlatWire(); break; - case DMTransparent:break; - } - } - -private: -template - void _DrawSmallTetra(){ - Point3x p[4],br; - typename CONT_TETRA::iterator it; - glPushAttrib(0xffffffff); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_LIGHT0); - glEnable(GL_LIGHTING); - glEnable(GL_NORMALIZE); - glPolygonMode(GL_FRONT,GL_FILL); - if (section.active) - { - section.GlClip(); - section.GlDraw(); - } - /*glBegin(GL_TRIANGLES);*/ - for( it = tetra->begin(); it != tetra->end(); ++it) - if((!it->IsD())&&(!(it->IsS()))) //draw as normal - { - _DrawSmallTetra(*it); - } - else - if((!it->IsD())&&((it->IsS())))//draw in selection mode - { - _DrawSelectedTetra(*it); - } - //glEnd(); - glPopAttrib(); - } - -template -void _DrawFlatWire(){ - glPushAttrib(0xffff); - glEnable(GL_COLOR_MATERIAL); - glEnable(GL_DEPTH); - glDepthRange(0.001,1.0); - Draw(); - glDisable(GL_LIGHTING); - glColor3f(0.0,0.0,0.0); - glDepthRange(0.0,0.999); - Draw(); - glPopAttrib(); -} - - -template -void _DrawSurface(){ - typename CONT_TETRA::iterator it; - - glPushAttrib(0xffff); - glEnable(GL_COLOR_MATERIAL); - if((dm == DMWire)||(dm ==DMHidden)) - { - glDisable(GL_LIGHTING); - glDisable(GL_NORMALIZE); - glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - } - else - { - glEnable(GL_LIGHTING); - glEnable(GL_NORMALIZE); - glPolygonMode(GL_FRONT,GL_FILL); - } - //glBegin(GL_TRIANGLES); - for( it = tetra->begin(); it != tetra->end(); ++it) - _DrawTetra((*it)); - //glEnd(); - glPopAttrib(); -} - - -void _DrawSelectedTetra(TetraType &t) -{ - glPushMatrix(); - glPushAttrib(0xffff); - glDisable(GL_CLIP_PLANE0); - glDisable(GL_BLEND); - glDisable(GL_LIGHTING); - glDisable(GL_NORMALIZE); - glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - - glColor3d(1,0,0); - - glBegin(GL_TRIANGLES); - for (int face=0;face<4;face++) - { - glVertex(t.V(Tetra::VofF(face,0))->P()); - glVertex(t.V(Tetra::VofF(face,1))->P()); - glVertex(t.V(Tetra::VofF(face,2))->P()); - } - glEnd(); - - //end drawing - glPopAttrib(); - glPopMatrix(); -} - -template -void _DrawTetra(TetraType &t) -{ - if((!t.IsD())&&(!t.IsS())) - { - if ((dm!=DMWire)&&(dm!=DMHidden)) - _ChooseColorTetra(t); - for(int i = 0; i < 4; ++i){ - if (dm == DMWire) - _DrawFace(t,i); - else - { - if (t.IsBorderF(i)) - { - if(nm==NMSmooth) - _DrawFaceSmooth(t,i); - else - if(nm==NMFlat) - _DrawFace(t,i); - } - } - } - } - else - if((!t.IsD())&&(t.IsS())) - _DrawSelectedTetra(t); -} - -template -void _ChooseColorTetra(TetraType &t) -{ - if (cm==CMNone) - { - if (t.IsS()) - glColor3d(1,0,0); - else - glColor3d(0.8f,0.8f,0.8f); - } - else - if(cm == CMPerTetraF) - { - Color4b c; - c = color_tetra(t); - GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3]; - glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic); - } -} - -template -void _ChooseColorVertex(VertexType &v) -{ - if (cm!=CMNone) - { - if(cm == CMPerVertexF) - { - Color4b c; - c = color_vertex(v); - GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3]; - glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic); - } - else - if(cm == CMPerVertex) - glColor3f(v.C()[0],v.C()[1],v.C()[2]); - } -} - -template -void _DrawFaceSmooth(TetraType &t,int face) -{ - - VertexType *v0=t.V(Tetra::VofF(face,0)); - VertexType *v1=t.V(Tetra::VofF(face,1)); - VertexType *v2=t.V(Tetra::VofF(face,2)); - - glBegin(GL_TRIANGLES); - _ChooseColorVertex(*v0); - glNormal(v0->N()); - glVertex(v0->P()); - _ChooseColorVertex(*v1); - glNormal(v1->N()); - glVertex(v1->P()); - _ChooseColorVertex(*v2); - glNormal(v2->N()); - glVertex(v2->P()); - glEnd(); -} - -template -void _DrawFace(TetraType &t,int face) -{ -glBegin(GL_TRIANGLES); - glNormal(t.N(face)); - VertexType *v0=t.V(Tetra::VofF(face,0)); - VertexType *v1=t.V(Tetra::VofF(face,1)); - VertexType *v2=t.V(Tetra::VofF(face,2)); - _ChooseColorVertex(*v0); - glVertex(v0->P()); - _ChooseColorVertex(*v1); - glVertex(v1->P()); - _ChooseColorVertex(*v2); - glVertex(v2->P()); - glEnd(); -} - -template -void _DrawSmallTetra(TetraType &t) -{ - Tetra3 T=Tetra3(); - T.P0(0)=t.V(0)->cP(); - T.P1(0)=t.V(1)->cP(); - T.P2(0)=t.V(2)->cP(); - T.P3(0)=t.V(3)->cP(); - Point3x p[4], br; - br=T.ComputeBarycenter(); - for(int i = 0; i < 4; ++i) - p[i] = t.V(i)->P()* shrink_factor + br *(1- shrink_factor); - _ChooseColorTetra(t); - - glBegin(GL_TRIANGLES); - for(int i = 0; i < 4; ++i) - { - glNormal(t.N(i)); - VertexType *v0=t.V(Tetra::VofF(i,0)); - VertexType *v1=t.V(Tetra::VofF(i,1)); - VertexType *v2=t.V(Tetra::VofF(i,2)); - _ChooseColorVertex(*v0); - glVertex(p[Tetra::VofF(i,0)]); - _ChooseColorVertex(*v1); - glVertex(p[Tetra::VofF(i,1)]); - _ChooseColorVertex(*v2); - glVertex(p[Tetra::VofF(i,2)]); - } - glEnd(); -} - - -}; - -} // end namespace tetra -} // end nemaspace tri -#endif +****************************************************************************/ + +#ifndef __GLWRAPTETRA__ +#define __GLWRAPTETRA__ +#include +#include +#include +#include +#include +#include +#include + +namespace vcg { + +namespace tetra { + +class GLW { +public: + enum DrawMode {DMNone, DMSmallTetra,DMFlat,DMWire, DMHidden,DMTransparent,DMFlatWire} ; + enum NormalMode{NMFlat,NMSmooth, NMUser, NMPerMesh}; + enum ColorMode {CMNone, CMPerMesh,CMUser,CMPerTetra,CMPerVertexF,CMPerVertex}; + enum Hint {HShrinkFactor}; +}; + +template +class GlTetramesh:public GLW{ + + +public: + + typedef typename CONT_TETRA::value_type TetraType; + typedef typename TetraType::VertexType VertexType; + typedef typename VertexType::ScalarType ScalarType; + typedef typename VertexType::CoordType Point3x; + + //subclass for clipping planes + class ClipPlane + { + private: + Point3x D; + Point3x D0; + GLdouble eqn[4]; + vcg::Matrix44 TR; + + Point3x pp0; + Point3x pp1; + Point3x pp2; + Point3x pp3; + + public: + + bool active; + + Point3x P; + + ClipPlane (){active=false;} + + ~ClipPlane (){} + + ClipPlane(Point3x p0, Point3x p1,Point3x p2) + { + Point3x N=((p1-p0)^(p2-p0)).Normalize(); + N.Normalize(); + D=N; + D0=D; + P=(p0+p1+p2)/3.f; + + Point3x v0=N; + Point3x v1=(P-p0); + v1.Normalize(); + Point3x v2=(v0^v1); + v2.Normalize(); + + v0=v0*2; + v1=v1*2; + v2=v2*2; + + pp0=-v1-v2; + pp1=-v1+v2; + pp2=v1+v2; + pp3=v1-v2; + + } + //set normal of the clipping plane + void SetD(Point3x d) + { + D=d; + } + //set the point of the clipping plane + void SetP(Point3x p) + { + P=p; + } + bool IsClipped(Point3x p) + { + return D.V(0) * p.X() + D.V(1) * p.Y() + D.V(2) * p.Z() - vcg::Norm(P) < 0; + } + + void GlClip() + { + if (active){ + GLdouble d=-(D.V(0)*P.V(0)+D.V(1)*P.V(1)+D.V(2)*P.V(2)); + eqn[0]=-D.V(0); + eqn[1]=-D.V(1); + eqn[2]=-D.V(2); + eqn[3]=-d; + glClipPlane(GL_CLIP_PLANE0, eqn); + glEnable(GL_CLIP_PLANE0); + } + } + + void GlDraw() + { + glPushMatrix(); + glPushAttrib(0xffffffff); + glDisable(GL_CLIP_PLANE0); + + glEnable(GL_LIGHTING); + glEnable(GL_NORMALIZE); + + glTranslate(P); + glMultMatrix(TR); + glLineWidth(0.5); + glColor3d(0.7,0,0.7); + glBegin(GL_LINE_LOOP); + glVertex(pp0); + glVertex(pp1); + glVertex(pp2); + glVertex(pp3); + glEnd(); + + glPopAttrib(); + glPopMatrix(); + } + + void Transform(vcg::Matrix44 Tr) + { + //thath's for casting in case of trackball using + //float to double and vice-versa + Point3f p=Point3f((float)D0.V(0),(float)D0.V(1),(float)D0.V(2)); + TR=Tr; + p=TR*p; + D=Point3x((ScalarType) p.V(0),(ScalarType) p.V(1),(ScalarType) p.V(2)); + } + + void Translate(float L) + { + Point3x D1=D*L; + P+=D1; + } + + + }; + + GlTetramesh(CONT_TETRA * _t):tetra(_t){} + GlTetramesh( ) {} + + CONT_TETRA * tetra; + ClipPlane section; + +private: + ScalarType shrink_factor = 0.95f; + + +public: + + void SetHint(Hint h, double value){ + switch(h){ + case HShrinkFactor: shrink_factor = value; break; + } + } + + void AddClipSection(Point3x p0,Point3x p1,Point3x p2) + { + section=ClipPlane(p0,p1,p2); + section.active=true; + } + + void ClearClipSection() + { + section.active=false; + } + + template + void Draw(){ + switch (dm){ + case DMNone: break; + case DMSmallTetra:_DrawSmallTetra();break; + case DMFlat:_DrawSurface();break; + case DMWire:_DrawSurface();break; + case DMHidden:_DrawSurface();break; + case DMFlatWire:_DrawFlatWire(); break; + case DMTransparent:break; + } + } + +private: + template + void _DrawSmallTetra(){ + typename CONT_TETRA::iterator it; + +// glPushAttrib(0xffff); +// glEnable(GL_COLOR_MATERIAL); +// glEnable(GL_NORMALIZE); +// glPolygonMode(GL_FRONT, GL_FILL); +// glLight(GL_LIGHT0, GL_DIFFUSE, vcg::Color4b::White); +// glEnable(GL_LIGHT0); +// glEnable(GL_LIGHTING); + /*glBegin(GL_TRIANGLES);*/ + for( it = tetra->begin(); it != tetra->end(); ++it) + if((!it->IsD())&&(!(it->IsS()))) //draw as normal + { + _DrawSmallTetra(*it); + } + else + if((!it->IsD())&&((it->IsS())))//draw in selection mode + { + _DrawSelectedTetra(*it); + } + //glEnd(); +// glPopAttrib(); + if (section.active) + { +// section.GlClip(); + section.GlDraw(); + } + } + + template + void _DrawFlatWire(){ + glPushAttrib(0xffff); + glEnable(GL_COLOR_MATERIAL); + glEnable(GL_DEPTH); + glDepthRange(0.001,1.0); + Draw(); + glDisable(GL_LIGHTING); + glColor3f(0.0,0.0,0.0); + glDepthRange(0.0,0.999); + Draw(); + glPopAttrib(); + } + + + template + void _DrawSurface(){ + typename CONT_TETRA::iterator it; + + glPushAttrib(0xffff); + glEnable(GL_COLOR_MATERIAL); + if((dm == DMWire)||(dm ==DMHidden)) + { + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + } + else + { + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + glEnable(GL_NORMALIZE); + glPolygonMode(GL_FRONT,GL_FILL); + } + //glBegin(GL_TRIANGLES); + for( it = tetra->begin(); it != tetra->end(); ++it) + _DrawTetra((*it)); + //glEnd(); + glPopAttrib(); + } + + + void _DrawSelectedTetra(TetraType &t) + { + glPushMatrix(); + glPushAttrib(0xffff); + glDisable(GL_CLIP_PLANE0); + glDisable(GL_BLEND); + glDisable(GL_LIGHTING); + glDisable(GL_NORMALIZE); + glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); + + glColor3d(1,0,0); + + glBegin(GL_TRIANGLES); + for (int face=0;face<4;face++) + { + glVertex(t.V(Tetra::VofF(face,0))->P()); + glVertex(t.V(Tetra::VofF(face,1))->P()); + glVertex(t.V(Tetra::VofF(face,2))->P()); + } + glEnd(); + + //end drawing + glPopAttrib(); + glPopMatrix(); + } + + template + void _DrawTetra(TetraType &t) + { + if((!t.IsD())&&(!t.IsS())) + { + if ((dm!=DMWire)&&(dm!=DMHidden)) + _ChooseColorTetra(t); + for(int i = 0; i < 4; ++i){ + if (dm == DMWire) + _DrawFace(t,i); + else + { + if (t.IsBorderF(i)) + { + if(nm==NMSmooth) + _DrawFaceSmooth(t,i); + else + if(nm==NMFlat) + _DrawFace(t,i); + } + } + } + } + else + if((!t.IsD())&&(t.IsS())) + _DrawSelectedTetra(t); + } + + template + void _ChooseColorTetra(TetraType &t) + { + if (cm==CMNone) + { + if (t.IsS()) + glColor3d(1,0,0); + else + glColor3d(0.8f,0.8f,0.8f); + } + if (cm == CMPerTetra) + vcg::glColor(t.C()); +// else +// if(cm == CMPerTetraF) +// { +// Color4b c; +// c = color_tetra(t); +// GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3]; +// glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic); +// } + } + + template + void _ChooseColorVertex(VertexType &v) + { + if (cm!=CMNone) + { +// if(cm == CMPerVertexF) +// { +// Color4b c; +// c = color_vertex(v); +// GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3]; +// glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic); +// } +// else + if(cm == CMPerVertex) + vcg::glColor(v.C()); + } + } + + template + void _DrawFaceSmooth(TetraType &t,int face) + { + + VertexType *v0=t.V(Tetra::VofF(face,0)); + VertexType *v1=t.V(Tetra::VofF(face,1)); + VertexType *v2=t.V(Tetra::VofF(face,2)); + + glBegin(GL_TRIANGLES); + _ChooseColorVertex(*v0); + glNormal(v0->N()); + glVertex(v0->P()); + _ChooseColorVertex(*v1); + glNormal(v1->N()); + glVertex(v1->P()); + _ChooseColorVertex(*v2); + glNormal(v2->N()); + glVertex(v2->P()); + glEnd(); + } + + template < ColorMode cm > + void _DrawFace(TetraType &t,int face) + { + glBegin(GL_TRIANGLES); + VertexType *v0=t.V(Tetra::VofF(face,0)); + VertexType *v1=t.V(Tetra::VofF(face,1)); + VertexType *v2=t.V(Tetra::VofF(face,2)); + glNormal(vcg::Normal(v0->P(), v1->P(), v2->P()).normalized()); + _ChooseColorVertex(*v0); + glVertex(v0->P()); + _ChooseColorVertex(*v1); + glVertex(v1->P()); + _ChooseColorVertex(*v2); + glVertex(v2->P()); + glEnd(); + } + + template < ColorMode cm > + void _DrawSmallTetra(TetraType &t) + { + Point3x p[4], br; + br = Tetra::Barycenter(t); + if (section.IsClipped(br)) + return; + bool border = false; + bool clipBorder = false; + for (int i = 0; i < 4; ++i) + { + border = border || t.IsB(i); + + Point3x br1 = Tetra::Barycenter(*t.TTp(i)); + clipBorder = clipBorder || section.IsClipped(br1); + } + + if (!border && !clipBorder) + return; + + for(int i = 0; i < 4; ++i) + p[i] = t.V(i)->P() * shrink_factor + br * (1 - shrink_factor); + + + _ChooseColorTetra(t); + + glBegin(GL_TRIANGLES); + for(int i = 0; i < 4; ++i) + { + VertexType *v0=t.V(Tetra::VofF(i,0)); + VertexType *v1=t.V(Tetra::VofF(i,1)); + VertexType *v2=t.V(Tetra::VofF(i,2)); + + + glNormal(vcg::Normal(v0->P(), v1->P(), v2->P()).normalized()); + + _ChooseColorVertex(*v0); + glVertex(p[Tetra::VofF(i,0)]); + _ChooseColorVertex(*v1); + glVertex(p[Tetra::VofF(i,1)]); + _ChooseColorVertex(*v2); + glVertex(p[Tetra::VofF(i,2)]); + } + glEnd(); + } +}; + +} // end namespace tetra +} // end nemaspace tri +#endif diff --git a/wrap/io_tetramesh/export_ply.h b/wrap/io_tetramesh/export_ply.h index f897744d..c4f13a09 100644 --- a/wrap/io_tetramesh/export_ply.h +++ b/wrap/io_tetramesh/export_ply.h @@ -354,7 +354,7 @@ public: fprintf(fpout,"%d ",vp->Flags()); if( HasPerVertexColor(m) && (pi.mask & Mask::IOM_VERTCOLOR) ) - fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); + fprintf(fpout,"%d %d %d %d ",vp->C()[0], vp->C()[1], vp->C()[2], vp->C()[3] ); if( HasPerVertexQuality(m) && (pi.mask & Mask::IOM_VERTQUALITY) ) fprintf(fpout,"%g ",vp->Q()); diff --git a/wrap/io_tetramesh/import_ply.h b/wrap/io_tetramesh/import_ply.h index 3bec6821..325a23e1 100644 --- a/wrap/io_tetramesh/import_ply.h +++ b/wrap/io_tetramesh/import_ply.h @@ -58,693 +58,540 @@ class ImporterPLY { public: -typedef ::vcg::ply::PropDescriptor PropDescriptor ; -typedef typename OpenMeshType::VertexPointer VertexPointer; -typedef typename OpenMeshType::ScalarType ScalarType; -typedef typename OpenMeshType::VertexType VertexType; -typedef typename OpenMeshType::TetraType TetraType; -typedef typename OpenMeshType::VertexIterator VertexIterator; -typedef typename OpenMeshType::TetraIterator TetraIterator; + typedef ::vcg::ply::PropDescriptor PropDescriptor ; + typedef typename OpenMeshType::VertexPointer VertexPointer; + typedef typename OpenMeshType::ScalarType ScalarType; + typedef typename OpenMeshType::VertexType VertexType; + typedef typename OpenMeshType::TetraType TetraType; + typedef typename OpenMeshType::VertexIterator VertexIterator; + typedef typename OpenMeshType::TetraIterator TetraIterator; -//template int PlyType () { assert(0); return 0;} + //template int PlyType () { assert(0); return 0;} #define MAX_USER_DATA 256 -// Struttura ausiliaria per la lettura del file ply -struct LoadPly_TetraAux -{ - unsigned char size; - int v[512]; - int flags; - float q; - float texcoord[32]; - unsigned char ntexcoord; - int texcoordind; - float colors[32]; - unsigned char ncolors; - - unsigned char r; - unsigned char g; - unsigned char b; - - unsigned char data[MAX_USER_DATA]; -}; - -//struct LoadPly_TristripAux -//{ -// int size; -// int *v; -// unsigned char data[MAX_USER_DATA]; -//}; - -// Struttura ausiliaria per la lettura del file ply -template -struct LoadPly_VertAux -{ - S p[3]; - int flags; - float q; - unsigned char r; - unsigned char g; - unsigned char b; - unsigned char data[MAX_USER_DATA]; -}; - -// Struttura ausiliaria caricamento camera -//struct LoadPly_Camera -//{ -// float view_px; -// float view_py; -// float view_pz; -// float x_axisx; -// float x_axisy; -// float x_axisz; -// float y_axisx; -// float y_axisy; -// float y_axisz; -// float z_axisx; -// float z_axisy; -// float z_axisz; -// float focal; -// float scalex; -// float scaley; -// float centerx; -// float centery; -// int viewportx; -// int viewporty; -// float k1; -// float k2; -// float k3; -// float k4; -//}; - -static const PropDescriptor &VertDesc(int i) -{ - const static PropDescriptor pv[9]={ - {"vertex", "x", ply::T_FLOAT, PlyType(),offsetof(LoadPly_VertAux,p[0]),0,0,0,0,0}, - {"vertex", "y", ply::T_FLOAT, PlyType(),offsetof(LoadPly_VertAux,p[1]),0,0,0,0,0}, - {"vertex", "z", ply::T_FLOAT, PlyType(),offsetof(LoadPly_VertAux,p[2]),0,0,0,0,0}, - {"vertex", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_VertAux,flags),0,0,0,0,0}, - {"vertex", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,q),0,0,0,0,0}, - {"vertex", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,r),0,0,0,0,0}, - {"vertex", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,g),0,0,0,0,0}, - {"vertex", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,b),0,0,0,0,0}, - {"vertex", "confidence",ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,q),0,0,0,0,0}, - }; - return pv[i]; -} - - -static const PropDescriptor &TetraDesc(int i) -{ - const static PropDescriptor qf[10]= - { - {"tetra", "vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,v), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,size) }, - {"tetra", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,flags), 0,0,0,0,0}, - {"tetra", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,q), 0,0,0,0,0}, - {"tetra", "texcoord", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,texcoord), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,ntexcoord) }, - {"tetra", "color", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,colors), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,ncolors) }, - {"tetra", "texnumber", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,texcoordind), 0,0,0,0,0}, - {"tetra", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,r), 0,0,0,0,0}, - {"tetra", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,g), 0,0,0,0,0}, - {"tetra", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,b), 0,0,0,0,0}, - {"tetra", "vertex_index", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,v), 1,0,ply::T_UCHAR,ply::T_CHAR,offsetof(LoadPly_TetraAux,size) }, - }; - return qf[i]; -} -//static const PropDescriptor &TristripDesc(int i) -//{ -// const static PropDescriptor qf[1]= -// { -// {"tristrips","vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TristripAux,v), 1,1,ply::T_INT,ply::T_INT,offsetof(LoadPly_TristripAux,size) }, -// }; -// return qf[i]; -//} - - -//static const PropDescriptor &CameraDesc(int i) -//{ -// const static PropDescriptor cad[23] = -// { -// {"camera","view_px",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_px),0,0,0,0,0}, -// {"camera","view_py",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_py),0,0,0,0,0}, -// {"camera","view_pz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_pz),0,0,0,0,0}, -// {"camera","x_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisx),0,0,0,0,0}, -// {"camera","x_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisy),0,0,0,0,0}, -// {"camera","x_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisz),0,0,0,0,0}, -// {"camera","y_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisx),0,0,0,0,0}, -// {"camera","y_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisy),0,0,0,0,0}, -// {"camera","y_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisz),0,0,0,0,0}, -// {"camera","z_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisx),0,0,0,0,0}, -// {"camera","z_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisy),0,0,0,0,0}, -// {"camera","z_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisz),0,0,0,0,0}, -// {"camera","focal" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,focal ),0,0,0,0,0}, -// {"camera","scalex" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scalex ),0,0,0,0,0}, -// {"camera","scaley" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scaley ),0,0,0,0,0}, -// {"camera","centerx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centerx),0,0,0,0,0}, -// {"camera","centery",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centery),0,0,0,0,0}, -// {"camera","viewportx",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewportx),0,0,0,0,0}, -// {"camera","viewporty",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewporty),0,0,0,0,0}, -// {"camera","k1" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k1 ),0,0,0,0,0}, -// {"camera","k2" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k2 ),0,0,0,0,0}, -// {"camera","k3" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k3 ),0,0,0,0,0}, -// {"camera","k4" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k4 ),0,0,0,0,0} -// }; -// return cad[i]; -//} - - -/// Standard call for reading a mesh -static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0) -{ - PlyInfo pi; - pi.cb=cb; - return Open(m, filename, pi); -} - -/// Read a mesh and store in loadmask the loaded field -static int Open( OpenMeshType &m, const char * filename, int & loadmask, CallBackPos *cb =0) -{ - PlyInfo pi; - pi.mask=loadmask; - return Open(m, filename,pi); - loadmask=pi.mask; -} - - -/// read a mesh with all the possible option specified in the PlyInfo obj. -static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi ) -{ - assert(filename!=0); - vector index; - LoadPly_TetraAux fa; -// LoadPly_TristripAux tsa; - LoadPly_VertAux va; - - pi.mask = 0; - - va.flags = 42; - - pi.status = ::vcg::ply::E_NOERROR; - - // The main descriptor of the ply file - vcg::ply::PlyFile pf; - - // Open the file and parse the header - if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 ) - { - pi.status = pf.GetError(); - return -1; - } - pi.header = pf.GetHeader(); - - // Descrittori della camera - { // Check that all the camera properties are present. - /* bool found = true; - for(int i=0;i<23;++i) - { - if( pf.AddToRead(CameraDesc(i))==-1 ) { - found = false; - break; - } - } - if(found) pi.mask |= ply::PLYMask::PM_CAMERA;*/ - } - - // Descrittori dati standard (vertex coord e faces) - if( pf.AddToRead(VertDesc(0))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } - if( pf.AddToRead(VertDesc(1))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } - if( pf.AddToRead(VertDesc(2))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } - if( pf.AddToRead(TetraDesc(0))==-1 ){ pi.status = PlyInfo::E_NO_VERTEX; return -1; } - - -// Se fallisce si prova anche la sintassi di rapidform con index al posto di indices -// if( pf.AddToRead(TetraDesc(9))==-1 ) -// if(pf.AddToRead(TristripDesc(0))==-1) // Se fallisce tutto si prova a vedere se ci sono tristrip alla levoy. -// { pi.status = PlyInfo::E_NO_FACE; return -1; } - - // Descrittori facoltativi dei flags - if( pf.AddToRead(VertDesc(3))!=-1 ) - pi.mask |= ply::PLYMask::PM_VERTFLAGS; - - if( VertexType::HasQuality() ) - { - if( pf.AddToRead(VertDesc(4))!=-1 || - pf.AddToRead(VertDesc(8))!=-1 ) - pi.mask |= ply::PLYMask::PM_VERTQUALITY; - } - - if( VertexType::HasColor() ) - { - if( pf.AddToRead(VertDesc(5))!=-1 ) - { - pf.AddToRead(VertDesc(6)); - pf.AddToRead(VertDesc(7)); - pi.mask |= ply::PLYMask::PM_VERTCOLOR; - } - } - - // se ci sono i flag per vertice ci devono essere anche i flag per faccia - if( pf.AddToRead(TetraDesc(1))!=-1 ) - pi.mask |= ply::PLYMask::PM_TETRAFLAGS; - - if( TetraType::HasTetraQuality()) - { - if( pf.AddToRead(TetraDesc(2))!=-1 ) - pi.mask |= ply::PLYMask::PM_TETRAQUALITY; - } - - if( TetraType::HasTetraColor() ) - { - if( pf.AddToRead(TetraDesc(6))!=-1 ) - { - pf.AddToRead(TetraDesc(7)); - pf.AddToRead(TetraDesc(8)); - pi.mask |= ply::PLYMask::PM_TETRACOLOR; - } - } - - - // if( FaceType::HasWedgeColor() || FaceType::HasFaceColor() || VertexType::HasColor()) - //{ - // if( pf.AddToRead(TetraDesc(4))!=-1 ) - // { - // pi.mask |= ply::PLYMask::PM_WEDGCOLOR; - // } - //} - - // Descrittori definiti dall'utente, - vector VPV(pi.vdn); // property descriptor relative al tipo LoadPly_VertexAux - vector FPV(pi.fdn); // property descriptor relative al tipo LoadPly_FaceAux - if(pi.vdn>0){ - // Compute the total size needed to load additional per vertex data. - size_t totsz=0; - for(int i=0;i,data)+totsz; - totsz+=pi.VertexData[i].memtypesize(); - if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return -1; } - } - if(totsz > MAX_USER_DATA) - { - pi.status = vcg::ply::E_BADTYPE; - return -1; - } - } - if(pi.fdn>0){ - size_t totsz=0; - for(int i=0;i MAX_USER_DATA) - { - pi.status = vcg::ply::E_BADTYPE; - return -1; - } - } - - /**************************************************************/ - /* Main Reading Loop */ - /**************************************************************/ - m.Clear(); - for(int i=0;i::AddVertices(m,n); - - for(j=0;j::AddTetra(m,n); - pf.SetCurElement(i); - - for(j=0;j=m.vn ) - { - pi.status = PlyInfo::E_BAD_VERT_INDEX; - return -1; - } - (*fi).V(k) = index[ fa.v[k] ]; - } - - if( pi.mask & ply::PLYMask::PM_TETRAFLAGS ) - { - (*fi).Flags() = fa.flags; - } - - if( pi.mask & ply::PLYMask::PM_TETRAQUALITY ) - { - (*fi).Q() = fa.q; - } - - if( pi.mask & ply::PLYMask::PM_TETRACOLOR ) - { - (*fi).C()[0] = fa.r; - (*fi).C()[1] = fa.g; - (*fi).C()[2] = fa.b; - (*fi).C()[3] = 255; - } - - if(TetraType::HasTetraColor()){ - { - (*fi).C()[0] = (unsigned char)((fa.colors[0*3+0]*255+fa.colors[1*3+0]*255+fa.colors[2*3+0]*255)/3.0f); - (*fi).C()[1] = (unsigned char)((fa.colors[0*3+1]*255+fa.colors[1*3+1]*255+fa.colors[2*3+1]*255)/3.0f); - (*fi).C()[2] = (unsigned char)((fa.colors[0*3+2]*255+fa.colors[1*3+2]*255+fa.colors[2*3+2]*255)/3.0f); - } - } - } - - for(k=0;k=numvert_tmp ) { -// pi.status = PlyInfo::E_BAD_VERT_INDEX; -// return -1; -// } -// if(tsa.v[k+2]==-1) -// { -// k+=2; -// if(k%2) remainder=0; -// else remainder=1; -// continue; -// } -// tf.V(0) = index[ tsa.v[k+0] ]; -// tf.V(1) = index[ tsa.v[k+1] ]; -// tf.V(2) = index[ tsa.v[k+2] ]; -// if((k+remainder)%2) swap (tf.V(0), tf.V(1) ); -// m.face.push_back( tf ); -// } -// } -// } - else - { - // Skippaggio elementi non gestiti - int n = pf.ElemNumber(i); - pf.SetCurElement(i); - - for(int j=0;j32 && buf[i]<125 ) buf[j++] = buf[i]; - // - // buf[j] = 0; - // char buf2[255]; - // __interpret_texture_name( buf,filename,buf2 ); - // textures.push_back( xstring(buf2) ); - // } - // if( !strncmp(c,NFILE,strlen(NFILE)) ) - // { - // strcpy(buf,c+strlen(NFILE)+1); - // n = strlen(buf); - // for(i=j=0;i32 && buf[i]<125 ) buf[j++] = buf[i]; - // - // buf[j] = 0; - // char buf2[255]; - // __interpret_texture_name( buf,filename,buf2 ); - // normalmaps.push_back( xstring(buf2) ); - // } - //} - - // vn and fn should be correct but if someone wrongly saved some deleted elements they can be wrong. - m.vn = 0; - VertexIterator vi; - for(vi=m.vert.begin();vi!=m.vert.end();++vi) - if( ! (*vi).IsD() ) - ++m.vn; - - m.tn = 0; - TetraIterator fi; - for(fi=m.tetra.begin();fi!=m.tetra.end();++fi) - if( ! (*fi).IsD() ) - ++m.tn; - - return 0; -} - - - // Caricamento camera da un ply -int LoadCamera(const char * filename) -{ - vcg::ply::PlyFile pf; - if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 ) - { - pi.status = pf.GetError(); - return -1; - } - - - bool found = true; - int i; - for(i=0;i<23;++i) - { - if( pf.AddToRead(CameraDesc(i))==-1 ) - { - found = false; - break; - } - } - - if(!found) - return -1; - - for(i=0;i + struct LoadPly_VertAux + { + S p[3]; + int flags; + float q; + unsigned char r; + unsigned char g; + unsigned char b; + unsigned char a; + unsigned char data[MAX_USER_DATA]; + }; + + // Struttura ausiliaria caricamento camera + //struct LoadPly_Camera + //{ + // float view_px; + // float view_py; + // float view_pz; + // float x_axisx; + // float x_axisy; + // float x_axisz; + // float y_axisx; + // float y_axisy; + // float y_axisz; + // float z_axisx; + // float z_axisy; + // float z_axisz; + // float focal; + // float scalex; + // float scaley; + // float centerx; + // float centery; + // int viewportx; + // int viewporty; + // float k1; + // float k2; + // float k3; + // float k4; + //}; + + static const PropDescriptor &VertDesc(int i) + { + const static PropDescriptor pv[9]={ + {"vertex", "x", ply::T_FLOAT, PlyType(), offsetof(LoadPly_VertAux,p),0,0,0,0,0}, + {"vertex", "y", ply::T_FLOAT, PlyType(), offsetof(LoadPly_VertAux,p) + sizeof(ScalarType),0,0,0,0,0}, + {"vertex", "z", ply::T_FLOAT, PlyType(), offsetof(LoadPly_VertAux,p) + 2 * sizeof(ScalarType),0,0,0,0,0}, + {"vertex", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_VertAux,flags),0,0,0,0,0}, + {"vertex", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux,q),0,0,0,0,0}, + {"vertex", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,r),0,0,0,0,0}, + {"vertex", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,g),0,0,0,0,0}, + {"vertex", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,b),0,0,0,0,0}, + {"vertex", "alpha" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux,a),0,0,0,0,0}, + }; + return pv[i]; + } + + + static const PropDescriptor &TetraDesc(int i) + { + const static PropDescriptor qf[10]= + { + {"tetra", "vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,v), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,size) }, + {"tetra", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,flags), 0,0,0,0,0}, + {"tetra", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,q), 0,0,0,0,0}, + {"tetra", "texcoord", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,texcoord), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,ntexcoord) }, + {"tetra", "color", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,colors), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,ncolors) }, + {"tetra", "texnumber", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,texcoordind), 0,0,0,0,0}, + {"tetra", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,r), 0,0,0,0,0}, + {"tetra", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,g), 0,0,0,0,0}, + {"tetra", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,b), 0,0,0,0,0}, + {"tetra", "alpha" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,a), 0,0,0,0,0}, + + }; + return qf[i]; + } + + + + /// Standard call for reading a mesh + static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0) + { + PlyInfo pi; + pi.cb=cb; + return Open(m, filename, pi); + } + + /// Read a mesh and store in loadmask the loaded field + static int Open( OpenMeshType &m, const char * filename, int & loadmask, CallBackPos *cb =0) + { + PlyInfo pi; + pi.mask=loadmask; + return Open(m, filename,pi); + loadmask=pi.mask; + } + + + /// read a mesh with all the possible option specified in the PlyInfo obj. + static int Open( OpenMeshType &m, const char * filename, PlyInfo & pi ) + { + assert(filename!=0); + vector index; + + LoadPly_TetraAux fa; + LoadPly_VertAux va; + + pi.mask = 0; + + va.flags = 42; + + pi.status = ::vcg::ply::E_NOERROR; + + // The main descriptor of the ply file + vcg::ply::PlyFile pf; + + // Open the file and parse the header + std::cerr << "Parsing the header.." << std::endl; + if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)== -1 ) + { + pi.status = pf.GetError(); + return -1; + } + std::cerr << "Parsed the header.." << std::endl; + pi.header = pf.GetHeader(); + + // Descrittori dati standard (vertex coord e faces) + if( pf.AddToRead(VertDesc(0)) == -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } + if( pf.AddToRead(VertDesc(1)) == -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } + if( pf.AddToRead(VertDesc(2)) == -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } + if( pf.AddToRead(TetraDesc(0))== -1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; } + + // Descrittori facoltativi dei flags + if( pf.AddToRead(VertDesc(3))!=-1 ) + pi.mask |= vcg::tetra::io::Mask::IOM_VERTFLAGS; + if( VertexType::HasQuality() ) + { + if( pf.AddToRead(VertDesc(4))!=-1 || + pf.AddToRead(VertDesc(9))!=-1 ) + pi.mask |= vcg::tetra::io::Mask::IOM_VERTQUALITY; + } + if( VertexType::HasColor() ) + { + if( pf.AddToRead(VertDesc(5))!=-1 ) + { + pf.AddToRead(VertDesc(6)); + pf.AddToRead(VertDesc(7)); + pf.AddToRead(VertDesc(8)); + + pi.mask |= vcg::tetra::io::Mask::IOM_VERTCOLOR; + } + } + // se ci sono i flag per vertice ci devono essere anche i flag per faccia + if( pf.AddToRead(TetraDesc(1))!=-1 ) + pi.mask |= vcg::tetra::io::Mask::IOM_TETRAFLAGS; + if( TetraType::HasQuality()) + { + if( pf.AddToRead(TetraDesc(2))!=-1 ) + pi.mask |= vcg::tetra::io::Mask::IOM_TETRAQUALITY; + } + if( TetraType::HasColor() ) + { + if( pf.AddToRead(TetraDesc(6))!=-1 ) + { + pf.AddToRead(TetraDesc(7)); + pf.AddToRead(TetraDesc(8)); + pf.AddToRead(TetraDesc(9)); + pi.mask |= vcg::tetra::io::Mask::IOM_TETRACOLOR; + } + } + // Descrittori definiti dall'utente, + vector VPV(pi.vdn); // property descriptor relative al tipo LoadPly_VertexAux + vector FPV(pi.fdn); // property descriptor relative al tipo LoadPly_FaceAux + + if(pi.vdn>0){ + // Compute the total size needed to load additional per vertex data. + size_t totsz=0; + for(int i=0;i,data)+totsz; + totsz+=pi.VertexData[i].memtypesize(); + if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return -1; } + } + if(totsz > MAX_USER_DATA) + { + pi.status = vcg::ply::E_BADTYPE; + return -1; + } + } + if(pi.fdn>0){ + size_t totsz=0; + for(int i=0;i MAX_USER_DATA) + { + pi.status = vcg::ply::E_BADTYPE; + return -1; + } + } + /**************************************************************/ + /* Main Reading Loop */ + /**************************************************************/ + m.Clear(); + for(int i=0;i::AddVertices(m,n); + + for(j=0;j::AddTetras(m, n); + pf.SetCurElement(i); + + for(j=0;j=m.vn ) + { + pi.status = PlyInfo::E_BAD_VERT_INDEX; + return -1; + } + (*ti).V(k) = index[ fa.v[k] ]; + } + + if( pi.mask & vcg::tetra::io::Mask::IOM_TETRAFLAGS ) + { + (*ti).Flags() = fa.flags; + } + + if( pi.mask & vcg::tetra::io::Mask::IOM_TETRAQUALITY ) + { + (*ti).Q() = fa.q; + } + + if( pi.mask & vcg::tetra::io::Mask::IOM_TETRACOLOR ) + { + (*ti).C()[0] = fa.r; + (*ti).C()[1] = fa.g; + (*ti).C()[2] = fa.b; + (*ti).C()[3] = fa.a; + } + ++ti; + } + + for(k=0;k32 && buf[i]<125 ) buf[j++] = buf[i]; + // + // buf[j] = 0; + // char buf2[255]; + // __interpret_texture_name( buf,filename,buf2 ); + // textures.push_back( xstring(buf2) ); + // } + // if( !strncmp(c,NFILE,strlen(NFILE)) ) + // { + // strcpy(buf,c+strlen(NFILE)+1); + // n = strlen(buf); + // for(i=j=0;i32 && buf[i]<125 ) buf[j++] = buf[i]; + // + // buf[j] = 0; + // char buf2[255]; + // __interpret_texture_name( buf,filename,buf2 ); + // normalmaps.push_back( xstring(buf2) ); + // } + //} + + // vn and fn should be correct but if someone wrongly saved some deleted elements they can be wrong. + m.vn = 0; + VertexIterator vi; + for(vi=m.vert.begin();vi!=m.vert.end();++vi) + if( ! (*vi).IsD() ) + ++m.vn; + + m.tn = 0; + TetraIterator fi; + for(fi=m.tetra.begin();fi!=m.tetra.end();++fi) + if( ! (*fi).IsD() ) + ++m.tn; + + return 0; + } + + +// // Caricamento camera da un ply +// int LoadCamera(const char * filename) +// { +// vcg::ply::PlyFile pf; +// if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 ) +// { +// pi.status = pf.GetError(); +// return -1; +// } + + +// bool found = true; +// int i; +// for(i=0;i<23;++i) +// { +// if( pf.AddToRead(CameraDesc(i))==-1 ) +// { +// found = false; +// break; +// } +// } + +// if(!found) +// return -1; + +// for(i=0;i