diff --git a/Apps/Tuto/CMakeLists.txt b/Apps/Tuto/CMakeLists.txt index 97dcc00e6f0e674829f92a2bf4bb8db10612f1ba..bc4d723155eb60d1a7a852b666375f49d500d3d8 100644 --- a/Apps/Tuto/CMakeLists.txt +++ b/Apps/Tuto/CMakeLists.txt @@ -53,6 +53,12 @@ add_executable( tuto5 tuto5.cpp ${tuto5_ui} ${tuto5_moc}) target_link_libraries( tuto5 ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) +QT4_WRAP_UI( tuto_oper2_ui tuto_oper2.ui ) +QT4_WRAP_CPP(tuto_oper2_moc tuto_oper2.h) +add_executable( tuto_oper2 tuto_oper2.cpp ${tuto_oper2_ui} ${tuto_oper2_moc}) +target_link_libraries( tuto_oper2 + ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) + QT4_WRAP_UI( tuto_orbits_ui tuto_orbits.ui ) QT4_WRAP_CPP(tuto_orbits_moc tuto_orbits.h) add_executable( tuto_orbits tuto_orbits.cpp ${tuto_orbits_ui} ${tuto_orbits_moc}) diff --git a/Apps/Tuto/tuto_oper2.cpp b/Apps/Tuto/tuto_oper2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e4688f5404143bfa694b0dd583e2a5087a95794 --- /dev/null +++ b/Apps/Tuto/tuto_oper2.cpp @@ -0,0 +1,291 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.u-strasbg.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#include "tuto_oper2.h" +#include "Algo/Geometry/boundingbox.h" +#include "Algo/Modelisation/polyhedron.h" +#include "Algo/Geometry/centroid.h" +using namespace CGoGN ; + + +int main(int argc, char **argv) +{ + // // interface + QApplication app(argc, argv); + MyQT sqt; + + + sqt.setDock(& sqt.dock); + sqt.setCallBack( sqt.dock.listOper, SIGNAL(currentRowChanged(int)), SLOT(operation(int)) ); + + int n=3; + if (argc==2) + n = atoi(argv[1]); + + // example code itself + sqt.createMap(n); + + // 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(); +} + + +void MyQT::operation(int x) +{ + switch(x) + { + case 0: + CGoGNout <<"split vertex"<(myMap, m_selected, position); + PFP::VEC3 c2 = Algo::Geometry::faceCentroid(myMap, m_selected2, position); + position[m_selected] = position[m_selected] * 0.7f + c1*0.3f; + position[m_selected2] = position[m_selected2] * 0.7f + c2*0.3f; + updateMap(); + } + break; + case 1: + CGoGNout <<"delete vertex"<setCurrentRow(-1); +} + +void MyQT::createMap(int n) +{ + + position = myMap.addAttribute(VERTEX, "position"); + colorDarts = myMap.addAttribute(DART, "color"); + + Algo::Modelisation::Polyhedron grid(myMap,position); + grid.grid_topo(n,n); + grid.embedGrid(1.,1.,0.); + + + // 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); + + // send BB info to interface for centering on GL screen + setParamObject(lWidthObj, lPosObj.data()); + + // first show for be sure that GL context is binded + show(); + + // render the topo of the map without boundary darts + + dm.markAll(); + + m_render_topo->setDartWidth(5.0f); + m_render_topo->setInitialDartsColor(0.0f,0.0f,0.0f); + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,nb); + + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + { + if (dm.isMarked(d) && (!myMap.isBoundaryMarked(d))) + { + int n = random(); + float r = float(n&0x7f)/255.0f + 0.25f; + float g = float((n>>8)&0x7f)/255.0f + 0.25f; + float b = float((n>>16)&0x7f)/255.0 + 0.25f; + colorDarts[d] = Geom::Vec3f(r,g,b); + m_render_topo->setDartColor(d,r,g,b); + } + } +} + + + +void MyQT::updateMap() +{ + m_render_topo->updateData(myMap, position, 0.9f, 0.9f,nb); + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + { + if (dm.isMarked(d) && (!myMap.isBoundaryMarked(d))) + { + const Geom::Vec3f& C = colorDarts[d]; + if (C*C != 0.0f) + m_render_topo->setDartColor(d,C[0],C[1],C[2]); + } + } +} + +// initialization GL callback +void MyQT::cb_initGL() +{ + glClearColor(1.0f,1.0f,1.0f,1.0f); + m_render_topo = new Algo::Render::GL2::TopoRender() ; +} + +// redraw GL callback (clear and swap already done) +void MyQT::cb_redraw() +{ + glEnable( GL_POLYGON_OFFSET_FILL ); + glPolygonOffset( 1.0f, 1.0f ); + + m_render_topo->drawTopo(); + + glDisable( GL_POLYGON_OFFSET_FILL ); + + if (m_selected != NIL) + m_render_topo->overdrawDart(m_selected, 11, 1.0f, 0.0f, 0.0f); + + if (m_selected2 != NIL) + m_render_topo->overdrawDart(m_selected2, 11, 0.0f, 1.0f, 0.0f); +} + +void MyQT::cb_mousePress(int button, int x, int y) +{ + if (Shift()) + { + Dart d = m_render_topo->picking(myMap, x,y, nb); + if (button == Qt::LeftButton) + { + if (d != Dart::nil()) + m_selected = d; + } + if (button == Qt::RightButton) + { + if (d != Dart::nil()) + m_selected2 = d; + } + updateGL(); + } +} + +void MyQT::cb_keyPress(int keycode) +{ + switch(keycode) + { + case 'c': + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + { + if (!myMap.isBoundaryMarked(d)) + { + int n = random(); + float r = float(n&0x7f)/255.0f + 0.25f; + float g = float((n>>8)&0x7f)/255.0f + 0.25f; + float b = float((n>>16)&0x7f)/255.0 + 0.25f; + colorDarts[d] = Geom::Vec3f(r,g,b); + m_render_topo->setDartColor(d,r,g,b); + } + } + break; + case 'g': + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + { + if (!myMap.isBoundaryMarked(d)) + { + colorDarts[d] = Geom::Vec3f(0.5f,0.5f,0.5f); + m_render_topo->setDartColor(d,0.5f,0.5f,0.5f); + } + } + break; + } + + updateGL(); +} + diff --git a/Apps/Tuto/tuto_oper2.h b/Apps/Tuto/tuto_oper2.h new file mode 100644 index 0000000000000000000000000000000000000000..5b32859ea0c3b5ed26c0a9d1bf80a7c0239139cf --- /dev/null +++ b/Apps/Tuto/tuto_oper2.h @@ -0,0 +1,112 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.u-strasbg.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef _TUTO_OPER2_ +#define _TUTO_OPER2_ + +//#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" + + +#include "ui_tuto_oper2.h" +#include "Utils/Qt/qtui.h" +#include "Utils/Qt/qtSimple.h" +#include "Utils/cgognStream.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 +#ifdef USE_GMAP + typedef EmbeddedGMap2 MAP; +#else + typedef EmbeddedMap2 MAP; +#endif +}; + + + +class MyQT: public Utils::QT::SimpleQT +{ + Q_OBJECT +public: + MyQT():nb(myMap),m_render_topo(NULL),m_selected(NIL),m_selected2(NIL),dm(myMap) {} + + void cb_redraw(); + void cb_initGL(); + void cb_mousePress(int button, int x, int y); + void cb_keyPress(int code); + + Utils::QT::uiDockInterface dock; + +protected: + // declaration of the map + PFP::MAP myMap; + + PFP::TVEC3 position; + AttributeHandler colorDarts; + + SelectorDartNoBoundary nb; + + // render (for the topo) + Algo::Render::GL2::TopoRender* m_render_topo; + Dart m_selected; + Dart m_selected2; + DartMarker dm; + + // 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);} + +public: + // example of simple map creation + void createMap(int n); + void updateMap(); + +public slots: + void operation(int x); +}; + + + +#endif diff --git a/Apps/Tuto/tuto_oper2.ui b/Apps/Tuto/tuto_oper2.ui new file mode 100644 index 0000000000000000000000000000000000000000..8eba27f1b108629eabaeaa09bbac5c5c5a886fbb --- /dev/null +++ b/Apps/Tuto/tuto_oper2.ui @@ -0,0 +1,119 @@ + + + DockWidget + + + + 0 + 0 + 227 + 369 + + + + + 150 + 250 + + + + Interface + + + + true + + + + 0 + 0 + + + + + 150 + 200 + + + + + 2 + + + 4 + + + + + + + Qt::NoFocus + + + + splitVertex + + + + + deleteVertex + + + + + cutEdge + + + + + uncutEdge + + + + + collapseEdge + + + + + flipEdge + + + + + flipBackEdge + + + + + splitFace + + + + + mergeFace + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + diff --git a/include/Algo/Render/GL2/topo3Render.h b/include/Algo/Render/GL2/topo3Render.h index f93f8e9d0ff6b74a6de85ad8afe0af919109e75c..08dc772e6cbcd6e2903a8678845843d9709943db 100644 --- a/include/Algo/Render/GL2/topo3Render.h +++ b/include/Algo/Render/GL2/topo3Render.h @@ -33,6 +33,7 @@ #include "Topology/generic/dart.h" #include "Topology/generic/attributeHandler.h" #include "Topology/generic/functor.h" +#include "Geometry/vector_gen.h" #include "Utils/vbo.h" @@ -102,9 +103,19 @@ protected: */ float m_topo_relation_width; - + /** + * pointer for saved colorvbo (in picking) + */ float *m_color_save; + /** + * initial darts color (set in update) + */ + Geom::Vec3f m_dartsColor; + + /** + * attribute index to get easy correspdance dart/color + */ AttributeHandler m_attIndex; @@ -204,6 +215,15 @@ public: */ void setAllDartsColor(float r, float g, float b); + /** + * change dart initial color (used when calling updateData) + * @param d the dart + * @param r red ! + * @param g green ! + * @param b blue ! + */ + void setInitialDartsColor(float r, float g, float b); + /** * overdraw a dart with given width and color * @param d the dart diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index 261472eaa230303483dc647efb148f6ba1ccffa8..5a6da3c830a7c002ab2cb06dc719f60de0a0e8c0 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -167,8 +167,8 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const typename PFP::TV *positionDartBuf++ = P; *positionDartBuf++ = Q; - *colorDartBuf++ = VEC3(1.,1.,1.0); - *colorDartBuf++ = VEC3(1.,1.,1.0); + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; fv1[d] = P*0.1f + Q*0.9f; fv11[d] = P*0.9f + Q*0.1f; @@ -417,10 +417,10 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const typename PFP::T *positionDartBuf++ = PP; *positionDartBuf++ = Q; *positionDartBuf++ = QQ; - *colorDartBuf++ = VEC3(1.,1.,1.); - *colorDartBuf++ = VEC3(1.,1.,1.); - *colorDartBuf++ = VEC3(1.,1.,1.); - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; + *colorDartBuf++ = m_dartsColor; m_attIndex[d] = posDBI; posDBI+=2; diff --git a/include/Algo/Render/GL2/topoRender.h b/include/Algo/Render/GL2/topoRender.h index a771f86a5b2179b5e50ea07f69f62f6bb4b43a97..08677fc96a0fdf52dc6533744125be5a87f14734 100644 --- a/include/Algo/Render/GL2/topoRender.h +++ b/include/Algo/Render/GL2/topoRender.h @@ -33,6 +33,7 @@ #include "Topology/generic/dart.h" #include "Topology/generic/attributeHandler.h" #include "Topology/generic/functor.h" +#include "Geometry/vector_gen.h" #include "Utils/vbo.h" @@ -88,6 +89,11 @@ protected: */ float m_topo_relation_width; + /** + * initial darts color (set in update) + */ + Geom::Vec3f m_dartsColor; + float *m_color_save; @@ -178,6 +184,8 @@ public: */ void setAllDartsColor(float r, float g, float b); + void setInitialDartsColor(float r, float g, float b); + /** * redraw one dart with specific width and color (not efficient use only for debug with small amount of call) * @param d the dart diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index 5d6ec2addb74dfb5871d8693c02c2772cb554914..f4a9607005c7db9757478f235e1898d42d3bfe32 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -139,9 +139,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const typename PFP::TVEC m_attIndex[d] = indexDC; indexDC+=2; *positionDartBuf++ = P; - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; *positionDartBuf++ = Q; - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; VEC3 f = P*0.5f + Q*0.5f; fv2[d] = f; f = P*0.1f + Q*0.9f; @@ -288,13 +288,13 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const typename PFP::TVE m_attIndex[d] = indexDC; indexDC+=2; *positionDartBuf++ = P; - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; *positionDartBuf++ = PP; - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; *positionDartBuf++ = Q; - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; *positionDartBuf++ = QQ; - *colorDartBuf++ = VEC3(1.,1.,1.); + *colorDartBuf++ = m_dartsColor; VEC3 f = P*0.5f + PP*0.5f; fv2[d] = f; diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp index 7baf0876a765f5d27db30086f34fa2b581cc011d..4afb33b40e7467dd9a8703d5695edf3fdc3fa858 100644 --- a/src/Algo/Render/topo3Render.cpp +++ b/src/Algo/Render/topo3Render.cpp @@ -44,7 +44,8 @@ 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_topo_dart_width(2.0f), m_topo_relation_width(3.0f),m_color_save(NULL), +m_dartsColor(1.0f,1.0f,1.0f) { m_vbo0 = new Utils::VBO(); m_vbo1 = new Utils::VBO(); @@ -130,6 +131,11 @@ void Topo3Render::setAllDartsColor(float r, float g, float b) } +void Topo3Render::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec3f(r,g,b); +} + void Topo3Render::drawDarts() { if (m_nbDarts==0) diff --git a/src/Algo/Render/topoRender.cpp b/src/Algo/Render/topoRender.cpp index 1bc3403519eb080a88289c8e2069c686130599e2..208aa487c7fd87258cd3c2cc681adf23fbc655bd 100644 --- a/src/Algo/Render/topoRender.cpp +++ b/src/Algo/Render/topoRender.cpp @@ -41,7 +41,8 @@ namespace GL2 TopoRender::TopoRender(): m_nbDarts(0),m_nbRel2(0), -m_topo_dart_width(2.0f),m_topo_relation_width(3.0f) +m_topo_dart_width(2.0f),m_topo_relation_width(3.0f), +m_dartsColor(1.0f,1.0f,1.0f) { m_vbo0 = new Utils::VBO(); m_vbo1 = new Utils::VBO(); @@ -120,6 +121,11 @@ void TopoRender::setAllDartsColor(float r, float g, float b) glUnmapBuffer(GL_ARRAY_BUFFER); } +void TopoRender::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec3f(r,g,b); +} + void TopoRender::drawDarts() { if (m_nbDarts==0)