From ab19874591d517ebc86cdcdfcaefe229230986b8 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Sun, 18 Nov 2012 18:09:02 +0000 Subject: [PATCH] moved several functions from glfield and added useful functions to draw and debug UV space , seams and other --- wrap/miq/core/glUtils.h | 210 +++++++++++++++++++++++++--------------- 1 file changed, 131 insertions(+), 79 deletions(-) diff --git a/wrap/miq/core/glUtils.h b/wrap/miq/core/glUtils.h index fe457813..3c092425 100644 --- a/wrap/miq/core/glUtils.h +++ b/wrap/miq/core/glUtils.h @@ -7,6 +7,137 @@ class Miq_Gl_Utils { public: + ///singular vertices should be selected + template + static void GLDrawSingularities(MeshType &mesh, + float size=8, + bool DrawUV=false) + { + bool hasSingular = vcg::tri::HasPerVertexAttribute(mesh,std::string("Singular")); + bool hasSingularDegree = vcg::tri::HasPerVertexAttribute(mesh,std::string("SingularityDegree")); + + if (!hasSingular)return; + + typename MeshType::template PerVertexAttributeHandle Handle_Singular; + typename MeshType::template PerVertexAttributeHandle Handle_SingularDegree; + + Handle_Singular=vcg::tri::Allocator::template GetPerVertexAttribute(mesh,std::string("Singular")); + + Handle_SingularDegree=vcg::tri::Allocator::template GetPerVertexAttribute(mesh,std::string("SingularityDegree")); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + glEnable(GL_COLOR_MATERIAL); + glDisable(GL_LIGHTING); + glDepthRange(0,0.999); + glPointSize(size); + glBegin(GL_POINTS); + glColor4d(0,0,1,0.7); + for (unsigned int j=0;jIsD())continue; + for (int i=0;i<3;i++) + { + CVertex *v=f->V(i); + if (!Handle_Singular[v])continue; + int mmatch=3; + if (hasSingularDegree) + mmatch=Handle_SingularDegree[i]; + if (!DrawUV) + vcg::glVertex(v->P()); + else + glVertex3d(f->WT(i).P().X(),f->WT(i).P().Y(),0); + } + } + + glEnd(); + glPopAttrib(); + } + + template + static void GLDrawFaceSeams(const FaceType &f, + vcg::Point3 seams, + vcg::Color4b seamCol[3], + float size=3, + bool UV=false) + { + typedef typename FaceType::CoordType CoordType; + typedef typename FaceType::ScalarType ScalarType; + glLineWidth(size); + glBegin(GL_LINES); + for (int i=0;i<3;i++) + { + if (!seams[i])continue; + vcg::glColor(seamCol[i]); + if (!UV) + { + glVertex(f.cV0(i)->P()); + glVertex(f.cV1(i)->P()); + } + else + { + int i0=i; + int i1=(i0+1)%3; + CoordType p0=CoordType(f.cWT(i0).P().X(),f.cWT(i0).P().Y(),0); + CoordType p1=CoordType(f.cWT(i1).P().X(),f.cWT(i1).P().Y(),0); + glVertex(p0); + glVertex(p1); + } + } + glEnd(); + } + + template + static void GLDrawSeams(MeshType &mesh, + float size=3, + bool UV=false) + { + bool hasSeam = vcg::tri::HasPerFaceAttribute(mesh,std::string("Seams")); + if(!hasSeam)return; + bool HasSeamIndex=vcg::tri::HasPerFaceAttribute(mesh,std::string("SeamsIndex")); + + typedef typename MeshType::template PerFaceAttributeHandle > SeamsHandleType; + typedef typename MeshType::template PerFaceAttributeHandle SeamsIndexHandleType; + + typedef typename vcg::tri::Allocator SeamsAllocator; + + SeamsHandleType Handle_Seam; + Handle_Seam=SeamsAllocator::template GetPerFaceAttribute >(mesh,std::string("Seams")); + + SeamsIndexHandleType Handle_SeamIndex; + if (HasSeamIndex) + Handle_SeamIndex=SeamsAllocator::template GetPerFaceAttribute(mesh,std::string("SeamsIndex")); + + glPushAttrib(GL_ALL_ATTRIB_BITS); + glEnable(GL_COLOR_MATERIAL); + glDisable(GL_LIGHTING); + + glDepthRange(0,0.999); + for (unsigned int i=0;i seams=Handle_Seam[i]; + vcg::Color4b seamCol[3]; + for (int j=0;j<3;j++) + { + seamCol[j]=vcg::Color4b(0,255,0,255); + if (HasSeamIndex) + { + int index=Handle_SeamIndex[i][j]; + //assert(index>0); + if (index>=0) + seamCol[j]=vcg::Color4b::Scatter(100,index); + } + } + + GLDrawFaceSeams(mesh.face[i],seams,seamCol,size,UV); + + } + glPopAttrib(); + } + + ///this is useful to debug the output + ///of the vertex indexing class template static void GLDrawVertexIndexing(VertexIndexingType &VI) { @@ -29,45 +160,6 @@ public: glPopAttrib(); } - template - static void DrawFlippedFacesIfSelected(MeshType &ParamMesh, - bool DrawUV=false, - vcg::Color4b color=vcg::Color4b(255,0,0,255), - typename MeshType::ScalarType width=2.0) - { - typedef typename MeshType::FaceType FaceType; - typedef typename MeshType::CoordType CoordType; - typedef typename MeshType::ScalarType ScalarType; - - glPushAttrib(GL_ALL_ATTRIB_BITS); - glDisable(GL_LIGHTING); - glLineWidth(width); - vcg::glColor(color); - glBegin(GL_LINES); - for (unsigned int i=0;iIsS())continue; - for (int k=0;k<3;k++) - { - CoordType p0,p1; - if (!DrawUV) - { - p0=f->P0(k); - p1=f->P1(k); - } - else - { - p0=CoordType(f->WT(k).P().X(),f->WT(k).P().Y(),0); - p1=CoordType(f->WT((k+1)%3).P().X(),f->WT((k+1)%3).P().Y(),0); - } - vcg::glVertex(p0); - vcg::glVertex(p1); - } - } - glEnd(); - glPopAttrib(); - } template static void QuadGLDrawIntegerVertices(QuadrangulatorType &Quadr) @@ -162,45 +254,5 @@ public: glPopAttrib(); } - - template - static void GLDrawPolygonalMesh(PolyMesh &polymesh) - { - glPushAttrib(GL_ALL_ATTRIB_BITS); - glEnable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); - glDisable(GL_TEXTURE_2D); - glColor3d(0.7,0.8,0.9); - //glFrontFace(GL_CW); - glDepthRange(0,0.998); - for (unsigned int i=0;iN()); - glVertex(v->P()); - } - glEnd(); - } - - glDepthRange(0,0.997); - glDisable(GL_LIGHTING); - glEnable(GL_COLOR_MATERIAL); - glColor3d(0,0,0); - for (unsigned int i=0;iN()); - glVertex(v->P()); - } - glEnd(); - } - glPopAttrib(); - } }; #endif