2012-10-08 13:53:07 +02:00
|
|
|
#ifndef GL_FIELD
|
|
|
|
#define GL_FIELD
|
|
|
|
|
2016-06-09 14:11:54 +02:00
|
|
|
#include <wrap/gl/space.h>
|
|
|
|
#include <wrap/gl/math.h>
|
2012-09-22 15:40:56 +02:00
|
|
|
#include <vcg/complex/algorithms/parametrization/tangent_field_operators.h>
|
2014-11-05 20:26:54 +01:00
|
|
|
#include <vcg/complex/allocate.h>
|
2012-09-22 15:40:56 +02:00
|
|
|
|
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
|
|
|
|
2015-09-14 14:05:03 +02:00
|
|
|
public:
|
|
|
|
|
2012-05-25 15:22:07 +02:00
|
|
|
static void GLDrawField(CoordType dir[4],
|
2017-01-23 16:20:22 +01:00
|
|
|
const CoordType ¢er,
|
|
|
|
const ScalarType &size,
|
|
|
|
const ScalarType &Width0,
|
|
|
|
const ScalarType &Width1,
|
|
|
|
const vcg::Color4b &Color0,
|
|
|
|
const vcg::Color4b &Color1,
|
|
|
|
bool oneside,
|
|
|
|
bool onlyPD1)
|
|
|
|
{
|
|
|
|
CoordType dirN[4];
|
|
|
|
for (size_t i=0;i<4;i++)
|
|
|
|
{
|
|
|
|
dirN[i]=dir[i];
|
|
|
|
dirN[i].Normalize();
|
|
|
|
}
|
|
|
|
|
2014-04-07 08:29:56 +02:00
|
|
|
ScalarType size1=size;
|
2017-01-23 16:20:22 +01:00
|
|
|
if (oneside)size1=0;
|
2012-09-03 17:58:38 +02:00
|
|
|
|
2017-01-23 16:20:22 +01:00
|
|
|
glLineWidth(Width0);
|
|
|
|
vcg::glColor(Color0);
|
2012-09-03 17:58:38 +02:00
|
|
|
glBegin(GL_LINES);
|
2017-01-23 16:20:22 +01:00
|
|
|
glVertex(center+dirN[0]*size);
|
|
|
|
glVertex(center+dirN[2]*size1);
|
2012-09-03 17:58:38 +02:00
|
|
|
glEnd();
|
|
|
|
|
2014-11-05 20:26:54 +01:00
|
|
|
if (onlyPD1)return;
|
2017-01-23 16:20:22 +01:00
|
|
|
|
|
|
|
glLineWidth(Width1);
|
|
|
|
vcg::glColor(Color1);
|
2012-09-06 01:27:10 +02:00
|
|
|
glBegin(GL_LINES);
|
2017-01-23 16:20:22 +01:00
|
|
|
glVertex(center+dirN[1]*size);
|
|
|
|
glVertex(center+dirN[3]*size1);
|
2012-09-06 01:27:10 +02:00
|
|
|
glEnd();
|
2014-04-07 08:29:56 +02:00
|
|
|
|
2012-03-16 14:50:45 +01:00
|
|
|
}
|
|
|
|
|
2017-01-23 16:20:22 +01:00
|
|
|
// ///draw the cross field of a given face in a given position
|
|
|
|
// static void GLDrawSingleFaceField(const FaceType &f,
|
|
|
|
// CoordType pos,
|
|
|
|
// ScalarType &size,
|
|
|
|
// bool onlyPD1,
|
|
|
|
// bool oneside)
|
|
|
|
// {
|
|
|
|
// CoordType center=pos;
|
|
|
|
// CoordType normal=f.cN();
|
|
|
|
// CoordType dir[4];
|
|
|
|
// vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
|
|
|
|
// GLDrawField(dir,center,size,onlyPD1,oneside);
|
|
|
|
// }
|
2012-09-03 17:58:38 +02:00
|
|
|
|
2012-05-25 15:22:07 +02:00
|
|
|
///draw the cross field of a given face
|
2015-09-14 14:05:03 +02:00
|
|
|
static void GLDrawSingleFaceField(const FaceType &f,
|
2017-01-23 16:20:22 +01:00
|
|
|
const ScalarType &size,
|
|
|
|
const bool oneside,
|
|
|
|
const bool onlyPD1,
|
2017-12-18 14:57:20 +01:00
|
|
|
const ScalarType maxN,
|
|
|
|
const ScalarType minN)
|
2012-05-25 15:22:07 +02:00
|
|
|
{
|
2014-11-05 20:26:54 +01:00
|
|
|
CoordType center=(f.cP(0)+f.cP(1)+f.cP(2))/3;
|
2017-12-18 14:57:20 +01:00
|
|
|
//CoordType normal=f.cN();
|
2012-05-25 15:22:07 +02:00
|
|
|
CoordType dir[4];
|
|
|
|
vcg::tri::CrossField<MeshType>::CrossVector(f,dir);
|
2017-01-23 16:20:22 +01:00
|
|
|
|
|
|
|
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;
|
2017-12-18 14:57:20 +01:00
|
|
|
vcg::Color4b Col0=vcg::Color4b::ColorRamp(minN,maxN,Norm0);
|
|
|
|
vcg::Color4b Col1=vcg::Color4b::ColorRamp(minN,maxN,Norm1);
|
|
|
|
ScalarType W0=(Norm0/(maxN-minN))*IntervW+MinW;
|
|
|
|
ScalarType W1=(Norm1/(maxN-minN))*IntervW+MinW;
|
2017-01-23 16:20:22 +01:00
|
|
|
GLDrawField(dir,center,size,W0,W1,Col0,Col1,oneside,onlyPD1);
|
|
|
|
}
|
2012-05-25 15:22:07 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-04-12 08:08:20 +02:00
|
|
|
static void GLDrawVertField(const VertexType &v,
|
|
|
|
ScalarType &size)
|
|
|
|
{
|
|
|
|
CoordType center=v.cP();
|
|
|
|
CoordType normal=v.cN();
|
|
|
|
CoordType dir[4];
|
|
|
|
vcg::tri::CrossField<MeshType>::CrossVector(v,dir);
|
2017-01-23 16:20:22 +01:00
|
|
|
GLDrawField(dir,center,size,2,2,vcg::Color4b(0,0,0,255),vcg::Color4b(0,0,0,255),false,false);
|
2015-04-12 08:08:20 +02:00
|
|
|
}
|
2012-03-16 14:50:45 +01:00
|
|
|
|
2012-05-25 15:22:07 +02:00
|
|
|
|
2014-04-07 08:29:56 +02:00
|
|
|
static void GLDrawFaceField(const MeshType &mesh,
|
2017-01-23 16:20:22 +01:00
|
|
|
bool onlyPD1,
|
|
|
|
bool oneside,
|
|
|
|
ScalarType GlobalScale=0.002,
|
2017-12-18 14:57:20 +01:00
|
|
|
const ScalarType maxN=0,
|
|
|
|
const ScalarType minN=0)
|
2012-03-16 14:50:45 +01:00
|
|
|
{
|
2014-02-16 17:37:39 +01:00
|
|
|
|
2012-03-16 14:50:45 +01:00
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
2014-11-05 20:26:54 +01:00
|
|
|
glDepthRange(0.0,0.999);
|
2012-03-16 14:50:45 +01:00
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
2014-02-16 17:37:39 +01:00
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_BLEND);
|
2017-01-23 16:20:22 +01:00
|
|
|
ScalarType size=mesh.bbox.Diag()*GlobalScale;
|
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
|
|
|
{
|
2014-11-05 20:26:54 +01:00
|
|
|
if (mesh.face[i].IsD())continue;
|
2017-12-18 14:57:20 +01:00
|
|
|
GLDrawSingleFaceField(mesh.face[i],size,oneside,onlyPD1,maxN,minN);
|
2012-05-25 15:22:07 +02:00
|
|
|
}
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
|
|
|
|
2015-04-12 08:08:20 +02:00
|
|
|
static void GLDrawVertField(const MeshType &mesh,ScalarType sizeF=0.01)
|
2012-05-25 15:22:07 +02:00
|
|
|
{
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
2014-02-16 17:37:39 +01:00
|
|
|
glDepthRange(0.0,0.9999);
|
2012-05-25 15:22:07 +02:00
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
glDisable(GL_LIGHTING);
|
2014-02-16 17:37:39 +01:00
|
|
|
glDisable(GL_BLEND);
|
2015-04-12 08:08:20 +02:00
|
|
|
ScalarType size=mesh.bbox.Diag()*sizeF;
|
2012-09-03 17:58:38 +02:00
|
|
|
for (int i=0;i<mesh.vert.size();i++)
|
2012-03-16 14:50:45 +01:00
|
|
|
{
|
2014-11-05 20:26:54 +01:00
|
|
|
if (mesh.vert[i].IsD())continue;
|
2015-04-12 08:08:20 +02:00
|
|
|
GLDrawVertField(mesh.vert[i],size);
|
2012-03-16 14:50:45 +01:00
|
|
|
}
|
|
|
|
glPopAttrib();
|
|
|
|
}
|
2014-11-05 20:26:54 +01:00
|
|
|
|
|
|
|
static void GLDrawSingularity(MeshType &mesh)
|
|
|
|
{
|
|
|
|
// query if an attribute is present or not
|
|
|
|
bool hasSingular = vcg::tri::HasPerVertexAttribute(mesh,std::string("Singular"));
|
|
|
|
bool hasSingularIndex = vcg::tri::HasPerVertexAttribute(mesh,std::string("SingularIndex"));
|
|
|
|
|
|
|
|
if (!hasSingular)return;
|
|
|
|
if(!hasSingularIndex)return;
|
|
|
|
|
|
|
|
typename MeshType::template PerVertexAttributeHandle<bool> Handle_Singular;
|
|
|
|
Handle_Singular=vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<bool>(mesh,std::string("Singular"));
|
|
|
|
typename MeshType::template PerVertexAttributeHandle<int> Handle_SingularIndex;
|
|
|
|
Handle_SingularIndex =vcg::tri::Allocator<MeshType>::template GetPerVertexAttribute<int>(mesh,std::string("SingularIndex"));
|
|
|
|
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
|
2015-09-14 14:05:03 +02:00
|
|
|
glDepthRange(0.0,0.9999);
|
2014-11-05 20:26:54 +01:00
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_BLEND);
|
2016-06-09 14:11:54 +02:00
|
|
|
glPointSize(20);
|
2014-11-05 20:26:54 +01:00
|
|
|
glBegin(GL_POINTS);
|
|
|
|
for (size_t i=0;i<mesh.vert.size();i++)
|
|
|
|
{
|
|
|
|
if (mesh.vert[i].IsD())continue;
|
|
|
|
if (!Handle_Singular[i])continue;
|
|
|
|
|
|
|
|
|
|
|
|
int SingIndex=Handle_SingularIndex[i];
|
|
|
|
|
|
|
|
vcg::Color4b colSing;
|
|
|
|
|
|
|
|
switch (SingIndex)
|
|
|
|
{
|
|
|
|
case 1:colSing=vcg::Color4b(0,0,255,255); break;
|
|
|
|
case 2:colSing=vcg::Color4b(0,255,0,255); break;
|
|
|
|
case 3:colSing=vcg::Color4b(255,0,0,255); break;
|
|
|
|
case 4:colSing=vcg::Color4b(255,255,0,255); break;
|
|
|
|
default:colSing=vcg::Color4b(255,0,255,255);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vcg::glColor(colSing);
|
|
|
|
vcg::glVertex(mesh.vert[i].P());
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
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
|