diff --git a/Apps/SandBox/CMakeLists.txt b/Apps/SandBox/CMakeLists.txt index 9bd6162c9dc3765ebfc1ebe155f433a41b2c1b5c..84c656f5140fcd37cc16c117eb2b2d492e27afa9 100644 --- a/Apps/SandBox/CMakeLists.txt +++ b/Apps/SandBox/CMakeLists.txt @@ -24,6 +24,9 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_executable(multi_att multi_att.cpp) target_link_libraries(multi_att ${CGoGN_LIBS} ${CGoGN_EXT_LIBS}) +add_executable(trav3_test trav3_test.cpp) +target_link_libraries(trav3_test ${CGoGN_LIBS} ${CGoGN_EXT_LIBS}) + IF (WITH_QT) QT4_WRAP_CPP(tilings_moc tilings.h) add_executable(tilings tilings.cpp ${tilings_moc}) diff --git a/Apps/SandBox/trav3_test.cpp b/Apps/SandBox/trav3_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e9c1318fa8c1b568cc83b25f49155c037316097 --- /dev/null +++ b/Apps/SandBox/trav3_test.cpp @@ -0,0 +1,193 @@ +/******************************************************************************* +* 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/embeddedMap3.h" +#include "Algo/Tiling/Volume/cubic.h" +#include "Utils/chrono.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_DOUBLE +{ + // definition of the type of the map + typedef EmbeddedMap3 MAP; +}; + +// some typedef shortcuts +typedef PFP::MAP MAP ; // map type +typedef PFP::VEC3 VEC3 ; // type of R³ vector + + + +template +typename V_ATT::DATA_TYPE localvolumeCentroidELW(typename PFP::MAP& map, Vol d, const V_ATT& attributs, unsigned int thread=0) +{ + typedef typename V_ATT::DATA_TYPE EMB; + EMB center(0.0); + + double count=0.0; + + for (Edge it : edgesIncidentToVolume3(map,d)) + { + EMB e1 = attributs[it.dart]; + EMB e2 = attributs[map.phi1(it)]; + double l = (e2-e1).norm(); + center += (e1+e2)*l; + count += 2.0*l ; + } + center /= double(count); + return center ; +} + + +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 4x4x4 squares + Algo::Volume::Tilings::Cubic::Grid cubic(myMap, 20, 20, 20); + cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f); + + // easy way to find the central vertex of the grid + Vertex v; + foreach_cell_until(myMap, [&] (Vertex it) + { + if (position[it] == VEC3(0,0,0)) + { + v = it; + std::cout << "Trouve"<< std::endl; + return false; + } + return true; + }); + + // must test of find ok (if not v.dart is NIL) + if (! v.valid()) + std::cerr << "could not find a vertex with position (0,0,0)" << std::endl; + +// WITH TRAVERSORS: + + // find incident faces to vertex + Traversor3VF trvf(myMap, v.dart); + for (Dart e = trvf.begin(); e != trvf.end(); e = trvf.next()) + { + std::cout << "Face of dart "< trvvaf(myMap, v.dart); + for (Dart e = trvvaf.begin(); e != trvvaf.end(); e = trvvaf.next()) + { + std::cout << "vertex of dart "<(myMap, v, [&](Face f) + { + std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl; + }); + + // find vertices adjacent to vertex v thru a face + foreach_adjacent3(myMap, v, [&](Vertex x) + { + std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl; + }); + +// WITH FOR C++11 SYNTAX + for(Face f : facesIncidentToVertex3(myMap,v)) + std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl; + + for (Vertex x : verticesAdjacentByFace3(myMap,v)) + std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl; + + + + for(Vertex v1 : allVerticesOf(myMap)) + { + for (Vertex v2 : verticesAdjacentByEdge3(myMap,v1)) + { + for (Face f : facesIncidentToVertex3(myMap,v2)) + if ((f.dart.index)%1000 == 1 ) + std::cout << "juste for fun face " << f << std::endl; + } + } + + + Utils::Chrono ch; + + VertexAttribute pos2 = myMap.getAttribute("pos2") ; + if(!pos2.isValid()) + pos2 = myMap.addAttribute("pos2") ; + + ch.start(); + + for (int i=0; i< 20; ++i) + { + VEC3 xx(0,0,0); + int nb=0; + for(Vol d : allVolumesOf(myMap)) + { + VEC3 vCentroid = localvolumeCentroidELW(myMap, d, position) ; + xx += vCentroid; + nb++; + } + xx /= nb; + std::cout << xx << std::endl; + } + std::cout << "for "<< ch.elapsed()<< " ms "<< std::endl; + + ch.start(); + + for (int i=0; i< 20; ++i) + { + VEC3 xx(0,0,0); + int nb=0; + foreach_cell(myMap, [&] (Vol d) + { + VEC3 vCentroid = Algo::Surface::Geometry::volumeCentroidELW(myMap, d, position) ; + xx += vCentroid; + nb++; + }); + xx /= nb; + std::cout << xx << std::endl; + } + std::cout << "Lambda "<< ch.elapsed()<< " ms "<< std::endl; + + + + + return 0; +} diff --git a/include/Topology/generic/traversor/traversorDoO.h b/include/Topology/generic/traversor/traversorDoO.h index 3da76ef92a263e4c146ae93eca81516434253ecd..9a42af30bfd7d00d91675655289ab120462cb253 100644 --- a/include/Topology/generic/traversor/traversorDoO.h +++ b/include/Topology/generic/traversor/traversorDoO.h @@ -47,7 +47,7 @@ public: ~TraversorDartsOfOrbit(); TraversorDartsOfOrbit(TraversorDartsOfOrbit&& tr): - m_vd(tr.m_vd), m_current(tr.m_current),m_thread(tr.m_thread) + m_current(tr.m_current),m_vd(tr.m_vd),m_thread(tr.m_thread) { }