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
This diff is collapsed.
This diff is collapsed.
......@@ -50,7 +50,7 @@ namespace CGoGN
class AttributeHandlerGen ;
class DartMarkerGen ;
class CellMarkerGen ;
template<unsigned int CELL> class CellMarkerBase ;
//template<typename MAP, unsigned int CELL> class CellMarkerBase ;
class GenericMap
{
......@@ -62,10 +62,9 @@ class GenericMap
template<typename T> friend class VolumeAutoAttribute ;
friend class DartMarkerGen ;
friend class CellMarkerGen ;
template<unsigned int CELL> friend class CellMarkerBase ;
template<typename MAP, unsigned int CELL> friend class CellMarkerBase ;
protected:
/**
* Attributes Containers
*/
......@@ -109,7 +108,6 @@ protected:
std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ;
std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ;
public:
static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ;
......@@ -165,17 +163,19 @@ public:
* @param d
* @return index of dart (depends on map implementation)
*/
virtual unsigned int dartIndex(Dart d) const ;
// virtual unsigned int dartIndex(Dart d) const = 0;
/**
* @return the number of darts in the map
* get the Dart of index in topological table
*/
virtual unsigned int getNbDarts() ;
// virtual Dart indexDart(unsigned int index) const = 0;
/**
* return true if the dart d refers to a valid index
* @return the number of darts in the map
*/
bool isDartValid(Dart d) ;
virtual unsigned int getNbDarts() ;
// AttributeContainer& getDartContainer() = 0;
/****************************************
* EMBEDDING MANAGEMENT *
......@@ -189,35 +189,6 @@ public:
bool isOrbitEmbedded(unsigned int orbit) const ;
/**
* get the cell index of the given dimension associated to dart d
* @return EMBNULL if the orbit of d is not attached to any cell
*/
template<unsigned int ORBIT>
unsigned int getEmbedding(Dart d) const;
/**
* Set the cell index of the given dimension associated to dart d
*/
template <unsigned int ORBIT>
void setDartEmbedding(Dart d, unsigned int emb) ;
/**
* Set the cell index of the given dimension associated to dart d
* !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding) !!! WARNING !!!
*/
template <unsigned int ORBIT>
void initDartEmbedding(Dart d, unsigned int emb) ;
/**
* Copy the index of the cell associated to a dart over an other dart
* @param orbit the id of orbit embedding
* @param dest the dart to overwrite
* @param src the dart to copy
*/
template <unsigned int ORBIT>
void copyDartEmbedding(Dart dest, Dart src) ;
/**
* Allocation of some place in attrib table
* @param orbit the orbit of embedding
......@@ -226,47 +197,6 @@ public:
template <unsigned int ORBIT>
unsigned int newCell() ;
/**
* Set the index of the associated cell to all the darts of an orbit
* @param orbit orbit to embed
* @param d a dart of the topological vertex
* @param em index of attribute to store as embedding
*/
template <unsigned int ORBIT>
void setOrbitEmbedding(Dart d, unsigned int em) ;
/**
* Set the index of the associated cell to all the darts of an orbit
* !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!!
*/
template <unsigned int ORBIT>
void initOrbitEmbedding(Dart d, unsigned int em) ;
/**
* Associate an new cell to all darts of an orbit
* @param orbit orbit to embed
* @param d a dart of the topological cell
* @return index of the attribute in table
*/
template <unsigned int ORBIT>
unsigned int setOrbitEmbeddingOnNewCell(Dart d) ;
/**
* Associate an new cell to all darts of an orbit
* !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!!
*/
template <unsigned int ORBIT>
unsigned int initOrbitEmbeddingNewCell(Dart d) ;
/**
* Copy the cell associated to a dart over an other dart
* @param orbit attribute orbit to use
* @param d the dart to overwrite (dest)
* @param e the dart to copy (src)
*/
template <unsigned int ORBIT>
void copyCell(Dart d, Dart e) ;
/**
* Line of attributes i is overwritten with line j
* @param orbit attribute orbit to use
......@@ -284,13 +214,6 @@ public:
template <unsigned int ORBIT>
void initCell(unsigned int i) ;
/**
* Traverse the map and embed all orbits of the given dimension with a new cell
* @param realloc if true -> all the orbits are embedded on new cells, if false -> already embedded orbits are not impacted
*/
template <unsigned int ORBIT>
void initAllOrbitsEmbedding(bool realloc = false) ;
/****************************************
* QUICK TRAVERSAL MANAGEMENT *
****************************************/
......@@ -440,14 +363,6 @@ public:
/****************************************
* SAVE & LOAD *
****************************************/
public:
/**
* check if an xml node has a given name
* @param node the xml node
* @param name the name
* @ return true if node has the good name
*/
// bool chechXmlNode(xmlNodePtr node, const std::string& name) ;
/**
* update the pointer of embedding vector after loading
......@@ -459,38 +374,24 @@ public:
*/
virtual void update_topo_shortcuts();
/**
* Save map in a XML file
* @param filename the file name
* @return true if OK
*/
// bool saveMapXml(const std::string& filename, bool compress = false) ;
/**
* Load map from a XML file
* @param filename the file name
* @return true if OK
*/
// bool loadMapXml(const std::string& filename, bool compress = false) ;
/**
* Save map in a binary file
* @param filename the file name
* @return true if OK
*/
bool saveMapBin(const std::string& filename) const;
virtual bool saveMapBin(const std::string& filename) const = 0;
/**
* Load map from a binary file
* @param filename the file name
* @return true if OK
*/
bool loadMapBin(const std::string& filename) ;
virtual bool loadMapBin(const std::string& filename) = 0 ;
/**
* copy from another map (of same type)
*/
bool copyFrom(const GenericMap& map) ;
virtual bool copyFrom(const GenericMap& map) = 0 ;
/**
* Dump attributes types and names per orbit
......@@ -511,11 +412,11 @@ public:
* DARTS TRAVERSALS *
****************************************/
// /**
// * Apply a functor on each dart of the map
// * @param f a ref to the functor obj
// */
// bool foreach_dart(FunctorType& f) ;
/**
* Apply a functor on each dart of the map
* @param f a ref to the functor obj
*/
bool foreach_dart(FunctorType& f) ;
virtual Dart begin() const;
virtual Dart end() const;
......
......@@ -90,10 +90,10 @@ inline unsigned int GenericMap::getNbDarts()
return m_attribs[DART].size() ;
}
inline bool GenericMap::isDartValid(Dart d)
{
return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ;
}
//inline bool GenericMap::isDartValid(Dart d)
//{
// return !d.isNil() && m_attribs[DART].used(dartIndex(d)) ;
//}
/****************************************
* EMBEDDING MANAGEMENT *
......@@ -110,61 +110,6 @@ inline bool GenericMap::isOrbitEmbedded(unsigned int orbit) const
return (orbit == DART) || (m_embeddings[orbit] != NULL) ;
}
template <unsigned int ORBIT>
inline unsigned int GenericMap::getEmbedding(Dart d) const
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
unsigned int d_index = dartIndex(d);
if (ORBIT == DART)
return d_index;
return (*m_embeddings[ORBIT])[d_index] ;
}
template <unsigned int ORBIT>
void GenericMap::setDartEmbedding(Dart d, unsigned int emb)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
unsigned int old = getEmbedding<ORBIT>(d);
if (old == emb) // if same emb
return; // nothing to do
if (old != EMBNULL) // if different
{
if(m_attribs[ORBIT].unrefLine(old)) // then unref the old emb
{
for (unsigned int t = 0; t < m_nbThreads; ++t) // clear the markers if it was the
(*m_markTables[ORBIT][t])[old].clear(); // last unref of the line
}
}
if (emb != EMBNULL)
m_attribs[ORBIT].refLine(emb); // ref the new emb
(*m_embeddings[ORBIT])[dartIndex(d)] = emb ; // finally affect the embedding to the dart
}
template <unsigned int ORBIT>
void GenericMap::initDartEmbedding(Dart d, unsigned int emb)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
assert(getEmbedding<ORBIT>(d) == EMBNULL || !"initDartEmbedding called on already embedded dart");
if(emb != EMBNULL)
m_attribs[ORBIT].refLine(emb); // ref the new emb
(*m_embeddings[ORBIT])[dartIndex(d)] = emb ; // affect the embedding to the dart
}
template <unsigned int ORBIT>
inline void GenericMap::copyDartEmbedding(Dart dest, Dart src)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
setDartEmbedding<ORBIT>(dest, getEmbedding<ORBIT>(src));
}
template <unsigned int ORBIT>
inline unsigned int GenericMap::newCell()
{
......@@ -172,54 +117,6 @@ inline unsigned int GenericMap::newCell()
return m_attribs[ORBIT].insertLine();
}
template <unsigned int ORBIT>
inline void GenericMap::setOrbitEmbedding(Dart d, unsigned int em)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
FunctorSetEmb<GenericMap, ORBIT> fsetemb(*this, em);
foreach_dart_of_orbit<ORBIT>(d, fsetemb);
}
template <unsigned int ORBIT>
inline void GenericMap::initOrbitEmbedding(Dart d, unsigned int em)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
FunctorInitEmb<GenericMap, ORBIT> fsetemb(*this, em);
foreach_dart_of_orbit<ORBIT>(d, fsetemb);
}
template <unsigned int ORBIT>
inline unsigned int GenericMap::setOrbitEmbeddingOnNewCell(Dart d)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
unsigned int em = newCell<ORBIT>();
setOrbitEmbedding<ORBIT>(d, em);
return em;
}
template <unsigned int ORBIT>
inline unsigned int GenericMap::initOrbitEmbeddingNewCell(Dart d)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
unsigned int em = newCell<ORBIT>();
initOrbitEmbedding<ORBIT>(d, em);
return em;
}
template <unsigned int ORBIT>
inline void GenericMap::copyCell(Dart d, Dart e)
{
assert(isOrbitEmbedded<ORBIT>() || !"Invalid parameter: orbit not embedded");
unsigned int dE = getEmbedding<ORBIT>(d) ;
unsigned int eE = getEmbedding<ORBIT>(e) ;
if(eE != EMBNULL) // if the source is NULL, nothing to copy
{
if(dE == EMBNULL) // if the dest is NULL, create a new cell
dE = setOrbitEmbeddingOnNewCell<ORBIT>(d) ;
m_attribs[ORBIT].copyLine(dE, eE) ; // copy the data
}
}
template <unsigned int ORBIT>
inline void GenericMap::copyCell(unsigned int i, unsigned int j)
{
......@@ -234,23 +131,6 @@ inline void GenericMap::initCell(unsigned int i)
m_attribs[ORBIT].initLine(i) ;
}
template <unsigned int ORBIT>
void GenericMap::initAllOrbitsEmbedding(bool realloc)
{
if(!isOrbitEmbedded<ORBIT>())
addEmbedding<ORBIT>() ;
DartMarker mark(*this) ;
for(Dart d = begin(); d != end(); next(d))
{
if(!mark.isMarked(d))
{
mark.markOrbit<ORBIT>(d) ;
if(realloc || getEmbedding<ORBIT>(d) == EMBNULL)
setOrbitEmbeddingOnNewCell<ORBIT>(d) ;
}
}
}
/****************************************
* QUICK TRAVERSAL MANAGEMENT *
****************************************/
......@@ -352,7 +232,7 @@ inline void GenericMap::updateQuickIncidentTraversal()
buffer.push_back(e);
delete tra_loc;
buffer.push_back(NIL);
std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
std::vector<Dart>& vd = (*ptrVD)[MAP::getEmbedding<ORBIT>(d)];
vd.reserve(buffer.size());
vd.assign(buffer.begin(),buffer.end());
}
......@@ -375,8 +255,6 @@ inline void GenericMap::disableQuickIncidentTraversal()
}
}
template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
inline void GenericMap::enableQuickAdjacentTraversal()
{
......@@ -413,7 +291,7 @@ inline void GenericMap::updateQuickAdjacentTraversal()
buffer.push_back(e);
buffer.push_back(NIL);
delete tra_loc;
std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
std::vector<Dart>& vd = (*ptrVD)[MAP::getEmbedding<ORBIT>(d)];
vd.reserve(buffer.size());
vd.assign(buffer.begin(),buffer.end());
}
......@@ -548,7 +426,7 @@ bool GenericMap::foreach_dart_of_orbit(Dart d, FunctorType& f, unsigned int thre
template <typename MAP, unsigned int ORBIT>
bool GenericMap::foreach_orbit(FunctorType& fonct, unsigned int thread) const
{
TraversorCell<MAP, ORBIT> trav(*this, true, thread);
TraversorCell<MAP, ORBIT> trav(*reinterpret_cast<const MAP*>(this), true, thread);
bool found = false;
for (Dart d = trav.begin(); !found && d != trav.end(); d = trav.next())
......