Commit e4faadd2 authored by Pierre Kraemer's avatar Pierre Kraemer

fonction generique degree(d) + applyFunctor dans les Traversors

parent 333cfee2
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <map> #include <map>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include "Container/attributeContainer.h" #include "Container/attributeContainer.h"
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
...@@ -89,7 +88,7 @@ protected: ...@@ -89,7 +88,7 @@ protected:
/** /**
* Direct access to the Dart attributes that store the orbits embeddings * Direct access to the Dart attributes that store the orbits embeddings
* (only initialized when necessary) * (only initialized when necessary, i.e. addEmbedding function)
*/ */
AttributeMultiVector<unsigned int>* m_embeddings[NB_ORBITS] ; AttributeMultiVector<unsigned int>* m_embeddings[NB_ORBITS] ;
...@@ -114,14 +113,12 @@ protected: ...@@ -114,14 +113,12 @@ protected:
/** /**
* Store links to created AttributeHandlers, DartMarkers and CellMarkers * Store links to created AttributeHandlers, DartMarkers and CellMarkers
*/ */
std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; // TODO think of MT (AttributeHandler creation & release are not thread safe! std::multimap<AttributeMultiVectorGen*, AttributeHandlerGen*> attributeHandlers ; // TODO think of MT (AttributeHandler creation & release are not thread safe!)
boost::mutex attributeHandlersMutex; boost::mutex attributeHandlersMutex;
std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ; std::vector<DartMarkerGen*> dartMarkers[NB_THREAD] ;
std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ; std::vector<CellMarkerGen*> cellMarkers[NB_THREAD] ;
/** /**
* is map a multiresolution map * is map a multiresolution map
*/ */
...@@ -170,6 +167,8 @@ public: ...@@ -170,6 +167,8 @@ public:
virtual std::string mapTypeName() const = 0 ; virtual std::string mapTypeName() const = 0 ;
virtual unsigned int dimension() const = 0 ;
/** /**
* Clear the map * Clear the map
* @param removeAttrib * @param removeAttrib
...@@ -236,7 +235,6 @@ public: ...@@ -236,7 +235,6 @@ public:
// */ // */
// AttributeMultiVector<unsigned int>* addLevel(); // AttributeMultiVector<unsigned int>* addLevel();
public:
/** /**
* add a resolution level in the back of the level table (use only in MRMaps) * add a resolution level in the back of the level table (use only in MRMaps)
*/ */
...@@ -314,7 +312,6 @@ public: ...@@ -314,7 +312,6 @@ public:
*/ */
void incDartLevel(Dart d) const ; void incDartLevel(Dart d) const ;
/** /**
* get the number of darts inserted in the given leveldart (use only in MRMaps) * get the number of darts inserted in the given leveldart (use only in MRMaps)
*/ */
...@@ -685,6 +682,12 @@ public: ...@@ -685,6 +682,12 @@ public:
template <unsigned int ORBIT> template <unsigned int ORBIT>
unsigned int getNbOrbits(const FunctorSelect& good = allDarts) ; unsigned int getNbOrbits(const FunctorSelect& good = allDarts) ;
//! For an orbit of a given dimension, return the number of incident cells of an other given dimension
/*! @param d a dart
*/
template <unsigned int ORBIT, unsigned int INCIDENT>
unsigned int degree(Dart d);
protected: protected:
/// boundary marker /// boundary marker
Mark m_boundaryMarker ; Mark m_boundaryMarker ;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "Topology/generic/dartmarker.h" #include "Topology/generic/dartmarker.h"
#include "Topology/generic/traversorCell.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversorFactory.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -611,6 +612,16 @@ unsigned int GenericMap::getNbOrbits(const FunctorSelect& good) ...@@ -611,6 +612,16 @@ unsigned int GenericMap::getNbOrbits(const FunctorSelect& good)
return fcount.getNb(); return fcount.getNb();
} }
template <unsigned int ORBIT, unsigned int INCIDENT>
unsigned int GenericMap::degree(Dart d)
{
assert(ORBIT != INCIDENT || !"degree does not manage adjacency counting");
Traversor<GenericMap>* t = TraversorFactory<GenericMap>::createIncident(*this, d, dimension(), ORBIT, INCIDENT) ;
FunctorCount fcount ;
t->applyFunctor(fcount) ;
return fcount.getNb() ;
}
template <unsigned int ORBIT> template <unsigned int ORBIT>
void GenericMap::boundaryMarkOrbit(Dart d) void GenericMap::boundaryMarkOrbit(Dart d)
{ {
......
...@@ -22,14 +22,11 @@ ...@@ -22,14 +22,11 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/traversorGen.h"
#ifndef __TRAVERSOR1_H__ #ifndef __TRAVERSOR1_H__
#define __TRAVERSOR1_H__ #define __TRAVERSOR1_H__
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/traversorGen.h"
namespace CGoGN namespace CGoGN
{ {
......
...@@ -22,14 +22,11 @@ ...@@ -22,14 +22,11 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/traversorGen.h"
#ifndef __TRAVERSOR2_H__ #ifndef __TRAVERSOR2_H__
#define __TRAVERSOR2_H__ #define __TRAVERSOR2_H__
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/traversorGen.h"
namespace CGoGN namespace CGoGN
{ {
......
...@@ -25,11 +25,11 @@ ...@@ -25,11 +25,11 @@
#ifndef __TRAVERSOR3_H__ #ifndef __TRAVERSOR3_H__
#define __TRAVERSOR3_H__ #define __TRAVERSOR3_H__
#include "Topology/generic/dart.h"
#include "Topology/generic/cellmarker.h"
#include "Topology/generic/traversorCell.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversorGen.h" #include "Topology/generic/traversorGen.h"
#include "Topology/generic/traversorDoO.h" #include "Topology/generic/traversorDoO.h"
#include "Topology/generic/dart.h"
#include "Topology/generic/cellmarker.h"
namespace CGoGN namespace CGoGN
{ {
......
...@@ -80,7 +80,6 @@ public: ...@@ -80,7 +80,6 @@ public:
{} {}
}; };
template <typename MAP> template <typename MAP>
class TraversorF : public TraversorCell<MAP, FACE> class TraversorF : public TraversorCell<MAP, FACE>
{ {
......
...@@ -153,35 +153,4 @@ void TraversorCell<MAP, ORBIT>::skip(Dart d) ...@@ -153,35 +153,4 @@ void TraversorCell<MAP, ORBIT>::skip(Dart d)
cmark->mark(d) ; cmark->mark(d) ;
} }
//
//template <typename MAP, unsigned int ORBIT>
//TraversorDartsOfOrbit<MAP, ORBIT>::TraversorDartsOfOrbit(MAP& map, Dart d, unsigned int thread)
//{
// m_vd.reserve(16);
// FunctorStoreNotBoundary<MAP> fs(map, m_vd);
// map.template foreach_dart_of_orbit<ORBIT>(d, fs, thread);
// m_vd.push_back(NIL);
//}
//
//template <typename MAP, unsigned int ORBIT>
//Dart TraversorDartsOfOrbit<MAP, ORBIT>::begin()
//{
// m_current = m_vd.begin();
// return *m_current;
//}
//
//template <typename MAP, unsigned int ORBIT>
//Dart TraversorDartsOfOrbit<MAP, ORBIT>::end()
//{
// return NIL;
//}
//
//template <typename MAP, unsigned int ORBIT>
//Dart TraversorDartsOfOrbit<MAP, ORBIT>::next()
//{
// if (*m_current != NIL)
// m_current++;
// return *m_current;
//}
} // namespace CGoGN } // namespace CGoGN
...@@ -25,10 +25,8 @@ ...@@ -25,10 +25,8 @@
#ifndef __TRAVERSOR_DOO_H__ #ifndef __TRAVERSOR_DOO_H__
#define __TRAVERSOR_DOO_H__ #define __TRAVERSOR_DOO_H__
#include "Topology/generic/traversorGen.h"
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/traversorGen.h"
namespace CGoGN namespace CGoGN
{ {
......
...@@ -25,11 +25,9 @@ ...@@ -25,11 +25,9 @@
#include "Topology/generic/genericmap.h" #include "Topology/generic/genericmap.h"
#include "Topology/generic/functor.h" #include "Topology/generic/functor.h"
namespace CGoGN namespace CGoGN
{ {
template <typename MAP, unsigned int ORBIT> template <typename MAP, unsigned int ORBIT>
TraversorDartsOfOrbit<MAP, ORBIT>::TraversorDartsOfOrbit(MAP& map, Dart d, unsigned int thread) TraversorDartsOfOrbit<MAP, ORBIT>::TraversorDartsOfOrbit(MAP& map, Dart d, unsigned int thread)
{ {
......
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
*******************************************************************************/ *******************************************************************************/
#ifndef __TRAVERSORFACTORY_H__ #ifndef __TRAVERSORFACTORY_H__
#define __TRAVERSORGEN_H__ #define __TRAVERSORFACTORY_H__
#include "Topology/generic/traversorGen.h"
namespace CGoGN namespace CGoGN
{ {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
* Contact information: cgogn@unistra.fr * * Contact information: cgogn@unistra.fr *
* * * *
*******************************************************************************/ *******************************************************************************/
#include "Topology/generic/traversor1.h" #include "Topology/generic/traversor1.h"
#include "Topology/generic/traversor2.h" #include "Topology/generic/traversor2.h"
#include "Topology/generic/traversor3.h" #include "Topology/generic/traversor3.h"
...@@ -33,7 +34,6 @@ namespace CGoGN ...@@ -33,7 +34,6 @@ namespace CGoGN
template<typename MAP> template<typename MAP>
Traversor<MAP>* TraversorFactory<MAP>::createIncident(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY) Traversor<MAP>* TraversorFactory<MAP>::createIncident(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY)
{ {
int code = 0x100*dim + 0x10*(orbX-VERTEX) + orbY-VERTEX; int code = 0x100*dim + 0x10*(orbX-VERTEX) + orbY-VERTEX;
switch(code) switch(code)
...@@ -78,7 +78,6 @@ Traversor<MAP>* TraversorFactory<MAP>::createIncident(MAP& map, Dart dart, unsig ...@@ -78,7 +78,6 @@ Traversor<MAP>* TraversorFactory<MAP>::createIncident(MAP& map, Dart dart, unsig
return new Traversor3XY<MAP, VOLUME, FACE>(map,dart); return new Traversor3XY<MAP, VOLUME, FACE>(map,dart);
break; break;
case 0x201: case 0x201:
return new Traversor2VE<MAP>(map,dart); return new Traversor2VE<MAP>(map,dart);
break; break;
...@@ -112,12 +111,9 @@ Traversor<MAP>* TraversorFactory<MAP>::createIncident(MAP& map, Dart dart, unsig ...@@ -112,12 +111,9 @@ Traversor<MAP>* TraversorFactory<MAP>::createIncident(MAP& map, Dart dart, unsig
return NULL; return NULL;
} }
template<typename MAP> template<typename MAP>
Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY) Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY)
{ {
int code = 0x100*dim + 0x10*(orbX-VERTEX) + orbY-VERTEX; int code = 0x100*dim + 0x10*(orbX-VERTEX) + orbY-VERTEX;
switch(code) switch(code)
...@@ -162,7 +158,6 @@ Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsig ...@@ -162,7 +158,6 @@ Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsig
return new Traversor3XXaY<MAP, VOLUME, FACE>(map,dart); return new Traversor3XXaY<MAP, VOLUME, FACE>(map,dart);
break; break;
case 0x201: case 0x201:
return new Traversor2VVaE<MAP>(map,dart); return new Traversor2VVaE<MAP>(map,dart);
break; break;
...@@ -182,7 +177,6 @@ Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsig ...@@ -182,7 +177,6 @@ Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsig
return new Traversor2FFaE<MAP>(map,dart); return new Traversor2FFaE<MAP>(map,dart);
break; break;
case 0x101: case 0x101:
return new Traversor1VVaE<MAP>(map,dart); return new Traversor1VVaE<MAP>(map,dart);
break; break;
...@@ -197,45 +191,44 @@ Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsig ...@@ -197,45 +191,44 @@ Traversor<MAP>* TraversorFactory<MAP>::createAdjacent(MAP& map, Dart dart, unsig
return NULL; return NULL;
} }
template<typename MAP> template<typename MAP>
Traversor<MAP>* TraversorFactory<MAP>::createCell(MAP& map, unsigned int orb, const FunctorSelect& good, bool forceDartMarker, unsigned int thread) Traversor<MAP>* TraversorFactory<MAP>::createCell(MAP& map, unsigned int orb, const FunctorSelect& good, bool forceDartMarker, unsigned int thread)
{ {
switch(orb) switch(orb)
{ {
case VERTEX: case VERTEX:
return new TraversorCell<MAP,VERTEX>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,VERTEX>(map,good,forceDartMarker,thread);
break; break;
case EDGE: case EDGE:
return new TraversorCell<MAP,EDGE>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,EDGE>(map,good,forceDartMarker,thread);
break; break;
case FACE: case FACE:
return new TraversorCell<MAP,FACE>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,FACE>(map,good,forceDartMarker,thread);
break; break;
case VOLUME: case VOLUME:
return new TraversorCell<MAP,VOLUME>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,VOLUME>(map,good,forceDartMarker,thread);
break; break;
case CC: case CC:
return new TraversorCell<MAP,CC>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,CC>(map,good,forceDartMarker,thread);
break; break;
case VERTEX1: case VERTEX1:
return new TraversorCell<MAP,VERTEX1>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,VERTEX1>(map,good,forceDartMarker,thread);
break; break;
case EDGE1: case EDGE1:
return new TraversorCell<MAP,EDGE1>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,EDGE1>(map,good,forceDartMarker,thread);
break; break;
case VERTEX2: case VERTEX2:
return new TraversorCell<MAP,VERTEX2>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,VERTEX2>(map,good,forceDartMarker,thread);
break; break;
case EDGE2: case EDGE2:
return new TraversorCell<MAP,EDGE2>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,EDGE2>(map,good,forceDartMarker,thread);
break; break;
case FACE2: case FACE2:
return new TraversorCell<MAP,FACE2>(map,good,forceDartMarker,thread); return new TraversorCell<MAP,FACE2>(map,good,forceDartMarker,thread);
break; break;
default: default:
return NULL; return NULL;
break; break;
} }
} }
...@@ -244,43 +237,40 @@ Traversor<MAP>* TraversorFactory<MAP>::createDartsOfOrbits(MAP& map, Dart dart, ...@@ -244,43 +237,40 @@ Traversor<MAP>* TraversorFactory<MAP>::createDartsOfOrbits(MAP& map, Dart dart,
{ {
switch(orb) switch(orb)
{ {
case VERTEX: case VERTEX:
return new TraversorDartsOfOrbit<MAP,VERTEX>(map,dart); return new TraversorDartsOfOrbit<MAP,VERTEX>(map,dart);
break; break;
case EDGE: case EDGE:
return new TraversorDartsOfOrbit<MAP,EDGE>(map,dart); return new TraversorDartsOfOrbit<MAP,EDGE>(map,dart);
break; break;
case FACE: case FACE:
return new TraversorDartsOfOrbit<MAP,FACE>(map,dart); return new TraversorDartsOfOrbit<MAP,FACE>(map,dart);
break; break;
case VOLUME: case VOLUME:
return new TraversorDartsOfOrbit<MAP,VOLUME>(map,dart); return new TraversorDartsOfOrbit<MAP,VOLUME>(map,dart);
break; break;
case CC: case CC:
return new TraversorDartsOfOrbit<MAP,CC>(map,dart); return new TraversorDartsOfOrbit<MAP,CC>(map,dart);
break; break;
case VERTEX1: case VERTEX1:
return new TraversorDartsOfOrbit<MAP,VERTEX1>(map,dart); return new TraversorDartsOfOrbit<MAP,VERTEX1>(map,dart);
break; break;
case EDGE1: case EDGE1:
return new TraversorDartsOfOrbit<MAP,EDGE1>(map,dart); return new TraversorDartsOfOrbit<MAP,EDGE1>(map,dart);
break; break;
case VERTEX2: case VERTEX2:
return new TraversorDartsOfOrbit<MAP,VERTEX2>(map,dart); return new TraversorDartsOfOrbit<MAP,VERTEX2>(map,dart);
break; break;
case EDGE2: case EDGE2:
return new TraversorDartsOfOrbit<MAP,EDGE2>(map,dart); return new TraversorDartsOfOrbit<MAP,EDGE2>(map,dart);
break; break;
case FACE2: case FACE2:
return new TraversorDartsOfOrbit<MAP,FACE2>(map,dart); return new TraversorDartsOfOrbit<MAP,FACE2>(map,dart);
break; break;
default: default:
return NULL; return NULL;
break; break;
} }
} }
} }
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define __TRAVERSORGEN_H__ #define __TRAVERSORGEN_H__
#include "Topology/generic/dart.h" #include "Topology/generic/dart.h"
#include "Topology/generic/functor.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -39,6 +40,17 @@ public: ...@@ -39,6 +40,17 @@ public:
virtual Dart end() = 0; virtual Dart end() = 0;
virtual Dart next() = 0; virtual Dart next() = 0;
bool applyFunctor(FunctorType& f, const FunctorSelect& good = allDarts)
{
for (Dart d = begin(); d != end(); d = next())
{
if (good(d))
if (f(d))
return true;
}
return false;
}
/** /**
* Factory of incident traversors creation * Factory of incident traversors creation
* @param map the map in which we work * @param map the map in which we work
...@@ -48,7 +60,7 @@ public: ...@@ -48,7 +60,7 @@ public:
* @param orbY incident to cell * @param orbY incident to cell
* @return a ptr on Generic Traversor * @return a ptr on Generic Traversor
*/ */
static Traversor<MAP>* createIncident(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY); // static Traversor<MAP>* createIncident(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY);
/** /**
* Factory of adjacent traversors creation * Factory of adjacent traversors creation
...@@ -59,7 +71,7 @@ public: ...@@ -59,7 +71,7 @@ public:
* @param orbY incident to cell * @param orbY incident to cell
* @return a ptr on Generic Traversor * @return a ptr on Generic Traversor
*/ */
static Traversor<MAP>* createAdjacent(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY); // static Traversor<MAP>* createAdjacent(MAP& map, Dart dart, unsigned int dim, unsigned int orbX, unsigned int orbY);
/** /**
* Factory of darts of orbit traversors creation * Factory of darts of orbit traversors creation
...@@ -68,7 +80,7 @@ public: ...@@ -68,7 +80,7 @@ public:
* @param orb the orbit * @param orb the orbit
* @return a ptr on Generic Traversor * @return a ptr on Generic Traversor
*/ */
static Traversor<MAP>* createDartsOfOrbits(MAP& map, Dart dart, unsigned int orb); // static Traversor<MAP>* createDartsOfOrbits(MAP& map, Dart dart, unsigned int orb);
/** /**