From a84e1f2d39bed037778f0d0f96f3f711423a3818 Mon Sep 17 00:00:00 2001 From: Sylvain Thery Date: Tue, 8 Nov 2011 11:15:07 +0100 Subject: [PATCH] foreach_orbit use traversor --- include/Topology/generic/attribmap.h | 20 ------- include/Topology/generic/attribmap.hpp | 15 ------ include/Topology/generic/cellmarker.h | 12 ++--- include/Topology/generic/genericmap.h | 21 ++++++++ include/Topology/generic/genericmap.hpp | 17 ++++++ include/Topology/generic/traversorCell.h | 31 +++++------ src/Topology/generic/attribmap.cpp | 30 ----------- src/Topology/generic/genericmap.cpp | 69 ++++++++++++++++++++---- 8 files changed, 118 insertions(+), 97 deletions(-) diff --git a/include/Topology/generic/attribmap.h b/include/Topology/generic/attribmap.h index a8d52f92..7f59ddc2 100644 --- a/include/Topology/generic/attribmap.h +++ b/include/Topology/generic/attribmap.h @@ -34,7 +34,6 @@ namespace CGoGN class AttribMap : public GenericMap { private: - friend class CellMarkerGen ; template friend class AutoAttributeHandler ; void init() ; @@ -94,25 +93,6 @@ public: */ unsigned int getNbCells(unsigned int orbit); -protected: - /**************************************** - * EMBEDDING ATTRIBUTES MANAGEMENT * - ****************************************/ - /** - * Create the dart attribute to store the embedding of this orbit (for internal use only) - * Also adds a Marker attribute to the container - */ - void addEmbedding(unsigned int orbit) ; - - /**************************************** - * TOPOLOGICAL ATTRIBUTES MANAGEMENT * - ****************************************/ - - /** - * Add a toological relation in the map - * @param name name of relation - */ - AttributeMultiVector* addRelation(const std::string& name) ; public: /**************************************** diff --git a/include/Topology/generic/attribmap.hpp b/include/Topology/generic/attribmap.hpp index 9283e30e..cbbd9bfc 100644 --- a/include/Topology/generic/attribmap.hpp +++ b/include/Topology/generic/attribmap.hpp @@ -88,20 +88,5 @@ inline unsigned int AttribMap::getNbCells(unsigned int orbit) return this->m_attribs[orbit].size() ; } -/**************************************** - * TOPOLOGICAL ATTRIBUTES MANAGEMENT * - ****************************************/ - -inline AttributeMultiVector* AttribMap::addRelation(const std::string& name) -{ - AttributeContainer& cont = m_attribs[DART] ; - AttributeMultiVector* amv = cont.addAttribute(name) ; - - // set new relation to fix point for all the darts of the map - for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i)) - amv->operator[](i) = i ; - - return amv ; -} } // namespace CGoGN diff --git a/include/Topology/generic/cellmarker.h b/include/Topology/generic/cellmarker.h index 6323ce01..87d2ea4e 100644 --- a/include/Topology/generic/cellmarker.h +++ b/include/Topology/generic/cellmarker.h @@ -26,7 +26,7 @@ #define __CELL_MARKER__ #include "Topology/generic/marker.h" -#include "Topology/generic/attribmap.h" +#include "Topology/generic/genericmap.h" #include "Topology/generic/functor.h" #include "Utils/static_assert.h" @@ -42,7 +42,7 @@ class CellMarkerGen { protected: Mark m_mark ; - AttribMap& m_map ; + GenericMap& m_map ; unsigned int m_cell ; unsigned int m_thread ; @@ -52,7 +52,7 @@ public: * @param map the map on which we work * @param cell the type of cell we want to mark VERTEX, EDGE,... */ - CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread) + CellMarkerGen(GenericMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread) { if(!map.isOrbitEmbedded(cell)) map.addEmbedding(cell) ; @@ -189,7 +189,7 @@ public: class CellMarker : public CellMarkerGen { public: - CellMarker(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) + CellMarker(GenericMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) {} virtual ~CellMarker() @@ -225,7 +225,7 @@ protected: std::vector m_markedCells ; public: - CellMarkerStore(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) + CellMarkerStore(GenericMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) {} @@ -272,7 +272,7 @@ public: class CellMarkerNoUnmark: public CellMarkerGen { public: - CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) + CellMarkerNoUnmark(GenericMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) {} virtual ~CellMarkerNoUnmark() diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 19f34861..d4fdbff7 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -77,6 +77,7 @@ class GenericMap : public MapBrowser { template friend class AttributeHandler ; template friend class AutoAttributeHandler ; + friend class CellMarkerGen ; protected: /** @@ -272,6 +273,26 @@ public: */ void initOrbitEmbedding(unsigned int orbit, bool realloc = false) ; +protected: + /**************************************** + * EMBEDDING ATTRIBUTES MANAGEMENT * + ****************************************/ + /** + * Create the dart attribute to store the embedding of this orbit (for internal use only) + * Also adds a Marker attribute to the container + */ + void addEmbedding(unsigned int orbit) ; + + /**************************************** + * TOPOLOGICAL ATTRIBUTES MANAGEMENT * + ****************************************/ + + /** + * Add a toological relation in the map + * @param name name of relation + */ + AttributeMultiVector* addRelation(const std::string& name) ; + /**************************************** * THREAD MANAGEMENT * ****************************************/ diff --git a/include/Topology/generic/genericmap.hpp b/include/Topology/generic/genericmap.hpp index c1cd7a8b..fb3dd21e 100644 --- a/include/Topology/generic/genericmap.hpp +++ b/include/Topology/generic/genericmap.hpp @@ -218,4 +218,21 @@ inline void GenericMap::next(Dart& d) m_attribs[DART].next(d.index) ; } +/**************************************** + * TOPOLOGICAL ATTRIBUTES MANAGEMENT * + ****************************************/ + +inline AttributeMultiVector* GenericMap::addRelation(const std::string& name) +{ + AttributeContainer& cont = m_attribs[DART] ; + AttributeMultiVector* amv = cont.addAttribute(name) ; + + // set new relation to fix point for all the darts of the map + for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i)) + amv->operator[](i) = i ; + + return amv ; +} + + } //namespace CGoGN diff --git a/include/Topology/generic/traversorCell.h b/include/Topology/generic/traversorCell.h index 1a88d518..94508cc8 100644 --- a/include/Topology/generic/traversorCell.h +++ b/include/Topology/generic/traversorCell.h @@ -32,7 +32,7 @@ namespace CGoGN { -template +template class TraversorCell { private: @@ -41,13 +41,14 @@ private: CellMarker* cmark ; Dart current ; bool firstTraversal ; + unsigned int m_orbit; public: - TraversorCell(MAP& map, unsigned int thread = 0) : - m(map), dmark(NULL), cmark(NULL), current(NIL), firstTraversal(true) + TraversorCell(MAP& map, unsigned int orbit, unsigned int thread = 0) : + m(map), dmark(NULL), cmark(NULL), current(NIL), firstTraversal(true), m_orbit(orbit) { - if(map.isOrbitEmbedded(ORBIT)) - cmark = new CellMarker(map, ORBIT, thread) ; + if(map.isOrbitEmbedded(m_orbit)) + cmark = new CellMarker(map, m_orbit, thread) ; else dmark = new DartMarker(map, thread) ; } @@ -79,7 +80,7 @@ public: else { if(dmark) - dmark->markOrbit(ORBIT, current) ; + dmark->markOrbit(m_orbit, current) ; else cmark->mark(current) ; } @@ -117,7 +118,7 @@ public: if(current != NIL) { if(dmark) - dmark->markOrbit(ORBIT, current) ; + dmark->markOrbit(m_orbit, current) ; else cmark->mark(current) ; } @@ -127,34 +128,34 @@ public: } ; template -class TraversorV : public TraversorCell +class TraversorV : public TraversorCell { public: - TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell(m, VERTEX, thread) {} }; template -class TraversorE : public TraversorCell +class TraversorE : public TraversorCell { public: - TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell(m, EDGE, thread) {} }; template -class TraversorF : public TraversorCell +class TraversorF : public TraversorCell { public: - TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell(m, FACE, thread) {} }; template -class TraversorW : public TraversorCell +class TraversorW : public TraversorCell { public: - TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell(m, thread) + TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell(m, VOLUME, thread) {} }; diff --git a/src/Topology/generic/attribmap.cpp b/src/Topology/generic/attribmap.cpp index 3c6b0d39..8b4696cb 100644 --- a/src/Topology/generic/attribmap.cpp +++ b/src/Topology/generic/attribmap.cpp @@ -53,36 +53,6 @@ void AttribMap::clear(bool removeAttrib) init() ; } -/**************************************** - * EMBEDDING ATTRIBUTES MANAGEMENT * - ****************************************/ - -void AttribMap::addEmbedding(unsigned int orbit) -{ - assert(!isOrbitEmbedded(orbit) || !"Invalid parameter: orbit already embedded") ; - - std::ostringstream oss; - oss << "EMB_" << orbit; - - AttributeContainer& dartCont = m_attribs[DART] ; - AttributeMultiVector* amv = dartCont.addAttribute(oss.str()) ; - m_embeddings[orbit] = amv ; - - // set new embedding to EMBNULL for all the darts of the map - for(unsigned int i = dartCont.begin(); i < dartCont.end(); dartCont.next(i)) - amv->operator[](i) = EMBNULL ; - - AttributeContainer& cellCont = m_attribs[orbit]; - for (unsigned int t = 0; t < m_nbThreads; ++t) - { - std::stringstream ss ; - ss << "Mark_"<< t ; - AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; - for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i)) - amvMark->operator[](i).clear() ; - m_markTables[orbit][t] = amvMark ; - } -} /**************************************** * UTILITIES * diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index c97c0366..6e310880 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -25,6 +25,8 @@ #include "Topology/generic/genericmap.h" #include "Topology/generic/attributeHandler.h" #include "Topology/generic/dartmarker.h" +#include "Topology/generic/traversorCell.h" + #include "Geometry/vector_gen.h" #include "Geometry/matrix.h" #include "Container/registered.h" @@ -193,6 +195,38 @@ bool GenericMap::registerAttribute(const std::string &nameType) return true; } +/**************************************** + * EMBEDDING ATTRIBUTES MANAGEMENT * + ****************************************/ + +void GenericMap::addEmbedding(unsigned int orbit) +{ + assert(!isOrbitEmbedded(orbit) || !"Invalid parameter: orbit already embedded") ; + + std::ostringstream oss; + oss << "EMB_" << orbit; + + AttributeContainer& dartCont = m_attribs[DART] ; + AttributeMultiVector* amv = dartCont.addAttribute(oss.str()) ; + m_embeddings[orbit] = amv ; + + // set new embedding to EMBNULL for all the darts of the map + for(unsigned int i = dartCont.begin(); i < dartCont.end(); dartCont.next(i)) + amv->operator[](i) = EMBNULL ; + + AttributeContainer& cellCont = m_attribs[orbit]; + for (unsigned int t = 0; t < m_nbThreads; ++t) + { + std::stringstream ss ; + ss << "Mark_"<< t ; + AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; + for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i)) + amvMark->operator[](i).clear() ; + m_markTables[orbit][t] = amvMark ; + } +} + + /**************************************** * THREAD MANAGEMENT * ****************************************/ @@ -592,24 +626,37 @@ bool GenericMap::foreach_dart_of_orbit(unsigned int orbit, Dart d, FunctorType& bool GenericMap::foreach_orbit(unsigned int orbit, FunctorType& fonct, const FunctorSelect& good, unsigned int thread) { - DartMarker marker(*this, thread); // Lock a marker - bool found = false; // Store the result + TraversorCell trav(*this,orbit,thread); + bool found = false; // Store the result - // Scan all darts of the map - for (Dart d = begin(); !found && d != end(); next(d)) + for (Dart d = trav.begin(); !found && d != trav.end(); d = trav.next()) { if (good(d)) // If d is selected { - if (!marker.isMarked(d)) // If d is in a not yet visited cell - { - if ((fonct)(d)) // Apply functor - found = true; - else - marker.markOrbit(orbit, d); // Mark the cell as visited - } + if ((fonct)(d)) // Apply functor + found = true; } } return found; + +// DartMarker marker(*this, thread); // Lock a marker +// bool found = false; // Store the result +// +// // Scan all darts of the map +// for (Dart d = begin(); !found && d != end(); next(d)) +// { +// if (good(d)) // If d is selected +// { +// if (!marker.isMarked(d)) // If d is in a not yet visited cell +// { +// if ((fonct)(d)) // Apply functor +// found = true; +// else +// marker.markOrbit(orbit, d); // Mark the cell as visited +// } +// } +// } +// return found; } unsigned int GenericMap::getNbOrbits(unsigned int orbit, const FunctorSelect& good) -- GitLab