diff --git a/Apps/CMakeLists.txt b/Apps/CMakeLists.txt index dc7ba0481cd2d6527820c0d17c99f61efeab5f13..5854d86af60577cf69af8aba2d360a2658c14dd5 100644 --- a/Apps/CMakeLists.txt +++ b/Apps/CMakeLists.txt @@ -36,3 +36,4 @@ ENDIF (WITH_QT) add_subdirectory(Examples/Tests) add_subdirectory(Tuto/Traversals) +add_subdirectory(Tuto/Attributes) diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index 2f942f8116ec25bc9380b7d4de2794481c2d1c24..24448639e4776fa7fd598bad0df7154c4f8994e5 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -23,6 +23,7 @@ *******************************************************************************/ #include "viewer.h" +#include "Utils/chrono.h" Viewer::Viewer() : m_renderStyle(FLAT), @@ -196,6 +197,141 @@ void Viewer::cb_keyPress(int keycode) case 'c' : myMap.check(); break; + + + case 'a': + { + Utils::Chrono ch; + ch.start(); + VertexAttribute pos2 = myMap.getAttribute("pos2") ; + if(!pos2.isValid()) + pos2 = myMap.addAttribute("pos2") ; + + for (int i=0; i< 10; ++i) + { + TraversorV trav(myMap); + for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next()) + { + pos2[d] = VEC3(0,0,0); + int nb=0; + Traversor2VVaF trf(myMap,d); + for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next()) + { + pos2[d] += position[e]; + nb++; + } + pos2[d]/=nb; + } + myMap.swapAttributes(position,pos2); + } + std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl; + Algo::Surface::Geometry::computeNormalVertices(myMap, position, normal) ; + m_positionVBO->updateData(position) ; + m_normalVBO->updateData(normal) ; + updateGL(); + } + break; + + case 'b': + { + Utils::Chrono ch; + ch.start(); + + VertexAttribute pos2 = myMap.getAttribute("pos2") ; + if(!pos2.isValid()) + pos2 = myMap.addAttribute("pos2") ; + + for (int i=0; i< 10; ++i) + { + foreach_cell(myMap, [&] (Vertex d) + { + pos2[d] = VEC3(0,0,0); + int nb=0; + foreach_adjacent2(myMap,d,[&](Vertex e) + { + pos2[d] += position[e]; + nb++; + }); + pos2[d]/=nb; + }); + myMap.swapAttributes(position,pos2); + } + std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl; + Algo::Surface::Geometry::computeNormalVertices(myMap, position, normal) ; + m_positionVBO->updateData(position) ; + m_normalVBO->updateData(normal) ; + updateGL(); + } + break; + + + case 'e': + { + Utils::Chrono ch; + ch.start(); + VertexAttribute pos2 = myMap.getAttribute("pos2") ; + if(!pos2.isValid()) + pos2 = myMap.addAttribute("pos2") ; + + for (int i=0; i< 10; ++i) + { + TraversorV trav(myMap); + for (Dart d=trav.begin(), d_end = trav.end(); d!=d_end ; d = trav.next()) + { + pos2[d] = VEC3(0,0,0); + int nb=0; + Traversor2VE trf(myMap,d); + for (Dart e = trf.begin(),e_end =trf.end() ; e != e_end; e = trf.next()) + { + pos2[d] += position[myMap.phi1(e)]; + nb++; + } + pos2[d]/=nb; + } + myMap.swapAttributes(position,pos2); + } + std::cout << "Traversor "<< ch.elapsed()<< " ms "<< std::endl; + Algo::Surface::Geometry::computeNormalVertices(myMap, position, normal) ; + m_positionVBO->updateData(position) ; + m_normalVBO->updateData(normal) ; + updateGL(); + } + break; + + case 'f': + { + Utils::Chrono ch; + ch.start(); + + VertexAttribute pos2 = myMap.getAttribute("pos2") ; + if(!pos2.isValid()) + pos2 = myMap.addAttribute("pos2") ; + + for (int i=0; i< 10; ++i) + { + foreach_cell(myMap, [&] (Vertex d) + { + pos2[d] = VEC3(0,0,0); + int nb=0; + foreach_incident2(myMap,d,[&](Edge e) + { + pos2[d] += position[myMap.phi1(e)]; + nb++; + }); + pos2[d]/=nb; + }); + myMap.swapAttributes(position,pos2); + } + std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl; + Algo::Surface::Geometry::computeNormalVertices(myMap, position, normal) ; + m_positionVBO->updateData(position) ; + m_normalVBO->updateData(normal) ; + updateGL(); + } + break; + + + default: break; } diff --git a/Apps/Tuto/Attributes/CMakeLists.txt b/Apps/Tuto/Attributes/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..65bf36b04f88a690d5d2f71a589c298893d34b83 --- /dev/null +++ b/Apps/Tuto/Attributes/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 2.8) + +project(Tuto_Traversals) + + +SET (CMAKE_BUILD_TYPE Debug) +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTOPOWARNING") + + + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${CGoGN_ROOT_DIR}/include + ${CGoGN_EXT_INCLUDES} +) + +# define libs path +IF(WIN32) + link_directories(${CGoGN_ROOT_DIR}/lib/$(ConfigurationName) + ${Boost_LIBRARY_DIRS}) +ELSE(WIN32) + link_directories(${CGoGN_ROOT_DIR}/lib/Release ${CGoGN_ROOT_DIR}/lib/Debug) +ENDIF(WIN32) + + +#define exec to compile + +add_executable( simple_attribs simple_attribs.cpp) +target_link_libraries( simple_attribs ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) + +add_executable( multi_attribs multi_attribs.cpp) +target_link_libraries( multi_attribs ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) diff --git a/Apps/Tuto/Attributes/multi_attribs.cpp b/Apps/Tuto/Attributes/multi_attribs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f562139db884af0d70d2570792de8f3a04f7d8e1 --- /dev/null +++ b/Apps/Tuto/Attributes/multi_attribs.cpp @@ -0,0 +1,137 @@ +/******************************************************************************* +* 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 "Topology/generic/parameters.h" +#include "Topology/map/embeddedMap2.h" +#include "Algo/Tiling/Surface/square.h" +#include "Topology/generic/multiAttribs.h" +#include "Algo/Geometry/centroid.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; +}; + +// some typedef shortcuts +typedef PFP::MAP MAP ; // map type +typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation +typedef PFP::VEC3 VEC3 ; // type of R³ vector +typedef PFP::VEC4 VEC4; + + + +/** + * Example of function that work with any kin of Vertex Attribute + */ +template +typename ATT::DATA_TYPE smooth(MAP& map, Vertex v, const ATT& attributs) +{ + typename ATT::DATA_TYPE res(0); + int count=0; + + foreach_adjacent2(map,v,[&](Vertex x) // for all its neighbours (by edges) + { + res += attributs[x]; + count ++; + }); + res /= typename PFP::REAL(count); + return res; +} + +/** + * Example of function that work with any kind of Vertex Attribute + */ +template +void applySmooth(MAP& map, const ATT& att_in, ATT& att_out) +{ + foreach_cell(map,[&](Vertex v) // for all edge e of map do + { + att_out[v] = smooth(map,v,att_in); + }); +} + + + + + +int main() +{ + // declare a map to handle the mesh + MAP myMap; + + // add position attribute on vertices and get handler on it + VertexAttribute position = myMap.addAttribute("position"); + + // create a topo grid of 2x2 squares + Algo::Surface::Tilings::Square::Grid grid(myMap, 2, 2, true); + // and embed it using position attribute + grid.embedIntoGrid(position, 2.,2.,0.); + + // second vertex attribute (for out) + VertexAttribute pos2 = myMap.addAttribute("pos2"); + + // first color attribute on vertices + VertexAttribute vc = myMap.addAttribute("vertexColor"); + // second color attribute on vertices + VertexAttribute vc2 = myMap.addAttribute("vertexColor2"); + + // add some random on position and compute a color + for (unsigned int i= position.begin(); i != position.end(); position.next(i)) + { + position[i] += VEC3(0.02f*i,0.01f*i,0.03f*i); + vc[i] = VEC4(position[i][0]*0.3f,position[i][1]*0.3f,position[i][2]*0.3f,1.0f); + } + + + std::cout << "========== initial values =========="<(myMap,[&](Vertex v) // for all edge e of map do + { + std::cout << position[v]<< " / "<< vc[v]<< std::endl; + }); + + // define two multi attributes (one for in, one for out) + Vertex2Attributes pv_in(position, vc); + Vertex2Attributes pv_out(pos2, vc2); + + // and call algo once just like with simple attributes + applySmooth(myMap, pv_in, pv_out); + + std::cout << "========== after smooth on position and color =========="<(myMap,[&](Vertex v) // for all edge e of map do + { + std::cout << pos2[v]<< " / "<< vc2[v]<< std::endl; + }); + + + return 0; +} diff --git a/Apps/Tuto/Attributes/simple_attribs.cpp b/Apps/Tuto/Attributes/simple_attribs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01126247417e7846207b74b41db9c8a2314898cc --- /dev/null +++ b/Apps/Tuto/Attributes/simple_attribs.cpp @@ -0,0 +1,201 @@ +/******************************************************************************* +* 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 "Topology/generic/parameters.h" +#include "Topology/map/embeddedMap2.h" +#include "Algo/Tiling/Surface/square.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; +}; + +// some typedef shortcuts +typedef PFP::MAP MAP ; // map type +typedef PFP::MAP::IMPL MAP_IMPL ; // map implementation +typedef PFP::VEC3 VEC3 ; // type of R³ vector + +/** + * @brief get attribute + * @param map + */ +void byNames(MAP& map, const std::string& name) +{ + VertexAttribute testPos = map.getAttribute(name); + if (testPos.isValid()) + std::cout << "Attribute "<< name <<" valid"<< std::endl; + else + std::cout << "Attribute "<< name <<"invalid"<< std::endl; +} + +/** + * @brief computeLengthEdges + * @param map the map + * @param pos attribute handler of position of vertices + * @param len attribute handler of length of edges + */ +void computeLengthEdges(MAP& map,const VertexAttribute& pos, EdgeAttribute len) +{ + // warning c++11 lambda syntax + foreach_cell(map,[&](Edge e) // for all edge e of map do + { + VEC3 P1 = pos[e.dart]; // access with dart because of access to VertexAttribute with an edge + VEC3 P2 = pos[map.phi1(e)]; // phi1 return a dart so no problem (and e can auto-cast in dart) + VEC3 V = P2 - P1; + len[e] = V.norm(); + }); +} + + +void computeNewPositions(MAP& map, VertexAttribute& pos) +{ + // here we need new and old positions simultaneously so create temporary position + + VertexAutoAttribute pos2(map); + + foreach_cell(map,[&](Vertex v) // for all vertices + { + int nb=0; + pos2[v] = VEC3(0,0,0);// init with 0,0,0, + foreach_adjacent2(map,v,[&](Vertex x) // for all its neighbours (by edges) + { + pos2[v] += pos[x]; + nb++; + }); + pos2[v] /= nb; + }); + + // swap attribute position with temporary (constant complexity !) + map.swapAttributes(pos,pos2); +} + +/** +* @brief dump any attribute +* @param attr attribute +*/ +template +void dumpAttribute(const ATTRIB& attr) +{ + std::cout << "Attribute " < grid(myMap, 2, 2, true); + // and embed it using position attribute + grid.embedIntoGrid(positionAtt, 1.,1.,0.); + + + // add an attribute of type float on orbit EDGE + EdgeAttribute lengthAtt = myMap.addAttribute("length"); + if (!lengthAtt.isValid()) + std::cerr << "impossible to create the attribute"<< std::endl; + + computeLengthEdges(myMap,positionAtt,lengthAtt); + + // add an attribute of type std::string on orbit FACE + FaceAttribute nameAtt = myMap.addAttribute("name"); + if (!nameAtt.isValid()) + std::cerr << "impossible to create the attribute"<< std::endl; + + // for complex type use following template (function nameOfType not applicable) + EdgeAttribute< NoTypeNameAttribute< std::vector >, MAP_IMPL> vectAtt = myMap.addAttribute< NoTypeNameAttribute< std::vector >, EDGE>("vector_of_int"); + if (!vectAtt.isValid()) + std::cerr << "impossible to create the attribute"<< std::endl; + + Dart d = myMap.begin(); + // define a vertex from a dart + Vertex v(d); + // define a face from a dart + Face f(d); + + // [] operator can take a dart, a cell (only same off attribute), or an unsigned inf + // access to any attributes with darts + std::cout << positionAtt[d]<< std::endl; + nameAtt[d] = "Hello"; + lengthAtt[myMap.phi1(d)] = 54.0f; + + std::vector vi = {3,5,7,9,11}; + vectAtt[d]= vi; + vectAtt[d].push_back(11); + + // access to VertexAttribute with a Vertex + std::cout << positionAtt[v]<< std::endl; + + // access to FaceAttribute with a Face + std::cout << nameAtt[f]<< std::endl; + +// following line does not compile because of wrong cell type +// std::cout << positionAtt[f]<< std::endl; +// possible to bypass using dart access + std::cout << positionAtt[f.dart]<< std::endl; + + // possible to have any number of attribute a same ORBIT + VertexAttribute position2Att = myMap.addAttribute("other_position"); + + // copy of attribute of same type (linear complexity) + myMap.copyAttribute(position2Att,positionAtt); + + positionAtt[v] += VEC3(0,0,1); + + computeNewPositions(myMap,positionAtt); + + dumpAttribute(positionAtt); + + byNames(myMap,"position"); + + myMap.removeAttribute(positionAtt); + + byNames(myMap,"position"); + + + return 0; +} diff --git a/Apps/Tuto/Traversals/CMakeLists.txt b/Apps/Tuto/Traversals/CMakeLists.txt index 1c4166dcd161eddd3ca33eb44d0da40af18faab3..be6ce20f0d4f9bd2b7b5ad0a0e13db5b82915d1e 100644 --- a/Apps/Tuto/Traversals/CMakeLists.txt +++ b/Apps/Tuto/Traversals/CMakeLists.txt @@ -42,7 +42,13 @@ target_link_libraries( traverse_cells ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) add_executable( traverse_neighbours traverse_neighbours.cpp) target_link_libraries( traverse_neighbours ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) -QT4_WRAP_UI( show_traversors_ui show_traversors.ui ) -QT4_WRAP_CPP(show_traversors_moc show_traversors.h) -add_executable( show_traversors show_traversors.cpp ${show_traversors_ui} ${show_traversors_moc}) -target_link_libraries( show_traversors ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) +QT4_WRAP_UI( show_traversors_ui2 show_traversors2.ui ) +QT4_WRAP_CPP(show_traversors_moc2 show_traversors2.h) +add_executable( show_traversors2 show_traversors2.cpp ${show_traversors_ui2} ${show_traversors_moc2}) +target_link_libraries( show_traversors2 ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) + +QT4_WRAP_UI( show_traversors_ui3 show_traversors3.ui ) +QT4_WRAP_CPP(show_traversors_moc3 show_traversors3.h) +add_executable( show_traversors3 show_traversors3.cpp ${show_traversors_ui3} ${show_traversors_moc3}) +target_link_libraries( show_traversors3 ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS} ) + diff --git a/Apps/Tuto/Traversals/show_traversors2.cpp b/Apps/Tuto/Traversals/show_traversors2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2151982f908d995cc70c97c0304bd4613f12142 --- /dev/null +++ b/Apps/Tuto/Traversals/show_traversors2.cpp @@ -0,0 +1,304 @@ +/******************************************************************************* +* 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 "show_traversors2.h" +#include + +#include "Algo/Tiling/Surface/square.h" +#include "Algo/Modelisation/polyhedron.h" +#include "Algo/Modelisation/subdivision.h" +#include "Algo/Import/import.h" + +#include "Algo/Render/GL2/topo3Render.h" +#include "Algo/Render/SVG/mapSVGRender.h" + +#include "Topology/generic/traversor/traversorFactory.h" + +#include "Algo/Render/GL2/drawerCells.h" + + +void MyQT::cb_checkTopo(bool b) +{ + m_showTopo = b; + updateGL(); +} + + + +void MyQT::cb_combo4(int x) +{ + m_first2 = x; + if (m_first2!=m_second2) + traverse2(); + else + CGoGNerr <<"undefined traversor" << CGoGNendl; +} + +void MyQT::cb_combo5(int x) +{ + m_ajd_or_inci2 = x; + if (m_first2!=m_second2) + traverse2(); + else + CGoGNerr <<"undefined traversor" << CGoGNendl; +} + +void MyQT::cb_combo6(int x) +{ + m_second2 = x; + if (m_first2!=m_second2) + traverse2(); + else + CGoGNerr <<"undefined traversor" << CGoGNendl; +} + +void MyQT::cb_explode(int x) +{ + m_expl = float (x) /100.0f; + if (m_last==2) + traverse2(); +} + +void MyQT::cb_initGL() +{ + // choose to use GL version 2 + Utils::GLSLShader::setCurrentOGLVersion(2); + + m_render_topo = new Algo::Render::GL2::TopoRenderMap(); + m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); + m_dm_topo = new DartMarker(myMap); +} + +void MyQT::cb_redraw() +{ + if (m_showTopo) + { + m_render_topo->drawTopo(); + + if (m_selected != NIL) + m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f); + + for (std::vector::iterator it=m_affDarts.begin(); it!=m_affDarts.end(); ++it) + { + m_render_topo->overdrawDart(*it, 6, 1.0f, 1.0f, 1.0f); + } + } + + m_drawer.callList(); +} + +void MyQT::cb_mousePress(int /*button*/, int x, int y) +{ + if (Shift()) + { + Dart d = m_render_topo->picking(myMap, x, y); + if (d != Dart::nil()) + { + CGoGNout << "Dart " << d << " clicked" << CGoGNendl; + m_selected = d; + } + updateGL(); + } +} + +void MyQT::cb_Save() +{ + std::string filename = selectFileSave("Export SVG file ",".","(*.svg)"); + + std::string filename1 = filename + std::string("Drawer") + std::string(".svg"); + std::string filename2 = filename + std::string("Topo") + std::string(".svg"); + + Utils::SVG::SVGOut svg1(filename1, modelViewMatrix(), projectionMatrix()); + m_drawer.toSVG(svg1); + svg1.write(); + + Utils::SVG::SVGOut svg2(filename2, modelViewMatrix(), projectionMatrix()); + m_render_topo->toSVG(svg2); + svg2.write(); +} + +template +void MyQT::colorizeCell(Dart d, float r,float g, float b) +{ + TraversorDartsOfOrbitdoo (myMap, d); + for (Dart e = doo.begin(); e != doo.end(); e = doo.next()) + m_render_topo->setDartColor(e, r, g, b); +} + +void MyQT::traverse2() +{ + if (m_selected == NIL) + return; + m_last=2; + // int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2; + + m_drawer.newList(GL_COMPILE); + m_drawer.lineWidth(7.0f); + m_drawer.pointSize(9.0f); + m_drawer.color3f(0.0f,0.7f,0.0f); + + m_affDarts.clear(); + + if (m_ajd_or_inci2 == 0) // incident + { + Algo::Render::drawerCell(VERTEX+m_second2, m_drawer, myMap, m_selected, position, m_expl); + m_drawer.color3f(1.0f,0.0f,0.0f); + Traversor* tra = TraversorFactory::createIncident(myMap, m_selected, 2, VERTEX+m_second2, VERTEX+m_first2); + for (Dart d=tra->begin(); d != tra->end(); d= tra->next()) + m_affDarts.push_back(d); + Algo::Render::drawerCells(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl); + } + else // adjacent + { + Algo::Render::drawerCell(VERTEX+m_first2, m_drawer, myMap, m_selected, position, m_expl); + m_drawer.color3f(1.0f,0.0f,0.0f); + Traversor* tra = TraversorFactory::createAdjacent(myMap, m_selected, 2, VERTEX+m_first2, VERTEX+m_second2); + for (Dart d = tra->begin(); d != tra->end(); d = tra->next()) + m_affDarts.push_back(d); + Algo::Render::drawerCells(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl); + } + + m_drawer.endList(); + + // SelectorMarked sm(*m_dm_topo); + m_render_topo->updateData(myMap, position, 0.95f, 0.9f, 0.8f); + + updateGL(); +} + +void MyQT::dynamicMarkOrbit(unsigned int orb) +{ + switch(orb) + { + case VERTEX: + m_dm_topo->markOrbit(m_selected); + break; + case EDGE: + m_dm_topo->markOrbit(m_selected); + break; + case FACE: + m_dm_topo->markOrbit(m_selected); + break; + case VOLUME: + m_dm_topo->markOrbit(m_selected); + break; + default: + break; + } +} + +void MyQT::init(char *fname) +{ + if(fname == NULL) + { + position = myMap.addAttribute( "position"); + + Algo::Surface::Tilings::Square::Grid grid(myMap, 5, 5, true); + grid.embedIntoGrid(position, 1.,1.,0.); + dglobal = NIL; + } + else + { + std::string filename(fname); + size_t pos = filename.rfind("."); // position of "." in filename + std::string extension = filename.substr(pos); + std::vector attrNames ; + + if(extension == std::string(".map")) + { + myMap.clear(true); + + if(!myMap.loadMapBin(filename)) + { + std::cout << "could not load file" << std::endl; + } + + //myMap.dumpAttributesAndMarkers(); + + position = myMap.getAttribute("position"); + } + else if(!Algo::Surface::Import::importMesh(myMap, filename, attrNames)) + { + std::cerr << "could not import " << filename << std::endl ; + exit(1); + } + position = myMap.getAttribute(attrNames[0]) ; + + } + + 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 + setParamObject(lWidthObj, lPosObj.data()); + m_selected = NIL; +} + +int main(int argc, char **argv) +{ + // un peu d'interface + QApplication app(argc, argv); + MyQT sqt; + + + if(argc == 1) + { + sqt.init(NULL); + } + else + { + sqt.init(argv[1]); + } + + + // interface de tuto5.ui + Utils::QT::uiDockInterface dock; + sqt.setDock(&dock); + + // message d'aide + sqt.setHelpMsg("shit click to select a dart\nand select a traversor\nif keyboard focus problem\nundock"); + + // 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.combo4, SIGNAL( activated(int)), SLOT(cb_combo4(int)) ); + sqt.setCallBack( dock.combo5, SIGNAL( activated(int)), SLOT(cb_combo5(int)) ); + sqt.setCallBack( dock.combo6, SIGNAL( activated(int)), SLOT(cb_combo6(int)) ); + sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) ); + + sqt.setCallBack( dock.checkTopo, SIGNAL( clicked(bool)), SLOT(cb_checkTopo(bool)) ); + +// sqt.m_selected = NIL; + + sqt.show(); + + // et on attend la fin. + return app.exec(); +} diff --git a/Apps/Tuto/Traversals/show_traversors2.h b/Apps/Tuto/Traversals/show_traversors2.h new file mode 100644 index 0000000000000000000000000000000000000000..9696d689c51dd97d9eae58267a6a0d8d6641edd3 --- /dev/null +++ b/Apps/Tuto/Traversals/show_traversors2.h @@ -0,0 +1,135 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ +#ifndef __SHOW_TRAVERSORS_ +#define __SHOW_TRAVERSORS_ + +#include + +#include "Topology/generic/parameters.h" +#include "Topology/map/embeddedMap3.h" + +#include "Geometry/vector_gen.h" +#include "Algo/Geometry/boundingbox.h" +#include "Algo/Render/GL2/mapRender.h" +#include "Algo/Render/GL2/topoRender.h" +#include "Topology/generic/cellmarker.h" + +#include "Utils/cgognStream.h" +#include "Utils/drawer.h" + +#include "Utils/Qt/qtSimple.h" + +#include "ui_show_traversors2.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 + typedef EmbeddedMap2 MAP; +}; + +typedef PFP::MAP MAP ; +typedef PFP::MAP::IMPL MAP_IMPL ; +typedef PFP::VEC3 VEC3 ; + +/** + * 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 + + Algo::Render::GL2::TopoRenderMap* m_render_topo; + bool m_showTopo; + + + unsigned int m_first2; + unsigned int m_ajd_or_inci2; + unsigned int m_second2; + float m_expl; + unsigned int m_last; +public: + MyQT(): + m_render_topo(NULL), + m_showTopo(true), + m_first2(0), + m_ajd_or_inci2(0), + m_second2(1), + m_expl(0.8f), + m_last(2), + m_selected(NIL), + m_dm_topo(NULL) + {} + + Dart m_selected; + std::vector m_affDarts; + + Utils::Drawer m_drawer; + + DartMarker* m_dm_topo; + + MAP myMap; + + VertexAttribute position ; + + Dart dglobal; + + void init(char *fname); + +protected: + void storeVerticesInfo(); + + void cb_redraw(); + + void cb_initGL(); + + void cb_Save(); + + void cb_mousePress(int button, int x, int y); + + template + void colorizeCell(Dart d, float r,float g, float b); + + void traverse2(); + void dynamicMarkOrbit(unsigned int orb); + +// slots locaux +public slots: + void cb_combo4(int x); + void cb_combo5(int x); + void cb_combo6(int x); + + void cb_checkTopo(bool b); + void cb_explode(int x); +}; + +#endif diff --git a/Apps/Tuto/Traversals/show_traversors2.ui b/Apps/Tuto/Traversals/show_traversors2.ui new file mode 100644 index 0000000000000000000000000000000000000000..249fd35558603b2515c9e8d4c4d560364850c379 --- /dev/null +++ b/Apps/Tuto/Traversals/show_traversors2.ui @@ -0,0 +1,181 @@ + + + DockWidget + + + + 0 + 0 + 150 + 417 + + + + + 150 + 250 + + + + Interface + + + + true + + + + 0 + 0 + + + + + 150 + 200 + + + + + 2 + + + 4 + + + + + + + Traversor2 + + + + + + + Qt::NoFocus + + + + Vertex + + + + + Edge + + + + + Face + + + + + + + + Qt::NoFocus + + + + incident to + + + + + adjacent by + + + + + + + + Qt::NoFocus + + + 1 + + + + Vertex + + + + + Edge + + + + + Face + + + + + + + + Qt::Horizontal + + + + + + + 1 + + + 100 + + + 80 + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + Qt::NoFocus + + + show topo + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + diff --git a/Apps/Tuto/Traversals/show_traversors.cpp b/Apps/Tuto/Traversals/show_traversors3.cpp similarity index 64% rename from Apps/Tuto/Traversals/show_traversors.cpp rename to Apps/Tuto/Traversals/show_traversors3.cpp index 8f87f26b67f5d7d824b855d06ecb0119cf320a54..89d9917ba04bad4ef4d79a8b294f05229a6a679b 100644 --- a/Apps/Tuto/Traversals/show_traversors.cpp +++ b/Apps/Tuto/Traversals/show_traversors3.cpp @@ -22,13 +22,12 @@ * * *******************************************************************************/ -#include "show_traversors.h" +#include "show_traversors3.h" #include #include "Algo/Tiling/Volume/cubic.h" #include "Algo/Modelisation/polyhedron.h" #include "Algo/Modelisation/subdivision.h" - #include "Algo/Import/import.h" #include "Algo/Render/GL2/topo3Render.h" @@ -323,279 +322,6 @@ void MyQT::traverse3() updateGL(); } -/* -void MyQT::dyn_trav3XXaY(unsigned int first, unsigned int second) -{ - unsigned int val = first *16 + second; - switch(val) - { - case 0x00: - break; - case 0x10: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x20: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x30: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x01: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x21: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x31: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - - case 0x02: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x12: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x32: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x03: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x13: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x23: - { - Traversor3XXaY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - } -} - -void MyQT::dyn_trav3XY(unsigned int first, unsigned int second) -{ - unsigned int val = second *16 + first; - switch(val) - { - case 0x00: - break; - case 0x10: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x20: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x30: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x01: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x21: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x31: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - - case 0x02: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x12: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x32: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - case 0x03: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x13: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - case 0x23: - { - Traversor3XY tra(myMap,m_selected); - for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) - { - m_affDarts.push_back(d); - m_dm_topo->markOrbit(d); - } - } - break; - - } -} -*/ - - int main(int argc, char **argv) diff --git a/Apps/Tuto/Traversals/show_traversors.h b/Apps/Tuto/Traversals/show_traversors3.h similarity index 95% rename from Apps/Tuto/Traversals/show_traversors.h rename to Apps/Tuto/Traversals/show_traversors3.h index 03c47fa1dad7094b00e3ad547b1aee5c3299e465..9cfec06b73bd24bb8ae900759f7e3906ade424e7 100644 --- a/Apps/Tuto/Traversals/show_traversors.h +++ b/Apps/Tuto/Traversals/show_traversors3.h @@ -32,21 +32,16 @@ #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 "Utils/drawer.h" #include "Utils/Qt/qtSimple.h" -#include "ui_show_traversors.h" +#include "ui_show_traversors3.h" // inclure qtui.h juste après le ui_xxx.h #include "Utils/Qt/qtui.h" diff --git a/Apps/Tuto/Traversals/show_traversors.ui b/Apps/Tuto/Traversals/show_traversors3.ui similarity index 100% rename from Apps/Tuto/Traversals/show_traversors.ui rename to Apps/Tuto/Traversals/show_traversors3.ui diff --git a/include/Topology/generic/cells.h b/include/Topology/generic/cells.h index 352cc2db929ec650910ba0afe8a7bb7fc5f6ffe3..c0ebe5d9edb2a4e299becb0412952542c3446079 100644 --- a/include/Topology/generic/cells.h +++ b/include/Topology/generic/cells.h @@ -46,7 +46,7 @@ public: /// empty construtor Cell(): dart() {} - /// construtor from Dart + /// constructor from Dart inline Cell(Dart d): dart(d) {} /// copy constructor diff --git a/include/Topology/generic/dart.h b/include/Topology/generic/dart.h index e5f98f270d970d16199471f3a26d35b397ecbc92..18df036a9a377125e53ab31e3ddcb32893880d2f 100644 --- a/include/Topology/generic/dart.h +++ b/include/Topology/generic/dart.h @@ -26,6 +26,7 @@ #define DART_H_ #include +#include namespace CGoGN { @@ -40,6 +41,7 @@ const unsigned int NB_THREAD = 16; const unsigned int NB_ORBITS = 11; const unsigned int DART = 0; + const unsigned int VERTEX = 1; const unsigned int EDGE = 2; const unsigned int FACE = 3; @@ -53,8 +55,6 @@ const unsigned int VERTEX2 = 8; const unsigned int EDGE2 = 9; const unsigned int FACE2 = 10; - - struct Dart { unsigned int index; @@ -114,6 +114,50 @@ struct Dart const Dart NIL = Dart::nil(); +inline std::string orbitName(unsigned int orbit) +{ + switch(orbit) + { + case DART: + return "DART"; + break; + case VERTEX: + return "VERTEX"; + break; + case EDGE: + return "EDGE"; + break; + case FACE: + return "FACE"; + break; + case VOLUME: + return "VOLUME"; + break; + case CC: + return "CC"; + break; + case VERTEX1: + return "VERTEX1"; + break; + case EDGE1: + return "EDGE1"; + break; + case VERTEX2: + return "VERTEX2"; + break; + case EDGE2: + return "EDGE2"; + break; + case FACE2: + return "FACE2"; + default: + break; + + } + return "UNKNOWN"; +} + + } #endif /* DART_H_ */