/******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by the * * Free Software Foundation; either version 2.1 of the License, or (at your * * option) any later version. * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: http://cgogn.unistra.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ #include "test_traversor2.h" #include "Algo/Geometry/boundingbox.h" #include "Algo/Tiling/Surface/square.h" #include "Algo/Geometry/centroid.h" #include "Algo/Import/import.h" #include "Algo/Export/export.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.listTravers, SIGNAL(currentRowChanged(int)), SLOT(traversors(int)) ); sqt.setCallBack( sqt.dock.withBoundary, SIGNAL(clicked()), SLOT(updateMap()) ); sqt.setCallBack( sqt.dock.svg, SIGNAL(clicked()), SLOT(svg()) ); sqt.setCallBack( sqt.dock.widthSlider, SIGNAL(valueChanged(int)), SLOT(width(int)) ); int n = 3; if (argc == 2) n = atoi(argv[1]); // example code itself sqt.createMap(n); sqt.width(5); // 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 fonct(const Cell& v) { std::cout << v.dart << std::endl; } void fonct2(Dart d) { std::cout << d << std::endl; } void MyQT::traversors(int x) { // update all color to grey for (Dart d = myMap.begin(); d != myMap.end(); myMap.next(d)) { m_render_topo->addColoredDart(d,0.5f,0.5f,0.5f); } switch(x) { case 0: { Traversor2VVaE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 1: { Traversor2VVaF trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 2: { Traversor2EEaV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 3: { Traversor2EEaF trav(myMap,m_selected); float c=0.0f; for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,c); } break; case 4: { Traversor2FFaV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 5: { Traversor2FFaE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 6: { Traversor2FV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 7: { Traversor2FE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 8: { Traversor2EV trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 9: { Traversor2EF trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 10: { Traversor2VE trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; case 11: { Traversor2VF trav(myMap,m_selected); for(Dart b=trav.begin(); b!= trav.end(); b=trav.next()) m_render_topo->addColoredDart(b,0.0f,1.0f,0.0f); } break; default: break; } updateGL(); } void MyQT::createMap(int n) { position = myMap.addAttribute("position"); Algo::Surface::Tilings::Square::Grid grid(myMap, n, n, true); grid.embedIntoGrid(position, 1.,1.,0.); // bounding box of scene Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position) ; setParamObject(bb.maxSize(), bb.center().data()) ; m_shift = bb.maxSize()/200.0f; // first show for be sure that GL context is binded show(); dm.markAll(); m_render_topo->setDartWidth(4.0f); m_render_topo->setInitialDartsColor(0.5f,0.5f,0.5f); m_render_topo->setInitialBoundaryDartsColor(0.3f,0.3f,0.3f); std::cout << "markAll OK"<< std::endl; #ifdef USE_GMAP m_render_topo->updateDataGMap(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); #else m_render_topo->updateData(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); #endif std::cout << "markAll OK"<< std::endl; } void MyQT::updateMap() { m_render_topo->setInitialBoundaryDartsColor(0.0f,0.0f,0.0f); #ifdef USE_GMAP m_render_topo->updateData(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); #else m_render_topo->updateDataGMap(myMap, position, 0.9f, 0.9f, dock.withBoundary->isChecked()); #endif updateGL(); } // initialization GL callback void MyQT::cb_initGL() { glClearColor(1.0f,1.0f,1.0f,1.0f); m_render_topo = new Algo::Render::GL2::TopoRender(0.01f) ; } // redraw GL callback (clear and swap already done) void MyQT::cb_redraw() { glDepthFunc(GL_LESS); m_render_topo->drawTopo(); glDepthFunc(GL_LEQUAL); m_render_topo->drawColoredDarts(myMap); if (m_selected != NIL) m_render_topo->overdrawDart(myMap, m_selected, 11, 1.0f, 0.0f, 0.0f); if (m_selected2 != NIL) m_render_topo->overdrawDart(myMap, 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 (d != Dart::nil()) std::cout << "DART=" << d.index << std::endl; } if (button == Qt::RightButton) { if (d != Dart::nil()) m_selected2 = d; } updateGL(); } } void MyQT::cb_keyPress(int keycode) { switch(keycode) { case Qt::Key_Up: if (m_selected!=NIL) position[m_selected][1] += m_shift; updateMap(); updateGL(); break; case Qt::Key_Down: if (m_selected!=NIL) position[m_selected][1] -= m_shift; updateMap(); updateGL(); break; case Qt::Key_Left: if (m_selected!=NIL) position[m_selected][0] -= m_shift; updateMap(); updateGL(); break; case Qt::Key_Right: if (m_selected!=NIL) position[m_selected][0] += m_shift; updateMap(); updateGL(); break; default: break; } updateGL(); } void MyQT::svg() { std::string filename = selectFileSave("snapshot file", ".", "(*.svg)"); m_render_topo->svgout2D(filename, modelViewMatrix(),projectionMatrix()); } void MyQT::cb_Open() { std::string filters("all (*.*);; trian (*.trian);; off (*.off);; ply (*.ply);; map (*.map)") ; std::string filename = selectFile("Open Mesh", "", filters) ; if (!filename.empty()) importMesh(filename); updateGL(); } void MyQT::cb_Save() { std::string filename = selectFileSave("Export Off file ",".","(*.off)"); Algo::Surface::Export::exportOFF(myMap,position,filename.c_str()); //std::cout << "could not save file : " << filename << std::endl; } void MyQT::importMesh(std::string& filename) { myMap.clear(true) ; size_t pos = filename.rfind("."); // position of "." in filename std::string extension = filename.substr(pos); if (extension == std::string(".map")) { myMap.loadMapBin(filename); position = myMap.getAttribute("position") ; } else { std::vector attrNames ; if(!Algo::Surface::Import::importMesh(myMap, filename.c_str(), attrNames)) { CGoGNerr << "could not import " << filename << CGoGNendl ; return; } position = myMap.getAttribute(attrNames[0]) ; } m_selected = NIL; m_selected2 = NIL; Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position) ; setParamObject(bb.maxSize(), bb.center().data()) ; m_shift = bb.maxSize()/200.0f; updateMap(); updateGLMatrices() ; } void MyQT::width(int w) { m_render_topo->setDartWidth(w); m_render_topo->setRelationWidth(w); updateGL(); }