restructured a bit the code

This commit is contained in:
nico 2017-01-23 16:20:22 +01:00
parent f5795556ba
commit 03f41fd117
1 changed files with 69 additions and 41 deletions

View File

@ -18,59 +18,86 @@ class GLField
public: public:
static void GLDrawField(CoordType dir[4], static void GLDrawField(CoordType dir[4],
CoordType center, const CoordType &center,
ScalarType &size, const ScalarType &size,
bool onlyPD1=false, const ScalarType &Width0,
bool oneside=false) const ScalarType &Width1,
{ const vcg::Color4b &Color0,
ScalarType size1=size; const vcg::Color4b &Color1,
ScalarType size2=size; bool oneside,
if (oneside)size2=0; bool onlyPD1)
{
CoordType dirN[4];
for (size_t i=0;i<4;i++)
{
dirN[i]=dir[i];
dirN[i].Normalize();
}
glLineWidth(2); ScalarType size1=size;
//vcg::glColor(vcg::Color4b(0,0,255,255)); if (oneside)size1=0;
vcg::glColor(vcg::Color4b(0,0,0,255));
glLineWidth(Width0);
vcg::glColor(Color0);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex(center+dir[0]*size1); glVertex(center+dirN[0]*size);
glVertex(center-dir[0]*size2); glVertex(center+dirN[2]*size1);
glEnd(); glEnd();
if (onlyPD1)return; if (onlyPD1)return;
glLineWidth(2);
//vcg::glColor(vcg::Color4b(0,255,0,255)); glLineWidth(Width1);
vcg::glColor(vcg::Color4b(0,0,0,255)); vcg::glColor(Color1);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex(center+dir[1]*size1); glVertex(center+dirN[1]*size);
glVertex(center-dir[1]*size2); glVertex(center+dirN[3]*size1);
glEnd(); glEnd();
} }
///draw the cross field of a given face in a given position // ///draw the cross field of a given face in a given position
static void GLDrawSingleFaceField(const FaceType &f, // static void GLDrawSingleFaceField(const FaceType &f,
CoordType pos, // CoordType pos,
ScalarType &size, // ScalarType &size,
bool onlyPD1=false, // bool onlyPD1,
bool oneside=false) // bool oneside)
{ // {
CoordType center=pos; // CoordType center=pos;
CoordType normal=f.cN(); // CoordType normal=f.cN();
CoordType dir[4]; // CoordType dir[4];
vcg::tri::CrossField<MeshType>::CrossVector(f,dir); // vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
GLDrawField(dir,center,size,onlyPD1,oneside); // GLDrawField(dir,center,size,onlyPD1,oneside);
} // }
///draw the cross field of a given face ///draw the cross field of a given face
static void GLDrawSingleFaceField(const FaceType &f, static void GLDrawSingleFaceField(const FaceType &f,
ScalarType &size, const ScalarType &size,
bool onlyPD1=false, const bool oneside,
bool oneside=false) const bool onlyPD1,
const ScalarType maxN)
{ {
CoordType center=(f.cP(0)+f.cP(1)+f.cP(2))/3; CoordType center=(f.cP(0)+f.cP(1)+f.cP(2))/3;
CoordType normal=f.cN(); CoordType normal=f.cN();
CoordType dir[4]; CoordType dir[4];
vcg::tri::CrossField<MeshType>::CrossVector(f,dir); vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
GLDrawField(dir,center,size,onlyPD1,oneside);
if (maxN<=0)
GLDrawField(dir,center,size,2,2,vcg::Color4b(0,0,0,255),vcg::Color4b(0,0,0,255),oneside,onlyPD1);
else
{
ScalarType Norm0=dir[0].Norm();
ScalarType Norm1=dir[1].Norm();
ScalarType MaxW=6;
ScalarType MinW=0.5;
ScalarType IntervW=MaxW-MinW;
if (Norm0>maxN)Norm0=maxN;
if (Norm1>maxN)Norm1=maxN;
vcg::Color4b Col0=vcg::Color4b::ColorRamp(0,maxN,Norm0);
vcg::Color4b Col1=vcg::Color4b::ColorRamp(0,maxN,Norm1);
ScalarType W0=(Norm0/maxN)*IntervW+MinW;
ScalarType W1=(Norm1/maxN)*IntervW+MinW;
GLDrawField(dir,center,size,W0,W1,Col0,Col1,oneside,onlyPD1);
}
} }
// static void GLDrawFaceSeams(const FaceType &f, // static void GLDrawFaceSeams(const FaceType &f,
@ -97,14 +124,15 @@ public:
CoordType normal=v.cN(); CoordType normal=v.cN();
CoordType dir[4]; CoordType dir[4];
vcg::tri::CrossField<MeshType>::CrossVector(v,dir); vcg::tri::CrossField<MeshType>::CrossVector(v,dir);
GLDrawField(dir,center,size); GLDrawField(dir,center,size,2,2,vcg::Color4b(0,0,0,255),vcg::Color4b(0,0,0,255),false,false);
} }
static void GLDrawFaceField(const MeshType &mesh, static void GLDrawFaceField(const MeshType &mesh,
bool onlyPD1=false, bool onlyPD1,
bool oneside=false, bool oneside,
ScalarType scale=0.002) ScalarType GlobalScale=0.002,
const ScalarType maxN=0)
{ {
glPushAttrib(GL_ALL_ATTRIB_BITS); glPushAttrib(GL_ALL_ATTRIB_BITS);
@ -112,11 +140,11 @@ public:
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_BLEND); glDisable(GL_BLEND);
ScalarType size=mesh.bbox.Diag()*scale; ScalarType size=mesh.bbox.Diag()*GlobalScale;
for (unsigned int i=0;i<mesh.face.size();i++) for (unsigned int i=0;i<mesh.face.size();i++)
{ {
if (mesh.face[i].IsD())continue; if (mesh.face[i].IsD())continue;
GLDrawSingleFaceField(mesh.face[i],size,onlyPD1,oneside); GLDrawSingleFaceField(mesh.face[i],size,oneside,onlyPD1,maxN);
} }
glPopAttrib(); glPopAttrib();
} }