Commit a84e1f2d authored by Sylvain Thery's avatar Sylvain Thery

foreach_orbit use traversor

parent d2336a45
......@@ -34,7 +34,6 @@ namespace CGoGN
class AttribMap : public GenericMap
{
private:
friend class CellMarkerGen ;
template<typename T> 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<Dart>* addRelation(const std::string& name) ;
public:
/****************************************
......
......@@ -88,20 +88,5 @@ inline unsigned int AttribMap::getNbCells(unsigned int orbit)
return this->m_attribs[orbit].size() ;
}
/****************************************
* TOPOLOGICAL ATTRIBUTES MANAGEMENT *
****************************************/
inline AttributeMultiVector<Dart>* AttribMap::addRelation(const std::string& name)
{
AttributeContainer& cont = m_attribs[DART] ;
AttributeMultiVector<Dart>* amv = cont.addAttribute<Dart>(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
......@@ -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<unsigned int> 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()
......
......@@ -77,6 +77,7 @@ class GenericMap : public MapBrowser
{
template<typename T> friend class AttributeHandler ;
template<typename T> 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<Dart>* addRelation(const std::string& name) ;
/****************************************
* THREAD MANAGEMENT *
****************************************/
......
......@@ -218,4 +218,21 @@ inline void GenericMap::next(Dart& d)
m_attribs[DART].next(d.index) ;
}
/****************************************
* TOPOLOGICAL ATTRIBUTES MANAGEMENT *
****************************************/
inline AttributeMultiVector<Dart>* GenericMap::addRelation(const std::string& name)
{
AttributeContainer& cont = m_attribs[DART] ;
AttributeMultiVector<Dart>* amv = cont.addAttribute<Dart>(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
......@@ -32,7 +32,7 @@
namespace CGoGN
{
template <typename MAP, unsigned int ORBIT>
template <typename MAP>
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 <typename MAP>
class TraversorV : public TraversorCell<MAP, VERTEX>
class TraversorV : public TraversorCell<MAP>
{
public:
TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VERTEX>(m, thread)
TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, VERTEX, thread)
{}
};
template <typename MAP>
class TraversorE : public TraversorCell<MAP, EDGE>
class TraversorE : public TraversorCell<MAP>
{
public:
TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, EDGE>(m, thread)
TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, EDGE, thread)
{}
};
template <typename MAP>
class TraversorF : public TraversorCell<MAP, FACE>
class TraversorF : public TraversorCell<MAP>
{
public:
TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, FACE>(m, thread)
TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, FACE, thread)
{}
};
template <typename MAP>
class TraversorW : public TraversorCell<MAP, VOLUME>
class TraversorW : public TraversorCell<MAP>
{
public:
TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VOLUME>(m, thread)
TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, VOLUME, thread)
{}
};
......
......@@ -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<unsigned int>* amv = dartCont.addAttribute<unsigned int>(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<Mark>* amvMark = cellCont.addAttribute<Mark>(ss.str()) ;
for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i))
amvMark->operator[](i).clear() ;
m_markTables[orbit][t] = amvMark ;
}
}
/****************************************
* UTILITIES *
......
......@@ -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<unsigned int>* amv = dartCont.addAttribute<unsigned int>(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<Mark>* amvMark = cellCont.addAttribute<Mark>(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<GenericMap> 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment