vcglib/wrap/gl/gl_field.h

116 lines
2.9 KiB
C
Raw Normal View History

2012-03-16 14:50:45 +01:00
namespace vcg{
template <class MeshType>
class GLField
{
typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::ScalarType ScalarType;
2012-05-25 15:22:07 +02:00
static void GLDrawField(CoordType dir[4],
CoordType center,
2012-03-16 14:50:45 +01:00
ScalarType &size)
{
glLineWidth(1);
vcg::Color4b c;
vcg::glColor(vcg::Color4b(0,0,0,255));
glBegin(GL_LINES);
for (int i=0;i<4;i++)
{
glVertex(center);
glVertex(center+dir[i]*size);
}
glEnd();
}
2012-05-25 15:22:07 +02:00
///draw the cross field of a given face
static void GLDrawFaceField(const MeshType &mesh,
const FaceType &f,
ScalarType &size)
{
CoordType center=(f.P0(0)+f.P0(1)+f.P0(2))/3;
CoordType normal=f.cN();
CoordType dir[4];
vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
GLDrawField(dir,center,size);
}
static void GLDrawVertField(const MeshType &mesh,
const VertexType &v,
ScalarType &size)
{
CoordType center=v.cP();
CoordType normal=v.cN();
CoordType dir[4];
vcg::tri::CrossField<MeshType>::CrossVector(v,dir);
GLDrawField(dir,center,size);
}
2012-03-16 14:50:45 +01:00
public:
///singular vertices should be selected
static void GLDrawSingularities(const MeshType &mesh)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
glDepthRange(0,0.999);
MyScalarType size=10;
glPointSize(size);
glBegin(GL_POINTS);
2012-05-25 15:22:07 +02:00
for (int i=0;i<mesh.vert.size();i++)
2012-03-16 14:50:45 +01:00
{
2012-05-25 15:22:07 +02:00
if (mesh.vert[i].IsD())continue;
if (!mesh.vert[i].IsS())continue;
2012-03-16 14:50:45 +01:00
int mmatch;
2012-05-25 15:22:07 +02:00
bool IsSing=vcg::tri::CrossField<MeshType>::IsSingular(mesh.vert[i],mmatch);
2012-03-16 14:50:45 +01:00
if (!IsSing)continue;
assert(IsSing);
assert(mmatch!=0);
/*vcg::glColor(vcg::Color4b(255,0,0,255));*/
if (mmatch==1)vcg::glColor(vcg::Color4b(0,0,255,255));
else
if (mmatch==2)vcg::glColor(vcg::Color4b(255,0,0,255));
else
if (mmatch==3)vcg::glColor(vcg::Color4b(0,255,255,255));
2012-05-25 15:22:07 +02:00
vcg::glVertex(mesh.vert[i].P());
2012-03-16 14:50:45 +01:00
}
glEnd();
glPopAttrib();
}
2012-05-25 15:22:07 +02:00
2012-03-16 14:50:45 +01:00
static void GLDrawFaceField(const MeshType &mesh)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
2012-05-25 15:22:07 +02:00
MyScalarType size=mesh.bbox.Diag()/100.0;
vcg::Color4b c=vcg::Color4b(255,0,0,255);
for (int i=0;i<mesh.face.size();i++)
{
if (mesh.face[i].IsD())continue;
//if (!mesh.face[i].leading)continue;
GLDrawFaceField(mesh,mesh.face[i],size);
}
glPopAttrib();
}
static void GLDrawVertField(const MeshType &mesh)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHTING);
MyScalarType size=mesh.bbox.Diag()/100.0;
2012-03-16 14:50:45 +01:00
vcg::Color4b c=vcg::Color4b(255,0,0,255);
2012-05-25 15:22:07 +02:00
for (int i=0;i<mesh.vert.size();i++)
2012-03-16 14:50:45 +01:00
{
2012-05-25 15:22:07 +02:00
if (mesh.vert[i].IsD())continue;
//if (!mesh.face[i].leading)continue;
GLDrawVertField(mesh,mesh.vert[i],size);
2012-03-16 14:50:45 +01:00
}
glPopAttrib();
}
};
}