Commit 929fb4d9 authored by Sylvain Thery's avatar Sylvain Thery

quick local traversal

parent eb300ea8
......@@ -284,6 +284,15 @@ void computeCentroidELWVolumes(typename PFP::MAP& map, const VertexAttribute<typ
}
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, unsigned int thread)
{
TraversorV<typename PFP::MAP> t(map, thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
vertex_centroid[d] = Volume::Geometry::vertexNeighborhoodCentroid<PFP>(map, d, position) ;
}
namespace Parallel
{
template <typename PFP>
......
......@@ -36,11 +36,14 @@
#include <boost/thread/mutex.hpp>
#include "Container/attributeContainer.h"
#include "Container/fakeAttribute.h"
#include "Topology/generic/dart.h"
#include "Topology/generic/marker.h"
#include "Topology/generic/functor.h"
namespace CGoGN
{
......@@ -102,6 +105,10 @@ protected:
*/
AttributeMultiVector<Dart>* m_quickTraversal[NB_ORBITS] ;
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* m_quickLocalIncidentTraversal[NB_ORBITS][NB_ORBITS] ;
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* m_quickLocalAdjacentTraversal[NB_ORBITS][NB_ORBITS] ;
/**
* Marks manager
*/
......@@ -474,6 +481,31 @@ public:
template <unsigned int ORBIT>
void disableQuickTraversal() ;
template <typename MAP, unsigned int ORBIT, unsigned int INCI>
void enableQuickLocalIncidentTraversal(MAP& map);
template <typename MAP, unsigned int ORBIT, unsigned int INCI>
void updateQuickLocalIncidentTraversal(MAP& map);
template <unsigned int ORBIT, unsigned int INCI>
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* getQuickLocalIncidentTraversal();
template <unsigned int ORBIT, unsigned int INCI>
void disableQuickLocalIncidentTraversal();
template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
void enableQuickLocalAdjacentTraversal(MAP& map);
template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
void updateQuickLocalAdjacentTraversal(MAP& map);
template <unsigned int ORBIT, unsigned int INCI>
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* getQuickLocalAdjacentTraversal();
template <unsigned int ORBIT, unsigned int ADJ>
void disableQuickLocalAdjacentTraversal();
/****************************************
* ATTRIBUTES MANAGEMENT *
****************************************/
......
......@@ -444,6 +444,7 @@ void GenericMap::initAllOrbitsEmbedding(bool realloc)
template <unsigned int ORBIT>
inline void GenericMap::enableQuickTraversal()
{
if(m_quickTraversal[ORBIT] == NULL)
{
if(!isOrbitEmbedded<ORBIT>())
......@@ -485,6 +486,130 @@ inline void GenericMap::disableQuickTraversal()
}
}
template <typename MAP, unsigned int ORBIT, unsigned int INCI>
inline void GenericMap::enableQuickLocalIncidentTraversal(MAP& map)
{
if(m_quickLocalIncidentTraversal[ORBIT][INCI] == NULL)
{
if(!isOrbitEmbedded<ORBIT>())
addEmbedding<ORBIT>() ;
std::stringstream ss;
ss << "quickLocalIncidentTraversal_" << INCI;
m_quickLocalIncidentTraversal[ORBIT][INCI] = m_attribs[ORBIT].addAttribute<NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
}
updateQuickLocalIncidentTraversal<MAP,ORBIT,INCI>(map) ;
}
template <typename MAP, unsigned int ORBIT, unsigned int INCI>
inline void GenericMap::updateQuickLocalIncidentTraversal(MAP& map)
{
assert(m_quickLocalIncidentTraversal[ORBIT][INCI] != NULL || !"updateQuickTraversal on a disabled orbit") ;
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* ptrVD = m_quickLocalIncidentTraversal[ORBIT][INCI];
m_quickLocalIncidentTraversal[ORBIT][INCI] = NULL;
std::vector<Dart> buffer;
buffer.reserve(100);
TraversorCell<MAP,ORBIT> tra_glob(map);
for (Dart d = tra_glob.begin(); d != tra_glob.end(); d = tra_glob.next())
{
buffer.clear();
Traversor3XY<MAP,ORBIT,INCI> tra_loc(map,d);
for (Dart e = tra_loc.begin(); e != tra_loc.end(); e = tra_loc.next())
buffer.push_back(e);
buffer.push_back(NIL);
std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
vd.reserve(buffer.size());
vd.assign(buffer.begin(),buffer.end());
}
m_quickLocalIncidentTraversal[ORBIT][INCI] = ptrVD;
}
template <unsigned int ORBIT, unsigned int INCI>
inline AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* GenericMap::getQuickLocalIncidentTraversal()
{
return m_quickLocalIncidentTraversal[ORBIT][INCI] ;
}
template <unsigned int ORBIT, unsigned int INCI>
inline void GenericMap::disableQuickLocalIncidentTraversal()
{
if(m_quickLocalIncidentTraversal[ORBIT][INCI] != NULL)
{
m_attribs[ORBIT].removeAttribute<Dart>(m_quickLocalIncidentTraversal[ORBIT][INCI]->getIndex()) ;
m_quickLocalIncidentTraversal[ORBIT][INCI] = NULL ;
}
}
template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
inline void GenericMap::enableQuickLocalAdjacentTraversal(MAP& map)
{
if(m_quickLocalAdjacentTraversal[ORBIT][ADJ] == NULL)
{
if(!isOrbitEmbedded<ORBIT>())
addEmbedding<ORBIT>() ;
std::stringstream ss;
ss << "m_quickLocalAdjacentTraversal" << ADJ;
m_quickLocalAdjacentTraversal[ORBIT][ADJ] = m_attribs[ORBIT].addAttribute<NoTypeNameAttribute<std::vector<Dart> > >(ss.str()) ;
}
updateQuickLocalAdjacentTraversal<MAP,ORBIT,ADJ>(map) ;
}
template <typename MAP, unsigned int ORBIT, unsigned int ADJ>
inline void GenericMap::updateQuickLocalAdjacentTraversal(MAP& map)
{
assert(m_quickLocalAdjacentTraversal[ORBIT][ADJ] != NULL || !"updateQuickTraversal on a disabled orbit") ;
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* ptrVD = m_quickLocalAdjacentTraversal[ORBIT][ADJ];
m_quickLocalAdjacentTraversal[ORBIT][ADJ] = NULL;
std::vector<Dart> buffer;
buffer.reserve(100);
TraversorCell<MAP,ORBIT> tra_glob(map);
for (Dart d = tra_glob.begin(); d != tra_glob.end(); d = tra_glob.next())
{
buffer.clear();
Traversor3XXaY<MAP,ORBIT,ADJ> tra_loc(map,d);
for (Dart e = tra_loc.begin(); e != tra_loc.end(); e = tra_loc.next())
buffer.push_back(e);
buffer.push_back(NIL);
std::vector<Dart>& vd = (*ptrVD)[getEmbedding<ORBIT>(d)];
vd.reserve(buffer.size());
vd.assign(buffer.begin(),buffer.end());
}
m_quickLocalAdjacentTraversal[ORBIT][ADJ] = ptrVD;
}
template <unsigned int ORBIT, unsigned int INCI>
inline AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* GenericMap::getQuickLocalAdjacentTraversal()
{
return m_quickLocalAdjacentTraversal[ORBIT][INCI] ;
}
template <unsigned int ORBIT, unsigned int ADJ>
inline void GenericMap::disableQuickLocalAdjacentTraversal()
{
if(m_quickLocalAdjacentTraversal[ORBIT][ADJ] != NULL)
{
m_attribs[ORBIT].removeAttribute<Dart>(m_quickLocalAdjacentTraversal[ORBIT][ADJ]->getIndex()) ;
m_quickLocalAdjacentTraversal[ORBIT][ADJ] = NULL ;
}
}
/****************************************
* ATTRIBUTES MANAGEMENT *
****************************************/
......
......@@ -69,6 +69,10 @@ private:
CellMarkerStore<ORBY>* m_cmark ;
Dart m_current ;
TraversorDartsOfOrbit<MAP, ORBX> m_tradoo;
std::vector<Dart>* m_QLT;
std::vector<Dart>::iterator m_ItDarts;
bool m_allocated;
bool m_first;
public:
......@@ -91,6 +95,9 @@ private:
MAP& m_map ;
std::vector<Dart> m_vecDarts;
std::vector<Dart>::iterator m_iter;
std::vector<Dart>* m_QLT;
std::vector<Dart>::iterator m_ItDarts;
public:
Traversor3XXaY(MAP& map, Dart dart, bool forceDartMarker = false, unsigned int thread = 0);
......
......@@ -22,6 +22,8 @@
* *
*******************************************************************************/
#include "Utils/static_assert.h"
#include "Container/attributeMultiVector.h"
#include "Container/fakeAttribute.h"
namespace CGoGN
{
......@@ -99,19 +101,29 @@ Traversor3XY<MAP, ORBX, ORBY>::Traversor3XY(MAP& map, Dart dart, bool forceDartM
m_dmark(NULL),
m_cmark(NULL),
m_tradoo(map, dart, thread),
m_QLT(NULL),
m_allocated(true),
m_first(true)
{
if(!forceDartMarker && map.isOrbitEmbedded(ORBY))
m_cmark = new CellMarkerStore<ORBY>(map, thread) ;
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickLocalIncidentTraversal<ORBX,ORBY>() ;
if (quickTraversal != NULL)
{
m_QLT = &(quickTraversal->operator[](map.template getEmbedding<ORBX>(dart)));
}
else
m_dmark = new DartMarkerStore(map, thread) ;
{
if(!forceDartMarker && map.isOrbitEmbedded(ORBY))
m_cmark = new CellMarkerStore<ORBY>(map, thread) ;
else
m_dmark = new DartMarkerStore(map, thread) ;
}
}
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Traversor3XY<MAP, ORBX, ORBY>::Traversor3XY(MAP& map, Dart dart, MarkerForTraversor<MAP, ORBY>& tmo, bool /*forceDartMarker*/, unsigned int thread) :
m_map(map),
m_tradoo(map, dart, thread),
m_QLT(NULL),
m_allocated(false),
m_first(true)
{
......@@ -134,6 +146,12 @@ Traversor3XY<MAP, ORBX, ORBY>::~Traversor3XY()
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Dart Traversor3XY<MAP, ORBX, ORBY>::begin()
{
if(m_QLT != NULL)
{
m_ItDarts = m_QLT->begin();
return *m_ItDarts++;
}
if (!m_first)
{
if (m_cmark)
......@@ -177,6 +195,11 @@ Dart Traversor3XY<MAP, ORBX, ORBY>::end()
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Dart Traversor3XY<MAP, ORBX, ORBY>::next()
{
if(m_QLT != NULL)
{
return *m_ItDarts++;
}
if(m_current != NIL)
{
if (m_cmark)
......@@ -233,24 +256,38 @@ Dart Traversor3XY<MAP, ORBX, ORBY>::next()
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Traversor3XXaY<MAP, ORBX, ORBY>::Traversor3XXaY(MAP& map, Dart dart, bool forceDartMarker, unsigned int thread):
m_map(map)
m_map(map),m_QLT(NULL)
{
MarkerForTraversor<MAP, ORBX> mk(map, forceDartMarker, thread);
mk.mark(dart);
Traversor3XY<MAP, ORBX, ORBY> traAdj(map, dart, forceDartMarker, thread);
for (Dart d = traAdj.begin(); d != traAdj.end(); d = traAdj.next())
AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickLocalAdjacentTraversal<ORBX,ORBY>() ;
if (quickTraversal != NULL)
{
Traversor3XY<MAP, ORBY, ORBX> traInci(map, d, mk, forceDartMarker, thread);
for (Dart e = traInci.begin(); e != traInci.end(); e = traInci.next())
m_vecDarts.push_back(e);
m_QLT = &(quickTraversal->operator[](map.template getEmbedding<ORBX>(dart)));
}
else
{
MarkerForTraversor<MAP, ORBX> mk(map, forceDartMarker, thread);
mk.mark(dart);
Traversor3XY<MAP, ORBX, ORBY> traAdj(map, dart, forceDartMarker, thread);
for (Dart d = traAdj.begin(); d != traAdj.end(); d = traAdj.next())
{
Traversor3XY<MAP, ORBY, ORBX> traInci(map, d, mk, forceDartMarker, thread);
for (Dart e = traInci.begin(); e != traInci.end(); e = traInci.next())
m_vecDarts.push_back(e);
}
m_vecDarts.push_back(NIL);
}
m_vecDarts.push_back(NIL);
}
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Dart Traversor3XXaY<MAP, ORBX, ORBY>::begin()
{
if(m_QLT != NULL)
{
m_ItDarts = m_QLT->begin();
return *m_ItDarts++;
}
m_iter = m_vecDarts.begin();
return *m_iter;
}
......@@ -264,6 +301,11 @@ Dart Traversor3XXaY<MAP, ORBX, ORBY>::end()
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Dart Traversor3XXaY<MAP, ORBX, ORBY>::next()
{
if(m_QLT != NULL)
{
return *m_ItDarts++;
}
if (*m_iter != NIL)
m_iter++;
return *m_iter ;
......
......@@ -87,6 +87,12 @@ GenericMap::GenericMap() : m_nbThreads(1)
m_marksets[i][j].clear() ;
m_markTables[i][j] = NULL ;
}
for(unsigned int j = 0; j < NB_ORBITS; ++j)
{
m_quickLocalIncidentTraversal[i][j] = NULL ;
m_quickLocalAdjacentTraversal[i][j] = NULL ;
}
}
for (unsigned int i=0; i<NB_THREAD; ++i)
......
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