From c3d7a637bc4bf7bcf14874364382cf3b6fa10b8b Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Wed, 25 Jan 2012 15:13:17 +0100 Subject: [PATCH] add tuto_orbits, show all orbits (with new ones !) --- Apps/Tuto/tuto_orbits.cpp | 258 ++++++++++++++++++++++++++++++++++++++ Apps/Tuto/tuto_orbits.h | 152 ++++++++++++++++++++++ Apps/Tuto/tuto_orbits.ui | 177 ++++++++++++++++++++++++++ 3 files changed, 587 insertions(+) create mode 100644 Apps/Tuto/tuto_orbits.cpp create mode 100644 Apps/Tuto/tuto_orbits.h create mode 100644 Apps/Tuto/tuto_orbits.ui diff --git a/Apps/Tuto/tuto_orbits.cpp b/Apps/Tuto/tuto_orbits.cpp new file mode 100644 index 00000000..ab1a0254 --- /dev/null +++ b/Apps/Tuto/tuto_orbits.cpp @@ -0,0 +1,258 @@ +/******************************************************************************* +* 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_orbits.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" + +#include "Algo/Import/import.h" + +PFP::MAP myMap; +PFP::TVEC3 position ; +PFP::TVEC3 middleDarts; + + + +void MyQT::text_onoff(bool x) +{ + render_text = !render_text; + updateGL(); + CGoGNerr << " text_onoff " << CGoGNflush; +} + + +void MyQT::slider_text(int x) +{ + m_strings->setScale(0.02f*x); + updateGL(); +} + + +void MyQT::orbit_list(int x) +{ + storeVerticesInfo(m_att_orbits[x]); + current_orbit = x; + updateGL(); +} + + +template +void MyQT::storeVerticesInfo(const AttributeHandler& attrib) +{ + SelectorDartNoBoundary nb(myMap); + m_render_topo->computeDartMiddlePositions(myMap,middleDarts,nb); + + m_strings->clear(); + for (Dart d=myMap.begin(); d!=myMap.end(); myMap.next(d)) + { + if (nb(d)) + { + std::stringstream ss; + ss << attrib[d]; + m_strings->addString(ss.str(),middleDarts[d]); + } + } + m_strings->sendToVBO(); +} + +void MyQT::cb_initGL() +{ + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); + + m_render_topo = new Algo::Render::GL2::Topo3Render(); + SelectorDartNoBoundary nb(myMap); + m_render_topo->updateData(myMap, position, 0.9f, 0.8f, 0.8f, nb); + + m_strings = new Utils::Strings3D(true, Geom::Vec3f(0.1f,0.0f,0.3f)); + registerShader(m_strings); + + + storeVerticesInfo(m_att_orbits[0]); + + +} + +void MyQT::cb_redraw() +{ + m_render_topo->drawTopo(); + + for (unsigned int i=0; i< m_selected.size(); ++i) + m_render_topo->overdrawDart(m_selected[i], 5, 1.0f, 0.0f, 1.0f); + + if (render_text) + m_strings->drawAll(Geom::Vec3f(0.0f, 1.0f, 1.0f)); + +} + +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()) + { + unsigned int orbs[9] ={VERTEX,EDGE,FACE,VOLUME,PFP::MAP::ORBIT_IN_PARENT(VERTEX),PFP::MAP::ORBIT_IN_PARENT(EDGE),PFP::MAP::ORBIT_IN_PARENT(FACE),PFP::MAP::ORBIT_IN_PARENT2(VERTEX),PFP::MAP::ORBIT_IN_PARENT2(EDGE)}; + m_selected.clear(); + + // easy way to traverse darts of orbit + TraversorDartsOfOrbit tra(myMap,orbs[current_orbit],d); + for (Dart e = tra.begin(); e != tra.end(); e = tra.next()) + m_selected.push_back(e); + } + updateGL(); + } +} + + +void MyQT::initMap() +{ + std::cout << "INIT MAP"<< std::endl; + + position = myMap.addAttribute(VERTEX, "position"); + Algo::Modelisation::Primitive3D prim(myMap, position); + int nb=2; + prim.hexaGrid_topo(nb,nb,nb); + prim.embedHexaGrid(1.0f,1.0f,1.0f); + + m_att_orbits[0] = myMap.addAttribute(VERTEX,"vertex"); + m_att_orbits[1] = myMap.addAttribute(EDGE,"edge"); + m_att_orbits[2] = myMap.addAttribute(FACE,"face"); + m_att_orbits[3] = myMap.addAttribute(VOLUME,"volume"); + m_att_orbits[4] = myMap.addAttribute(PFP::MAP::ORBIT_IN_PARENT(VERTEX),"vertex2"); + m_att_orbits[5] = myMap.addAttribute(PFP::MAP::ORBIT_IN_PARENT(EDGE),"edge2"); + m_att_orbits[6] = myMap.addAttribute(PFP::MAP::ORBIT_IN_PARENT(FACE),"face2"); + m_att_orbits[7] = myMap.addAttribute(PFP::MAP::ORBIT_IN_PARENT2(VERTEX),"vertex1"); + m_att_orbits[8] = myMap.addAttribute(PFP::MAP::ORBIT_IN_PARENT2(EDGE),"face1"); + + int i=0; + TraversorCell tra0(myMap, VERTEX); + for (Dart d = tra0.begin(); d != tra0.end(); d = tra0.next()) + { + m_att_orbits[0][d] = i++; + } + + i=0; + TraversorCell tra1(myMap, EDGE); + for (Dart d = tra1.begin(); d != tra1.end(); d = tra1.next()) + { + m_att_orbits[1][d] = i++; + } + + i=0; + TraversorCell tra2(myMap, FACE); + for (Dart d = tra2.begin(); d != tra2.end(); d = tra2.next()) + { + m_att_orbits[2][d] = i++; + } + + i=0; + TraversorCell tra3(myMap, VOLUME); + for (Dart d = tra3.begin(); d != tra3.end(); d = tra3.next()) + { + m_att_orbits[3][d] = i++; + } + + i=0; + TraversorCell tra02(myMap, PFP::MAP::ORBIT_IN_PARENT(VERTEX)); + for (Dart d = tra02.begin(); d != tra02.end(); d = tra02.next()) + { + m_att_orbits[4][d] = i++; + } + + i=0; + TraversorCell tra12(myMap, PFP::MAP::ORBIT_IN_PARENT(EDGE)); + for (Dart d = tra12.begin(); d != tra12.end(); d = tra12.next()) + { + m_att_orbits[5][d] = i++; + } + + i=0; + TraversorCell tra22(myMap, PFP::MAP::ORBIT_IN_PARENT(FACE)); + for (Dart d = tra22.begin(); d != tra22.end(); d = tra22.next()) + { + m_att_orbits[6][d] = i++; + } + + i=0; + TraversorCell tra01(myMap, PFP::MAP::ORBIT_IN_PARENT2(VERTEX)); + for (Dart d = tra01.begin(); d != tra01.end(); d = tra01.next()) + { + m_att_orbits[7][d] = i++; + } + + i=0; + TraversorCell tra11(myMap, PFP::MAP::ORBIT_IN_PARENT2(EDGE)); + for (Dart d = tra11.begin(); d != tra11.end(); d = tra11.next()) + { + m_att_orbits[8][d] = i++; + } + + middleDarts = myMap.addAttribute(DART, "middle"); + +} + +int main(int argc, char **argv) +{ + + // 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"); + + sqt.initMap(); + + // 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); + + // envoit info BB a l'interface + sqt.setParamObject(lWidthObj, lPosObj.data()); + + sqt.setCallBack( dock.checkBox_text, SIGNAL(toggled(bool)), SLOT(text_onoff(bool)) ); + sqt.setCallBack( dock.slider_text, SIGNAL(valueChanged(int)), SLOT(slider_text(int)) ); + sqt.setCallBack( dock.Orbits, SIGNAL( currentIndexChanged(int)), SLOT(orbit_list(int)) ); + + sqt.show(); + sqt.slider_text(50); + + // et on attend la fin. + return app.exec(); +} diff --git a/Apps/Tuto/tuto_orbits.h b/Apps/Tuto/tuto_orbits.h new file mode 100644 index 00000000..6c8a0c9b --- /dev/null +++ b/Apps/Tuto/tuto_orbits.h @@ -0,0 +1,152 @@ +/******************************************************************************* +* 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 __TUTO5_ +#define __TUTO5_ + + +#include + +//#define WITH_GMAP 1 + +#include "Topology/generic/parameters.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 "Utils/Shaders/shaderSimpleColor.h" + +#include "Algo/Render/GL2/topo3Render.h" + +#include "Topology/generic/cellmarker.h" +#include "Utils/text3d.h" + +#include "Utils/pointSprite.h" +#include "Utils/Shaders/shaderVectorPerVertex.h" +#include "Utils/cgognStream.h" + +#include "Algo/Render/GL2/explodeVolumeRender.h" + + +#include "Utils/Qt/qtSimple.h" + +#include "ui_tuto_orbits.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 + * 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) + */ +class MyQT: public Utils::QT::SimpleQT +{ + Q_OBJECT + + bool render_text; + bool render_balls; + bool render_vectors; + bool render_topo; + + Algo::Render::GL2::MapRender* m_render; + Algo::Render::GL2::Topo3Render* m_render_topo; + + Utils::VBO* m_positionVBO; + Utils::VBO* m_dataVBO; + + Utils::ShaderSimpleColor* m_shader; + Utils::ShaderVectorPerVertex* m_lines; + Utils::Strings3D* m_strings; + Utils::PointSprite* m_sprite; + + Algo::Render::GL2::ExplodeVolumeRender* m_explodeRender; + +// AttributeHandler attv2; + AttributeHandler m_att_orbits[9]; + + QTimer *m_timer; + unsigned int current_orbit; + + +public: + 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_timer(NULL), + current_orbit(0) + {} + + std::vector m_selected; + + void initMap(); + +protected: + template + void storeVerticesInfo(const AttributeHandler& attrib); + + void cb_redraw(); + void cb_initGL(); + void cb_mousePress(int button, int x, int y); + +// slots locaux +public slots: + void text_onoff(bool x); + void slider_text(int x); + void orbit_list(int x); +}; + +#endif diff --git a/Apps/Tuto/tuto_orbits.ui b/Apps/Tuto/tuto_orbits.ui new file mode 100644 index 00000000..1d5d6629 --- /dev/null +++ b/Apps/Tuto/tuto_orbits.ui @@ -0,0 +1,177 @@ + + + DockWidget + + + + 0 + 0 + 293 + 507 + + + + + 150 + 250 + + + + Interface + + + + true + + + + 0 + 0 + + + + + 150 + 200 + + + + + 2 + + + 4 + + + + + + + Qt::Horizontal + + + + + + + Display attribute + + + true + + + + + + + 50 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Select orbit: + + + + + + + Qt::NoFocus + + + + Vertex + + + + + Edge + + + + + Face + + + + + Volume + + + + + Vertex_of_parent + + + + + Edge_of_parent + + + + + Face_of_parent + + + + + Vertex_of_parent2 + + + + + Edge_of_parent_2 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + checkBox_text + toggled(bool) + slider_text + setVisible(bool) + + + 95 + 157 + + + 95 + 183 + + + + + -- GitLab