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

template in the dart/cell markers

parent b066d4a5
...@@ -125,9 +125,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position ...@@ -125,9 +125,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
typedef Geom::Vec3f VEC3F; 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) if (m_attIndex.map() != &mapx)
m_attIndex = mapx.template getAttribute<unsigned int, DART>("dart_index"); m_attIndex = mapx.template getAttribute<unsigned int, DART>("dart_index");
if (!m_attIndex.isValid()) if (!m_attIndex.isValid())
...@@ -197,7 +194,7 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position ...@@ -197,7 +194,7 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
*positionDartBuf++ = PFP::toVec3f(P); *positionDartBuf++ = PFP::toVec3f(P);
*positionDartBuf++ = PFP::toVec3f(PP); *positionDartBuf++ = PFP::toVec3f(PP);
if (map.isBoundaryMarked3(d)) if (mapx.isBoundaryMarked3(d))
{ {
*colorDartBuf++ = m_boundaryDartsColor; *colorDartBuf++ = m_boundaryDartsColor;
*colorDartBuf++ = m_boundaryDartsColor; *colorDartBuf++ = m_boundaryDartsColor;
...@@ -216,8 +213,8 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position ...@@ -216,8 +213,8 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
*positionDartBuf++ = PFP::toVec3f(Q); *positionDartBuf++ = PFP::toVec3f(Q);
*positionDartBuf++ = PFP::toVec3f(QQ); *positionDartBuf++ = PFP::toVec3f(QQ);
Dart dx = map.phi3(d); Dart dx = mapx.phi3(d);
if (map.isBoundaryMarked3(dx)) if (mapx.isBoundaryMarked3(dx))
{ {
*colorDartBuf++ = m_boundaryDartsColor; *colorDartBuf++ = m_boundaryDartsColor;
*colorDartBuf++ = m_boundaryDartsColor; *colorDartBuf++ = m_boundaryDartsColor;
...@@ -251,9 +248,9 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position ...@@ -251,9 +248,9 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position
m_nbRel2=0; 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) //if (d < e)
{ {
......
...@@ -66,14 +66,12 @@ void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribut ...@@ -66,14 +66,12 @@ void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribut
template<typename PFP> template<typename PFP>
void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, float ke, float kf, bool withBoundary) 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 (map.mapTypeName()[0] == "M") // "Map2"
if (ptrMap2 != NULL)
{ {
updateDataMap<PFP>(map, positions, ke, kf, withBoundary); updateDataMap<PFP>(map, positions, ke, kf, withBoundary);
return; return;
} }
GMap2* ptrGMap2 = dynamic_cast<GMap2*>(&map); if (map.mapTypeName()[0] == "G") // "GMap2"
if (ptrGMap2 != NULL)
{ {
updateDataGMap<PFP>(map, positions, ke, kf, withBoundary); updateDataGMap<PFP>(map, positions, ke, kf, withBoundary);
return; return;
......
...@@ -37,15 +37,16 @@ namespace CGoGN ...@@ -37,15 +37,16 @@ namespace CGoGN
* Browser that traverses all darts and jumps over * Browser that traverses all darts and jumps over
* those not selected by the selector * those not selected by the selector
*/ */
template <typename MAP>
class DartContainerBrowserSelector : public ContainerBrowser class DartContainerBrowserSelector : public ContainerBrowser
{ {
protected: protected:
AttributeContainer* m_cont ; AttributeContainer* m_cont ;
const FunctorSelect* m_selector ; const FunctorSelect* m_selector ;
AttribMap& m_map; MAP& m_map;
public: public:
DartContainerBrowserSelector(AttribMap& m, const FunctorSelect& fs); DartContainerBrowserSelector(MAP& m, const FunctorSelect& fs);
~DartContainerBrowserSelector(); ~DartContainerBrowserSelector();
unsigned int begin() const; unsigned int begin() const;
unsigned int end() const; unsigned int end() const;
...@@ -54,6 +55,8 @@ public: ...@@ -54,6 +55,8 @@ public:
void disable(); void disable();
} ; } ;
template <unsigned int CELL> template <unsigned int CELL>
class ContainerBrowserCellMarked : public ContainerBrowser class ContainerBrowserCellMarked : public ContainerBrowser
{ {
......
...@@ -21,57 +21,44 @@ ...@@ -21,57 +21,44 @@
* Contact information: cgogn@unistra.fr * * Contact information: cgogn@unistra.fr *
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/attribmap.h" #include "Topology/generic/attribmap.h"
namespace CGoGN namespace CGoGN
{ {
template <typename MAP>
inline DartContainerBrowserSelector::DartContainerBrowserSelector(AttribMap& m, const FunctorSelect& fs): inline DartContainerBrowserSelector<MAP>::DartContainerBrowserSelector(MAP& m, const FunctorSelect& fs):
m_map(m) m_map(m)
{ {
if (GenericMap::isMultiRes()) m_cont = &m.getDartContainer();
{
m_cont = &(m.getMRAttributeContainer());
}
else
{
m_cont = &(m.getAttributeContainer<DART>());
}
m_selector = fs.copy(); m_selector = fs.copy();
} }
inline DartContainerBrowserSelector::~DartContainerBrowserSelector() template <typename MAP>
inline DartContainerBrowserSelector<MAP>::~DartContainerBrowserSelector()
{ {
delete m_selector; 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)) )
unsigned int it = m_cont->realBegin() ; m_cont->realNext(it);
while ( (it != m_cont->realEnd()) && !m_selector->operator()(m_map.indexDart(it)) ) return 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;
}
} }
inline unsigned int DartContainerBrowserSelector::end() const template <typename MAP>
inline unsigned int DartContainerBrowserSelector<MAP>::end() const
{ {
return m_cont->realEnd(); 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 do
{ {
...@@ -80,39 +67,55 @@ inline void DartContainerBrowserSelector::next(unsigned int& it) const ...@@ -80,39 +67,55 @@ inline void DartContainerBrowserSelector::next(unsigned int& it) const
while ( (it != m_cont->realEnd()) && !m_selector->operator()(Dart(it)) ) ; while ( (it != m_cont->realEnd()) && !m_selector->operator()(Dart(it)) ) ;
} }
template <typename MAP>
inline void DartContainerBrowserSelector::enable() inline void DartContainerBrowserSelector<MAP>::enable()
{ {
m_cont->setContainerBrowser(this); m_cont->setContainerBrowser(this);
} }
inline void DartContainerBrowserSelector::disable() template <typename MAP>
inline void DartContainerBrowserSelector<MAP>::disable()
{ {
m_cont->setContainerBrowser(NULL); m_cont->setContainerBrowser(NULL);
} }
inline ContainerBrowserLinked::ContainerBrowserLinked(AttribMap& m, unsigned int orbit): 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_cont = &(m.getAttributeContainer(orbit));
m_links = m_cont->addAttribute<unsigned int>("Browser_Links") ; m_links = m_cont->addAttribute<unsigned int>("Browser_Links") ;
} }
inline ContainerBrowserLinked::ContainerBrowserLinked(AttributeContainer& c): 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") ; m_links = m_cont->addAttribute<unsigned int>("Browser_Links") ;
} }
inline ContainerBrowserLinked::ContainerBrowserLinked(AttributeContainer& c, AttributeMultiVector<unsigned int>* 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): 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() inline ContainerBrowserLinked::~ContainerBrowserLinked()
...@@ -157,7 +160,6 @@ inline void ContainerBrowserLinked::pushBack(unsigned int it) ...@@ -157,7 +160,6 @@ inline void ContainerBrowserLinked::pushBack(unsigned int it)
} }
} }
inline void ContainerBrowserLinked::enable() inline void ContainerBrowserLinked::enable()
{ {
m_cont->setContainerBrowser(this); m_cont->setContainerBrowser(this);
...@@ -181,13 +183,11 @@ inline ContainerBrowserCellMarked<CELL>::ContainerBrowserCellMarked(AttribMap& m ...@@ -181,13 +183,11 @@ inline ContainerBrowserCellMarked<CELL>::ContainerBrowserCellMarked(AttribMap& m
m_cont = &(m.getAttributeContainer<CELL>()); m_cont = &(m.getAttributeContainer<CELL>());
} }
template <unsigned int CELL> template <unsigned int CELL>
inline ContainerBrowserCellMarked<CELL>::~ContainerBrowserCellMarked() inline ContainerBrowserCellMarked<CELL>::~ContainerBrowserCellMarked()
{ {
} }
template <unsigned int CELL> template <unsigned int CELL>
inline unsigned int ContainerBrowserCellMarked<CELL>::begin() const inline unsigned int ContainerBrowserCellMarked<CELL>::begin() const
{ {
...@@ -226,5 +226,4 @@ inline void ContainerBrowserCellMarked<CELL>::disable() ...@@ -226,5 +226,4 @@ inline void ContainerBrowserCellMarked<CELL>::disable()
m_cont->setContainerBrowser(NULL); m_cont->setContainerBrowser(NULL);
} }
} // namespace CGoGN } // namespace CGoGN
...@@ -41,7 +41,6 @@ class CellMarkerGen ...@@ -41,7 +41,6 @@ class CellMarkerGen
friend class GenericMap ; friend class GenericMap ;
protected: protected:
GenericMap& m_map ;
Mark m_mark ; Mark m_mark ;
AttributeMultiVector<Mark>* m_markVector ; AttributeMultiVector<Mark>* m_markVector ;
unsigned int m_thread ; unsigned int m_thread ;
...@@ -49,15 +48,12 @@ protected: ...@@ -49,15 +48,12 @@ protected:
bool releaseOnDestruct ; bool releaseOnDestruct ;
public: public:
CellMarkerGen(GenericMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(unsigned int cell, unsigned int thread = 0) :
m_map(map),
m_thread(thread), m_thread(thread),
m_cell(cell), m_cell(cell),
releaseOnDestruct(true) releaseOnDestruct(true)
{} {}
~CellMarkerGen() ~CellMarkerGen()
{} {}
...@@ -66,6 +62,11 @@ public: ...@@ -66,6 +62,11 @@ public:
void updateMarkVector(AttributeMultiVector<Mark>* amv) { m_markVector = amv ; } 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 * set if the mark has to be release on destruction or not
*/ */
...@@ -86,30 +87,36 @@ public: ...@@ -86,30 +87,36 @@ public:
* generic class that allows the marking of cells * generic class that allows the marking of cells
* \warning no default constructor * \warning no default constructor
*/ */
template <unsigned int CELL> template <typename MAP, unsigned int CELL>
class CellMarkerBase : public CellMarkerGen class CellMarkerBase : public CellMarkerGen
{ {
protected:
MAP& m_map ;
public: public:
/** /**
* constructor * constructor
* @param map the map on which we work * @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>()) if(!m_map.template isOrbitEmbedded<CELL>())
m_map.addEmbedding<CELL>() ; m_map.template addEmbedding<CELL>() ;
m_mark = m_map.getMarkerSet<CELL>(m_thread).getNewMark() ; m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.getMarkVector<CELL>(m_thread) ; m_markVector = m_map.template getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers[m_thread].push_back(this) ; m_map.cellMarkers[m_thread].push_back(this) ;
} }
CellMarkerBase(const GenericMap& map, unsigned int thread = 0) : CellMarkerBase(const MAP& map, unsigned int thread = 0) :
CellMarkerGen(const_cast<GenericMap&>(map), CELL, thread) CellMarkerGen(CELL, thread),
m_map(const_cast<MAP&>(map))
{ {
if(!m_map.isOrbitEmbedded<CELL>()) if(!m_map.template isOrbitEmbedded<CELL>())
m_map.addEmbedding<CELL>() ; m_map.template addEmbedding<CELL>() ;
m_mark = m_map.getMarkerSet<CELL>(m_thread).getNewMark() ; m_mark = m_map.template getMarkerSet<CELL>(m_thread).getNewMark() ;
m_markVector = m_map.getMarkVector<CELL>(m_thread) ; m_markVector = m_map.template getMarkVector<CELL>(m_thread) ;
m_map.cellMarkers[m_thread].push_back(this) ; m_map.cellMarkers[m_thread].push_back(this) ;
} }
...@@ -117,7 +124,7 @@ public: ...@@ -117,7 +124,7 @@ public:
{ {
if(releaseOnDestruct) 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]; std::vector<CellMarkerGen*>& cmg = m_map.cellMarkers[m_thread];
for(std::vector<CellMarkerGen*>::iterator it = cmg.begin(); it != cmg.end(); ++it) for(std::vector<CellMarkerGen*>::iterator it = cmg.begin(); it != cmg.end(); ++it)
...@@ -134,7 +141,9 @@ public: ...@@ -134,7 +141,9 @@ public:
protected: protected:
// protected copy constructor to forbid its usage // 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: public:
...@@ -143,7 +152,7 @@ public: ...@@ -143,7 +152,7 @@ public:
*/ */
inline void mark(Dart d) 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); assert(m_markVector != NULL);
unsigned int a = m_map.getEmbedding<CELL>(d) ; unsigned int a = m_map.getEmbedding<CELL>(d) ;
...@@ -157,7 +166,7 @@ public: ...@@ -157,7 +166,7 @@ public:
*/ */
inline void unmark(Dart d) 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); assert(m_markVector != NULL);
unsigned int a = m_map.getEmbedding<CELL>(d) ; unsigned int a = m_map.getEmbedding<CELL>(d) ;
...@@ -171,7 +180,7 @@ public: ...@@ -171,7 +180,7 @@ public:
*/ */
inline bool isMarked(Dart d) const 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); assert(m_markVector != NULL);
unsigned int a = m_map.getEmbedding<CELL>(d) ; unsigned int a = m_map.getEmbedding<CELL>(d) ;
...@@ -185,7 +194,7 @@ public: ...@@ -185,7 +194,7 @@ public:
*/ */
inline void mark(unsigned int em) 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); assert(m_markVector != NULL);
m_markVector->operator[](em).setMark(m_mark) ; m_markVector->operator[](em).setMark(m_mark) ;
...@@ -196,7 +205,7 @@ public: ...@@ -196,7 +205,7 @@ public:
*/ */
inline void unmark(unsigned int em) 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); assert(m_markVector != NULL);
m_markVector->operator[](em).unsetMark(m_mark) ; m_markVector->operator[](em).unsetMark(m_mark) ;
...@@ -207,7 +216,7 @@ public: ...@@ -207,7 +216,7 @@ public:
*/ */
inline bool isMarked(unsigned int em) const 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); assert(m_markVector != NULL);
if (em == EMBNULL) if (em == EMBNULL)
...@@ -220,20 +229,20 @@ public: ...@@ -220,20 +229,20 @@ public:
*/ */
inline void markAll() 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); 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)) for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
m_markVector->operator[](i).setMark(m_mark) ; m_markVector->operator[](i).setMark(m_mark) ;
} }