From b6872481f80ec1b6bb814990b92d22695539700e Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Mon, 7 Nov 2011 14:28:46 +0100 Subject: [PATCH] ajout rendu bord (ALGO::RENDER::GL2::BOUNDARY) test dans tuto1 functor SelectorEdgeNoBoundary/SelectorEdgeBoundary --- Apps/Tuto/tuto1.cpp | 10 ++++- include/Algo/Render/GL2/mapRender.h | 11 ++++- include/Algo/Render/GL2/mapRender.hpp | 57 ++++++++++++++++-------- include/Topology/generic/functor.h | 30 +++++++++++-- include/Topology/generic/traversorCell.h | 2 +- src/Algo/Render/mapRender.cpp | 13 +++++- src/Topology/map/map2.cpp | 1 - 7 files changed, 95 insertions(+), 29 deletions(-) diff --git a/Apps/Tuto/tuto1.cpp b/Apps/Tuto/tuto1.cpp index 36d6a3640..327cd9b5b 100644 --- a/Apps/Tuto/tuto1.cpp +++ b/Apps/Tuto/tuto1.cpp @@ -88,6 +88,11 @@ void MyQT::cb_redraw() m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); m_render->draw(m_shader, Algo::Render::GL2::LINES); + m_shader->setColor(Geom::Vec4f(0.,1.,1.,0.)); + m_render->draw(m_shader, Algo::Render::GL2::BOUNDARY); + + + glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 1.0f); @@ -169,9 +174,10 @@ int main(int argc, char **argv) // update des primitives du renderer SelectorTrue allDarts; -// SelectorNoBoundary allDarts(myMap); + SelectorEdgeNoBoundary insideEdges(myMap);// just to draw only inside edges sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + sqt.m_render->initPrimitives(myMap, insideEdges, Algo::Render::GL2::LINES); + sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::BOUNDARY); // special primitive for boundary edges // show final pour premier redraw sqt.show(); diff --git a/include/Algo/Render/GL2/mapRender.h b/include/Algo/Render/GL2/mapRender.h index 1b86419a7..663d53a32 100644 --- a/include/Algo/Render/GL2/mapRender.h +++ b/include/Algo/Render/GL2/mapRender.h @@ -61,7 +61,8 @@ enum drawingType POINTS = 4, EXPLODED = 8, FLAT_TRIANGLES = 16, - ERR = 32 + BOUNDARY = 32, + ERR = 64 } ; enum bufferIndex @@ -70,6 +71,7 @@ enum bufferIndex LINE_INDICES = 1, TRIANGLE_INDICES = 2, FLAT_BUFFER = 3, + BOUNDARY_INDICES = 4, SIZE_BUFFER } ; @@ -204,6 +206,11 @@ public: template void initPoints(typename PFP::MAP& map, const FunctorSelect& good,std::vector& tableIndices, unsigned int thread=0) ; + + + template + void initBoundaries(typename PFP::MAP& map, const FunctorSelect& good,std::vector& tableIndices, unsigned int thread=0) ; + /** * initialization of the VBO indices primitives * computed by a traversal of the map @@ -212,6 +219,8 @@ public: template void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized = true, unsigned int thread = 0) ; + + /** * initialization of the VBO indices primitives * using the given table diff --git a/include/Algo/Render/GL2/mapRender.hpp b/include/Algo/Render/GL2/mapRender.hpp index 3bceeb647..5b957a775 100644 --- a/include/Algo/Render/GL2/mapRender.hpp +++ b/include/Algo/Render/GL2/mapRender.hpp @@ -323,18 +323,6 @@ template void MapRender::initTriangles(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) { // DartMarker m(map, thread); -// tableIndices.reserve(4 * map.getNbDarts() / 3); -// -// for(Dart dd = map.begin(); dd != map.end(); map.next(dd)) -// { -// if(!m.isMarked(dd) && good(dd)) -// { -// addTri(map, dd, tableIndices); -// m.markOrbit(FACE, dd); -// } -// } - - DartMarker m(map, thread); tableIndices.reserve(4 * map.getNbDarts() / 3); TraversorF trav(map); @@ -361,7 +349,7 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele { std::list bound; - if (good(dd)) + if (good(dd) && !map.isBoundaryMarked(dd)) addTri(map, dd, tableIndices); m.markOrbit(FACE, dd); bound.push_back(dd); @@ -377,7 +365,7 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele { if (!m.isMarked(f)) { - if(good(f)) + if (good(f) && !map.isBoundaryMarked(dd)) addTri(map, f, tableIndices); m.markOrbit(FACE, f); bound.push_back(map.phi1(f)); @@ -404,16 +392,42 @@ void MapRender::initTrianglesOptimized(typename PFP::MAP& map, const FunctorSele template void MapRender::initLines(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) { - DartMarker m(map, thread); +// DartMarker m(map, thread); tableIndices.reserve(map.getNbDarts()); - for(Dart d = map.begin(); d != map.end(); map.next(d)) +// for(Dart d = map.begin(); d != map.end(); map.next(d)) +// { +// if(!m.isMarked(d) && good(d)) +// { +// tableIndices.push_back(map.getEmbedding(VERTEX, d)); +// tableIndices.push_back(map.getEmbedding(VERTEX, map.phi1(d))); +// m.markOrbit(EDGE, d); +// } +// } + + TraversorE trav(map); + for (Dart d = trav.begin(); d!= trav.end(); d = trav.next()) { - if(!m.isMarked(d) && good(d)) + if (good(d) && map.isBoundaryEdge(d)) + { + tableIndices.push_back(map.getEmbedding(VERTEX, d)); + tableIndices.push_back(map.getEmbedding(VERTEX, map.phi1(d))); + } + } +} + +template +void MapRender::initBoundaries(typename PFP::MAP& map, const FunctorSelect& good, std::vector& tableIndices, unsigned int thread) +{ + TraversorE trav(map); + tableIndices.reserve(map.getNbDarts()); //TODO optimisation ? + + for (Dart d = trav.begin(); d!= trav.end(); d = trav.next()) + { + if (good(d) && map.isBoundaryEdge(d)) { tableIndices.push_back(map.getEmbedding(VERTEX, d)); - tableIndices.push_back(map.getEmbedding(VERTEX, map.phi2(d))); - m.markOrbit(EDGE, d); + tableIndices.push_back(map.getEmbedding(VERTEX, map.phi1(d))); } } } @@ -518,6 +532,11 @@ void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good break; case FLAT_TRIANGLES: break; + case BOUNDARY: + initBoundaries(map, good, tableIndices, thread) ; + m_nbIndices[BOUNDARY_INDICES] = tableIndices.size(); + vbo_ind = m_indexBuffers[BOUNDARY_INDICES]; + break; default: CGoGNerr << "problem initializing VBO indices" << CGoGNendl; break; diff --git a/include/Topology/generic/functor.h b/include/Topology/generic/functor.h index 2419209f4..74170429a 100644 --- a/include/Topology/generic/functor.h +++ b/include/Topology/generic/functor.h @@ -77,17 +77,41 @@ public: }; +//template +//class SelectorNoBoundary : public FunctorSelect +//{ +//public: +//protected: +// MAP& m_map; +//public: +// SelectorNoBoundary(MAP& m): m_map(m) {} +// bool operator()(Dart d) const { return !m_map.isBoundaryMarked(d); } +//}; + template -class SelectorNoBoundary : public FunctorSelect +class SelectorEdgeBoundary : public FunctorSelect { public: protected: MAP& m_map; public: - SelectorNoBoundary(MAP& m): m_map(m) {} - bool operator()(Dart d) const { return !m_map.isBoundaryMarked(d); } + SelectorEdgeBoundary(MAP& m): m_map(m) {} + bool operator()(Dart d) const { return m_map.isBoundaryEdge(d); } }; + +template +class SelectorEdgeNoBoundary : public FunctorSelect +{ +public: +protected: + MAP& m_map; +public: + SelectorEdgeNoBoundary(MAP& m): m_map(m) {} + bool operator()(Dart d) const { return !m_map.isBoundaryEdge(d); } +}; + + // Counting Functors : increment its value every time it is applied /********************************************************/ diff --git a/include/Topology/generic/traversorCell.h b/include/Topology/generic/traversorCell.h index 11076596b..744842636 100644 --- a/include/Topology/generic/traversorCell.h +++ b/include/Topology/generic/traversorCell.h @@ -45,7 +45,7 @@ public: Dart begin() { - mark.unmarkAll() ; + mark.unmarkAll() ; // TODO ajouter test pour ne pas toujours faire le unmark !! current = m.begin() ; while(m.isBoundaryMarked(current)) m.next(current) ; diff --git a/src/Algo/Render/mapRender.cpp b/src/Algo/Render/mapRender.cpp index a6418fdad..d62d97896 100644 --- a/src/Algo/Render/mapRender.cpp +++ b/src/Algo/Render/mapRender.cpp @@ -40,8 +40,8 @@ namespace GL2 MapRender::MapRender() { - glGenBuffersARB(4, m_indexBuffers) ; - for(unsigned int i = 0; i < 4; ++i) + glGenBuffersARB(SIZE_BUFFER, m_indexBuffers) ; + for(unsigned int i = 0; i < SIZE_BUFFER; ++i) m_nbIndices[i] = 0 ; } @@ -68,6 +68,10 @@ void MapRender::initPrimitives(int prim, std::vector& tableIndices) m_nbIndices[TRIANGLE_INDICES] = tableIndices.size(); vbo_ind = m_indexBuffers[TRIANGLE_INDICES]; break; + case BOUNDARY: + m_nbIndices[BOUNDARY_INDICES] = tableIndices.size(); + vbo_ind = m_indexBuffers[BOUNDARY_INDICES]; + break; default: CGoGNerr << "problem initializing VBO indices" << CGoGNendl; break; @@ -97,6 +101,11 @@ void MapRender::draw(Utils::GLSLShader* sh, int prim) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[TRIANGLE_INDICES]); glDrawElements(GL_TRIANGLES, m_nbIndices[TRIANGLE_INDICES], GL_UNSIGNED_INT, 0); break; + case BOUNDARY: + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[BOUNDARY_INDICES]); + glDrawElements(GL_LINES, m_nbIndices[BOUNDARY_INDICES], GL_UNSIGNED_INT, 0); + break; + default: break; } diff --git a/src/Topology/map/map2.cpp b/src/Topology/map/map2.cpp index bd3e7a338..1c220959e 100644 --- a/src/Topology/map/map2.cpp +++ b/src/Topology/map/map2.cpp @@ -120,7 +120,6 @@ void Map2::deleteOrientedFace(Dart d) Dart Map2::newFace(unsigned int nbEdges) { - std::cout << "OUCHHH"<< std::endl; Dart d = Map1::newFace(nbEdges); Dart e = Map1::newBoundaryFace(nbEdges); -- GitLab