Commit 4e878d8e authored by Pierre Kraemer's avatar Pierre Kraemer

template in the dart/cell markers

parent b066d4a5
......@@ -125,9 +125,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F;
Map3& map = dynamic_cast<Map3&>(mapx); // TODO reflechir comment virer ce warning quand on compile avec PFP::MAP=Map3
if (m_attIndex.map() != &mapx)
m_attIndex = mapx.template getAttribute<unsigned int, DART>("dart_index");
if (!m_attIndex.isValid())
......@@ -197,7 +194,7 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
*positionDartBuf++ = PFP::toVec3f(P);
*positionDartBuf++ = PFP::toVec3f(PP);
if (map.isBoundaryMarked3(d))
if (mapx.isBoundaryMarked3(d))
{
*colorDartBuf++ = m_boundaryDartsColor;
*colorDartBuf++ = m_boundaryDartsColor;
......@@ -216,8 +213,8 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
*positionDartBuf++ = PFP::toVec3f(Q);
*positionDartBuf++ = PFP::toVec3f(QQ);
Dart dx = map.phi3(d);
if (map.isBoundaryMarked3(dx))
Dart dx = mapx.phi3(d);
if (mapx.isBoundaryMarked3(dx))
{
*colorDartBuf++ = m_boundaryDartsColor;
*colorDartBuf++ = m_boundaryDartsColor;
......@@ -251,9 +248,9 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
m_nbRel2=0;
for (Dart d = map.begin(); d != map.end(); map.next(d))
for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d))
{
Dart e = map.phi2(map.phi3(d));
Dart e = mapx.phi2(mapx.phi3(d));
//if (d < e)
{
......
......@@ -66,14 +66,12 @@ void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribut
template<typename PFP>
void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary)
{
Map2* ptrMap2 = dynamic_cast<Map2*>(&map);
if (ptrMap2 != NULL)
if (map.mapTypeName()[0] == "M") // "Map2"
{
updateDataMap<PFP>(map, positions, ke, kf, withBoundary);
return;
}
GMap2* ptrGMap2 = dynamic_cast<GMap2*>(&map);
if (ptrGMap2 != NULL)
if (map.mapTypeName()[0] == "G") // "GMap2"
{
updateDataGMap<PFP>(map, positions, ke, kf, withBoundary);
return;
......
......@@ -37,15 +37,16 @@ namespace CGoGN
* Browser that traverses all darts and jumps over
* those not selected by the selector
*/
template <typename MAP>
class DartContainerBrowserSelector : public ContainerBrowser
{
protected:
AttributeContainer* m_cont ;
const FunctorSelect* m_selector ;
AttribMap& m_map;
MAP& m_map;
public:
DartContainerBrowserSelector(AttribMap& m, const FunctorSelect& fs);
DartContainerBrowserSelector(MAP& m, const FunctorSelect& fs);
~DartContainerBrowserSelector();
unsigned int begin() const;
unsigned int end() const;
......@@ -54,6 +55,8 @@ public:
void disable();
} ;
template <unsigned int CELL>
class ContainerBrowserCellMarked : public ContainerBrowser
{
......
......@@ -21,57 +21,44 @@
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Topology/generic/dart.h"
#include "Topology/generic/attribmap.h"
namespace CGoGN
{
inline DartContainerBrowserSelector::DartContainerBrowserSelector(AttribMap& m, const FunctorSelect& fs):
template <typename MAP>
inline DartContainerBrowserSelector<MAP>::DartContainerBrowserSelector(MAP& m, const FunctorSelect& fs):
m_map(m)
{
if (GenericMap::isMultiRes())
{
m_cont = &(m.getMRAttributeContainer());
}
else
{
m_cont = &(m.getAttributeContainer<DART>());
}
m_cont = &m.getDartContainer();
m_selector = fs.copy();
}
inline DartContainerBrowserSelector::~DartContainerBrowserSelector()
template <typename MAP>
inline DartContainerBrowserSelector<MAP>::~DartContainerBrowserSelector()
{
delete m_selector;
}
inline unsigned int DartContainerBrowserSelector::begin() const
template <typename MAP>
inline unsigned int DartContainerBrowserSelector<MAP>::begin() const
{
if (GenericMap::isMultiRes())
{
unsigned int it = m_cont->realBegin() ;
while ( (it != m_cont->realEnd()) && !m_selector->operator()(m_map.indexDart(it)) )
m_cont->realNext(it);
return it;
}
else
{
unsigned int it = m_cont->realBegin() ;
while ( (it != m_cont->realEnd()) && !m_selector->operator()(Dart(it)) )
m_cont->realNext(it);
return it;
}
unsigned int it = m_cont->realBegin() ;
while ( (it != m_cont->realEnd()) && !m_selector->operator()(m_map.indexDart(it)) )
m_cont->realNext(it);
return it;
}
inline unsigned int DartContainerBrowserSelector::end() const
template <typename MAP>
inline unsigned int DartContainerBrowserSelector<MAP>::end() const
{
return m_cont->realEnd();
}
inline void DartContainerBrowserSelector::next(unsigned int& it) const
template <typename MAP>
inline void DartContainerBrowserSelector<MAP>::next(unsigned int& it) const
{
do
{
......@@ -80,39 +67,55 @@ inline void DartContainerBrowserSelector::next(unsigned int& it) const
while ( (it != m_cont->realEnd()) && !m_selector->operator()(Dart(it)) ) ;
}
inline void DartContainerBrowserSelector::enable()
template <typename MAP>
inline void DartContainerBrowserSelector<MAP>::enable()
{
m_cont->setContainerBrowser(this);
}
inline void DartContainerBrowserSelector::disable()
template <typename MAP>
inline void DartContainerBrowserSelector<MAP>::disable()
{
m_cont->setContainerBrowser(NULL);
}
inline ContainerBrowserLinked::ContainerBrowserLinked(AttribMap& m, unsigned int orbit):
autoAttribute(true), m_first(0xffffffff), m_end(0xffffffff)
autoAttribute(true),
m_first(0xffffffff),
m_end(0xffffffff)
{
m_cont = &(m.getAttributeContainer(orbit));
m_links = m_cont->addAttribute<unsigned int>("Browser_Links") ;
}
inline ContainerBrowserLinked::ContainerBrowserLinked(AttributeContainer& c):
m_cont(&c), autoAttribute(true), m_first(0xffffffff), m_end(0xffffffff)
m_cont(&c),
autoAttribute(true),
m_first(0xffffffff),
m_end(0xffffffff)
{
m_links = m_cont->addAttribute<unsigned int>("Browser_Links") ;
}
inline ContainerBrowserLinked::ContainerBrowserLinked(AttributeContainer& c, AttributeMultiVector<unsigned int>* links):
m_cont(&c), m_links(links), autoAttribute(false), m_first(0xffffffff), m_end(0xffffffff)
m_cont(&c),
m_links(links),
autoAttribute(false),
m_first(0xffffffff),
m_end(0xffffffff)
{}
inline ContainerBrowserLinked::ContainerBrowserLinked(ContainerBrowserLinked& cbl):
m_cont(cbl.m_cont), m_links(cbl.m_links), m_first(0xffffffff), m_end(0xffffffff)
m_cont(cbl.m_cont),
m_links(cbl.m_links),
m_first(0xffffffff),
m_end(0xffffffff)
{}
inline ContainerBrowserLinked::~ContainerBrowserLinked()
......@@ -157,7 +160,6 @@ inline void ContainerBrowserLinked::pushBack(unsigned int it)
}
}
inline void ContainerBrowserLinked::enable()
{
m_cont->setContainerBrowser(this);
......@@ -181,13 +183,11 @@ inline ContainerBrowserCellMarked<CELL>::ContainerBrowserCellMarked(AttribMap& m
m_cont = &(m.getAttributeContainer<CELL>());
}
template <unsigned int CELL>
inline ContainerBrowserCellMarked<CELL>::~ContainerBrowserCellMarked()
{
}
template <unsigned int CELL>
inline unsigned int ContainerBrowserCellMarked<CELL>::begin() const
{
......@@ -226,5 +226,4 @@ inline void ContainerBrowserCellMarked<CELL>::disable()
m_cont->setContainerBrowser(NULL);
}
} // namespace CGoGN
......@@ -41,7 +41,6 @@ class CellMarkerGen
friend class GenericMap ;
protected:
GenericMap& m_map ;
Mark m_mark ;
AttributeMultiVector<Mark>* m_markVector ;
unsigned int m_thread ;
......@@ -49,15 +48,12 @@ protected:
bool releaseOnDestruct ;
public:
CellMarkerGen(GenericMap& map, unsigned int cell, unsigned int thread = 0) :
m_map(map),
CellMarkerGen(unsigned int cell, unsigned int thread = 0) :
m_thread(thread),
m_cell(cell),
releaseOnDestruct(true)
{}
~CellMarkerGen()
{}
......@@ -66,6 +62,11 @@ public:
void updateMarkVector(AttributeMultiVector<Mark>* amv) { m_markVector = amv ; }
protected:
// protected copy constructor to forbid its usage
CellMarkerGen(const CellMarkerGen& /*cm*/)
{}
/**
* set if the mark has to be release on destruction or not
*/
......@@ -86,30 +87,36 @@ public:
* generic class that allows the marking of cells
* \warning no default constructor
*/
template <unsigned int CELL>
template <typename MAP, unsigned int CELL>
class CellMarkerBase : public CellMarkerGen
{
protected:
MAP& m_map ;
public:
/**
* constructor
* @param map the map on which we work
*/
CellMarkerBase(GenericMap& map, unsigned int thread = 0) : CellMarkerGen(map, CELL, thread)
CellMarkerBase(MAP& map, unsigned int thread = 0) :
CellMarkerGen(CELL, thread),
m_map(map)
{
if(!m_map.isOrbitEmbedded<CELL>())
m_map.addEmbedding<CELL>() ;
m_mark = m_map.getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.getMarkVector<CELL>(m_thread) ;
if(!m_map.template isOrbitEmbedded<CELL>())
m_map.template addEmbedding<CELL>() ;
m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.template getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers[m_thread].push_back(this) ;
}
CellMarkerBase(const GenericMap& map, unsigned int thread = 0) :
CellMarkerGen(const_cast<GenericMap&>(map), CELL, thread)
CellMarkerBase(const MAP& map, unsigned int thread = 0) :
CellMarkerGen(CELL, thread),
m_map(const_cast<MAP&>(map))
{
if(!m_map.isOrbitEmbedded<CELL>())
m_map.addEmbedding<CELL>() ;
m_mark = m_map.getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.getMarkVector<CELL>(m_thread) ;
if(!m_map.template isOrbitEmbedded<CELL>())
m_map.template addEmbedding<CELL>() ;
m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.template getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers[m_thread].push_back(this) ;
}
......@@ -117,7 +124,7 @@ public:
{
if(releaseOnDestruct)
{
m_map.getMarkerSet<CELL>(m_thread).releaseMark(m_mark) ;
m_map.template getMarkerSet<CELL>(m_thread).releaseMark(m_mark) ;
std::vector<CellMarkerGen*>& cmg = m_map.cellMarkers[m_thread];
for(std::vector<CellMarkerGen*>::iterator it = cmg.begin(); it != cmg.end(); ++it)
......@@ -134,7 +141,9 @@ public:
protected:
// protected copy constructor to forbid its usage
CellMarkerBase(const CellMarkerGen& cm) : CellMarkerGen(cm.m_map, CELL)
CellMarkerBase(const CellMarkerBase<MAP, CELL>& cm) :
m_map(cm.m_map),
CellMarkerGen(CELL)
{}
public:
......@@ -143,7 +152,7 @@ public:
*/
inline void mark(Dart d)
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
unsigned int a = m_map.getEmbedding<CELL>(d) ;
......@@ -157,7 +166,7 @@ public:
*/
inline void unmark(Dart d)
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
unsigned int a = m_map.getEmbedding<CELL>(d) ;
......@@ -171,7 +180,7 @@ public:
*/
inline bool isMarked(Dart d) const
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
unsigned int a = m_map.getEmbedding<CELL>(d) ;
......@@ -185,7 +194,7 @@ public:
*/
inline void mark(unsigned int em)
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
m_markVector->operator[](em).setMark(m_mark) ;
......@@ -196,7 +205,7 @@ public:
*/
inline void unmark(unsigned int em)
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
m_markVector->operator[](em).unsetMark(m_mark) ;
......@@ -207,7 +216,7 @@ public:
*/
inline bool isMarked(unsigned int em) const
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
if (em == EMBNULL)
......@@ -220,20 +229,20 @@ public:
*/
inline void markAll()
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
AttributeContainer& cont = m_map.getAttributeContainer<CELL>() ;
AttributeContainer& cont = m_map.template getAttributeContainer<CELL>() ;
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
m_markVector->operator[](i).setMark(m_mark) ;
}
inline bool isAllUnmarked()
{
assert(m_map.getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
AttributeContainer& cont = m_map.getAttributeContainer<CELL>() ;
AttributeContainer& cont = m_map.template getAttributeContainer<CELL>() ;
for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
if(m_markVector->operator[](i).testMark(m_mark))
return false ;
......@@ -245,15 +254,15 @@ public:
* class that allows the marking of cells
* \warning no default constructor
*/
template <unsigned int CELL>
class CellMarker : public CellMarkerBase<CELL>
template <typename MAP, unsigned int CELL>
class CellMarker : public CellMarkerBase<MAP, CELL>
{
public:
CellMarker(GenericMap& map, unsigned int thread = 0) : CellMarkerBase<CELL>(map, thread)
CellMarker(MAP& map, unsigned int thread = 0) : CellMarkerBase<MAP, CELL>(map, thread)
{}
CellMarker(const GenericMap& map, unsigned int thread = 0) :
CellMarkerBase<CELL>(map, thread)
CellMarker(const MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
~CellMarker()
......@@ -262,7 +271,8 @@ public:
}
protected:
CellMarker(const CellMarker& cm) : CellMarkerBase<CELL>(cm)
CellMarker(const CellMarker& cm) :
CellMarkerBase<MAP, CELL>(cm)
{}
public:
......@@ -282,18 +292,19 @@ public:
* the marked cells are stored to optimize the unmarking task at destruction
* \warning no default constructor
*/
template <unsigned int CELL>
class CellMarkerStore: public CellMarkerBase<CELL>
template <typename MAP, unsigned int CELL>
class CellMarkerStore: public CellMarkerBase<MAP, CELL>
{
protected:
std::vector<unsigned int> m_markedCells ;
public:
CellMarkerStore(GenericMap& map, unsigned int thread = 0) : CellMarkerBase<CELL>(map, thread)
CellMarkerStore(MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
CellMarkerStore(const GenericMap& map, unsigned int thread = 0) :
CellMarkerBase<CELL>(map, thread)
CellMarkerStore(const MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
~CellMarkerStore()
......@@ -304,19 +315,20 @@ public:
}
protected:
CellMarkerStore(const CellMarkerStore& cm) : CellMarkerBase<CELL>(cm)
CellMarkerStore(const CellMarkerStore& cm) :
CellMarkerBase<MAP, CELL>(cm)
{}
public:
inline void mark(Dart d)
{
CellMarkerBase<CELL>::mark(d) ;
CellMarkerBase<MAP, CELL>::mark(d) ;
m_markedCells.push_back(this->m_map.template getEmbedding<CELL>(d)) ;
}
inline void mark(unsigned int em)
{
CellMarkerBase<CELL>::mark(em) ;
CellMarkerBase<MAP, CELL>::mark(em) ;
m_markedCells.push_back(em) ;
}
......@@ -335,21 +347,21 @@ public:
* the marked Darts are stored to optimize the unmarking task at destruction
* \warning no default constructor
*/
template <unsigned int CELL>
class CellMarkerMemo: public CellMarkerBase<CELL>
template <typename MAP, unsigned int CELL>
class CellMarkerMemo: public CellMarkerBase<MAP, CELL>
{
protected:
std::vector<Dart> m_markedDarts ;
public:
CellMarkerMemo(GenericMap& map, unsigned int thread = 0) : CellMarkerBase<CELL>(map, thread)
CellMarkerMemo(MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
CellMarkerMemo(const GenericMap& map, unsigned int thread = 0) :
CellMarkerBase<CELL>(map, thread)
CellMarkerMemo(const MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
~CellMarkerMemo()
{
unmarkAll() ;
......@@ -358,7 +370,8 @@ public:
}
protected:
CellMarkerMemo(const CellMarkerMemo& cm) : CellMarkerBase<CELL>(cm)
CellMarkerMemo(const CellMarkerMemo& cm) :
CellMarkerBase<MAP, CELL>(cm)
{}
public:
......@@ -366,7 +379,7 @@ public:
{
if(!this->isMarked(d))
{
CellMarkerBase<CELL>::mark(d) ;
CellMarkerBase<MAP, CELL>::mark(d) ;
m_markedDarts.push_back(d) ;
}
}
......@@ -383,7 +396,7 @@ public:
}
inline std::vector<Dart> get_markedCells()
inline const std::vector<Dart>& get_markedCells()
{
return m_markedDarts;
}
......@@ -394,18 +407,18 @@ public:
* the markers are not unmarked at destruction
* \warning no default constructor
*/
template <unsigned int CELL>
class CellMarkerNoUnmark: public CellMarkerBase<CELL>
template <typename MAP, unsigned int CELL>
class CellMarkerNoUnmark: public CellMarkerBase<MAP, CELL>
{
public:
CellMarkerNoUnmark(GenericMap& map, unsigned int thread = 0) : CellMarkerBase<CELL>(map, thread)
CellMarkerNoUnmark(MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
CellMarkerNoUnmark(const GenericMap& map, unsigned int thread = 0) :
CellMarkerBase<CELL>(map, thread)
CellMarkerNoUnmark(const MAP& map, unsigned int thread = 0) :
CellMarkerBase<MAP, CELL>(map, thread)
{}
~CellMarkerNoUnmark()
{
// assert(isAllUnmarked()) ;
......@@ -413,7 +426,8 @@ public:
}
protected:
CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarkerBase<CELL>(cm)
CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) :
CellMarkerBase<MAP, CELL>(cm)
{}
public:
......@@ -428,17 +442,22 @@ public:
}
};
// Selector and count functors testing for marker existence
/********************************************************/
/**
* selector that say if a dart has its cell marked
*/
template <unsigned int CELL>
template <typename MAP, unsigned int CELL>
class SelectorCellMarked : public FunctorSelect
{
protected:
const CellMarkerBase<CELL>& m_cmarker ;
const CellMarkerBase<MAP, CELL>& m_cmarker ;
public:
SelectorCellMarked(const CellMarkerBase<CELL>& cm) : m_cmarker(cm) {}
SelectorCellMarked(const CellMarkerBase<MAP, CELL>& cm) :
m_cmarker(cm)
{}
inline bool operator()(Dart d) const
{
......@@ -449,44 +468,59 @@ public: