2012-10-08 13:53:07 +02:00
|
|
|
#ifndef GL_FIELD
|
|
|
|
#define GL_FIELD
|
|
|
|
|
2012-09-22 15:40:56 +02:00
|
|
|
#include <vcg/complex/algorithms/parametrization/tangent_field_operators.h>
|
|
|
|
|
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;
|
2012-09-03 17:58:38 +02:00
|
|
|
typedef typename MeshType::CoordType CoordType;
|
2012-03-16 14:50:45 +01:00
|
|
|
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)
|
|
|
|
{
|
2012-09-03 17:58:38 +02:00
|
|
|
|
2012-09-06 01:27:10 +02:00
|
|
|
glLineWidth(2);
|
2012-09-03 17:58:38 +02:00
|
|
|
vcg::glColor(vcg::Color4b(0,0,255,255));
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex(center);
|
|
|
|
glVertex(center+dir[0]*size);
|
|
|
|
glEnd();
|
|
|
|
|
2012-09-06 01:27:10 +02:00
|
|
|
glLineWidth(2);
|
|
|
|
vcg::glColor(vcg::Color4b(0,255,0,255));
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex(center);
|
|
|
|
glVertex(center+dir[1]*size);
|
|
|
|
glEnd();
|
|
|
|
/*glLineWidth(1);
|
2012-09-03 17:58:38 +02:00
|
|
|
vcg::glColor(vcg::Color4b(0,0,0,255));
|
2012-03-16 14:50:45 +01:00
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
2012-09-03 17:58:38 +02:00
|
|
|
for (int i=1;i<4;i++)
|
|
|
|
{
|
|
|
|
glVertex(center);
|
|
|
|
glVertex(center+dir[i]*size);
|
2012-03-16 14:50:45 +01:00
|
|
|
}
|
2012-09-06 01:27:10 +02:00
|
|
|
glEnd();*/
|
2012-03-16 14:50:45 +01:00
|
|
|
}
|
|
|
|
|
2012-09-03 17:58:38 +02:00
|
|
|
|
2012-05-25 15:22:07 +02:00
|
|
|
///draw the cross field of a given face
|
2012-09-06 01:27:10 +02:00
|
|
|
static void GLDrawFaceField(const FaceType &f,
|
2012-05-25 15:22:07 +02:00
|
|
|
ScalarType &size)
|
|
|
|
{
|
2012-11-18 19:07:39 +01:00
|
|
|
CoordType center=(f.cP0(0)+f.cP0(1)+f.cP0(2))/3;
|
2012-05-25 15:22:07 +02:00
|
|
|
CoordType normal=f.cN();
|
|
|
|
CoordType dir[4];
|
|
|
|
vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
|
|
|
|
GLDrawField(dir,center,size);
|
|
|
|
}
|
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// static void GLDrawFaceSeams(const FaceType &f,
|
|
|
|
// vcg::Point3<bool> seams,
|
|
|
|
// vcg::Color4b seamCol[3])
|
|
|
|
// {
|
|
|
|
// glLineWidth(2);
|
|
|
|
|
|
|
|
// glBegin(GL_LINES);
|
|
|
|
// for (int i=0;i<3;i++)
|
|
|
|
// {
|
|
|
|
// if (!seams[i])continue;
|
|
|
|
// vcg::glColor(seamCol[i]);
|
|
|
|
// glVertex(f.V0(i)->P());
|
|
|
|
// glVertex(f.V1(i)->P());
|
|
|
|
// }
|
|
|
|
// glEnd();
|
|
|
|
// }
|
2012-09-03 17:58:38 +02:00
|
|
|
|
2012-05-25 15:22:07 +02:00
|
|
|
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:
|
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// ///singular vertices should be selected
|
|
|
|
// static void GLDrawSingularities(MeshType &mesh)
|
|
|
|
// {
|
|
|
|
// bool hasSingular = vcg::tri::HasPerVertexAttribute(mesh,std::string("Singular"));
|
|
|
|
// bool hasSingularDegree = vcg::tri::HasPerVertexAttribute(mesh,std::string("SingularityDegree"));
|
2012-10-15 03:13:30 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// if (!hasSingular)return;
|
2012-10-15 03:13:30 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// typename MeshType::template PerVertexAttributeHandle<bool> Handle_Singular;
|
|
|
|
// typename MeshType::template PerVertexAttributeHandle<int> Handle_SingularDegree;
|
2012-10-15 03:13:30 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// Handle_Singular=vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<bool>(mesh,std::string("Singular"));
|
2012-10-15 03:13:30 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// Handle_SingularDegree=vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<int>(mesh,std::string("SingularityDegree"));
|
2012-10-15 03:13:30 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
// glEnable(GL_COLOR_MATERIAL);
|
|
|
|
// glDisable(GL_LIGHTING);
|
|
|
|
// glDepthRange(0,0.999);
|
|
|
|
// ScalarType size=10;
|
|
|
|
// glPointSize(size);
|
|
|
|
// glBegin(GL_POINTS);
|
|
|
|
// for (unsigned int i=0;i<mesh.vert.size();i++)
|
|
|
|
// {
|
|
|
|
// if (mesh.vert[i].IsD())continue;
|
|
|
|
// if (!Handle_Singular[i])continue;
|
|
|
|
// int mmatch=3;
|
|
|
|
// if (hasSingularDegree)
|
|
|
|
// mmatch=Handle_SingularDegree[i];
|
2012-10-15 03:13:30 +02:00
|
|
|
|
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// 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-10-15 03:13:30 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// vcg::glVertex(mesh.vert[i].P());
|
2012-03-16 14:50:45 +01:00
|
|
|
|
2012-11-18 19:07:39 +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-09-03 17:58:38 +02:00
|
|
|
ScalarType size=mesh.bbox.Diag()/400.0;
|
2012-09-06 01:27:10 +02:00
|
|
|
for (unsigned int i=0;i<mesh.face.size();i++)
|
2012-05-25 15:22:07 +02:00
|
|
|
{
|
|
|
|
if (mesh.face[i].IsD())continue;
|
|
|
|
//if (!mesh.face[i].leading)continue;
|
2012-09-06 01:27:10 +02:00
|
|
|
GLDrawFaceField(mesh.face[i],size);
|
2012-05-25 15:22:07 +02:00
|
|
|
}
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void GLDrawVertField(const MeshType &mesh)
|
|
|
|
{
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
glDisable(GL_LIGHTING);
|
2012-09-03 17:58:38 +02:00
|
|
|
ScalarType size=mesh.bbox.Diag()/100.0;
|
|
|
|
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();
|
|
|
|
}
|
2012-09-03 17:58:38 +02:00
|
|
|
|
2012-11-18 19:07:39 +01:00
|
|
|
// static void GLDrawSeams(MeshType &mesh)
|
|
|
|
// {
|
|
|
|
// 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<vcg::Point3<bool> > SeamsHandleType;
|
|
|
|
// typedef typename MeshType::template PerFaceAttributeHandle<vcg::Point3i > SeamsIndexHandleType;
|
|
|
|
|
|
|
|
// typedef typename vcg::tri::Allocator<MeshType> SeamsAllocator;
|
|
|
|
|
|
|
|
// SeamsHandleType Handle_Seam;
|
|
|
|
// Handle_Seam=SeamsAllocator::template GetPerFaceAttribute<vcg::Point3<bool> >(mesh,std::string("Seams"));
|
|
|
|
|
|
|
|
// SeamsIndexHandleType Handle_SeamIndex;
|
|
|
|
// if (HasSeamIndex)
|
|
|
|
// Handle_SeamIndex=SeamsAllocator::template GetPerFaceAttribute<vcg::Point3i >(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<mesh.face.size();i++)
|
|
|
|
// {
|
|
|
|
// if (mesh.face[i].IsD())continue;
|
|
|
|
// vcg::Point3<bool> 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);
|
|
|
|
|
|
|
|
// }
|
|
|
|
// glPopAttrib();
|
|
|
|
// }
|
2012-03-16 14:50:45 +01:00
|
|
|
};
|
2012-09-03 17:58:38 +02:00
|
|
|
|
|
|
|
}
|
2012-10-08 13:53:07 +02:00
|
|
|
|
|
|
|
#endif
|