diff --git a/Apps/Examples/mcmesh.cpp b/Apps/Examples/mcmesh.cpp index 1a4555d6bcd6406fd2c620a1183964f3f0421508..862c5e56a01fa15758f4c7081724b9ad09f3736f 100644 --- a/Apps/Examples/mcmesh.cpp +++ b/Apps/Examples/mcmesh.cpp @@ -154,7 +154,7 @@ void MCMesh::MC() void MCMesh::updateRender() { - SelectorDartNoBoundary nb(myMap); +// SelectorDartNoBoundary nb(myMap); //TODO add Browser for no border m_render->initPrimitives(myMap, Algo::Render::GL2::LINES); m_render->initPrimitives(myMap, Algo::Render::GL2::TRIANGLES); diff --git a/Apps/Tuto/show_traversors.cpp b/Apps/Tuto/show_traversors.cpp index 8af5b3b14922b309a736d3dda4e65aaf3b9fc895..c6c872f87a1468dc5ab2d823a522c7e28cc85268 100644 --- a/Apps/Tuto/show_traversors.cpp +++ b/Apps/Tuto/show_traversors.cpp @@ -118,7 +118,6 @@ void MyQT::cb_initGL() m_render_topo = new Algo::Render::GL2::Topo3Render(); -// SelectorDartNoBoundary nb(myMap); m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); m_dm_topo = new DartMarker(myMap); } @@ -145,7 +144,6 @@ void MyQT::cb_mousePress(int button, int x, int y) { if (Shift()) { -// SelectorDartNoBoundary nb(myMap); Dart d = m_render_topo->picking(myMap, x, y); if (d != Dart::nil()) { @@ -199,7 +197,6 @@ void MyQT::traverse2() return; m_last=2; // int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2; - SelectorDartNoBoundary nb(myMap); m_drawer.newList(GL_COMPILE); m_drawer.lineWidth(7.0f); @@ -266,8 +263,6 @@ void MyQT::traverse3() m_last=3; - SelectorDartNoBoundary nb(myMap); - m_affDarts.clear(); m_drawer.newList(GL_COMPILE); diff --git a/Apps/Tuto/tuto1.cpp b/Apps/Tuto/tuto1.cpp index a02d3ba46d09a17bf1ffdc317d0a77128321c0f3..747be0a6f212b20a30c4be9ad70f88aa21389d00 100644 --- a/Apps/Tuto/tuto1.cpp +++ b/Apps/Tuto/tuto1.cpp @@ -77,7 +77,8 @@ void MyQT::createMap() show(); // render the topo of the map without boundary darts - m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true ); + m_render_topo->setInitialBoundaryDartsColor(0,1,0); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); } // initialization GL callback diff --git a/Apps/Tuto/tuto_oper2.cpp b/Apps/Tuto/tuto_oper2.cpp index 0f82fc179146d13b2c6a792b2eb5ac1d45bde5af..f6aa8fab9e75e44d1f7f656d9ad7ab4c8fe56b0a 100644 --- a/Apps/Tuto/tuto_oper2.cpp +++ b/Apps/Tuto/tuto_oper2.cpp @@ -191,9 +191,10 @@ void MyQT::createMap(int n) dm.markAll(); - m_render_topo->setDartWidth(5.0f); + m_render_topo->setDartWidth(4.0f); m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f); // nb + m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); // nb for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) { @@ -211,7 +212,8 @@ void MyQT::createMap(int n) void MyQT::updateMap() { - m_render_topo->updateData(myMap, position, 0.9f, 0.9f); // nb + m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); // nb for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) { if (dm.isMarked(d) && (!myMap.isBoundaryMarked2(d))) @@ -227,7 +229,7 @@ void MyQT::updateMap() void MyQT::cb_initGL() { glClearColor(1.0f,1.0f,1.0f,1.0f); - m_render_topo = new Algo::Render::GL2::TopoRender() ; + m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ; } // redraw GL callback (clear and swap already done) diff --git a/Apps/Tuto/tuto_oper2.h b/Apps/Tuto/tuto_oper2.h index 9f37b4dc74c2516ebc65c79f4ade6cfa115779dd..586a10e210d3d4a0366e3f8c50ea341e6d7da1d4 100644 --- a/Apps/Tuto/tuto_oper2.h +++ b/Apps/Tuto/tuto_oper2.h @@ -69,7 +69,7 @@ class MyQT: public Utils::QT::SimpleQT { Q_OBJECT public: - MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f) {} + MyQT():m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap),m_shift(0.01f) {} void cb_redraw(); void cb_initGL(); @@ -87,8 +87,6 @@ protected: VertexAttribute position; DartAttribute colorDarts; - SelectorDartNoBoundary nb; - // render (for the topo) Algo::Render::GL2::TopoRender* m_render_topo; Dart m_selected; diff --git a/Apps/Tuto/tuto_orbits.cpp b/Apps/Tuto/tuto_orbits.cpp index 826ec39e47e50260314ef4e47255827825949bec..c829b7decf1d3511651dea36771af76088074b73 100644 --- a/Apps/Tuto/tuto_orbits.cpp +++ b/Apps/Tuto/tuto_orbits.cpp @@ -142,8 +142,7 @@ void MyQT::cb_initGL() Utils::GLSLShader::setCurrentOGLVersion(2); m_render_topo = new Algo::Render::GL2::Topo3Render(); - SelectorDartNoBoundary nb(myMap); - m_render_topo->updateData(myMap, position, 0.9f, 0.8f, 0.8f/*, nb*/); + m_render_topo->updateData(myMap, position, 0.9f, 0.8f, 0.8f); m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f)); registerShader(m_strings); @@ -167,8 +166,7 @@ void MyQT::cb_mousePress(int button, int x, int y) { if (Shift()) { - SelectorDartNoBoundary nb(myMap); - m_clicked = m_render_topo->picking(myMap, x,y/*, nb*/); + m_clicked = m_render_topo->picking(myMap, x,y); if (m_clicked != Dart::nil()) { unsigned int orbs[9] = {VERTEX,EDGE,FACE,VOLUME,PFP::MAP::VERTEX_OF_PARENT,PFP::MAP::EDGE_OF_PARENT,PFP::MAP::FACE_OF_PARENT,PFP::MAP::VERTEX_OF_PARENT2,PFP::MAP::EDGE_OF_PARENT2}; diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index bc7e349d419fee7edfa03f2fa8a507327f5fe11e..c921f67cff6efd5d3dd6f3dc53e9f9c7a474795f 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -75,6 +75,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute< m_nbDarts = 0; for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) { + if (!mapx.isBoundaryMarked3(d)) // in the following code Traversor do not traverse boundary m_nbDarts++; } @@ -237,25 +238,27 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map) for (Dart d = map.begin(); d != map.end(); map.next(d)) { - if (nb < m_nbDarts) + if ( !map.isBoundaryMarked3(d)) // topo3 Render do not traverse boundary { - float r,g,b; - dartToCol(d, r,g,b); - - float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO - *local++ = r; - *local++ = g; - *local++ = b; - *local++ = r; - *local++ = g; - *local++ = b; - - nb++; - } - else - { - CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl; - break; + if (nb < m_nbDarts) + { + float r,g,b; + dartToCol(d, r,g,b); + + float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO + *local++ = r; + *local++ = g; + *local++ = b; + *local++ = r; + *local++ = g; + *local++ = b; + nb++; + } + else + { + CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl; + break; + } } } glUnmapBuffer(GL_ARRAY_BUFFER); @@ -270,15 +273,18 @@ void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute - void setDartsIdColor(typename PFP::MAP& map); + void setDartsIdColor(typename PFP::MAP& map, bool withBoundary); /** * save colors before picking @@ -146,8 +156,7 @@ public: /** * Constructor */ - - TopoRender(); + TopoRender(float bs = 0.01f); /** * Destructor @@ -185,6 +194,7 @@ public: * draw all topo */ void drawTopo(); + /** * change dart drawing color * @param d the dart @@ -205,6 +215,8 @@ public: void setInitialDartsColor(float r, float g, float b); + void setInitialBoundaryDartsColor(float r, float g, float b); + /** * redraw one dart with specific width and color (not efficient use only for debug with small amount of call) * @param d the dart @@ -225,7 +237,7 @@ public: * @return the dart or NIL */ template - Dart picking(typename PFP::MAP& map, int x, int y); + Dart picking(typename PFP::MAP& map, int x, int y, bool withBoundary=false); template @@ -245,6 +257,13 @@ public: template void updateDataGMap(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); + /** + * Special update function used to draw boundary of map3 + */ + template + void updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf,float ns); + + /** * render to svg struct */ @@ -254,6 +273,18 @@ public: * render svg into svg file */ void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); + + /** + * @brief set normal shift for boundary of dim 3 drawing + * @param ns distance shift along normals (use BB.diagSize()/100 is good approximation) + */ + void setNormalShift(float ns); + + /** + * @brief set boundary shift for boundary of dim 2 drawing + * @param ns distance shift + */ + void setBoundaryShift(float bs); }; // just for compatibility with old code diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index 842971e5a95d4fbff9229766333e5dbd671ce599..99b1ffc55c7185809135788b7bb3512416616be6 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -30,9 +30,12 @@ #include "Topology/map/embeddedMap2.h" #include "Topology/gmap/embeddedGMap2.h" +#include "Algo/Geometry/basic.h" #include "Geometry/distances.h" #include "Algo/Geometry/centroid.h" +#include "Algo/Geometry/normal.h" +#include "Topology/generic/mapBrowser.h" namespace CGoGN { @@ -46,6 +49,22 @@ namespace Render namespace GL2 { + +template +void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf,float ns) +{ + m_normalShift = ns; + SelectorDartBoundary sdb(map); + MapBrowserSelector mbs(map,sdb); + map.setBrowser(&mbs); + + updateData(map,positions, ke, kf,true); + + map.setBrowser(NULL); + m_normalShift = 0.0f; +} + + template void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary) { @@ -83,6 +102,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute(mapx,d,positions); - - float k = 1.0f - kf; - Dart dd = d; - do + if (!map.isBoundaryMarked2(d)) { - vecPos.push_back(center*k + positions[dd]*kf); - dd = map.phi1(dd); - } while (dd != d); - - unsigned int nb = vecPos.size(); - vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop - - - k = 1.0f - ke; - for (unsigned int i = 0; i < nb; ++i) + VEC3 center = Algo::Surface::Geometry::faceCentroidELW(mapx,d,positions); + float k = 1.0f - kf; + Dart dd = d; + do + { + vecPos.push_back(center*k + positions[dd]*kf); + dd = map.phi1(dd); + } while (dd != d); + + + if (m_normalShift > 0.0f) + { + VEC3 normal = Algo::Surface::Geometry::newellNormal(mapx,d,positions); + for (typename std::vector::iterator pit = vecPos.begin(); pit != vecPos.end(); ++pit) + { + *pit -= normal*m_normalShift; + } + } + + unsigned int nb = vecPos.size(); + vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop + + k = 1.0f - ke; + for (unsigned int i = 0; i < nb; ++i) + { + + VEC3 P = vecPos[i]*ke + vecPos[i+1]*k; + VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k; + + m_attIndex[d] = indexDC; + indexDC+=2; + *positionDartBuf++ = P; + *positionDartBuf++ = Q; + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; + VEC3 f = P*0.5f + Q*0.5f; + fv2[d] = f; + f = P*0.1f + Q*0.9f; + fv1[d] = f; + f = P*0.9f + Q*0.1f; + fv11[d] = f; + d = map.phi1(d); + } + mf.markOrbit(d); + } + else if (withBoundary) { - VEC3 P = vecPos[i]*ke + vecPos[i+1]*k; - VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k; - m_attIndex[d] = indexDC; - indexDC+=2; - *positionDartBuf++ = P; - *positionDartBuf++ = Q; - *colorDartBuf++ = m_dartsColor; - *colorDartBuf++ = m_dartsColor; - VEC3 f = P*0.5f + Q*0.5f; - fv2[d] = f; - f = P*0.1f + Q*0.9f; - fv1[d] = f; - f = P*0.9f + Q*0.1f; - fv11[d] = f; - d = map.phi1(d); + Dart dd = d; + do + { + Dart ee = mapx.phi2(dd); + VEC3 normal = Algo::Surface::Geometry::newellNormal(mapx,ee,positions); + VEC3 vd = Algo::Surface::Geometry::vectorOutOfDart(mapx,ee,positions); + VEC3 v = vd ^ normal; + v.normalize(); + VEC3 P = positions[map.phi1(ee)] + v* m_boundShift; + vecPos.push_back(P); + dd = map.phi1(dd); + ee = mapx.phi2(dd); + P = positions[map.phi1(ee)] + v* m_boundShift; + vecPos.push_back(P); + } while (dd != d); + + unsigned int nb = vecPos.size()/2; + float k = 1.0f - ke; + for (unsigned int i = 0; i < nb; ++i) + { + + VEC3 P = vecPos[2*i]*ke + vecPos[2*i+1]*k; + VEC3 Q = vecPos[2*i+1]*ke + vecPos[2*i]*k; + + m_attIndex[d] = indexDC; + indexDC+=2; + *positionDartBuf++ = P; + *positionDartBuf++ = Q; + *colorDartBuf++ = m_dartsBoundaryColor; + *colorDartBuf++ = m_dartsBoundaryColor; + VEC3 f = P*0.5f + Q*0.5f; + fv2[d] = f; + f = P*0.1f + Q*0.9f; + fv1[d] = f; + f = P*0.9f + Q*0.1f; + fv11[d] = f; + d = map.phi1(d); + } + mf.markOrbit(d); } - mf.markOrbit(d); } } @@ -184,7 +259,7 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute d.index)) - if ( (withBoundary || !map.isBoundaryMarked2(e)) && (d < e )) + if ( (withBoundary || !map.isBoundaryMarked2(e)) && (e.index > d.index)) { *positionF2++ = fv2[d]; *positionF2++ = fv2[e]; @@ -269,9 +344,19 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute 0.0f) + { + VEC3 normal = Algo::Surface::Geometry::newellNormal(mapx,d,positions); + for (typename std::vector::iterator pit = vecPos.begin(); pit != vecPos.end(); ++pit) + { + *pit -= normal*m_normalShift; + } + } unsigned int nb = vecPos.size(); vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop + k = 1.0f - ke; for (unsigned int i = 0; i < nb; ++i) { @@ -355,7 +440,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute -void TopoRender::setDartsIdColor(typename PFP::MAP& map) +void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary) { m_vbo3->bind(); float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); @@ -370,33 +455,38 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map) for (Dart d = map.begin(); d != map.end(); map.next(d)) { - if (nb < m_nbDarts) - { - float r,g,b; - dartToCol(d, r,g,b); - float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO - *local++ = r; - *local++ = g; - *local++ = b; - *local++ = r; - *local++ = g; - *local++ = b; - nb++; - } - else + if (withBoundary || !map.isBoundaryMarked2(d)) { - CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl; - break; + + if (nb < m_nbDarts) + { + float r,g,b; + dartToCol(d, r,g,b); + float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO + *local++ = r; + *local++ = g; + *local++ = b; + *local++ = r; + *local++ = g; + *local++ = b; + nb++; + } + else + { + CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl; + CGoGNerr << "NB = " << nb << " NBDARTs = "<< m_nbDarts< -Dart TopoRender::picking(typename PFP::MAP& map,int x, int y) +Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, bool withBoundary) { pushColors(); - setDartsIdColor(map); + setDartsIdColor(map,withBoundary); Dart d = pickColor(x,y); popColors(); return d; diff --git a/include/Topology/generic/mapBrowser.hpp b/include/Topology/generic/mapBrowser.hpp index c8ed6d8476c94852b7be4b2ebc8242003a76b13c..88ea5860740e2b1a234ab94f304549dc445edd7b 100644 --- a/include/Topology/generic/mapBrowser.hpp +++ b/include/Topology/generic/mapBrowser.hpp @@ -32,7 +32,11 @@ inline MapBrowserSelector::MapBrowserSelector(AttribMap& m, const FunctorSelect& inline Dart MapBrowserSelector::begin() const { - return m_map.realBegin() ; + Dart d = m_map.realBegin() ; + while ( (d != m_map.realEnd()) && !m_selector(d) ) + m_map.realNext(d); + + return d; } inline Dart MapBrowserSelector::end() const diff --git a/src/Algo/Render/topoRender.cpp b/src/Algo/Render/topoRender.cpp index a4b5b008a7a1ee25f4e1fec38ab8111ea256fe90..126e184bf54c88a8b99dc8683e838cd0a32794f0 100644 --- a/src/Algo/Render/topoRender.cpp +++ b/src/Algo/Render/topoRender.cpp @@ -38,12 +38,15 @@ namespace Render namespace GL2 { -TopoRender::TopoRender(): +TopoRender::TopoRender(float bs): m_nbDarts(0), m_nbRel2(0), m_topo_dart_width(2.0f), m_topo_relation_width(3.0f), + m_normalShift(0.0f), + m_boundShift(bs), m_dartsColor(1.0f,1.0f,1.0f), + m_dartsBoundaryColor(0.7f,1.0f,0.7f), m_bufferDartPosition(NULL) { m_vbo0 = new Utils::VBO(); @@ -129,6 +132,12 @@ void TopoRender::setInitialDartsColor(float r, float g, float b) m_dartsColor = Geom::Vec3f(r,g,b); } + +void TopoRender::setInitialBoundaryDartsColor(float r, float g, float b) +{ + m_dartsBoundaryColor = Geom::Vec3f(r,g,b); +} + void TopoRender::drawDarts() { if (m_nbDarts==0) @@ -336,6 +345,17 @@ void TopoRender::toSVG(Utils::SVG::SVGOut& svg) } +void TopoRender::setNormalShift(float ns) +{ + m_normalShift = ns; +} + +void TopoRender::setBoundaryShift(float bs) +{ + m_boundShift = bs; +} + + }//end namespace GL2