From 2e3d2fa259d83d58ec29771cf8b5b7409db56ede Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Wed, 15 Oct 2014 11:27:27 +0200 Subject: [PATCH] topoRender + schnappsTopoRender --- Apps/Examples/simpleMap3.cpp | 4 +- Apps/Examples/simpleMap3.h | 2 +- Apps/Examples/viewer.cpp | 15 +- Apps/Examples/viewer.h | 6 +- Apps/Examples/volumeExplorer.cpp | 4 +- Apps/SandBox/testPlaneCutting.cpp | 8 +- Apps/SandBox/testPlaneCutting.h | 2 +- Apps/SandBox/test_traversor2.cpp | 135 +--- Apps/SandBox/test_traversor2.h | 2 +- Apps/Tuto/Modelling/tuto_oper2.cpp | 103 +-- Apps/Tuto/Modelling/tuto_oper2.h | 3 +- Apps/Tuto/Modelling/tuto_oper3.cpp | 16 +- Apps/Tuto/Modelling/tuto_oper3.h | 5 +- Apps/Tuto/Traversals/show_traversors2.cpp | 17 +- Apps/Tuto/Traversals/show_traversors2.h | 4 +- Apps/Tuto/Traversals/show_traversors3.cpp | 2 + Apps/Tuto/tuto1.cpp | 4 +- Apps/Tuto/tuto1.h | 8 +- Apps/Tuto/tuto3.cpp | 12 +- Apps/Tuto/tuto3.h | 2 +- Apps/Tuto/tuto4.cpp | 6 +- Apps/Tuto/tuto4.h | 2 +- .../src/surface_deformation.cpp | 4 + .../src/surface_modelisation.cpp | 4 + .../surface_render/include/surface_render.h | 5 + .../surface_render/src/surface_render.cpp | 50 ++ .../src/surface_render_dockTab.cpp | 2 +- .../src/surface_renderScalar.cpp | 4 + .../forms/surface_renderTopo.ui | 128 +++- .../include/surface_renderTopo.h | 79 ++- .../include/surface_renderTopo_dockTab.h | 2 +- .../src/surface_renderTopo.cpp | 58 +- .../src/surface_renderTopo_dockTab.cpp | 65 +- .../src/surface_renderVector.cpp | 4 + .../src/surface_selection.cpp | 5 + SCHNApps/include/mapHandler.h | 27 + SCHNApps/include/mapHandler.hpp | 48 +- SCHNApps/include/view.h | 4 + SCHNApps/src/controlDock_mapTab.cpp | 29 + SCHNApps/src/mapHandler.cpp | 13 +- SCHNApps/src/schnapps.cpp | 34 + SCHNApps/src/view.cpp | 17 + include/Algo/Render/GL2/topoRender.h | 237 ++++--- include/Algo/Render/GL2/topoRender.hpp | 670 ++++++------------ include/Topology/gmap/gmap2.hpp | 2 +- include/Utils/GLSLShader.h | 1 + include/Utils/Shaders/shaderSimpleFlat.frag | 51 ++ include/Utils/Shaders/shaderSimpleFlat.h | 105 +++ include/Utils/Shaders/shaderSimpleFlat.vert | 26 + src/Algo/Render/topoGenRender.cpp | 395 +++++++++++ src/Utils/GLSLShader.cpp | 42 ++ src/Utils/Shaders/shaderSimpleFlat.cpp | 191 +++++ 52 files changed, 1760 insertions(+), 904 deletions(-) create mode 100644 include/Utils/Shaders/shaderSimpleFlat.frag create mode 100644 include/Utils/Shaders/shaderSimpleFlat.h create mode 100644 include/Utils/Shaders/shaderSimpleFlat.vert create mode 100644 src/Algo/Render/topoGenRender.cpp create mode 100644 src/Utils/Shaders/shaderSimpleFlat.cpp diff --git a/Apps/Examples/simpleMap3.cpp b/Apps/Examples/simpleMap3.cpp index bbdd6b0b1..b8306ff1f 100644 --- a/Apps/Examples/simpleMap3.cpp +++ b/Apps/Examples/simpleMap3.cpp @@ -110,10 +110,10 @@ void SimpleMap3::cb_initGL() m_render_topo->setInitialDartsColor(1.0f,1.0f,1.0f); m_render_topo->updateData(myMap, position, 0.9f,0.9f,0.8f); - m_render_topo_boundary = new Algo::Render::GL2::TopoRenderMap(); + m_render_topo_boundary = new Algo::Render::GL2::TopoRender(); m_render_topo_boundary->setDartWidth(2.0f); m_render_topo_boundary->setInitialDartsColor(0.4f,0.8f,0.4f); - m_render_topo_boundary->updateDataBoundary(myMap, position, 0.9f,0.9f,bb.maxSize()/50.0f); + m_render_topo_boundary->updateDataBoundary(myMap, position, 0.9f,0.9f,bb.maxSize()/50.0f); m_render_topo_primal = new Algo::Render::GL2::Topo3PrimalRender(); m_render_topo_primal->setDartWidth(2.0f); diff --git a/Apps/Examples/simpleMap3.h b/Apps/Examples/simpleMap3.h index f00ed2adc..a4b97b95c 100644 --- a/Apps/Examples/simpleMap3.h +++ b/Apps/Examples/simpleMap3.h @@ -58,7 +58,7 @@ public: VertexAttribute position ; Algo::Render::GL2::Topo3RenderMap* m_render_topo; - Algo::Render::GL2::TopoRenderMap* m_render_topo_boundary; + Algo::Render::GL2::TopoRender* m_render_topo_boundary; Algo::Render::GL2::Topo3PrimalRender* m_render_topo_primal; SimpleMap3() ; diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index 87cbf9782..a76de4a3e 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -83,7 +83,7 @@ void Viewer::cb_initGL() Utils::GLSLShader::areShadersSupported(); m_render = new Algo::Render::GL2::MapRender() ; - m_topoRender = new Algo::Render::GL2::TopoRenderMap() ; + m_topoRender = new Algo::Render::GL2::TopoRender() ; m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ; @@ -98,12 +98,12 @@ void Viewer::cb_initGL() m_phongShader->setSpecular(colSpec) ; m_phongShader->setShininess(shininess) ; - m_flatShader = new Utils::ShaderFlat() ; + m_flatShader = new Utils::ShaderSimpleFlat() ; m_flatShader->setAttributePosition(m_positionVBO) ; m_flatShader->setAmbiant(colClear) ; m_flatShader->setDiffuse(colDif) ; - m_flatShader->setDiffuseBack(Geom::Vec4f(0,0,0,0)) ; - m_flatShader->setExplode(faceShrinkage) ; +// m_flatShader->setDiffuseBack(Geom::Vec4f(0,0,0,0)) ; +// m_flatShader->setExplode(faceShrinkage) ; m_vectorShader = new Utils::ShaderVectorPerVertex() ; m_vectorShader->setAttributePosition(m_positionVBO) ; @@ -130,12 +130,14 @@ void Viewer::cb_redraw() { if(m_drawVertices) { + glDepthFunc(GL_LEQUAL); m_pointSprite->setSize(vertexScaleFactor) ; m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ; } if(m_drawEdges) { + glDepthFunc(GL_LEQUAL); glLineWidth(1.0f) ; m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ; } @@ -146,10 +148,10 @@ void Viewer::cb_redraw() glEnable(GL_LIGHTING) ; glEnable(GL_POLYGON_OFFSET_FILL) ; glPolygonOffset(1.0f, 1.0f) ; + glDepthFunc(GL_LESS); switch(m_renderStyle) { case FLAT : - m_flatShader->setExplode(faceShrinkage) ; m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ; break ; case PHONG : @@ -161,6 +163,7 @@ void Viewer::cb_redraw() if(m_drawTopo) { + glDepthFunc(GL_LEQUAL); m_topoRender->drawTopo() ; } @@ -543,7 +546,7 @@ void Viewer::importMesh(std::string& filename) m_render->initPrimitives(myMap, Algo::Render::GL2::LINES) ; m_render->initPrimitives(myMap, Algo::Render::GL2::TRIANGLES) ; - m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; + m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; bb = Algo::Geometry::computeBoundingBox(myMap, position) ; normalBaseSize = bb.diagSize() / 100.0f ; diff --git a/Apps/Examples/viewer.h b/Apps/Examples/viewer.h index 9d0a3c63f..583c15698 100644 --- a/Apps/Examples/viewer.h +++ b/Apps/Examples/viewer.h @@ -42,7 +42,7 @@ #include "Algo/Render/GL2/topoRender.h" #include "Utils/Shaders/shaderPhong.h" -#include "Utils/Shaders/shaderFlat.h" +#include "Utils/Shaders/shaderSimpleFlat.h" #include "Utils/Shaders/shaderSimpleColor.h" #include "Utils/Shaders/shaderVectorPerVertex.h" #include "Utils/pointSprite.h" @@ -104,13 +104,13 @@ public: VertexAttribute normal ; Algo::Render::GL2::MapRender* m_render ; - Algo::Render::GL2::TopoRenderMap* m_topoRender ; + Algo::Render::GL2::TopoRender* m_topoRender ; Utils::VBO* m_positionVBO ; Utils::VBO* m_normalVBO; Utils::ShaderPhong* m_phongShader ; - Utils::ShaderFlat* m_flatShader ; + Utils::ShaderSimpleFlat* m_flatShader ; Utils::ShaderVectorPerVertex* m_vectorShader ; Utils::ShaderSimpleColor* m_simpleColorShader ; Utils::PointSprite* m_pointSprite ; diff --git a/Apps/Examples/volumeExplorer.cpp b/Apps/Examples/volumeExplorer.cpp index 208639175..605b962b5 100644 --- a/Apps/Examples/volumeExplorer.cpp +++ b/Apps/Examples/volumeExplorer.cpp @@ -447,13 +447,13 @@ int main(int argc, char **argv) { position = myMap.addAttribute("position"); - int nb = 8; + int nb = 64; Algo::Volume::Tilings::Cubic::Grid cubic(myMap, nb, nb, nb); cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f); for (unsigned int i = position.begin(); i != position.end(); position.next(i)) { - VEC3 pert(float(double(rand())/RAND_MAX/20.0),float(double(rand())/RAND_MAX/20.0),float(double(rand())/RAND_MAX/20.0)); + VEC3 pert(float(double(rand())/RAND_MAX/200.0),float(double(rand())/RAND_MAX/200.0),float(double(rand())/RAND_MAX/200.0)); position[i]+= pert; } diff --git a/Apps/SandBox/testPlaneCutting.cpp b/Apps/SandBox/testPlaneCutting.cpp index 08941d101..accba87f7 100644 --- a/Apps/SandBox/testPlaneCutting.cpp +++ b/Apps/SandBox/testPlaneCutting.cpp @@ -85,7 +85,7 @@ void Viewer::cb_initGL() Utils::GLSLShader::setCurrentOGLVersion(2) ; m_render = new Algo::Render::GL2::MapRender() ; - m_topoRender = new Algo::Render::GL2::TopoRenderMap() ; + m_topoRender = new Algo::Render::GL2::TopoRender() ; m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ; @@ -232,7 +232,7 @@ void Viewer::cb_keyPress(int keycode) m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; - m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; + m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; updateGL(); break; @@ -267,7 +267,7 @@ void Viewer::cb_keyPress(int keycode) m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; - m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; + m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; updateGL(); break; @@ -338,7 +338,7 @@ void Viewer::importMesh(std::string& filename) m_render->initPrimitives(myMap, Algo::Render::GL2::LINES) ; m_render->initPrimitives(myMap, Algo::Render::GL2::TRIANGLES) ; - m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; + m_topoRender->updateData(myMap, position, 0.85f, 0.85f, m_drawBoundaryTopo) ; bb = Algo::Geometry::computeBoundingBox(myMap, position) ; normalBaseSize = bb.diagSize() / 100.0f ; diff --git a/Apps/SandBox/testPlaneCutting.h b/Apps/SandBox/testPlaneCutting.h index f754ffe61..2dd32c8cb 100644 --- a/Apps/SandBox/testPlaneCutting.h +++ b/Apps/SandBox/testPlaneCutting.h @@ -103,7 +103,7 @@ public: VertexAttribute normal ; Algo::Render::GL2::MapRender* m_render ; - Algo::Render::GL2::TopoRenderMap* m_topoRender ; + Algo::Render::GL2::TopoRender* m_topoRender ; Utils::VBO* m_positionVBO ; Utils::VBO* m_normalVBO; diff --git a/Apps/SandBox/test_traversor2.cpp b/Apps/SandBox/test_traversor2.cpp index ee42b26d0..3f158679a 100644 --- a/Apps/SandBox/test_traversor2.cpp +++ b/Apps/SandBox/test_traversor2.cpp @@ -75,8 +75,7 @@ void MyQT::traversors(int x) // update all color to grey for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) { - colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); - m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); + m_render_topo->addColoredDart(d,0.5f,0.5f,0.5f); } switch(x) @@ -85,7 +84,7 @@ void MyQT::traversors(int x) { Traversor2VVaE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; @@ -94,14 +93,14 @@ void MyQT::traversors(int x) Traversor2VVaF trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 2: { Traversor2EEaV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 3: @@ -109,63 +108,63 @@ void MyQT::traversors(int x) Traversor2EEaF trav(myMap,m_selected); float c=0.0f; for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,c); + m_render_topo->addColoredDart(b,0.0f,1.0f,c); } break; case 4: { Traversor2FFaV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 5: { Traversor2FFaE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 6: { Traversor2FV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 7: { Traversor2FE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 8: { Traversor2EV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 9: { Traversor2EF trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 10: { Traversor2VE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 11: { Traversor2VF trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) - m_render_topo->setDartColor(b,0.0f,1.0f,0.0f); + m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; default: @@ -178,9 +177,8 @@ void MyQT::traversors(int x) void MyQT::createMap(int n) { position = myMap.addAttribute("position"); - colorDarts = myMap.addAttribute("color"); - Algo::Surface::Tilings::Square::Grid grid(myMap, n, n, true); + Algo::Surface::Tilings::Square::Grid grid(myMap, n, n, true); grid.embedIntoGrid(position, 1.,1.,0.); // bounding box of scene @@ -197,31 +195,28 @@ void MyQT::createMap(int n) m_render_topo->setInitialDartsColor(0.5f,0.5f,0.5f); m_render_topo->setInitialBoundaryDartsColor(0.3f,0.3f,0.3f); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); + std::cout << "markAll OK"<< std::endl; + + + #ifdef USE_GMAP + m_render_topo->updateDataGMap(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); + #else + m_render_topo->updateData(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); + #endif + + std::cout << "markAll OK"<< std::endl; - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (dm.isMarked(d) && (!myMap.isBoundaryMarked<2>(d))) - { - colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); - m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); - } - } } void MyQT::updateMap() { m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (dm.isMarked(d) && (!myMap.isBoundaryMarked<2>(d))) - { - const Geom::Vec3f& C = colorDarts[d]; - if (C*C != 0.0f) - m_render_topo->setDartColor(d,C[0],C[1],C[2]); - } - } + #ifdef USE_GMAP + m_render_topo->updateData(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); + #else + m_render_topo->updateDataGMap(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); + #endif + updateGL(); } @@ -229,28 +224,24 @@ void MyQT::updateMap() void MyQT::cb_initGL() { glClearColor(1.0f,1.0f,1.0f,1.0f); -#ifdef USE_GMAP - m_render_topo = new Algo::Render::GL2::TopoRenderGMap(0.01f) ; -#else - m_render_topo = new Algo::Render::GL2::TopoRenderMap(0.01f) ; -#endif + m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ; } // redraw GL callback (clear and swap already done) void MyQT::cb_redraw() { - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); + glDepthFunc(GL_LESS); m_render_topo->drawTopo(); - glDisable( GL_POLYGON_OFFSET_FILL ); + glDepthFunc(GL_LEQUAL); + m_render_topo->drawColoredDarts(myMap); if (m_selected != NIL) - m_render_topo->overdrawDart(m_selected, 11, 1.0f, 0.0f, 0.0f); + m_render_topo->overdrawDart(myMap, m_selected, 11, 1.0f, 0.0f, 0.0f); if (m_selected2 != NIL) - m_render_topo->overdrawDart(m_selected2, 11, 0.0f, 1.0f, 0.0f); + m_render_topo->overdrawDart(myMap, m_selected2, 11, 0.0f, 1.0f, 0.0f); } void MyQT::cb_mousePress(int button, int x, int y) @@ -279,38 +270,6 @@ void MyQT::cb_keyPress(int keycode) { switch(keycode) { - case 'c': - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (!myMap.isBoundaryMarked<2>(d)) - { - int n = rand(); - float r = float(n&0x7f)/255.0f + 0.25f; - float g = float((n>>8)&0x7f)/255.0f + 0.25f; - float b = float((n>>16)&0x7f)/255.0 + 0.25f; - colorDarts[d] = Geom::Vec3f(r,g,b); - m_render_topo->setDartColor(d,r,g,b); - } - } - break; - case 'g': - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); - m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); - } - break; - - case 'h': - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (!myMap.isBoundaryMarked<2>(d)) - { - colorDarts[d] = Geom::Vec3f(0.0f,0.0f,0.0f); - m_render_topo->setDartColor(d,0.0f,0.0f,0.0f); - } - } - break; case Qt::Key_Up: if (m_selected!=NIL) position[m_selected][1] += m_shift; @@ -344,11 +303,6 @@ void MyQT::cb_keyPress(int keycode) void MyQT::svg() { - if (m_selected!=NIL) - m_render_topo->setDartColor(m_selected,0.8f,0.0f,0.0f); - if (m_selected2!=NIL) - m_render_topo->setDartColor(m_selected2,0.0f,0.8f,0.0f); - std::string filename = selectFileSave("snapshot file", ".", "(*.svg)"); m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix()); } @@ -392,23 +346,6 @@ void MyQT::importMesh(std::string& filename) position = myMap.getAttribute(attrNames[0]) ; } - colorDarts = myMap.getAttribute("color"); - if (!colorDarts.isValid()) - { - colorDarts = myMap.addAttribute("color"); - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (dm.isMarked(d) && (!myMap.isBoundaryMarked<2>(d))) - { - int n = rand(); - float r = float(n&0x7f)/255.0f + 0.25f; - float g = float((n>>8)&0x7f)/255.0f + 0.25f; - float b = float((n>>16)&0x7f)/255.0 + 0.25f; - colorDarts[d] = Geom::Vec3f(r,g,b); - m_render_topo->setDartColor(d,r,g,b); - } - } - } m_selected = NIL; m_selected2 = NIL; diff --git a/Apps/SandBox/test_traversor2.h b/Apps/SandBox/test_traversor2.h index d94efce95..9cbf9049c 100644 --- a/Apps/SandBox/test_traversor2.h +++ b/Apps/SandBox/test_traversor2.h @@ -94,7 +94,7 @@ protected: #ifdef USE_GMAP Algo::Render::GL2::TopoRenderGMap* m_render_topo; #else - Algo::Render::GL2::TopoRenderMap* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; #endif Dart m_selected; diff --git a/Apps/Tuto/Modelling/tuto_oper2.cpp b/Apps/Tuto/Modelling/tuto_oper2.cpp index 820ec7b98..578a361b9 100644 --- a/Apps/Tuto/Modelling/tuto_oper2.cpp +++ b/Apps/Tuto/Modelling/tuto_oper2.cpp @@ -169,7 +169,6 @@ void MyQT::operation(int x) void MyQT::createMap(int n) { position = myMap.addAttribute("position"); - colorDarts = myMap.addAttribute("color"); Algo::Surface::Tilings::Square::Grid grid(myMap, n, n, true); grid.embedIntoGrid(position, 1.,1.,0.); @@ -191,43 +190,22 @@ void MyQT::createMap(int n) m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); #ifdef PRIMAL_TOPO - m_render_topo->updateData(myMap, position, 0.9); + m_render_topo->updateData(myMap, position, 0.9); #else - m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); #endif - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (dm.isMarked(d) && (!myMap.isBoundaryMarked<2>(d))) - { - int n = rand(); - float r = float(n&0x7f)/255.0f + 0.25f; - float g = float((n>>8)&0x7f)/255.0f + 0.25f; - float b = float((n>>16)&0x7f)/255.0 + 0.25f; - colorDarts[d] = Geom::Vec3f(r,g,b); - m_render_topo->setDartColor(d,r,g,b); - } - } } void MyQT::updateMap() { m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); #ifdef PRIMAL_TOPO - m_render_topo->updateData(myMap, position, 0.9); + m_render_topo->updateData(myMap, position, 0.9); #else - m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); #endif - for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) - { - if (dm.isMarked(d) && (!myMap.isBoundaryMarked<2>(d))) - { - const Geom::Vec3f& C = colorDarts[d]; - if (C*C != 0.0f) - m_render_topo->setDartColor(d,C[0],C[1],C[2]); - } - } } // initialization GL callback @@ -235,27 +213,27 @@ void MyQT::cb_initGL() { glClearColor(1.0f,1.0f,1.0f,1.0f); #ifdef PRIMAL_TOPO - m_render_topo = new Algo::Render::GL2::TopoPrimalRender() ; + m_render_topo = new Algo::Render::GL2::TopoPrimalRender() ; #else - m_render_topo = new Algo::Render::GL2::TopoRenderMap(0.01f) ; + m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ; #endif } // redraw GL callback (clear and swap already done) void MyQT::cb_redraw() { - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); - + glDepthFunc(GL_LESS); m_render_topo->drawTopo(); - glDisable( GL_POLYGON_OFFSET_FILL ); + glDepthFunc(GL_LEQUAL); + + m_render_topo->drawColoredDarts(myMap); if (m_selected != NIL) - m_render_topo->overdrawDart(m_selected, 11, 1.0f, 0.0f, 0.0f); + m_render_topo->overdrawDart(myMap, m_selected, 11, 1.0f, 0.0f, 0.0f); if (m_selected2 != NIL) - m_render_topo->overdrawDart(m_selected2, 11, 0.0f, 1.0f, 0.0f); + m_render_topo->overdrawDart(myMap, m_selected2, 11, 0.0f, 1.0f, 0.0f); } void MyQT::cb_mousePress(int button, int x, int y) @@ -281,41 +259,6 @@ void MyQT::cb_keyPress(int keycode) { switch(keycode) { - case 'c': - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (!myMap.isBoundaryMarked<2>(d)) - { - int n = rand(); - float r = float(n&0x7f)/255.0f + 0.25f; - float g = float((n>>8)&0x7f)/255.0f + 0.25f; - float b = float((n>>16)&0x7f)/255.0 + 0.25f; - colorDarts[d] = Geom::Vec3f(r,g,b); - m_render_topo->setDartColor(d,r,g,b); - } - } - break; - case 'g': - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (!myMap.isBoundaryMarked<2>(d)) - { - colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); - m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); - } - } - break; - - case 'b': - for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) - { - if (!myMap.isBoundaryMarked<2>(d)) - { - colorDarts[d] = Geom::Vec3f(0.0f,0.0f,0.0f); - m_render_topo->setDartColor(d,0.0f,0.0f,0.0f); - } - } - break; case Qt::Key_Up: if (m_selected!=NIL) position[m_selected][1] += m_shift; @@ -346,11 +289,6 @@ void MyQT::cb_keyPress(int keycode) void MyQT::svg() { - if (m_selected!=NIL) - m_render_topo->setDartColor(m_selected,0.8f,0.0f,0.0f); - if (m_selected2!=NIL) - m_render_topo->setDartColor(m_selected2,0.0f,0.8f,0.0f); - std::string filename = selectFileSave("snapshot file", ".", "(*.svg)"); m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix()); } @@ -394,23 +332,6 @@ void MyQT::importMesh(std::string& filename) position = myMap.getAttribute(attrNames[0]) ; } - colorDarts = myMap.getAttribute("color"); - if (!colorDarts.isValid()) - { - colorDarts = myMap.addAttribute("color"); - for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) - { - if (dm.isMarked(d) && (!myMap.isBoundaryMarked<2>(d))) - { - int n = rand(); - float r = float(n&0x7f)/255.0f + 0.25f; - float g = float((n>>8)&0x7f)/255.0f + 0.25f; - float b = float((n>>16)&0x7f)/255.0 + 0.25f; - colorDarts[d] = Geom::Vec3f(r,g,b); - m_render_topo->setDartColor(d,r,g,b); - } - } - } m_selected = NIL; m_selected2 = NIL; diff --git a/Apps/Tuto/Modelling/tuto_oper2.h b/Apps/Tuto/Modelling/tuto_oper2.h index 471f8bd00..5678932df 100644 --- a/Apps/Tuto/Modelling/tuto_oper2.h +++ b/Apps/Tuto/Modelling/tuto_oper2.h @@ -84,13 +84,12 @@ protected: MAP myMap; VertexAttribute position; - DartAttribute colorDarts; // render (for the topo) #ifdef PRIMAL_TOPO Algo::Render::GL2::TopoPrimalRender* m_render_topo; #else - Algo::Render::GL2::TopoRenderMap* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; #endif Dart m_selected; Dart m_selected2; diff --git a/Apps/Tuto/Modelling/tuto_oper3.cpp b/Apps/Tuto/Modelling/tuto_oper3.cpp index c14a6f35a..74751af0c 100644 --- a/Apps/Tuto/Modelling/tuto_oper3.cpp +++ b/Apps/Tuto/Modelling/tuto_oper3.cpp @@ -76,19 +76,16 @@ void MyQT::clipping_onoff(bool x) m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos); m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos); m_sh3->setClipPlaneParamsAll(clip_id3, normal, pos); - m_sh4->setClipPlaneParamsAll(clip_id4, normal, pos); } else { m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); m_sh3->setClipPlaneParamsAll(clip_id3, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); - m_sh4->setClipPlaneParamsAll(clip_id4, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f)); m_sh1->setClipColorAttenuationFactorRelative(0.0f,0.0f); m_sh2->setClipColorAttenuationFactorRelative(0.0f,0.0f); m_sh3->setClipColorAttenuationFactorRelative(0.0f,0.0f); - m_sh4->setClipColorAttenuationFactorRelative(0.0f,0.0f); } updateMap(); @@ -343,7 +340,7 @@ void MyQT::updateMap() #else m_render_topo->updateData(myMap, position, m_ex1,m_ex2,m_ex3); #endif - m_render_topo_boundary->updateDataBoundary(myMap,position,m_ex1,m_ex2,m_shift); + m_render_topo_boundary->updateDataBoundary(myMap,position,m_ex1,m_ex2,m_shift); } // initialization GL callback @@ -356,7 +353,7 @@ void MyQT::cb_initGL() #else m_render_topo = new Algo::Render::GL2::Topo3RenderMap() ; #endif - m_render_topo_boundary = new Algo::Render::GL2::TopoRenderMap(); + m_render_topo_boundary = new Algo::Render::GL2::TopoRender(); m_render_topo_boundary->setInitialDartsColor(0.0f,0.9f,0.0f); m_PlanePick = new Utils::Pickable(Utils::Pickable::GRID,1); @@ -366,26 +363,18 @@ void MyQT::cb_initGL() m_sh1 = static_cast(m_render_topo->shader1()); m_sh2 = static_cast(m_render_topo->shader2()); m_sh3 = static_cast(m_render_topo_boundary->shader1()); - m_sh4 = static_cast(m_render_topo_boundary->shader2()); - - m_sh1->insertClippingCode(); m_sh2->insertClippingCode(); m_sh3->insertClippingCode(); - m_sh4->insertClippingCode(); - clip_id1 = m_sh1->addClipPlane(); clip_id2 = m_sh2->addClipPlane(); clip_id3 = m_sh3->addClipPlane(); - clip_id4 = m_sh4->addClipPlane(); - m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), bb.center()); m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), bb.center()); m_sh3->setClipPlaneParamsAll(clip_id3, Geom::Vec3f(0,0,1), bb.center()); - m_sh4->setClipPlaneParamsAll(clip_id4, Geom::Vec3f(0,0,1), bb.center()); } @@ -553,7 +542,6 @@ void MyQT::cb_mouseMove(int buttons, int x, int y) m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos); m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos); m_sh3->setClipPlaneParamsAll(clip_id3, normal, pos); - m_sh4->setClipPlaneParamsAll(clip_id4, normal, pos); m_begX = x; diff --git a/Apps/Tuto/Modelling/tuto_oper3.h b/Apps/Tuto/Modelling/tuto_oper3.h index 9bb664f2d..930cd7378 100644 --- a/Apps/Tuto/Modelling/tuto_oper3.h +++ b/Apps/Tuto/Modelling/tuto_oper3.h @@ -104,7 +104,7 @@ protected: #else Algo::Render::GL2::Topo3RenderMap* m_render_topo; #endif - Algo::Render::GL2::TopoRenderMap* m_render_topo_boundary; + Algo::Render::GL2::TopoRender* m_render_topo_boundary; Dart m_selected; Dart m_selected2; std::vector m_selecteds; @@ -132,11 +132,10 @@ protected: int clip_id1; int clip_id2; int clip_id3; - int clip_id4; + Utils::ClippingShader* m_sh1; Utils::ClippingShader* m_sh2; Utils::ClippingShader* m_sh3; - Utils::ClippingShader* m_sh4; public: // example of simple map creation diff --git a/Apps/Tuto/Traversals/show_traversors2.cpp b/Apps/Tuto/Traversals/show_traversors2.cpp index 3596adb94..d2b162155 100644 --- a/Apps/Tuto/Traversals/show_traversors2.cpp +++ b/Apps/Tuto/Traversals/show_traversors2.cpp @@ -85,8 +85,8 @@ void MyQT::cb_initGL() // choose to use GL version 2 Utils::GLSLShader::setCurrentOGLVersion(2); - m_render_topo = new Algo::Render::GL2::TopoRenderMap(); - m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); + m_render_topo = new Algo::Render::GL2::TopoRender(); + m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); m_dm_topo = new DartMarker(myMap); } @@ -94,14 +94,16 @@ void MyQT::cb_redraw() { if (m_showTopo) { + glDepthFunc(GL_LESS); m_render_topo->drawTopo(); + glDepthFunc(GL_LEQUAL); if (m_selected != NIL) - m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f); + m_render_topo->overdrawDart(myMap, m_selected, 7, 1.0f, 0.0f, 1.0f); for (std::vector::iterator it=m_affDarts.begin(); it!=m_affDarts.end(); ++it) { - m_render_topo->overdrawDart(*it, 6, 1.0f, 1.0f, 1.0f); + m_render_topo->overdrawDart(myMap, *it, 6, 1.0f, 1.0f, 1.0f); } } @@ -138,11 +140,6 @@ void MyQT::cb_Save() svg2.write(); } -template -void MyQT::colorizeCell(Cell c, float r, float g, float b) -{ - myMap.foreach_dart_of_orbit(c, [&] (Dart d) { m_render_topo->setDartColor(d, r, g, b); }); -} void MyQT::traverse2() { @@ -180,7 +177,7 @@ void MyQT::traverse2() m_drawer.endList(); // SelectorMarked sm(*m_dm_topo); - m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); + m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); updateGL(); } diff --git a/Apps/Tuto/Traversals/show_traversors2.h b/Apps/Tuto/Traversals/show_traversors2.h index cd72d2582..1ce56c9dc 100644 --- a/Apps/Tuto/Traversals/show_traversors2.h +++ b/Apps/Tuto/Traversals/show_traversors2.h @@ -67,7 +67,7 @@ class MyQT: public Utils::QT::SimpleQT { Q_OBJECT - Algo::Render::GL2::TopoRenderMap* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; bool m_showTopo; @@ -115,8 +115,6 @@ protected: void cb_mousePress(int button, int x, int y); - template - void colorizeCell(Cell c, float r,float g, float b); void traverse2(); void dynamicMarkOrbit(unsigned int orb); diff --git a/Apps/Tuto/Traversals/show_traversors3.cpp b/Apps/Tuto/Traversals/show_traversors3.cpp index 315c685af..71a3957f7 100644 --- a/Apps/Tuto/Traversals/show_traversors3.cpp +++ b/Apps/Tuto/Traversals/show_traversors3.cpp @@ -126,8 +126,10 @@ void MyQT::cb_redraw() { if (m_showTopo) { + glDepthFunc(GL_LESS); m_render_topo->drawTopo(); + glDepthFunc(GL_LEQUAL); if (m_selected != NIL) m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f); diff --git a/Apps/Tuto/tuto1.cpp b/Apps/Tuto/tuto1.cpp index 3b780dfad..fb683f750 100644 --- a/Apps/Tuto/tuto1.cpp +++ b/Apps/Tuto/tuto1.cpp @@ -93,13 +93,13 @@ void MyQT::createMap() // render the topo of the map without boundary darts m_render_topo->setInitialBoundaryDartsColor(0,1,0); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f,true); + m_render_topo->updateDataGMap(myMap, position, 0.9f, 0.9f,true); } // initialization GL callback void MyQT::cb_initGL() { - m_render_topo = new Algo::Render::GL2::TopoRenderMap() ; + m_render_topo = new Algo::Render::GL2::TopoRender() ; } // redraw GL callback (clear and swap already done) diff --git a/Apps/Tuto/tuto1.h b/Apps/Tuto/tuto1.h index dda9225b7..9abf1b403 100644 --- a/Apps/Tuto/tuto1.h +++ b/Apps/Tuto/tuto1.h @@ -25,14 +25,12 @@ #ifndef _TUTO1_ #define _TUTO1_ -//#define USE_GMAP - //#include "Utils/Qt/qtSimple.h" #include "Utils/Qt/qtQGLV.h" #include "Utils/cgognStream.h" #include "Topology/generic/parameters.h" -#include "Topology/map/embeddedMap2.h" +#include "Topology/gmap/embeddedGMap2.h" #include "Algo/Render/GL2/topoRender.h" @@ -45,7 +43,7 @@ using namespace CGoGN ; struct PFP: public PFP_STANDARD { // definition of the type of the map - typedef EmbeddedMap2 MAP; + typedef EmbeddedGMap2 MAP; }; typedef PFP::MAP MAP; @@ -69,7 +67,7 @@ protected: VertexAttribute position; // render (for the topo) - Algo::Render::GL2::TopoRenderMap* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; // just for more compact writing inline Dart PHI1(Dart d) { return myMap.phi1(d); } diff --git a/Apps/Tuto/tuto3.cpp b/Apps/Tuto/tuto3.cpp index df100304f..878f3d99b 100644 --- a/Apps/Tuto/tuto3.cpp +++ b/Apps/Tuto/tuto3.cpp @@ -67,17 +67,17 @@ void MyQT::traverseMap() // render the topo of the map without boundary darts // SelectorDartNoBoundary nb(myMap); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f); // nb + m_render_topo->updateData(myMap, position, 0.9f, 0.9f); // nb for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) { if (m2.isMarked(d)) { - m_render_topo->setDartColor(d,1.0f,0.0f,0.0f); +// m_render_topo->setDartColor(myMap,d,1.0f,0.0f,0.0f); } if (m1.isMarked(d)) { - m_render_topo->setDartColor(d,0.0f,1.0f,0.0f); +// m_render_topo->setDartColor(myMap,d,0.0f,1.0f,0.0f); } } @@ -198,20 +198,20 @@ void MyQT::createMap() // render the topo of the map without boundary darts // SelectorDartNoBoundary nb(myMap); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f); // nb + m_render_topo->updateData(myMap, position, 0.9f, 0.9f); // nb } // initialization GL callback void MyQT::cb_initGL() { - m_render_topo = new Algo::Render::GL2::TopoRenderMap(); + m_render_topo = new Algo::Render::GL2::TopoRender(); } // redraw GL callback (clear and swap already done) void MyQT::cb_redraw() { if (dart_selected != NIL) - m_render_topo->overdrawDart(dart_selected, 5, 1.0f,0.0f,0.0f); + m_render_topo->overdrawDart(myMap, dart_selected, 5, 1.0f,0.0f,0.0f); m_render_topo->drawTopo(); } diff --git a/Apps/Tuto/tuto3.h b/Apps/Tuto/tuto3.h index 4c273965e..7916d90ad 100644 --- a/Apps/Tuto/tuto3.h +++ b/Apps/Tuto/tuto3.h @@ -66,7 +66,7 @@ protected: VertexAttribute position; // render (for the topo) - Algo::Render::GL2::TopoRenderMap* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; // selected dart (mouse click) Dart dart_selected; diff --git a/Apps/Tuto/tuto4.cpp b/Apps/Tuto/tuto4.cpp index 4f3403d6d..8920c0982 100644 --- a/Apps/Tuto/tuto4.cpp +++ b/Apps/Tuto/tuto4.cpp @@ -150,13 +150,13 @@ void MyQT::createMap() // first show for be sure that GL context is binded show(); - m_render_topo->updateData(myMap, position, 0.9f, 0.9f); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f); } // initialization GL callback void MyQT::cb_initGL() { - m_render_topo = new Algo::Render::GL2::TopoRenderMap() ; + m_render_topo = new Algo::Render::GL2::TopoRender() ; } // redraw GL callback (clear and swap already done) @@ -165,7 +165,7 @@ void MyQT::cb_redraw() if (!dart_selected.empty()) for (std::vector::iterator it = dart_selected.begin(); it != dart_selected.end(); ++it) { - m_render_topo->overdrawDart(*it, 5, color[0],color[1],color[2]); + m_render_topo->overdrawDart(myMap, *it, 5, color[0],color[1],color[2]); } m_render_topo->drawTopo(); } diff --git a/Apps/Tuto/tuto4.h b/Apps/Tuto/tuto4.h index 500884789..32781651b 100644 --- a/Apps/Tuto/tuto4.h +++ b/Apps/Tuto/tuto4.h @@ -65,7 +65,7 @@ protected: VertexAttribute position; // render (for the topo) - Algo::Render::GL2::TopoRenderMap* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; // selected dart (mouse click) std::vector dart_selected; diff --git a/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp b/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp index bf77bf587..fc01e2656 100644 --- a/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp +++ b/SCHNApps/Plugins/surface_deformation/src/surface_deformation.cpp @@ -240,6 +240,10 @@ void Surface_Deformation_Plugin::mouseMove(View* view, QMouseEvent* event) void Surface_Deformation_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { m_dockTab->updateMapParameters(); + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_Deformation_Plugin::mapAdded(MapHandlerGen* map) diff --git a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp index ebf5b72ba..a8b442317 100644 --- a/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp +++ b/SCHNApps/Plugins/surface_modelisation/src/surface_modelisation.cpp @@ -92,6 +92,10 @@ void Surface_Modelisation_Plugin::mousePress(View* view, QMouseEvent* event) void Surface_Modelisation_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { m_dockTab->updateMapParameters(); + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_Modelisation_Plugin::mapAdded(MapHandlerGen* map) diff --git a/SCHNApps/Plugins/surface_render/include/surface_render.h b/SCHNApps/Plugins/surface_render/include/surface_render.h index 9bfda1bd5..d3b6d1a7b 100644 --- a/SCHNApps/Plugins/surface_render/include/surface_render.h +++ b/SCHNApps/Plugins/surface_render/include/surface_render.h @@ -106,6 +106,11 @@ public slots: void changeRenderFaces(const QString& view, const QString& map, bool b); void changeFacesStyle(const QString& view, const QString& map, MapParameters::FaceShadingStyle style); void changeRenderBoundary(const QString& view, const QString& map, bool b); + void changeFaceColor(const QString& view, const QString& map, float r, float g, float b); + void changeEdgeColor(const QString& view, const QString& map, float r, float g, float b); + void changeVertexColor(const QString& view, const QString& map, float r, float g, float b); + + protected: Surface_Render_DockTab* m_dockTab; diff --git a/SCHNApps/Plugins/surface_render/src/surface_render.cpp b/SCHNApps/Plugins/surface_render/src/surface_render.cpp index 979453284..dbf75a505 100644 --- a/SCHNApps/Plugins/surface_render/src/surface_render.cpp +++ b/SCHNApps/Plugins/surface_render/src/surface_render.cpp @@ -134,6 +134,10 @@ void Surface_Render_Plugin::selectedViewChanged(View *prev, View *cur) void Surface_Render_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { m_dockTab->updateMapParameters(); + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_Render_Plugin::mapAdded(MapHandlerGen *map) @@ -329,6 +333,52 @@ void Surface_Render_Plugin::changeRenderBoundary(const QString& view, const QStr } } +void Surface_Render_Plugin::changeFaceColor(const QString& view, const QString& map, float r, float g, float b) +{ + View* v = m_schnapps->getView(view); + MapHandlerGen* m = m_schnapps->getMap(map); + if(v && m) + { + h_viewParameterSet[v][m].diffuseColor = Geom::Vec4f(r,g,b,0); + if(v->isSelectedView()) + { + if(v->isLinkedToMap(m)) v->updateGL(); + if(m->isSelectedMap()) m_dockTab->updateMapParameters(); + } + } +} + +void Surface_Render_Plugin::changeEdgeColor(const QString& view, const QString& map, float r, float g, float b) +{ + View* v = m_schnapps->getView(view); + MapHandlerGen* m = m_schnapps->getMap(map); + if(v && m) + { + h_viewParameterSet[v][m].simpleColor = Geom::Vec4f(r,g,b,0); + if(v->isSelectedView()) + { + if(v->isLinkedToMap(m)) v->updateGL(); + if(m->isSelectedMap()) m_dockTab->updateMapParameters(); + } + } +} + +void Surface_Render_Plugin::changeVertexColor(const QString& view, const QString& map, float r, float g, float b) +{ + View* v = m_schnapps->getView(view); + MapHandlerGen* m = m_schnapps->getMap(map); + if(v && m) + { + h_viewParameterSet[v][m].vertexColor = Geom::Vec4f(r,g,b,0); + if(v->isSelectedView()) + { + if(v->isLinkedToMap(m)) v->updateGL(); + if(m->isSelectedMap()) m_dockTab->updateMapParameters(); + } + } +} + + Q_EXPORT_PLUGIN2(Surface_Render_Plugin, Surface_Render_Plugin) } // namespace SCHNApps diff --git a/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp b/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp index 10c52b326..2d8ec29ea 100644 --- a/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp +++ b/SCHNApps/Plugins/surface_render/src/surface_render_dockTab.cpp @@ -320,7 +320,7 @@ void Surface_Render_DockTab::updateMapParameters() m_simpleColor = QColor(255*p.simpleColor[0],255*p.simpleColor[1],255*p.simpleColor[2]); scolorButton->setStyleSheet("QPushButton { background-color:"+m_simpleColor.name()+ " }"); - m_vertexColor = QColor(255*p.simpleColor[0],255*p.vertexColor[1],255*p.vertexColor[2]); + m_vertexColor = QColor(255*p.vertexColor[0],255*p.vertexColor[1],255*p.vertexColor[2]); vcolorButton->setStyleSheet("QPushButton { background-color:"+m_vertexColor.name()+ " }"); diff --git a/SCHNApps/Plugins/surface_renderScalar/src/surface_renderScalar.cpp b/SCHNApps/Plugins/surface_renderScalar/src/surface_renderScalar.cpp index bf6189dba..4de9bf69b 100644 --- a/SCHNApps/Plugins/surface_renderScalar/src/surface_renderScalar.cpp +++ b/SCHNApps/Plugins/surface_renderScalar/src/surface_renderScalar.cpp @@ -79,6 +79,10 @@ void Surface_RenderScalar_Plugin::selectedViewChanged(View *prev, View *cur) void Surface_RenderScalar_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { m_dockTab->updateMapParameters(); + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_RenderScalar_Plugin::mapAdded(MapHandlerGen* map) diff --git a/SCHNApps/Plugins/surface_renderTopo/forms/surface_renderTopo.ui b/SCHNApps/Plugins/surface_renderTopo/forms/surface_renderTopo.ui index 8149b537c..487508dd8 100644 --- a/SCHNApps/Plugins/surface_renderTopo/forms/surface_renderTopo.ui +++ b/SCHNApps/Plugins/surface_renderTopo/forms/surface_renderTopo.ui @@ -6,7 +6,7 @@ 0 0 - 207 + 337 600 @@ -14,9 +14,38 @@ Form + + + + draw phi1 + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + @@ -27,23 +56,27 @@ - - + + - draw phi1 - - - true + explod faces - - + + + + 50 + + + Qt::Horizontal + + - + - + 0 0 @@ -55,17 +88,7 @@ - - - - explod edges - - - - - - - + 50 @@ -75,17 +98,7 @@ - - - - 50 - - - Qt::Horizontal - - - - + Qt::Vertical @@ -98,10 +111,22 @@ - - - - explod faces + + + + + 0 + 0 + + + + + 230 + 0 + + + + Qt::Horizontal @@ -115,13 +140,39 @@ - + + + + explod edges + + + + + + + 0 + 0 + + Position : + + + + + 75 + true + + + + Per map parameters + + + @@ -132,7 +183,6 @@ - combo_positionAttribute check_drawDarts combo_dartsColor check_drawPhi1 diff --git a/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo.h b/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo.h index 516850772..126a373c0 100644 --- a/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo.h +++ b/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo.h @@ -5,6 +5,8 @@ #include "surface_renderTopo_dockTab.h" #include "Algo/Render/GL2/topoRender.h" +#include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderColorPerVertex.h" namespace CGoGN { @@ -12,29 +14,6 @@ namespace CGoGN namespace SCHNApps { -struct MapParameters -{ - MapParameters() : - drawDarts(true), - dartsColor("white"), - drawPhi1(true), - phi1Color("cyan"), - drawPhi2(true), - phi2Color("red"), - edgesScaleFactor(1.0f), - facesScaleFactor(1.0f) - {} - - VertexAttribute positionAttribute; - bool drawDarts; - QColor dartsColor; - bool drawPhi1; - QColor phi1Color; - bool drawPhi2; - QColor phi2Color; - float edgesScaleFactor; - float facesScaleFactor; -}; class Surface_RenderTopo_Plugin : public PluginInteraction { @@ -44,6 +23,42 @@ class Surface_RenderTopo_Plugin : public PluginInteraction friend class Surface_RenderTopo_DockTab; public: + + struct ViewMapParam + { + ViewMapParam() : + drawDarts(true), + dartsColor("white"), + drawPhi1(true), + phi1Color("cyan"), + drawPhi2(true), + phi2Color("red") + {} + + bool drawDarts; + QColor dartsColor; + bool drawPhi1; + QColor phi1Color; + bool drawPhi2; + QColor phi2Color; + }; + + + struct MapParam + { + MapParam() : + edgesScaleFactor(0.95f), + facesScaleFactor(0.95f), + needUpdate(true) + {} + + QString posAttName; + float edgesScaleFactor; + float facesScaleFactor; + bool needUpdate; + }; + + Surface_RenderTopo_Plugin() {} @@ -78,22 +93,32 @@ private slots: public slots: // slots for Python calls -// void changePositionAttribute(const QString& view, const QString& map, const QString& attrName); // void changeDrawDarts(const QString& view, const QString& map, bool b); // void changeDartsColor(const QString& view, const QString& map, QColor c); // void changeDrawPhi1(const QString& view, const QString& map, bool b); // void changePhi1Color(const QString& view, const QString& map, QColor c); // void changeDrawPhi2(const QString& view, const QString& map, bool b); // void changePhi2Color(const QString& view, const QString& map, QColor c); -// void changeEdgesScaleFactor(const QString& view, const QString& map, int i); -// void changeFacesScaleFactor(const QString& view, const QString& map, int i); + +// void changePositionAttribute(const QString& map, const QString& attrName); +// void changeEdgesScaleFactor(const QString& map, int i); +// void changeFacesScaleFactor(const QString& map, int i); //signals: // void dartSelected(Dart d); protected: Surface_RenderTopo_DockTab* m_dockTab; - QHash > h_viewParameterSet; + + /// parameters that depend of view and map + QHash > h_viewParameterSet; + + /// parameters that depend of map only + QHash h_parameterSet; + + /// shader used in TopoRender + CGoGN::Utils::ShaderSimpleColor* m_shaderTopo1; + }; } // namespace SCHNApps diff --git a/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo_dockTab.h b/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo_dockTab.h index 9559aa365..73b0fd56d 100644 --- a/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo_dockTab.h +++ b/SCHNApps/Plugins/surface_renderTopo/include/surface_renderTopo_dockTab.h @@ -11,7 +11,7 @@ namespace SCHNApps class SCHNApps; class Surface_RenderTopo_Plugin; -struct MapParameters; +//struct MapParameters; class Surface_RenderTopo_DockTab : public QWidget, public Ui::Surface_RenderTopo_TabWidget { diff --git a/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo.cpp b/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo.cpp index c0f939530..5d4b3f4d4 100644 --- a/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo.cpp +++ b/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo.cpp @@ -11,7 +11,7 @@ namespace SCHNApps bool Surface_RenderTopo_Plugin::enable() { // magic line that init static variables of GenericMap in the plugins - GenericMap::copyAllStatics(m_schnapps->getStaticPointers()); + GenericMap::copyAllStatics(m_schnapps->getStaticPointers()); m_dockTab = new Surface_RenderTopo_DockTab(m_schnapps, this); m_schnapps->addPluginDockTab(this, m_dockTab, "Surface_RenderTopo"); @@ -21,8 +21,13 @@ bool Surface_RenderTopo_Plugin::enable() connect(m_schnapps, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*))); connect(m_schnapps, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*))); + m_shaderTopo1 = new CGoGN::Utils::ShaderSimpleColor(); + registerShader(m_shaderTopo1); + foreach(MapHandlerGen* map, m_schnapps->getMapSet().values()) + { mapAdded(map); + } m_dockTab->updateMapParameters(); @@ -42,17 +47,33 @@ void Surface_RenderTopo_Plugin::disable() void Surface_RenderTopo_Plugin::drawMap(View* view, MapHandlerGen* map) { - const MapParameters& p = h_viewParameterSet[view][map]; - -// if(p.positionAttribute.isValid()) -// { -// if(p.drawDarts) -// map->drawTopo(DARTS); -// if(p.drawPhi1) -// map->drawTopo(RELATION1); -// if(p.drawPhi2) -// map->drawTopo(RELATION2); -// } +// std::cout << "Surface_RenderTopo_Plugin::drawMap"<< std::endl; + ViewMapParam& p = h_viewParameterSet[view][map]; + + map->getTopoRender()->setInitialDartsColor(p.dartsColor.redF(),p.dartsColor.greenF(),p.dartsColor.blueF()); + map->getTopoRender()->setColorPhi1(Geom::Vec4f(p.phi1Color.redF(),p.phi1Color.greenF(),p.phi1Color.blueF(),0.0f)); + map->getTopoRender()->setColorPhi2(Geom::Vec4f(p.phi2Color.redF(),p.phi2Color.greenF(),p.phi2Color.blueF(),0.0f)); + + MapParam& pm = h_parameterSet[map]; + + if (pm.needUpdate) + { +// std::cout << "NEED UPDATE"<< std::endl; + map->getTopoRender()->setExplodeEdge(pm.edgesScaleFactor); + map->getTopoRender()->setExplodeFace(pm.facesScaleFactor); + QString pos = m_dockTab->combo_positionAttribute->currentText(); + map->updateTopoRender(pos); + pm.needUpdate = false; + } + + int code=0; + if(p.drawDarts) + code |= 1; + if(p.drawPhi1) + code |= 2; + if(p.drawPhi2) + code |= 4; + map->drawTopoRender(code); } @@ -67,11 +88,17 @@ void Surface_RenderTopo_Plugin::selectedViewChanged(View *prev, View *cur) void Surface_RenderTopo_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { m_dockTab->updateMapParameters(); + + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_RenderTopo_Plugin::mapAdded(MapHandlerGen* map) { connect(map, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(attributeAdded(unsigned int, const QString&))); + map->createTopoRender(m_shaderTopo1); } void Surface_RenderTopo_Plugin::mapRemoved(MapHandlerGen* map) @@ -85,17 +112,22 @@ void Surface_RenderTopo_Plugin::mapRemoved(MapHandlerGen* map) void Surface_RenderTopo_Plugin::attributeAdded(unsigned int orbit, const QString& name) { +// std::cout << "attributeAdded"<< std::endl; MapHandlerGen* map = static_cast(QObject::sender()); if(orbit == VERTEX && map == m_schnapps->getSelectedMap()) + { m_dockTab->addVertexAttribute(name); + } } -//void Surface_RenderTopo_Plugin::changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute attribute, bool fromUI) +//void Surface_RenderTopo_Plugin::changePositionAttribute(View* view, MapHandlerGen* map, VertexAttribute attribute, bool fromUI) //{ +//// map->updateTopoRender + // ParameterSet* params = h_viewParams[view]; // PerMapParameterSet* perMap = params->perMap[map->getName()]; // perMap->positionAttribute = attribute; diff --git a/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo_dockTab.cpp b/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo_dockTab.cpp index cee07f320..f8379c7f2 100644 --- a/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo_dockTab.cpp +++ b/SCHNApps/Plugins/surface_renderTopo/src/surface_renderTopo_dockTab.cpp @@ -43,7 +43,13 @@ void Surface_RenderTopo_DockTab::positionAttributeChanged(int index) // if(index == 0) // ; // else -// m_plugin->h_viewParameterSet[view][map].positionAttribute = map->getAttribute(combo_positionAttribute->currentText()); + +// m_plugin->h_viewParameterSet[view][map].positionAttribute = map->getAttribute(combo_positionAttribute->currentText()); +// QString pos = this->combo_positionAttribute->currentText(); + + QString& pos = m_plugin->h_parameterSet[map].posAttName; + pos = this->combo_positionAttribute->currentText(); + map->updateTopoRender(pos); view->updateGL(); } } @@ -133,20 +139,35 @@ void Surface_RenderTopo_DockTab::phi2ColorChanged(int i) } } + void Surface_RenderTopo_DockTab::facesScaleFactorChanged(int i) { if(!b_updatingUI) { View* view = m_schnapps->getSelectedView(); MapHandlerGen* map = m_schnapps->getSelectedMap(); + if(view && map) { - m_plugin->h_viewParameterSet[view][map].facesScaleFactor = i / 100.0f; - view->updateGL(); + m_plugin->h_parameterSet[map].facesScaleFactor = i / 100.0f; + m_plugin->h_parameterSet[map].needUpdate = true; + map->updateTopoRender(m_plugin->h_parameterSet[map].posAttName); + } + const ViewSet& vs= m_schnapps->getViewSet(); + foreach (View* pv, vs) + { + if (m_plugin->h_viewParameterSet[pv].find(map) != m_plugin->h_viewParameterSet[pv].end())/* && (pv!=view))*/ + { + pv->updateGL(); + } } } } + + + + void Surface_RenderTopo_DockTab::edgesScaleFactorChanged(int i) { if(!b_updatingUI) @@ -155,8 +176,16 @@ void Surface_RenderTopo_DockTab::edgesScaleFactorChanged(int i) MapHandlerGen* map = m_schnapps->getSelectedMap(); if(view && map) { - m_plugin->h_viewParameterSet[view][map].edgesScaleFactor = i / 100.0f; - view->updateGL(); + m_plugin->h_parameterSet[map].edgesScaleFactor = i / 100.0f; + m_plugin->h_parameterSet[map].needUpdate = true; + } + const ViewSet& vs= m_schnapps->getViewSet(); + foreach (View* pv, vs) + { + if (m_plugin->h_viewParameterSet[pv].find(map) != m_plugin->h_viewParameterSet[pv].end()) + { + pv->updateGL(); + } } } } @@ -187,20 +216,29 @@ void Surface_RenderTopo_DockTab::updateMapParameters() if(view && map) { - const MapParameters& p = m_plugin->h_viewParameterSet[view][map]; + this->label_map_param->setText(QString("Per map parameters: ")+map->getName()); + + const Surface_RenderTopo_Plugin::ViewMapParam& p = m_plugin->h_viewParameterSet[view][map]; + + bool attChanged; QString vec3TypeName = QString::fromStdString(nameOfType(PFP2::VEC3())); - unsigned int i = 1; + int i = 1; const AttributeSet& attribs = map->getAttributeSet(VERTEX); for(AttributeSet::const_iterator it = attribs.constBegin(); it != attribs.constEnd(); ++it) { if(it.value() == vec3TypeName) { combo_positionAttribute->addItem(it.key()); - if(p.positionAttribute.isValid() && it.key() == QString::fromStdString(p.positionAttribute.name())) - combo_positionAttribute->setCurrentIndex(i); - + if (m_plugin->h_parameterSet[map].posAttName == it.key()) + { + if (combo_positionAttribute->currentIndex() != i) + { + combo_positionAttribute->setCurrentIndex(i); + attChanged = true; + } + } ++i; } } @@ -211,8 +249,11 @@ void Surface_RenderTopo_DockTab::updateMapParameters() combo_phi1Color->setColor(p.phi1Color); check_drawPhi2->setChecked(p.drawPhi2); combo_phi2Color->setColor(p.phi2Color); - slider_edgesScaleFactor->setSliderPosition(p.edgesScaleFactor * 100.0); - slider_facesScaleFactor->setSliderPosition(p.facesScaleFactor * 100.0); + + slider_edgesScaleFactor->setSliderPosition(m_plugin->h_parameterSet[map].edgesScaleFactor * 100.0); + slider_facesScaleFactor->setSliderPosition(m_plugin->h_parameterSet[map].facesScaleFactor * 100.0); + m_plugin->h_parameterSet[map].needUpdate = true; + } b_updatingUI = false; diff --git a/SCHNApps/Plugins/surface_renderVector/src/surface_renderVector.cpp b/SCHNApps/Plugins/surface_renderVector/src/surface_renderVector.cpp index 60880aaf0..9bd90b7db 100644 --- a/SCHNApps/Plugins/surface_renderVector/src/surface_renderVector.cpp +++ b/SCHNApps/Plugins/surface_renderVector/src/surface_renderVector.cpp @@ -76,6 +76,10 @@ void Surface_RenderVector_Plugin::selectedViewChanged(View *prev, View *cur) void Surface_RenderVector_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur) { m_dockTab->updateMapParameters(); + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_RenderVector_Plugin::mapAdded(MapHandlerGen* map) diff --git a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp index 5d04611ea..0849d9129 100644 --- a/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp +++ b/SCHNApps/Plugins/surface_selection/src/surface_selection.cpp @@ -491,6 +491,11 @@ void Surface_Selection_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandle connect(cur, SIGNAL(connectivityModified()), this, SLOT(selectedMapConnectivityModified())); m_selectionRadius = cur->getBBdiagSize() / 50.0f; } + + if (cur==NULL) + m_dockTab->setDisabled(true); + else + m_dockTab->setDisabled(false); } void Surface_Selection_Plugin::updateSelectedCellsRendering() diff --git a/SCHNApps/include/mapHandler.h b/SCHNApps/include/mapHandler.h index 880903fc2..f9f477351 100644 --- a/SCHNApps/include/mapHandler.h +++ b/SCHNApps/include/mapHandler.h @@ -15,6 +15,7 @@ #include "Utils/drawer.h" #include "Algo/Render/GL2/mapRender.h" +#include "Algo/Render/GL2/topoRender.h" #include "Algo/Geometry/boundingbox.h" #include "Algo/Topo/basic.h" @@ -147,6 +148,21 @@ private: void linkView(View* view); void unlinkView(View* view); + /********************************************************* + * MANAGE TOPO_RENDERING + *********************************************************/ +public: + + virtual void createTopoRender(CGoGN::Utils::GLSLShader* sh1) = 0; + void deleteTopoRender(); + virtual void updateTopoRender(const QString& name) = 0; + virtual void drawTopoRender(int code) = 0; + + inline Algo::Render::GL2::TopoRender* getTopoRender() { return m_topoRender;} + +protected: + Algo::Render::GL2::TopoRender* m_topoRender; + /********************************************************* * SIGNALS *********************************************************/ @@ -186,6 +202,8 @@ protected: AttributeSet m_attribs[NB_ORBITS]; CellSelectorSet m_cellSelectors[NB_ORBITS]; + + }; @@ -235,6 +253,14 @@ public: void updateBB(const VertexAttribute& position); void updateBBDrawer(); + /********************************************************* + * MANAGE TOPO DRAWING + *********************************************************/ + void createTopoRender(CGoGN::Utils::GLSLShader* sh1); + void updateTopoRender(const QString& positionName); + void drawTopoRender(int code); + + /********************************************************* * MANAGE CELL SELECTORS *********************************************************/ @@ -252,6 +278,7 @@ protected: } // namespace CGoGN + #include "mapHandler.hpp" #endif diff --git a/SCHNApps/include/mapHandler.hpp b/SCHNApps/include/mapHandler.hpp index 0434cf74a..29937076a 100644 --- a/SCHNApps/include/mapHandler.hpp +++ b/SCHNApps/include/mapHandler.hpp @@ -1,3 +1,5 @@ +#include "Utils/Shaders/shaderColorPerVertex.h" +#include "Utils/Shaders/shaderSimpleColor.h" namespace CGoGN { @@ -21,7 +23,6 @@ inline QString MapHandlerGen::getAttributeTypeName(unsigned int orbit, const QSt - template unsigned int MapHandler::getNbDarts() { @@ -182,6 +183,51 @@ CellSelector* MapHandler::getCellSelector(const Q return NULL; } +template +void MapHandler::createTopoRender(CGoGN::Utils::GLSLShader* sh1) +{ +// std::cout << "MH:createTopo"<< std::endl; + if (m_topoRender) + return; + + if (m_map->dimension() == 2) + { + CGoGN::Utils::ShaderSimpleColor* ssc =static_cast(sh1); + + m_topoRender = new Algo::Render::GL2::TopoRender(ssc); + m_topoRender->setInitialDartsColor(0.25f, 0.25f, 0.25f) ; + } + else + std::cerr << "TOPO3 NOT SUPPORTED"<< std::endl; +} + +template +void MapHandler::updateTopoRender(const QString& positionName) +{ + if (m_topoRender==NULL) + return; + + typename PFP::MAP* map = this->getMap(); + + VertexAttribute position = map->getAttribute(positionName.toStdString()) ; + if(position.isValid()) + { + m_topoRender->updateData(*map,position,false); + + } +} + +template +void MapHandler::drawTopoRender(int code) +{ + if (m_topoRender == NULL) + return; + m_topoRender->drawTopo(code); +} + + + + } // namespace SCHNApps } // namespace CGoGN diff --git a/SCHNApps/include/view.h b/SCHNApps/include/view.h index 3500ded32..8573f9ee1 100644 --- a/SCHNApps/include/view.h +++ b/SCHNApps/include/view.h @@ -33,6 +33,9 @@ public: const QString& getName() const { return m_name; } + MapHandlerGen* lastSelectedMap() { return m_lastSelectedMap;} + void setLastSelectedMap(MapHandlerGen* m); + public slots: QString getName() { return m_name; } SCHNApps* getSCHNApps() const { return m_schnapps; } @@ -109,6 +112,7 @@ protected: Camera* m_currentCamera; QList l_plugins; QList l_maps; + MapHandlerGen* m_lastSelectedMap; ViewButtonArea* m_buttonArea; diff --git a/SCHNApps/src/controlDock_mapTab.cpp b/SCHNApps/src/controlDock_mapTab.cpp index a94cd1cda..3839ca633 100644 --- a/SCHNApps/src/controlDock_mapTab.cpp +++ b/SCHNApps/src/controlDock_mapTab.cpp @@ -77,6 +77,8 @@ void ControlDock_MapTab::selectedMapChanged() { if(!b_updatingUI) { + + if(m_selectedMap) { disconnect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&))); @@ -87,6 +89,7 @@ void ControlDock_MapTab::selectedMapChanged() } QList items = list_maps->selectedItems(); + if(!items.empty()) { MapHandlerGen* old = m_selectedMap; @@ -94,9 +97,12 @@ void ControlDock_MapTab::selectedMapChanged() QString selectedMapName = items[0]->text(); m_selectedMap = m_schnapps->getMap(selectedMapName); + items[0]->setCheckState(Qt::Checked); + updateSelectedMapInfo(); m_schnapps->notifySelectedMapChanged(old, m_selectedMap); + m_schnapps->getSelectedView()->setLastSelectedMap(m_selectedMap); connect(m_selectedMap, SIGNAL(attributeAdded(unsigned int, const QString&)), this, SLOT(selectedMapAttributeAdded(unsigned int, const QString&))); connect(m_selectedMap, SIGNAL(vboAdded(Utils::VBO*)), this, SLOT(selectedMapVBOAdded(Utils::VBO*))); @@ -104,6 +110,13 @@ void ControlDock_MapTab::selectedMapChanged() connect(m_selectedMap, SIGNAL(cellSelectorAdded(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorAdded(unsigned int, const QString&))); connect(m_selectedMap, SIGNAL(cellSelectorRemoved(unsigned int, const QString&)), this, SLOT(selectedMapCellSelectorRemoved(unsigned int, const QString&))); } + else + { + MapHandlerGen* old = m_selectedMap; + m_selectedMap = NULL; + m_schnapps->notifySelectedMapChanged(old,m_selectedMap); + m_schnapps->getSelectedView()->setLastSelectedMap(NULL); + } } } @@ -116,9 +129,16 @@ void ControlDock_MapTab::mapCheckStateChanged(QListWidgetItem *item) if(m) { if(item->checkState() == Qt::Checked) + { selectedView->linkMap(m); + if (m_selectedMap==NULL) + setSelectedMap(m->getName()); + } else + { selectedView->unlinkMap(m); + item->setSelected(false); + } } } } @@ -455,6 +475,15 @@ void ControlDock_MapTab::setSelectedMap(const QString& mapName) { lm[0]->setSelected(true); } + else + { + QList items = list_maps->selectedItems(); + if(!items.empty()) + { + m_selectedMap = NULL; + items[0]->setSelected(false); + } + } } diff --git a/SCHNApps/src/mapHandler.cpp b/SCHNApps/src/mapHandler.cpp index 00fa9145e..93c1d9d2e 100644 --- a/SCHNApps/src/mapHandler.cpp +++ b/SCHNApps/src/mapHandler.cpp @@ -12,7 +12,9 @@ MapHandlerGen::MapHandlerGen(const QString& name, SCHNApps* s, GenericMap* map) m_map(map), m_frame(NULL), m_bbDrawer(NULL), - m_render(NULL) + m_render(NULL), + m_topoRender(NULL) + { m_frame = new qglviewer::ManipulatedFrame(); } @@ -27,6 +29,8 @@ MapHandlerGen::~MapHandlerGen() delete m_render; foreach(CGoGN::Utils::VBO* vbo, m_vbo) delete vbo; + + deleteTopoRender(); } /********************************************************* @@ -252,6 +256,13 @@ void MapHandlerGen::unlinkView(View* view) l_views.removeOne(view); } + +void MapHandlerGen::deleteTopoRender() +{ + if (m_topoRender) + delete m_topoRender; +} + } // namespace SCHNApps } // namespace CGoGN diff --git a/SCHNApps/src/schnapps.cpp b/SCHNApps/src/schnapps.cpp index fa4d65321..b3721b74d 100644 --- a/SCHNApps/src/schnapps.cpp +++ b/SCHNApps/src/schnapps.cpp @@ -262,11 +262,45 @@ void SCHNApps::setSelectedView(View* view) m_pluginDockTabWidget->setCurrentIndex(currentTab); + + emit(selectedViewChanged(oldSelected, m_selectedView)); if(oldSelected) oldSelected->updateGL(); m_selectedView->updateGL(); + + // check if selected map is correct + + + if( (view->lastSelectedMap() != NULL) && (view->lastSelectedMap()->isLinkedToView(view))) + { + this->setSelectedMap(view->lastSelectedMap()->getName()); + } + else + { + MapHandlerGen* map = this->getSelectedMap(); + if ((map == NULL) || (! map->isLinkedToView(view))) + { + bool changed = false; + const MapSet& ms = this->getMapSet(); + foreach(MapHandlerGen* mhg,ms) + { + if (mhg->isLinkedToView(view)) + { + this->setSelectedMap(mhg->getName()); + changed = true; + break; // out of the loop, not nice but ... + } + } + if (!changed)// no possibility to selected a map automatically so none + { + setSelectedMap(QString("NONE")); + } + } + + } + } void SCHNApps::splitView(const QString& name, Qt::Orientation orientation) diff --git a/SCHNApps/src/view.cpp b/SCHNApps/src/view.cpp index 817204366..21c4540d9 100644 --- a/SCHNApps/src/view.cpp +++ b/SCHNApps/src/view.cpp @@ -25,6 +25,7 @@ View::View(const QString& name, SCHNApps* s, const QGLWidget* shareWidget) : m_name(name), m_schnapps(s), m_currentCamera(NULL), + m_lastSelectedMap(NULL), m_buttonArea(NULL), m_closeButton(NULL), m_VsplitButton(NULL), @@ -410,8 +411,15 @@ void View::updateCurrentCameraBB() void View::selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur) { +// m_lastSelectedMap = cur; if(cur && isLinkedToMap(cur)) + { setManipulatedFrame(cur->getFrame()); +// std::cout << "in view "<< this->getName().toStdString(); +// std::cout << " selectedMapChanged: "<< cur->getName().toStdString() << std::endl; + } +// else +// std::cout << "in view "<< this->getName().toStdString()<< " selectedMapChanged: NULL"<< std::endl; updateGL(); } @@ -430,6 +438,15 @@ void View::ui_closeView(int x, int y, int globalX, int globalY) m_schnapps->removeView(m_name); } +void View::setLastSelectedMap(MapHandlerGen* m) { + m_lastSelectedMap=m; + std::cout << "in view "<< this->getName().toStdString(); + if (m) + std::cout << " selectedMapChanged: "<< m->getName().toStdString() << std::endl; + else + std::cout << " selectedMapChanged: NULL"<< std::endl; +} + } // namespace SCHNApps } // namespace CGoGN diff --git a/include/Algo/Render/GL2/topoRender.h b/include/Algo/Render/GL2/topoRender.h index 19c8c3257..0983b3f7e 100644 --- a/include/Algo/Render/GL2/topoRender.h +++ b/include/Algo/Render/GL2/topoRender.h @@ -37,7 +37,7 @@ #include "Utils/svg.h" #include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderColorPerVertex.h" + namespace CGoGN { @@ -51,13 +51,12 @@ namespace Render namespace GL2 { -template -class TopoRender -{ - typedef typename PFP::MAP MAP; - typedef typename PFP::VEC3 VEC3; - typedef typename PFP::REAL REAL; + + + +class TopoGenRender +{ protected: /** * vbo buffers @@ -69,7 +68,7 @@ protected: Utils::VBO* m_vbo0; Utils::VBO* m_vbo1; Utils::VBO* m_vbo2; - Utils::VBO* m_vbo3; + unsigned int m_vaId; @@ -106,24 +105,28 @@ protected: /** * initial darts color (set in update) */ - Geom::Vec3f m_dartsColor; + Geom::Vec4f m_dartsColor; + Geom::Vec4f m_colorPhi1; + Geom::Vec4f m_colorPhi2; + Geom::Vec4f m_dartsBoundaryColor; - /** - * initial darts color (set in update) - */ - Geom::Vec3f m_dartsBoundaryColor; + Geom::Vec3f* m_bufferDartPosition; - float *m_color_save; + Utils::ShaderSimpleColor* m_shader1; - /** - * attribut d'index dans le VBO - */ - DartAttribute m_attIndex; + bool m_sharedShaders; - Geom::Vec3f* m_bufferDartPosition; + std::string m_nameIndex; + + + float m_ke; + float m_kf; + bool m_wb; + float m_ns; + + Geom::Vec4f colorPhi1; + Geom::Vec4f colorPhi2; - Utils::ShaderSimpleColor* m_shader1; - Utils::ShaderColorPerVertex* m_shader2; /** * compute color from dart index (for color picking) @@ -135,37 +138,35 @@ protected: */ void dartToCol(Dart d, float& r, float& g, float& b); - /** - * pick the color in the rendered image - */ - Dart pickColor(unsigned int x, unsigned int y); + class ColoredDart + { + public: + Dart d; + float r; + float g; + float b; + ColoredDart(Dart dd, float rr, float gg, float bb): + d(dd),r(rr),g(gg),b(bb) {} - /** - * affect a color to each dart - */ - void setDartsIdColor(MAP& map, bool withBoundary); + }; + + std::vector m_coloredDarts; - /** - * save colors before picking - */ - void pushColors(); - /** - * restore colors after picking - */ - void popColors(); public: /** * Constructor * @param bs shift for boundary drawing */ - TopoRender(float bs = 0.01f); + TopoGenRender(float bs = 0.01f); + + TopoGenRender(Utils::ShaderSimpleColor* ssc, float bs = 0.01f); /** * Destructor */ - ~TopoRender(); + ~TopoGenRender(); /** * set the with of line use to draw darts (default val is 2) @@ -179,6 +180,10 @@ public: */ void setRelationWidth(float pw); + void setColorPhi1(const Geom::Vec4f& col); + + void setColorPhi2(const Geom::Vec4f& col); + /** * Drawing function for darts only */ @@ -196,23 +201,15 @@ public: /** * draw all topo + * @param code bit 0: draw darts/ bit 1 drawRelation1 / bit 2 drawRelation2(); */ - void drawTopo(); + void drawTopo(int code=0xf); /** * get shader objects */ Utils::GLSLShader* shader1() { return static_cast(m_shader1); } - Utils::GLSLShader* shader2() { return static_cast(m_shader2); } - /** - * change dart drawing color - * @param d the dart - * @param r red ! - * @param g green ! - * @param b blue ! - */ - void setDartColor(Dart d, float r, float g, float b); /** * change all darts drawing color @@ -227,6 +224,84 @@ public: void setInitialBoundaryDartsColor(float r, float g, float b); + + /** + * pick the color in the rendered image + */ + Dart pickColor(unsigned int x, unsigned int y); + + + /** + * render to svg struct + */ + void toSVG(Utils::SVG::SVGOut& svg); + + /** + * 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); + + void setExplodeEdge(float ke); + + void setExplodeFace(float kf); + + void setWithBoundary(bool wb); + + + /** + * @brief add dart to set of colored dart to draw + * @param d + * @param r + * @param g + * @param b + */ + void addColoredDart(Dart d, float r, float g, float b); + + /** + * @brief clear the ColoredDarts set + * @param d + */ + inline void clearColoredDarts() { m_coloredDarts.clear();} + + /** + * @brief remove a dart the ColoredDarts set + * @param d + */ + void removeColoredDart(Dart d); + +}; + + + +//template +class TopoRender : public TopoGenRender +{ +public: + /** + * Constructor + * @param bs shift for boundary drawing + */ + TopoRender(float bs = 0.01f): TopoGenRender(bs) {} + + TopoRender(Utils::ShaderSimpleColor* ssc, float bs = 0.01f) :TopoGenRender(ssc,bs) {} + + /** + * Destructor + */ + ~TopoRender() {} + /** * redraw one dart with specific width and color (not efficient use only for debug with small amount of call) * @param d the dart @@ -235,7 +310,8 @@ public: * @param g green ! * @param b blue ! */ - void overdrawDart(Dart d, float width, float r, float g, float b); + template + void overdrawDart(MAP& map, Dart d, float width, float r, float g, float b); /** * pick dart with color set by setDartsIdColor @@ -245,66 +321,45 @@ public: * @param y position of mouse (pass H-y, classic pb of origin) * @return the dart or NIL */ + template Dart picking(MAP& map, int x, int y, bool withBoundary=false); + template Dart coneSelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle); + template Dart raySelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float distmax); - virtual void updateData(MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false, bool onlyBoundary=false) = 0; - /** - * Special update function used to draw boundary of map3 - */ - void updateDataBoundary(MAP& map, const VertexAttribute& positions, float ke, float kf, float ns); + template + void updateData(typename PFP::MAP &map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false, bool onlyBoundary=false); - /** - * render to svg struct - */ - void toSVG(Utils::SVG::SVGOut& svg); + template + void updateData(typename PFP::MAP &map, const VertexAttribute& positions, bool onlyBoundary=false); - /** - * 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) + * Special update function used to draw boundary of map3 */ - void setNormalShift(float ns); + template + void updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float ns); - /** - * @brief set boundary shift for boundary of dim 2 drawing - * @param ns distance shift - */ - void setBoundaryShift(float bs); -}; + template + void updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions); -template -class TopoRenderMap : public TopoRender -{ - typedef typename PFP::MAP MAP; - typedef typename PFP::VEC3 VEC3; - typedef typename PFP::REAL REAL; -public: - TopoRenderMap(float bs = 0.01f) : TopoRender(bs) {} - void updateData(MAP &map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false, bool onlyBoundary=false); -}; + template + void updateDataGMap(typename PFP::MAP &map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false, bool onlyBoundary=false); -template -class TopoRenderGMap : public TopoRender -{ - typedef typename PFP::MAP MAP; - typedef typename PFP::VEC3 VEC3; - typedef typename PFP::REAL REAL; + template + void updateDataGMap(typename PFP::MAP &map, const VertexAttribute& positions, bool onlyBoundary=false); -public: - TopoRenderGMap(float bs = 0.01f) : TopoRender(bs) {} - void updateData(MAP &map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false, bool onlyBoundary=false); + + template + void drawColoredDarts(MAP& map); }; + } // namespace GL2 } // namespace Render diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index 2d0eaaf4b..6a7d5ca41 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -36,6 +36,7 @@ #include "Algo/Geometry/normal.h" #include "Container/containerBrowser.h" +#include "Utils/Shaders/shaderColorPerVertex.h" namespace CGoGN { @@ -49,179 +50,15 @@ namespace Render namespace GL2 { -template -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(); - m_vbo1 = new Utils::VBO(); - m_vbo2 = new Utils::VBO(); - m_vbo3 = new Utils::VBO(); - - m_vbo0->setDataSize(3); - m_vbo1->setDataSize(3); - m_vbo2->setDataSize(3); - m_vbo3->setDataSize(3); - - m_shader1 = new Utils::ShaderSimpleColor(); - m_shader2 = new Utils::ShaderColorPerVertex(); - - // binding VBO - VA - m_vaId = m_shader1->setAttributePosition(m_vbo1); - - m_shader2->setAttributePosition(m_vbo0); - m_shader2->setAttributeColor(m_vbo3); - - // registering for auto matrices update - Utils::GLSLShader::registerShader(NULL, m_shader1); - Utils::GLSLShader::registerShader(NULL, m_shader2); -} - -template -TopoRender::~TopoRender() -{ - Utils::GLSLShader::unregisterShader(NULL, m_shader2); - Utils::GLSLShader::unregisterShader(NULL, m_shader1); - - delete m_shader2; - delete m_shader1; - delete m_vbo3; - delete m_vbo2; - delete m_vbo1; - delete m_vbo0; - - if (m_attIndex.isValid()) - m_attIndex.map()->removeAttribute(m_attIndex); - - if (m_bufferDartPosition!=NULL) - delete[] m_bufferDartPosition; -} - -template -void TopoRender::setDartWidth(float dw) -{ - m_topo_dart_width = dw; -} - -template -void TopoRender::setRelationWidth(float pw) -{ - m_topo_relation_width = pw; -} - -template -void TopoRender::setDartColor(Dart d, float r, float g, float b) -{ - float RGB[6]; - RGB[0]=r; RGB[1]=g; RGB[2]=b; - RGB[3]=r; RGB[4]=g; RGB[5]=b; - m_vbo3->bind(); - glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); -} - -template -void TopoRender::setAllDartsColor(float r, float g, float b) -{ - m_vbo3->bind(); - GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - for (unsigned int i=0; i < 2*m_nbDarts; ++i) - { - *colorDartBuf++ = r; - *colorDartBuf++ = g; - *colorDartBuf++ = b; - } - - m_vbo3->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); -} - -template -void TopoRender::setInitialDartsColor(float r, float g, float b) -{ - m_dartsColor = Geom::Vec3f(r,g,b); -} - -template -void TopoRender::setInitialBoundaryDartsColor(float r, float g, float b) -{ - m_dartsBoundaryColor = Geom::Vec3f(r,g,b); -} - -template -void TopoRender::drawDarts() -{ - if (m_nbDarts==0) - return; - - m_shader2->enableVertexAttribs(); - - glLineWidth(m_topo_dart_width); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - // change the stride to take 1/2 vertices - m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); - - glPointSize(2.0f*m_topo_dart_width); - glDrawArrays(GL_POINTS, 0, m_nbDarts); - - m_shader2->disableVertexAttribs(); -} - -template -void TopoRender::drawRelation1() -{ - if (m_nbDarts==0) - return; - - glLineWidth(m_topo_relation_width); - - m_shader1->changeVA_VBO(m_vaId, m_vbo1); - m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - m_shader1->disableVertexAttribs(); -} - -template -void TopoRender::drawRelation2() +template +void TopoRender::overdrawDart(MAP& map, Dart d, float width, float r, float g, float b) { - if (m_nbRel2==0) - return; - - glLineWidth(m_topo_relation_width); - - m_shader1->changeVA_VBO(m_vaId, m_vbo2); - m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_LINES, 0, m_nbRel2*2); - - m_shader1->disableVertexAttribs(); -} + DartAttribute attIndex = map.template getAttribute(m_nameIndex); + if (!attIndex.isValid()) + attIndex = map.template addAttribute(m_nameIndex); -template -void TopoRender::drawTopo() -{ - drawDarts(); - drawRelation1(); - drawRelation2(); -} -template -void TopoRender::overdrawDart(Dart d, float width, float r, float g, float b) -{ - unsigned int indexDart = m_attIndex[d]; + unsigned int indexDart = attIndex[d]; m_shader1->changeVA_VBO(m_vaId, m_vbo0); m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); @@ -233,257 +70,98 @@ void TopoRender::overdrawDart(Dart d, float width, float r, float g, float glPointSize(2.0f*width); glDrawArrays(GL_POINTS, indexDart, 1); - m_shader2->disableVertexAttribs(); -} - -template -Dart TopoRender::colToDart(float* color) -{ - unsigned int r = (unsigned int)(color[0]*255.0f); - unsigned int g = (unsigned int)(color[1]*255.0f); - unsigned int b = (unsigned int)(color[2]*255.0f); - - unsigned int id = r + 255*g +255*255*b; - - if (id == 0) - return NIL; - return Dart(id-1); + m_shader1->disableVertexAttribs(); } -template -void TopoRender::dartToCol(Dart d, float& r, float& g, float& b) -{ - // here use d.index beacause it is what we want (and not map.dartIndex(d) !!) - unsigned int lab = d.index + 1; // add one to avoid picking the black of screen - - r = float(lab%255) / 255.0f; lab = lab/255; - g = float(lab%255) / 255.0f; lab = lab/255; - b = float(lab%255) / 255.0f; lab = lab/255; - if (lab!=0) - CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; -} -template -Dart TopoRender::pickColor(unsigned int x, unsigned int y) +template +void TopoRender::drawColoredDarts(MAP& map) { - //more easy picking for - unsigned int dw = m_topo_dart_width; - m_topo_dart_width+=2; - - // save clear color and set to zero - float cc[4]; - glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); - - glClearColor(0.0f,0.0f,0.0f,0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glDisable(GL_LIGHTING); - // draw in back buffer (not shown on screen) - drawDarts(); - - // restore dart width - m_topo_dart_width = dw; - - // read the pixel under the mouse in back buffer - glReadBuffer(GL_BACK); - float color[3]; - glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); - - glClearColor(cc[0], cc[1], cc[2], cc[3]); + DartAttribute attIndex = map.template getAttribute(m_nameIndex); + if (!attIndex.isValid()) + return; - return colToDart(color); -} + glLineWidth(m_topo_dart_width); + float ps = 2.0f*m_topo_dart_width; -template -void TopoRender::pushColors() -{ - m_color_save = new float[6*m_nbDarts]; - m_vbo3->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->enableVertexAttribs(); - memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); -} + for (auto it=m_coloredDarts.begin(); it != m_coloredDarts.end(); ++it) + { + unsigned int indexDart = attIndex[it->d]; -template -void TopoRender::popColors() -{ - m_vbo3->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_shader1->setColor(Geom::Vec4f(it->r,it->g,it->b,0.0f)); + m_shader1->enableVertexAttribs(); + glDrawArrays(GL_LINES, indexDart, 2); - memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); + glPointSize(ps); + glDrawArrays(GL_POINTS, indexDart, 1); + } + m_shader1->disableVertexAttribs(); - delete[] m_color_save; - m_color_save=NULL; } -template -void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) -{ - Utils::SVG::SVGOut svg(filename,model,proj); - toSVG(svg); - svg.write(); -} -template -void TopoRender::toSVG(Utils::SVG::SVGOut& svg) -{ -// svg.setWidth(m_topo_relation_width); -// -// // PHI2 / beta2 -// const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); -// svg.beginLines(); -// for (unsigned int i=0; ireleasePtr(); -// -// //PHI1 /beta1 -// ptr = reinterpret_cast(m_vbo1->lockPtr()); -// svg.beginLines(); -// for (unsigned int i=0; ireleasePtr(); -// -// -// const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); -// ptr= reinterpret_cast(m_vbo0->lockPtr()); -// -// svg.setWidth(m_topo_dart_width); -// svg.beginLines(); -// for (unsigned int i=0; ireleasePtr(); -// m_vbo3->releasePtr(); - - // PHI2 / beta2 - Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); - svg1->setToLayer(); - const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); - svg1->setWidth(m_topo_relation_width); - svg1->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.8f,0.0f,0.0f)); - svg1->endLines(); - m_vbo2->releasePtr(); - - svg.addGroup(svg1); - - //PHI1 /beta1 - Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); - svg2->setToLayer(); - ptr = reinterpret_cast(m_vbo1->lockPtr()); - svg2->setWidth(m_topo_relation_width); - svg2->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); - svg2->endLines(); - m_vbo1->releasePtr(); - - svg.addGroup(svg2); - - const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); - ptr= reinterpret_cast(m_vbo0->lockPtr()); - - Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); - svg3->setToLayer(); - svg3->setWidth(m_topo_dart_width); - svg3->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1], colorsPtr[2*i]); - svg3->endLines(); - - svg.addGroup(svg3); - - Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); - svg4->setWidth(m_topo_dart_width); - svg4->setToLayer(); - svg4->beginPoints(); - for (unsigned int i=0; iaddPoint(ptr[2*i], colorsPtr[2*i]); - svg4->endPoints(); - - svg.addGroup(svg4); - - m_vbo0->releasePtr(); - m_vbo3->releasePtr(); -} template -void TopoRender::setNormalShift(float ns) +void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions) { - m_normalShift = ns; + updateDataBoundary(map,positions,m_ke,m_kf,m_ns); } -template -void TopoRender::setBoundaryShift(float bs) -{ - m_boundShift = bs; -} template -void TopoRender::updateDataBoundary(MAP& map, const VertexAttribute& positions, float ke, float kf, float ns) +void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float ns) { m_normalShift = ns; - SelectorDartBoundary sdb(map); - DartContainerBrowserSelector browser(map, sdb); + SelectorDartBoundary sdb(map); + DartContainerBrowserSelector browser(map, sdb); browser.enable(); - updateData(map, positions, ke, kf, false,true); // false,true because we are drawing the boundary of a 3map + this->updateData(map, positions, ke, kf, false,true); // false,true because we are drawing the boundary of a 3map browser.disable(); m_normalShift = 0.0f; } - +template +void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, bool onlyBoundary) +{ + updateData(map,positions,m_ke,m_kf,m_wb,onlyBoundary); +} template -void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& positions, float ke, float kf, bool withBoundary, bool onlyBoundary) +void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary, bool onlyBoundary) { - std::string name_index("dart_index2"); + typedef typename PFP::MAP MAP; + typedef typename PFP::VEC3 VEC3; + typedef typename PFP::REAL REAL; + + std::string name_index(this->m_nameIndex); if (onlyBoundary) name_index = std::string("dart_boundary_index2"); std::vector vecDarts; - vecDarts.reserve(mapx.getNbDarts()); // no problem dart is int: no problem of memory + vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory - this->m_attIndex = mapx.template getAttribute(name_index); + DartAttribute attIndex = map.template getAttribute(name_index); + if (!attIndex.isValid()) + attIndex = map.template addAttribute(name_index); - if (!this->m_attIndex.isValid()) - this->m_attIndex = mapx.template addAttribute(name_index); - for(Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) + for(Dart d = map.begin(); d != map.end(); map.next(d)) { - if (withBoundary || !mapx.template isBoundaryMarked<2>(d)) + if (withBoundary || !map.template isBoundaryMarked<2>(d)) vecDarts.push_back(d); } this->m_nbDarts = vecDarts.size(); // debut phi1 - DartAutoAttribute fv1(mapx); + DartAutoAttribute fv1(map); // fin phi1 - DartAutoAttribute fv11(mapx); + DartAutoAttribute fv11(map); // phi2 - DartAutoAttribute fv2(mapx); - - this->m_vbo3->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*this->m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); - GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - Geom::Vec3f* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - -// m_vbo0->bind(); -// glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); -// GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); -// VEC3* positionDartBuf = reinterpret_cast(PositionDartsBuffer); + DartAutoAttribute fv2(map); if (this->m_bufferDartPosition!=NULL) delete this->m_bufferDartPosition; @@ -495,28 +173,28 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& unsigned int indexDC = 0; - DartMarker mf(mapx); + DartMarker mf(map); for(std::vector::iterator id = vecDarts.begin(); id != vecDarts.end(); id++) { Dart d = *id; if (!mf.isMarked(d)) { vecPos.clear(); - if (!mapx.template isBoundaryMarked<2>(d)) + if (!map.template isBoundaryMarked<2>(d)) { - //VEC3 center = Algo::Surface::Geometry::faceCentroidELW(mapx,d,positions); - VEC3 center = Algo::Surface::Geometry::faceCentroid(mapx,d,positions); + //VEC3 center = Algo::Surface::Geometry::faceCentroidELW(map,d,positions); + VEC3 center = Algo::Surface::Geometry::faceCentroid(map,d,positions); float k = 1.0f - kf; Dart dd = d; do { vecPos.push_back(center*k + positions[dd]*kf); - dd = mapx.phi1(dd); + dd = map.phi1(dd); } while (dd != d); if (this->m_normalShift > 0.0f) { - VEC3 normal = Algo::Surface::Geometry::newellNormal(mapx,d,positions); + VEC3 normal = Algo::Surface::Geometry::newellNormal(map,d,positions); for (typename std::vector::iterator pit = vecPos.begin(); pit != vecPos.end(); ++pit) { *pit -= normal * this->m_normalShift; @@ -533,19 +211,17 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& VEC3 P = vecPos[i]*ke + vecPos[i+1]*k; VEC3 Q = vecPos[i+1]*ke + vecPos[i]*k; - this->m_attIndex[d] = indexDC; + attIndex[d] = indexDC; indexDC+=2; *positionDartBuf++ = PFP::toVec3f(P); *positionDartBuf++ = PFP::toVec3f(Q); - *colorDartBuf++ = this->m_dartsColor; - *colorDartBuf++ = this->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 = mapx.phi1(d); + d = map.phi1(d); } mf.template markOrbit(d); } @@ -554,16 +230,16 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& 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); + Dart ee = map.phi2(dd); + VEC3 normal = Algo::Surface::Geometry::newellNormal(map,ee,positions); + VEC3 vd = Algo::Surface::Geometry::vectorOutOfDart(map,ee,positions); VEC3 v = vd ^ normal; v.normalize(); - VEC3 P = positions[mapx.phi1(ee)] + v* this->m_boundShift; + VEC3 P = positions[map.phi1(ee)] + v* this->m_boundShift; vecPos.push_back(P); - dd = mapx.phi1(dd); - ee = mapx.phi2(dd); - P = positions[mapx.phi1(ee)] + v* this->m_boundShift; + dd = map.phi1(dd); + ee = map.phi2(dd); + P = positions[map.phi1(ee)] + v* this->m_boundShift; vecPos.push_back(P); } while (dd != d); @@ -575,19 +251,17 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& VEC3 P = vecPos[2*i]*ke + vecPos[2*i+1]*k; VEC3 Q = vecPos[2*i+1]*ke + vecPos[2*i]*k; - this->m_attIndex[d] = indexDC; + attIndex[d] = indexDC; indexDC+=2; *positionDartBuf++ = PFP::toVec3f(P); *positionDartBuf++ = PFP::toVec3f(Q); - *colorDartBuf++ = this->m_dartsBoundaryColor; - *colorDartBuf++ = this->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 = mapx.phi1(d); + d = map.phi1(d); } mf.template markOrbit(d); } @@ -596,10 +270,7 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& this->m_vbo0->bind(); glBufferData(GL_ARRAY_BUFFER, 2*this->m_nbDarts*sizeof(Geom::Vec3f), this->m_bufferDartPosition, GL_STREAM_DRAW); -// glUnmapBuffer(GL_ARRAY_BUFFER); - this->m_vbo3->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); this->m_vbo1->bind(); glBufferData(GL_ARRAY_BUFFER, 2*this->m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); @@ -617,17 +288,17 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& { Dart d = *id; - Dart e = mapx.phi2(d); + Dart e = map.phi2(d); // if (good(e) && (e.index > d.index)) - if ( (withBoundary || !mapx.template isBoundaryMarked<2>(e)) && (e.index > d.index)) + if ( (withBoundary || !map.template isBoundaryMarked<2>(e)) && (e.index > d.index)) { *positionF2++ = PFP::toVec3f(fv2[d]); *positionF2++ = PFP::toVec3f(fv2[e]); this->m_nbRel2++; } - e = mapx.phi1(d); + e = map.phi1(d); *positionF1++ = PFP::toVec3f(fv1[d]); *positionF1++ = PFP::toVec3f(fv11[e]); } @@ -642,23 +313,41 @@ void TopoRenderMap::updateData(MAP& mapx, const VertexAttribute& template -void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary, bool onlyBoundary) +void TopoRender::updateDataGMap(typename PFP::MAP& map, const VertexAttribute& positions, bool onlyBoundary) { -// GMap2& map = dynamic_cast(mapx); + updateDataGMap(map,positions,m_ke,m_kf,m_wb,onlyBoundary); +} + +template +void TopoRender::updateDataGMap(typename PFP::MAP& dmap, const VertexAttribute& positions, float ke, float kf, bool withBoundary, bool onlyBoundary) +{ + + // compilation trick to bypass compilation problems + + struct GPFP:public PFP + { + typedef EmbeddedGMap2 MAP; + }; + + typedef typename GPFP::MAP MAP; + typedef typename GPFP::VEC3 VEC3; + typedef typename GPFP::REAL REAL; + + + MAP& map = reinterpret_cast(dmap); std::vector vecDarts; vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory - std::string name_index("dart_index2"); + std::string name_index(this->m_nameIndex); if (onlyBoundary) name_index = std::string("dart_boundary_index2"); - if (this->m_attIndex.map() != &map) - this->m_attIndex = map.template getAttribute(name_index); + DartAttribute attIndex = map.template getAttribute(name_index); + if (!attIndex.isValid()) + attIndex = map.template addAttribute(name_index); - if (!this->m_attIndex.isValid()) - this->m_attIndex = map.template addAttribute(name_index); for(Dart d = map.begin(); d != map.end(); map.next(d)) { @@ -674,11 +363,6 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& // phi2 DartAutoAttribute fv2(map); - this->m_vbo3->bind(); - glBufferData(GL_ARRAY_BUFFER, 4*this->m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); - GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - Geom::Vec3f* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - this->m_vbo0->bind(); glBufferData(GL_ARRAY_BUFFER, 4*this->m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); @@ -697,7 +381,7 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& if (!mf.isMarked(d)) { vecPos.clear(); - VEC3 center = Algo::Surface::Geometry::faceCentroidELW(map, d, positions); + VEC3 center = Algo::Surface::Geometry::faceCentroidELW(map, d, positions); float k = 1.0f - kf; Dart dd = d; @@ -710,7 +394,7 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& if (this->m_normalShift > 0.0f) { - VEC3 normal = Algo::Surface::Geometry::newellNormal(map, d, positions); + VEC3 normal = Algo::Surface::Geometry::newellNormal(map, d, positions); for (typename std::vector::iterator pit = vecPos.begin(); pit != vecPos.end(); ++pit) { *pit -= normal * this->m_normalShift; @@ -727,17 +411,12 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& VEC3 PP = REAL(0.52)*P + REAL(0.48)*Q; VEC3 QQ = REAL(0.52)*Q + REAL(0.48)*P; - this->m_attIndex[d] = indexDC; + attIndex[d] = indexDC; indexDC+=2; - *positionDartBuf++ = PFP::toVec3f(P); - *colorDartBuf++ = this->m_dartsColor; - *positionDartBuf++ = PFP::toVec3f(PP); - *colorDartBuf++ = this->m_dartsColor; - *positionDartBuf++ = PFP::toVec3f(Q); - *colorDartBuf++ = this->m_dartsColor; - *positionDartBuf++ = PFP::toVec3f(QQ); - *colorDartBuf++ = this->m_dartsColor; - + *positionDartBuf++ = GPFP::toVec3f(P); + *positionDartBuf++ = GPFP::toVec3f(PP); + *positionDartBuf++ = GPFP::toVec3f(Q); + *positionDartBuf++ = GPFP::toVec3f(QQ); VEC3 f = P*0.5f + PP*0.5f; fv2[d] = f; f = P*0.9f + PP*0.1f; @@ -748,7 +427,7 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& fv2[dd] = f; f = Q*0.9f + QQ*0.1f; fv1[dd] = f; - this->m_attIndex[dd] = indexDC; + attIndex[dd] = indexDC; indexDC+=2; d = map.phi1(d); @@ -760,9 +439,6 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& this->m_vbo0->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); - this->m_vbo3->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); - this->m_vbo1->bind(); glBufferData(GL_ARRAY_BUFFER, 2*this->m_nbDarts*sizeof(Geom::Vec3f), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer1 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); @@ -782,14 +458,14 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& // if (d < e ) if ( (withBoundary || !map.template isBoundaryMarked<2>(e)) && (d < e )) { - *positionF2++ = PFP::toVec3f(fv2[d]); - *positionF2++ = PFP::toVec3f(fv2[e]); + *positionF2++ = GPFP::toVec3f(fv2[d]); + *positionF2++ = GPFP::toVec3f(fv2[e]); this->m_nbRel2++; } e = map.beta1(d); - *positionF1++ = PFP::toVec3f(fv1[d]); - *positionF1++ = PFP::toVec3f(fv1[e]); + *positionF1++ = GPFP::toVec3f(fv1[d]); + *positionF1++ = GPFP::toVec3f(fv1[e]); } this->m_nbRel1 = vecDarts.size()/2; @@ -800,18 +476,25 @@ void TopoRenderGMap::updateData(MAP& map, const VertexAttribute& glUnmapBuffer(GL_ARRAY_BUFFER); } -template -void TopoRender::setDartsIdColor(MAP& map, bool withBoundary) + + +template +Dart TopoRender::picking(MAP& map,int x, int y, bool withBoundary) { - m_vbo3->bind(); + + Utils::VBO vboCol; + vboCol.setDataSize(3); + + vboCol.bind(); + glBufferData(GL_ARRAY_BUFFER, 2*this->m_nbDarts*sizeof(Geom::Vec3f), NULL, GL_STREAM_DRAW); float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); unsigned int nb = 0; - m_attIndex = map.template getAttribute("dart_index2"); - if (!m_attIndex.isValid()) + DartAttribute attIndex = map.template getAttribute(m_nameIndex); + if (!attIndex.isValid()) { CGoGNerr << "Error attribute_dartIndex does not exist during TopoRender::picking" << CGoGNendl; - return; + return NIL; } for (Dart d = map.begin(); d != map.end(); map.next(d)) @@ -823,7 +506,7 @@ void TopoRender::setDartsIdColor(MAP& map, bool withBoundary) { float r,g,b; dartToCol(d, r,g,b); - float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO + float* local = colorBuffer+3*attIndex[d]; // get the right position in VBO *local++ = r; *local++ = g; *local++ = b; @@ -841,21 +524,89 @@ void TopoRender::setDartsIdColor(MAP& map, bool withBoundary) } } glUnmapBuffer(GL_ARRAY_BUFFER); -} -template -Dart TopoRender::picking(MAP& map,int x, int y, bool withBoundary) -{ - pushColors(); - setDartsIdColor(map,withBoundary); - Dart d = pickColor(x,y); - popColors(); + + Utils::ShaderColorPerVertex shaderCol; + shaderCol.setAttributePosition(m_vbo0); + shaderCol.setAttributeColor(&vboCol); + shaderCol.updateMatrices(m_shader1); + + unsigned int dw = m_topo_dart_width; + m_topo_dart_width+=2; + + // save clear color and set to zero + float cc[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); + + glClearColor(0.0f,0.0f,0.0f,0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + // draw in back buffer (not shown on screen) + + shaderCol.enableVertexAttribs(); + + glLineWidth(m_topo_dart_width); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + // change the stride to take 1/2 vertices + shaderCol.enableVertexAttribs(6*sizeof(GL_FLOAT)); + + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + shaderCol.disableVertexAttribs(); + + // restore dart width + m_topo_dart_width = dw; + + // read the pixel under the mouse in back buffer + glReadBuffer(GL_BACK); + float color[3]; + glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); + + glClearColor(cc[0], cc[1], cc[2], cc[3]); + + Dart d = colToDart(color); + return d; + + } -template -Dart TopoRender::coneSelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) + + + + + + + + + + + + + + + + + + + + + + + + + +//template +template +Dart TopoRender::coneSelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) { + DartAttribute attIndex = map.template getAttribute(m_nameIndex); + if (!attIndex.isValid()) + attIndex = map.template addAttribute(m_nameIndex); + float AB2 = rayAB*rayAB; Dart dFinal; double sin2 = sin(M_PI/180.0 * angle); @@ -865,8 +616,8 @@ Dart TopoRender::coneSelection(MAP& map, const Geom::Vec3f& rayA, const Geo for(Dart d = map.begin(); d!=map.end(); map.next(d)) { // get back position of segment PQ - const Geom::Vec3f& P = m_bufferDartPosition[m_attIndex[d]]; - const Geom::Vec3f& Q =m_bufferDartPosition[m_attIndex[d]+1]; + const Geom::Vec3f& P = m_bufferDartPosition[attIndex[d]]; + const Geom::Vec3f& Q =m_bufferDartPosition[attIndex[d]+1]; float ld2 = Geom::squaredDistanceLine2Seg(rayA, rayAB, AB2, P, Q); Geom::Vec3f V = (P+Q)/2.0f - rayA; double d2 = double(V*V); @@ -883,9 +634,14 @@ Dart TopoRender::coneSelection(MAP& map, const Geom::Vec3f& rayA, const Geo return dFinal; } -template -Dart TopoRender::raySelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) +//template +template +Dart TopoRender::raySelection(MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) { + DartAttribute attIndex = map.template getAttribute(m_nameIndex); + if (!attIndex.isValid()) + attIndex = map.template addAttribute(m_nameIndex); + float AB2 = rayAB*rayAB; Dart dFinal; float dm2 = dmax*dmax; @@ -894,8 +650,8 @@ Dart TopoRender::raySelection(MAP& map, const Geom::Vec3f& rayA, const Geom for(Dart d = map.begin(); d!=map.end(); map.next(d)) { // get back position of segment PQ - const Geom::Vec3f& P = m_bufferDartPosition[m_attIndex[d]]; - const Geom::Vec3f& Q =m_bufferDartPosition[m_attIndex[d]+1]; + const Geom::Vec3f& P = m_bufferDartPosition[attIndex[d]]; + const Geom::Vec3f& Q =m_bufferDartPosition[attIndex[d]+1]; float ld2 = Geom::squaredDistanceLine2Seg(rayA, rayAB, AB2, P, Q); if (ld2::phi(Dart d) const } switch(N%10) { - case 1 : return phi1(phi(d)) ; + case 1 : return this->phi1(phi(d)) ; case 2 : return phi2(phi(d)) ; default : assert(!"Wrong multi-phi relation value") ; return d ; } diff --git a/include/Utils/GLSLShader.h b/include/Utils/GLSLShader.h index 88b1773b0..1b6f2c369 100644 --- a/include/Utils/GLSLShader.h +++ b/include/Utils/GLSLShader.h @@ -391,6 +391,7 @@ public: */ void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview, const glm::mat4& PMV, const glm::mat4& normalMatrix); + void updateMatrices(const Utils::GLSLShader *sh); /** * bind, enable, and set all vertex attrib pointers diff --git a/include/Utils/Shaders/shaderSimpleFlat.frag b/include/Utils/Shaders/shaderSimpleFlat.frag new file mode 100644 index 000000000..07fb4c7f0 --- /dev/null +++ b/include/Utils/Shaders/shaderSimpleFlat.frag @@ -0,0 +1,51 @@ +//ShaderSimpleFlat::fragmentShaderText + +PRECISON; +VARYING_FRAG vec3 LightDir; +VARYING_VERT vec3 Position; +#ifdef WITH_COLOR +VARYING_FRAG vec3 Color; +#endif +uniform vec4 materialDiffuse; +uniform vec4 materialSpecular; +uniform vec4 materialAmbient; +uniform float shininess; +FRAG_OUT_DEF; +void main() +{ + vec3 DX = dFdx(Position); + vec3 DY = dFdy(Position); + vec3 N=normalize(cross(DX,DY)); + + vec3 L = normalize (LightDir); + + vec4 finalColor = materialAmbient; + +#ifdef DOUBLE_SIDED + float lambertTerm; + vec4 diffuseColor = materialDiffuse; + if (!gl_FrontFacing) + { + N *= -1.0; + lambertTerm = clamp(dot(N,L),0.0,1.0); + } + else + lambertTerm = clamp(dot(N,L),0.0,1.0); +#ifndef WITH_COLOR + finalColor += materialDiffuse * lambertTerm; +#else + finalColor += vec4((Color*lambertTerm),0.0) ; +#endif +#else + float lambertTerm = clamp(dot(N,L),0.0,1.0); + if (gl_FrontFacing) + { +#ifndef WITH_COLOR + finalColor += materialDiffuse * lambertTerm; +#else + finalColor += vec4((Color*lambertTerm),0.0) ; +#endif + } +#endif + gl_FragColor=finalColor; +} diff --git a/include/Utils/Shaders/shaderSimpleFlat.h b/include/Utils/Shaders/shaderSimpleFlat.h new file mode 100644 index 000000000..e731c6dd2 --- /dev/null +++ b/include/Utils/Shaders/shaderSimpleFlat.h @@ -0,0 +1,105 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef __CGOGN_SHADER_SFLAT__ +#define __CGOGN_SHADER_SFLAT__ + +#include "Utils/GLSLShader.h" +#include "Utils/clippingShader.h" +#include "Geometry/vector_gen.h" + +#include + +namespace CGoGN +{ + +namespace Utils +{ + +class ShaderSimpleFlat : public ClippingShader +{ +protected: + // flag color per vertex or not + bool m_with_color; + // flag color per vertex or not + bool m_with_eyepos; + + // shader sources OGL3 + static std::string vertexShaderText; + static std::string fragmentShaderText; + + // uniform locations + CGoGNGLuint m_unif_ambiant; + CGoGNGLuint m_unif_diffuse; + CGoGNGLuint m_unif_lightPos; + + //values + Geom::Vec4f m_ambiant; + Geom::Vec4f m_diffuse; + Geom::Vec3f m_lightPos; + + VBO* m_vboPos; + VBO* m_vboColor; + + void getLocations(); + + void sendParams(); + + void restoreUniformsAttribs(); + +public: + ShaderSimpleFlat(bool doubleSided = false); + + // inviduals parameter setting functions + void setAmbiant(const Geom::Vec4f& ambiant); + + void setDiffuse(const Geom::Vec4f& diffuse); + + + void setLightPosition(const Geom::Vec3f& lp); + + const Geom::Vec4f& getAmbiant() const { return m_ambiant; } + + const Geom::Vec4f& getDiffuse() const { return m_diffuse; } + + const Geom::Vec3f& getLightPosition() const { return m_lightPos; } + + /** + * set all parameter in on call (one bind also) + */ + void setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos); + + // attributes + unsigned int setAttributePosition(VBO* vbo); + + // optional attributes + unsigned int setAttributeColor(VBO* vbo); + void unsetAttributeColor(); +}; + +} // namespace Utils + +} // namespace CGoGN + +#endif diff --git a/include/Utils/Shaders/shaderSimpleFlat.vert b/include/Utils/Shaders/shaderSimpleFlat.vert new file mode 100644 index 000000000..e6f5d8ab4 --- /dev/null +++ b/include/Utils/Shaders/shaderSimpleFlat.vert @@ -0,0 +1,26 @@ +//ShaderSimpleFlat::vertexShaderText + +ATTRIBUTE vec3 VertexPosition, VertexNormal; +#ifdef WITH_COLOR +ATTRIBUTE vec3 VertexColor; +#endif +uniform mat4 ModelViewProjectionMatrix; +uniform mat4 ModelViewMatrix; +uniform vec3 lightPosition; +VARYING_VERT vec3 LightDir; +VARYING_VERT vec3 Position; + +#ifdef WITH_COLOR +VARYING_VERT vec3 Color; +#endif + +INVARIANT_POS; +void main () +{ + Position = vec3 (ModelViewMatrix * vec4 (VertexPosition, 1.0)); + LightDir = lightPosition - Position; + #ifdef WITH_COLOR + Color = VertexColor; + #endif + gl_Position = ModelViewProjectionMatrix * vec4 (VertexPosition, 1.0); +} diff --git a/src/Algo/Render/topoGenRender.cpp b/src/Algo/Render/topoGenRender.cpp new file mode 100644 index 000000000..c8ce4b2d2 --- /dev/null +++ b/src/Algo/Render/topoGenRender.cpp @@ -0,0 +1,395 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include "Algo/Render/GL2/topoRender.h" +#include "Utils/GLSLShader.h" + +namespace CGoGN +{ + +namespace Algo +{ + +namespace Render +{ + +namespace GL2 +{ + +TopoGenRender::TopoGenRender(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,0.0f), + m_colorPhi1(0.0f,1.0f,1.0f,0.0f), + m_colorPhi2(1.0f,0.0f,0.0f,0.0f), + m_dartsBoundaryColor(0.7f,1.0f,0.7f,0.0f), + m_bufferDartPosition(NULL), + m_sharedShaders(false), + m_nameIndex("dart_index2"), + m_ke(0.9f), + m_kf(0.9f), + m_wb(false), + m_ns(0.0f) +{ + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + + m_shader1 = new Utils::ShaderSimpleColor(); + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + // registering for auto matrices update + Utils::GLSLShader::registerShader(NULL, m_shader1); +} + + +TopoGenRender::TopoGenRender(Utils::ShaderSimpleColor* ssc, 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,0.0f), + m_colorPhi1(0.0f,1.0f,1.0f,0.0f), + m_colorPhi2(1.0f,0.0f,0.0f,0.0f), + m_dartsBoundaryColor(0.7f,1.0f,0.7f,0.0f), + m_bufferDartPosition(NULL), + m_shader1(ssc), + m_sharedShaders(true), + m_nameIndex("dart_index2"), + m_ke(0.9f), + m_kf(0.9f), + m_wb(false), + m_ns(0.0f) +{ + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + // registering for auto matrices update + Utils::GLSLShader::registerShader(NULL, m_shader1); + +} + + +TopoGenRender::~TopoGenRender() +{ + if (m_shader1) + Utils::GLSLShader::unregisterShader(NULL, m_shader1); + + if (!m_sharedShaders) + { + if (m_shader1) + delete m_shader1; + } + + + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + + if (m_bufferDartPosition!=NULL) + delete[] m_bufferDartPosition; +} + + + +void TopoGenRender::setDartWidth(float dw) +{ + m_topo_dart_width = dw; +} + + +void TopoGenRender::setRelationWidth(float pw) +{ + m_topo_relation_width = pw; +} + + +void TopoGenRender::setColorPhi1(const Geom::Vec4f& col) +{ + m_colorPhi1 = col; +} + +void TopoGenRender::setColorPhi2(const Geom::Vec4f& col) +{ + m_colorPhi2 = col; +} + + +void TopoGenRender::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec4f(r,g,b,0.0); +} + + +void TopoGenRender::setInitialBoundaryDartsColor(float r, float g, float b) +{ + m_dartsBoundaryColor = Geom::Vec4f(r,g,b,0.0); +} + + +void TopoGenRender::drawDarts() +{ + if (m_nbDarts==0) + return; + + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(m_dartsColor); + m_shader1->enableVertexAttribs(); + + glLineWidth(m_topo_dart_width); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + // change the stride to take 1/2 vertices + m_shader1->enableVertexAttribs(6*sizeof(GL_FLOAT)); + + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + m_shader1->disableVertexAttribs(); +} + + +void TopoGenRender::drawRelation1() +{ + if (m_nbDarts==0) + return; + + + glLineWidth(m_topo_relation_width); + + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(m_colorPhi1); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + m_shader1->disableVertexAttribs(); +} + + +void TopoGenRender::drawRelation2() +{ + if (m_nbRel2==0) + return; + + glLineWidth(m_topo_relation_width); + + m_shader1->changeVA_VBO(m_vaId, m_vbo2); + m_shader1->setColor(m_colorPhi2); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_LINES, 0, m_nbRel2*2); + + m_shader1->disableVertexAttribs(); +} + + +void TopoGenRender::drawTopo(int code) +{ + if (m_nbDarts==0) + return; + + if (code&1) + { + drawDarts(); + } + + glLineWidth(m_topo_relation_width); + + if (code&2) + { + drawRelation1(); + } + + if (code&4) + { + drawRelation2(); + } +} + + + + +Dart TopoGenRender::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id == 0) + return NIL; + return Dart(id-1); +} + + +void TopoGenRender::dartToCol(Dart d, float& r, float& g, float& b) +{ + // here use d.index beacause it is what we want (and not map.dartIndex(d) !!) + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; +} + + + +void TopoGenRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) +{ + Utils::SVG::SVGOut svg(filename,model,proj); + toSVG(svg); + svg.write(); +} + + +void TopoGenRender::toSVG(Utils::SVG::SVGOut& svg) +{ + + // PHI2 / beta2 + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); + svg1->setToLayer(); + const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); + svg1->setWidth(m_topo_relation_width); + svg1->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.8f,0.0f,0.0f)); + svg1->endLines(); + m_vbo2->releasePtr(); + + svg.addGroup(svg1); + + //PHI1 /beta1 + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); + svg2->setToLayer(); + ptr = reinterpret_cast(m_vbo1->lockPtr()); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); + svg2->endLines(); + m_vbo1->releasePtr(); + + svg.addGroup(svg2); + + Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg3->setToLayer(); + svg3->setWidth(m_topo_dart_width); + svg3->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1], Geom::Vec3f(m_dartsColor[0],m_dartsColor[1],m_dartsColor[2])); + svg3->endLines(); + + svg.addGroup(svg3); + + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); + svg4->setToLayer(); + svg4->beginPoints(); + for (unsigned int i=0; iaddPoint(ptr[2*i],Geom::Vec3f(m_dartsColor[0],m_dartsColor[1],m_dartsColor[2])); + svg4->endPoints(); + + svg.addGroup(svg4); + + m_vbo0->releasePtr(); +} + + +void TopoGenRender::setNormalShift(float ns) +{ + m_ns = ns; +} + + +void TopoGenRender::setBoundaryShift(float bs) +{ + m_boundShift = bs; +} + +void TopoGenRender::setExplodeEdge(float ke) +{ + m_ke = ke; +} + +void TopoGenRender::setExplodeFace(float kf) +{ + m_kf = kf; +} + +void TopoGenRender::setWithBoundary(bool wb) +{ + m_wb = wb; +} + +void TopoGenRender::addColoredDart(Dart d, float r, float g, float b) +{ + m_coloredDarts.push_back(ColoredDart(d,r,g,b)); +} + +void TopoGenRender::removeColoredDart(Dart d) +{ + for (auto it=m_coloredDarts.begin(); it != m_coloredDarts.end(); ++it) + { + if (it->d == d) + { + (*it) = m_coloredDarts.back(); + m_coloredDarts.pop_back(); + return; + } + } +} + + + +} // namespace GL2 + +} // namespace Render + +} // namespace Algo + +} // namespace CGoGN diff --git a/src/Utils/GLSLShader.cpp b/src/Utils/GLSLShader.cpp index 1f2a512ad..d560d708e 100644 --- a/src/Utils/GLSLShader.cpp +++ b/src/Utils/GLSLShader.cpp @@ -1110,6 +1110,48 @@ void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& mo } +void GLSLShader::updateMatrices(const Utils::GLSLShader *sh) +{ + float mp[16]; + float mmv[16]; + float mmpv[16]; + float mn[16]; + + sh->bind(); + if (*m_uniMat_Proj >= 0) + glGetUniformfv(*(sh->m_program_object),*(sh->m_uniMat_Proj),mp); + + + if (*m_uniMat_Model >= 0) + glGetUniformfv(*(sh->m_program_object),*(sh->m_uniMat_Model),mmv); + + if (*m_uniMat_ModelProj >= 0) + glGetUniformfv(*(sh->m_program_object),*(sh->m_uniMat_ModelProj),mmpv); + + if (*m_uniMat_Normal >= 0) + glGetUniformfv(*(sh->m_program_object),*(sh->m_uniMat_Normal),mn); + + + this->bind(); + + if (*m_uniMat_Proj >= 0) + glUniformMatrix4fv(*m_uniMat_Proj, 1, false, mp); + + if (*m_uniMat_Model >= 0) + glUniformMatrix4fv(*m_uniMat_Model, 1, false, mmv); + + if (*m_uniMat_ModelProj >= 0) + glUniformMatrix4fv(*m_uniMat_ModelProj, 1 , false, mmpv); + + if (*m_uniMat_Normal >= 0) + glUniformMatrix4fv(*m_uniMat_Normal, 1 , false, mn); + + this->unbind(); +} + + + + void GLSLShader::enableVertexAttribs(unsigned int stride, unsigned int begin) const diff --git a/src/Utils/Shaders/shaderSimpleFlat.cpp b/src/Utils/Shaders/shaderSimpleFlat.cpp new file mode 100644 index 000000000..47a09663c --- /dev/null +++ b/src/Utils/Shaders/shaderSimpleFlat.cpp @@ -0,0 +1,191 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include +#include "Utils/Shaders/shaderSimpleFlat.h" + +namespace CGoGN +{ + +namespace Utils +{ + +#include "shaderSimpleFlat.vert" +#include "shaderSimpleFlat.frag" + + +ShaderSimpleFlat::ShaderSimpleFlat(bool doubleSided): + m_with_color(false), + m_ambiant(Geom::Vec4f(0.05f,0.05f,0.1f,0.0f)), + m_diffuse(Geom::Vec4f(0.1f,1.0f,0.1f,0.0f)), + m_lightPos(Geom::Vec3f(10.0f,10.0f,1000.0f)), + m_vboPos(NULL), + m_vboColor(NULL) +{ + m_nameVS = "ShaderSimpleFlat_vs"; + m_nameFS = "ShaderSimpleFlat_fs"; +// m_nameGS = "ShaderSimpleFlat_gs"; + + // get choose GL defines (2 or 3) + // ans compile shaders + std::string glxvert(*GLSLShader::DEFINES_GL); + glxvert.append(vertexShaderText); + std::string glxfrag(*GLSLShader::DEFINES_GL); + if (doubleSided) + glxfrag.append("#define DOUBLE_SIDED\n"); + glxfrag.append(fragmentShaderText); + + loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str()); + + // and get and fill uniforms + getLocations(); + sendParams(); +} + +void ShaderSimpleFlat::getLocations() +{ + bind(); + *m_unif_ambiant = glGetUniformLocation(this->program_handler(), "materialAmbient"); + *m_unif_diffuse = glGetUniformLocation(this->program_handler(), "materialDiffuse"); + *m_unif_lightPos = glGetUniformLocation(this->program_handler(), "lightPosition"); + unbind(); +} + +void ShaderSimpleFlat::sendParams() +{ + bind(); + glUniform4fv(*m_unif_ambiant, 1, m_ambiant.data()); + glUniform4fv(*m_unif_diffuse, 1, m_diffuse.data()); + glUniform3fv(*m_unif_lightPos, 1, m_lightPos.data()); + unbind(); +} + +void ShaderSimpleFlat::setAmbiant(const Geom::Vec4f& ambiant) +{ + bind(); + glUniform4fv(*m_unif_ambiant,1, ambiant.data()); + m_ambiant = ambiant; + unbind(); +} + +void ShaderSimpleFlat::setDiffuse(const Geom::Vec4f& diffuse) +{ + bind(); + glUniform4fv(*m_unif_diffuse,1, diffuse.data()); + m_diffuse = diffuse; + unbind(); +} + + +void ShaderSimpleFlat::setLightPosition(const Geom::Vec3f& lightPos) +{ + bind(); + glUniform3fv(*m_unif_lightPos,1,lightPos.data()); + m_lightPos = lightPos; + unbind(); +} + + +void ShaderSimpleFlat::setParams(const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos) +{ + m_ambiant = ambiant; + m_diffuse = diffuse; + m_lightPos = lightPos; + sendParams(); +} + +unsigned int ShaderSimpleFlat::setAttributeColor(VBO* vbo) +{ + m_vboColor = vbo; + if (!m_with_color) + { + m_with_color=true; + // set the define and recompile shader + std::string gl3vert(*GLSLShader::DEFINES_GL); + gl3vert.append("#define WITH_COLOR 1\n"); + gl3vert.append(vertexShaderText); + std::string gl3frag(*GLSLShader::DEFINES_GL); + gl3frag.append("#define WITH_COLOR 1\n"); + gl3frag.append(fragmentShaderText); + loadShadersFromMemory(gl3vert.c_str(), gl3frag.c_str()); + + // and treat uniforms + getLocations(); + sendParams(); + } + // bind th VA with WBO + bind(); + unsigned int id = bindVA_VBO("VertexColor", vbo); + unbind(); + return id; +} + +void ShaderSimpleFlat::unsetAttributeColor() +{ + m_vboColor = NULL; + if (m_with_color) + { + m_with_color = false; + // unbind the VA + bind(); + unbindVA("VertexColor"); + unbind(); + // recompile shader + std::string gl3vert(*GLSLShader::DEFINES_GL); + gl3vert.append(vertexShaderText); + std::string gl3frag(*GLSLShader::DEFINES_GL); + gl3frag.append(fragmentShaderText); + loadShadersFromMemory(gl3vert.c_str(), gl3frag.c_str()); + // and treat uniforms + getLocations(); + sendParams(); + } +} + +void ShaderSimpleFlat::restoreUniformsAttribs() +{ + getLocations(); + sendParams(); + + bind(); + bindVA_VBO("VertexPosition", m_vboPos); + if (m_vboColor) + bindVA_VBO("VertexColor", m_vboColor); + + unbind(); +} + +unsigned int ShaderSimpleFlat::setAttributePosition(VBO* vbo) +{ + m_vboPos = vbo; + bind(); + unsigned int id = bindVA_VBO("VertexPosition", vbo); + unbind(); + return id; +} + + +} // namespace Utils + +} // namespace CGoGN -- GitLab