Commit 96797011 authored by Pierre Kraemer's avatar Pierre Kraemer

update mapRender : initPrimitives takes position for ear triangulation

parent a8743320
...@@ -438,10 +438,9 @@ int main(int argc, char **argv) ...@@ -438,10 +438,9 @@ int main(int argc, char **argv)
sqt.m_positionVBO->updateData(position); sqt.m_positionVBO->updateData(position);
// update des primitives du renderer // update des primitives du renderer
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES); sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES); sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES, &position);
sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS); sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS, &position);
// show final pour premier redraw // show final pour premier redraw
sqt.show(); sqt.show();
......
...@@ -78,7 +78,6 @@ enum bufferIndex ...@@ -78,7 +78,6 @@ enum bufferIndex
SIZE_BUFFER SIZE_BUFFER
} ; } ;
class MapRender class MapRender
{ {
...@@ -137,8 +136,6 @@ protected: ...@@ -137,8 +136,6 @@ protected:
}; };
public: public:
/** /**
* Constructor * Constructor
...@@ -159,7 +156,6 @@ public: ...@@ -159,7 +156,6 @@ public:
buffer_array get_nb_index_buffer() { return std::make_pair(m_nbIndices, SIZE_BUFFER); } buffer_array get_nb_index_buffer() { return std::make_pair(m_nbIndices, SIZE_BUFFER); }
protected: protected:
/** /**
* addition of indices table of one triangle * addition of indices table of one triangle
* @param d a dart of the triangle * @param d a dart of the triangle
...@@ -169,29 +165,28 @@ protected: ...@@ -169,29 +165,28 @@ protected:
void addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) ; void addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) ;
template<typename PFP> template<typename PFP>
inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices); inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position);
template<typename PFP> template<typename PFP>
float computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly); float computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly);
template<typename PFP> template<typename PFP>
bool computeEarIntersection(AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly); bool computeEarIntersection(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly);
template<typename PFP> template<typename PFP>
void recompute2Ears( AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex); void recompute2Ears(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex);
template<typename VEC3> template<typename VEC3>
bool inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc); bool inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc);
public:
/** /**
* creation of indices table of triangles (optimized order) * creation of indices table of triangles (optimized order)
* @param tableIndices the table where indices are stored * @param tableIndices the table where indices are stored
*/ */
template <typename PFP> template <typename PFP>
void initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ; void initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread = 0) ;
template <typename PFP> template <typename PFP>
void initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ; void initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread = 0) ;
/** /**
* creation of indices table of lines (optimized order) * creation of indices table of lines (optimized order)
...@@ -216,6 +211,7 @@ public: ...@@ -216,6 +211,7 @@ public:
template <typename PFP> template <typename PFP>
void initBoundaries(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ; void initBoundaries(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ;
public:
/** /**
* initialization of the VBO indices primitives * initialization of the VBO indices primitives
* computed by a traversal of the map * computed by a traversal of the map
...@@ -224,6 +220,9 @@ public: ...@@ -224,6 +220,9 @@ public:
template <typename PFP> template <typename PFP>
void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized = true, unsigned int thread = 0) ; void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized = true, unsigned int thread = 0) ;
template <typename PFP>
void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, const typename PFP::TVEC3* position, bool optimized = true, unsigned int thread = 0) ;
/** /**
* initialization of the VBO indices primitives * initialization of the VBO indices primitives
* using the given table * using the given table
......
...@@ -71,7 +71,7 @@ bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, c ...@@ -71,7 +71,7 @@ bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, c
} }
template<typename PFP> template<typename PFP>
void MapRender::recompute2Ears( AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex) void MapRender::recompute2Ears(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex)
{ {
VertexPoly* vprev = vp->prev; VertexPoly* vprev = vp->prev;
VertexPoly* vp2 = vp->next; VertexPoly* vp2 = vp->next;
...@@ -151,7 +151,7 @@ float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PF ...@@ -151,7 +151,7 @@ float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PF
} }
template<typename PFP> template<typename PFP>
bool MapRender::computeEarIntersection(AttributeHandler<typename PFP::VEC3>& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly) bool MapRender::computeEarIntersection(const typename PFP::TVEC3& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly)
{ {
VertexPoly* endV = vp->prev; VertexPoly* endV = vp->prev;
...@@ -175,20 +175,19 @@ bool MapRender::computeEarIntersection(AttributeHandler<typename PFP::VEC3>& pos ...@@ -175,20 +175,19 @@ bool MapRender::computeEarIntersection(AttributeHandler<typename PFP::VEC3>& pos
} }
template<typename PFP> template<typename PFP>
inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* pos)
{ {
bool(*fn_pt1)(VertexPoly*,VertexPoly*) = &(MapRender::cmpVP); bool(*fn_pt1)(VertexPoly*,VertexPoly*) = &(MapRender::cmpVP);
VPMS ears(fn_pt1); VPMS ears(fn_pt1);
const typename PFP::TVEC3& position = *pos ;
AttributeHandler<typename PFP::VEC3> position = map.template getAttribute<typename PFP::VEC3>(VERTEX,"position");
// compute normal to polygon // compute normal to polygon
typename PFP::VEC3 normalPoly = Algo::Geometry::newellNormal<PFP>(map, d, position); typename PFP::VEC3 normalPoly = Algo::Geometry::newellNormal<PFP>(map, d, position);
// first pass create polygon in chained list witht angle computation // first pass create polygon in chained list witht angle computation
VertexPoly* vpp=NULL; VertexPoly* vpp = NULL;
VertexPoly* prem=NULL; VertexPoly* prem = NULL;
unsigned int nbv = 0; unsigned int nbv = 0;
unsigned int nbe = 0; unsigned int nbe = 0;
Dart a = d; Dart a = d;
...@@ -196,27 +195,27 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu ...@@ -196,27 +195,27 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
Dart c = map.phi1(b); Dart c = map.phi1(b);
do do
{ {
typename PFP::VEC3 P1= position[map.getEmbedding(VERTEX,a)]; typename PFP::VEC3 P1 = position[map.getEmbedding(VERTEX, a)];
typename PFP::VEC3 P2= position[map.getEmbedding(VERTEX,b)]; typename PFP::VEC3 P2 = position[map.getEmbedding(VERTEX, b)];
typename PFP::VEC3 P3= position[map.getEmbedding(VERTEX,c)]; typename PFP::VEC3 P3 = position[map.getEmbedding(VERTEX, c)];
float val = computeEarAngle<PFP>(P1,P2,P3,normalPoly); float val = computeEarAngle<PFP>(P1, P2, P3, normalPoly);
VertexPoly* vp = new VertexPoly(map.getEmbedding(VERTEX,b),val,(P3-P1).norm2(),vpp); VertexPoly* vp = new VertexPoly(map.getEmbedding(VERTEX, b), val, (P3-P1).norm2(), vpp);
if (vp->value <5.0f) if (vp->value < 5.0f)
nbe++; nbe++;
if (vpp==NULL) if (vpp == NULL)
prem = vp; prem = vp;
vpp = vp; vpp = vp;
a = b; a = b;
b = c; b = c;
c = map.phi1(c); c = map.phi1(c);
nbv++; nbv++;
}while (a!=d); }while (a != d);
VertexPoly::close(prem,vpp); VertexPoly::close(prem, vpp);
bool convex = nbe==nbv; bool convex = nbe == nbv;
if (convex) if (convex)
{ {
// second pass with no test of intersections with polygons // second pass with no test of intersections with polygons
...@@ -234,7 +233,7 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu ...@@ -234,7 +233,7 @@ inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector<GLu
for (unsigned int i=0; i< nbv; ++i) for (unsigned int i=0; i< nbv; ++i)
{ {
if (vpp->value <5.0f) if (vpp->value <5.0f)
computeEarIntersection<PFP>(position,vpp,normalPoly); computeEarIntersection<PFP>(position, vpp, normalPoly);
vpp->ear = ears.insert(vpp); vpp->ear = ears.insert(vpp);
vpp = vpp->next; vpp = vpp->next;
} }
...@@ -286,40 +285,43 @@ inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint ...@@ -286,40 +285,43 @@ inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint
Dart b = map.phi1(a); Dart b = map.phi1(a);
Dart c = map.phi1(b); Dart c = map.phi1(b);
if (map.phi1(c) != a)
{
addEarTri<PFP>(map, d, tableIndices);
return;
}
tableIndices.push_back(map.getEmbedding(VERTEX, d));
tableIndices.push_back(map.getEmbedding(VERTEX, b));
tableIndices.push_back(map.getEmbedding(VERTEX, c));
// loop to cut a polygon in triangle on the fly (works only with convex faces) // loop to cut a polygon in triangle on the fly (works only with convex faces)
// do do
// { {
// tableIndices.push_back(map.getEmbedding(VERTEX, d)); tableIndices.push_back(map.getEmbedding(VERTEX, d));
// tableIndices.push_back(map.getEmbedding(VERTEX, b)); tableIndices.push_back(map.getEmbedding(VERTEX, b));
// tableIndices.push_back(map.getEmbedding(VERTEX, c)); tableIndices.push_back(map.getEmbedding(VERTEX, c));
// b = c; b = c;
// c = map.phi1(b); c = map.phi1(b);
// } while (c != d); } while (c != d);
} }
template<typename PFP> template<typename PFP>
void MapRender::initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread) void MapRender::initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread)
{ {
tableIndices.reserve(4 * map.getNbDarts() / 3); tableIndices.reserve(4 * map.getNbDarts() / 3);
TraversorF<typename PFP::MAP> trav(map, good, thread); TraversorF<typename PFP::MAP> trav(map, good, thread);
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
addTri<PFP>(map, d, tableIndices); if(position == NULL)
{
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
addTri<PFP>(map, d, tableIndices);
}
else
{
for (Dart d = trav.begin(); d != trav.end(); d = trav.next())
{
if(map.faceDegree(d) == 3)
addTri<PFP>(map, d, tableIndices);
else
addEarTri<PFP>(map, d, tableIndices, position);
}
}
} }
template<typename PFP> template<typename PFP>
void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread) void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, const typename PFP::TVEC3* position, unsigned int thread)
{ {
#define LIST_SIZE 20 #define LIST_SIZE 20
DartMarker m(map, thread); DartMarker m(map, thread);
...@@ -335,7 +337,17 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele ...@@ -335,7 +337,17 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele
std::list<Dart> bound; std::list<Dart> bound;
if (good(dd) && !map.isBoundaryMarked(dd)) if (good(dd) && !map.isBoundaryMarked(dd))
addTri<PFP>(map, dd, tableIndices); {
if(position == NULL)
addTri<PFP>(map, dd, tableIndices);
else
{
if(map.faceDegree(dd) == 3)
addTri<PFP>(map, dd, tableIndices);
else
addEarTri<PFP>(map, dd, tableIndices, position);
}
}
m.markOrbit(FACE, dd); m.markOrbit(FACE, dd);
bound.push_back(dd); bound.push_back(dd);
int nb = 1; int nb = 1;
...@@ -351,7 +363,17 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele ...@@ -351,7 +363,17 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele
if (!m.isMarked(f)) if (!m.isMarked(f))
{ {
if (good(f) && !map.isBoundaryMarked(f)) if (good(f) && !map.isBoundaryMarked(f))
addTri<PFP>(map, f, tableIndices); {
if(position == NULL)
addTri<PFP>(map, f, tableIndices);
else
{
if(map.faceDegree(f) == 3)
addTri<PFP>(map, f, tableIndices);
else
addEarTri<PFP>(map, f, tableIndices, position);
}
}
m.markOrbit(FACE, f); m.markOrbit(FACE, f);
bound.push_back(map.phi1(f)); bound.push_back(map.phi1(f));
++nb; ++nb;
...@@ -464,6 +486,12 @@ void MapRender::initPoints(typename PFP::MAP& map, const FunctorSelect& good, st ...@@ -464,6 +486,12 @@ void MapRender::initPoints(typename PFP::MAP& map, const FunctorSelect& good, st
template<typename PFP> template<typename PFP>
void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized, unsigned int thread) void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized, unsigned int thread)
{
initPrimitives<PFP>(map, good, prim, NULL, optimized, thread) ;
}
template <typename PFP>
void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, const typename PFP::TVEC3* position, bool optimized, unsigned int thread)
{ {
std::vector<GLuint> tableIndices; std::vector<GLuint> tableIndices;
...@@ -487,9 +515,9 @@ void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good ...@@ -487,9 +515,9 @@ void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good
break; break;
case TRIANGLES: case TRIANGLES:
if(optimized) if(optimized)
initTrianglesOptimized<PFP>(map, good, tableIndices, thread); initTrianglesOptimized<PFP>(map, good, tableIndices, position, thread);
else else
initTriangles<PFP>(map, good, tableIndices, thread) ; initTriangles<PFP>(map, good, tableIndices, position, thread) ;
m_nbIndices[TRIANGLE_INDICES] = tableIndices.size(); m_nbIndices[TRIANGLE_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[TRIANGLE_INDICES]; vbo_ind = m_indexBuffers[TRIANGLE_INDICES];
break; break;
......
...@@ -6,7 +6,7 @@ VARYING_FRAG float scalar; ...@@ -6,7 +6,7 @@ VARYING_FRAG float scalar;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
float s = scalar * 50.0; float s = scalar * 30.0;
if( s - floor(s) <= 0.01 ) if( s - floor(s) <= 0.01 )
gl_FragColor = vec4(0.0); gl_FragColor = vec4(0.0);
else else
......
...@@ -37,7 +37,6 @@ namespace Render ...@@ -37,7 +37,6 @@ namespace Render
namespace GL2 namespace GL2
{ {
MapRender::MapRender() MapRender::MapRender()
{ {
glGenBuffersARB(SIZE_BUFFER, m_indexBuffers) ; glGenBuffersARB(SIZE_BUFFER, m_indexBuffers) ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment