diff --git a/Apps/Examples/clipping.cpp b/Apps/Examples/clipping.cpp index 5e127d8c0e4d5ac7547a6f3be40124abf88d3589..5c90e8cd037f0bd8892fbaced2bfbc87ed6d659f 100644 --- a/Apps/Examples/clipping.cpp +++ b/Apps/Examples/clipping.cpp @@ -137,21 +137,21 @@ void Clipping::slot_drawFaces(bool b) void Clipping::slot_explodTopoPhi1(double c) { m_coeffTopoExplod[0] = (float)c; - m_render_topo->updateData(myMap, allDarts, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]); + m_render_topo->updateData(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts); updateGL(); } void Clipping::slot_explodTopoPhi2(double c) { m_coeffTopoExplod[1] = (float)c; - m_render_topo->updateData(myMap, allDarts, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]); + m_render_topo->updateData(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts); updateGL(); } void Clipping::slot_explodTopoPhi3(double c) { m_coeffTopoExplod[2] = (float)c; - m_render_topo->updateData(myMap, allDarts, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]); + m_render_topo->updateData(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts); updateGL(); } @@ -830,7 +830,7 @@ void Clipping::importMesh(std::string& filename) updateVBOprimitives(Algo::Render::GL2::TRIANGLES | Algo::Render::GL2::LINES | Algo::Render::GL2::POINTS) ; - m_render_topo->updateData(myMap, allDarts, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2]); + m_render_topo->updateData(myMap, position, m_coeffTopoExplod[0], m_coeffTopoExplod[1], m_coeffTopoExplod[2], allDarts); m_bb = Algo::Geometry::computeBoundingBox(myMap, position) ; gPosObj = m_bb.center() ; @@ -859,7 +859,7 @@ void Clipping::cb_initGL() // create the render m_render = new Algo::Render::GL2::MapRender(); - m_render_topo = new Algo::Render::GL2::Topo3RenderMapD(); + m_render_topo = new Algo::Render::GL2::Topo3Render(); // create VBO for position m_positionVBO = new Utils::VBO(); diff --git a/Apps/Examples/clipping.h b/Apps/Examples/clipping.h index 922a09d900f7843e9b495fbafb8fa006777b21f0..2b79ecc6fd2f68da0ef75de77e82cc6001623c3f 100644 --- a/Apps/Examples/clipping.h +++ b/Apps/Examples/clipping.h @@ -91,7 +91,7 @@ public: bool m_drawTopo; Algo::Render::GL2::MapRender* m_render; - Algo::Render::GL2::Topo3RenderMapD* m_render_topo; + Algo::Render::GL2::Topo3Render* m_render_topo; Geom::BoundingBox m_bb; diff --git a/Apps/Tuto/README b/Apps/Tuto/README.TXT similarity index 100% rename from Apps/Tuto/README rename to Apps/Tuto/README.TXT diff --git a/Apps/Tuto/tp_master.cpp b/Apps/Tuto/tp_master.cpp index 950850787f6d6522efa8553586f0dc06df10c461..9e0fc06d026bc1a58348865c0c31f7a31480656d 100644 --- a/Apps/Tuto/tp_master.cpp +++ b/Apps/Tuto/tp_master.cpp @@ -369,7 +369,7 @@ void MyQT::cb_initGL() // create the render m_render = new Algo::Render::GL2::MapRender(); - m_render_topo = new Algo::Render::GL2::TopoRenderMapD() ; + m_render_topo = new Algo::Render::GL2::TopoRender() ; m_ds = new Utils::Drawer(); diff --git a/Apps/Tuto/tp_master.h b/Apps/Tuto/tp_master.h index f828fd1c5290bd4c165ddbf16551b9e04b4d7e43..c770b0a0a61992bb71c88466e1a7519902c9e280 100644 --- a/Apps/Tuto/tp_master.h +++ b/Apps/Tuto/tp_master.h @@ -31,7 +31,7 @@ // forward definitions (minimize includes) namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } -namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class TopoRenderMapD; } } } } +namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class TopoRender; } } } } namespace CGoGN { namespace Utils { class VBO; } } namespace CGoGN { namespace Utils { class ShaderPhong; } } namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } @@ -53,7 +53,7 @@ protected: public: // render Algo::Render::GL2::MapRender* m_render; - Algo::Render::GL2::TopoRenderMapD* m_render_topo; + Algo::Render::GL2::TopoRender* m_render_topo; // VBO Utils::VBO* m_positionVBO; diff --git a/Apps/Tuto/tuto1.cpp b/Apps/Tuto/tuto1.cpp index 92fac847f6e5949ca2ce5ecf5a443e7495cb5700..79ca0118d86cc5106552d8fccdfc577b4ae8aa21 100644 --- a/Apps/Tuto/tuto1.cpp +++ b/Apps/Tuto/tuto1.cpp @@ -23,114 +23,32 @@ *******************************************************************************/ #include "tuto1.h" - -#include - -#include "Topology/generic/parameters.h" -#include "Topology/map/embeddedMap2.h" -#include "Geometry/vector_gen.h" - - -#include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/GL2/mapRender.h" -#include "Utils/Shaders/shaderSimpleColor.h" - -#include - -#include "Algo/Render/SVG/mapSVGRender.h" - - using namespace CGoGN ; -/** - * Struct that contains some informations about the types of the manipulated objects - * Mainly here to be used by the algorithms that are parameterized by it - */ -struct PFP: public PFP_STANDARD -{ - // definition of the type of the map - typedef EmbeddedMap2 MAP; -}; - -// declaration of the map -PFP::MAP myMap; -// and attribute of position -AttributeHandler position; - -void MyQT::cb_initGL() -{ - // choose to use GL version 2 - Utils::GLSLShader::setCurrentOGLVersion(2); - // create the render - m_render = new Algo::Render::GL2::MapRender(); - - // create VBO for position - m_positionVBO = new Utils::VBO(); - - // using simple shader with color - m_shader = new Utils::ShaderSimpleColor(); - m_shader->setAttributePosition(m_positionVBO); - m_shader->setColor(Geom::Vec4f(0.0f, 1.0f, 0.0f, 0.0f)); - registerShader(m_shader); -} - -void MyQT::cb_redraw() +int main(int argc, char **argv) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); - if (m_shader) - { - glLineWidth(2.0f); - m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); - m_render->draw(m_shader, Algo::Render::GL2::LINES); - - m_shader->setColor(Geom::Vec4f(0.,1.,1.,0.)); - m_render->draw(m_shader, Algo::Render::GL2::BOUNDARY); - - - glPointSize(7.0f); - m_shader->setColor(Geom::Vec4f(1.,1.,1.,0.)); - m_render->draw(m_shader, Algo::Render::GL2::POINTS); - - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0f, 1.0f); - - m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); - m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES); + // // interface + QApplication app(argc, argv); + MyQT sqt; - glDisable(GL_POLYGON_OFFSET_FILL); - } -} + // example code itself + sqt.createMap(); -void MyQT::cb_keyPress(int code) -{ - if ((code >65) && (code< 123 )) - CGoGNout << " key char " << char(code) << "pressed"<< CGoGNendl; - - if ((code >'0') && (code<='9')) - CGoGNout << " key num " << code-'0' << "pressed"<< CGoGNendl; - - if (code == 's') - { - std::string filename = selectFileSave("Export SVG file "); - CGoGNout << "Exporting "<(myMap,position); - svg.setColor(Geom::Vec3f(0.7f,0.0f,0.4f)); - svg.renderFacesToSVG(myMap,position,0.8f); - //svg destruction close the file - } + // set help message in menu + sqt.setHelpMsg("First Tuto: \nCreate two faces\nsew them\nand affect positions"); + // final show for redraw + sqt.show(); + // and wait for the end + return app.exec(); } -int main(int argc, char **argv) +void MyQT::createMap() { - // creation of 2 new faces: 1 triangle and 1 square Dart d1 = myMap.newFace(3); Dart d2 = myMap.newFace(4); @@ -138,64 +56,45 @@ int main(int argc, char **argv) // sew these faces along one of their edge myMap.sewFaces(d1, d2); - // creation of a new attribute on vertices of type 3D vector - // a handler to this attribute is returned - position = myMap.addAttribute(VERTEX, "position"); + // creation of a new attribute on vertices of type 3D vector for position. + // a handler to this attribute is returned (TVEC3 is a typdef of AttributeHandler) + PFP::TVEC3 position = myMap.addAttribute(VERTEX, "position"); + //warning: at the end of scope of variable position, handler is destroyed but attribute stay - // affect a position to the vertices of the mesh + // affect position by moving in the map position[d1] = PFP::VEC3(0, 0, 0); - position[myMap.phi1(d1)] = PFP::VEC3(2, 0, 0); - position[myMap.phi_1(d1)] = PFP::VEC3(1, 2, 0); - - position[myMap.phi<11>(d2)] = PFP::VEC3(0, -2, 0); - position[myMap.phi_1(d2)] = PFP::VEC3(2, -2, 0); - - // interface: - QApplication app(argc, argv); - MyQT sqt; - - // ajout entree dans le menu application - sqt.add_menu_entry("entree1", SLOT(menu_slot1())); - - // message d'aide - sqt.setHelpMsg("First Tuto:\n" - "create 2 faces\n" - "and sew them \n" - "simple interface in Qt"); + position[PHI1(d1)] = PFP::VEC3(2, 0, 0); + position[PHI_1(d1)] = PFP::VEC3(1, 2, 0); + position[PHI<11>(d2)] = PFP::VEC3(0, -2, 0); + position[PHI_1(d2)] = PFP::VEC3(2, -2, 0); - // bounding box + // bounding box of scene Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); - // envoit info BB a l'interface - sqt.setParamObject(lWidthObj, lPosObj.data()); + // send BB info to interface for centering on GL screen + setParamObject(lWidthObj, lPosObj.data()); - // show 1 pour GL context - sqt.show(); - - // update du VBO position (context GL necessaire) - sqt.m_positionVBO->updateData(position); + // first show for be sure that GL context is binded + show(); - // update des primitives du renderer - SelectorEdgeNoBoundary insideEdges(myMap);// just to draw only inside edges + // render the topo of the map without boundary darts + SelectorDartNoBoundary nb(myMap); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,nb); +} - DartMarker dm(myMap); - dm.markOrbit(VERTEX,d2); - dm.markOrbit(VERTEX,d1); - CellMarker cm(myMap,FACE); - cm.mark(d2); - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); - sqt.m_render->initPrimitives(myMap, insideEdges, Algo::Render::GL2::LINES); - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::BOUNDARY); // special primitive for boundary edges - // example of using boolean operator on Selectors - sqt.m_render->initPrimitives(myMap, ( SelectorFalse() || ( SelectorTrue() && (SelectorMarked(dm) && SelectorCellMarked(cm)))) , Algo::Render::GL2::POINTS); // special primitive for boundary edges +// initialization GL callback +void MyQT::cb_initGL() +{ + m_render_topo = new Algo::Render::GL2::TopoRender() ; +} +// redraw GL callback (clear and swap already done) +void MyQT::cb_redraw() +{ + m_render_topo->drawTopo(); +} - // show final pour premier redraw - sqt.show(); - // et on attend la fin. - return app.exec(); -} diff --git a/Apps/Tuto/tuto1.h b/Apps/Tuto/tuto1.h index 9e4ff98e2837f502479e9ff33c94544d355d1069..4942662f0b4fb3b4295b1a80dd76eb7523cfce0a 100644 --- a/Apps/Tuto/tuto1.h +++ b/Apps/Tuto/tuto1.h @@ -25,51 +25,67 @@ #ifndef _TUTO1_ #define _TUTO1_ -#include +//#define USE_GMAP #include "Utils/Qt/qtSimple.h" #include "Utils/cgognStream.h" -// forward definitions (minimize includes) -namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } -namespace CGoGN { namespace Utils { class VBO; } } -namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } +#include "Topology/generic/parameters.h" + +#ifdef USE_GMAP + #include "Topology/gmap/embeddedGMap2.h" +#else + #include "Topology/map/embeddedMap2.h" +#endif + +#include "Algo/Render/GL2/topoRender.h" using namespace CGoGN ; /** - * A class for a little interface and rendering + * Struct that contains some informations about the types of the manipulated objects + * Mainly here to be used by the algorithms that are parameterized by it */ -class MyQT : public Utils::QT::SimpleQT +struct PFP: public PFP_STANDARD { - Q_OBJECT - -public: - // render - Algo::Render::GL2::MapRender* m_render; + // definition of the type of the map +#ifdef USE_GMAP + typedef EmbeddedGMap2 MAP; +#else + typedef EmbeddedMap2 MAP; +#endif +}; - // VBO - Utils::VBO* m_positionVBO; - // shader basic - Utils::ShaderSimpleColor* m_shader; - MyQT() : m_render(NULL), m_positionVBO(NULL), m_shader(NULL) - {} +class MyQT: public Utils::QT::SimpleQT +{ + Q_OBJECT +public: + MyQT():m_render_topo(NULL) {} - // callbacks of simpleQT to overdefine: + void cb_redraw(); void cb_initGL(); - void cb_redraw(); +protected: + // declaration of the map + PFP::MAP myMap; - void cb_keyPress(int code); + // render (for the topo) + Algo::Render::GL2::TopoRender* m_render_topo; - void cb_New() { CGoGNout << "New ..." << CGoGNendl; } - void cb_Save() { CGoGNout << "Rien a sauver ..." << CGoGNendl; } + // just for more compact writing + inline Dart PHI1(Dart d) {return myMap.phi1(d);} + inline Dart PHI_1(Dart d) {return myMap.phi_1(d);} + inline Dart PHI2(Dart d) {return myMap.phi2(d);} + template + Dart PHI(Dart d) {return myMap.phi(d);} - // callbacks (slots) locally defined -public slots: - void menu_slot1() { CGoGNout << "Exemple de menu" << CGoGNendl; } +public: + // example of simple map creation + void createMap(); }; + + #endif diff --git a/Apps/Tuto/tuto2.cpp b/Apps/Tuto/tuto2.cpp index cf6d510dc2bef067b81b85a2633ad4cd1a935d18..1f1f3bb7d70a9554a40db7a21f791132ce76fea0 100644 --- a/Apps/Tuto/tuto2.cpp +++ b/Apps/Tuto/tuto2.cpp @@ -22,239 +22,176 @@ * * *******************************************************************************/ -#include - -#include "Topology/generic/parameters.h" -#include "Topology/map/map2.h" -#include "Topology/generic/mapBrowser.h" - -#include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/GL2/mapRender.h" -#include "Utils/Shaders/shaderSimpleColor.h" - -#include "Utils/drawer.h" - #include "tuto2.h" +#include "Algo/Geometry/boundingbox.h" using namespace CGoGN ; -struct PFP: public PFP_STANDARD -{ - // definition de la carte - typedef Map2 MAP; -}; - -PFP::MAP myMap; - -PFP::TVEC3 position ; -PFP::TVEC3 normal ; -AttributeHandler color ; -void MyQT::cb_initGL() +int main(int argc, char **argv) { - // choose to use GL version 2 - Utils::GLSLShader::setCurrentOGLVersion(2); - - // create the render - m_render = new Algo::Render::GL2::MapRender(); - - // create VBO for position - m_positionVBO = new Utils::VBO(); - - // using simple shader with color - m_shader = new Utils::ShaderSimpleColor(); - m_shader->setAttributePosition(m_positionVBO); - - m_color = Geom::Vec4f(0.,1.,0.,0.); - m_shader->setColor(m_color); + // // interface + QApplication app(argc, argv); + MyQT sqt; + // copy output tout Qt console of application (shift enter) + CGoGNout.toConsole(&sqt); - registerShader(m_shader); + // example code itself + sqt.createMap(); + // set help message in menu + sqt.setHelpMsg("Tuto 2: \nCreate and use multiple attributes\nrender with multiple shaders"); - m_with_lines = true; - m_line_width = 4.0; + // final show for redraw + sqt.show(); + // and wait for the end + return app.exec(); } -void MyQT::cb_redraw() -{ - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glEnable(GL_LIGHTING); - if (m_shader) - { - if (m_with_lines) - { - glLineWidth(m_line_width); - m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); - m_render->draw(m_shader, Algo::Render::GL2::LINES); - } - - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0f, 1.0f); - - m_shader->setColor(m_color); - m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES); - glDisable(GL_POLYGON_OFFSET_FILL); - } -} -void MyQT::lines_slot(bool x) +void MyQT::createMap() { - m_with_lines = x; - updateGL(); -} -void MyQT::line_width_slot(int x) -{ + // creation of 2 new faces: 1 triangle and 1 square, sew and embed (see tuto1 for details) + Dart d1 = myMap.newFace(3); + Dart d2 = myMap.newFace(4); + myMap.sewFaces(d1, d2); + PFP::TVEC3 position = myMap.addAttribute(VERTEX, "position"); + position[d1] = PFP::VEC3(0, 0, 0); + position[PHI1(d1)] = PFP::VEC3(2, 0, 0); + position[PHI_1(d1)] = PFP::VEC3(1, 2, 0); + position[PHI<11>(d2)] = PFP::VEC3(0, -2, 0); + position[PHI_1(d2)] = PFP::VEC3(2, -2, 0); - m_line_width=x; - updateGL(); -} -void MyQT::color_slot() -{ - QColor col = QColorDialog::getColor (); - if (col.isValid()) - { + // create another attribute on vertices (for faces drawing) + AttributeHandler colorF = myMap.addAttribute(VERTEX, "colorF"); - m_color = Geom::Vec4f(float(col.red())/255.0f,float(col.green())/255.0f,float(col.blue())/255.0f,0.0f); - updateGL(); - } - else - { - CGoGNout << "Cancel Color" << CGoGNendl; - } -} + colorF[d1] = Geom::Vec3f(1.0f,0.0f,0.0f); + colorF[PHI1(d1)] = Geom::Vec3f(0.0f,1.0f,0.0f); + colorF[PHI_1(d1)] = Geom::Vec3f(0.0f,0.0f,1.0f); + colorF[PHI<11>(d2)] = Geom::Vec3f(1.0f,0.0f,1.0f); + colorF[PHI_1(d2)] = Geom::Vec3f(0.0f,1.0f,1.0f); -// Algorithme qui parcours une carte et affiche l'attribut position de chaque brin -template -void TestDeParcoursAFF(typename PFP::MAP& m, MapBrowser& mb, const typename PFP::TVEC3& pos) -{ - for (Dart d = mb.begin(); d != mb.end(); mb.next(d)) - { - typename PFP::VEC3 P = pos[d]; - CGoGNout << "P "<< P << CGoGNendl; - } -} -int main(int argc, char **argv) -{ - /// Utilisation des MapBrowsers + // create another attribute on vertices (for edges drawing) + AttributeHandler colorE = myMap.addAttribute(VERTEX, "colorE"); - /// on reprend la carte de tuto1 + colorE[d1] = Geom::Vec3f(0.0f,0.5f,0.5f); + colorE[PHI1(d1)] = Geom::Vec3f(0.5f,0.0f,0.5f); + colorE[PHI_1(d1)] = Geom::Vec3f(0.5f,0.5f,0.0f); + colorE[PHI<11>(d2)] = Geom::Vec3f(0.0f,0.5f,0.0f); + colorE[PHI_1(d2)] = Geom::Vec3f(0.5f,0.0f,0.0f); - Dart d2 = myMap.newFace(3); - Dart d3 = myMap.newFace(4); - myMap.sewFaces(d2, d3); - position = myMap.addAttribute(VERTEX, "position"); + // example of attribute on face + // here for example we store the number of edges of faces at construction + AttributeHandler side = myMap.addAttribute(FACE, "nb_sides"); + side[d1]=3; + side[d2]=4; - position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); - d2 = myMap.phi1(d2); - position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f); - d2 = myMap.phi1(d2); - position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f); - d2 = myMap.phi1(d2); - d3 = myMap.phi<11>(d3); - position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f); - d3 = myMap.phi1(d3); - position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f); - d3 = myMap.phi1(d3); + // bounding box of scene + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); + float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); + Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); - // MapBrowser: la carte elle meme - CGoGNout << "Parcours avec la carte" << CGoGNendl; - TestDeParcoursAFF(myMap, myMap, position); - - // MapBrowserLinkedAuto - // sous-carte dans une liste avec attribut gere par le browser - CGoGNout << "Parcours avec le browser (les sommets)"<mbl(myMap); + // first show for be sure that GL context is binded + show(); - // on ajoute un brin par sommet dans le browser - myMap.foreach_orbit(VERTEX, mbl); - // et on parcours la sous-carte avec ce browser - TestDeParcoursAFF(myMap, mbl, position); + // update of position VBO (context GL necessary) + m_positionVBO->updateData(position); + m_colorVBO1->updateData(colorF); + m_colorVBO2->updateData(colorE); + // construct rendering primities + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::POINTS); // special primitive for boundary edges - // MapBrowserLinkedAttr - // sous-carte dans une liste avec attribut gere par l'appelant - CGoGNout << "Parcours avec le browser (le triangle)"< tableLink(myMap, DART); - // le browser - MapBrowserLinkedmbl2(myMap,tableLink); - // que l'on remplit a la main - Dart d = d2; - mbl2.pushBack(d); - d = myMap.phi1(d); - mbl2.pushBack(d); - d = myMap.phi1(d); - mbl2.pushFront(d); + // traverse of all dart of the map: + // and write informations + for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) + { + CGoGNout << "Dart "<< d; + if (myMap.isBoundaryMarked(d)) + CGoGNout << " is a boundary dart (implicitly added)"<< CGoGNendl; + else + { + CGoGNout <<": position= "<< position[d]; + CGoGNout <<" / color1= "<< colorF[d]; + CGoGNout <<" / color2= "<< colorE[d]; + CGoGNout << " / numer of side of face "<< side[d] << CGoGNendl; + } + } - // et on parcours la sous-carte avec ce browser - TestDeParcoursAFF(myMap, mbl2, position); +} - // MapBrowserSelector - // sous-carte avec des brins marques (equivalent de l'utilisation de good dans les algos) - CGoGNout << "Parcours avec le browser selector"<mbsel(myMap,selector); + // create the render + m_render = new Algo::Render::GL2::MapRender(); -// // et on parcours la sous-carte avec ce browser -// TestDeParcoursAFF(myMap,mbsel,position); + // create VBO for position + m_positionVBO = new Utils::VBO(); + // and color + m_colorVBO1 = new Utils::VBO(); + m_colorVBO2 = new Utils::VBO(); - // interface: - QApplication app(argc, argv); - MyQT sqt; + // using simple shader with color + m_shader = new Utils::ShaderSimpleColor(); + m_shader->setAttributePosition(m_positionVBO); + m_shader->setColor(Geom::Vec4f(0.0f, 1.0f, 0.0f, 0.0f)); + // each shader must be registred to allow Qt interface to update matrices uniforms + registerShader(m_shader); - Utils::QT::uiDockInterface dock; - sqt.setDock(&dock); + m_shader2 = new Utils::ShaderColorPerVertex(); + m_shader2->setAttributePosition(m_positionVBO); +// m_shader2->setAttributeColor(m_colorVBO1); + // each shader must be registred to allow Qt interface to update matrices uniforms + registerShader(m_shader2); - sqt.setCallBack( dock.checkLines, SIGNAL(toggled(bool)), SLOT(lines_slot(bool)) ); - sqt.setCallBack( dock.color_button , SIGNAL(pressed()), SLOT(color_slot()) ); - sqt.setCallBack( dock.dial_line_width , SIGNAL(valueChanged(int)), SLOT(line_width_slot(int)) ); - // message d'aide - sqt.setHelpMsg("Second Tuto"); +} - dock.number_of_darts->display(int(myMap.getNbDarts())); +// redraw GL callback (clear and swap already done) +void MyQT::cb_redraw() +{ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_CULL_FACE); - // bounding box - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); - float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); - Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); + // draw yellow points + glLineWidth(2.0f); + m_shader2->setAttributeColor(m_colorVBO1); + m_render->draw(m_shader2, Algo::Render::GL2::LINES); - // envoit info BB a l'interface - sqt.setParamObject(lWidthObj,lPosObj.data()); + // draw white points + glPointSize(7.0f); + m_shader->setColor(Geom::Vec4f(1.,1.,1.,0.)); + m_render->draw(m_shader, Algo::Render::GL2::POINTS); - // show 1 pour GL context - sqt.show(); + // use offset for nice drawing + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); - // update du VBO position (context GL necessaire) - sqt.m_positionVBO->updateData(position); + // draw faces with pervertex color rendering + m_shader2->setAttributeColor(m_colorVBO2); + m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); - // update des primitives du renderer - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + glDisable(GL_POLYGON_OFFSET_FILL); +} - // show final pour premier redraw - sqt.show(); - // et on attend la fin. - return app.exec(); -} diff --git a/Apps/Tuto/tuto2.h b/Apps/Tuto/tuto2.h index 355be382ea41cd20b8ebeb5b1ae56d22186c6352..523c1f8a032f6f60dbd9490fe50f95f81b98c6de 100644 --- a/Apps/Tuto/tuto2.h +++ b/Apps/Tuto/tuto2.h @@ -25,58 +25,81 @@ #ifndef _TUTO2_ #define _TUTO2_ -#include +//#define USE_GMAP + #include "Utils/Qt/qtSimple.h" -#include "ui_tuto2.h" -#include "Utils/Qt/qtui.h" +#include "Utils/cgognStream.h" +#include "Topology/generic/parameters.h" + +#ifdef USE_GMAP + #include "Topology/gmap/embeddedGMap2.h" +#else + #include "Topology/map/embeddedMap2.h" +#endif -#include "Geometry/vector_gen.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Utils/Shaders/shaderSimpleColor.h" +#include "Utils/Shaders/shaderColorPerVertex.h" -// forward definitions (minimize includes) -namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } -namespace CGoGN { namespace Utils { class VBO; } } -namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } using namespace CGoGN ; /** - * Utilisation de designer-qt4: - * Faire un DockWiget (laisser le nom par defaut - * dans le Contents ajouter le layout choisi (vertical classiquement) - * Ajouter les widgets necessaires, mettre des noms clairs pour - * les utiliser dans le .cpp (pour les call back principalement) + * Struct that contains some informations about the types of the manipulated objects + * Mainly here to be used by the algorithms that are parameterized by it */ +struct PFP: public PFP_STANDARD +{ + // definition of the type of the map +#ifdef USE_GMAP + typedef EmbeddedGMap2 MAP; +#else + typedef EmbeddedMap2 MAP; +#endif +}; + + class MyQT: public Utils::QT::SimpleQT { Q_OBJECT +public: + MyQT(): m_render(NULL), m_positionVBO(NULL), m_shader(NULL) {} - bool m_with_lines; - Geom::Vec4f m_color; - int m_line_width; + void cb_redraw(); + void cb_initGL(); + +protected: + // declaration of the map + PFP::MAP myMap; + + // render (for the topo) +// Algo::Render::GL2::TopoRenderMapD* m_render_topo; -public: // render Algo::Render::GL2::MapRender* m_render; // VBO - Utils::VBO* m_positionVBO; + Utils::VBO* m_positionVBO; // position 3D + Utils::VBO* m_colorVBO1; // color per vertex for face drawing + Utils::VBO* m_colorVBO2; // color per vertex for edge drawing - // shader basic + //shaders Utils::ShaderSimpleColor* m_shader; + Utils::ShaderColorPerVertex* m_shader2; - MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL) - {} + // just for more compact writing + inline Dart PHI1(Dart d) {return myMap.phi1(d);} + inline Dart PHI_1(Dart d) {return myMap.phi_1(d);} + inline Dart PHI2(Dart d) {return myMap.phi2(d);} + template + Dart PHI(Dart d) {return myMap.phi(d);} - void cb_redraw(); +public: + // example of simple map creation + void createMap(); +}; - void cb_initGL(); -// slots locaux -public slots: - void lines_slot(bool x); - void line_width_slot(int x); - void color_slot(); -}; #endif diff --git a/Apps/Tuto/tuto3.cpp b/Apps/Tuto/tuto3.cpp index c256245d36c20132173c8ffb2d4752761f69d345..6f62d56be1f871978341de75de1dfcadfa36ce30 100644 --- a/Apps/Tuto/tuto3.cpp +++ b/Apps/Tuto/tuto3.cpp @@ -22,219 +22,164 @@ * * *******************************************************************************/ -#include - -#include "Topology/generic/parameters.h" -#include "Topology/map/map2.h" -#include "Topology/generic/cellmarker.h" - -#include "Geometry/vector_gen.h" -#include "Algo/Geometry/boundingbox.h" -#include "Algo/Render/GL2/mapRender.h" -#include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderColorPerVertex.h" - - #include "tuto3.h" - -MyQT* sqt1_ptr; -MyQT* sqt2_ptr; +#include "Algo/Geometry/boundingbox.h" +#include "Algo/Selection/raySelector.h" +#include "Algo/Modelisation/polyhedron.h" using namespace CGoGN ; -struct PFP: public PFP_STANDARD -{ - // definition de la carte - typedef Map2 MAP; -}; -void MyQT::cb_initGL() +int main(int argc, char **argv) { - // choose to use GL version 2 - Utils::GLSLShader::setCurrentOGLVersion(2); + // // interface + QApplication app(argc, argv); + MyQT sqt; + // copy output tout Qt console of application (shift enter) + CGoGNout.toConsole(&sqt); - // create the render - m_render = new Algo::Render::GL2::MapRender(); + // example code itself + sqt.createMap(); - // create VBO for position - m_positionVBO = new Utils::VBO(); - m_colorVBO = new Utils::VBO(); + sqt.traverseMap(); - // using simple shader with color - m_shader = new Utils::ShaderSimpleColor(); - m_shader->setAttributePosition(m_positionVBO); + // set help message in menu + sqt.setHelpMsg("Tuto 3: \nUsage of DartMarker and CellMarker\nPick of dart with mouse"); + // final show for redraw + sqt.show(); - m_shader2 = new Utils::ShaderColorPerVertex(); - m_shader2->setAttributePosition(m_positionVBO); - m_shader2->setAttributeColor(m_colorVBO); + CGoGNout << "You can pick darts dans see it's id with left mouse button"<< CGoGNendl; - registerShader(m_shader); - registerShader(m_shader2); + // and wait for the end + return app.exec(); } -void MyQT::cb_redraw() + +void MyQT::traverseMap() { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(2.0f); - m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); - m_render->draw(m_shader, Algo::Render::GL2::LINES); + //traverse cells of map using topological markers on darts - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0f, 1.0f); - m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); - glDisable(GL_POLYGON_OFFSET_FILL); -} - -void MyQT::cb_keyPress(int code) -{ - switch(code) + CGoGNout << "Traverse with DartMarkers:"<< CGoGNendl; + DartMarker dmV(myMap); + DartMarker dmE(myMap); + DartMarker dmF(myMap); + for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) { - case 's': - if (this == sqt2_ptr) - sqt1_ptr->synchronize(sqt2_ptr); - if (this == sqt1_ptr) - sqt2_ptr->synchronize(sqt1_ptr); - break; + if (!dmV.isMarked(d)) + { + CGoGNout << "Vertex of dart "< color ; - Dart d2 = myMap.newFace(3); - Dart d3 = myMap.newFace(4); - myMap.sewFaces(d2,d3); + // traverses cells of map with markers on embedded cells. + // More efficients but more memory costly if cells are not already embedded. + // Avoid using construction of objects not ell embedded - position = myMap.addAttribute(VERTEX, "position"); - color = myMap.addAttribute(VERTEX, "couleur"); - - position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); - color[d2] = PFP::VEC3(1.0f, 0.0f, 0.0f); - d2 = myMap.phi1(d2); - position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f); - color[d2] = PFP::VEC3(0.0f, 1.0f, 0.0f); - d2 = myMap.phi1(d2); - position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f); - color[d2] = PFP::VEC3(0.0f, 0.0f, 1.0f); - d2 = myMap.phi1(d2); - d3 = myMap.phi<11>(d3); - position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f); - color[d3] = PFP::VEC3(1.0f, 0.0f, 1.0f); - d3 = myMap.phi1(d3); - position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f); - color[d3] = PFP::VEC3(0.0f, 1.0f, 1.0f); - d3 = myMap.phi1(d3); - - //MARK !!! - - // on reserve des marqueur de brins - DartMarkerStore mf(myMap); - DartMarkerStore me(myMap); - - // avec lesquels on peut marquer des orbits - mf.markOrbit(FACE, d2); - me.markOrbit(EDGE, d2); - - // les sommet sont plonges, on peut utiliser un marqueur de cellule sommet - CellMarker cm(myMap, VERTEX); - cm.mark(d3); - - for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d)) + CGoGNout << "========================="<< CGoGNendl; + CGoGNout << "Traverse with CellMarkers:"<< CGoGNendl; + CellMarker cmV(myMap,VERTEX); + CellMarker cmE(myMap,EDGE); + CellMarker cmF(myMap,FACE); + for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) { - if (me.isMarked(d)) - CGoGNout << "Dart "<< d.label() << " marque par me"<< CGoGNendl; - if (mf.isMarked(d)) - CGoGNout << "Dart "<< d.label() << " marque par mf"<< CGoGNendl; - if (cm.isMarked(d)) - CGoGNout << "Sommet de dart "<< d.label() << " marque par mcv"<< CGoGNendl; + if (!cmV.isMarked(d)) + { + CGoGNout << "Vertex of dart "< bb = Algo::Geometry::computeBoundingBox(myMap, position); - float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); - Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); - // envoit info BB a l'interface - sqt.setParamObject(lWidthObj, lPosObj.data()); +void MyQT::createMap() +{ - // show 1 pour GL context - sqt.show(); + Dart d1 = Algo::Modelisation::Polyhedron::createTetra(myMap); - // update du VBO position (context GL necessaire) - sqt.m_positionVBO->updateData(position); - // update du VBO color - sqt.m_colorVBO->updateData(color); + Dart d2 = d1; - // update des primitives du renderer - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + position = myMap.addAttribute(VERTEX, "position"); - // show final pour premier redraw - sqt.show(); + position[d2] = PFP::VEC3(1, 0, 0); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(-1, 0, 0); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(0, 2, 0); + d2 = PHI<211>(d2); + position[d2] = PFP::VEC3(0, 1, 2); - // et pour le fun une deuxieme carte et une deuxieme interface: + // bounding box of scene + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); + float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); + Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); - PFP::MAP myMap2; - PFP::TVEC3 position2 ; - AttributeHandler color2 ; + // send BB info to interface for centering on GL screen + setParamObject(lWidthObj, lPosObj.data()); - Dart dx = myMap2.newFace(4); + // first show for be sure that GL context is binded + show(); - position2 = myMap2.addAttribute(VERTEX, "position"); - color2 = myMap2.addAttribute(VERTEX, "couleur"); + // render the topo of the map without boundary darts + SelectorDartNoBoundary nb(myMap); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,nb); +} - position2[dx] = PFP::VEC3(0.0f, 0.0f, 0.0f); - color2[dx] = PFP::VEC3(1.0f, 1.0f, 0.0f); - dx = myMap.phi1(dx); - position2[dx] = PFP::VEC3(2.0f, 0.0f, 0.0f); - color2[dx] = PFP::VEC3(0.0f, 1.0f, 0.0f); - dx = myMap.phi1(dx); - position2[dx] = PFP::VEC3(2.0f, 2.0f, 0.0f); - color2[dx] = PFP::VEC3(1.0f, 0.0f, 1.0f); - dx = myMap.phi1(dx); - position2[dx] = PFP::VEC3(0.0f, 2.0f, 0.0f); - color2[dx] = PFP::VEC3(0.0f, 1.0f, 1.0f); - sqt2.setHelpMsg("Fenetre 2!!"); +// initialization GL callback +void MyQT::cb_initGL() +{ + m_render_topo = new Algo::Render::GL2::TopoRender(); +} - sqt2.setParamObject(lWidthObj,lPosObj.data()); +// 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->drawTopo(); - // show 1 pour GL context - sqt2.show(); +} - // update du VBO position (context GL necessaire) - sqt2.m_positionVBO->updateData(position2); - // update du VBO color - sqt2.m_colorVBO->updateData(color2); +// mouse picking +void MyQT::cb_mouseClick(int button, int x, int y) +{ + if (button == Qt::LeftButton) + { + Dart d = m_render_topo->picking(myMap,x,y); + if (d != NIL) - // update des primitives du renderer - sqt2.m_render->initPrimitives(myMap2, allDarts, Algo::Render::GL2::TRIANGLES); - sqt2.m_render->initPrimitives(myMap2, allDarts, Algo::Render::GL2::LINES); + CGoGNout << "Dart "<< d << CGoGNendl; + dart_selected=d; + updateGL(); + } - // et on attend la fin. - return app.exec(); } diff --git a/Apps/Tuto/tuto3.h b/Apps/Tuto/tuto3.h index e00fc5b4f2e247d5f0a4add128b7e758c08ed0c4..f38a896833b3981e80904640489225928a49332b 100644 --- a/Apps/Tuto/tuto3.h +++ b/Apps/Tuto/tuto3.h @@ -26,43 +26,76 @@ #define _TUTO3_H_ #include "Utils/Qt/qtSimple.h" +#include "Utils/cgognStream.h" + +//#define USE_GMAP + +#include "Topology/generic/parameters.h" +#ifdef USE_GMAP + #include "Topology/gmap/embeddedGMap2.h" +#else + #include "Topology/map/embeddedMap2.h" +#endif +#include "Algo/Render/GL2/topoRender.h" + -// forward definition (minimize includes) -namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } } -namespace CGoGN { namespace Utils { class VBO; } } -namespace CGoGN { namespace Utils { class ShaderSimpleColor; class ShaderColorPerVertex; } } using namespace CGoGN ; /** - * A class for a little interface and rendering + * Struct that contains some informations about the types of the manipulated objects + * Mainly here to be used by the algorithms that are parameterized by it */ +struct PFP: public PFP_STANDARD +{ + // definition of the type of the map +#ifdef USE_GMAP + typedef EmbeddedGMap2 MAP; +#else + typedef EmbeddedMap2 MAP; +#endif +}; + + class MyQT: public Utils::QT::SimpleQT { Q_OBJECT public: - // render - Algo::Render::GL2::MapRender* m_render; + MyQT():m_render_topo(NULL),dart_selected(NIL){} - // VBO - Utils::VBO* m_positionVBO; - Utils::VBO* m_colorVBO; + void cb_redraw(); + void cb_initGL(); + void cb_mouseClick(int button, int x, int y); - // shader basic - Utils::ShaderSimpleColor* m_shader; - Utils::ShaderColorPerVertex* m_shader2; +protected: + // declaration of the map + PFP::MAP myMap; - bool m_sync; + // attribute handler on position; + PFP::TVEC3 position; - MyQT() : m_render(NULL), m_positionVBO(NULL), m_shader(NULL), m_sync(false) - {} + // render (for the topo) + Algo::Render::GL2::TopoRender* m_render_topo; - // callbacks of simpleQT to overdefine: - void cb_redraw(); + // selected dart (mouse click) + Dart dart_selected; - void cb_initGL(); + // just for more compact writing + inline Dart PHI1(Dart d) {return myMap.phi1(d);} + inline Dart PHI_1(Dart d) {return myMap.phi_1(d);} + inline Dart PHI2(Dart d) {return myMap.phi2(d);} + template + Dart PHI(Dart d) {return myMap.phi(d);} - void cb_keyPress(int code); +public: + + // create the map (here tetrahedron + void createMap(); + + // traverse the map using markers + void traverseMap(); }; + + #endif diff --git a/Apps/Tuto/tuto4.cpp b/Apps/Tuto/tuto4.cpp index 107bdc444aae2a2ddd6738c06a3d742cb5b30a41..bea40039c0a9f019832b9fcbe4ec18ac5b3c40bc 100644 --- a/Apps/Tuto/tuto4.cpp +++ b/Apps/Tuto/tuto4.cpp @@ -22,215 +22,165 @@ * * *******************************************************************************/ -#include - #include "tuto4.h" - -#include "Topology/generic/parameters.h" -#include "Topology/map/map2.h" - -#include "Geometry/matrix.h" -#include "Geometry/vector_gen.h" -#include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" -#include "Topology/generic/cellmarker.h" - -#include "Algo/Render/GL2/mapRender.h" -#include "Algo/Render/GL2/topoRender.h" -#include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderFlat.h" - -#include "Utils/cgognStream.h" +#include "Algo/Modelisation/polyhedron.h" using namespace CGoGN ; -struct PFP: public PFP_STANDARD -{ - // definition de la carte - typedef Map2 MAP; -}; - -PFP::MAP myMap; -PFP::TVEC3 position ; -PFP::TVEC3 normal ; -AttributeHandler color ; - -void MyQT::cb_initGL() +int main(int argc, char **argv) { - // choose to use GL version 2 - Utils::GLSLShader::setCurrentOGLVersion(2); + // // interface + QApplication app(argc, argv); + MyQT sqt; + // copy output tout Qt console of application (shift enter) + CGoGNout.toConsole(&sqt); - // create the render - m_render = new Algo::Render::GL2::MapRender(); + // example code itself + sqt.createMap(); - m_render_topo = new Algo::Render::GL2::TopoRenderMapD(); + sqt.traverseMap(); - // create VBO for position - m_positionVBO = new Utils::VBO(); + // set help message in menu + sqt.setHelpMsg("Tuto 3: \nUsage of DartMarker and CellMarker\nPick of dart with mouse"); + // final show for redraw + sqt.show(); - // using simple shader with color - m_shader = new Utils::ShaderSimpleColor(); - m_shader->setAttributePosition(m_positionVBO); - m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); - m_shader2 = new Utils::ShaderFlat(); - m_shader2->setAttributePosition(m_positionVBO); + CGoGNout << "You can pick darts dans see incident/dajacent cells (one dart) with click/shift click/ctrl click"<< CGoGNendl; - registerShader(m_shader); - registerShader(m_shader2); + // and wait for the end + return app.exec(); } -void MyQT::cb_redraw() + +// example of usage of traversor for local traverse +void MyQT::cb_mouseClick(int button, int x, int y) { - if(render_topo) - { - m_render_topo->drawTopo(); - } - if(render_obj) + if (button == Qt::LeftButton) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - - glEnable( GL_POLYGON_OFFSET_FILL ); - glPolygonOffset( 1.0f, 1.0f ); - m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES); - glDisable(GL_POLYGON_OFFSET_FILL); + Dart d = m_render_topo->picking(myMap,x,y); + if (d != NIL) + { + dart_selected.clear(); + // EDGES INCIDENT TO VERTEX + if (Shift()) + { + Traversor2VE tra(myMap,d); + for (Dart e=tra.begin(); e!=tra.end(); e=tra.next()) + dart_selected.push_back(e); + CGoGNout << "traverse edges incident to a vertex" << CGoGNendl; + color = Geom::Vec3f(1,0,0); + } + // EDGES INCIDENT TO FACES + else if (Control()) + { + Traversor2FE tra(myMap,d); + for (Dart e=tra.begin(); e!=tra.end(); e=tra.next()) + dart_selected.push_back(e); + CGoGNout << "traverse edges incident to a face (its boundary)" << CGoGNendl; + color = Geom::Vec3f(0,1,0); + } + // VERTICES ADJACENT TO VERTEX BY A FACE + else + { + Traversor2VVaF tra(myMap,d); + for (Dart e=tra.begin(); e!=tra.end(); e=tra.next()) + dart_selected.push_back(e); + CGoGNout << "traverse vertices adjacent to vertex by a face " << CGoGNendl; + color = Geom::Vec3f(1,1,0); + + } + } + updateGL(); } } -void MyQT::cb_keyPress(int code) +void MyQT::traverseMap() { - switch(code) - { - case 'o': - render_obj = !render_obj; - updateGL(); - break; + //traverse cells with traversor - case 't': - render_topo = !render_topo; - updateGL(); - break; - } -} + CGoGNout << "Traverse with Vertex Traversor: "<< CGoGNendl; + TraversorV traV(myMap); + for (Dart d=traV.begin(); d!=traV.end(); d=traV.next()) + CGoGNout << "Vertex of dart "<(dockWidget())->vertexEdit->toPlainText(); - QString st2 = dynamic_cast(dockWidget())->fragmentEdit->toPlainText(); - QString st3 = dynamic_cast(dockWidget())->geometryEdit->toPlainText(); + CGoGNout << "Traverse with Edge Traversor: "<< CGoGNendl; + TraversorE traE(myMap); + for (Dart d=traE.begin(); d!=traE.end(); d=traE.next()) + CGoGNout << "Edge of dart "<reloadVertexShaderFromMemory(st1.toStdString().c_str()); - m_shader2->reloadFragmentShaderFromMemory(st2.toStdString().c_str()); - m_shader2->reloadGeometryShaderFromMemory(st3.toStdString().c_str()); + CGoGNout << "Traverse with Face Traversor: "<< CGoGNendl; + TraversorF traF(myMap); + for (Dart d=traF.begin(); d!=traF.end(); d=traF.next()) + CGoGNout << "Face of dart "<recompile(); - updateGLMatrices(); } -void MyQT::slider_explode(int x) -{ - m_shader2->setExplode(0.01*x); - updateGL(); -} -int main(int argc, char **argv) -{ - /// Utilisation des Marker - position = myMap.addAttribute(VERTEX, "position"); - - Algo::Modelisation::Polyhedron prim3(myMap, position); - Dart d2 = prim3.tore_topo(16, 24); - prim3.embedTore(1.0f,0.3f); - -// position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f); -// d2 = myMap.phi1(d2); -// position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f); -// d2 = myMap.phi1(d2); -// position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f); -// d2 = myMap.phi1(d2); -// d3 = myMap.phi<11>(d3); -// position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f); -// d3 = myMap.phi1(d3); -// position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f); -// d3 = myMap.phi1(d3); - -// unsigned int idAttV2 = myMap.addAttribute(VERTEX,"reel"); -// PFP::AttributeHandler tableReels(idAttV2,VERTEX,myMap); -// -// tableReels[d2] = 3.5f; -// tableReels[myMap.phi1(d2)] = 3.7f; -// -// // Attention ici on cree un attribut de FACE donc les face sont maintenant plangees -// // l'attribut cree se detruira a la fin de la portee de l'objet -// PFP::MAP::AutoAttributeHandler tableRGB(myMap, FACE, "RGB"); // "RGB" optionnel -// -// tableRGB[d3] = Geom::Vec3f(1.0f,2.0f,3.0f); -// -// // acces par les brins -// for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d)) -// { -// CGoGNout << "Brin "<::createHexa(myMap); + + Dart d2 = d1; + + position = myMap.addAttribute(VERTEX, "position"); + + position[d2] = PFP::VEC3(1, 0, 0); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(0, 0, 0); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(0, 1, 0); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(1, 1, 0); + d2 = PHI<2112>(d2); + position[d2] = PFP::VEC3(1, 0, 1); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(1, 1, 1); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(0, 1, 1); + d2 = PHI1(d2); + position[d2] = PFP::VEC3(0, 0, 1); + + // bounding box of scene Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); - // envoit info BB a l'interface - sqt.setParamObject(lWidthObj,lPosObj.data()); + // send BB info to interface for centering on GL screen + setParamObject(lWidthObj, lPosObj.data()); - sqt.setCallBack( dock.compileButton, SIGNAL(clicked()), SLOT(button_compile()) ); - sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(slider_explode(int)) ); + // first show for be sure that GL context is binded + show(); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f); +} - // show 1 pour GL context - sqt.show(); - // update du VBO position (context GL necessaire) - sqt.m_positionVBO->updateData(position); +// initialization GL callback +void MyQT::cb_initGL() +{ + m_render_topo = new Algo::Render::GL2::TopoRender() ; +} + +// redraw GL callback (clear and swap already done) +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->drawTopo(); + +} - // update des primitives du renderer - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); - sqt.m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); - sqt.m_render_topo->updateData(myMap, position, 0.9f, 0.9f); - dock.vertexEdit->setPlainText(QString(sqt.m_shader2->getVertexShaderSrc())); - dock.fragmentEdit->setPlainText(QString(sqt.m_shader2->getFragmentShaderSrc())); - dock.geometryEdit->setPlainText(QString(sqt.m_shader2->getGeometryShaderSrc())); - // show final pour premier redraw - sqt.show(); - CGoGNout.toConsole(&sqt); - CGoGNerr.toConsole(&sqt); - // et on attend la fin. - return app.exec(); -} diff --git a/Apps/Tuto/tuto4.h b/Apps/Tuto/tuto4.h index 0d6f58cd676ad24f824f2f3fd0d968e8122cef1b..0b5e0deeaa3d7f65b5f0ab3b2d7c62b00e6531d1 100644 --- a/Apps/Tuto/tuto4.h +++ b/Apps/Tuto/tuto4.h @@ -21,57 +21,70 @@ * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ - #ifndef _TUTO4_H_ #define _TUTO4_H_ #include "Utils/Qt/qtSimple.h" +#include "Utils/cgognStream.h" -#include "ui_tuto4.h" -// inclure qtui.h juste après le ui_xxx.h -#include "Utils/Qt/qtui.h" +#include "Topology/generic/parameters.h" +#include "Topology/map/embeddedMap2.h" +#include "Algo/Render/GL2/topoRender.h" -// forward definitions (minimize includes) syntax a little bit tricky !! -namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; class TopoRenderMapD; } } } } -namespace CGoGN { namespace Utils { class VBO; } } -namespace CGoGN { namespace Utils { class ShaderSimpleColor; } } -namespace CGoGN { namespace Utils { class ShaderFlat; } } using namespace CGoGN ; + /** - * A class for a little interface and rendering + * Struct that contains some informations about the types of the manipulated objects + * Mainly here to be used by the algorithms that are parameterized by it */ +struct PFP: public PFP_STANDARD +{ + // definition of the type of the map + typedef EmbeddedMap2 MAP; +}; + class MyQT: public Utils::QT::SimpleQT { Q_OBJECT - public: - // render - Algo::Render::GL2::MapRender* m_render; - Algo::Render::GL2::TopoRenderMapD* m_render_topo; + MyQT():m_render_topo(NULL){} - // VBO - Utils::VBO* m_positionVBO; + void cb_redraw(); + void cb_initGL(); + void cb_mouseClick(int button, int x, int y); - // shader basic - Utils::ShaderSimpleColor* m_shader; - Utils::ShaderFlat* m_shader2; +protected: + // declaration of the map + PFP::MAP myMap; - bool render_obj; - bool render_topo; + // attribute handler on position; + PFP::TVEC3 position; - MyQT():m_render(NULL), m_positionVBO(NULL), m_shader(NULL), render_obj(true), render_topo(false) {} + // render (for the topo) + Algo::Render::GL2::TopoRender* m_render_topo; - void cb_redraw(); + // selected dart (mouse click) + std::vector dart_selected; + // + Geom::Vec3f color; - void cb_initGL(); + // just for more compact writing + inline Dart PHI1(Dart d) {return myMap.phi1(d);} + inline Dart PHI_1(Dart d) {return myMap.phi_1(d);} + inline Dart PHI2(Dart d) {return myMap.phi2(d);} + template + Dart PHI(Dart d) {return myMap.phi(d);} - void cb_keyPress(int code); +public: + + // create the map (here tetrahedron + void createMap(); -public slots: - void button_compile(); - void slider_explode(int x); + // traverse the map using markers + void traverseMap(); }; + #endif diff --git a/Apps/Tuto/tuto5.cpp b/Apps/Tuto/tuto5.cpp index 3702aef8fb836d5372e240bbf8db489e2aee5b31..12a2cce799313c38cc06ee61accf32e22639190f 100644 --- a/Apps/Tuto/tuto5.cpp +++ b/Apps/Tuto/tuto5.cpp @@ -22,564 +22,314 @@ * * *******************************************************************************/ + #include "tuto5.h" +#include + + +#include "Algo/Modelisation/primitives3d.h" +#include "Algo/Modelisation/polyhedron.h" +#include "Algo/Modelisation/subdivision.h" + +#include "Algo/Render/GL2/topo3Render.h" +#include "Algo/Render/SVG/mapSVGRender.h" -//void Tuto5::balls_onoff(bool x) -//{ -// render_balls = !render_balls; -// updateGL(); -// CGoGNerr << " balls_onoff "<< CGoGNendl; -//} -// -//void Tuto5::vectors_onoff(bool x) -//{ -// render_vectors = !render_vectors; -// updateGL(); -// CGoGNerr << " vectors_onoff "<< CGoGNflush; -//} -// -//void Tuto5::text_onoff(bool x) -//{ -// render_text = !render_text; -// updateGL(); -// CGoGNerr << " text_onoff " << CGoGNflush; -//} - -void Tuto5::topo_onoff(bool x) + +PFP::MAP myMap; +PFP::TVEC3 position ; +Dart dglobal; + +void MyQT::balls_onoff(bool x) { - render_topo = !render_topo; + render_balls = !render_balls; updateGL(); - CGoGNerr << " topo_onoff " << CGoGNflush; + CGoGNerr << " balls_onoff "<< CGoGNendl; } -//void Tuto5::slider_balls(int x) -//{ -// m_sprite->setSize(0.05f*x); -// updateGL(); -//} -// -//void Tuto5::slider_vectors(int x) -//{ -// m_lines->setScale(0.02*x); -// updateGL(); -//} -// -//void Tuto5::slider_text(int x) -//{ -// m_strings->setScale(0.02f*x); -// updateGL(); -//} - -void Tuto5::animate() +void MyQT::vectors_onoff(bool x) { -// transfoMatrix() = glm::rotate(transfoMatrix(), 0.5f, glm::vec3(0.5773f,0.5773f,0.5773f)); - transfoRotate( 0.5f, 0.5773f,0.5773f,0.5773f); - updateGLMatrices(); + render_vectors = !render_vectors; + updateGL(); + CGoGNerr << " vectors_onoff "<< CGoGNflush; } -//void Tuto5::storeVerticesInfo() -//{ -// -// CellMarker mv(myMap,VERTEX); -// for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) -// { -// if (!mv.isMarked(d)) -// { -// mv.mark(d); -// std::stringstream ss; -// ss << d << " : "<< position[d]; -// m_strings->addString(ss.str(),position[d]); -// } -// } -//} - -void Tuto5::cb_initGL() +void MyQT::text_onoff(bool x) { -// Utils::GLSLShader::setCurrentOGLVersion(2); - Utils::GLSLShader::setCurrentOGLVersion(1) ; - -// // create the render -// m_render = new Algo::Render::GL2::MapRender(); -// -// m_render_topo = new Algo::Render::GL2::Topo3RenderMapD(); -// -// // create VBO for position -// m_positionVBO = new Utils::VBO(); -// m_positionVBO->updateData(position); -// -// // using simple shader with color -// m_shader = new Utils::ShaderSimpleColor(); -// m_shader->setAttributePosition(m_positionVBO); -// m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); -// -// m_sprite = new Utils::PointSprite(); -// m_sprite->setAttributePosition(m_positionVBO); -// -// m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f)); -// storeVerticesInfo(); -// m_strings->sendToVBO(); -// -// // copy de contenu de VBO a la creation -// m_dataVBO = new Utils::VBO(*m_positionVBO); -// -// m_lines = new Utils::ShaderVectorPerVertex(); -// m_lines->setAttributePosition(m_positionVBO); -// m_lines->setAttributeVector(m_dataVBO); -// m_lines->setScale(0.2f); -// m_lines->setColor(Geom::Vec4f(0.0f, 1.0f, 0.2f, 0.0f)); -// -// // accede au buffer du VBO pour modification -// PFP::VEC3* data = static_cast(m_dataVBO->lockPtr()); -// for (unsigned int i=0; i< m_dataVBO->nbElts(); ++i) -// { -// data[i].normalize(); -// } -// m_dataVBO->releasePtr(); -// -// registerShader(m_shader); -// registerShader(m_strings); -// registerShader(m_sprite); -// registerShader(m_lines); -// -// m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); -// m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); -// m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::POINTS); -// -// m_render_topo->updateData(myMap, allDarts, position, 0.9f, 0.9f, 0.9f); - - // timer example for animation - m_timer = new QTimer( this ); - connect( m_timer, SIGNAL(timeout()), SLOT(animate()) ); + render_text = !render_text; + updateGL(); + CGoGNerr << " text_onoff " << CGoGNflush; } -void Tuto5::cb_redraw() -{ -// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); -// glEnable(GL_LIGHTING); -// -// m_render->draw(m_shader, Algo::Render::GL2::POINTS); -// -// glLineWidth(2.0f); -// m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); -// m_render->draw(m_shader, Algo::Render::GL2::LINES); -// -// glEnable(GL_POLYGON_OFFSET_FILL); -// glPolygonOffset(1.0f, 1.0f); - if (render_topo) - { - glDisable(GL_LIGHTING); - glLineWidth(1.0f); -// Algo::Render::GL1::renderTopoGMD3(m, position, true, true, true, true, 0.9f, 0.9f, 0.9f, 0.9f); - Algo::Render::GL1::renderTopoMD3(m, position, true, true, true, 0.9f, 0.9f, 0.9f); -// m_render_topo->drawTopo(); - } - -// Dart d = myMap.phi2(myMap.begin()); -// m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f); -// d = myMap.phi1(myMap.begin()); -// m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f); -// -// glDisable(GL_POLYGON_OFFSET_FILL); -// -// if (render_text) -// m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f)); -// -// if (render_balls) -// { -// m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f)); -// m_render->draw(m_sprite, Algo::Render::GL2::POINTS); -// m_sprite->postdraw(); -// } -// -// if (render_vectors) -// { -// glLineWidth(1.0f); -// m_render->draw(m_lines, Algo::Render::GL2::POINTS); -// } +void MyQT::topo_onoff(bool x) +{ + render_topo = !render_topo; + updateGL(); + CGoGNerr << " topo_onoff " << CGoGNflush; } -void Tuto5::cb_mousePress(int button, int x, int y) +void MyQT::slider_balls(int x) { -// if (Shift()) -// { -// Dart d = m_render_topo->picking(myMap, allDarts, x,y); -// if (d != Dart::nil()) -// { -// CGoGNout << "Dart "<< d << " clicked" << CGoGNendl; -// } -// else -// { -// statusMsg(""); -// } -// } + m_sprite->setSize(0.05f*x); + updateGL(); } -void Tuto5::cb_keyPress(int code) +void MyQT::slider_vectors(int x) { -// if (code == 's') -// { -// std::string filename = selectFileSave("Export SVG file "); -// CGoGNout << "Exporting "<< filename << CGoGNendl; -// Algo::Render::SVG::SVGOut svg(filename, modelViewMatrix(), projectionMatrix()); -//// svg.renderLinesToSVG(myMap,position); -// svg.setColor(Geom::Vec3f(1.,0.,0.)); -// svg.renderFacesToSVG(myMap,position,0.8f); -// //svg destruction close the file -// } - if (code == 't') - { - if (m_timer->isActive()) - m_timer->stop(); - else - m_timer->start(1000/30); // 30 fps - } + m_lines->setScale(0.02*x); + updateGL(); } -Dart Tuto5::embedCube1() +void MyQT::slider_text(int x) { - Dart d = Algo::Modelisation::Polyhedron::createPolyhedron(m,6); - - m.closeMap(); - - Dart dres = d; - position[d] = PFP::VEC3(0,0,0); - position[m.phi1(d)] = PFP::VEC3(1,0,0); - position[m.phi1(m.phi1(d))] = PFP::VEC3(1,0,1); - position[m.phi_1(d)] = PFP::VEC3(0,0,1); - d = m.phi_1(m.phi2(m.phi_1(m.phi_1(m.phi2(m.phi_1(d)))))); - position[d] = PFP::VEC3(1,1,0); - position[m.phi1(d)] = PFP::VEC3(0,1,0); - position[m.phi1(m.phi1(d))] = PFP::VEC3(0,1,1); - position[m.phi_1(d)] = PFP::VEC3(1,1,1); - - return m.phi2(m.phi1(dres)); + m_strings->setScale(0.02f*x); + updateGL(); } -Dart Tuto5::embedCube2() + + +void MyQT::animate() { - Dart d = Algo::Modelisation::Polyhedron::createPolyhedron(m,6); - - m.closeMap(); - - Dart dres = d; - position[d] = PFP::VEC3(2,0,0); - position[m.phi1(d)] = PFP::VEC3(3,0,0); - position[m.phi1(m.phi1(d))] = PFP::VEC3(3,0,1); - position[m.phi_1(d)] = PFP::VEC3(2,0,1); - d = m.phi_1(m.phi2(m.phi_1(m.phi_1(m.phi2(m.phi_1(d)))))); - position[d] = PFP::VEC3(3,1,0); - position[m.phi1(d)] = PFP::VEC3(2,1,0); - position[m.phi1(m.phi1(d))] = PFP::VEC3(2,1,1); - position[m.phi_1(d)] = PFP::VEC3(3,1,1); - - return m.phi2(m.phi_1(dres)); +// transfoMatrix() = glm::rotate(transfoMatrix(), 0.5f, glm::vec3(0.5773f,0.5773f,0.5773f)); + transfoRotate( 0.5f, 0.5773f,0.5773f,0.5773f); + updateGLMatrices(); } -Dart Tuto5::embedMapCollapse() +void MyQT::storeVerticesInfo() { - Dart dd = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - Dart t1 = dd; - // plongement - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -1.f, -1.f); - t1 = m.phi_1(m.phi2(dd)); - position[t1] = PFP::VEC3(-0.5f, -1.f, 0.f); - - Dart ee = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(dd,ee); - t1 = ee; - // plongement - position[t1] = PFP::VEC3(0.0f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -1.f, -1.f); - t1 = m.phi_1(m.phi2(ee)); - position[t1] = PFP::VEC3(1.f, -1.f, 0.f); - - Dart ff = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(m.phi2(dd),ff); - t1 = ff; - // plongement - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(-0.5f, -1.f, 0.f); - t1 = m.phi_1(m.phi2(ff)); - position[t1] = PFP::VEC3(0.f, -1.f, 1.f); - - Dart gg = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(gg,m.phi2(ee)); - m.sewVolumes(m.phi2(gg),m.phi2(ff)); - t1 = gg; - // plongement - position[t1] = PFP::VEC3(0.0f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(1.f, -1.f, 0.f); - t1 = m.phi_1(m.phi2(gg)); - position[t1] = PFP::VEC3(0.f, -1.f, 1.f); - - Dart hh = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(m.phi2(m.phi_1(dd)),hh); - t1 = hh; - // plongement - position[t1] = PFP::VEC3(0.0f, -1.0f, -1.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(-0.5f, -1.f, 0.f); - t1 = m.phi_1(m.phi2(hh)); - position[t1] = PFP::VEC3(0.f, -0.2f, -0.8f); - - Dart jj = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(jj,m.phi<12>(ee)); - t1 = jj; - // plongement - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, -1.0f, -1.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(1.f, -1.f, 0.f); - t1 = m.phi_1(m.phi2(jj)); - position[t1] = PFP::VEC3(0.f, -0.2f, -0.8f); - - Dart kk = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(kk,m.phi<12>(dd)); - t1 = kk; - // plongement - position[t1] = PFP::VEC3(0.0f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, -1.0f, -1.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(-0.5f, -1.f, 0.f); - t1 = m.phi_1(m.phi2(kk)); - position[t1] = PFP::VEC3(0.f, -1.8f, -0.6f); - - Dart ll = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(ll,m.phi2(m.phi_1(ee))); - t1 = ll; - // plongement - position[t1] = PFP::VEC3(0.0f, -1.0f, -1.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(1.f, -1.f, 0.f); - t1 = m.phi_1(m.phi2(ll)); - position[t1] = PFP::VEC3(0.f, -1.8f, -0.6f); - - /*4 tetra du pourtout de devant */ - Dart mm = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(mm,m.phi2(m.phi_1(ff))); - t1 = mm; - // plongement - position[t1] = PFP::VEC3(-0.5f, -1.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.0f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -1.f, 1.f); - t1 = m.phi_1(m.phi2(mm)); - position[t1] = PFP::VEC3(0.f, -0.2f, 0.8f); - - Dart ww = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(ww,m.phi<12>(gg)); - t1 = ww; - // plongement - position[t1] = PFP::VEC3(0.f, 0.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(1.0f, -1.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -1.f, 1.f); - t1 = m.phi_1(m.phi2(ww)); - position[t1] = PFP::VEC3(0.f, -0.2f, 0.8f); - - Dart xx = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(xx,m.phi<12>(ff)); - t1 = xx; - // plongement - position[t1] = PFP::VEC3(0.f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(-0.5f, -1.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -1.f, 1.f); - t1 = m.phi_1(m.phi2(xx)); - position[t1] = PFP::VEC3(0.f, -1.6f, 0.6f); - - Dart cc = Algo::Modelisation::Polyhedron::createPolyhedron(m,4); - m.closeMap(); - m.sewVolumes(cc,m.phi2(m.phi_1(gg))); - t1 = cc; - // plongement - position[t1] = PFP::VEC3(1.f, -1.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -2.0f, 0.0f); - t1 = m.phi1(t1); - position[t1] = PFP::VEC3(0.f, -1.f, 1.f); - t1 = m.phi_1(m.phi2(cc)); - position[t1] = PFP::VEC3(0.f, -1.6f, 0.6f); - - return dd; + CellMarker mv(myMap,VERTEX); + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + { + if (!mv.isMarked(d)) + { + mv.mark(d); + std::stringstream ss; + ss << d << " : "<< position[d]; + m_strings->addString(ss.str(),position[d]); + } + } } -int main(int argc, char **argv) +void MyQT::cb_initGL() { - // un peu d'interface - QApplication app(argc, argv); - Tuto5 sqt; - - sqt.position = sqt.m.addAttribute(VERTEX, "position"); + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); + + // create the render + m_render = new Algo::Render::GL2::MapRender(); + + m_render_topo = new Algo::Render::GL2::Topo3Render(); + + // create VBO for position + m_positionVBO = new Utils::VBO(); + m_positionVBO->updateData(position); - Dart t1 = Algo::Modelisation::Polyhedron::createTetra(sqt.m) ; - Dart t2 = Algo::Modelisation::Polyhedron::createTetra(sqt.m) ; - sqt.m.sewVolumes(t1, t2, false) ; - sqt.m.closeHole(sqt.m.phi2(t1)) ; + // using simple shader with color + m_shader = new Utils::ShaderSimpleColor(); + m_shader->setAttributePosition(m_positionVBO); + m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.)); - Algo::Modelisation::Primitive3D primCat(sqt.m, sqt.position); - Dart d = primCat.hexaGrid_topo(3, 3, 3); - primCat.embedHexaGrid(1, 1, 1); + m_sprite = new Utils::PointSprite(); + m_sprite->setAttributePosition(m_positionVBO); -// Dart d1 = sqt.embedMapCollapse(); -// -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; -// -// -// sqt.m.collapseEdge(d1); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f)); + storeVerticesInfo(); + m_strings->sendToVBO(); -// Dart d1 = embedCube1() ; -// Dart d2 = embedCube2() ; + // copy de contenu de VBO a la creation + m_dataVBO = new Utils::VBO(*m_positionVBO); -// Dart dd = sqt.m.phi2(d1) ; + m_lines = new Utils::ShaderVectorPerVertex(); + m_lines->setAttributePosition(m_positionVBO); + m_lines->setAttributeVector(m_dataVBO); + m_lines->setScale(0.2f); + m_lines->setColor(Geom::Vec4f(0.0f, 1.0f, 0.2f, 0.0f)); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + // accede au buffer du VBO pour modification + PFP::VEC3* data = static_cast(m_dataVBO->lockPtr()); + for (unsigned int i=0; i< m_dataVBO->nbElts(); ++i) + { + data[i].normalize(); + } + m_dataVBO->releasePtr(); -// sqt.m.sewVolumes(d1, d2); + registerShader(m_shader); + registerShader(m_strings); + registerShader(m_sprite); + registerShader(m_lines); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + SelectorTrue allDarts; -// sqt.m.mergeVolumes(d1) ; + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::TRIANGLES); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::LINES); + m_render->initPrimitives(myMap, allDarts, Algo::Render::GL2::POINTS); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + SelectorDartNoBoundary nb(myMap); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f, 0.9f, nb); -// std::vector v ; -// v.push_back(dd) ; -// dd = sqt.m.phi1(sqt.m.phi2(sqt.m.phi1(dd))) ; -// v.push_back(dd) ; -// dd = sqt.m.phi1(sqt.m.phi2(sqt.m.phi1(dd))) ; -// v.push_back(dd) ; -// dd = sqt.m.phi1(sqt.m.phi2(sqt.m.phi1(dd))) ; -// v.push_back(dd) ; -// -// sqt.m.splitVolume(v) ; -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + // timer example for animation + m_timer = new QTimer( this ); + connect( m_timer, SIGNAL(timeout()), SLOT(animate()) ); +} -// Dart f = sqt.m.phi2(v.front()) ; -// Dart f3 = sqt.m.phi3(f) ; -// sqt.m.unsewVolumes(f) ; +void MyQT::cb_redraw() +{ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glEnable(GL_LIGHTING); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + m_render->draw(m_shader, Algo::Render::GL2::POINTS); -// sqt.m.sewVolumes(f, f3) ; + glLineWidth(2.0f); + m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); + m_render->draw(m_shader, Algo::Render::GL2::LINES); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + glEnable(GL_POLYGON_OFFSET_FILL); + glPolygonOffset(1.0f, 1.0f); -// sqt.m.splitFace(f, sqt.m.phi1(sqt.m.phi1(f))) ; + if (render_topo) + m_render_topo->drawTopo(); + +/* Dart d = myMap.phi2(myMap.begin()); + m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f); + d = myMap.phi1(myMap.begin()); + m_render_topo->overdrawDart(d, 5, 1.0f, 0.0f, 1.0f); +*/ + m_render_topo->overdrawDart(m_selected, 5, 1.0f, 0.0f, 1.0f); + -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + glDisable(GL_POLYGON_OFFSET_FILL); -// PFP::VEC3 p = sqt.position[f] + sqt.position[sqt.m.phi_1(f)] ; -// p /= 2.0 ; -// sqt.m.cutEdge(sqt.m.phi_1(f)) ; -// sqt.position[sqt.m.phi_1(f)] = p ; + if (render_text) + m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f)); -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; + if (render_balls) + { + m_sprite->predraw(Geom::Vec3f(1.0f, 0.0f ,0.0f)); + m_render->draw(m_sprite, Algo::Render::GL2::POINTS); + m_sprite->postdraw(); + } -// sqt.m.uncutEdge(sqt.m.phi_1(sqt.m.phi_1(f))) ; + if (render_vectors) + { + glLineWidth(1.0f); + m_render->draw(m_lines, Algo::Render::GL2::POINTS); + } +} -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; +void MyQT::cb_mousePress(int button, int x, int y) +{ + if (Shift()) + { + SelectorDartNoBoundary nb(myMap); + Dart d = m_render_topo->picking(myMap, x,y, nb); + if (d != Dart::nil()) + { + CGoGNout << "Dart "<< d << " clicked" << CGoGNendl; + m_selected = d; + } + else + { + statusMsg(""); + } + updateGL(); + } +} + +void MyQT::cb_keyPress(int code) +{ + if (code == 's') + { + std::string filename = selectFileSave("Export SVG file "); + CGoGNout << "Exporting "<(myMap,position); + svg.setColor(Geom::Vec3f(1.,0.,0.)); + svg.renderFacesToSVG(myMap,position,0.8f); + //svg destruction close the file + } + if (code == 't') + { + if (m_timer->isActive()) + m_timer->stop(); + else + m_timer->start(1000/30); // 30 fps + } +} -// sqt.m.deleteVolume(f) ; -// sqt.m.check() ; -// std::cout << "nb darts -> " << sqt.m.getNbDarts() << std::endl ; -// Algo::Modelisation::Primitive3D prim(myMap, position); + +int main(int argc, char **argv) +{ + position = myMap.addAttribute(VERTEX, "position"); + + CGoGNout << 5.34 << " toto "<< Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl; + CGoGNout << 3 << " tutu "<< 4 < prim(myMap, position); + int nb=3; + if (argc>1) + nb = atoi(argv[1]); + dglobal = prim.hexaGrid_topo(nb,nb,nb); + prim.embedHexaGrid(1.0f,1.0f,1.0f); + + // un peu d'interface + QApplication app(argc, argv); + MyQT sqt; // interface de tuto5.ui Utils::QT::uiDockInterface dock; sqt.setDock(&dock); -// // message d'aide -// sqt.setHelpMsg("Enter pour dock on/off\nShift Enter pour console on/off\nShift Click gauche pour selectionner un brin"); -// -// CGoGNout.toStatusBar(&sqt); -// CGoGNout << "CGoGNOut StatusBar" << Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl; -// -// CGoGNout.toConsole(&sqt); -// -// CGoGNout << "CGoGNOut dans la console" << Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl; -// -// CGoGNout.toStatusBar(NULL); - + // message d'aide + sqt.setHelpMsg("Enter pour dock on/off\nShift Enter pour console on/off\nShift Click gauche pour selectionner un brin"); + + CGoGNout.toStatusBar(&sqt); + CGoGNout << "CGoGNOut StatusBar" << Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl; + + CGoGNout.toConsole(&sqt); + + CGoGNout << "CGoGNOut dans la console" << Geom::Vec3f(2.5f, 2.2f, 4.3f) << CGoGNendl; + + CGoGNout.toStatusBar(NULL); + // bounding box - Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(sqt.m, sqt.position); + Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); // envoit info BB a l'interface sqt.setParamObject(lWidthObj, lPosObj.data()); -// sqt.setCallBack( dock.checkBox_balls, SIGNAL(toggled(bool)), SLOT(balls_onoff(bool)) ); -// sqt.setCallBack( dock.checkBox_vectors, SIGNAL(toggled(bool)), SLOT(vectors_onoff(bool)) ); -// sqt.setCallBack( dock.checkBox_text, SIGNAL(toggled(bool)), SLOT(text_onoff(bool)) ); + sqt.setCallBack( dock.checkBox_balls, SIGNAL(toggled(bool)), SLOT(balls_onoff(bool)) ); + sqt.setCallBack( dock.checkBox_vectors, SIGNAL(toggled(bool)), SLOT(vectors_onoff(bool)) ); + sqt.setCallBack( dock.checkBox_text, SIGNAL(toggled(bool)), SLOT(text_onoff(bool)) ); sqt.setCallBack( dock.checkBox_topo, SIGNAL(toggled(bool)), SLOT(topo_onoff(bool)) ); -// sqt.setCallBack( dock.slider_balls, SIGNAL(valueChanged(int)), SLOT(slider_balls(int)) ); -// sqt.setCallBack( dock.slider_vectors, SIGNAL(valueChanged(int)), SLOT(slider_vectors(int)) ); -// sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) ); + sqt.setCallBack( dock.slider_balls, SIGNAL(valueChanged(int)), SLOT(slider_balls(int)) ); + sqt.setCallBack( dock.slider_vectors, SIGNAL(valueChanged(int)), SLOT(slider_vectors(int)) ); + sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) ); + + + sqt.m_selected = myMap.begin(); sqt.show(); -// sqt.slider_balls(50); -// sqt.slider_vectors(50); -// sqt.slider_text(50); + sqt.slider_balls(50); + sqt.slider_vectors(50); + sqt.slider_text(50); + + GLint texSize; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); + CGoGNdbg.toConsole(&sqt); + CGoGNerr.toConsole(&sqt); + CGoGNdbg << " TextureSize " << texSize << CGoGNendl; + CGoGNerr << " test ERROR " << 5*7 << CGoGNflush; + -// GLint texSize; -// glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); -// CGoGNdbg.toConsole(&sqt); -// CGoGNerr.toConsole(&sqt); -// CGoGNdbg << " TextureSize " << texSize << CGoGNendl; -// CGoGNerr << " test ERROR " << 5*7 << CGoGNflush; // et on attend la fin. return app.exec(); diff --git a/Apps/Tuto/tuto5.h b/Apps/Tuto/tuto5.h index fd35fdf0913446ccf1d82805bedf9ef14fe92341..08d83be12b94a036eb7b01d608a2c5e1bbf57465 100644 --- a/Apps/Tuto/tuto5.h +++ b/Apps/Tuto/tuto5.h @@ -24,46 +24,57 @@ #ifndef __TUTO5_ #define __TUTO5_ + #include +#define WITH_GMAP 1 + #include "Topology/generic/parameters.h" -#include "Topology/map/embeddedMap3.h" +#ifdef WITH_GMAP + #include "Topology/gmap/embeddedGMap3.h" +#else + #include "Topology/map/embeddedMap3.h" +#endif #include "Geometry/vector_gen.h" #include "Algo/Geometry/boundingbox.h" #include "Algo/Render/GL2/mapRender.h" -#include "Algo/Render/GL2/topo3Render.h" #include "Utils/Shaders/shaderSimpleColor.h" -#include "Algo/Render/SVG/mapSVGRender.h" - -#include "Algo/Modelisation/primitives3d.h" -#include "Algo/Modelisation/polyhedron.h" -#include "Algo/Modelisation/subdivision.h" +#include "Algo/Render/GL2/topo3Render.h" #include "Topology/generic/cellmarker.h" - -#include "Algo/Render/GL1/map_glRender.h" -#include "Algo/Render/GL1/topo_render.h" - #include "Utils/text3d.h" + #include "Utils/pointSprite.h" #include "Utils/Shaders/shaderVectorPerVertex.h" #include "Utils/cgognStream.h" + + + #include "Utils/Qt/qtSimple.h" #include "ui_tuto5.h" // inclure qtui.h juste après le ui_xxx.h #include "Utils/Qt/qtui.h" + using namespace CGoGN ; struct PFP: public PFP_STANDARD { // definition de la carte +#ifdef WITH_GMAP + typedef EmbeddedGMap3 MAP; +#else typedef EmbeddedMap3 MAP; +#endif }; + +using namespace CGoGN ; + + /** * Utilisation de designer-qt4: * Faire un DockWiget (laisser le nom par defaut @@ -71,7 +82,7 @@ struct PFP: public PFP_STANDARD * Ajouter les widgets necessaires, mettre des noms clairs pour * les utiliser dans le .cpp (pour les call back principalement) */ -class Tuto5: public Utils::QT::SimpleQT +class MyQT: public Utils::QT::SimpleQT { Q_OBJECT @@ -80,42 +91,39 @@ class Tuto5: public Utils::QT::SimpleQT bool render_vectors; bool render_topo; -// Algo::Render::GL2::MapRender* m_render; -// Algo::Render::GL2::Topo3RenderMapD* m_render_topo; -// -// Utils::VBO* m_positionVBO; -// Utils::VBO* m_dataVBO; + Algo::Render::GL2::MapRender* m_render; + Algo::Render::GL2::Topo3Render* m_render_topo; -// Utils::ShaderSimpleColor* m_shader; -// Utils::ShaderVectorPerVertex* m_lines; -// Utils::Strings3D* m_strings; -// Utils::PointSprite* m_sprite; + Utils::VBO* m_positionVBO; + Utils::VBO* m_dataVBO; - QTimer *m_timer; + Utils::ShaderSimpleColor* m_shader; + Utils::ShaderVectorPerVertex* m_lines; + Utils::Strings3D* m_strings; + Utils::PointSprite* m_sprite; + QTimer *m_timer; + public: - PFP::MAP m; - PFP::TVEC3 position ; - Dart dglobal; - - Tuto5(): - render_text(false), - render_balls(false), - render_vectors(false), + MyQT(): + render_text(true), + render_balls(true), + render_vectors(true), render_topo(true), -// m_render(NULL), -// m_render_topo(NULL), -// m_positionVBO(NULL), -// m_dataVBO(NULL), -// m_shader(NULL), -// m_lines(NULL), -// m_strings(NULL), -// m_sprite(NULL), + m_render(NULL), + m_render_topo(NULL), + m_positionVBO(NULL), + m_dataVBO(NULL), + m_shader(NULL), + m_lines(NULL), + m_strings(NULL), + m_sprite(NULL), m_timer(NULL) {} + Dart m_selected; protected: - void storeVerticesInfo(); + void storeVerticesInfo(); void cb_redraw(); @@ -127,21 +135,16 @@ protected: // slots locaux public slots: -// void balls_onoff(bool x); -// void vectors_onoff(bool x); -// void text_onoff(bool x); + void balls_onoff(bool x); + void vectors_onoff(bool x); + void text_onoff(bool x); void topo_onoff(bool x); -// void slider_balls(int x); -// void slider_vectors(int x); -// void slider_text(int x); + void slider_balls(int x); + void slider_vectors(int x); + void slider_text(int x); void animate(); - - Dart embedCube1(); - Dart embedCube2(); - Dart embedMapCollapse(); - }; #endif diff --git a/include/Algo/MC/image.hpp b/include/Algo/MC/image.hpp index 53040ff99ef9481fe350a776759c1649defd8ea9..f8d9cd00e3ca4bee6a887b9b9179da5717b05ab5 100644 --- a/include/Algo/MC/image.hpp +++ b/include/Algo/MC/image.hpp @@ -719,7 +719,7 @@ template< typename DataType > Image* Image::cropz(unsigned int zmin, unsigned int nb) { - unsigned int zmax = zmin+nb; + int zmax = zmin+nb; if (zmax> m_WZ) { zmax = m_WZ; @@ -731,7 +731,7 @@ Image* Image::cropz(unsigned int zmin, unsigned int nb) newImg->m_Alloc=true; // set origin of real data in image ?? - for(unsigned int z=zmin; z< zmax; ++z) + for(int z=zmin; z< zmax; ++z) { for(int y=0; y namespace CGoGN { @@ -1221,11 +1222,11 @@ void MarchingCube::removeFacesOfBoundary(AttributeHand boundVertices[it] = 0; } - // traverse face and check if all vertices are bound +// traverse face and check if all vertices are bound DartMarker mf(*m_map); - for (Dart d = m_map->begin(); d != m_map->end();) + for (Dart d = m_map->begin(); d != m_map->end();) // next done inside loop because of deleteFace { - if (!mf.isMarked(d)) + if (!mf.isMarked(d) && !m_map->isBoundaryMarked(d)) { Dart dd = d; Dart e = m_map->phi1(d); @@ -1236,13 +1237,32 @@ void MarchingCube::removeFacesOfBoundary(AttributeHand m_map->next(d); } if ((boundVertices[dd]!=0) && (boundVertices[e]!=0) && (boundVertices[f]!=0)) - m_map->deleteFace(dd); + m_map->deleteFace(dd,false); else mf.markOrbit(FACE,dd); } + else m_map->next(d); } + m_map->closeMap(); - +//// VERSION USING DELETE FACE WITH BOUNDARY +// DartMarker mf(*m_map); +// std::vector vecF; +// vecF.reserve(8192); +// for (Dart d = m_map->begin(); d != m_map->end();m_map->next(d)) // next done inside loop because of deleteFace +// { +// if ((!mf.isMarked(d)) && (!m_map->isBoundaryMarked(d)) ) +// { +// Dart dd = d; +// Dart e = m_map->phi1(d); +// Dart f = m_map->phi1(e); +// if ((boundVertices[dd]!=0) && (boundVertices[e]!=0) && (boundVertices[f]!=0)) +// vecF.push_back(d); +// mf.markOrbit(FACE,dd); +// } +// } +// for (std::vector::iterator it = vecF.begin(); it != vecF.end(); ++it) +// m_map->deleteFace(*it); } diff --git a/include/Algo/Render/GL2/topo3Render.h b/include/Algo/Render/GL2/topo3Render.h index a8cc1f76f12d80975804825e3bffef50484e1ef7..d98b3d0237b9418c8921c7aaf296bc15402afbf9 100644 --- a/include/Algo/Render/GL2/topo3Render.h +++ b/include/Algo/Render/GL2/topo3Render.h @@ -60,9 +60,9 @@ protected: /** * vbo buffers * 0: vertices darts - * 1: vertices phi1 - * 2: vertices phi2 - * 3: vertices phi3 + * 1: vertices phi1 / beta1 + * 2: vertices phi2 / beta2 + * 3: vertices phi3 / beta3 * 4: colors */ Utils::VBO* m_vbo0; @@ -238,8 +238,6 @@ public: */ void overdrawDart(Dart d, float width, float r, float g, float b); - - /* * store darts in color for picking * @param map the map (must be the same than during updating data) @@ -248,8 +246,6 @@ public: template void setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good); - - /** * pick dart with color set bey setDartsIdColor * Do not forget to apply same transformation to scene before picking than before drawing ! @@ -260,15 +256,8 @@ public: * @return the dart or NIL */ template - Dart picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y); - -}; - + Dart picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good=allDarts); - -class Topo3RenderMapD: public Topo3Render -{ -public: /** * update all drawing buffers to render a dual map * @param map the map @@ -279,27 +268,37 @@ public: * @param kv exploding coef for face */ template - void updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float ke, float kf, float kv); -}; + void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); +protected: + /** + * update all drawing buffers to render a dual map + * @param map the map + * @param positions attribute of position vertices + * @param ke exploding coef for edge + * @param kf exploding coef for face + * @param kv exploding coef for face + * @param good selector + */ + template + void updateDataMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); -class Topo3RenderGMap: public Topo3Render -{ -public: /** * update all drawing buffers to render a gmap * @param map the map - * @param good selector * @param positions attribute of position vertices * @param ke exploding coef for edge * @param kf exploding coef for face * @param kv exploding coef for face + * @param good selector */ template - void updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float kd, float ke, float kf, float kv); + void updateDataGMap3(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good = allDarts); + }; -}//end namespace VBO + +}//end namespace GL2 }//end namespace Algo diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index fb8811b64777f1ddc3b0dbc9cbf5c10c3ba4d87a..5612a9f98e679e2a18819f248e5dd726588f0a6c 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -42,10 +42,27 @@ namespace Render namespace GL2 { +template +void Topo3Render::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good) +{ + Map3* ptrMap3 = dynamic_cast(&map); + if (ptrMap3 != NULL) + { + updateDataMap3(map,positions,ke,kf,kv,good); + } + GMap3* ptrGMap3 = dynamic_cast(&map); + if (ptrGMap3 != NULL) + { + updateDataGMap3(map,positions,ke,kf,kv,good); + } +} + template -void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float ke, float kf, float kv) +void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good) { + Map3& map = reinterpret_cast(mapx); + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -57,8 +74,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go m_attIndex = map.template addAttribute(DART, "dart_index"); } - - m_nbDarts = 0; // table of center of volume @@ -71,11 +86,16 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go std::vector vecDartFaces; vecDartFaces.reserve(map.getNbDarts()/4); + unsigned int posDBI=0; + DartMarker mark(map); // marker for darts for (Dart d = map.begin(); d != map.end(); map.next(d)) { if (good(d)) { + m_attIndex[d] = posDBI; + posDBI+=2; + CellMarkerStore markVert(map, VERTEX); //marker for vertices VEC3 center(0, 0, 0); unsigned int nbv = 0; @@ -133,7 +153,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go 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); - unsigned int posDBI=0; @@ -154,8 +173,6 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go { const VEC3& P = positions[d]; vecPos.push_back(P); - m_attIndex[d] = posDBI; - posDBI+=2; center += P; d = map.phi1(d); } while (d != dd); @@ -181,8 +198,8 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go *positionDartBuf++ = P; *positionDartBuf++ = Q; - *colorDartBuf++ = VEC3(1.,1.,1.); - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = VEC3(1.,1.,1.0); + *colorDartBuf++ = VEC3(1.,1.,1.0); fv1[d] = P*0.1f + Q*0.9f; fv11[d] = P*0.9f + Q*0.1f; @@ -236,7 +253,7 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go m_nbRel2++; } e = map.phi3(d); - if (!map.isBoundaryFace(d) && (d < e)) + if (!map.isBoundaryMarked(e) && (d < e)) { *positionF3++ = fv2[d]; *positionF3++ = fv2x[e]; @@ -268,19 +285,19 @@ void Topo3RenderMapD::updateData(typename PFP::MAP& map, const FunctorSelect& go template void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& good) { - m_vbo4->bind(); float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); unsigned int nb=0; for (Dart d = map.begin(); d != map.end(); map.next(d)) { - if (nb < m_nbDarts) + if (good(d)) { - if (good(d)) + if (nb < m_nbDarts) { float r,g,b; dartToCol(d, r,g,b); + float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO *local++ = r; *local++ = g; @@ -291,18 +308,20 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& g nb++; } - } - else - { - CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl; - d = map.end(); + else + { + CGoGNerr << "Error buffer too small for color picking (change the good parameter ?)" << CGoGNendl; + d = map.end(); + } } } glUnmapBuffer(GL_ARRAY_BUFFER); + + std::cout << "NB DARTS="< -Dart Topo3Render::picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y) +Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good) { pushColors(); setDartsIdColor(map,good); @@ -312,15 +331,13 @@ Dart Topo3Render::picking(typename PFP::MAP& map, const FunctorSelect& good, int } template -void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& positions, float kd, float ke, float kf, float kv) +void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv, const FunctorSelect& good) { + GMap3& map = reinterpret_cast(mapx); + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; - AutoAttributeHandler posBeta1(map, DART); - AutoAttributeHandler posBeta2(map, DART); //beta 3 link is represented at the same location as beta2 - AutoAttributeHandler posBeta2x(map, DART); //beta 3 link is represented at the same location as beta2 - AutoAttributeHandler vert(map, DART); if (m_attIndex.map() != &map) { @@ -331,29 +348,29 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go m_nbDarts = 0; - // table of face (one dart of each) - std::vector vecDartFaces; - vecDartFaces.reserve(map.getNbDarts()/6); //6 = nb of darts for tri mesh - + // table of center of volume + std::vector vecCenters; + vecCenters.reserve(1000); // table of nbfaces per volume std::vector vecNbFaces; - vecNbFaces.reserve(vecDartFaces.size()); - - // table of center of volume - std::vector vecVolCenters; - vecVolCenters.reserve(vecDartFaces.size()/4); // = nb of volumes for a tetra mesh + vecNbFaces.reserve(1000); + // table of face (one dart of each) + std::vector vecDartFaces; + vecDartFaces.reserve(map.getNbDarts()/4); + unsigned int posDBI=0; DartMarker mark(map); // marker for darts - CellMarker mVol(map, VOLUME); for (Dart d = map.begin(); d != map.end(); map.next(d)) { - if(!mVol.isMarked(d)) + if (good(d)) { - mVol.mark(d); + m_attIndex[d] = posDBI; + posDBI+=2; + CellMarkerStore markVert(map, VERTEX); //marker for vertices - VEC3 center(0); - unsigned int nbVertices = 0; - unsigned int nbFace = 0; + VEC3 center(0, 0, 0); + unsigned int nbv = 0; + unsigned int nbf = 0; std::list visitedFaces; // Faces that are traversed visitedFaces.push_back(d); // Start with the face of d @@ -364,48 +381,49 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go { // store a dart of face vecDartFaces.push_back(*face); - nbFace++; + nbf++; Dart dNext = *face ; do { - mark.mark(dNext); // Mark - m_nbDarts++; - if (!markVert.isMarked(dNext)) { markVert.mark(dNext); center += positions[dNext]; - nbVertices++; + nbv++; } - - Dart adj = map.phi2(dNext); // add adjacent face if not done already + mark.mark(dNext); // Mark + mark.mark(map.beta0(dNext)); + m_nbDarts++; + Dart adj = map.phi2(dNext); // Get adjacent face if (adj != dNext && !mark.isMarked(adj)) - visitedFaces.push_back(adj); - + visitedFaces.push_back(adj); // Add it dNext = map.phi1(dNext); } while(dNext != *face); } } - center /= typename PFP::REAL(nbVertices); - vecVolCenters.push_back(center); - vecNbFaces.push_back(nbFace); + center /= typename PFP::REAL(nbv); + vecCenters.push_back(center); + vecNbFaces.push_back(nbf); } } - m_nbDarts *= 2; // x2 : only one orientation is used for the previous computation, multiply by 2 to get the number of darts + m_nbDarts *=2; + + // beta1 + AutoAttributeHandler fv1(map, DART); + // beta2/3 + AutoAttributeHandler fv2(map, DART); + AutoAttributeHandler fv2x(map, DART); - //colors m_vbo4->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - //darts 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); - unsigned int posDBI=0; std::vector::iterator face = vecDartFaces.begin(); for (unsigned int iVol=0; iVolbind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + + // beta1 m_vbo1->bind(); - glBufferData(GL_ARRAY_BUFFER, m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - //beta2 + // beta2 m_vbo2->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - //beta3 + // beta3 m_vbo3->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer3 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionF1 = reinterpret_cast(PositionBuffer1); @@ -508,38 +515,52 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go m_nbRel2=0; m_nbRel3=0; - //draw beta1, beta2, beta3 if required - for(Dart d = map.begin(); d != map.end(); map.next(d)) + for(std::vector::iterator face = vecDartFaces.begin(); face != vecDartFaces.end(); ++face) { - Dart e = map.beta2(d); - if ((dbind(); @@ -551,16 +572,11 @@ void Topo3RenderGMap::updateData(typename PFP::MAP& map, const FunctorSelect& go m_vbo1->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); - m_vbo0->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); - m_vbo4->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); - } - }//end namespace VBO }//end namespace Algo diff --git a/include/Algo/Render/GL2/topoRender.h b/include/Algo/Render/GL2/topoRender.h index 91c77c0daccea4de638bac498d20c8ed8dfbdf57..a158a0a06f881df33943f8a264e468751822851b 100644 --- a/include/Algo/Render/GL2/topoRender.h +++ b/include/Algo/Render/GL2/topoRender.h @@ -198,40 +198,24 @@ public: * @return the dart or NIL */ template - Dart picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y); -}; + Dart picking(typename PFP::MAP& map, int x, int y, const FunctorSelect& good=allDarts); -class TopoRenderMapD : public TopoRender -{ -public: - /** - * update all drawing buffers to render a dual map - * @param map the map - * @param positions attribute of position vertices - * @param ke exploding coef for edge - * @param kf exploding coef for face - * @param good selector - */ template void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts); -}; -class TopoRenderGMap : public TopoRender -{ -public: - /** - * update all drawing buffers to render a gmap - * @param map the map - * @param positions attribute of position vertices - * @param ke exploding coef for edge - * @param kf exploding coef for face - * @param good selector - */ template - void updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts); + void updateDataMap(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts); + + template + void updateDataGMap(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good = allDarts); }; -} // namespace VBO +// just for compatibility with old code +typedef TopoRender TopoRenderMapD; +typedef TopoRender TopoRenderGMap; + + +} // namespace GL2 } // namespace Render diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index 68a3f098c453c988c9934cdc53c01060e1f993fa..4d3ca64ea92e417709e5767678aaaf08136c6020 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -25,27 +25,47 @@ #include "Geometry/vector_gen.h" #include "Topology/generic/autoAttributeHandler.h" #include "Topology/generic/dartmarker.h" +#include "Topology/generic/parameters.h" + +#include "Topology/map/embeddedMap2.h" +#include "Topology/gmap/embeddedGMap2.h" namespace CGoGN { - namespace Algo { - namespace Render { - namespace GL2 { + +template +void TopoRender::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +{ + Map2* ptrMap2 = dynamic_cast(&map); + if (ptrMap2 != NULL) + { + updateDataMap(map,positions,ke,kf,good); + } + GMap2* ptrGMap2 = dynamic_cast(&map); + if (ptrGMap2 != NULL) + { + updateDataGMap(map,positions,ke,kf,good); + } +} + template -void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +//void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) { + Map2& map = reinterpret_cast(mapx); + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; std::vector vecDarts; - vecDarts.reserve(map.getNbDarts()/4); // not too big but not too many reallocation + vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory if (m_attIndex.map() != &map) { @@ -57,6 +77,7 @@ void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC if (good(d)) { vecDarts.push_back(d); + m_attIndex[d] = (vecDarts.size()-1)*2; } } m_nbDarts = vecDarts.size(); @@ -77,7 +98,9 @@ void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC 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); - unsigned int posDBI = 0; + + std::vector vecPos; + vecPos.reserve(16); DartMarker mf(map); for(std::vector::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) @@ -85,9 +108,8 @@ void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC Dart d = *id; if (!mf.isMarked(d)) { - std::vector vecPos; - vecPos.reserve(16); + vecPos.clear(); // store the face & center VEC3 center(0.0f,0.0f,0.0f); Dart dd = d; @@ -95,8 +117,6 @@ void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC { const VEC3& P = positions[d]; vecPos.push_back(P); - m_attIndex[d] = posDBI; - posDBI+=2; center += P; d = map.phi1(d); } while (d != dd); @@ -181,14 +201,16 @@ void TopoRenderMapD::updateData(typename PFP::MAP& map, const typename PFP::TVEC template -void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +//void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) +void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, const FunctorSelect& good) { -/* + GMap2& map = reinterpret_cast(mapx); + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; std::vector vecDarts; - vecDarts.reserve(map.getNbDarts()/4); // not too big but not too many reallocation + vecDarts.reserve(map.getNbDarts()); // no problem dart is int: no problem of memory if (m_attIndex.map() != &map) { @@ -200,39 +222,40 @@ void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC if (good(d)) { vecDarts.push_back(d); + m_attIndex[d] = (vecDarts.size()-1)*2; } } m_nbDarts = vecDarts.size(); - // beta1 + // debut phi1 AutoAttributeHandler fv1(map, DART); - // beta2 + // fin phi1 + AutoAttributeHandler fv11(map, DART); + // phi2 AutoAttributeHandler fv2(map, DART); - // sommets du brin -// AutoAttributeHandler vert(map, DART); - // 2ieme sommet du brin -// AutoAttributeHandler vert2(map, DART); - - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + m_vbo3->bind(); + glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo0->bind(); + glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionDartBuf = reinterpret_cast(PositionDartsBuffer); - unsigned int posDBI=0; + + + std::vector vecPos; + vecPos.reserve(16); DartMarker mf(map); for(std::vector::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) { Dart d = *id; + if (!mf.isMarked(d)) { - std::vector vecPos; - vecPos.reserve(16); - + vecPos.clear(); // store the face & center VEC3 center(0.0f,0.0f,0.0f); Dart dd = d; @@ -241,10 +264,6 @@ void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC const VEC3& P = positions[d]; vecPos.push_back(P); center += P; - m_attIndex[d] = posDBI; - posDBI+=2; - m_attIndex[map.beta0(d)] = posDBI; - posDBI+=2; d = map.phi1(d); } while (d != dd); center /= REAL(vecPos.size()); @@ -267,76 +286,74 @@ void TopoRenderGMap::updateData(typename PFP::MAP& map, const typename PFP::TVEC VEC3 QQ = REAL(0.52)*Q + REAL(0.48)*P; *positionDartBuf++ = P; - *positionDartBuf++ = PP; *colorDartBuf++ = VEC3(1.,1.,1.); + *positionDartBuf++ = PP; *colorDartBuf++ = VEC3(1.,1.,1.); - *positionDartBuf++ = Q; - *positionDartBuf++ = QQ; *colorDartBuf++ = VEC3(1.,1.,1.); + *positionDartBuf++ = QQ; *colorDartBuf++ = VEC3(1.,1.,1.); - Dart d0 = map.beta0(d); - - VEC3 f = Q*REAL(0.5) + QQ*REAL(0.5); - fv2[d0] = f; - f = QQ*REAL(0.2) + Q*REAL(0.8); - fv1[d0] = f; - - f = P*REAL(0.5) + PP*REAL(0.5); + VEC3 f = P*0.5f + PP*0.5f; fv2[d] = f; - f = PP*REAL(0.2) + P*REAL(0.8); + f = P*0.9f + PP*0.1f; fv1[d] = f; + dd = map.beta0(d); + f = Q*0.5f + QQ*0.5f; + fv2[dd] = f; + f = Q*0.9f + QQ*0.1f; + fv1[dd] = f; + d = map.phi1(d); } mf.markOrbit(FACE, d); } } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[0]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo0->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[3]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo3->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo1->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionBuffer1 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); - glBufferDataARB(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); - GLvoid* PositionBuffer2 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + m_vbo2->bind(); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + GLvoid* PositionBuffer2 = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionF1 = reinterpret_cast(PositionBuffer1); VEC3* positionF2 = reinterpret_cast(PositionBuffer2); - m_nbRel2=0; + m_nbRel2 =0; for(std::vector::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) { Dart d = *id; Dart e = map.beta2(d); - if (e.index > d.index) + + if (good(e) && (e.index > d.index)) { *positionF2++ = fv2[d]; *positionF2++ = fv2[e]; m_nbRel2++; } - e = map.beta1(d); *positionF1++ = fv1[d]; *positionF1++ = fv1[e]; } - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[1]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); + m_vbo1->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); + + m_vbo2->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); - glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_VBOBuffers[2]); - glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER); -*/ } @@ -377,7 +394,7 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelect& go } template -Dart TopoRender::picking(typename PFP::MAP& map, const FunctorSelect& good, int x, int y) +Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, const FunctorSelect& good) { pushColors(); setDartsIdColor(map,good); diff --git a/include/Topology/map/map2.h b/include/Topology/map/map2.h index 72c8130f82bc1244c52dda047c783ffb82a3e92b..46b40e2753989060916d16e15a1949897257aa3d 100644 --- a/include/Topology/map/map2.h +++ b/include/Topology/map/map2.h @@ -100,6 +100,7 @@ protected: void phi2unsew(Dart d); public: + /*! @name Generator and Deletor * To generate or delete faces in a 2-map *************************************************************************/ @@ -114,8 +115,9 @@ public: //! Delete the face of d /*! @param d a dart of the face + * @param withBoudary create or extend boundary face instead of fixed points (default true) */ - virtual void deleteFace(Dart d) ; + virtual void deleteFace(Dart d, bool withBoundary = true) ; //! Delete a connected component of the map /*! @param d a dart of the connected component diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index 5306159b00af1bdefe114d982626e1e3cb329275..5515d61af106b4a0a5e8c3eaf7fd8cc078cdaf77 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -43,6 +43,7 @@ namespace GL2 { Topo3Render::Topo3Render(): +m_nbDarts(0),m_nbRel2(0),m_nbRel3(0), m_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL) { m_vbo0 = new Utils::VBO(); @@ -132,6 +133,9 @@ void Topo3Render::setAllDartsColor(float r, float g, float b) void Topo3Render::drawDarts() { + if (m_nbDarts==0) + return; + m_shader2->enableVertexAttribs(); glLineWidth(m_topo_dart_width); @@ -174,6 +178,9 @@ void Topo3Render::drawDarts() void Topo3Render::drawRelation1() { + if (m_nbDarts==0) + return; + glLineWidth(m_topo_relation_width); m_shader1->changeVA_VBO(m_vaId, m_vbo1); @@ -197,6 +204,9 @@ void Topo3Render::drawRelation1() void Topo3Render::drawRelation2() { + if (m_nbRel2==0) + return; + m_shader1->changeVA_VBO(m_vaId, m_vbo2); m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); m_shader1->enableVertexAttribs(); @@ -218,6 +228,9 @@ void Topo3Render::drawRelation2() void Topo3Render::drawRelation3() { + if (m_nbRel3==0) + return; + m_shader1->changeVA_VBO(m_vaId, m_vbo3); m_shader1->setColor(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); m_shader1->enableVertexAttribs(); @@ -342,7 +355,9 @@ Dart Topo3Render::pickColor(unsigned int x, unsigned int y) glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); glClearColor(cc[0], cc[1], cc[2], cc[3]); - + + + std::cout << color[0] << ", "<enableVertexAttribs(); glLineWidth(m_topo_dart_width); @@ -137,6 +141,9 @@ void TopoRender::drawDarts() void TopoRender::drawRelation1() { + if (m_nbDarts==0) + return; + glLineWidth(m_topo_relation_width); m_shader1->changeVA_VBO(m_vaId, m_vbo1); @@ -150,6 +157,9 @@ void TopoRender::drawRelation1() void TopoRender::drawRelation2() { + if (m_nbRel2==0) + return; + glLineWidth(m_topo_relation_width); m_shader1->changeVA_VBO(m_vaId, m_vbo2); diff --git a/src/Topology/gmap/gmap2.cpp b/src/Topology/gmap/gmap2.cpp index a16648010bbd7834c4db39d900c68a8149293fb1..c052320b924d9fac05e3f2ba81924c2080887ec1 100644 --- a/src/Topology/gmap/gmap2.cpp +++ b/src/Topology/gmap/gmap2.cpp @@ -62,7 +62,7 @@ Dart GMap2::newFace(unsigned int nbEdges, bool withBoundary) Dart d = GMap1::newFace(nbEdges); if (withBoundary) { - Dart e = GMap1::newFace(nbEdges); + Dart e = GMap1::newBoundaryFace(nbEdges); Dart it = d; do diff --git a/src/Topology/map/map2.cpp b/src/Topology/map/map2.cpp index b318fe66c0d1c8863cb42fff0a570f9a0e73d188..197cfe18b2726b9be5cb32f7885547d35b424893 100644 --- a/src/Topology/map/map2.cpp +++ b/src/Topology/map/map2.cpp @@ -75,19 +75,31 @@ Dart Map2::newFace(unsigned int nbEdges, bool withBoundary) return d; } -void Map2::deleteFace(Dart d) +void Map2::deleteFace(Dart d, bool withBoundary) { assert(!isBoundaryMarked(d)) ; + if (withBoundary) + { + Dart it = d ; + do + { + if(!isBoundaryEdge(it)) + unsewFaces(it) ; + it = phi1(it) ; + } while(it != d) ; + Dart dd = phi2(d) ; + Map1::deleteCycle(d) ; + Map1::deleteCycle(dd) ; + return; + } + //else with remove the face and create fixed points Dart it = d ; do { - if(!isBoundaryEdge(it)) - unsewFaces(it) ; + phi2unsew(it); it = phi1(it) ; } while(it != d) ; - Dart dd = phi2(d) ; - Map1::deleteCycle(d) ; - Map1::deleteCycle(dd) ; + Map1::deleteCycle(d); } void Map2::deleteCC(Dart d) @@ -316,12 +328,13 @@ void Map2::unsewFaces(Dart d) Dart ee = phi1(e) ; Dart f = findBoundaryEdgeOfVertex(d) ; + Dart ff = findBoundaryEdgeOfVertex(dd) ; + if(f != NIL) phi1sew(e, phi_1(f)) ; - f = findBoundaryEdgeOfVertex(dd) ; - if(f != NIL) - phi1sew(ee, phi_1(f)) ; + if(ff != NIL) + phi1sew(ee, phi_1(ff)) ; phi2unsew(d) ; diff --git a/src/Utils/GLSLShader.cpp b/src/Utils/GLSLShader.cpp index d8b195b037d8379a6519a73d7cb451d25a989807..3165974044a41e11c8fbd18d0420fea696db1646 100644 --- a/src/Utils/GLSLShader.cpp +++ b/src/Utils/GLSLShader.cpp @@ -84,7 +84,7 @@ GLSLShader::GLSLShader() : m_geom_shader_source(NULL) { if (DEFINES_GL == NULL) - DEFINES_GL = &DEFINES_GL3; + DEFINES_GL = &DEFINES_GL2; } void GLSLShader::registerShader(void* ptr, GLSLShader* shader)