From b0194eba01dc0b3a59ac41ef15549668645f50a4 Mon Sep 17 00:00:00 2001 From: Pierre Kraemer Date: Thu, 30 Jun 2011 16:51:23 +0200 Subject: [PATCH] petite refonte des Marks --- include/Algo/Modelisation/polyhedron.h | 5 +- include/Algo/Modelisation/polyhedron.hpp | 22 ++--- include/Algo/Modelisation/primitives3d.h | 2 +- include/Algo/Modelisation/primitives3d.hpp | 18 ++-- include/Algo/Render/GL1/topo_render.h | 20 +++-- include/Algo/Render/GL1/topo_render.hpp | 12 +-- include/Geometry/intersection.h | 12 +-- include/Topology/generic/cellmarker.h | 97 ++++++++++------------ include/Topology/generic/dart.h | 13 ++- include/Topology/generic/dartmarker.h | 57 +++++++------ include/Topology/generic/genericmap.h | 16 ++-- include/Topology/generic/genericmap.hpp | 40 ++++----- include/Topology/generic/marker.h | 51 +++++------- include/Utils/mark.h | 10 +-- src/Topology/generic/attribmap.cpp | 6 +- src/Topology/generic/genericmap.cpp | 20 ++--- src/Topology/generic/marker.cpp | 19 ----- 17 files changed, 191 insertions(+), 229 deletions(-) diff --git a/include/Algo/Modelisation/polyhedron.h b/include/Algo/Modelisation/polyhedron.h index d44788706..c0e71b845 100644 --- a/include/Algo/Modelisation/polyhedron.h +++ b/include/Algo/Modelisation/polyhedron.h @@ -42,8 +42,7 @@ namespace Algo namespace Modelisation { -enum {NONE,GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED}; - +enum { NONE,GRID, CUBE, CYLINDER, CONE, SPHERE, TORE, COMPOSED }; /** * sudivide the all quads of primtive into 2 triangles @@ -326,7 +325,7 @@ public: * mark all embedded vertices of the Polyhedron * @param m the marker to use */ - void markEmbVertices(Marker m); +// void markEmbVertices(Mark m); /** * test if a vertex is in the Polyhedron diff --git a/include/Algo/Modelisation/polyhedron.hpp b/include/Algo/Modelisation/polyhedron.hpp index dd0e3ba07..0391f742e 100644 --- a/include/Algo/Modelisation/polyhedron.hpp +++ b/include/Algo/Modelisation/polyhedron.hpp @@ -974,21 +974,21 @@ void Polyhedron::transform(const Geom::Matrix44f& matrice) template void Polyhedron::mark(CellMarker& m) { - for(typename std::vector::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di) + for(typename std::vector::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di) { m.mark(*di); } } -template -void Polyhedron::markEmbVertices(Marker m) -{ - AttributeHandler markers(VERTEX<<24,m_map); - for(typename std::vector::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di) - { - markers[*di].setMark(m); - } -} +//template +//void Polyhedron::markEmbVertices(Mark m) +//{ +// AttributeHandler markers(VERTEX << 24, m_map); +// for(typename std::vector::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di) +// { +// markers[*di].setMark(m); +// } +//} @@ -1018,7 +1018,7 @@ void Polyhedron::embedTwistedStrip( float radius_min, float radius_max, fl } template -void Polyhedron::embedHelicoid( float radius_min, float radius_max, float maxHeight, float nbTurn, int orient) +void Polyhedron::embedHelicoid(float radius_min, float radius_max, float maxHeight, float nbTurn, int orient) { typedef typename PFP::VEC3 VEC3 ; diff --git a/include/Algo/Modelisation/primitives3d.h b/include/Algo/Modelisation/primitives3d.h index c9209e5d8..c83844b82 100644 --- a/include/Algo/Modelisation/primitives3d.h +++ b/include/Algo/Modelisation/primitives3d.h @@ -141,7 +141,7 @@ public: * mark all darts of the primitive * @param m the marker to use */ - void mark(Marker m); +// void mark(Mark m); /** diff --git a/include/Algo/Modelisation/primitives3d.hpp b/include/Algo/Modelisation/primitives3d.hpp index b2367d732..bf6176176 100644 --- a/include/Algo/Modelisation/primitives3d.hpp +++ b/include/Algo/Modelisation/primitives3d.hpp @@ -218,7 +218,7 @@ void Primitive3D::embedHexaGrid( float x, float y, float z) template void Primitive3D::transform(const Geom::Matrix44f& matrice) { - for(typename std::vector::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di) + for(typename std::vector::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di) { typename PFP::VEC3& pos = m_positions[*di]; pos = Geom::transform(pos, matrice); @@ -226,14 +226,14 @@ void Primitive3D::transform(const Geom::Matrix44f& matrice) } -template -void Primitive3D::mark(Marker m) -{ - for(typename std::vector::iterator di=m_tableVertDarts.begin(); di!=m_tableVertDarts.end(); ++di) - { - m_map.markOrbit(0,*di,m); - } -} +//template +//void Primitive3D::mark(Mark m) +//{ +// for(typename std::vector::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di) +// { +// m_map.markOrbit(0, *di, m); +// } +//} }//end namespace }//end namespace diff --git a/include/Algo/Render/GL1/topo_render.h b/include/Algo/Render/GL1/topo_render.h index c8b3f8ed0..b90debb39 100644 --- a/include/Algo/Render/GL1/topo_render.h +++ b/include/Algo/Render/GL1/topo_render.h @@ -46,11 +46,11 @@ namespace Render namespace GL1 { -/** -* Render darts of generalized map -*/ -template -void renderTopoGM2(typename PFP::MAP& the_map, Marker m); +///** +//* Render darts of generalized map +//*/ +//template +//void renderTopoGM2(typename PFP::MAP& the_map, Mark m); /** * Render darts of dual map @@ -83,11 +83,13 @@ void renderTopoMD3(typename PFP::MAP& the_map, const typename PFP::TVEC3& positi template void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool drawPhi1, bool drawPhi2, bool drawPhi3, float ke, float kf, float kv); +} // namespace GL1 + +} // namespace Render + +} // namespace Algo -}// end namespace -}// end namespace -}// end namespace -}// end namespace +} // namespace CGoGN #include "Algo/Render/GL1/topo_render.hpp" diff --git a/include/Algo/Render/GL1/topo_render.hpp b/include/Algo/Render/GL1/topo_render.hpp index 888d3f0ac..8811fdd72 100644 --- a/include/Algo/Render/GL1/topo_render.hpp +++ b/include/Algo/Render/GL1/topo_render.hpp @@ -121,7 +121,7 @@ namespace GL1 //}; // //template -//void renderTopoGM2(typename PFP::MAP& map, Marker m) +//void renderTopoGM2(typename PFP::MAP& map, Mark m) //{ // // @@ -642,9 +642,11 @@ void renderTopoMD3(typename PFP::MAP& map, typename PFP::TVEC3& positions, bool } +} // namespace GL1 -} // endnamespace -} // endnamespace -} // endnamespace -} // endnamespace +} // namespace Render + +} // namespace Algo + +} // namespace CGoGN diff --git a/include/Geometry/intersection.h b/include/Geometry/intersection.h index cdd494d09..0ce4dee3a 100644 --- a/include/Geometry/intersection.h +++ b/include/Geometry/intersection.h @@ -47,7 +47,7 @@ enum Intersection * test the intersection between a ray and a triangle */ template -Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; +Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; /** * test the intersection between a line and a triangle @@ -60,7 +60,7 @@ Intersection intersectionRayTriangle(const VEC3& P, const VEC3& Dir, const VEC3& * @return the intersection */ template -Intersection intersectionLineTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; +Intersection intersectionLineTriangle(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; /** * test the intersection between a line and a triangle the line MUST be in the plane of the triangle, assumed to be CCW @@ -74,7 +74,7 @@ Intersection intersectionLineTriangle(const VEC3& P, const VEC3& Dir, const VEC3 * @return the intersection */ template -Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; +Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; /** * test the intersection between a segment and a triangle @@ -87,13 +87,13 @@ Intersection intersectionLineTriangle2D(const VEC3& P, const VEC3& Dir, const VE * @return the intersection */ template -Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; +Intersection intersectionSegmentTriangle(const VEC3& PA, const VEC3& PB, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc, VEC3& Inter) ; template -Intersection intersectionPlaneRay(const PLANE3D& pl,const VEC3& p1,const VEC3& dir, VEC3& Inter); +Intersection intersectionPlaneRay(const PLANE3D& pl,const VEC3& p1,const VEC3& dir, VEC3& Inter) ; template -Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const VEC3& QA, const VEC3& QB, VEC3& Inter) ; +Intersection intersection2DSegmentSegment(const VEC3& PA, const VEC3& PB, const VEC3& QA, const VEC3& QB, VEC3& Inter) ; } // namespace Geom diff --git a/include/Topology/generic/cellmarker.h b/include/Topology/generic/cellmarker.h index ffd700e5e..3ded95cc4 100644 --- a/include/Topology/generic/cellmarker.h +++ b/include/Topology/generic/cellmarker.h @@ -40,8 +40,9 @@ namespace CGoGN class CellMarkerGen { protected: - Marker m_marker; + Mark m_mark; AttribMap& m_map; + unsigned int m_cell; unsigned int m_thread; public: @@ -49,23 +50,17 @@ public: * constructor * @param map the map on which we work (not stored use to get table of markers and new marker. * @param cell the type of cell we want to mark VERTEX, EDGE,... - * \pre the cell is embedded in the map */ - CellMarkerGen(AttribMap& map, unsigned int cell) : m_map(map), m_thread(0) + CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread) { if(!map.isOrbitEmbedded(cell)) map.addEmbedding(cell) ; - m_marker = map.getNewMarker(cell); - } - - CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread) : m_map(map), m_thread(thread) - { - m_marker = map.getNewMarker(cell, thread); + m_mark = map.getNewMark(cell, thread); } virtual ~CellMarkerGen() { - m_map.releaseMarker(m_marker, m_thread); + m_map.releaseMark(m_mark, m_cell, m_thread); } protected: @@ -79,12 +74,11 @@ public: */ virtual void mark(Dart d) { - unsigned int cell = m_marker.getCell() ; - unsigned int a = m_map.getEmbedding(cell, d); + unsigned int a = m_map.getEmbedding(m_cell, d); if (a == EMBNULL) - a = m_map.embedNewCell(cell, d); + a = m_map.embedNewCell(m_cell, d); - m_map.getMarkerVector(cell, m_thread)->operator[](a).setMark(m_marker); + m_map.getMarkVector(m_cell, m_thread)->operator[](a).setMark(m_mark); } /** @@ -92,12 +86,11 @@ public: */ virtual void unmark(Dart d) { - unsigned int cell = m_marker.getCell() ; - unsigned int a = m_map.getEmbedding(cell, d); + unsigned int a = m_map.getEmbedding(m_cell, d); if (a == EMBNULL) - a = m_map.embedNewCell(cell, d); + a = m_map.embedNewCell(m_cell, d); - m_map.getMarkerVector(cell, m_thread)->operator[](a).unsetMark(m_marker); + m_map.getMarkVector(m_cell, m_thread)->operator[](a).unsetMark(m_mark); } /** @@ -105,12 +98,11 @@ public: */ virtual bool isMarked(Dart d) { - unsigned int cell = m_marker.getCell() ; - unsigned int a = m_map.getEmbedding(cell, d); + unsigned int a = m_map.getEmbedding(m_cell, d); if (a == EMBNULL) return false; - return m_map.getMarkerVector(cell, m_thread)->operator[](a).testMark(m_marker); + return m_map.getMarkVector(m_cell, m_thread)->operator[](a).testMark(m_mark); } /** @@ -118,7 +110,7 @@ public: */ virtual void mark(unsigned int em) { - m_map.getMarkerVector(m_marker.getCell(), m_thread)->operator[](em).setMark(m_marker); + m_map.getMarkVector(m_cell, m_thread)->operator[](em).setMark(m_mark); } /** @@ -126,7 +118,7 @@ public: */ virtual void unmark(unsigned int em) { - m_map.getMarkerVector(m_marker.getCell(), m_thread)->operator[](em).unsetMark(m_marker); + m_map.getMarkVector(m_cell, m_thread)->operator[](em).unsetMark(m_mark); } /** @@ -134,7 +126,7 @@ public: */ virtual bool isMarked(unsigned int em) { - return m_map.getMarkerVector(m_marker.getCell(), m_thread)->operator[](em).testMark(m_marker); + return m_map.getMarkVector(m_cell, m_thread)->operator[](em).testMark(m_mark); } /** @@ -142,10 +134,9 @@ public: */ virtual void markAll() { - unsigned int cell = m_marker.getCell() ; - AttributeContainer& cont = m_map.getAttributeContainer(cell) ; + AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - m_map.getMarkerVector(cell,m_thread)->operator[](i).setMark(m_marker); + m_map.getMarkVector(m_cell, m_thread)->operator[](i).setMark(m_mark); } /** @@ -161,10 +152,7 @@ public: class CellMarker : public CellMarkerGen { public: - CellMarker(AttribMap& map, unsigned int cell) : CellMarkerGen(map, cell) - {} - - CellMarker(AttribMap& map, unsigned int cell, unsigned int thread) : CellMarkerGen(map, cell, thread) + CellMarker(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) {} virtual ~CellMarker() @@ -179,10 +167,9 @@ protected: public: virtual void unmarkAll() { - unsigned int cell = m_marker.getCell() ; - AttributeContainer& cont = m_map.getAttributeContainer(cell) ; + AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - m_map.getMarkerVector(cell, m_thread)->operator[](i).unsetMark(m_marker) ; + m_map.getMarkVector(m_cell, m_thread)->operator[](i).unsetMark(m_mark) ; } }; @@ -197,13 +184,10 @@ protected: std::vector m_markedCells ; public: - CellMarkerStore(AttribMap& map, unsigned int cell) : CellMarkerGen(map, cell) + CellMarkerStore(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) {} - CellMarkerStore(AttribMap& map, unsigned int cell, unsigned int thread) : CellMarkerGen(map, cell, thread) - {} - - ~CellMarkerStore() + virtual ~CellMarkerStore() { unmarkAll() ; } @@ -216,7 +200,7 @@ public: void mark(Dart d) { CellMarkerGen::mark(d) ; - m_markedCells.push_back(m_map.getEmbedding(m_marker.getCell(), d)) ; + m_markedCells.push_back(m_map.getEmbedding(m_cell, d)) ; } void mark(unsigned int em) @@ -227,9 +211,8 @@ public: void unmarkAll() { - unsigned int cell = m_marker.getCell() ; for (std::vector::iterator it = m_markedCells.begin(); it != m_markedCells.end(); ++it) - m_map.getMarkerVector(cell,m_thread)->operator[](*it).unsetMark(m_marker) ; + m_map.getMarkVector(m_cell, m_thread)->operator[](*it).unsetMark(m_mark) ; } }; @@ -241,27 +224,35 @@ public: class CellMarkerNoUnmark: public CellMarkerGen { public: - CellMarkerNoUnmark(AttribMap& map, unsigned int cell) : CellMarkerGen(map, cell) - {} - - - CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread) : CellMarkerGen(map, cell, thread) - {} + CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread) + { + std::cout << "CellMarkerNoUnmark.." << std::endl ; + } - ~CellMarkerNoUnmark() - {} + virtual ~CellMarkerNoUnmark() + { + assert(isAllUnmarked()); + } protected: CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarkerGen(cm) {} + bool isAllUnmarked() + { + AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ; + for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) + if(m_map.getMarkVector(m_cell, m_thread)->operator[](i).testMark(m_mark)) + return false ; + return true ; + } + public: void unmarkAll() { - unsigned int cell = m_marker.getCell() ; - AttributeContainer& cont = m_map.getAttributeContainer(cell) ; + AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - m_map.getMarkerVector(cell, m_thread)->operator[](i).unsetMark(m_marker) ; + m_map.getMarkVector(m_cell, m_thread)->operator[](i).unsetMark(m_mark) ; } }; diff --git a/include/Topology/generic/dart.h b/include/Topology/generic/dart.h index d0b4740c7..8b493ffc0 100644 --- a/include/Topology/generic/dart.h +++ b/include/Topology/generic/dart.h @@ -35,13 +35,12 @@ const unsigned int EMBNULL = 0xffffffff; const unsigned int NB_ORBITS = 6; const unsigned int NB_THREAD = 16; -const unsigned int VERTEX = 0; -const unsigned int EDGE = 1; -const unsigned int ORIENTED_FACE= 2; -const unsigned int FACE = 3; -const unsigned int VOLUME = 4; -const unsigned int DART = 5; - +const unsigned int VERTEX = 0; +const unsigned int EDGE = 1; +const unsigned int ORIENTED_FACE = 2; +const unsigned int FACE = 3; +const unsigned int VOLUME = 4; +const unsigned int DART = 5; struct Dart { diff --git a/include/Topology/generic/dartmarker.h b/include/Topology/generic/dartmarker.h index fb886b045..5a5a7ac0c 100644 --- a/include/Topology/generic/dartmarker.h +++ b/include/Topology/generic/dartmarker.h @@ -39,21 +39,23 @@ template class FunctorMarker : public FunctorMap { protected: - Marker m_marker ; - AttributeMultiVector* m_markerTable ; + Mark m_mark ; + AttributeMultiVector* m_markTable ; public: - FunctorMarker(MAP& map, Marker m, AttributeMultiVector* mTable) : FunctorMap(map), m_marker(m), m_markerTable(mTable) {} - Marker getMarker() { return m_marker ; } + FunctorMarker(MAP& map, Mark m, AttributeMultiVector* mTable) : FunctorMap(map), m_mark(m), m_markTable(mTable) + {} +// Mark getMark() { return m_mark ; } } ; template class FunctorMark : public FunctorMarker { public: - FunctorMark(MAP& map, Marker m, AttributeMultiVector* mTable) : FunctorMarker(map, m, mTable) {} + FunctorMark(MAP& map, Mark m, AttributeMultiVector* mTable) : FunctorMarker(map, m, mTable) + {} bool operator()(Dart d) { - this->m_markerTable->operator[](d.index).setMark(this->m_marker) ; + this->m_markTable->operator[](d.index).setMark(this->m_mark) ; return false ; } } ; @@ -64,13 +66,13 @@ class FunctorMarkStore : public FunctorMarker protected: std::vector& m_markedDarts ; public: - FunctorMarkStore(MAP& map, Marker m, AttributeMultiVector* mTable, std::vector& marked) : + FunctorMarkStore(MAP& map, Mark m, AttributeMultiVector* mTable, std::vector& marked) : FunctorMarker(map, m, mTable), m_markedDarts(marked) {} bool operator()(Dart d) { - this->m_markerTable->operator[](d.index).setMark(this->m_marker) ; + this->m_markTable->operator[](d.index).setMark(this->m_mark) ; m_markedDarts.push_back(d.index) ; return false ; } @@ -80,10 +82,11 @@ template class FunctorUnmark : public FunctorMarker { public: - FunctorUnmark(MAP& map, Marker m, AttributeMultiVector* mTable) : FunctorMarker(map, m, mTable) {} + FunctorUnmark(MAP& map, Mark m, AttributeMultiVector* mTable) : FunctorMarker(map, m, mTable) + {} bool operator()(Dart d) { - this->m_markerTable->operator[](d.index).unsetMark(this->m_marker) ; + this->m_markTable->operator[](d.index).unsetMark(this->m_mark) ; return false ; } } ; @@ -95,7 +98,7 @@ public: class DartMarkerGen { protected: - Marker m_marker; + Mark m_mark; GenericMap& m_map; unsigned int m_thread; @@ -106,17 +109,17 @@ public: */ DartMarkerGen(GenericMap& map): m_map(map), m_thread(0) { - m_marker = map.getNewMarker(DART); + m_mark = map.getNewMark(DART); } DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread) { - m_marker = map.getNewMarker(DART, thread); + m_mark = map.getNewMark(DART, thread); } virtual ~DartMarkerGen() { - m_map.releaseMarker(m_marker, m_thread); + m_map.releaseMark(m_mark, DART, m_thread); } protected: @@ -130,7 +133,7 @@ public: */ virtual void mark(Dart d) { - m_map.getMarkerVector(DART, m_thread)->operator[](d.index).setMark(m_marker); + m_map.getMarkVector(DART, m_thread)->operator[](d.index).setMark(m_mark); } /** @@ -138,7 +141,7 @@ public: */ virtual void unmark(Dart d) { - m_map.getMarkerVector(DART, m_thread)->operator[](d.index).unsetMark(m_marker); + m_map.getMarkVector(DART, m_thread)->operator[](d.index).unsetMark(m_mark); } /** @@ -146,7 +149,7 @@ public: */ virtual bool isMarked(Dart d) { - return m_map.getMarkerVector(DART, m_thread)->operator[](d.index).testMark(m_marker); + return m_map.getMarkVector(DART, m_thread)->operator[](d.index).testMark(m_mark); } /** @@ -154,7 +157,7 @@ public: */ virtual void markOrbit(unsigned int orbit, Dart d) { - FunctorMark fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ; + FunctorMark fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ; m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ; } @@ -163,7 +166,7 @@ public: */ virtual void unmarkOrbit(unsigned int orbit, Dart d) { - FunctorUnmark fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ; + FunctorUnmark fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ; m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ; } @@ -173,7 +176,7 @@ public: template void markOrbitInParent(unsigned int orbit, Dart d) { - FunctorMark fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ; + FunctorMark fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ; foreach_dart_of_orbit_in_parent(dynamic_cast(&m_map), orbit, d, fm, m_thread); } @@ -183,7 +186,7 @@ public: template void unmarkOrbitInParent(unsigned int orbit, Dart d) { - FunctorUnmark fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ; + FunctorUnmark fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ; foreach_dart_of_orbit_in_parent(dynamic_cast(&m_map), orbit, d, fm, m_thread); } @@ -194,7 +197,7 @@ public: { AttributeContainer& cont = m_map.getAttributeContainer(DART) ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - m_map.getMarkerVector(DART, m_thread)->operator[](i).setMark(m_marker); + m_map.getMarkVector(DART, m_thread)->operator[](i).setMark(m_mark); } /** @@ -230,7 +233,7 @@ public: { AttributeContainer& cont = m_map.getAttributeContainer(DART) ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - m_map.getMarkerVector(DART, m_thread)->operator[](i).unsetMark(m_marker); + m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark); } }; @@ -269,14 +272,14 @@ public: void markOrbit(unsigned int orbit, Dart d) { - FunctorMarkStore fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread), m_markedDarts) ; + FunctorMarkStore fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ; m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ; } template void markOrbitInParent(unsigned int orbit, Dart d) { - FunctorMarkStore fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread), m_markedDarts) ; + FunctorMarkStore fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ; foreach_dart_of_orbit_in_parent(dynamic_cast(&m_map), orbit, d, fm, m_thread); } @@ -289,7 +292,7 @@ public: void unmarkAll() { for (std::vector::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it) - m_map.getMarkerVector(DART, m_thread)->operator[](*it).unsetMark(m_marker) ; + m_map.getMarkVector(DART, m_thread)->operator[](*it).unsetMark(m_mark) ; } }; @@ -319,7 +322,7 @@ public: { AttributeContainer& cont = m_map.getAttributeContainer(DART) ; for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - m_map.getMarkerVector(DART, m_thread)->operator[](i).unsetMark(m_marker) ; + m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark) ; } }; diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 867319ce4..b92357ece 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -92,14 +92,14 @@ protected: AttributeMultiVector* m_embeddings[NB_ORBITS] ; /** - * Markers manager + * Marks manager */ - MarkerSet m_orbMarker[NB_ORBITS][NB_THREAD] ; + MarkSet m_marksets[NB_ORBITS][NB_THREAD] ; /** * Direct access to the attributes that store Marks */ - AttributeMultiVector* m_markerTables[NB_ORBITS][NB_THREAD]; + AttributeMultiVector* m_markTables[NB_ORBITS][NB_THREAD]; unsigned int m_nbThreads; @@ -233,10 +233,10 @@ public: AttributeContainer& getAttributeContainer(unsigned int orbit); /** - * get a multi vector of marker attribute (direct access with [i]) + * get a multi vector of mark attribute (direct access with [i]) * @param orbit code */ - AttributeMultiVector* getMarkerVector(unsigned int orbit, unsigned int thread = 0); + AttributeMultiVector* getMarkVector(unsigned int orbit, unsigned int thread = 0); /** * return a pointer to the Dart attribute vector that store the embedding of the given orbit @@ -271,13 +271,13 @@ protected: * @param orbit the orbit of cell to use (xxx_ORBIT) * @return the marker to use */ - Marker getNewMarker(unsigned int cell = DART, unsigned int thread = 0); + Mark getNewMark(unsigned int cell, unsigned int thread = 0); /** * release a marker of cell. * @param m the marker to release */ - void releaseMarker(Marker m, unsigned int thread = 0); + void releaseMark(Mark m, unsigned int cell, unsigned int thread = 0); /**************************************** * THREAD MANAGEMENT * @@ -297,7 +297,7 @@ public: unsigned int getNbThreadMarkers(); /** - * Remove some added threads + * Remove some added threads * @return remaining number of threads (including principal) */ void removeThreadMarker(unsigned int nb); diff --git a/include/Topology/generic/genericmap.hpp b/include/Topology/generic/genericmap.hpp index fdac8334f..2c29f834a 100644 --- a/include/Topology/generic/genericmap.hpp +++ b/include/Topology/generic/genericmap.hpp @@ -47,7 +47,7 @@ inline void GenericMap::deleteDart(Dart d) { m_attribs[DART].removeLine(d.index) ; for (unsigned int t = 0; t < m_nbThreads; ++t) - m_markerTables[DART][t]->operator[](d.index).clear() ; + m_markTables[DART][t]->operator[](d.index).clear() ; for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) { @@ -59,7 +59,7 @@ inline void GenericMap::deleteDart(Dart d) if(m_attribs[orbit].unrefLine(emb)) { for (unsigned int t = 0; t < m_nbThreads; ++t) - m_markerTables[orbit][t]->operator[](emb).clear() ; + m_markTables[orbit][t]->operator[](emb).clear() ; } } } @@ -104,16 +104,6 @@ inline unsigned int GenericMap::getEmbedding(unsigned int orbit, Dart d) return (*m_embeddings[orbit])[d.index] ; } -//inline unsigned int GenericMap::getDartEmbedding(unsigned int orbit, Dart d) -//{ -// assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded"); -// -// if (orbit == DART) -// return d.index; -// -// return (*m_embeddings[orbit])[d.index] ; -//} - inline void GenericMap::copyDartEmbedding(unsigned int orbit, Dart d, Dart e) { assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded"); @@ -175,10 +165,10 @@ inline AttributeContainer& GenericMap::getAttributeContainer(unsigned int orbit) return m_attribs[orbit] ; } -inline AttributeMultiVector* GenericMap::getMarkerVector(unsigned int orbit, unsigned int thread) +inline AttributeMultiVector* GenericMap::getMarkVector(unsigned int orbit, unsigned int thread) { assert(isOrbitEmbedded(orbit) || !"Invalid parameter: orbit not embedded") ; - return m_markerTables[orbit][thread] ; + return m_markTables[orbit][thread] ; } inline AttributeMultiVector* GenericMap::getEmbeddingAttributeVector(unsigned int orbit) @@ -199,13 +189,13 @@ inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned in for(unsigned int t = 0; t < m_nbThreads; ++t) { - AttributeMultiVector* m = m_markerTables[orbit1][t] ; - m_markerTables[orbit1][t] = m_markerTables[orbit2][t] ; - m_markerTables[orbit2][t] = m ; + AttributeMultiVector* m = m_markTables[orbit1][t] ; + m_markTables[orbit1][t] = m_markTables[orbit2][t] ; + m_markTables[orbit2][t] = m ; - MarkerSet ms = m_orbMarker[orbit1][t] ; - m_orbMarker[orbit1][t] = m_orbMarker[orbit2][t] ; - m_orbMarker[orbit2][t] = ms ; + MarkSet ms = m_marksets[orbit1][t] ; + m_marksets[orbit1][t] = m_marksets[orbit2][t] ; + m_marksets[orbit2][t] = ms ; } } @@ -213,16 +203,16 @@ inline void GenericMap::swapEmbeddingContainers(unsigned int orbit1, unsigned in * MARKERS MANAGEMENT * ****************************************/ -inline Marker GenericMap::getNewMarker(unsigned int cell, unsigned int thread) +inline Mark GenericMap::getNewMark(unsigned int cell, unsigned int thread) { - return m_orbMarker[cell][thread].getNewMarker(cell) ; + assert(isOrbitEmbedded(cell) || !"Try to get a marker on non embedded cell! ") ; + return m_marksets[cell][thread].getNewMark() ; } -inline void GenericMap::releaseMarker(Marker m, unsigned int thread) +inline void GenericMap::releaseMark(Mark m, unsigned int cell, unsigned int thread) { - unsigned int cell = m.getCell(); assert(isOrbitEmbedded(cell) || !"Try to release a marker on non embedded cell! ") ; - m_orbMarker[cell][thread].releaseMarker(m) ; + m_marksets[cell][thread].releaseMark(m) ; } /**************************************** diff --git a/include/Topology/generic/marker.h b/include/Topology/generic/marker.h index 06b4cc012..645b98bd4 100644 --- a/include/Topology/generic/marker.h +++ b/include/Topology/generic/marker.h @@ -26,46 +26,39 @@ #define _MARKER_H_ #include "Utils/mark.h" -#include "Topology/generic/dart.h" namespace CGoGN { -class Marker: public Mark -{ -protected: - unsigned int m_cell; - -public: - Marker(Mark m, unsigned int cell): Mark(m), m_cell(cell) {} -//#ifndef DART -//#define DART (unsigned int)(5) -//#endif - Marker(): Mark(0), m_cell(DART) {} // TODO trouver un moyen propre de faire ça - - Marker operator+(const Marker m) const - { - Marker n(*this); - n.setMark(m); - return n; - } - - unsigned int getCell() const { return m_cell; } -}; - - //! Class that manages the locking (lock and release) of markers -class MarkerSet : public Mark +class MarkSet : public Mark { public: //! Constructor - MarkerSet() : Mark() {}; - + MarkSet() : Mark() + {} + //! Get a free marker and lock it - Marker getNewMarker(unsigned int cell); + Mark getNewMark() + { + Mark m; + m.m_bits = 1; + for (unsigned int i = 0; i < getNbMarks(); ++i) + { + if (!testMark(m)) + { + setMark(m); + return m; + } + m.m_bits <<= 1; + } + assert(!"No more markers"); + m.m_bits = 0; + return m; + } //! Release a locked marker - void releaseMarker(Marker m) + void releaseMark(Mark m) { unsetMark(m); } diff --git a/include/Utils/mark.h b/include/Utils/mark.h index aebe0d783..96e88781d 100644 --- a/include/Utils/mark.h +++ b/include/Utils/mark.h @@ -41,7 +41,7 @@ namespace CGoGN */ class Mark { - friend class MarkerSet; + friend class MarkSet; typedef unsigned int value_type; value_type m_bits; @@ -51,15 +51,15 @@ public: static unsigned getNbMarks() { return 8 * sizeof(Mark); - }; + } //! Constructor - Mark() : m_bits(0) {}; + Mark() : m_bits(0) {} - Mark(unsigned int a) : m_bits(a) {}; + Mark(unsigned int a) : m_bits(a) {} //! Copy constructor - Mark(const Mark& m) : m_bits(m.m_bits) {}; + Mark(const Mark& m) : m_bits(m.m_bits) {} static std::string CGoGNnameOfType() { return "Mark"; } diff --git a/src/Topology/generic/attribmap.cpp b/src/Topology/generic/attribmap.cpp index d7e1950df..09047d7ff 100644 --- a/src/Topology/generic/attribmap.cpp +++ b/src/Topology/generic/attribmap.cpp @@ -31,7 +31,7 @@ AttribMap::AttribMap() : GenericMap() { AttributeContainer& dartCont = m_attribs[DART] ; AttributeMultiVector* amv = dartCont.addAttribute("Mark") ; - m_markerTables[DART][0] = amv ; + m_markTables[DART][0] = amv ; } /**************************************** @@ -59,7 +59,9 @@ void AttribMap::addEmbedding(unsigned int orbit) std::stringstream ss ; ss << "Mark_"<< t ; AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; - m_markerTables[orbit][t] = amvMark ; + for(unsigned int i = cellCont.begin(); i < cellCont.end(); cellCont.next(i)) + amvMark->operator[](i).clear() ; + m_markTables[orbit][t] = amvMark ; } } diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index bc9eeb425..84eab978d 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -72,7 +72,7 @@ GenericMap::GenericMap() : m_nbThreads(1) m_attribs[i].setRegistry(m_attributes_registry_map) ; m_embeddings[i] = NULL ; for (unsigned int j = 0; j < NB_THREAD; ++j) - m_markerTables[i][j] = NULL ; + m_markTables[i][j] = NULL ; } } @@ -107,7 +107,7 @@ void GenericMap::setDartEmbedding(unsigned int orbit, Dart d, unsigned int emb) { if(m_attribs[orbit].unrefLine(old)) for (unsigned int t=0; toperator[](old).clear(); + m_markTables[orbit][t]->operator[](old).clear(); } // ref the new emb if (emb != EMBNULL) @@ -172,7 +172,7 @@ void GenericMap::addThreadMarker(unsigned int nb) ss << "Mark_"<< th ; AttributeContainer& cellCont = m_attribs[i] ; AttributeMultiVector* amvMark = cellCont.addAttribute(ss.str()) ; - m_markerTables[i][th] = amvMark ; + m_markTables[i][th] = amvMark ; } } } @@ -198,7 +198,7 @@ void GenericMap::removeThreadMarker(unsigned int nb) ss << "Mark_"<< th ; AttributeContainer& cellCont = m_attribs[i] ; cellCont.removeAttribute(ss.str()) ; - m_markerTables[i][th] = NULL ; + m_markTables[i][th] = NULL ; } } } @@ -255,9 +255,9 @@ bool GenericMap::saveMapXml(const std::string& filename, bool compress) { int rc = xmlTextWriterStartElement(writer, BAD_CAST "MarkerSet"); rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "orbit", "%u", i); - rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "val", "%u", m_orbMarker[i][0].getMarkVal()); -// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "bin", BAD_CAST m_orbMarker[i][0].getMarkerAsBinaryString().c_str()); -// m_orbMarker[i] ; + rc = xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "val", "%u", m_marksets[i][0].getMarkVal()); +// rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "bin", BAD_CAST m_marksets[i][0].getMarkerAsBinaryString().c_str()); +// m_marksets[i] ; rc = xmlTextWriterEndElement(writer); } rc = xmlTextWriterEndElement(writer); @@ -373,7 +373,7 @@ bool GenericMap::loadMapXml(const std::string& filename, bool compress) unsigned int orb = atoi((char*)prop); prop = xmlGetProp(mark_node, BAD_CAST "val"); unsigned int val = atoi((char*)prop); - m_orbMarker[orb][0].setMarkVal(val); + m_marksets[orb][0].setMarkVal(val); } read1 =true; } @@ -441,7 +441,7 @@ bool GenericMap::saveMapBin(const std::string& filename) buffer.reserve(NB_ORBITS+1); for (unsigned int i=0; i(&(buffer[0])), (NB_ORBITS+1)*sizeof(unsigned int)); for (unsigned int i=0; i