diff --git a/include/Algo/Geometry/area.h b/include/Algo/Geometry/area.h index bdf334e1a6237ae17c98c54a5911293805e4f97b..9d171ed53b75e91cb9e67232c94fd9b918fe265f 100644 --- a/include/Algo/Geometry/area.h +++ b/include/Algo/Geometry/area.h @@ -43,7 +43,7 @@ namespace Geometry //! @param position //! @return template -typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; //! \brief Compute convex polygonal face area //! @param map @@ -51,14 +51,14 @@ typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttr //! @param position //! @return template -typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; //! \brief Compute the total area of a mesh by summing all face areas. //! @param map //! @param position //! @return template -typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute& position, unsigned int thread = 0) ; +typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute& position, unsigned int thread = 0) ; //! \brief Compute the area of the faces around a vertex. //! @param map @@ -66,25 +66,25 @@ typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute -typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; template -typename PFP::REAL vertexBarycentricArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +typename PFP::REAL vertexBarycentricArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; template -typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; template -void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_area) ; +void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_area) ; template -void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) ; +void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) ; template -void computeBarycentricAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) ; +void computeBarycentricAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) ; template -void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) ; +void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) ; } // namespace Geometry diff --git a/include/Algo/Geometry/area.hpp b/include/Algo/Geometry/area.hpp index b76693c4332f783f3f131c20946f30d83b444ebe..944737f057c5c86a2855ca067caff757015a7acb 100644 --- a/include/Algo/Geometry/area.hpp +++ b/include/Algo/Geometry/area.hpp @@ -40,7 +40,7 @@ namespace Geometry { template -typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typename PFP::VEC3 p1 = position[d] ; typename PFP::VEC3 p2 = position[map.phi1(d)] ; @@ -50,7 +50,7 @@ typename PFP::REAL triangleArea(typename PFP::MAP& map, Dart d, const VertexAttr } template -typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typedef typename PFP::VEC3 VEC3 ; @@ -72,7 +72,7 @@ typename PFP::REAL convexFaceArea(typename PFP::MAP& map, Dart d, const VertexAt } template -typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute& position, unsigned int thread) +typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute& position, unsigned int thread) { typename PFP::REAL area(0) ; TraversorF t(map) ; @@ -82,7 +82,7 @@ typename PFP::REAL totalArea(typename PFP::MAP& map, const VertexAttribute -typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typename PFP::REAL area(0) ; Traversor2VF t(map, d) ; @@ -92,7 +92,7 @@ typename PFP::REAL vertexOneRingArea(typename PFP::MAP& map, Dart d, const Verte } template -typename PFP::REAL vertexBarycentricArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL vertexBarycentricArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typename PFP::REAL area(0) ; Traversor2VF t(map, d) ; @@ -102,7 +102,7 @@ typename PFP::REAL vertexBarycentricArea(typename PFP::MAP& map, Dart d, const V } template -typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typename PFP::REAL area(0) ; Traversor2VF t(map, d) ; @@ -130,7 +130,7 @@ typename PFP::REAL vertexVoronoiArea(typename PFP::MAP& map, Dart d, const Verte } template -void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_area) +void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_area) { TraversorF t(map) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) @@ -138,7 +138,7 @@ void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute -void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) +void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) { TraversorV t(map) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) @@ -146,7 +146,7 @@ void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute -void computeBarycentricAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) +void computeBarycentricAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) { TraversorV t(map) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) @@ -154,7 +154,7 @@ void computeBarycentricAreaVertices(typename PFP::MAP& map, const VertexAttribut } template -void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) +void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_area) { TraversorV t(map) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) @@ -162,15 +162,17 @@ void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute class FunctorConvexFaceArea: public FunctorMapThreaded { - const VertexAttribute& m_position; - FaceAttribute& m_area; + const VertexAttribute& m_position; + FaceAttribute& m_area; public: - FunctorConvexFaceArea( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area): + FunctorConvexFaceArea( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area): FunctorMapThreaded(map), m_position(position), m_area(area) { } @@ -181,20 +183,19 @@ public: }; template -void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area, unsigned int nbth) +void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area, unsigned int nbth) { FunctorConvexFaceArea funct(map,position,area); Algo::Parallel::foreach_cell(map, funct, nbth, false); } - template class FunctorVertexOneRingArea: public FunctorMapThreaded { - const VertexAttribute& m_position; - VertexAttribute& m_area; + const VertexAttribute& m_position; + VertexAttribute& m_area; public: - FunctorVertexOneRingArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): + FunctorVertexOneRingArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): FunctorMapThreaded(map), m_position(position), m_area(area) { } @@ -205,21 +206,19 @@ public: }; template -void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, unsigned int nbth) +void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, unsigned int nbth) { FunctorConvexFaceArea funct(map,position,area); Algo::Parallel::foreach_cell(map, funct, nbth, false); } - - template class FunctorVertexVoronoiArea: public FunctorMapThreaded { - const VertexAttribute& m_position; - VertexAttribute& m_area; + const VertexAttribute& m_position; + VertexAttribute& m_area; public: - FunctorVertexVoronoiArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): + FunctorVertexVoronoiArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): FunctorMapThreaded(map), m_position(position), m_area(area) { } @@ -230,24 +229,19 @@ public: }; template -void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, unsigned int nbth) +void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, unsigned int nbth) { FunctorConvexFaceArea funct(map,position,area); - Algo::Parallel::foreach_cell(map, funct, nbth, false); + Algo::Parallel::foreach_cell(map, funct, nbth, false); } - -} - - - - +} // namespace Parallel } // namespace Geometry -} +} // namespace Surface } // namespace Algo diff --git a/include/Algo/Geometry/basic.h b/include/Algo/Geometry/basic.h index a4824b499c5f1b5e08b5dbd7fd40a9ff736d8650..2d012007da1fe04762266c3489ebd93daf6fd860 100644 --- a/include/Algo/Geometry/basic.h +++ b/include/Algo/Geometry/basic.h @@ -43,7 +43,7 @@ namespace Geometry * vectorOutOfDart return a dart from the position of vertex attribute of d to the position of vertex attribute of phi1(d) */ template -inline typename PFP::VEC3 vectorOutOfDart(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +inline typename PFP::VEC3 vectorOutOfDart(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typename PFP::VEC3 vec = position[map.phi1(d)] ; vec -= position[d] ; @@ -51,14 +51,14 @@ inline typename PFP::VEC3 vectorOutOfDart(typename PFP::MAP& map, Dart d, const } template -inline typename PFP::REAL edgeLength(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +inline typename PFP::REAL edgeLength(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { typename PFP::VEC3 v = vectorOutOfDart(map, d, position) ; return v.norm() ; } template -inline float angle(typename PFP::MAP& map, Dart d1, Dart d2, const VertexAttribute& position) +inline float angle(typename PFP::MAP& map, Dart d1, Dart d2, const VertexAttribute& position) { typename PFP::VEC3 v1 = vectorOutOfDart(map, d1, position) ; typename PFP::VEC3 v2 = vectorOutOfDart(map, d2, position) ; @@ -66,7 +66,7 @@ inline float angle(typename PFP::MAP& map, Dart d1, Dart d2, const VertexAttribu } template -bool isTriangleObtuse(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +bool isTriangleObtuse(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { return Geom::isTriangleObtuse(position[d], position[map.phi1(d)], position[map.phi_1(d)]) ; } diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 752cdc8c0b7dec2c71cb4b60952c28ef52554f7f..842b579269c263371453e5a99dad9ba0fdec7d88 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -212,7 +212,7 @@ typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Dart d, con VEC3 N(0) ; std::vector faces; - CellMarker f(map); + CellMarker f(map); FunctorStore fs(faces); map.foreach_dart_of_vertex(d,fs); @@ -237,8 +237,6 @@ typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Dart d, con return N ; } - - template void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_normal, unsigned int thread) { diff --git a/include/Algo/ImplicitHierarchicalMesh/ihm3.h b/include/Algo/ImplicitHierarchicalMesh/ihm3.h index 1f7717dd8f8afd769df3f04537580cccd52cae41..4de8c2688afc59c975ecad591f8edc04f1c0cc2c 100644 --- a/include/Algo/ImplicitHierarchicalMesh/ihm3.h +++ b/include/Algo/ImplicitHierarchicalMesh/ihm3.h @@ -40,15 +40,15 @@ namespace Volume namespace IHM { - template class AttributeHandler_IHM ; +typedef EmbeddedMap3::IMPL EMap3_IMPL; + class ImplicitHierarchicalMap3 : public EmbeddedMap3 { template friend class AttributeHandler_IHM ; public: - FunctorType* vertexVertexFunctor ; FunctorType* edgeVertexFunctor ; FunctorType* faceVertexFunctor ; @@ -59,9 +59,9 @@ public: unsigned int m_edgeIdCount ; unsigned int m_faceIdCount; - DartAttribute m_dartLevel ; - DartAttribute m_edgeId ; - DartAttribute m_faceId ; + DartAttribute m_dartLevel ; + DartAttribute m_edgeId ; + DartAttribute m_faceId ; AttributeMultiVector* m_nextLevelCell[NB_ORBITS] ; @@ -404,25 +404,25 @@ public: } ; template -class AttributeHandler_IHM : public AttributeHandler +class AttributeHandler_IHM : public AttributeHandler { public: typedef T DATA_TYPE ; - AttributeHandler_IHM() : AttributeHandler() + AttributeHandler_IHM() : AttributeHandler() {} - AttributeHandler_IHM(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m, amv) + AttributeHandler_IHM(ImplicitHierarchicalMap3* m, AttributeMultiVector* amv) : AttributeHandler(m, amv) {} AttributeMultiVector* getDataVector() const { - return AttributeHandler::getDataVector() ; + return AttributeHandler::getDataVector() ; } bool isValid() const { - return AttributeHandler::isValid() ; + return AttributeHandler::isValid() ; } virtual T& operator[](Dart d) ; @@ -431,12 +431,12 @@ public: T& operator[](unsigned int a) { - return AttributeHandler::operator[](a) ; + return AttributeHandler::operator[](a) ; } const T& operator[](unsigned int a) const { - return AttributeHandler::operator[](a) ; + return AttributeHandler::operator[](a) ; } } ; @@ -447,14 +447,16 @@ class VertexAttribute_IHM : public IHM::AttributeHandler_IHM public: VertexAttribute_IHM() : IHM::AttributeHandler_IHM() {} VertexAttribute_IHM(const IHM::AttributeHandler_IHM& ah) : IHM::AttributeHandler_IHM(ah) {} - VertexAttribute_IHM& operator=(const IHM::AttributeHandler_IHM& ah) { this->IHM::AttributeHandler_IHM::operator=(ah); return *this; } +// VertexAttribute_IHM& operator=(const IHM::AttributeHandler_IHM& ah) { this->IHM::AttributeHandler_IHM::operator=(ah); return *this; } }; -} //namespace IHM -} // Volume -} //namespace Algo +} // namespace IHM -} //namespace CGoGN +} // namespace Volume + +} // namespace Algo + +} // namespace CGoGN #include "Algo/ImplicitHierarchicalMesh/ihm3.hpp" @@ -464,4 +466,3 @@ public: ///*! // */ //bool faceIsSubdividedOnce(Dart d); - diff --git a/include/Algo/ImplicitHierarchicalMesh/ihm3.hpp b/include/Algo/ImplicitHierarchicalMesh/ihm3.hpp index ab48fd9963e6fec1c6cab2bc54d5d68f2f128f39..53fdfc83cb45b87d3d881f246b11d65f1070611d 100644 --- a/include/Algo/ImplicitHierarchicalMesh/ihm3.hpp +++ b/include/Algo/ImplicitHierarchicalMesh/ihm3.hpp @@ -45,7 +45,7 @@ AttributeHandler_IHM ImplicitHierarchicalMap3::addAttribute(const std: if(!isOrbitEmbedded()) addNextLevelCell = true ; - AttributeHandler h = Map3::addAttribute(nameAttr) ; + AttributeHandler h = Map3::addAttribute(nameAttr) ; if(addNextLevelCell) { @@ -62,11 +62,10 @@ AttributeHandler_IHM ImplicitHierarchicalMap3::addAttribute(const std: template AttributeHandler_IHM ImplicitHierarchicalMap3::getAttribute(const std::string& nameAttr) { - AttributeHandler h = Map3::getAttribute(nameAttr) ; + AttributeHandler h = Map3::getAttribute(nameAttr) ; return AttributeHandler_IHM(this, h.getDataVector()) ; } - inline void ImplicitHierarchicalMap3::update_topo_shortcuts() { Map3::update_topo_shortcuts(); @@ -227,7 +226,7 @@ inline void ImplicitHierarchicalMap3::next(Dart& d) const inline bool ImplicitHierarchicalMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mv(*this, thread); // Lock a marker + DartMarkerStore mv(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector darts; // Darts that are traversed @@ -288,7 +287,7 @@ inline bool ImplicitHierarchicalMap3::foreach_dart_of_face(Dart d, FunctorType& inline bool ImplicitHierarchicalMap3::foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mark(*this, thread); // Lock a marker + DartMarkerStore mark(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector visitedFaces; // Faces that are traversed @@ -329,7 +328,7 @@ inline bool ImplicitHierarchicalMap3::foreach_dart_of_volume(Dart d, FunctorType inline bool ImplicitHierarchicalMap3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mark(*this, thread); // Lock a marker + DartMarkerStore mark(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector visitedFaces; // Faces that are traversed diff --git a/include/Algo/Multiresolution/filter.h b/include/Algo/Multiresolution/filter.h index 83ad60d4b0c29e57379a63a337c3109c26e3ccb8..e0a9e44b3668242cc2b08e02c572582cea1cc1b7 100644 --- a/include/Algo/Multiresolution/filter.h +++ b/include/Algo/Multiresolution/filter.h @@ -27,7 +27,6 @@ #include - namespace CGoGN { @@ -77,7 +76,7 @@ unsigned int vertexLevel(typename PFP::MAP& map, Dart d) template -void filterLowPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevel) +void filterLowPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevel) { unsigned int cur = map.getCurrentLevel(); unsigned int max = map.getMaxLevel(); @@ -95,7 +94,7 @@ void filterLowPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned i } template -void filterHighPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevel) +void filterHighPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevel) { unsigned int cur = map.getCurrentLevel(); unsigned int max = map.getMaxLevel(); @@ -113,7 +112,7 @@ void filterHighPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned } template -void filterBandPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevelLow, unsigned int cutoffLevelHigh) +void filterBandPass(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevelLow, unsigned int cutoffLevelHigh) { unsigned int cur = map.getCurrentLevel(); unsigned int max = map.getMaxLevel(); @@ -149,7 +148,7 @@ typename PFP::VEC3 doTwist(typename PFP::VEC3 pos, float t ) } template -void frequencyDeformation(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevel) +void frequencyDeformation(typename PFP::MAP& map, VertexAttribute& attIn, unsigned int cutoffLevel) { float time = 1.0; //float angle_deg_max = 0.4; @@ -162,7 +161,6 @@ void frequencyDeformation(typename PFP::MAP& map, VertexAttribute tv(map); for (Dart d = tv.begin(); d != tv.end(); d = tv.next()) { - typename PFP::VEC3 p = attIn[d]; float dist = std::sqrt(p[0]*p[0] + p[2]*p[2]); @@ -178,10 +176,6 @@ void frequencyDeformation(typename PFP::MAP& map, VertexAttribute*>& funcs, bool n vd[i].reserve(SIZE_BUFFER_THREAD); AttributeContainer* cont = NULL; - DartMarker* dmark = NULL; - CellMarker* cmark = NULL; + DartMarker* dmark = NULL; + CellMarker* cmark = NULL; const AttributeMultiVector* quickTraversal = map.template getQuickTraversal() ; // fill each vd buffers with SIZE_BUFFER_THREAD darts @@ -197,7 +197,7 @@ void foreach_cell(MAP& map, std::vector*>& funcs, bool n { if(map.template isOrbitEmbedded()) { - cmark = new CellMarker(map) ; + cmark = new CellMarker(map) ; d = map.begin(); unsigned int nb = 0; @@ -214,7 +214,7 @@ void foreach_cell(MAP& map, std::vector*>& funcs, bool n } else { - dmark = new DartMarker(map) ; + dmark = new DartMarker(map) ; d = map.begin(); unsigned int nb = 0; while ((d != map.end()) && (nb < nbth*SIZE_BUFFER_THREAD) ) @@ -486,7 +486,7 @@ void foreach_cell2Pass(MAP& map, std::vector*>& funcsFro map.addThreadMarker(nbth+1-nbth_prec); } - CellMarkerNoUnmark cm(map); // for 2 pass front mark / back unmark + CellMarkerNoUnmark cm(map); // for 2 pass front mark / back unmark boost::barrier sync1(nbth+1); boost::barrier sync2(nbth+1); @@ -663,8 +663,8 @@ void foreach_cell_all_thread(MAP& map, std::vector*>& fu vd.reserve(SIZE_BUFFER_THREAD); AttributeContainer* cont = NULL; - DartMarker* dmark = NULL; - CellMarker* cmark = NULL; + DartMarker* dmark = NULL; + CellMarker* cmark = NULL; AttributeMultiVector* quickTraversal = map.template getQuickTraversal() ; // fill each vd buffers with SIZE_BUFFER_THREAD darts @@ -688,7 +688,7 @@ void foreach_cell_all_thread(MAP& map, std::vector*>& fu { if(map.template isOrbitEmbedded()) { - cmark = new CellMarker(map) ; + cmark = new CellMarker(map) ; d = map.begin(); unsigned int nb=0; while ((d != map.end()) && (nb < SIZE_BUFFER_THREAD) ) @@ -704,7 +704,7 @@ void foreach_cell_all_thread(MAP& map, std::vector*>& fu } else { - dmark = new DartMarker(map) ; + dmark = new DartMarker(map) ; d = map.begin(); unsigned int nb=0; while ((d != map.end()) && (nb < SIZE_BUFFER_THREAD) ) @@ -818,13 +818,6 @@ void foreach_cell_all_thread(MAP& map, std::vector*>& fu delete dmark; } - - - - - - - } // namespace Parallel } // namespace Algo diff --git a/include/Algo/Render/GL2/mapRender.h b/include/Algo/Render/GL2/mapRender.h index 81b8cec07c8e77c3a3149409e6381843e2d022a7..4db4112bbcdd781192d36ef615b01c056c17189c 100644 --- a/include/Algo/Render/GL2/mapRender.h +++ b/include/Algo/Render/GL2/mapRender.h @@ -40,7 +40,6 @@ #include "Container/convert.h" #include "Geometry/vector_gen.h" - // forward definition namespace CGoGN { namespace Utils { class GLSLShader; } } @@ -155,16 +154,16 @@ protected: void addTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices) ; template - inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices, const VertexAttribute* position); + inline void addEarTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices, const VertexAttribute* position); template float computeEarAngle(const typename PFP::VEC3& P1, const typename PFP::VEC3& P2, const typename PFP::VEC3& P3, const typename PFP::VEC3& normalPoly); template - bool computeEarIntersection(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly); + bool computeEarIntersection(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly); template - void recompute2Ears(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex); + void recompute2Ears(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex); template bool inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, const VEC3& Tb, const VEC3& Tc); @@ -175,9 +174,9 @@ public: * @param tableIndices the table where indices are stored */ template - void initTriangles(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread = 0) ; + void initTriangles(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread = 0) ; template - void initTrianglesOptimized(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread = 0) ; + void initTrianglesOptimized(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread = 0) ; /** * creation of indices table of lines (optimized order) @@ -210,13 +209,13 @@ public: void initPrimitives(typename PFP::MAP& map, int prim, bool optimized = true, unsigned int thread = 0) ; template - void initPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized = true, unsigned int thread = 0) ; + void initPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized = true, unsigned int thread = 0) ; /** * add primitives to the VBO of indices */ template - void addPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized = true, unsigned int thread = 0); + void addPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized = true, unsigned int thread = 0); /** * initialization of the VBO indices primitives diff --git a/include/Algo/Render/GL2/mapRender.hpp b/include/Algo/Render/GL2/mapRender.hpp index e72da0d75c6c68dfe49c0cc378cb38b96bcf3839..c6e1b84fed978f833f4fa9b484c46028927a4753 100644 --- a/include/Algo/Render/GL2/mapRender.hpp +++ b/include/Algo/Render/GL2/mapRender.hpp @@ -71,7 +71,7 @@ bool MapRender::inTriangle(const VEC3& P, const VEC3& normal, const VEC3& Ta, c } template -void MapRender::recompute2Ears(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex) +void MapRender::recompute2Ears(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly, VPMS& ears, bool convex) { VertexPoly* vprev = vp->prev; VertexPoly* vp2 = vp->next; @@ -151,7 +151,7 @@ float MapRender::computeEarAngle(const typename PFP::VEC3& P1, const typename PF } template -bool MapRender::computeEarIntersection(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly) +bool MapRender::computeEarIntersection(const VertexAttribute& position, VertexPoly* vp, const typename PFP::VEC3& normalPoly) { VertexPoly* endV = vp->prev; @@ -175,12 +175,12 @@ bool MapRender::computeEarIntersection(const VertexAttribute } template -inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices, const VertexAttribute* pos) +inline void MapRender::addEarTri(typename PFP::MAP& map, Dart d, std::vector& tableIndices, const VertexAttribute* pos) { bool(*fn_pt1)(VertexPoly*,VertexPoly*) = &(MapRender::cmpVP); VPMS ears(fn_pt1); - const VertexAttribute& position = *pos ; + const VertexAttribute& position = *pos ; // compute normal to polygon typename PFP::VEC3 normalPoly = Algo::Surface::Geometry::newellNormal(map, d, position); @@ -297,7 +297,7 @@ inline void MapRender::addTri(typename PFP::MAP& map, Dart d, std::vector -void MapRender::initTriangles(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread) +void MapRender::initTriangles(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread) { tableIndices.reserve(4 * map.getNbDarts() / 3); @@ -321,10 +321,10 @@ void MapRender::initTriangles(typename PFP::MAP& map, std::vector& table } template -void MapRender::initTrianglesOptimized(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread) +void MapRender::initTrianglesOptimized(typename PFP::MAP& map, std::vector& tableIndices, const VertexAttribute* position, unsigned int thread) { #define LIST_SIZE 20 - DartMarker m(map, thread); + DartMarker m(map, thread); // reserve memory for triangles ( nb indices == nb darts ) // and a little bit more // if lots of polygonal faces, realloc is done by vector @@ -429,7 +429,7 @@ template void MapRender::initLinesOptimized(typename PFP::MAP& map, std::vector& tableIndices, unsigned int thread) { #define LIST_SIZE 20 - DartMarker m(map, thread); + DartMarker m(map, thread); // reserve memory for edges indices ( nb indices == nb darts) tableIndices.reserve(map.getNbDarts()); @@ -489,7 +489,7 @@ void MapRender::initPrimitives(typename PFP::MAP& map, int prim, bool optimized, } template -void MapRender::initPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized, unsigned int thread) +void MapRender::initPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized, unsigned int thread) { std::vector tableIndices; @@ -531,7 +531,7 @@ void MapRender::initPrimitives(typename PFP::MAP& map, int prim, const VertexAtt template -void MapRender::addPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized, unsigned int thread) +void MapRender::addPrimitives(typename PFP::MAP& map, int prim, const VertexAttribute* position, bool optimized, unsigned int thread) { std::vector tableIndices; @@ -588,10 +588,8 @@ void MapRender::addPrimitives(typename PFP::MAP& map, int prim, const VertexAttr m_indexBuffers[prim] = newBuffer; m_nbIndices[prim] += tableIndices.size(); - } - } // namespace GL2 } // namespace Render diff --git a/include/Algo/Render/GL2/topo3PrimalRender.h b/include/Algo/Render/GL2/topo3PrimalRender.h index 4c0b86a53e74d793b5ea64195b032887d32797a6..95e2e06547d052621c981e85b4fc516457c90a95 100644 --- a/include/Algo/Render/GL2/topo3PrimalRender.h +++ b/include/Algo/Render/GL2/topo3PrimalRender.h @@ -37,13 +37,9 @@ #include "Utils/Shaders/shaderSimpleColor.h" #include "Utils/Shaders/shaderColorPerVertex.h" - - - #include "Utils/vbo_base.h" #include "Utils/svg.h" - namespace CGoGN { @@ -56,11 +52,10 @@ namespace Render namespace GL2 { - +template class Topo3PrimalRender { protected: - /** * vbo buffers * 0: vertices darts @@ -114,8 +109,7 @@ protected: /** * attribute index to get easy correspondence dart/color */ - DartAttribute m_attIndex; - + DartAttribute m_attIndex; Geom::Vec3f* m_bufferDartPosition; @@ -138,7 +132,6 @@ protected: Dart pickColor(unsigned int x, unsigned int y); public: - /** * Constructor */ @@ -149,9 +142,8 @@ public: */ ~Topo3PrimalRender(); - - Utils::GLSLShader* shader1() { return static_cast(m_shader1);} - Utils::GLSLShader* shader2() { return static_cast(m_shader2);} + Utils::GLSLShader* shader1() { return static_cast(m_shader1); } + Utils::GLSLShader* shader2() { return static_cast(m_shader2); } /** * set the with of line use to draw darts (default val is 2) @@ -223,7 +215,6 @@ public: /** * store darts in color for picking */ - template void setDartsIdColor(typename PFP::MAP& map); /** @@ -235,10 +226,8 @@ public: * @param y position of mouse (pass H-y, classic pb of origin) * @return the dart or NIL */ - template Dart picking(typename PFP::MAP& map, int x, int y); - /** * compute dart from color (for picking) */ @@ -249,7 +238,6 @@ public: */ void dartToCol(Dart d, float& r, float& g, float& b); - /** * update all drawing buffers to render a dual map * @param map the map @@ -261,24 +249,21 @@ public: // template // void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf); - template - void updateData(typename PFP::MAP& mapx, const EMBV& positions, float ke, float kf); + void updateData(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf); /** * update color buffer with color attribute handler * @param map the map * @param colors attribute of dart's colors */ - template - void updateColors(typename PFP::MAP& map, const VertexAttribute& colors); + void updateColors(typename PFP::MAP& map, const VertexAttribute& colors); /** * Get back middle position of drawn darts * @param map the map * @param posExpl the output positions */ - template - void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl); + void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl); /** * render to svg struct @@ -290,11 +275,8 @@ public: */ void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); - - template Dart coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle); - template Dart raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float distmax); protected: @@ -321,14 +303,13 @@ protected: // void updateDataGMap3(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv); }; +} // end namespace GL2 -}//end namespace GL2 - -}//end namespace Algo +} // end namespace Algo -}//end namespace Render +} // end namespace Render -}//end namespace CGoGN +} // end namespace CGoGN #include "Algo/Render/GL2/topo3PrimalRender.hpp" diff --git a/include/Algo/Render/GL2/topo3PrimalRender.hpp b/include/Algo/Render/GL2/topo3PrimalRender.hpp index 1f167a30aecec303a6da8f053bfbaebd77c6d353..cff42bdd6e3582c19a0992f0dad8e1c92eb1f099 100644 --- a/include/Algo/Render/GL2/topo3PrimalRender.hpp +++ b/include/Algo/Render/GL2/topo3PrimalRender.hpp @@ -47,12 +47,325 @@ namespace Render namespace GL2 { -template -void Topo3PrimalRender::setDartsIdColor(typename PFP::MAP& map) +template +Topo3PrimalRender::Topo3PrimalRender(): + m_nbDarts(0), + m_nbRel2(0), + m_topo_dart_width(2.0f), + m_topo_relation_width(3.0f), + m_color_save(NULL), + m_dartsColor(1.0f,1.0f,1.0f), + m_boundaryDartsColor(0.5f,0.5f,0.5f), + m_bufferDartPosition(NULL) { + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + + + m_shader1 = new Utils::ShaderSimpleColor(); + m_shader2 = new Utils::ShaderColorPerVertex(); + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + m_shader2->setAttributePosition(m_vbo0); + m_shader2->setAttributeColor(m_vbo2); + + // registering for auto matrices update + Utils::GLSLShader::registerShader(NULL, m_shader1); + Utils::GLSLShader::registerShader(NULL, m_shader2); +} + +template +Topo3PrimalRender::~Topo3PrimalRender() +{ + Utils::GLSLShader::unregisterShader(NULL, m_shader2); + Utils::GLSLShader::unregisterShader(NULL, m_shader1); + + delete m_shader2; + delete m_shader1; + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + + if (m_attIndex.isValid()) + m_attIndex.map()->removeAttribute(m_attIndex); + + if (m_color_save != NULL) + delete[] m_color_save; + + if (m_bufferDartPosition!=NULL) + delete[] m_bufferDartPosition; +} + +template +void Topo3PrimalRender::setDartWidth(float dw) +{ + m_topo_dart_width = dw; +} + +template +void Topo3PrimalRender::setRelationWidth(float pw) +{ + m_topo_relation_width = pw; +} + +template +void Topo3PrimalRender::setDartColor(Dart d, float r, float g, float b) +{ + float RGB[6]; + RGB[0]=r; RGB[1]=g; RGB[2]=b; + RGB[3]=r; RGB[4]=g; RGB[5]=b; m_vbo2->bind(); - float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); - unsigned int nb=0; + glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); +} + +template +void Topo3PrimalRender::setAllDartsColor(float r, float g, float b) +{ + m_vbo2->bind(); + GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); + for (unsigned int i=0; i < 2*m_nbDarts; ++i) + { + *colorDartBuf++ = r; + *colorDartBuf++ = g; + *colorDartBuf++ = b; + } + glUnmapBufferARB(GL_ARRAY_BUFFER); +} + +template +void Topo3PrimalRender::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec3f(r,g,b); +} + +template +void Topo3PrimalRender::setInitialBoundaryDartsColor(float r, float g, float b) +{ + m_boundaryDartsColor = Geom::Vec3f(r,g,b); +} + +template +void Topo3PrimalRender::drawDarts() +{ + if (m_nbDarts==0) + return; + + m_shader2->enableVertexAttribs(); + + glLineWidth(m_topo_dart_width); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + // change the stride to take 1/2 vertices + m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); + + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + m_shader2->disableVertexAttribs(); +} + +template +void Topo3PrimalRender::drawRelation2() +{ + if (m_nbRel2==0) + return; + + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(m_topo_relation_width); + glDrawArrays(GL_LINES, 0, m_nbRel2*2); + + m_shader1->disableVertexAttribs(); +} + +template +void Topo3PrimalRender::drawTopo() +{ + drawDarts(); + drawRelation2(); +} + +template +void Topo3PrimalRender::overdrawDart(Dart d, float width, float r, float g, float b) +{ + unsigned int indexDart = m_attIndex[d]; + + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(width); + glDrawArrays(GL_LINES, indexDart, 2); + + glPointSize(2.0f*width); + glDrawArrays(GL_POINTS, indexDart, 1); + + m_shader2->disableVertexAttribs(); +} + +template +void Topo3PrimalRender::pushColors() +{ + m_color_save = new float[6*m_nbDarts]; + m_vbo2->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); +} + +template +void Topo3PrimalRender::popColors() +{ + m_vbo2->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + delete[] m_color_save; + m_color_save=0; +} + +template +Dart Topo3PrimalRender::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id == 0) + return NIL; + return Dart(id-1); +} + +template +void Topo3PrimalRender::dartToCol(Dart d, float& r, float& g, float& b) +{ + // here use dart.index beacause it is what we want (and not map.dartIndex(d) !!) + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; +} + +template +Dart Topo3PrimalRender::pickColor(unsigned int x, unsigned int y) +{ + //more easy picking for + unsigned int dw = m_topo_dart_width; + m_topo_dart_width+=2; + + // save clear color and set to zero + float cc[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); + + glClearColor(0.0f,0.0f,0.0f,0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + // draw in back buffer (not shown on screen) + + drawDarts(); + + // restore dart with + m_topo_dart_width = dw; + + // read the pixel under the mouse in back buffer + glReadBuffer(GL_BACK); + float color[3]; + glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); + + glClearColor(cc[0], cc[1], cc[2], cc[3]); + + + std::cout << color[0] << ", "< +void Topo3PrimalRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) +{ + Utils::SVG::SVGOut svg(filename,model,proj); + toSVG(svg); + svg.write(); +} + +template +void Topo3PrimalRender::toSVG(Utils::SVG::SVGOut& svg) +{ + // alpha2 + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("alpha2", svg.m_model, svg.m_proj); + Geom::Vec3f* ptr = reinterpret_cast(m_vbo1->lockPtr()); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); + for (unsigned int i=0; iaddLine(P, Q, Geom::Vec3f(0.8f,0.0f,0.0f)); + } + svg2->endLines(); + m_vbo1->releasePtr(); + svg.addGroup(svg2); + + const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo2->lockPtr()); + ptr= reinterpret_cast(m_vbo0->lockPtr()); + + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); + + svg4->beginLines(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg4->addLine(ptr[2*i], ptr[2*i+1], col); + } + svg4->endLines(); + + svg.addGroup(svg4); + + Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg5->setWidth(m_topo_dart_width); + svg5->beginPoints(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg5->addPoint(ptr[2*i], col); + } + svg5->endPoints(); + svg.addGroup(svg5); + + m_vbo0->releasePtr(); + m_vbo2->releasePtr(); + +} + +template +void Topo3PrimalRender::setDartsIdColor(typename PFP::MAP& map) +{ + m_vbo2->bind(); + float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); + unsigned int nb = 0; for (Dart d = map.begin(); d != map.end(); map.next(d)) { @@ -79,8 +392,8 @@ void Topo3PrimalRender::setDartsIdColor(typename PFP::MAP& map) glUnmapBuffer(GL_ARRAY_BUFFER); } -template -void Topo3PrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribute& colors) +template +void Topo3PrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribute& colors) { m_vbo2->bind(); Geom::Vec3f* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); @@ -102,26 +415,26 @@ void Topo3PrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribu glUnmapBuffer(GL_ARRAY_BUFFER); } -template -Dart Topo3PrimalRender::picking(typename PFP::MAP& map, int x, int y) +template +Dart Topo3PrimalRender::picking(typename PFP::MAP& map, int x, int y) { pushColors(); - setDartsIdColor(map); + setDartsIdColor(map); Dart d = pickColor(x,y); popColors(); return d; } //template -//void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf) +//void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf) //{ // updateDataGen, typename PFP::VEC3>(mapx,positions,ke,kf); //} -template -void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& positions, float ke, float kf) +template +void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf) { - typedef typename EMBV::DATA_TYPE VEC3; + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; typedef Geom::Vec3f VEC3F; @@ -139,20 +452,18 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position m_nbDarts = mapx.getNbDarts(); // beta2/3 - DartAutoAttribute fv2(mapx); + DartAutoAttribute fv2(mapx); m_vbo2->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW); GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3F* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - if (m_bufferDartPosition!=NULL) delete m_bufferDartPosition; m_bufferDartPosition = new VEC3F[2*m_nbDarts]; VEC3F* positionDartBuf = reinterpret_cast(m_bufferDartPosition); - unsigned int posDBI=0; int nbf=0; @@ -163,7 +474,7 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position std::vector vecPos; vecPos.reserve(16); - VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW(mapx,d,positions); + VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW(mapx, d, positions); //shrink the face float okf = 1.0f - kf; @@ -209,7 +520,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position posDBI+=2; fv2[d] = (P+PP)*0.5f; - *positionDartBuf++ = PFP::toVec3f(Q); *positionDartBuf++ = PFP::toVec3f(QQ); @@ -253,7 +563,6 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position Dart e = mapx.phi2(mapx.phi3(d)); //if (d < e) { - *positionF2++ = PFP::toVec3f(fv2[d]); *positionF2++ = PFP::toVec3f(fv2[e]); m_nbRel2++; @@ -266,11 +575,10 @@ void Topo3PrimalRender::updateData(typename PFP::MAP& mapx, const EMBV& position glBindBuffer(GL_ARRAY_BUFFER, 0); } -template -void Topo3PrimalRender::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl) +template +void Topo3PrimalRender::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl) { typedef Geom::Vec3f VEC3F; - typedef typename PFP::VEC3 VEC3; m_vbo0->bind(); VEC3F* positionsPtr = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); @@ -285,10 +593,8 @@ void Topo3PrimalRender::computeDartMiddlePositions(typename PFP::MAP& map, DartA glUnmapBuffer(GL_ARRAY_BUFFER); } - - -template -Dart Topo3PrimalRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) +template +Dart Topo3PrimalRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -317,8 +623,8 @@ Dart Topo3PrimalRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& return dFinal; } -template -Dart Topo3PrimalRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) +template +Dart Topo3PrimalRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -345,7 +651,6 @@ Dart Topo3PrimalRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& return dFinal; } - } //end namespace GL2 } //end namespace Render diff --git a/include/Algo/Render/GL2/topo3Render.h b/include/Algo/Render/GL2/topo3Render.h index 8b5f448ff2eac228dd037ad30264dffd2d1a62de..47d32b4efb1c6b38b93150056c054fcf6e556a94 100644 --- a/include/Algo/Render/GL2/topo3Render.h +++ b/include/Algo/Render/GL2/topo3Render.h @@ -22,8 +22,8 @@ * * *******************************************************************************/ -#ifndef _TOPO3_VBO_RENDER -#define _TOPO3_VBO_RENDER +#ifndef _TOPO3_VBO_RENDER_ +#define _TOPO3_VBO_RENDER_ #include #include @@ -37,13 +37,9 @@ #include "Utils/Shaders/shaderSimpleColor.h" #include "Utils/Shaders/shaderColorPerVertex.h" - - - #include "Utils/vbo_base.h" #include "Utils/svg.h" - namespace CGoGN { @@ -56,11 +52,10 @@ namespace Render namespace GL2 { - +template class Topo3Render { protected: - /** * vbo buffers * 0: vertices darts @@ -123,8 +118,7 @@ protected: /** * attribute index to get easy correspondence dart/color */ - DartAttribute m_attIndex; - + DartAttribute m_attIndex; Geom::Vec3f* m_bufferDartPosition; @@ -158,9 +152,8 @@ public: */ ~Topo3Render(); - - Utils::GLSLShader* shader1() { return static_cast(m_shader1);} - Utils::GLSLShader* shader2() { return static_cast(m_shader2);} + Utils::GLSLShader* shader1() { return static_cast(m_shader1); } + Utils::GLSLShader* shader2() { return static_cast(m_shader2); } /** * set the with of line use to draw darts (default val is 2) @@ -240,7 +233,6 @@ public: /** * store darts in color for picking */ - template void setDartsIdColor(typename PFP::MAP& map); /** @@ -252,10 +244,8 @@ public: * @param y position of mouse (pass H-y, classic pb of origin) * @return the dart or NIL */ - template Dart picking(typename PFP::MAP& map, int x, int y); - /** * compute dart from color (for picking) */ @@ -266,7 +256,6 @@ public: */ void dartToCol(Dart d, float& r, float& g, float& b); - /** * update all drawing buffers to render a dual map * @param map the map @@ -275,8 +264,7 @@ public: * @param kf exploding coef for face * @param kv exploding coef for face */ - template - void updateData(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv); + void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv); // template // void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv); @@ -286,20 +274,17 @@ public: * @param map the map * @param colors attribute of dart's colors */ - template - void updateColorsGen(typename PFP::MAP& map, const EMBV& colors); - - template - void updateColors(typename PFP::MAP& map, const VertexAttribute& colors); +// template +// void updateColorsGen(typename PFP::MAP& map, const EMBV& colors); + void updateColors(typename PFP::MAP& map, const VertexAttribute& colors); /** * Get back middle position of drawn darts * @param map the map * @param posExpl the output positions */ - template - void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl); + void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl); /** * render to svg struct @@ -311,11 +296,8 @@ public: */ void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); - - template Dart coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle); - template Dart raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float distmax); protected: @@ -327,8 +309,7 @@ protected: * @param kf exploding coef for face * @param kv exploding coef for face */ - template - void updateDataMap3(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv); + void updateDataMap3(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv); /** * update all drawing buffers to render a gmap @@ -338,11 +319,9 @@ protected: * @param kf exploding coef for face * @param kv exploding coef for face */ - template - void updateDataGMap3(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv); + void updateDataGMap3(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv); }; - }//end namespace GL2 }//end namespace Algo diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index c107b835a5fac5f61f3c43aa78526ee21286674a..a81715510b531439b212508085669e44440479d7 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -46,8 +46,437 @@ namespace Render namespace GL2 { + +template +Topo3Render::Topo3Render(): + m_nbDarts(0), + m_nbRel1(0), + m_nbRel2(0), + m_nbRel3(0), + m_topo_dart_width(2.0f), + m_topo_relation_width(3.0f), + m_color_save(NULL), + m_dartsColor(1.0f,1.0f,1.0f), + m_bufferDartPosition(NULL) +{ + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + m_vbo3 = new Utils::VBO(); + m_vbo4 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + m_vbo3->setDataSize(3); + m_vbo4->setDataSize(3); + + m_shader1 = new Utils::ShaderSimpleColor(); + m_shader2 = new Utils::ShaderColorPerVertex(); + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + m_shader2->setAttributePosition(m_vbo0); + m_shader2->setAttributeColor(m_vbo4); + + // registering for auto matrices update + Utils::GLSLShader::registerShader(NULL, m_shader1); + Utils::GLSLShader::registerShader(NULL, m_shader2); +} + +template +Topo3Render::~Topo3Render() +{ + Utils::GLSLShader::unregisterShader(NULL, m_shader2); + Utils::GLSLShader::unregisterShader(NULL, m_shader1); + + delete m_shader2; + delete m_shader1; + delete m_vbo4; + delete m_vbo3; + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + + if (m_attIndex.map() != NULL) + m_attIndex.map()->removeAttribute(m_attIndex); + + if (m_color_save != NULL) + delete[] m_color_save; + + if (m_bufferDartPosition != NULL) + delete[] m_bufferDartPosition; +} + +template +void Topo3Render::setDartWidth(float dw) +{ + m_topo_dart_width = dw; +} + +template +void Topo3Render::setRelationWidth(float pw) +{ + m_topo_relation_width = pw; +} + +template +void Topo3Render::setDartColor(Dart d, float r, float g, float b) +{ + float RGB[6]; + RGB[0]=r; RGB[1]=g; RGB[2]=b; + RGB[3]=r; RGB[4]=g; RGB[5]=b; + m_vbo4->bind(); + glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); +} + +template +void Topo3Render::setAllDartsColor(float r, float g, float b) +{ + m_vbo4->bind(); + GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); + for (unsigned int i=0; i < 2*m_nbDarts; ++i) + { + *colorDartBuf++ = r; + *colorDartBuf++ = g; + *colorDartBuf++ = b; + } + glUnmapBufferARB(GL_ARRAY_BUFFER); + +} + +template +void Topo3Render::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec3f(r,g,b); +} + +template +void Topo3Render::drawDarts() +{ + if (m_nbDarts==0) + return; + + m_shader2->enableVertexAttribs(); + + glLineWidth(m_topo_dart_width); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + // change the stride to take 1/2 vertices + m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); + + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + m_shader2->disableVertexAttribs(); + +// +//// glColor3f(1.0f,1.0f,1.0f); +// glLineWidth(m_topo_dart_width); +// glPointSize(2.0f*m_topo_dart_width); +// +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); +// glColorPointer(3, GL_FLOAT, 0, 0); +// glEnableClientState(GL_COLOR_ARRAY); +// +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_LINES, 0, m_nbDarts*2); +// +// glVertexPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); +// +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); +// glColorPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); +// glDrawArrays(GL_POINTS, 0, m_nbDarts) +// ; +// glDisableClientState(GL_COLOR_ARRAY); +// glDisableClientState(GL_VERTEX_ARRAY); + +} + +template +void Topo3Render::drawRelation1() +{ + if (m_nbDarts==0) + return; + + glLineWidth(m_topo_relation_width); + + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_LINES, 0, m_nbRel1*2); + + m_shader1->disableVertexAttribs(); + +// glLineWidth(m_topo_relation_width); +// glColor3f(0.0f,1.0f,1.0f); +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_LINES, 0, m_nbDarts*2); +// glDisableClientState(GL_VERTEX_ARRAY); +} + +template +void Topo3Render::drawRelation2() +{ + if (m_nbRel2==0) + return; + + m_shader1->changeVA_VBO(m_vaId, m_vbo2); + m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_QUADS, 0, m_nbRel2*4); + + m_shader1->disableVertexAttribs(); + +// glLineWidth(m_topo_relation_width); +// glColor3f(1.0f,0.0f,0.0f); +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_QUADS, 0, m_nbRel2*4); +// glDisableClientState(GL_VERTEX_ARRAY); +} + +template +void Topo3Render::drawRelation3(Geom::Vec4f c) +{ + if (m_nbRel3==0) + return; + + m_shader1->changeVA_VBO(m_vaId, m_vbo3); + m_shader1->setColor(c); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_QUADS, 0, m_nbRel3*4); + + m_shader1->disableVertexAttribs(); + +// glLineWidth(m_topo_relation_width); +// glColor3f(1.0f,1.0f,0.0f); +// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); +// glVertexPointer(3, GL_FLOAT, 0, 0); +// +// glEnableClientState(GL_VERTEX_ARRAY); +// glDrawArrays(GL_QUADS, 0, m_nbRel3*4); +// glDisableClientState(GL_VERTEX_ARRAY); +} + +template +void Topo3Render::drawTopo() +{ + drawDarts(); + drawRelation1(); + drawRelation2(); + drawRelation3(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); +} + +template +void Topo3Render::overdrawDart(Dart d, float width, float r, float g, float b) +{ + unsigned int indexDart = m_attIndex[d]; + + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(width); + glDrawArrays(GL_LINES, indexDart, 2); + + glPointSize(2.0f*width); + glDrawArrays(GL_POINTS, indexDart, 1); + + m_shader2->disableVertexAttribs(); +} + +template +void Topo3Render::pushColors() +{ + m_color_save = new float[6*m_nbDarts]; + m_vbo4->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); +} + +template +void Topo3Render::popColors() +{ + m_vbo4->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + delete[] m_color_save; + m_color_save=0; +} + +template +Dart Topo3Render::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id == 0) + return NIL; + return Dart(id-1); +} + +template +void Topo3Render::dartToCol(Dart d, float& r, float& g, float& b) +{ + // here use dart.index beacause it is what we want (and not map.dartIndex(d) !!) + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; +} + +template +Dart Topo3Render::pickColor(unsigned int x, unsigned int y) +{ + //more easy picking for + unsigned int dw = m_topo_dart_width; + m_topo_dart_width+=2; + + // save clear color and set to zero + float cc[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); + + glClearColor(0.0f,0.0f,0.0f,0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + // draw in back buffer (not shown on screen) + + drawDarts(); + + // restore dart with + m_topo_dart_width = dw; + + // read the pixel under the mouse in back buffer + glReadBuffer(GL_BACK); + float color[3]; + glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); + + glClearColor(cc[0], cc[1], cc[2], cc[3]); + + + std::cout << color[0] << ", "< +void Topo3Render::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) +{ + Utils::SVG::SVGOut svg(filename,model,proj); + toSVG(svg); + svg.write(); +} + +template +void Topo3Render::toSVG(Utils::SVG::SVGOut& svg) +{ + + // PHI3 / beta3 + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi3", svg.m_model, svg.m_proj); + const Geom::Vec3f* ptr = reinterpret_cast(m_vbo3->lockPtr()); + svg1->setWidth(m_topo_relation_width); + svg1->beginLines(); + for (unsigned int i=0; iaddLine(P, Q,Geom::Vec3f(0.8f,0.8f,0.0f)); + } + svg1->endLines(); + m_vbo3->releasePtr(); + + svg.addGroup(svg1); + + // PHI2 / beta2 + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); + ptr = reinterpret_cast(m_vbo2->lockPtr()); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); + for (unsigned int i=0; iaddLine(P, Q,Geom::Vec3f(0.8f,0.0f,0.0f)); + } + svg2->endLines(); + m_vbo2->releasePtr(); + + svg.addGroup(svg2); + + //PHI1 /beta1 + Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); + ptr = reinterpret_cast(m_vbo1->lockPtr()); + svg3->setWidth(m_topo_relation_width); + svg3->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); + svg3->endLines(); + m_vbo1->releasePtr(); + + svg.addGroup(svg3); + + const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo4->lockPtr()); + ptr= reinterpret_cast(m_vbo0->lockPtr()); + + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); + + svg4->beginLines(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg4->addLine(ptr[2*i], ptr[2*i+1], col); + } + svg4->endLines(); + + svg.addGroup(svg4); + + Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg5->setWidth(m_topo_dart_width); + svg5->beginPoints(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg5->addPoint(ptr[2*i], col); + } + svg5->endPoints(); + + svg.addGroup(svg5); + + m_vbo0->releasePtr(); + m_vbo4->releasePtr(); +} + //template -//void Topo3Render::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv) +//void Topo3Render::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv) //{ // Map3* ptrMap3 = dynamic_cast(&map); // if (ptrMap3 != NULL) @@ -61,32 +490,30 @@ namespace GL2 // } //} - -template -void Topo3Render::updateData(typename PFP::MAP& map, const EMBV& positions, float ke, float kf, float kv) +template +void Topo3Render::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float kv) { - Map3* ptrMap3 = dynamic_cast(&map); - if (ptrMap3 != NULL) + if (map.mapTypeName()[0] == "M") // "Map2" { - updateDataMap3(map,positions,ke,kf,kv); + updateDataMap3(map, positions, ke, kf, kv); + return; } - GMap3* ptrGMap3 = dynamic_cast(&map); - if (ptrGMap3 != NULL) + if (map.mapTypeName()[0] == "G") // "GMap2" { - updateDataGMap3(map,positions,ke,kf,kv); + updateDataGMap3(map, positions, ke, kf, kv); + return; } } - - -template -void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const EMBV& positions, float ke, float kf, float kv) +template +void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf, float kv) { - typedef typename EMBV::DATA_TYPE VEC3; + typedef typename PFP::MAP MAP; + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; typedef Geom::Vec3f VEC3F; - m_attIndex = mapx.template getAttribute("dart_index3"); + m_attIndex = mapx.template getAttribute("dart_index3"); if (!m_attIndex.isValid()) m_attIndex = mapx.template addAttribute("dart_index3"); @@ -99,19 +526,19 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const EMBV& positions, } // compute center of each volumes - CellMarker cmv(mapx); - VolumeAutoAttribute centerVolumes(mapx, "centerVolumes"); + CellMarker cmv(mapx); + VolumeAutoAttribute centerVolumes(mapx, "centerVolumes"); Algo::Volume::Geometry::Parallel::computeCentroidELWVolumes(mapx, positions, centerVolumes,3); // debut phi1 - DartAutoAttribute fv1(mapx); + DartAutoAttribute fv1(mapx); // fin phi1 - DartAutoAttribute fv11(mapx); + DartAutoAttribute fv11(mapx); // phi2 - DartAutoAttribute fv2(mapx); - DartAutoAttribute fv2x(mapx); + DartAutoAttribute fv2(mapx); + DartAutoAttribute fv2x(mapx); m_vbo4->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); @@ -123,13 +550,12 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const EMBV& positions, GLvoid* PositionDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3F* positionDartBuf = reinterpret_cast(PositionDartsBuffer); - std::vector vecDartFaces; vecDartFaces.reserve(m_nbDarts/3); unsigned int posDBI=0; // traverse each face of each volume - TraversorCell traFace(mapx); + TraversorCell traFace(mapx); for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { vecDartFaces.push_back(d); @@ -188,7 +614,6 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const EMBV& positions, m_vbo4->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); - VEC3F* positioniF1 = new VEC3F[ 2*m_nbDarts]; VEC3F* positioniF2 = new VEC3F[ 2*m_nbDarts]; VEC3F* positioniF3 = new VEC3F[ 2*m_nbDarts]; @@ -248,7 +673,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const EMBV& positions, } template -void Topo3Render::setDartsIdColor(typename PFP::MAP& map) +void Topo3Render::setDartsIdColor(typename PFP::MAP& map) { m_vbo4->bind(); float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); @@ -282,13 +707,13 @@ void Topo3Render::setDartsIdColor(typename PFP::MAP& map) glUnmapBuffer(GL_ARRAY_BUFFER); } -template -void Topo3Render::updateColorsGen(typename PFP::MAP& map, const EMBV& colors) +template +void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute& colors) { - typedef typename EMBV::DATA_TYPE EMB; + typedef typename PFP::VEC3 VEC3; m_vbo4->bind(); - EMB* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); + VEC3* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); unsigned int nb=0; for (Dart d = map.begin(); d != map.end(); map.next(d)) @@ -311,60 +736,52 @@ void Topo3Render::updateColorsGen(typename PFP::MAP& map, const EMBV& colors) } template -void Topo3Render::updateColors(typename PFP::MAP& map, const VertexAttribute& colors) -{ -// updateColorsGen >(map,colors); - updateColorsGen(map,colors); -} - -template -Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y) +Dart Topo3Render::picking(typename PFP::MAP& map, int x, int y) { pushColors(); - setDartsIdColor(map); + setDartsIdColor(map); Dart d = pickColor(x,y); popColors(); return d; } -template -void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions, float ke, float kf, float kv) +template +void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf, float kv) { - typedef typename EMBV::DATA_TYPE VEC3; + typedef typename PFP::MAP MAP; + typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; typedef Geom::Vec3f VEC3F; - - GMap3& map = dynamic_cast(mapx); // TODO reflechir comment virer ce warning quand on compile avec PFP::MAP=Map3 +// GMap3& map = dynamic_cast(mapx); // TODO reflechir comment virer ce warning quand on compile avec PFP::MAP=Map3 if (m_attIndex.map() != &mapx) - m_attIndex = mapx.template getAttribute("dart_index3"); + m_attIndex = mapx.template getAttribute("dart_index3"); if (!m_attIndex.isValid()) - m_attIndex = mapx.template addAttribute("dart_index3"); + m_attIndex = mapx.template addAttribute("dart_index3"); m_nbDarts = 0; for (Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) { - if (!map.isBoundaryMarked3(d)) // in the following code Traversor do not traverse boundary + if (!mapx.isBoundaryMarked<3>(d)) // in the following code Traversor do not traverse boundary m_nbDarts++; } // compute center of each volumes - VolumeAutoAttribute centerVolumes(mapx, "centerVolumes"); + VolumeAutoAttribute centerVolumes(mapx, "centerVolumes"); Algo::Volume::Geometry::Parallel::computeCentroidELWVolumes(mapx, positions, centerVolumes); // beta1 - DartAutoAttribute fv1(mapx); + DartAutoAttribute fv1(mapx); // beta2/3 - DartAutoAttribute fv2(mapx); - DartAutoAttribute fv2x(mapx); + DartAutoAttribute fv2(mapx); + DartAutoAttribute fv2x(mapx); m_vbo4->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW); GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3F* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - if (m_bufferDartPosition!=NULL) delete m_bufferDartPosition; m_bufferDartPosition = new VEC3F[2*m_nbDarts]; @@ -380,7 +797,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions unsigned int posDBI=0; //traverse each face of each volume - TraversorCell traFace(mapx); + TraversorCell traFace(mapx); for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { vecDartFaces.push_back(d); @@ -393,7 +810,6 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions VEC3 vc = centerVolumes[d]; - VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW(mapx,d,positions)*kv +vc*okv; //shrink the face @@ -432,11 +848,10 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions m_attIndex[d] = posDBI; posDBI+=2; - fv1[d] = P*0.9f + PP*0.1f; fv2x[d] = P*0.52f + PP*0.48f; fv2[d] = P*0.48f + PP*0.52f; - Dart dx = map.beta0(d); + Dart dx = mapx.beta0(d); fv1[dx] = Q*0.9f + QQ*0.1f; fv2[dx] = Q*0.52f + QQ*0.48f; fv2x[dx] = Q*0.48f + QQ*0.52f; @@ -475,15 +890,15 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions VEC3F* positionF2 = reinterpret_cast(PositionBuffer2); VEC3F* positionF3 = reinterpret_cast(PositionBuffer3); - m_nbRel2=0; - m_nbRel3=0; + m_nbRel2 = 0; + m_nbRel3 = 0; for(std::vector::iterator face = vecDartFaces.begin(); face != vecDartFaces.end(); ++face) { Dart d = *face; do { - Dart e = map.beta2(d); + Dart e = mapx.beta2(d); if (d < e) { *positionF2++ = PFP::toVec3f(fv2[d]); @@ -492,8 +907,8 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions *positionF2++ = PFP::toVec3f(fv2x[d]); m_nbRel2++; } - e = map.beta3(d); - if (!map.isBoundaryMarked3(e) && (d < e)) + e = mapx.beta3(d); + if (!mapx.isBoundaryMarked<3>(e) && (d < e)) { *positionF3++ = PFP::toVec3f(fv2[d]); *positionF3++ = PFP::toVec3f(fv2x[e]); @@ -501,8 +916,8 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions *positionF3++ = PFP::toVec3f(fv2x[d]); m_nbRel3++; } - d = map.beta0(d); - e = map.beta2(d); + d = mapx.beta0(d); + e = mapx.beta2(d); if (d < e) { *positionF2++ = PFP::toVec3f(fv2[d]); @@ -511,8 +926,8 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions *positionF2++ = PFP::toVec3f(fv2x[d]); m_nbRel2++; } - e = map.beta3(d); - if (!map.isBoundaryMarked3(e) && (d < e)) + e = mapx.beta3(d); + if (!mapx.isBoundaryMarked<3>(e) && (d < e)) { *positionF3++ = PFP::toVec3f(fv2[d]); *positionF3++ = PFP::toVec3f(fv2x[e]); @@ -521,7 +936,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions m_nbRel3++; } *positionF1++ = PFP::toVec3f(fv1[d]); - d = map.beta1(d); + d = mapx.beta1(d); *positionF1++ = PFP::toVec3f(fv1[d]); m_nbRel1++; } while (d != *face ); @@ -541,7 +956,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const EMBV& positions } template -void Topo3Render::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl) +void Topo3Render::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl) { typedef Geom::Vec3f VEC3F; typedef typename PFP::VEC3 VEC3; @@ -560,7 +975,7 @@ void Topo3Render::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribu } //template -//void Topo3Render::updateDataMap3OldFashioned(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv) +//void Topo3Render::updateDataMap3OldFashioned(typename PFP::MAP& mapx, const typename PFP::TVEC3& positions, float ke, float kf, float kv) //{ // Map3& map = reinterpret_cast(mapx); // @@ -783,7 +1198,7 @@ void Topo3Render::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribu template -Dart Topo3Render::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) +Dart Topo3Render::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -813,7 +1228,7 @@ Dart Topo3Render::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, } template -Dart Topo3Render::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) +Dart Topo3Render::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -892,12 +1307,6 @@ Dart Topo3Render::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, // vecEdges[i] = distndart[i].second; //} - - - - - - } //end namespace GL2 } //end namespace Render diff --git a/include/Algo/Render/GL2/topoPrimalRender.h b/include/Algo/Render/GL2/topoPrimalRender.h index 14adac28c38558a15ee572ed0c870e1c4bfa724c..05cbe5db2eceb29ed622270d53247b08cafdf351 100644 --- a/include/Algo/Render/GL2/topoPrimalRender.h +++ b/include/Algo/Render/GL2/topoPrimalRender.h @@ -22,8 +22,8 @@ * * *******************************************************************************/ -#ifndef _TOPO_PRIMAL_RENDER -#define _TOPO_PRIMAL_RENDER +#ifndef _TOPO_PRIMAL_RENDER_ +#define _TOPO_PRIMAL_RENDER_ #include #include @@ -40,7 +40,6 @@ #include "Utils/vbo_base.h" #include "Utils/svg.h" - namespace CGoGN { @@ -53,11 +52,10 @@ namespace Render namespace GL2 { - +template class TopoPrimalRender { protected: - /** * vbo buffers * 0: vertices darts @@ -111,8 +109,7 @@ protected: /** * attribute index to get easy correspondence dart/color */ - DartAttribute m_attIndex; - + DartAttribute m_attIndex; Geom::Vec3f* m_bufferDartPosition; @@ -135,7 +132,6 @@ protected: Dart pickColor(unsigned int x, unsigned int y); public: - /** * Constructor */ @@ -146,9 +142,8 @@ public: */ ~TopoPrimalRender(); - - Utils::GLSLShader* shader1() { return static_cast(m_shader1);} - Utils::GLSLShader* shader2() { return static_cast(m_shader2);} + Utils::GLSLShader* shader1() { return static_cast(m_shader1); } + Utils::GLSLShader* shader2() { return static_cast(m_shader2); } /** * set the with of line use to draw darts (default val is 2) @@ -218,7 +213,6 @@ public: /** * store darts in color for picking */ - template void setDartsIdColor(typename PFP::MAP& map); /** @@ -230,10 +224,8 @@ public: * @param y position of mouse (pass H-y, classic pb of origin) * @return the dart or NIL */ - template Dart picking(typename PFP::MAP& map, int x, int y); - /** * compute dart from color (for picking) */ @@ -244,31 +236,28 @@ public: */ void dartToCol(Dart d, float& r, float& g, float& b); - /** * update all drawing buffers to render a dual map * @param map the map * @param positions attribute of position vertices * @param ke exploding coef for edge */ - template - void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke); + void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke); /** * update color buffer with color attribute handler * @param map the map * @param colors attribute of dart's colors */ - template - void updateColors(typename PFP::MAP& map, const VertexAttribute& colors); + void updateColors(typename PFP::MAP& map, const VertexAttribute& colors); /** * Get back middle position of drawn darts * @param map the map * @param posExpl the output positions */ - template - void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl); + template + void computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl); /** * render to svg struct @@ -280,22 +269,18 @@ public: */ void svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj); - - template Dart coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle); - template Dart raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float distmax); }; +} // end namespace GL2 -}//end namespace GL2 - -}//end namespace Algo +} // end namespace Algo -}//end namespace Render +} // end namespace Render -}//end namespace CGoGN +} // end namespace CGoGN #include "Algo/Render/GL2/topoPrimalRender.hpp" diff --git a/include/Algo/Render/GL2/topoPrimalRender.hpp b/include/Algo/Render/GL2/topoPrimalRender.hpp index c600aca1683129fe0ba697b3d50c875cd3357490..796872fe840d0f3f22c04770e7089d0e52ed8b2c 100644 --- a/include/Algo/Render/GL2/topoPrimalRender.hpp +++ b/include/Algo/Render/GL2/topoPrimalRender.hpp @@ -43,12 +43,322 @@ namespace Render namespace GL2 { -template -void TopoPrimalRender::setDartsIdColor(typename PFP::MAP& map) +template +TopoPrimalRender::TopoPrimalRender(): + m_nbDarts(0), + m_nbRel1(0), + m_topo_dart_width(2.0f), + m_topo_relation_width(3.0f), + m_color_save(NULL), + m_dartsColor(1.0f,1.0f,1.0f), + m_boundaryDartsColor(0.5f,0.5f,0.5f), + m_bufferDartPosition(NULL) +{ + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + + m_shader1 = new Utils::ShaderSimpleColor(); + m_shader2 = new Utils::ShaderColorPerVertex(); + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + m_shader2->setAttributePosition(m_vbo0); + m_shader2->setAttributeColor(m_vbo2); + + // registering for auto matrices update + Utils::GLSLShader::registerShader(NULL, m_shader1); + Utils::GLSLShader::registerShader(NULL, m_shader2); +} + +template +TopoPrimalRender::~TopoPrimalRender() +{ + Utils::GLSLShader::unregisterShader(NULL, m_shader2); + Utils::GLSLShader::unregisterShader(NULL, m_shader1); + + delete m_shader2; + delete m_shader1; + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + + if (m_attIndex.isValid()) + m_attIndex.map()->removeAttribute(m_attIndex); + + if (m_color_save != NULL) + delete[] m_color_save; + + if (m_bufferDartPosition!=NULL) + delete[] m_bufferDartPosition; +} + +template +void TopoPrimalRender::setDartWidth(float dw) +{ + m_topo_dart_width = dw; +} + +template +void TopoPrimalRender::setRelationWidth(float pw) +{ + m_topo_relation_width = pw; +} + +template +void TopoPrimalRender::setDartColor(Dart d, float r, float g, float b) +{ + float RGB[6]; + RGB[0]=r; RGB[1]=g; RGB[2]=b; + RGB[3]=r; RGB[4]=g; RGB[5]=b; + m_vbo2->bind(); + glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); +} + +template +void TopoPrimalRender::setAllDartsColor(float r, float g, float b) { m_vbo2->bind(); - float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); - unsigned int nb=0; + GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); + for (unsigned int i=0; i < 2*m_nbDarts; ++i) + { + *colorDartBuf++ = r; + *colorDartBuf++ = g; + *colorDartBuf++ = b; + } + glUnmapBufferARB(GL_ARRAY_BUFFER); +} + +template +void TopoPrimalRender::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec3f(r,g,b); +} + +template +void TopoPrimalRender::setInitialBoundaryDartsColor(float r, float g, float b) +{ + m_boundaryDartsColor = Geom::Vec3f(r,g,b); +} + +template +void TopoPrimalRender::drawDarts() +{ + if (m_nbDarts==0) + return; + + m_shader2->enableVertexAttribs(); + + glLineWidth(m_topo_dart_width); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + // change the stride to take 1/2 vertices + m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); + + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + m_shader2->disableVertexAttribs(); +} + +template +void TopoPrimalRender::drawRelation1() +{ + if (m_nbRel1==0) + return; + + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(m_topo_relation_width); + glDrawArrays(GL_LINES, 0, m_nbRel1*2); + + m_shader1->disableVertexAttribs(); +} + +template +void TopoPrimalRender::drawTopo() +{ + drawDarts(); + drawRelation1(); +} + +template +void TopoPrimalRender::overdrawDart(Dart d, float width, float r, float g, float b) +{ + unsigned int indexDart = m_attIndex[d]; + + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(width); + glDrawArrays(GL_LINES, indexDart, 2); + + glPointSize(2.0f*width); + glDrawArrays(GL_POINTS, indexDart, 1); + + m_shader2->disableVertexAttribs(); +} + +template +void TopoPrimalRender::pushColors() +{ + m_color_save = new float[6*m_nbDarts]; + m_vbo2->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); +} + +template +void TopoPrimalRender::popColors() +{ + m_vbo2->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + delete[] m_color_save; + m_color_save=0; +} + +template +Dart TopoPrimalRender::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id == 0) + return NIL; + return Dart(id-1); +} + +template +void TopoPrimalRender::dartToCol(Dart d, float& r, float& g, float& b) +{ + // here use dart.index beacause it is what we want (and not map.dartIndex(d) !!) + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; +} + +template +Dart TopoPrimalRender::pickColor(unsigned int x, unsigned int y) +{ + //more easy picking for + unsigned int dw = m_topo_dart_width; + m_topo_dart_width+=2; + + // save clear color and set to zero + float cc[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); + + glClearColor(0.0f,0.0f,0.0f,0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + // draw in back buffer (not shown on screen) + + drawDarts(); + + // restore dart with + m_topo_dart_width = dw; + + // read the pixel under the mouse in back buffer + glReadBuffer(GL_BACK); + float color[3]; + glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); + + glClearColor(cc[0], cc[1], cc[2], cc[3]); + + std::cout << color[0] << ", "< +void TopoPrimalRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) +{ + Utils::SVG::SVGOut svg(filename,model,proj); + toSVG(svg); + svg.write(); +} + +template +void TopoPrimalRender::toSVG(Utils::SVG::SVGOut& svg) +{ + // alpha2 + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("alpha2", svg.m_model, svg.m_proj); + Geom::Vec3f* ptr = reinterpret_cast(m_vbo1->lockPtr()); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); + for (unsigned int i=0; iaddLine(P, Q, Geom::Vec3f(0.8f,0.0f,0.0f)); + } + svg2->endLines(); + m_vbo1->releasePtr(); + svg.addGroup(svg2); + + const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo2->lockPtr()); + ptr= reinterpret_cast(m_vbo0->lockPtr()); + + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); + + svg4->beginLines(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg4->addLine(ptr[2*i], ptr[2*i+1], col); + } + svg4->endLines(); + + svg.addGroup(svg4); + + Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg5->setWidth(m_topo_dart_width); + svg5->beginPoints(); + for (unsigned int i=0; i2.9f) + col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; + svg5->addPoint(ptr[2*i], col); + } + svg5->endPoints(); + svg.addGroup(svg5); + + m_vbo0->releasePtr(); + m_vbo2->releasePtr(); +} + +template +void TopoPrimalRender::setDartsIdColor(typename PFP::MAP& map) +{ + m_vbo2->bind(); + float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); + unsigned int nb = 0; for (Dart d = map.begin(); d != map.end(); map.next(d)) { @@ -75,12 +385,12 @@ void TopoPrimalRender::setDartsIdColor(typename PFP::MAP& map) glUnmapBuffer(GL_ARRAY_BUFFER); } -template -void TopoPrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribute& colors) +template +void TopoPrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribute& colors) { m_vbo2->bind(); - Geom::Vec3f* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); - unsigned int nb=0; + Geom::Vec3f* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); + unsigned int nb = 0; for (Dart d = map.begin(); d != map.end(); map.next(d)) { @@ -98,24 +408,20 @@ void TopoPrimalRender::updateColors(typename PFP::MAP& map, const VertexAttribut glUnmapBuffer(GL_ARRAY_BUFFER); } -template -Dart TopoPrimalRender::picking(typename PFP::MAP& map, int x, int y) +template +Dart TopoPrimalRender::picking(typename PFP::MAP& map, int x, int y) { pushColors(); - setDartsIdColor(map); + setDartsIdColor(map); Dart d = pickColor(x,y); popColors(); return d; } -template -void TopoPrimalRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke) +template +void TopoPrimalRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke) { typedef typename PFP::VEC3 VEC3; - typedef typename PFP::REAL REAL; - - typedef typename PFP::VEC3 VEC3; - typedef typename PFP::REAL REAL; if (m_attIndex.map() != &map) m_attIndex = map.template getAttribute("dart_index"); @@ -129,27 +435,24 @@ void TopoPrimalRender::updateData(typename PFP::MAP& map, const VertexAttribute< // } m_nbDarts = map.getNbDarts(); - - DartAutoAttribute fv1(map); + DartAutoAttribute fv1(map); m_vbo2->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - - if (m_bufferDartPosition!=NULL) + if (m_bufferDartPosition != NULL) delete m_bufferDartPosition; m_bufferDartPosition = new Geom::Vec3f[2*m_nbDarts]; VEC3* positionDartBuf = reinterpret_cast(m_bufferDartPosition); - std::vector vecDartFaces; vecDartFaces.reserve(m_nbDarts/6); unsigned int posDBI=0; //traverse each edge - TraversorE traEdge(map); + TraversorE traEdge(map); for (Dart d = traEdge.begin(); d != traEdge.end(); d = traEdge.next()) { @@ -211,12 +514,12 @@ void TopoPrimalRender::updateData(typename PFP::MAP& map, const VertexAttribute< // alpha1 m_vbo1->bind(); - glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(typename PFP::VEC3), 0, GL_STREAM_DRAW); + glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3), 0, GL_STREAM_DRAW); GLvoid* PositionBuffer1 = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); VEC3* positionF1 = reinterpret_cast(PositionBuffer1); - m_nbRel1=0; + m_nbRel1 = 0; for (Dart d = map.begin(); d != map.end(); map.next(d)) { @@ -232,25 +535,21 @@ void TopoPrimalRender::updateData(typename PFP::MAP& map, const VertexAttribute< glBindBuffer(GL_ARRAY_BUFFER, 0); } -template -void TopoPrimalRender::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl) +template +void TopoPrimalRender::computeDartMiddlePositions(typename PFP::MAP& map, DartAttribute& posExpl) { m_vbo0->bind(); - typename PFP::VEC3* positionsPtr = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); + VEC3* positionsPtr = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY)); for (Dart d = map.begin(); d != map.end(); map.next(d)) - { posExpl[d] = (positionsPtr[m_attIndex[d]] + positionsPtr[m_attIndex[d]+1])*0.5f; - } m_vbo0->bind(); glUnmapBuffer(GL_ARRAY_BUFFER); } - - -template -Dart TopoPrimalRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) +template +Dart TopoPrimalRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -279,8 +578,8 @@ Dart TopoPrimalRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& return dFinal; } -template -Dart TopoPrimalRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) +template +Dart TopoPrimalRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -291,7 +590,7 @@ Dart TopoPrimalRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& r { // get back position of segment PQ const Geom::Vec3f& P = m_bufferDartPosition[m_attIndex[d]]; - const Geom::Vec3f& Q =m_bufferDartPosition[m_attIndex[d]+1]; + const Geom::Vec3f& Q = m_bufferDartPosition[m_attIndex[d]+1]; float ld2 = Geom::squaredDistanceLine2Seg(rayA, rayAB, AB2, P, Q); if (ld2 class TopoRender { protected: @@ -114,7 +114,7 @@ protected: /** * attribut d'index dans le VBO */ - DartAttribute m_attIndex; + DartAttribute m_attIndex; Geom::Vec3f* m_bufferDartPosition; @@ -139,7 +139,6 @@ protected: /** * affect a color to each dart */ - template void setDartsIdColor(typename PFP::MAP& map, bool withBoundary); /** @@ -171,7 +170,7 @@ public: void setDartWidth(float dw); /** - * set the with of line use to draw phi (default val is ") + * set the with of line use to draw phi (default val is 3) * @param pw width */ void setRelationWidth(float pw); @@ -234,7 +233,6 @@ public: */ void overdrawDart(Dart d, float width, float r, float g, float b); - /** * pick dart with color set by setDartsIdColor * Do not forget to apply same transformation to scene before picking than before drawing ! @@ -243,32 +241,22 @@ public: * @param y position of mouse (pass H-y, classic pb of origin) * @return the dart or NIL */ - template Dart picking(typename PFP::MAP& map, int x, int y, bool withBoundary=false); - - template Dart coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle); - template Dart raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float distmax); + void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); + void updateDataMap(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); - template - void updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); - - template - void updateDataMap(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); - - template - void updateDataGMap(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); + void updateDataGMap(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary = false); /** * Special update function used to draw boundary of map3 */ - template - void updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float ns); + void updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, float ns); /** * render to svg struct @@ -293,10 +281,6 @@ public: void setBoundaryShift(float bs); }; -// just for compatibility with old code -typedef TopoRender TopoRenderMapD; -typedef TopoRender TopoRenderGMap; - } // namespace GL2 } // namespace Render @@ -305,7 +289,6 @@ typedef TopoRender TopoRenderGMap; } // namespace CGoGN - #include "Algo/Render/GL2/topoRender.hpp" #endif diff --git a/include/Algo/Render/GL2/topoRender.hpp b/include/Algo/Render/GL2/topoRender.hpp index 9404240cd9a0ffaa888f7780f9303bc8f4ba3ecc..b80077367be0ca3732a5b8c5e928857b44a8e51b 100644 --- a/include/Algo/Render/GL2/topoRender.hpp +++ b/include/Algo/Render/GL2/topoRender.hpp @@ -49,42 +49,421 @@ namespace Render namespace GL2 { +template +TopoRender::TopoRender(float bs): + m_nbDarts(0), + m_nbRel2(0), + m_topo_dart_width(2.0f), + m_topo_relation_width(3.0f), + m_normalShift(0.0f), + m_boundShift(bs), + m_dartsColor(1.0f,1.0f,1.0f), + m_dartsBoundaryColor(0.7f,1.0f,0.7f), + m_bufferDartPosition(NULL) +{ + m_vbo0 = new Utils::VBO(); + m_vbo1 = new Utils::VBO(); + m_vbo2 = new Utils::VBO(); + m_vbo3 = new Utils::VBO(); + + m_vbo0->setDataSize(3); + m_vbo1->setDataSize(3); + m_vbo2->setDataSize(3); + m_vbo3->setDataSize(3); + + m_shader1 = new Utils::ShaderSimpleColor(); + m_shader2 = new Utils::ShaderColorPerVertex(); + + // binding VBO - VA + m_vaId = m_shader1->setAttributePosition(m_vbo1); + + m_shader2->setAttributePosition(m_vbo0); + m_shader2->setAttributeColor(m_vbo3); + + // registering for auto matrices update + Utils::GLSLShader::registerShader(NULL, m_shader1); + Utils::GLSLShader::registerShader(NULL, m_shader2); +} + +template +TopoRender::~TopoRender() +{ + Utils::GLSLShader::unregisterShader(NULL, m_shader2); + Utils::GLSLShader::unregisterShader(NULL, m_shader1); + + delete m_shader2; + delete m_shader1; + delete m_vbo3; + delete m_vbo2; + delete m_vbo1; + delete m_vbo0; + + if (m_attIndex.isValid()) + m_attIndex.map()->removeAttribute(m_attIndex); + + if (m_bufferDartPosition!=NULL) + delete[] m_bufferDartPosition; +} + +template +void TopoRender::setDartWidth(float dw) +{ + m_topo_dart_width = dw; +} + +template +void TopoRender::setRelationWidth(float pw) +{ + m_topo_relation_width = pw; +} + +template +void TopoRender::setDartColor(Dart d, float r, float g, float b) +{ + float RGB[6]; + RGB[0]=r; RGB[1]=g; RGB[2]=b; + RGB[3]=r; RGB[4]=g; RGB[5]=b; + m_vbo3->bind(); + glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); +} + +template +void TopoRender::setAllDartsColor(float r, float g, float b) +{ + m_vbo3->bind(); + GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); + float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); + for (unsigned int i=0; i < 2*m_nbDarts; ++i) + { + *colorDartBuf++ = r; + *colorDartBuf++ = g; + *colorDartBuf++ = b; + } + + m_vbo3->bind(); + glUnmapBuffer(GL_ARRAY_BUFFER); +} + +template +void TopoRender::setInitialDartsColor(float r, float g, float b) +{ + m_dartsColor = Geom::Vec3f(r,g,b); +} + +template +void TopoRender::setInitialBoundaryDartsColor(float r, float g, float b) +{ + m_dartsBoundaryColor = Geom::Vec3f(r,g,b); +} + +template +void TopoRender::drawDarts() +{ + if (m_nbDarts==0) + return; + + m_shader2->enableVertexAttribs(); + + glLineWidth(m_topo_dart_width); + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + // change the stride to take 1/2 vertices + m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); + + glPointSize(2.0f*m_topo_dart_width); + glDrawArrays(GL_POINTS, 0, m_nbDarts); + + m_shader2->disableVertexAttribs(); +} + +template +void TopoRender::drawRelation1() +{ + if (m_nbDarts==0) + return; + + glLineWidth(m_topo_relation_width); + + m_shader1->changeVA_VBO(m_vaId, m_vbo1); + m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_LINES, 0, m_nbDarts*2); + + m_shader1->disableVertexAttribs(); +} + +template +void TopoRender::drawRelation2() +{ + if (m_nbRel2==0) + return; + + glLineWidth(m_topo_relation_width); + + m_shader1->changeVA_VBO(m_vaId, m_vbo2); + m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); + m_shader1->enableVertexAttribs(); + + glDrawArrays(GL_LINES, 0, m_nbRel2*2); + + m_shader1->disableVertexAttribs(); +} template -void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf,float ns) +void TopoRender::drawTopo() +{ + drawDarts(); + drawRelation1(); + drawRelation2(); +} + +template +void TopoRender::overdrawDart(Dart d, float width, float r, float g, float b) +{ + unsigned int indexDart = m_attIndex[d]; + + m_shader1->changeVA_VBO(m_vaId, m_vbo0); + m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); + m_shader1->enableVertexAttribs(); + + glLineWidth(width); + glDrawArrays(GL_LINES, indexDart, 2); + + glPointSize(2.0f*width); + glDrawArrays(GL_POINTS, indexDart, 1); + + m_shader2->disableVertexAttribs(); +} + +template +Dart TopoRender::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id == 0) + return NIL; + return Dart(id-1); +} + +template +void TopoRender::dartToCol(Dart d, float& r, float& g, float& b) +{ + // here use d.index beacause it is what we want (and not map.dartIndex(d) !!) + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; +} + +template +Dart TopoRender::pickColor(unsigned int x, unsigned int y) +{ + //more easy picking for + unsigned int dw = m_topo_dart_width; + m_topo_dart_width+=2; + + // save clear color and set to zero + float cc[4]; + glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); + + glClearColor(0.0f,0.0f,0.0f,0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glDisable(GL_LIGHTING); + // draw in back buffer (not shown on screen) + drawDarts(); + + // restore dart width + m_topo_dart_width = dw; + + // read the pixel under the mouse in back buffer + glReadBuffer(GL_BACK); + float color[3]; + glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); + + glClearColor(cc[0], cc[1], cc[2], cc[3]); + + return colToDart(color); +} + +template +void TopoRender::pushColors() +{ + m_color_save = new float[6*m_nbDarts]; + m_vbo3->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); +} + +template +void TopoRender::popColors() +{ + m_vbo3->bind(); + void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); + + memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); + glUnmapBuffer(GL_ARRAY_BUFFER); + + delete[] m_color_save; + m_color_save=NULL; +} + +template +void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) +{ + Utils::SVG::SVGOut svg(filename,model,proj); + toSVG(svg); + svg.write(); +} + +template +void TopoRender::toSVG(Utils::SVG::SVGOut& svg) +{ +// svg.setWidth(m_topo_relation_width); +// +// // PHI2 / beta2 +// const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); +// svg.beginLines(); +// for (unsigned int i=0; ireleasePtr(); +// +// //PHI1 /beta1 +// ptr = reinterpret_cast(m_vbo1->lockPtr()); +// svg.beginLines(); +// for (unsigned int i=0; ireleasePtr(); +// +// +// const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); +// ptr= reinterpret_cast(m_vbo0->lockPtr()); +// +// svg.setWidth(m_topo_dart_width); +// svg.beginLines(); +// for (unsigned int i=0; ireleasePtr(); +// m_vbo3->releasePtr(); + + // PHI2 / beta2 + Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); + svg1->setToLayer(); + const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); + svg1->setWidth(m_topo_relation_width); + svg1->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.8f,0.0f,0.0f)); + svg1->endLines(); + m_vbo2->releasePtr(); + + svg.addGroup(svg1); + + //PHI1 /beta1 + Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); + svg2->setToLayer(); + ptr = reinterpret_cast(m_vbo1->lockPtr()); + svg2->setWidth(m_topo_relation_width); + svg2->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); + svg2->endLines(); + m_vbo1->releasePtr(); + + svg.addGroup(svg2); + + const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); + ptr= reinterpret_cast(m_vbo0->lockPtr()); + + Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); + svg3->setToLayer(); + svg3->setWidth(m_topo_dart_width); + svg3->beginLines(); + for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1], colorsPtr[2*i]); + svg3->endLines(); + + svg.addGroup(svg3); + + Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); + svg4->setWidth(m_topo_dart_width); + svg4->setToLayer(); + svg4->beginPoints(); + for (unsigned int i=0; iaddPoint(ptr[2*i], colorsPtr[2*i]); + svg4->endPoints(); + + svg.addGroup(svg4); + + m_vbo0->releasePtr(); + m_vbo3->releasePtr(); +} + +template +void TopoRender::setNormalShift(float ns) +{ + m_normalShift = ns; +} + +template +void TopoRender::setBoundaryShift(float bs) +{ + m_boundShift = bs; +} + +template +void TopoRender::updateDataBoundary(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf,float ns) { m_normalShift = ns; SelectorDartBoundary sdb(map); - DartContainerBrowserSelector browser(map,sdb); + DartContainerBrowserSelector browser(map, sdb); browser.enable(); - updateData(map,positions, ke, kf,true); + updateData(map, positions, ke, kf, true); browser.disable(); m_normalShift = 0.0f; } - template -void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary) +void TopoRender::updateData(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary) { if (map.mapTypeName()[0] == "M") // "Map2" { - updateDataMap(map, positions, ke, kf, withBoundary); + updateDataMap(map, positions, ke, kf, withBoundary); return; } if (map.mapTypeName()[0] == "G") // "GMap2" { - updateDataGMap(map, positions, ke, kf, withBoundary); + updateDataGMap(map, positions, ke, kf, withBoundary); return; } } - - template -void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf, bool withBoundary) +void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf, bool withBoundary) { //Map2& map = reinterpret_cast(mapx); + typedef typename PFP::MAP MAP; typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -98,20 +477,19 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute("dart_index2"); - for(Dart d = mapx.begin(); d!= mapx.end(); mapx.next(d)) + for(Dart d = mapx.begin(); d != mapx.end(); mapx.next(d)) { if (withBoundary || !mapx.isBoundaryMarked2(d)) vecDarts.push_back(d); - } m_nbDarts = vecDarts.size(); // debut phi1 - DartAutoAttribute fv1(mapx); + DartAutoAttribute fv1(mapx); // fin phi1 - DartAutoAttribute fv11(mapx); + DartAutoAttribute fv11(mapx); // phi2 - DartAutoAttribute fv2(mapx); + DartAutoAttribute fv2(mapx); m_vbo3->bind(); glBufferData(GL_ARRAY_BUFFER, 2*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW); @@ -131,9 +509,9 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute vecPos; vecPos.reserve(16); - unsigned int indexDC=0; + unsigned int indexDC = 0; - DartMarker mf(mapx); + DartMarker mf(mapx); for(std::vector::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) { Dart d = *id; @@ -152,7 +530,6 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute 0.0f) { VEC3 normal = Algo::Surface::Geometry::newellNormal(mapx,d,positions); @@ -281,10 +658,11 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute -void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute& positions, float ke, float kf, bool withBoundary) +void TopoRender::updateDataGMap(typename PFP::MAP& map, const VertexAttribute& positions, float ke, float kf, bool withBoundary) { - GMap2& map = dynamic_cast(mapx); +// GMap2& map = dynamic_cast(mapx); + typedef typename PFP::MAP MAP; typedef typename PFP::VEC3 VEC3; typedef typename PFP::REAL REAL; @@ -300,7 +678,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute("dart_index2"); - for(Dart d = map.begin(); d!= map.end(); map.next(d)) + for(Dart d = map.begin(); d != map.end(); map.next(d)) { if (withBoundary || !map.isBoundaryMarked2(d)) vecDarts.push_back(d); @@ -308,11 +686,11 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute fv1(map); + DartAutoAttribute fv1(map); // fin phi1 - DartAutoAttribute fv11(map); + DartAutoAttribute fv11(map); // phi2 - DartAutoAttribute fv2(map); + DartAutoAttribute fv2(map); m_vbo3->bind(); glBufferData(GL_ARRAY_BUFFER, 4*m_nbDarts*sizeof(VEC3F), 0, GL_STREAM_DRAW); @@ -327,9 +705,9 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute vecPos; vecPos.reserve(16); - unsigned int indexDC=0; + unsigned int indexDC = 0; - DartMarker mf(map); + DartMarker mf(map); for(std::vector::iterator id = vecDarts.begin(); id!= vecDarts.end(); id++) { Dart d = *id; @@ -337,7 +715,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute(mapx,d,positions); + VEC3 center = Algo::Surface::Geometry::faceCentroidELW(map, d, positions); float k = 1.0f - kf; Dart dd = d; @@ -350,16 +728,15 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute 0.0f) { - VEC3 normal = Algo::Surface::Geometry::newellNormal(mapx,d,positions); + VEC3 normal = Algo::Surface::Geometry::newellNormal(map, d, positions); for (typename std::vector::iterator pit = vecPos.begin(); pit != vecPos.end(); ++pit) { - *pit -= normal*m_normalShift; + *pit -= normal * m_normalShift; } } unsigned int nb = vecPos.size(); vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop - k = 1.0f - ke; for (unsigned int i = 0; i < nb; ++i) { @@ -392,7 +769,6 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute(d); @@ -443,7 +819,7 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute -void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary) +void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary) { m_vbo3->bind(); float* colorBuffer = reinterpret_cast(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE)); @@ -452,7 +828,7 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary) m_attIndex = map.template getAttribute("dart_index2"); if (!m_attIndex.isValid()) { - CGoGNerr << "Error attribute_dartIndex does not exist during TopoRender::picking" << CGoGNendl; + CGoGNerr << "Error attribute_dartIndex does not exist during TopoRender::picking" << CGoGNendl; return; } @@ -486,20 +862,18 @@ void TopoRender::setDartsIdColor(typename PFP::MAP& map, bool withBoundary) } template -Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, bool withBoundary) +Dart TopoRender::picking(typename PFP::MAP& map,int x, int y, bool withBoundary) { pushColors(); - setDartsIdColor(map,withBoundary); + setDartsIdColor(map,withBoundary); Dart d = pickColor(x,y); popColors(); return d; } - - template -Dart TopoRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) +Dart TopoRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float angle) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -529,7 +903,7 @@ Dart TopoRender::coneSelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, } template -Dart TopoRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) +Dart TopoRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, const Geom::Vec3f& rayAB, float dmax) { float AB2 = rayAB*rayAB; Dart dFinal; @@ -556,11 +930,10 @@ Dart TopoRender::raySelection(typename PFP::MAP& map, const Geom::Vec3f& rayA, c return dFinal; } +} // end namespace GL2 -}//end namespace GL2 - -}//end namespace Algo +} // end namespace Algo -}//end namespace Render +} // end namespace Render -}//end namespace CGoGN +} // end namespace CGoGN diff --git a/include/Container/containerBrowser.h b/include/Container/containerBrowser.h index fcae12fad0bb4e4aa42dff99096ec08da2974d8f..1eefb4cbf3020ab95470a987edd226c63dbc5adb 100644 --- a/include/Container/containerBrowser.h +++ b/include/Container/containerBrowser.h @@ -57,15 +57,15 @@ public: -template +template class ContainerBrowserCellMarked : public ContainerBrowser { protected: AttributeContainer* m_cont ; - CellMarker& m_marker ; + CellMarker& m_marker ; public: - ContainerBrowserCellMarked(AttribMap& m, CellMarker& cm); + ContainerBrowserCellMarked(GenericMap& m, CellMarker& cm); ~ContainerBrowserCellMarked(); unsigned int begin() const; unsigned int end() const; @@ -87,7 +87,7 @@ protected: unsigned int m_end ; public: - ContainerBrowserLinked(AttribMap& m, unsigned int orbit); + ContainerBrowserLinked(GenericMap& m, unsigned int orbit); ContainerBrowserLinked(AttributeContainer& c); ContainerBrowserLinked(AttributeContainer& c, AttributeMultiVector* links); /** diff --git a/include/Container/containerBrowser.hpp b/include/Container/containerBrowser.hpp index e56a021e6b44cdfbeacc2cdf379146221c3cf812..94f1009411220e1bbe13adee5be6e1e8e83a8d80 100644 --- a/include/Container/containerBrowser.hpp +++ b/include/Container/containerBrowser.hpp @@ -84,7 +84,63 @@ inline void DartContainerBrowserSelector::disable() -inline ContainerBrowserLinked::ContainerBrowserLinked(AttribMap& m, unsigned int orbit): + +template +inline ContainerBrowserCellMarked::ContainerBrowserCellMarked(GenericMap& m, CellMarker& cm): + m_marker(cm) +{ + m_cont = &(m.getAttributeContainer()); +} + +template +inline ContainerBrowserCellMarked::~ContainerBrowserCellMarked() +{ +} + +template +inline unsigned int ContainerBrowserCellMarked::begin() const +{ + unsigned int it = m_cont->realBegin() ; + while ( (it != m_cont->realEnd()) && !m_marker.isMarked(it) ) + m_cont->realNext(it); + + return it; +} + +template +inline unsigned int ContainerBrowserCellMarked::end() const +{ + return m_cont->realEnd(); +} + +template +inline void ContainerBrowserCellMarked::next(unsigned int& it) const +{ + do + { + m_cont->realNext(it) ; + } + while ( (it != m_cont->realEnd()) && !m_marker.isMarked(it) ); +} + +template +inline void ContainerBrowserCellMarked::enable() +{ + m_cont->setContainerBrowser(this); +} + +template +inline void ContainerBrowserCellMarked::disable() +{ + m_cont->setContainerBrowser(NULL); +} + + + + + + +inline ContainerBrowserLinked::ContainerBrowserLinked(GenericMap& m, unsigned int orbit): autoAttribute(true), m_first(0xffffffff), m_end(0xffffffff) @@ -170,60 +226,4 @@ inline void ContainerBrowserLinked::disable() m_cont->setContainerBrowser(NULL); } - - - - - - -template -inline ContainerBrowserCellMarked::ContainerBrowserCellMarked(AttribMap& m, CellMarker& cm): - m_marker(cm) -{ - m_cont = &(m.getAttributeContainer()); -} - -template -inline ContainerBrowserCellMarked::~ContainerBrowserCellMarked() -{ -} - -template -inline unsigned int ContainerBrowserCellMarked::begin() const -{ - unsigned int it = m_cont->realBegin() ; - while ( (it != m_cont->realEnd()) && !m_marker.isMarked(it) ) - m_cont->realNext(it); - - return it; -} - -template -inline unsigned int ContainerBrowserCellMarked::end() const -{ - return m_cont->realEnd(); -} - -template -inline void ContainerBrowserCellMarked::next(unsigned int& it) const -{ - do - { - m_cont->realNext(it) ; - } - while ( (it != m_cont->realEnd()) && !m_marker.isMarked(it) ); -} - -template -inline void ContainerBrowserCellMarked::enable() -{ - m_cont->setContainerBrowser(this); -} - -template -inline void ContainerBrowserCellMarked::disable() -{ - m_cont->setContainerBrowser(NULL); -} - } // namespace CGoGN diff --git a/include/Geometry/vector_gen.h b/include/Geometry/vector_gen.h index d1b1e11d96e21f847737e950d249515f120eb656..b78ecebe61c48cdec4d906216f9b5dd33fb857c9 100644 --- a/include/Geometry/vector_gen.h +++ b/include/Geometry/vector_gen.h @@ -144,10 +144,10 @@ public: Vector normalized() const; // dot product - T operator*(const Vector v) const ; + T operator*(const Vector& v) const ; // cross product - Vector operator^(const Vector v) const ; + Vector operator^(const Vector& v) const ; // Equal bool operator==(const Vector& v) const ; @@ -256,6 +256,6 @@ typedef Vector<4, unsigned char> Vec4uc ; } -#include "vector_gen.hpp" +#include "Geometry/vector_gen.hpp" #endif diff --git a/include/Geometry/vector_gen.hpp b/include/Geometry/vector_gen.hpp index 036029fc704c0c8cef62a1631cc9ea0b8a277409..d8815b4647c9838fd2cb7b1f2759375b76691040 100644 --- a/include/Geometry/vector_gen.hpp +++ b/include/Geometry/vector_gen.hpp @@ -275,7 +275,7 @@ inline Vector Vector::normalized() const } template -inline T Vector::operator*(const Vector v) const +inline T Vector::operator*(const Vector& v) const { T d(0) ; for (unsigned int i = 0; i < DIM; ++i) @@ -284,7 +284,7 @@ inline T Vector::operator*(const Vector v) const } template -inline Vector Vector::operator^(const Vector v) const +inline Vector Vector::operator^(const Vector& v) const { CGoGN_STATIC_ASSERT(DIM == 3, incompatible_Vector_cross_product_dimension) ; Vector c ; diff --git a/include/Topology/generic/attribmap.h b/include/Topology/generic/attribmap.h index 94bd48b10f5535d005620ffbd5017938f4f81c77..3dfb3858b2a7e7e1c0d781e5919976705ab46dbb 100644 --- a/include/Topology/generic/attribmap.h +++ b/include/Topology/generic/attribmap.h @@ -43,80 +43,6 @@ public: virtual void clear(bool removeAttrib) ; - /**************************************** - * ATTRIBUTES MANAGEMENT * - ****************************************/ - - /** - * Create an attribute for a given orbit - * @param nameAttr attribute name - * @return an AttributeHandler - */ - template - AttributeHandler addAttribute(const std::string& nameAttr) ; - - /** - * remove an attribute - * @param attr a handler to the attribute to remove - * @return true if remove succeed else false - */ - template - bool removeAttribute(AttributeHandler& attr) ; - - /** - * search an attribute for a given orbit - * @param nameAttr attribute name - * @return an AttributeHandler - */ - template - AttributeHandler getAttribute(const std::string& nameAttr) ; - - /** - * @brief get a generic pointer to an existing attribute multi vector - * @param orbit the concerned orbit - * @param nameAttr attribute name - * @return a pointer to an AttributeMultiVectorGen - */ - AttributeMultiVectorGen* getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr) ; - - /** - * check if an attribute exist ( get, test if valid and add if necessary) - * @param nameAttr attribute name - * @return an AttributeHandler - */ - template - AttributeHandler checkAttribute(const std::string& nameAttr) ; - - /** - * swap the content of two attributes (efficient, only swap pointers) - */ - template - bool swapAttributes(AttributeHandler& attr1, AttributeHandler& attr2) ; - - /** - * copy the content of src attribute to dst attribute - */ - template - bool copyAttribute(AttributeHandler& dst, AttributeHandler& src) ; - - - /**************************************** - * UTILITIES * - ****************************************/ - - /** - * use the given attribute to store the indices of the cells of the corresponding orbit - * @return the number of cells of the orbit - */ - template - unsigned int computeIndexCells(AttributeHandler& idx) ; - - /** - * ensure that each orbit as one embedding and that each embedding is handle by only one orbit - */ - template - void bijectiveOrbitEmbedding(); - } ; } // namespace CGoGN diff --git a/include/Topology/generic/attribmap.hpp b/include/Topology/generic/attribmap.hpp index d3f8a65a8a2c062af9aaf0ff742c304fe54a774a..c9d251d9e9e0d591fd05f5bd3290535663793538 100644 --- a/include/Topology/generic/attribmap.hpp +++ b/include/Topology/generic/attribmap.hpp @@ -25,118 +25,5 @@ namespace CGoGN { -template -inline AttributeHandler AttribMap::addAttribute(const std::string& nameAttr) -{ - if(!isOrbitEmbedded()) - addEmbedding() ; - AttributeMultiVector* amv = m_attribs[ORBIT].addAttribute(nameAttr) ; - return AttributeHandler(this, amv) ; -} - -template -inline bool AttribMap::removeAttribute(AttributeHandler& attr) -{ - assert(attr.isValid() || !"Invalid attribute handler") ; - if(m_attribs[attr.getOrbit()].template removeAttribute(attr.getIndex())) - { - AttributeMultiVectorGen* amv = attr.getDataVector(); - typedef std::multimap::iterator IT ; - std::pair bounds = attributeHandlers.equal_range(amv) ; - for(IT i = bounds.first; i != bounds.second; ++i) - (*i).second->setInvalid() ; - attributeHandlers.erase(bounds.first, bounds.second) ; - return true ; - } - return false ; -} - -template -inline AttributeHandler AttribMap::getAttribute(const std::string& nameAttr) -{ - AttributeMultiVector* amv = m_attribs[ORBIT].getDataVector(nameAttr) ; - return AttributeHandler(this, amv) ; -} - -template -inline AttributeHandler AttribMap::checkAttribute(const std::string& nameAttr) -{ - AttributeHandler att = this->getAttribute(nameAttr); - if (!att.isValid()) - att = this->addAttribute(nameAttr); - return att; -} - - - -template -inline bool AttribMap::swapAttributes(AttributeHandler& attr1, AttributeHandler& attr2) -{ - assert((attr1.isValid() && attr2.isValid()) || !"Invalid attribute handler") ; -// assert(attr1.getOrbit() == attr2.getOrbit() || !"Cannot swap attributes of different orbits") ; -// unsigned int orbit = attr1.getOrbit() ; - unsigned int index1 = attr1.getIndex() ; - unsigned int index2 = attr2.getIndex() ; - if(index1 != index2) - return m_attribs[ORBIT].swapAttributes(index1, index2) ; - return false ; -} - -template -inline bool AttribMap::copyAttribute(AttributeHandler& dst, AttributeHandler& src) -{ - assert((dst.isValid() && src.isValid()) || !"Invalid attribute handler") ; -// unsigned int orbit = dst.getOrbit() ; -// assert(orbit == src.getOrbit() || !"Cannot copy attributes of different orbits") ; - unsigned int index_dst = dst.getIndex() ; - unsigned int index_src = src.getIndex() ; - if(index_dst != index_src) - return m_attribs[ORBIT].copyAttribute(index_dst, index_src) ; - return false ; -} - -/**************************************** - * UTILITIES * - ****************************************/ - -template -unsigned int AttribMap::computeIndexCells(AttributeHandler& idx) -{ - AttributeContainer& cont = m_attribs[ORBIT] ; - unsigned int cpt = 0 ; - for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) - idx[i] = cpt++ ; - return cpt ; -} - -template -void AttribMap::bijectiveOrbitEmbedding() -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded") ; - - AttributeHandler counter = addAttribute("tmpCounter") ; - counter.setAllValues(int(0)) ; - - DartMarker mark(*this) ; - for(Dart d = begin(); d != end(); next(d)) - { - if(!mark.isMarked(d)) - { - mark.markOrbit(d) ; - unsigned int emb = getEmbedding(d) ; - if (emb != EMBNULL) - { - if (counter[d] > 0) - { - unsigned int newEmb = setOrbitEmbeddingOnNewCell(d) ; - copyCell(newEmb, emb) ; - } - counter[d]++ ; - } - } - } - - removeAttribute(counter) ; -} } // namespace CGoGN diff --git a/include/Topology/generic/attributeHandler.h b/include/Topology/generic/attributeHandler.h index dedf32197c3b964d1b815251d1edfc9e9515088c..81b7a8924a793891c4a383244a525a3d50c1d8e4 100644 --- a/include/Topology/generic/attributeHandler.h +++ b/include/Topology/generic/attributeHandler.h @@ -29,6 +29,7 @@ #include #include "Topology/generic/genericmap.h" +#include "Container/attributeContainer.h" #include "Container/fakeAttribute.h" namespace CGoGN @@ -38,24 +39,16 @@ class AttributeHandlerGen { protected: friend class GenericMap ; - friend class AttribMap ; + template friend class MapCommon; - // the map that contains the linked attribute - GenericMap* m_map ; // boolean that states the validity of the handler bool valid ; public: - AttributeHandlerGen(GenericMap* m, bool v) : - m_map(m), + AttributeHandlerGen(bool v) : valid(v) {} - GenericMap* map() const - { - return m_map ; - } - bool isValid() const { return valid ; @@ -77,6 +70,8 @@ protected: } } ; +template class MapCommon; + /** * Class that create an access-table to an existing attribute * Main available operations are: @@ -84,10 +79,12 @@ protected: * - [ dart ] * - begin / end / next to manage indexing */ -template +template class AttributeHandler : public AttributeHandlerGen { protected: + // the map that contains the linked attribute + MapCommon* m_map; // the multi-vector that contains attribute data AttributeMultiVector* m_attrib; @@ -108,13 +105,13 @@ public: * @param m the map which belong attribute * @param amv a pointer to the AttributeMultiVector */ - AttributeHandler(GenericMap* m, AttributeMultiVector* amv) ; + AttributeHandler(MapCommon* m, AttributeMultiVector* amv) ; /** * Copy constructor * @param ta the table attribute */ - AttributeHandler(const AttributeHandler& ta) ; + AttributeHandler(const AttributeHandler& ta) ; /** * Transmute Constructor @@ -122,26 +119,35 @@ public: * @param h the table attribute */ template - AttributeHandler(const AttributeHandler& h) ; + AttributeHandler(const AttributeHandler& h) ; /** * affectation operator * @param ta the table attribute to affect to this */ - AttributeHandler& operator=(const AttributeHandler& ta) ; + AttributeHandler& operator=(const AttributeHandler& ta) ; /** * transmuted affectation operator * @param ta the table attribute to affect to this */ template - AttributeHandler& operator=(const AttributeHandler& ta) ; + AttributeHandler& operator=(const AttributeHandler& ta) ; /** * Destructor (empty & virtual) */ virtual ~AttributeHandler() ; + /** + * @brief map + * @return the map that contains the attribute + */ + MapCommon* map() const + { + return m_map ; + } + /** * get attribute data vector */ @@ -237,77 +243,73 @@ public: } ; /** - * shortcut class for Vertex Attribute (Handler) + * shortcut class for Dart Attribute (Handler) */ -template -class DartAttribute : public AttributeHandler +template +class DartAttribute : public AttributeHandler { public: - DartAttribute() : AttributeHandler() {} - DartAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} - DartAttribute(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} - DartAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + DartAttribute() : AttributeHandler() {} + DartAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} + DartAttribute(MapCommon* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} + DartAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } }; - /** * shortcut class for Vertex Attribute (Handler) */ -template -class VertexAttribute : public AttributeHandler +template +class VertexAttribute : public AttributeHandler { public: - VertexAttribute() : AttributeHandler() {} - VertexAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} - VertexAttribute(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} - VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } - VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } - VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } - VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + VertexAttribute() : AttributeHandler() {} + VertexAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} + VertexAttribute(MapCommon* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} + VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + VertexAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } }; - /** * shortcut class for Edge Attribute (Handler) */ -template -class EdgeAttribute : public AttributeHandler +template +class EdgeAttribute : public AttributeHandler { public: - EdgeAttribute() : AttributeHandler() {} - EdgeAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} - EdgeAttribute(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} - EdgeAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + EdgeAttribute() : AttributeHandler() {} + EdgeAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} + EdgeAttribute(MapCommon* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} + EdgeAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } }; - /** * shortcut class for Face Attribute (Handler) */ -template -class FaceAttribute : public AttributeHandler +template +class FaceAttribute : public AttributeHandler { public: - FaceAttribute() : AttributeHandler() {} - FaceAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} - FaceAttribute(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} - FaceAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } - FaceAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + FaceAttribute() : AttributeHandler() {} + FaceAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} + FaceAttribute(MapCommon* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} + FaceAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + FaceAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } }; - /** * shortcut class for Volume Attribute (Handler) */ -template -class VolumeAttribute : public AttributeHandler +template +class VolumeAttribute : public AttributeHandler { public: - VolumeAttribute() : AttributeHandler() {} - VolumeAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} - VolumeAttribute(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} - VolumeAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } - VolumeAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + VolumeAttribute() : AttributeHandler() {} + VolumeAttribute(const AttributeHandler& ah) : AttributeHandler(ah) {} + VolumeAttribute(MapCommon* m, AttributeMultiVector* amv) : AttributeHandler(m,amv) {} + VolumeAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } + VolumeAttribute& operator=(const AttributeHandler& ah) { this->AttributeHandler::operator=(ah); return *this; } }; diff --git a/include/Topology/generic/attributeHandler.hpp b/include/Topology/generic/attributeHandler.hpp index 4cda4d79be791aaf9f1e1a4998c4db12ec804a7c..adc2e52ab5f5bf43fa961049277eeec8ac0024f5 100644 --- a/include/Topology/generic/attributeHandler.hpp +++ b/include/Topology/generic/attributeHandler.hpp @@ -25,15 +25,15 @@ namespace CGoGN { -template -inline void AttributeHandler::registerInMap() +template +inline void AttributeHandler::registerInMap() { boost::mutex::scoped_lock lockAH(m_map->attributeHandlersMutex); m_map->attributeHandlers.insert(std::pair(m_attrib, this)) ; } -template -inline void AttributeHandler::unregisterFromMap() +template +inline void AttributeHandler::unregisterFromMap() { typedef std::multimap::iterator IT ; @@ -52,14 +52,18 @@ inline void AttributeHandler::unregisterFromMap() // ================================================================= -template -AttributeHandler::AttributeHandler() : - AttributeHandlerGen(NULL, false), m_attrib(NULL) +template +AttributeHandler::AttributeHandler() : + AttributeHandlerGen(false), + m_map(NULL), + m_attrib(NULL) {} -template -AttributeHandler::AttributeHandler(GenericMap* m, AttributeMultiVector* amv) : - AttributeHandlerGen(m, false), m_attrib(amv) +template +AttributeHandler::AttributeHandler(MapCommon* m, AttributeMultiVector* amv) : + AttributeHandlerGen(false), + m_map(m), + m_attrib(amv) { if(m != NULL && amv != NULL && amv->getIndex() != AttributeContainer::UNKNOWN) { @@ -71,23 +75,23 @@ AttributeHandler::AttributeHandler(GenericMap* m, AttributeMultiVector valid = false ; } -template -AttributeHandler::AttributeHandler(const AttributeHandler& ta) : - AttributeHandlerGen(ta.m_map, ta.valid), +template +AttributeHandler::AttributeHandler(const AttributeHandler& ta) : + AttributeHandlerGen(ta.valid), + m_map(ta.m_map), m_attrib(ta.m_attrib) { if(valid) registerInMap() ; } -//template -//template -template +template template -AttributeHandler::AttributeHandler(const AttributeHandler& h) : - AttributeHandlerGen(h.m_map, h.valid) +AttributeHandler::AttributeHandler(const AttributeHandler& h) : + AttributeHandlerGen(h.valid), + m_map(h.m_map), + m_attrib(h.m_attrib) { - m_attrib = h.m_attrib; if(m_attrib->getOrbit() == ORBIT2) { if(valid) @@ -97,8 +101,8 @@ AttributeHandler::AttributeHandler(const AttributeHandler& valid = false; } -template -inline AttributeHandler& AttributeHandler::operator=(const AttributeHandler& ta) +template +inline AttributeHandler& AttributeHandler::operator=(const AttributeHandler& ta) { if(valid) unregisterFromMap() ; @@ -110,9 +114,9 @@ inline AttributeHandler& AttributeHandler::operator=(const A return *this ; } -template +template template -inline AttributeHandler& AttributeHandler::operator=(const AttributeHandler& ta) +inline AttributeHandler& AttributeHandler::operator=(const AttributeHandler& ta) { if(valid) unregisterFromMap() ; @@ -124,140 +128,139 @@ inline AttributeHandler& AttributeHandler::operator=(const A return *this ; } - -template -AttributeHandler::~AttributeHandler() +template +AttributeHandler::~AttributeHandler() { if(valid) unregisterFromMap() ; } -template -inline AttributeMultiVector* AttributeHandler::getDataVector() const +template +inline AttributeMultiVector* AttributeHandler::getDataVector() const { return m_attrib ; } -template -inline AttributeMultiVectorGen* AttributeHandler::getDataVectorGen() const +template +inline AttributeMultiVectorGen* AttributeHandler::getDataVectorGen() const { return m_attrib ; } -template -inline int AttributeHandler::getSizeOfType() const +template +inline int AttributeHandler::getSizeOfType() const { return sizeof(T) ; } -template -inline unsigned int AttributeHandler::getOrbit() const +template +inline unsigned int AttributeHandler::getOrbit() const { return ORBIT ; } -template -inline unsigned int AttributeHandler::getIndex() const +template +inline unsigned int AttributeHandler::getIndex() const { return m_attrib->getIndex() ; } -template -inline const std::string& AttributeHandler::name() const +template +inline const std::string& AttributeHandler::name() const { return m_attrib->getName() ; } -template -inline const std::string& AttributeHandler::typeName() const +template +inline const std::string& AttributeHandler::typeName() const { return m_attrib->getTypeName(); } -template -inline unsigned int AttributeHandler::nbElements() const +template +inline unsigned int AttributeHandler::nbElements() const { - return m_map->getAttributeContainer().size() ; + return m_map->template getAttributeContainer().size() ; } -template -inline T& AttributeHandler::operator[](Dart d) +template +inline T& AttributeHandler::operator[](Dart d) { assert(valid || !"Invalid AttributeHandler") ; - unsigned int a = m_map->getEmbedding(d) ; + unsigned int a = m_map->template getEmbedding(d) ; if (a == EMBNULL) - a = m_map->setOrbitEmbeddingOnNewCell(d) ; + a = m_map->template setOrbitEmbeddingOnNewCell(d) ; return m_attrib->operator[](a) ; } -template -inline const T& AttributeHandler::operator[](Dart d) const +template +inline const T& AttributeHandler::operator[](Dart d) const { assert(valid || !"Invalid AttributeHandler") ; - unsigned int a = m_map->getEmbedding(d) ; + unsigned int a = m_map->template getEmbedding(d) ; return m_attrib->operator[](a) ; } -template -inline T& AttributeHandler::operator[](unsigned int a) +template +inline T& AttributeHandler::operator[](unsigned int a) { assert(valid || !"Invalid AttributeHandler") ; return m_attrib->operator[](a) ; } -template -inline const T& AttributeHandler::operator[](unsigned int a) const +template +inline const T& AttributeHandler::operator[](unsigned int a) const { assert(valid || !"Invalid AttributeHandler") ; return m_attrib->operator[](a) ; } -template -inline unsigned int AttributeHandler::insert(const T& elt) +template +inline unsigned int AttributeHandler::insert(const T& elt) { assert(valid || !"Invalid AttributeHandler") ; - unsigned int idx = m_map->getAttributeContainer().insertLine() ; + unsigned int idx = m_map->template getAttributeContainer().insertLine() ; m_attrib->operator[](idx) = elt ; return idx ; } -template -inline unsigned int AttributeHandler::newElt() +template +inline unsigned int AttributeHandler::newElt() { assert(valid || !"Invalid AttributeHandler") ; - unsigned int idx = m_map->getAttributeContainer().insertLine() ; + unsigned int idx = m_map->template getAttributeContainer().insertLine() ; return idx ; } -template -inline void AttributeHandler::setAllValues(const T& v) +template +inline void AttributeHandler::setAllValues(const T& v) { for(unsigned int i = begin(); i != end(); next(i)) m_attrib->operator[](i) = v ; } -template -inline unsigned int AttributeHandler::begin() const +template +inline unsigned int AttributeHandler::begin() const { assert(valid || !"Invalid AttributeHandler") ; - return m_map->getAttributeContainer().begin() ; + return m_map->template getAttributeContainer().begin() ; } -template -inline unsigned int AttributeHandler::end() const +template +inline unsigned int AttributeHandler::end() const { assert(valid || !"Invalid AttributeHandler") ; - return m_map->getAttributeContainer().end() ; + return m_map->template getAttributeContainer().end() ; } -template -inline void AttributeHandler::next(unsigned int& iter) const +template +inline void AttributeHandler::next(unsigned int& iter) const { assert(valid || !"Invalid AttributeHandler") ; - m_map->getAttributeContainer().next(iter) ; + m_map->template getAttributeContainer().next(iter) ; } } //namespace CGoGN diff --git a/include/Topology/generic/autoAttributeHandler.h b/include/Topology/generic/autoAttributeHandler.h index 5ce1d2ea7e59c3200527e0509d0fb5259cd3efb7..314aff2d4fdf93362d3b0be424a8aa4f3c53687d 100644 --- a/include/Topology/generic/autoAttributeHandler.h +++ b/include/Topology/generic/autoAttributeHandler.h @@ -25,25 +25,23 @@ #ifndef __AUTO_ATTRIBUTE_HANDLER_H__ #define __AUTO_ATTRIBUTE_HANDLER_H__ -#include "Topology/generic/attribmap.h" #include "Topology/generic/attributeHandler.h" namespace CGoGN { - /** * shortcut class for Dart AutoAttribute (Handler) */ -template -class DartAutoAttribute : public DartAttribute +template +class DartAutoAttribute : public DartAttribute { public: - DartAutoAttribute(AttribMap& m, const std::string& nameAttr = "") + DartAutoAttribute(MapCommon& m, const std::string& nameAttr = "") { this->m_map = &m ; - if(!m.isOrbitEmbedded()) - m.addEmbedding() ; + if(!m.template isOrbitEmbedded()) + m.template addEmbedding() ; AttributeMultiVector* amv = this->m_map->template getAttributeContainer().template addAttribute(nameAttr) ; this->m_attrib = amv ; this->valid = true ; @@ -53,22 +51,22 @@ public: ~DartAutoAttribute() { if (this->valid) - reinterpret_cast(this->m_map)->removeAttribute(*this) ; + this->m_map->template removeAttribute(*this) ; } }; /** * shortcut class for Vertex AutoAttribute (Handler) */ -template -class VertexAutoAttribute : public VertexAttribute +template +class VertexAutoAttribute : public VertexAttribute { public: - VertexAutoAttribute(AttribMap& m, const std::string& nameAttr = "") + VertexAutoAttribute(MapCommon& m, const std::string& nameAttr = "") { this->m_map = &m ; - if(!m.isOrbitEmbedded()) - m.addEmbedding() ; + if(!m.template isOrbitEmbedded()) + m.template addEmbedding() ; AttributeMultiVector* amv = this->m_map->template getAttributeContainer().template addAttribute(nameAttr) ; this->m_attrib = amv ; this->valid = true ; @@ -78,22 +76,22 @@ public: ~VertexAutoAttribute() { if (this->valid) - reinterpret_cast(this->m_map)->removeAttribute(*this) ; + this->m_map->template removeAttribute(*this) ; } }; /** * shortcut class for Edge AutoAttribute (Handler) */ -template -class EdgeAutoAttribute : public EdgeAttribute +template +class EdgeAutoAttribute : public EdgeAttribute { public: - EdgeAutoAttribute(AttribMap& m, const std::string& nameAttr = "") + EdgeAutoAttribute(MapCommon& m, const std::string& nameAttr = "") { this->m_map = &m ; - if(!m.isOrbitEmbedded()) - m.addEmbedding() ; + if(!m.template isOrbitEmbedded()) + m.template addEmbedding() ; AttributeMultiVector* amv = this->m_map->template getAttributeContainer().template addAttribute(nameAttr) ; this->m_attrib = amv ; this->valid = true ; @@ -103,22 +101,22 @@ public: ~EdgeAutoAttribute() { if (this->valid) - reinterpret_cast(this->m_map)->removeAttribute(*this) ; + this->m_map->template removeAttribute(*this) ; } }; /** * shortcut class for Face AutoAttribute (Handler) */ -template -class FaceAutoAttribute : public FaceAttribute +template +class FaceAutoAttribute : public FaceAttribute { public: - FaceAutoAttribute(AttribMap& m, const std::string& nameAttr = "") + FaceAutoAttribute(MapCommon& m, const std::string& nameAttr = "") { this->m_map = &m ; - if(!m.isOrbitEmbedded()) - m.addEmbedding() ; + if(!m.template isOrbitEmbedded()) + m.template addEmbedding() ; AttributeMultiVector* amv = this->m_map->template getAttributeContainer().template addAttribute(nameAttr) ; this->m_attrib = amv ; this->valid = true ; @@ -128,22 +126,22 @@ public: ~FaceAutoAttribute() { if (this->valid) - reinterpret_cast(this->m_map)->removeAttribute(*this) ; + this->m_map->template removeAttribute(*this) ; } }; /** * shortcut class for Volume AutoAttribute (Handler) */ -template -class VolumeAutoAttribute : public VolumeAttribute +template +class VolumeAutoAttribute : public VolumeAttribute { public: - VolumeAutoAttribute(AttribMap& m, const std::string& nameAttr = "") + VolumeAutoAttribute(MAP_IMPL& m, const std::string& nameAttr = "") { this->m_map = &m ; - if(!m.isOrbitEmbedded()) - m.addEmbedding() ; + if(!m.template isOrbitEmbedded()) + m.template addEmbedding() ; AttributeMultiVector* amv = this->m_map->template getAttributeContainer().template addAttribute(nameAttr) ; this->m_attrib = amv ; this->valid = true ; @@ -153,11 +151,10 @@ public: ~VolumeAutoAttribute() { if (this->valid) - reinterpret_cast(this->m_map)->removeAttribute(*this) ; + this->m_map->template removeAttribute(*this) ; } }; - } // namespace CGoGN #endif diff --git a/include/Topology/generic/cellmarker.h b/include/Topology/generic/cellmarker.h index 78862ee3438c82936cadfa73bd0361683ae3893a..a211bbf387d949a7316c3a175f9571f2ed9e428c 100644 --- a/include/Topology/generic/cellmarker.h +++ b/include/Topology/generic/cellmarker.h @@ -155,9 +155,9 @@ public: assert(m_map.template getMarkerSet(m_thread).testMark(m_mark)); assert(m_markVector != NULL); - unsigned int a = m_map.getEmbedding(d) ; + unsigned int a = m_map.template getEmbedding(d) ; if (a == EMBNULL) - a = m_map.setOrbitEmbeddingOnNewCell(d) ; + a = m_map.template setOrbitEmbeddingOnNewCell(d) ; m_markVector->operator[](a).setMark(m_mark) ; } @@ -169,9 +169,9 @@ public: assert(m_map.template getMarkerSet(m_thread).testMark(m_mark)); assert(m_markVector != NULL); - unsigned int a = m_map.getEmbedding(d) ; + unsigned int a = m_map.template getEmbedding(d) ; if (a == EMBNULL) - a = m_map.setOrbitEmbeddingOnNewCell(d) ; + a = m_map.template setOrbitEmbeddingOnNewCell(d) ; m_markVector->operator[](a).unsetMark(m_mark) ; } @@ -183,7 +183,7 @@ public: assert(m_map.template getMarkerSet(m_thread).testMark(m_mark)); assert(m_markVector != NULL); - unsigned int a = m_map.getEmbedding(d) ; + unsigned int a = m_map.template getEmbedding(d) ; if (a == EMBNULL) return false ; return m_markVector->operator[](a).testMark(m_mark) ; diff --git a/include/Topology/generic/dartmarker.h b/include/Topology/generic/dartmarker.h index 06389662199d487f71906f7c3141393d23f7f5af..1b2f96edd8646bedd627c4524218c58c6cab186a 100644 --- a/include/Topology/generic/dartmarker.h +++ b/include/Topology/generic/dartmarker.h @@ -169,7 +169,7 @@ public: { assert(m_map.template getMarkerSet(m_thread).testMark(m_mark)); FunctorMark fm(m_map, m_mark, m_markVector) ; - m_map.foreach_dart_of_orbit(d, fm, m_thread) ; + m_map.template foreach_dart_of_orbit(d, fm, m_thread) ; } /** @@ -291,14 +291,14 @@ public: template inline void markOrbit(Dart d) { - assert(this->m_map.getMarkerSet(this->m_thread).testMark(this->m_mark)); + assert(this->m_map.template getMarkerSet(this->m_thread).testMark(this->m_mark)); FunctorMarkStore fm(this->m_map, this->m_mark, this->m_markVector, m_markedDarts) ; - this->m_map.foreach_dart_of_orbit(d, fm, this->m_thread) ; + this->m_map.template foreach_dart_of_orbit(d, fm, this->m_thread) ; } inline void unmarkAll() { - assert(this->m_map.getMarkerSet(this->m_thread).testMark(this->m_mark)); + assert(this->m_map.template getMarkerSet(this->m_thread).testMark(this->m_mark)); for (std::vector::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it) this->m_markVector->operator[](*it).unsetMark(this->m_mark) ; } diff --git a/include/Topology/generic/genericmap.h b/include/Topology/generic/genericmap.h index 19066d76f2e7cb1fe5dc811e6fd1140760b8d608..3ef2cc8c423bca328fb5e3dd9c2d7f213f54a363 100644 --- a/include/Topology/generic/genericmap.h +++ b/include/Topology/generic/genericmap.h @@ -54,12 +54,12 @@ class CellMarkerGen ; class GenericMap { - template friend class AttributeHandler ; - template friend class DartAutoAttribute ; - template friend class VertexAutoAttribute ; - template friend class EdgeAutoAttribute ; - template friend class FaceAutoAttribute ; - template friend class VolumeAutoAttribute ; + template friend class AttributeHandler ; + template friend class DartAutoAttribute ; + template friend class VertexAutoAttribute ; + template friend class EdgeAutoAttribute ; + template friend class FaceAutoAttribute ; + template friend class VolumeAutoAttribute ; friend class DartMarkerGen ; friend class CellMarkerGen ; template friend class CellMarkerBase ; @@ -108,6 +108,8 @@ protected: std::vector dartMarkers[NB_THREAD] ; std::vector cellMarkers[NB_THREAD] ; + void init(); + public: static const unsigned int UNKNOWN_ATTRIB = AttributeContainer::UNKNOWN ; @@ -157,30 +159,10 @@ protected: */ void deleteDartLine(unsigned int index) ; -public: - /** - * @brief dartIndex - * @param d - * @return index of dart (depends on map implementation) - */ -// virtual unsigned int dartIndex(Dart d) const = 0; - - /** - * get the Dart of index in topological table - */ -// virtual Dart indexDart(unsigned int index) const = 0; - - /** - * @return the number of darts in the map - */ - virtual unsigned int getNbDarts() ; - -// AttributeContainer& getDartContainer() = 0; - /**************************************** * EMBEDDING MANAGEMENT * ****************************************/ - +public: /** * tell if an orbit is embedded or not */ @@ -218,10 +200,10 @@ public: * QUICK TRAVERSAL MANAGEMENT * ****************************************/ - template + template void enableQuickTraversal() ; - template + template void updateQuickTraversal() ; template @@ -230,7 +212,6 @@ public: template void disableQuickTraversal() ; - template void enableQuickIncidentTraversal(); @@ -444,28 +425,6 @@ public: virtual bool foreach_dart_of_edge2(Dart /*d*/, FunctorType& /*f*/, unsigned int /*thread = 0*/) const { std::cerr << "Not implemented" << std::endl; return false; } virtual bool foreach_dart_of_face2(Dart /*d*/, FunctorType& /*f*/, unsigned int /*thread = 0*/) const { std::cerr << "Not implemented" << std::endl; return false; } - /** - * execute functor for each orbit - * @param dim the dimension of the orbit - * @param f the functor - */ - template - bool foreach_orbit(FunctorType& f, unsigned int thread = 0) const; - - - //! Count the number of orbits of dimension dim in the map - /*! @param dim the dimension of the orbit - * @return the number of orbits - */ - template - unsigned int getNbOrbits() const; - - //! 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 degree(Dart d) const; - /**************************************** * BOUNDARY MANAGEMENT * ****************************************/ @@ -474,46 +433,7 @@ protected: /// boundary markers Mark m_boundaryMarkers[2] ; // 0 for dim 2 / 1 for dim 3 - /** - * mark a dart as belonging to boundary - */ - template - void boundaryMark(Dart d) ; - void boundaryMark2(Dart d) ; - void boundaryMark3(Dart d) ; - - /** - * unmark a dart from the boundary - */ - template - void boundaryUnmark(Dart d) ; - void boundaryUnmark2(Dart d) ; - void boundaryUnmark3(Dart d) ; - -public: - /** - * test if a dart belong to the boundary - */ - template - bool isBoundaryMarked(Dart d) const ; - - bool isBoundaryMarked2(Dart d) const ; - bool isBoundaryMarked3(Dart d) const ; - bool isBoundaryMarkedCurrent(Dart d) const ; - protected: - /** - * mark an orbit of dart as belonging to boundary - */ - template - void boundaryMarkOrbit(Dart d) ; - - /** - * unmark an orbit of dart from the boundary - */ - template - void boundaryUnmarkOrbit(Dart d) ; - /** * clear all boundary markers */ diff --git a/include/Topology/generic/genericmap.hpp b/include/Topology/generic/genericmap.hpp index e6602d6ac8c7c721351d91852db1fb9031cc77bd..179c338a4fab1698a21d1f78a6d8bdc70a8f8dfa 100644 --- a/include/Topology/generic/genericmap.hpp +++ b/include/Topology/generic/genericmap.hpp @@ -85,11 +85,6 @@ inline unsigned int GenericMap::copyDartLine(unsigned int index) return newindex ; } -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)) ; @@ -135,7 +130,7 @@ inline void GenericMap::initCell(unsigned int i) * QUICK TRAVERSAL MANAGEMENT * ****************************************/ -template +template inline void GenericMap::enableQuickTraversal() { @@ -145,33 +140,22 @@ inline void GenericMap::enableQuickTraversal() addEmbedding() ; m_quickTraversal[ORBIT] = m_attribs[ORBIT].addAttribute("quick_traversal") ; } - updateQuickTraversal() ; + updateQuickTraversal() ; } -template +template inline void GenericMap::updateQuickTraversal() { assert(m_quickTraversal[ORBIT] != NULL || !"updateQuickTraversal on a disabled orbit") ; -// CellMarker cm(*this) ; -// for(Dart d = begin(); d != end(); next(d)) -// { -// if ((!cm.isMarked(d)) && (!isBoundaryMarkedCurrent(d))) -// { -// cm.mark(d) ; -// (*m_quickTraversal[ORBIT])[getEmbedding(d)] = d ; -// } -// } - - // ensure that we do not try to use quick traversal in Traversors - AttributeMultiVector* qt = m_quickTraversal[ORBIT]; - m_quickTraversal[ORBIT] = NULL; - - // fill the quick travsersal - TraversorCell trav(*this); - for(Dart d = trav.begin(); d != trav.end(); d=trav.next()) + CellMarker cm(*this) ; + for(Dart d = begin(); d != end(); next(d)) { - (*qt)[getEmbedding(d)] = d ; + if(!cm.isMarked(d)) + { + cm.mark(d) ; + (*m_quickTraversal[ORBIT])[MAP::getEmbedding(d)] = d ; + } } // restore ptr @@ -195,7 +179,6 @@ inline void GenericMap::disableQuickTraversal() } } - template inline void GenericMap::enableQuickIncidentTraversal() { @@ -423,39 +406,6 @@ bool GenericMap::foreach_dart_of_orbit(Dart d, FunctorType& f, unsigned int thre return false; } -template -bool GenericMap::foreach_orbit(FunctorType& fonct, unsigned int thread) const -{ - TraversorCell trav(*reinterpret_cast(this), true, thread); - bool found = false; - - for (Dart d = trav.begin(); !found && d != trav.end(); d = trav.next()) - { - if ((fonct)(d)) - found = true; - } - return found; -} - -template -unsigned int GenericMap::getNbOrbits() const -{ - FunctorCount fcount; - foreach_orbit(fcount); - return fcount.getNb(); -} - -template -unsigned int GenericMap::degree(Dart d) const -{ - assert(ORBIT != INCIDENT || !"degree does not manage adjacency counting") ; - Traversor* t = TraversorFactory::createIncident(*(reinterpret_cast(this)), d, dimension(), ORBIT, INCIDENT) ; - FunctorCount fcount ; - t->applyFunctor(fcount) ; - delete t ; - return fcount.getNb() ; -} - /**************************************** * TOPOLOGICAL ATTRIBUTES MANAGEMENT * ****************************************/ @@ -479,80 +429,10 @@ inline AttributeMultiVector* GenericMap::getRelation(const std::string& na return amv ; } - /************************** * BOUNDARY MANAGEMENT * **************************/ -template -inline void GenericMap::boundaryMark(Dart d) -{ - m_markTables[DART][0]->operator[](dartIndex(d)).setMark(m_boundaryMarkers[D-2]); -} - -template -inline void GenericMap::boundaryUnmark(Dart d) -{ - m_markTables[DART][0]->operator[](dartIndex(d)).unsetMark(m_boundaryMarkers[D-2]); -} - -template -inline bool GenericMap::isBoundaryMarked(Dart d) const -{ - return m_markTables[DART][0]->operator[](dartIndex(d)).testMark(m_boundaryMarkers[D-2]); -} - - -inline bool GenericMap::isBoundaryMarkedCurrent(Dart d) const -{ - return m_markTables[DART][0]->operator[](dartIndex(d)).testMark(m_boundaryMarkers[this->dimension()-2]); -} - - -inline void GenericMap::boundaryMark2(Dart d) -{ - boundaryMark<2>(d); -} - -inline void GenericMap::boundaryUnmark2(Dart d) -{ - boundaryUnmark<2>(d); -} - -inline bool GenericMap::isBoundaryMarked2(Dart d) const -{ - return isBoundaryMarked<2>(d); -} - -inline void GenericMap::boundaryMark3(Dart d) -{ - boundaryMark<3>(d); -} - -inline void GenericMap::boundaryUnmark3(Dart d) -{ - boundaryUnmark<3>(d); -} - -inline bool GenericMap::isBoundaryMarked3(Dart d) const -{ - return isBoundaryMarked<3>(d); -} - -template -void GenericMap::boundaryMarkOrbit(Dart d) -{ - FunctorMark fm(*this, m_boundaryMarkers[DIM-2], m_markTables[DART][0]) ; - foreach_dart_of_orbit(d, fm, 0) ; -} - -template -void GenericMap::boundaryUnmarkOrbit(Dart d) -{ - FunctorUnmark fm(*this, m_boundaryMarkers[DIM-2], m_markTables[DART][0]) ; - foreach_dart_of_orbit(d, fm, 0) ; -} - template void GenericMap::boundaryUnmarkAll() { diff --git a/include/Topology/generic/mapCommon.h b/include/Topology/generic/mapCommon.h new file mode 100644 index 0000000000000000000000000000000000000000..4debc6c3d0d374f8d26e8b40aab574875db7526d --- /dev/null +++ b/include/Topology/generic/mapCommon.h @@ -0,0 +1,259 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +#ifndef __MAP_COMMON__ +#define __MAP_COMMON__ + +#include "Topology/generic/mapMono.h" +#include "Topology/generic/attributeHandler.h" + +namespace CGoGN +{ + +template +class MapCommon : public MAP_IMPL +{ + typedef MAP_IMPL IMPL; + + /**************************************** + * DARTS TRAVERSALS * + ****************************************/ +public: + /** + * execute functor for each orbit + * @param dim the dimension of the orbit + * @param f the functor + */ + template + bool foreach_orbit(FunctorType& f, unsigned int thread = 0); + + //! Count the number of orbits of dimension dim in the map + /*! @param dim the dimension of the orbit + * @return the number of orbits + */ + template + unsigned int getNbOrbits(); + + //! 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 degree(Dart d) const; + + /**************************************** + * EMBEDDING MANAGEMENT * + ****************************************/ + + /** + * 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 + inline unsigned int getEmbedding(Dart d) const; + + /** + * Set the cell index of the given dimension associated to dart d + */ + template + 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 + 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 + inline void copyDartEmbedding(Dart dest, Dart src) ; + + /** + * 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 + 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 + 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 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 initOrbitEmbeddingOnNewCell(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 + void copyCell(Dart d, Dart e) ; + + /** + * 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 + void initAllOrbitsEmbedding(bool realloc = false) ; + + /**************************************** + * BOUNDARY MANAGEMENT * + ****************************************/ +protected: + /** + * mark a dart as belonging to boundary + */ + template + void boundaryMark(Dart d) ; + + /** + * unmark a dart from the boundary + */ + template + void boundaryUnmark(Dart d) ; + + /** + * mark an orbit of dart as belonging to boundary + */ + template + void boundaryMarkOrbit(Dart d) ; + + /** + * unmark an orbit of dart from the boundary + */ + template + void boundaryUnmarkOrbit(Dart d) ; + +public: + /** + * test if a dart belong to the boundary + */ + template + bool isBoundaryMarked(Dart d) const ; + bool isBoundaryMarkedCurrent(Dart d) const ; + + /**************************************** + * ATTRIBUTES MANAGEMENT * + ****************************************/ + + /** + * Create an attribute for a given orbit + * @param nameAttr attribute name + * @return an AttributeHandler + */ + template + inline AttributeHandler addAttribute(const std::string& nameAttr) ; + + /** + * remove an attribute + * @param attr a handler to the attribute to remove + * @return true if remove succeed else false + */ + template + inline bool removeAttribute(AttributeHandler& attr) ; + + /** + * search an attribute for a given orbit + * @param nameAttr attribute name + * @return an AttributeHandler + */ + template + inline AttributeHandler getAttribute(const std::string& nameAttr) ; + + /** + * @brief get a generic pointer to an existing attribute multi vector + * @param orbit the concerned orbit + * @param nameAttr attribute name + * @return a pointer to an AttributeMultiVectorGen + */ + inline AttributeMultiVectorGen* getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr) ; + + /** + * check if an attribute exist ( get, test if valid and add if necessary) + * @param nameAttr attribute name + * @return an AttributeHandler + */ + template + AttributeHandler checkAttribute(const std::string& nameAttr) ; + + /** + * swap the content of two attributes (efficient, only swap pointers) + */ + template + bool swapAttributes(AttributeHandler& attr1, AttributeHandler& attr2) ; + + /** + * copy the content of src attribute to dst attribute + */ + template + bool copyAttribute(AttributeHandler& dst, AttributeHandler& src) ; + + /**************************************** + * UTILITIES * + ****************************************/ + + /** + * use the given attribute to store the indices of the cells of the corresponding orbit + * @return the number of cells of the orbit + */ + template + unsigned int computeIndexCells(AttributeHandler& idx) ; + + /** + * ensure that each orbit as one embedding and that each embedding is handle by only one orbit + */ + template + void bijectiveOrbitEmbedding(); +}; + +} //namespace CGoGN + +#include "Topology/generic/mapCommon.hpp" + +#endif diff --git a/include/Topology/generic/mapCommon.hpp b/include/Topology/generic/mapCommon.hpp new file mode 100644 index 0000000000000000000000000000000000000000..15a6870eb3f123ccd2104e7984a9c079d5e620ca --- /dev/null +++ b/include/Topology/generic/mapCommon.hpp @@ -0,0 +1,385 @@ +/******************************************************************************* +* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * +* version 0.1 * +* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * +* * +* This library is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by the * +* Free Software Foundation; either version 2.1 of the License, or (at your * +* option) any later version. * +* * +* This library is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this library; if not, write to the Free Software Foundation, * +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * +* * +* Web site: http://cgogn.unistra.fr/ * +* Contact information: cgogn@unistra.fr * +* * +*******************************************************************************/ + +namespace CGoGN +{ + +/**************************************** + * DARTS TRAVERSALS * + ****************************************/ + +template +template +bool MapCommon::foreach_orbit(FunctorType& fonct, unsigned int thread) +{ + TraversorCell trav(*static_cast(this), true, thread); + bool found = false; + + for (Dart d = trav.begin(); !found && d != trav.end(); d = trav.next()) + { + if ((fonct)(d)) + found = true; + } + return found; +} + +template +template +unsigned int MapCommon::getNbOrbits() +{ + FunctorCount fcount; + foreach_orbit(fcount); + return fcount.getNb(); +} + +template +template +unsigned int MapCommon::degree(Dart d) const +{ + assert(ORBIT != INCIDENT || !"degree does not manage adjacency counting") ; + Traversor* t = TraversorFactory::createIncident(*this, d, this->dimension(), ORBIT, INCIDENT) ; + FunctorCount fcount ; + t->applyFunctor(fcount) ; + delete t ; + return fcount.getNb() ; +} + +/**************************************** + * EMBEDDING MANAGEMENT * + ****************************************/ + +template +template +inline unsigned int MapCommon::getEmbedding(Dart d) const +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int d_index = this->dartIndex(d); + + if (ORBIT == DART) + return d_index; + + return (*this->m_embeddings[ORBIT])[d_index] ; +} + +template +template +void MapCommon::setDartEmbedding(Dart d, unsigned int emb) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int old = getEmbedding(d); + + if (old == emb) // if same emb + return; // nothing to do + + if (old != EMBNULL) // if different + { + if(this->m_attribs[ORBIT].unrefLine(old)) // then unref the old emb + { + for (unsigned int t = 0; t < this->m_nbThreads; ++t) // clear the markers if it was the + (*this->m_markTables[ORBIT][t])[old].clear(); // last unref of the line + } + } + + if (emb != EMBNULL) + this->m_attribs[ORBIT].refLine(emb); // ref the new emb + + (*this->m_embeddings[ORBIT])[this->dartIndex(d)] = emb ; // finally affect the embedding to the dart +} + +template +template +void MapCommon::initDartEmbedding(Dart d, unsigned int emb) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + assert(getEmbedding(d) == EMBNULL || !"initDartEmbedding called on already embedded dart"); + + if(emb != EMBNULL) + this->m_attribs[ORBIT].refLine(emb); // ref the new emb + (*this->m_embeddings[ORBIT])[this->dartIndex(d)] = emb ; // affect the embedding to the dart +} + +template +template +inline void MapCommon::copyDartEmbedding(Dart dest, Dart src) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + setDartEmbedding(dest, getEmbedding(src)); +} + +template +template +inline void MapCommon::setOrbitEmbedding(Dart d, unsigned int em) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + FunctorSetEmb, ORBIT> fsetemb(*this, em); + this->template foreach_dart_of_orbit(d, fsetemb); +} + +template +template +inline void MapCommon::initOrbitEmbedding(Dart d, unsigned int em) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + FunctorInitEmb, ORBIT> fsetemb(*this, em); + this->template foreach_dart_of_orbit(d, fsetemb); +} + +template +template +inline unsigned int MapCommon::setOrbitEmbeddingOnNewCell(Dart d) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int em = this->template newCell(); + setOrbitEmbedding(d, em); + return em; +} + +template +template +inline unsigned int MapCommon::initOrbitEmbeddingOnNewCell(Dart d) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + + unsigned int em = this->template newCell(); + initOrbitEmbedding(d, em); + return em; +} + +template +template +inline void MapCommon::copyCell(Dart d, Dart e) +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); + unsigned int dE = getEmbedding(d) ; + unsigned int eE = getEmbedding(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(d) ; + copyCell(dE, eE); // copy the data + } +} + +template +template +void MapCommon::initAllOrbitsEmbedding(bool realloc) +{ + if(!this->template isOrbitEmbedded()) + this->template addEmbedding() ; + DartMarker > mark(*this) ; + for(Dart d = this->begin(); d != this->end(); this->next(d)) + { + if(!mark.isMarked(d)) + { + mark.markOrbit(d) ; + if(realloc || getEmbedding(d) == EMBNULL) + setOrbitEmbeddingOnNewCell(d) ; + } + } +} + +/************************** + * BOUNDARY MANAGEMENT * + **************************/ + +template +template +inline void MapCommon::boundaryMark(Dart d) +{ + this->m_markTables[DART][0]->operator[](this->dartIndex(d)).setMark(this->m_boundaryMarkers[DIM-2]); +} + +template +template +inline void MapCommon::boundaryUnmark(Dart d) +{ + this->m_markTables[DART][0]->operator[](this->dartIndex(d)).unsetMark(this->m_boundaryMarkers[DIM-2]); +} + +template +template +void MapCommon::boundaryMarkOrbit(Dart d) +{ + FunctorMark fm(*this, this->m_boundaryMarkers[DIM-2], this->m_markTables[DART][0]) ; + this->template foreach_dart_of_orbit(d, fm, 0) ; +} + +template +template +void MapCommon::boundaryUnmarkOrbit(Dart d) +{ + FunctorUnmark fm(*this, this->m_boundaryMarkers[DIM-2], this->m_markTables[DART][0]) ; + this->template foreach_dart_of_orbit(d, fm, 0) ; +} + +template +template +inline bool MapCommon::isBoundaryMarked(Dart d) const +{ + return this->m_markTables[DART][0]->operator[](this->dartIndex(d)).testMark(this->m_boundaryMarkers[DIM-2]); +} + +template +inline bool MapCommon::isBoundaryMarkedCurrent(Dart d) const +{ + return this->m_markTables[DART][0]->operator[](this->dartIndex(d)).testMark(this->m_boundaryMarkers[this->dimension()-2]); +} + +/**************************************** + * ATTRIBUTES MANAGEMENT * + ****************************************/ + +template +template +inline AttributeHandler MapCommon::addAttribute(const std::string& nameAttr) +{ + if(!this->template isOrbitEmbedded()) + this->template addEmbedding() ; + AttributeMultiVector* amv = this->m_attribs[ORBIT].addAttribute(nameAttr) ; + return AttributeHandler(this, amv) ; +} + +template +template +inline bool MapCommon::removeAttribute(AttributeHandler& attr) +{ + assert(attr.isValid() || !"Invalid attribute handler") ; + if(this->m_attribs[attr.getOrbit()].template removeAttribute(attr.getIndex())) + { + AttributeMultiVectorGen* amv = attr.getDataVector(); + typedef std::multimap::iterator IT ; + std::pair bounds = this->attributeHandlers.equal_range(amv) ; + for(IT i = bounds.first; i != bounds.second; ++i) + (*i).second->setInvalid() ; + this->attributeHandlers.erase(bounds.first, bounds.second) ; + return true ; + } + return false ; +} + +template +template +inline AttributeHandler MapCommon::getAttribute(const std::string& nameAttr) +{ + AttributeMultiVector* amv = this->m_attribs[ORBIT].template getDataVector(nameAttr) ; + return AttributeHandler(this, amv) ; +} + +template +inline AttributeMultiVectorGen* MapCommon::getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr) +{ + return this->m_attribs[orbit].getVirtualDataVector(nameAttr) ; +} + +template +template +inline AttributeHandler MapCommon::checkAttribute(const std::string& nameAttr) +{ + AttributeHandler att = this->getAttribute(nameAttr); + if (!att.isValid()) + att = this->addAttribute(nameAttr); + return att; +} + +template +template +inline bool MapCommon::swapAttributes(AttributeHandler& attr1, AttributeHandler& attr2) +{ + assert((attr1.isValid() && attr2.isValid()) || !"Invalid attribute handler") ; +// assert(attr1.getOrbit() == attr2.getOrbit() || !"Cannot swap attributes of different orbits") ; +// unsigned int orbit = attr1.getOrbit() ; + unsigned int index1 = attr1.getIndex() ; + unsigned int index2 = attr2.getIndex() ; + if(index1 != index2) + return this->m_attribs[ORBIT].swapAttributes(index1, index2) ; + return false ; +} + +template +template +inline bool MapCommon::copyAttribute(AttributeHandler& dst, AttributeHandler& src) +{ + assert((dst.isValid() && src.isValid()) || !"Invalid attribute handler") ; +// unsigned int orbit = dst.getOrbit() ; +// assert(orbit == src.getOrbit() || !"Cannot copy attributes of different orbits") ; + unsigned int index_dst = dst.getIndex() ; + unsigned int index_src = src.getIndex() ; + if(index_dst != index_src) + return this->m_attribs[ORBIT].copyAttribute(index_dst, index_src) ; + return false ; +} + +/**************************************** + * UTILITIES * + ****************************************/ + +template +template +unsigned int MapCommon::computeIndexCells(AttributeHandler& idx) +{ + AttributeContainer& cont = this->m_attribs[ORBIT] ; + unsigned int cpt = 0 ; + for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i)) + idx[i] = cpt++ ; + return cpt ; +} + +template +template +void MapCommon::bijectiveOrbitEmbedding() +{ + assert(this->template isOrbitEmbedded() || !"Invalid parameter: orbit not embedded") ; + + AttributeHandler counter = addAttribute("tmpCounter") ; + counter.setAllValues(int(0)) ; + + DartMarker mark(*this) ; + for(Dart d = this->begin(); d != this->end(); this->next(d)) + { + if(!mark.isMarked(d)) + { + mark.markOrbit(d) ; + unsigned int emb = getEmbedding(d) ; + if (emb != EMBNULL) + { + if (counter[d] > 0) + { + unsigned int newEmb = setOrbitEmbeddingOnNewCell(d) ; + copyCell(newEmb, emb) ; + } + counter[d]++ ; + } + } + } + + removeAttribute(counter) ; +} + +} // namespace CGoGN diff --git a/include/Topology/generic/mapMono.h b/include/Topology/generic/mapMono.h index edcf5864a5526206b686e85cc4a87052f2d25213..2c254c8e9ea08ce1afb63fa1895befda3b202a78 100644 --- a/include/Topology/generic/mapMono.h +++ b/include/Topology/generic/mapMono.h @@ -25,14 +25,15 @@ #ifndef __MAP_MONO__ #define __MAP_MONO__ -#include "attribmap.h" +#include "Topology/generic/genericmap.h" namespace CGoGN { -class MapMono : public AttribMap +class MapMono : public GenericMap { template friend class DartMarkerTmpl ; + template friend class DartMarkerStore ; public: MapMono() @@ -51,21 +52,14 @@ protected: inline virtual void deleteDart(Dart d); - inline unsigned int dartIndex(Dart d) const - { - return d.index; - } +public: + inline unsigned int dartIndex(Dart d) const; - inline Dart indexDart(unsigned int index) const - { - return Dart(index); - } + inline Dart indexDart(unsigned int index) const; - /** - * @return the number of darts in the map - */ inline virtual unsigned int getNbDarts(); +protected: inline AttributeContainer& getDartContainer(); /**************************************** @@ -122,87 +116,6 @@ public: */ inline virtual void next(Dart& d) const; - /**************************************** - * EMBEDDING MANAGEMENT * - ****************************************/ - - /** - * 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 - inline unsigned int getEmbedding(Dart d) const; - - /** - * Set the cell index of the given dimension associated to dart d - */ - template - 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 - 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 - inline void copyDartEmbedding(Dart dest, Dart src) ; - - /** - * 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 - 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 - 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 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 initOrbitEmbeddingOnNewCell(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 - void copyCell(Dart d, Dart e) ; - - /** - * 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 - void initAllOrbitsEmbedding(bool realloc = false) ; - /**************************************** * SAVE & LOAD * ****************************************/ diff --git a/include/Topology/generic/mapMono.hpp b/include/Topology/generic/mapMono.hpp index 1e7481a6a3db97d4337bd1b4d5fad13cc80f7368..7a0ad9ab4fed9fe389cd19b989c60967cc73646a 100644 --- a/include/Topology/generic/mapMono.hpp +++ b/include/Topology/generic/mapMono.hpp @@ -48,6 +48,21 @@ inline void MapMono::deleteDart(Dart d) deleteDartLine(d.index) ; } +inline unsigned int MapMono::dartIndex(Dart d) const +{ + return d.index; +} + +inline Dart MapMono::indexDart(unsigned int index) const +{ + return Dart(index); +} + +inline unsigned int MapMono::getNbDarts() +{ + return m_attribs[DART].size() ; +} + inline AttributeContainer& MapMono::getDartContainer() { return m_attribs[DART]; @@ -175,134 +190,4 @@ inline void MapMono::next(Dart& d) const m_attribs[DART].next(d.index) ; } -/**************************************** - * EMBEDDING MANAGEMENT * - ****************************************/ - -template -inline unsigned int MapMono::getEmbedding(Dart d) const -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int d_index = dartIndex(d); - - if (ORBIT == DART) - return d_index; - - return (*m_embeddings[ORBIT])[d_index] ; -} - -template -void MapMono::setDartEmbedding(Dart d, unsigned int emb) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int old = getEmbedding(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 -void MapMono::initDartEmbedding(Dart d, unsigned int emb) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - assert(getEmbedding(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 -inline void MapMono::copyDartEmbedding(Dart dest, Dart src) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - setDartEmbedding(dest, getEmbedding(src)); -} - -template -inline void MapMono::setOrbitEmbedding(Dart d, unsigned int em) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - FunctorSetEmb fsetemb(*this, em); - foreach_dart_of_orbit(d, fsetemb); -} - -template -inline void MapMono::initOrbitEmbedding(Dart d, unsigned int em) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - FunctorInitEmb fsetemb(*this, em); - foreach_dart_of_orbit(d, fsetemb); -} - -template -inline unsigned int MapMono::setOrbitEmbeddingOnNewCell(Dart d) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int em = newCell(); - setOrbitEmbedding(d, em); - return em; -} - -template -inline unsigned int MapMono::initOrbitEmbeddingOnNewCell(Dart d) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int em = newCell(); - initOrbitEmbedding(d, em); - return em; -} - -template -inline void MapMono::copyCell(Dart d, Dart e) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - unsigned int dE = getEmbedding(d) ; - unsigned int eE = getEmbedding(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(d) ; - copyCell(dE, eE); // copy the data - } -} - -template -void MapMono::initAllOrbitsEmbedding(bool realloc) -{ - if(!isOrbitEmbedded()) - addEmbedding() ; - DartMarker mark(*this) ; - for(Dart d = begin(); d != end(); next(d)) - { - if(!mark.isMarked(d)) - { - mark.markOrbit(d) ; - if(realloc || getEmbedding(d) == EMBNULL) - setOrbitEmbeddingOnNewCell(d) ; - } - } -} - } // namespace CGoGN diff --git a/include/Topology/generic/mapMulti.h b/include/Topology/generic/mapMulti.h index fd64e321a7046d5c8a3ba92fc1017340ab4a3811..f241ef7f518623bc365671d6bdb03ee21f95325f 100644 --- a/include/Topology/generic/mapMulti.h +++ b/include/Topology/generic/mapMulti.h @@ -25,12 +25,12 @@ #ifndef __MAP_MULTI__ #define __MAP_MULTI__ -#include "Topology/generic/attribmap.h" +#include "Topology/generic/genericmap.h" namespace CGoGN { -class MapMulti : public AttribMap +class MapMulti : public GenericMap { template friend class DartMarkerTmpl ; @@ -42,7 +42,7 @@ public: virtual void clear(bool removeAttrib) { - AttribMap::clear(removeAttrib); + GenericMap::clear(removeAttrib); initMR(); } @@ -90,7 +90,9 @@ public: inline virtual void deleteDart(Dart d); - inline virtual unsigned int dartIndex(Dart d) const; + inline unsigned int dartIndex(Dart d) const; + + inline Dart indexDart(unsigned int index) const; /** * get the number of darts inserted in the given leveldart @@ -272,87 +274,6 @@ public: */ inline virtual void next(Dart& d) const; - /**************************************** - * EMBEDDING MANAGEMENT * - ****************************************/ - - /** - * 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 - inline unsigned int getEmbedding(Dart d) const; - - /** - * Set the cell index of the given dimension associated to dart d - */ - template - 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 - 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 - inline void copyDartEmbedding(Dart dest, Dart src) ; - - /** - * 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 - 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 - 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 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 initOrbitEmbeddingOnNewCell(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 - void copyCell(Dart d, Dart e) ; - - /** - * 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 - void initAllOrbitsEmbedding(bool realloc = false) ; - /**************************************** * SAVE & LOAD * ****************************************/ diff --git a/include/Topology/generic/mapMulti.hpp b/include/Topology/generic/mapMulti.hpp index 5957650a06bcc9c26d090b869a3d9ce8958fcb0b..575414c58016ae0036a6b71ca56f24cc1ba50979 100644 --- a/include/Topology/generic/mapMulti.hpp +++ b/include/Topology/generic/mapMulti.hpp @@ -180,7 +180,7 @@ inline void MapMulti::duplicateDartAtOneLevel(Dart d, unsigned int level) (*m_mrDarts[level])[d.index] = copyDartLine(dartIndex(d)) ; } -inline MapMulti::AttributeContainer& getDartContainer() +inline AttributeContainer& MapMulti::getDartContainer() { return m_mrattribs; } @@ -268,6 +268,31 @@ inline void MapMulti::involutionUnsew(Dart d) (*m_involution[I])[dartIndex(e)] = e ; } +inline void MapMulti::compactTopoRelations(const std::vector& oldnew) +{ + for (unsigned int i = m_attribs[DART].begin(); i != m_attribs[DART].end(); m_attribs[DART].next(i)) + { + for (unsigned int j = 0; j < m_permutation.size(); ++j) + { + Dart d = (*m_permutation[j])[i]; + if (d.index != oldnew[d.index]) + (*m_permutation[j])[i] = Dart(oldnew[d.index]); + } + for (unsigned int j = 0; j < m_permutation_inv.size(); ++j) + { + Dart d = (*m_permutation_inv[j])[i]; + if (d.index != oldnew[d.index]) + (*m_permutation_inv[j])[i] = Dart(oldnew[d.index]); + } + for (unsigned int j = 0; j < m_involution.size(); ++j) + { + Dart d = (*m_involution[j])[i]; + if (d.index != oldnew[d.index]) + (*m_involution[j])[i] = Dart(oldnew[d.index]); + } + } +} + /**************************************** * MR CONTAINER MANAGEMENT * ****************************************/ @@ -365,134 +390,4 @@ inline void MapMulti::next(Dart& d) const } while (d.index != m_mrattribs.end() && getDartLevel(d) > m_mrCurrentLevel) ; } -/**************************************** - * EMBEDDING MANAGEMENT * - ****************************************/ - -template -inline unsigned int MapMulti::getEmbedding(Dart d) const -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int d_index = dartIndex(d); - - if (ORBIT == DART) - return d_index; - - return (*m_embeddings[ORBIT])[d_index] ; -} - -template -void MapMulti::setDartEmbedding(Dart d, unsigned int emb) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int old = getEmbedding(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 -void MapMulti::initDartEmbedding(Dart d, unsigned int emb) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - assert(getEmbedding(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 -inline void MapMulti::copyDartEmbedding(Dart dest, Dart src) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - setDartEmbedding(dest, getEmbedding(src)); -} - -template -inline void MapMulti::setOrbitEmbedding(Dart d, unsigned int em) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - FunctorSetEmb fsetemb(*this, em); - foreach_dart_of_orbit(d, fsetemb); -} - -template -inline void MapMulti::initOrbitEmbedding(Dart d, unsigned int em) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - FunctorInitEmb fsetemb(*this, em); - foreach_dart_of_orbit(d, fsetemb); -} - -template -inline unsigned int MapMulti::setOrbitEmbeddingOnNewCell(Dart d) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int em = newCell(); - setOrbitEmbedding(d, em); - return em; -} - -template -inline unsigned int MapMulti::initOrbitEmbeddingNewCell(Dart d) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - - unsigned int em = newCell(); - initOrbitEmbedding(d, em); - return em; -} - -template -inline void MapMulti::copyCell(Dart d, Dart e) -{ - assert(isOrbitEmbedded() || !"Invalid parameter: orbit not embedded"); - unsigned int dE = getEmbedding(d) ; - unsigned int eE = getEmbedding(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(d) ; - copyCell(dE, eE); // copy the data - } -} - -template -void MapMulti::initAllOrbitsEmbedding(bool realloc) -{ - if(!isOrbitEmbedded()) - addEmbedding() ; - DartMarker mark(*this) ; - for(Dart d = begin(); d != end(); next(d)) - { - if(!mark.isMarked(d)) - { - mark.markOrbit(d) ; - if(realloc || getEmbedding(d) == EMBNULL) - setOrbitEmbeddingOnNewCell(d) ; - } - } -} - } // namespace CGoGN diff --git a/include/Topology/generic/parameters.h b/include/Topology/generic/parameters.h index 9a97894d960956f6f8e65b38f47e3b1e2d9e7e24..b561e1c4804894a233e5a93c2f3812de761483c9 100644 --- a/include/Topology/generic/parameters.h +++ b/include/Topology/generic/parameters.h @@ -23,12 +23,12 @@ *******************************************************************************/ -#ifndef __PARAMETERS_ -#define __PARAMETERS_ +#ifndef __PARAMETERS__ +#define __PARAMETERS__ #include "Geometry/vector_gen.h" #include "Geometry/matrix.h" -#include "attributeHandler.h" +#include "Topology/generic/attributeHandler.h" namespace CGoGN { diff --git a/include/Topology/generic/traversor3.h b/include/Topology/generic/traversor3.h index 537ec5f9d453ae87abf356b55d572d68891ccb16..4048bb81d08e05c296201596f5e44c1e230be0c7 100644 --- a/include/Topology/generic/traversor3.h +++ b/include/Topology/generic/traversor3.h @@ -43,19 +43,19 @@ class MarkerForTraversor { private: const MAP& m_map ; - DartMarkerStore* m_dmark ; - CellMarkerStore* m_cmark ; + DartMarkerStore* m_dmark ; + CellMarkerStore* m_cmark ; public: MarkerForTraversor(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ; ~MarkerForTraversor(); - DartMarkerStore* dmark(); - CellMarkerStore* cmark(); + + DartMarkerStore* dmark(); + CellMarkerStore* cmark(); void mark(Dart d); void unmark(Dart d); bool isMarked(Dart d); } ; - /** * Generic class Traversor (do not use directly) * Traverse all Y incident to X @@ -65,8 +65,8 @@ class Traversor3XY//: public Traversor { private: const MAP& m_map ; - DartMarkerStore* m_dmark ; - CellMarkerStore* m_cmark ; + DartMarkerStore* m_dmark ; + CellMarkerStore* m_cmark ; Dart m_current ; TraversorDartsOfOrbit m_tradoo; @@ -102,13 +102,10 @@ public: Traversor3XXaY(const MAP& map, Dart dart, bool forceDartMarker = false, unsigned int thread = 0); Dart begin(); - Dart end(); - Dart next(); }; - /** * Traverse vertices incident to volume */ diff --git a/include/Topology/generic/traversor3.hpp b/include/Topology/generic/traversor3.hpp index f89dcddbcf2d13ba6df8890238d7e0d7933ac640..dc79ad3f9b947d668fbf5df098a925c97f3a6f61 100644 --- a/include/Topology/generic/traversor3.hpp +++ b/include/Topology/generic/traversor3.hpp @@ -39,9 +39,9 @@ MarkerForTraversor::MarkerForTraversor(const MAP& map, bool forceDar m_cmark(NULL) { if(!forceDartMarker && map.isOrbitEmbedded(ORBIT)) - m_cmark = new CellMarkerStore(map, thread) ; + m_cmark = new CellMarkerStore(map, thread) ; else - m_dmark = new DartMarkerStore(map, thread) ; + m_dmark = new DartMarkerStore(map, thread) ; } template @@ -59,7 +59,7 @@ void MarkerForTraversor::mark(Dart d) if (m_cmark) m_cmark->mark(d); else - m_dmark->markOrbit(d); + m_dmark->template markOrbit(d); } template @@ -68,7 +68,7 @@ void MarkerForTraversor::unmark(Dart d) if (m_cmark) m_cmark->unmark(d); else - m_dmark->unmarkOrbit(d); + m_dmark->template unmarkOrbit(d); } template @@ -80,13 +80,13 @@ bool MarkerForTraversor::isMarked(Dart d) } template -CellMarkerStore* MarkerForTraversor::cmark() +CellMarkerStore* MarkerForTraversor::cmark() { return m_cmark; } template -DartMarkerStore* MarkerForTraversor::dmark() +DartMarkerStore* MarkerForTraversor::dmark() { return m_dmark; } @@ -113,9 +113,9 @@ Traversor3XY::Traversor3XY(const MAP& map, Dart dart, bool forc else { if(!forceDartMarker && map.isOrbitEmbedded(ORBY)) - m_cmark = new CellMarkerStore(map, thread) ; + m_cmark = new CellMarkerStore(map, thread) ; else - m_dmark = new DartMarkerStore(map, thread) ; + m_dmark = new DartMarkerStore(map, thread) ; } } @@ -179,7 +179,7 @@ Dart Traversor3XY::begin() if ((ORBY == VOLUME) && (m_current != NIL)) { - if(m_map.isBoundaryMarked3(m_current)) + if(m_map.template isBoundaryMarked<3>(m_current)) m_current = next(); } @@ -208,7 +208,7 @@ Dart Traversor3XY::next() m_current = m_tradoo.next(); if(ORBY == VOLUME) { - if(m_map.isBoundaryMarked3(m_current)) + if(m_map.template isBoundaryMarked<3>(m_current)) m_cmark->mark(m_current); } while ((m_current != NIL) && m_cmark->isMarked(m_current)) @@ -220,27 +220,27 @@ Dart Traversor3XY::next() { // if allocated we are in a local traversal of volume so we can mark only darts of volume if (m_allocated) - m_dmark->markOrbit(m_current); + m_dmark->template markOrbit(m_current); else - m_dmark->markOrbit(m_current); // here we need to mark all the darts + m_dmark->template markOrbit(m_current); // here we need to mark all the darts } else - m_dmark->markOrbit(m_current); + m_dmark->template markOrbit(m_current); m_current = m_tradoo.next(); if(ORBY == VOLUME) { - if(m_map.isBoundaryMarked3(m_current)) + if(m_map.template isBoundaryMarked<3>(m_current)) { if (ORBX == VOLUME) { // if allocated we are in a local traversal of volume so we can mark only darts of volume if (m_allocated) - m_dmark->markOrbit(m_current); + m_dmark->template markOrbit(m_current); else - m_dmark->markOrbit(m_current); // here we need to mark all the darts + m_dmark->template markOrbit(m_current); // here we need to mark all the darts } else - m_dmark->markOrbit(m_current); + m_dmark->template markOrbit(m_current); } } while ((m_current != NIL) && m_dmark->isMarked(m_current)) diff --git a/include/Topology/generic/traversorCell.hpp b/include/Topology/generic/traversorCell.hpp index 251280ac33e3bbd33819dfb1e1994ed29f04baf0..ba4ffe5a2b6e6d9f87b0d3ad0859243fa9ffbe9c 100644 --- a/include/Topology/generic/traversorCell.hpp +++ b/include/Topology/generic/traversorCell.hpp @@ -85,7 +85,7 @@ Dart TraversorCell::begin() else { if(dmark) - dmark->markOrbit(current) ; + dmark->template markOrbit(current) ; else cmark->mark(current) ; } @@ -129,7 +129,7 @@ Dart TraversorCell::next() ismarked = dmark->isMarked(current) ; } if(current != NIL) - dmark->markOrbit(current) ; + dmark->template markOrbit(current) ; } else { diff --git a/include/Topology/gmap/embeddedGMap2.h b/include/Topology/gmap/embeddedGMap2.h index dec471446ba2307bdda0515c6e3bfe5212bdf2e6..4deaf7f9ed206518ca7621c976bbd2772d616840 100644 --- a/include/Topology/gmap/embeddedGMap2.h +++ b/include/Topology/gmap/embeddedGMap2.h @@ -37,6 +37,7 @@ namespace CGoGN class EmbeddedGMap2 : public GMap2 { public: + typedef MapMono IMPL; typedef GMap2 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; diff --git a/include/Topology/gmap/embeddedGMap3.h b/include/Topology/gmap/embeddedGMap3.h index 476773dd75cd7a0614b8ab7d8ab5547971b03f33..81802633457e00bc2311346dc8ddf2ceb87d8975 100644 --- a/include/Topology/gmap/embeddedGMap3.h +++ b/include/Topology/gmap/embeddedGMap3.h @@ -37,6 +37,7 @@ namespace CGoGN class EmbeddedGMap3 : public GMap3 { public: + typedef MapMono IMPL; typedef GMap3 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; diff --git a/include/Topology/gmap/gmap0.h b/include/Topology/gmap/gmap0.h index e9b06d111ce9af03c75bbe8cc1f3c20e3aff5921..71ed43f383e030765c30c2d7d397e3a5d68cd05b 100644 --- a/include/Topology/gmap/gmap0.h +++ b/include/Topology/gmap/gmap0.h @@ -25,7 +25,7 @@ #ifndef __GMAP0_H__ #define __GMAP0_H__ -#include "Topology/generic/mapMono.h" +#include "Topology/generic/mapCommon.h" #include "Topology/generic/dartmarker.h" #include "Topology/generic/cellmarker.h" @@ -36,13 +36,15 @@ namespace CGoGN * The class of 0-GMap * Warning here we use beta instead of classic alpha */ -template -class GMap0 : public MAP +template +class GMap0 : public MapCommon { protected: void init() ; public: + typedef MAP_IMPL IMPL; + GMap0(); static const unsigned int DIMENSION = 0 ; diff --git a/include/Topology/gmap/gmap0.hpp b/include/Topology/gmap/gmap0.hpp index 44533e747629e38a4c32f7a6c42cae5c9d8beaa7..5dcd0d3312be073c3b838c7ba081925ab85ebcb6 100644 --- a/include/Topology/gmap/gmap0.hpp +++ b/include/Topology/gmap/gmap0.hpp @@ -27,42 +27,42 @@ namespace CGoGN /// INLINE FUNCTIONS -template -inline void GMap0::init() +template +inline void GMap0::init() { - MAP::addInvolution() ; + MAP_IMPL::addInvolution() ; } -template -inline GMap0::GMap0() : MAP() +template +inline GMap0::GMap0() : MapCommon() { init() ; } -template -inline std::string GMap0::mapTypeName() const +template +inline std::string GMap0::mapTypeName() const { return "GMap0"; } -template -inline unsigned int GMap0::dimension() const +template +inline unsigned int GMap0::dimension() const { return 0; } -template -inline void GMap0::clear(bool removeAttrib) +template +inline void GMap0::clear(bool removeAttrib) { - MAP::clear(removeAttrib) ; + MAP_IMPL::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void GMap0::update_topo_shortcuts() +template +inline void GMap0::update_topo_shortcuts() { - MAP::update_topo_shortcuts(); + MAP_IMPL::update_topo_shortcuts(); // m_beta0 = getRelation("beta0"); } @@ -70,30 +70,30 @@ inline void GMap0::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart GMap0::beta0(Dart d) const +template +inline Dart GMap0::beta0(Dart d) const { - return MAP::template getInvolution<0>(d); + return MAP_IMPL::template getInvolution<0>(d); } -template -inline void GMap0::beta0sew(Dart d, Dart e) +template +inline void GMap0::beta0sew(Dart d, Dart e) { - MAP::template involutionSew<0>(d,e); + MAP_IMPL::template involutionSew<0>(d,e); } -template -inline void GMap0::beta0unsew(Dart d) +template +inline void GMap0::beta0unsew(Dart d) { - MAP::template involutionUnsew<0>(d); + MAP_IMPL::template involutionUnsew<0>(d); } /*! @name Constructors and Destructors * To generate or delete edges in a 0-G-map *************************************************************************/ -template -Dart GMap0::newEdge() +template +Dart GMap0::newEdge() { Dart d1 = this->newDart(); Dart d2 = this->newDart(); @@ -101,8 +101,8 @@ Dart GMap0::newEdge() return d1; } -template -void GMap0::deleteEdge(Dart d) +template +void GMap0::deleteEdge(Dart d) { this->deleteDart(beta0(d)); this->deleteDart(d); @@ -112,14 +112,14 @@ void GMap0::deleteEdge(Dart d) * Apply functors to all darts of a cell *************************************************************************/ -template -inline bool GMap0::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool GMap0::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const { return f(d) ; } -template -inline bool GMap0::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool GMap0::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const { if (f(d)) return true; Dart d1 = beta0(d); diff --git a/include/Topology/gmap/gmap1.h b/include/Topology/gmap/gmap1.h index 4f9052828efdeae407e9b63b77349d4303c7b24a..8aedb37b1caf5b1d1b23e08216c63e35e20c6420 100644 --- a/include/Topology/gmap/gmap1.h +++ b/include/Topology/gmap/gmap1.h @@ -33,14 +33,15 @@ namespace CGoGN /** * The class of 1-GMap */ -template -class GMap1 : public GMap0 +template +class GMap1 : public GMap0 { protected: void init() ; public: - typedef GMap0 ParentMap; + typedef MAP_IMPL IMPL; + typedef GMap0 ParentMap; static const unsigned int DIMENSION = 1 ; @@ -179,6 +180,12 @@ public: * @return a boolean indicating if the face is a triangle */ bool isCycleTriangle(Dart d) const; + + template + unsigned int getNbOrbits() + { + return MapCommon::template getNbOrbits(); + } //@} /*! @name Cell Functors diff --git a/include/Topology/gmap/gmap1.hpp b/include/Topology/gmap/gmap1.hpp index 302251eac5072ed8f80155619768e1958276d207..cd3d4c4c71312011f9bd686a974f1756b5e0974f 100644 --- a/include/Topology/gmap/gmap1.hpp +++ b/include/Topology/gmap/gmap1.hpp @@ -25,40 +25,40 @@ namespace CGoGN { -template -inline void GMap1::init() +template +inline void GMap1::init() { - MAP::addInvolution() ; + MAP_IMPL::addInvolution() ; } -template -inline GMap1::GMap1() : GMap0() +template +inline GMap1::GMap1() : GMap0() { init() ; } -template -inline std::string GMap1::mapTypeName() const +template +inline std::string GMap1::mapTypeName() const { return "GMap1"; } -template -inline unsigned int GMap1::dimension() const +template +inline unsigned int GMap1::dimension() const { return 1; } -template -inline void GMap1::clear(bool removeAttrib) +template +inline void GMap1::clear(bool removeAttrib) { ParentMap::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void GMap1::update_topo_shortcuts() +template +inline void GMap1::update_topo_shortcuts() { ParentMap::update_topo_shortcuts(); // m_beta1 = getRelation("beta1"); @@ -68,15 +68,15 @@ inline void GMap1::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart GMap1::beta1(Dart d) const +template +inline Dart GMap1::beta1(Dart d) const { - return MAP::template getInvolution<1>(d); + return MAP_IMPL::template getInvolution<1>(d); } -template +template template -inline Dart GMap1::beta(const Dart d) const +inline Dart GMap1::beta(const Dart d) const { assert( (N > 0) || !"negative parameters not allowed in template multi-beta"); if (N<10) @@ -96,21 +96,21 @@ inline Dart GMap1::beta(const Dart d) const } } -template -inline Dart GMap1::phi1(Dart d) const +template +inline Dart GMap1::phi1(Dart d) const { return beta1(this->beta0(d)) ; } -template -inline Dart GMap1::phi_1(Dart d) const +template +inline Dart GMap1::phi_1(Dart d) const { return this->beta0(beta1(d)) ; } -template +template template -inline Dart GMap1::phi(Dart d) const +inline Dart GMap1::phi(Dart d) const { assert((N > 0) || !"negative parameters not allowed in template multi-phi"); if (N < 10) @@ -128,36 +128,36 @@ inline Dart GMap1::phi(Dart d) const } } -template -inline Dart GMap1::alpha1(Dart d) const +template +inline Dart GMap1::alpha1(Dart d) const { return beta1(this->beta0(d)) ; } -template -inline Dart GMap1::alpha_1(Dart d) const +template +inline Dart GMap1::alpha_1(Dart d) const { return beta0(beta1(d)) ; } -template -inline void GMap1::beta1sew(Dart d, Dart e) +template +inline void GMap1::beta1sew(Dart d, Dart e) { - MAP::template involutionSew<1>(d,e); + MAP_IMPL::template involutionSew<1>(d,e); } -template -inline void GMap1::beta1unsew(Dart d) +template +inline void GMap1::beta1unsew(Dart d) { - MAP::template involutionUnsew<1>(d); + MAP_IMPL::template involutionUnsew<1>(d); } /*! @name Constructors and Destructors * To generate or delete faces in a 1-G-map *************************************************************************/ -template -Dart GMap1::newCycle(unsigned int nbEdges) +template +Dart GMap1::newCycle(unsigned int nbEdges) { assert(nbEdges > 0 || !"Cannot create a face with no edge") ; @@ -173,8 +173,8 @@ Dart GMap1::newCycle(unsigned int nbEdges) return d0; } -template -void GMap1::deleteCycle(Dart d) +template +void GMap1::deleteCycle(Dart d) { Dart e = phi1(d); while (e != d) @@ -190,8 +190,8 @@ void GMap1::deleteCycle(Dart d) * Topological operations on 1-G-maps *************************************************************************/ -template -inline Dart GMap1::cutEdge(Dart d) +template +inline Dart GMap1::cutEdge(Dart d) { Dart dd = this->beta0(d) ; Dart e = this->newDart(); @@ -201,23 +201,23 @@ inline Dart GMap1::cutEdge(Dart d) this->beta0sew(e, d) ; this->beta0sew(f, dd) ; - if (this->isBoundaryMarked2(d)) + if (this->template isBoundaryMarked<2>(d)) { - this->boundaryMark2(e); - this->boundaryMark2(f); + this->template boundaryMark<2>(e); + this->template boundaryMark<2>(f); } - if (this->isBoundaryMarked3(d)) + if (this->template isBoundaryMarked<3>(d)) { - this->boundaryMark3(e); - this->boundaryMark3(f); + this->template boundaryMark<3>(e); + this->template boundaryMark<3>(f); } return f ; } -template -inline void GMap1::uncutEdge(Dart d) +template +inline void GMap1::uncutEdge(Dart d) { Dart d0 = this->beta0(d) ; Dart d1 = phi1(d) ; @@ -229,8 +229,8 @@ inline void GMap1::uncutEdge(Dart d) this->deleteDart(d1) ; } -template -inline void GMap1::collapseEdge(Dart d) +template +inline void GMap1::collapseEdge(Dart d) { Dart d1 = beta1(d) ; Dart dd = this->beta0(d) ; @@ -241,8 +241,8 @@ inline void GMap1::collapseEdge(Dart d) this->deleteEdge(d) ; } -template -inline void GMap1::splitCycle(Dart d, Dart e) +template +inline void GMap1::splitCycle(Dart d, Dart e) { assert(d != e && sameCycle(d, e)) ; @@ -257,8 +257,8 @@ inline void GMap1::splitCycle(Dart d, Dart e) beta1sew(e, d1) ; } -template -inline void GMap1::mergeCycles(Dart d, Dart e) +template +inline void GMap1::mergeCycles(Dart d, Dart e) { assert(!sameCycle(d, e)) ; @@ -270,8 +270,8 @@ inline void GMap1::mergeCycles(Dart d, Dart e) beta1sew(e, d1) ; } -template -inline void GMap1::linkCycles(Dart d, Dart e) +template +inline void GMap1::linkCycles(Dart d, Dart e) { assert(d != e && !sameCycle(d, e)) ; Dart d1 = beta1(d) ; @@ -290,8 +290,8 @@ inline void GMap1::linkCycles(Dart d, Dart e) * Return or set various topological information *************************************************************************/ -template -inline bool GMap1::sameOrientedCycle(Dart d, Dart e) const +template +inline bool GMap1::sameOrientedCycle(Dart d, Dart e) const { Dart it = d ; do @@ -303,8 +303,8 @@ inline bool GMap1::sameOrientedCycle(Dart d, Dart e) const return false ; } -template -inline bool GMap1::sameCycle(Dart d, Dart e) const +template +inline bool GMap1::sameCycle(Dart d, Dart e) const { Dart it = d ; do @@ -319,8 +319,8 @@ inline bool GMap1::sameCycle(Dart d, Dart e) const return false ; } -template -inline unsigned int GMap1::cycleDegree(Dart d) const +template +inline unsigned int GMap1::cycleDegree(Dart d) const { unsigned int count = 0 ; Dart it = d ; @@ -332,8 +332,8 @@ inline unsigned int GMap1::cycleDegree(Dart d) const return count ; } -template -inline int GMap1::checkCycleDegree(Dart d, unsigned int degree) const +template +inline int GMap1::checkCycleDegree(Dart d, unsigned int degree) const { unsigned int count = 0 ; Dart it = d ; @@ -346,8 +346,8 @@ inline int GMap1::checkCycleDegree(Dart d, unsigned int degree) const return count-degree; } -template -inline bool GMap1::isCycleTriangle(Dart d) const +template +inline bool GMap1::isCycleTriangle(Dart d) const { return (phi1(d) != d) && (phi1(phi1(phi1(d))) == d) ; } @@ -356,8 +356,8 @@ inline bool GMap1::isCycleTriangle(Dart d) const * Apply functors to all darts of a cell *************************************************************************/ -template -inline bool GMap1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool GMap1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const { if (f(d)) return true; Dart d1 = beta1(d); @@ -365,8 +365,8 @@ inline bool GMap1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned return false; } -template -inline bool GMap1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool GMap1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const { if (f(d)) return true; Dart d1 = this->beta0(d); @@ -374,8 +374,8 @@ inline bool GMap1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned in return false; } -template -inline bool GMap1::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool GMap1::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsigned int /*thread*/) const { Dart it = d ; do @@ -387,10 +387,10 @@ inline bool GMap1::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsi return false ; } -template -inline bool GMap1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const { - return GMap1::foreach_dart_of_oriented_cc(d, f, thread) || GMap1::foreach_dart_of_oriented_cc(this->beta0(d), f, thread) ; + return GMap1::foreach_dart_of_oriented_cc(d, f, thread) || GMap1::foreach_dart_of_oriented_cc(this->beta0(d), f, thread) ; } } // namespace CGoGN diff --git a/include/Topology/gmap/gmap2.h b/include/Topology/gmap/gmap2.h index d4a5f5556541a0fee94f39673ecfa1541ef6c5ae..e6cf3ec9920f90901be0d59b08fb5192ebd99c36 100644 --- a/include/Topology/gmap/gmap2.h +++ b/include/Topology/gmap/gmap2.h @@ -33,14 +33,15 @@ namespace CGoGN /** * The class of 2-GMap */ -template -class GMap2 : public GMap1 +template +class GMap2 : public GMap1 { protected: void init() ; public: - typedef GMap1 ParentMap; + typedef MAP_IMPL IMPL; + typedef GMap1 ParentMap; inline static unsigned int ORBIT_IN_PARENT(unsigned int o) { return o+5; } @@ -382,6 +383,12 @@ public: * Check if a serie of darts is an oriented simple close path */ virtual bool checkSimpleOrientedPath(std::vector& vd); + + template + unsigned int getNbOrbits() + { + return MapCommon::template getNbOrbits(); + } //@} /*! @name Cell Functors diff --git a/include/Topology/gmap/gmap2.hpp b/include/Topology/gmap/gmap2.hpp index 665e5bf42213fe70b4a708298a9647dae54070ae..2a52dd5efe807eaa8a78c72143db302cd9697526 100644 --- a/include/Topology/gmap/gmap2.hpp +++ b/include/Topology/gmap/gmap2.hpp @@ -25,40 +25,40 @@ namespace CGoGN { -template -inline void GMap2::init() +template +inline void GMap2::init() { - MAP::addInvolution() ; + MAP_IMPL::addInvolution() ; } -template -inline GMap2::GMap2() : GMap1() +template +inline GMap2::GMap2() : GMap1() { init() ; } -template -inline std::string GMap2::mapTypeName() const +template +inline std::string GMap2::mapTypeName() const { return "GMap2"; } -template -inline unsigned int GMap2::dimension() const +template +inline unsigned int GMap2::dimension() const { return 2; } -template -inline void GMap2::clear(bool removeAttrib) +template +inline void GMap2::clear(bool removeAttrib) { ParentMap::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void GMap2::update_topo_shortcuts() +template +inline void GMap2::update_topo_shortcuts() { ParentMap::update_topo_shortcuts(); // m_beta2 = getRelation("beta2"); @@ -68,15 +68,15 @@ inline void GMap2::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart GMap2::beta2(Dart d) const +template +inline Dart GMap2::beta2(Dart d) const { - return MAP::template getInvolution<2>(d); + return MAP_IMPL::template getInvolution<2>(d); } -template +template template -inline Dart GMap2::beta(const Dart d) const +inline Dart GMap2::beta(const Dart d) const { assert( (N > 0) || !"negative parameters not allowed in template multi-beta"); if (N<10) @@ -98,15 +98,15 @@ inline Dart GMap2::beta(const Dart d) const } } -template -inline Dart GMap2::phi2(Dart d) const +template +inline Dart GMap2::phi2(Dart d) const { return beta2(this->beta0(d)) ; } -template +template template -inline Dart GMap2::phi(Dart d) const +inline Dart GMap2::phi(Dart d) const { assert( (N >0) || !"negative parameters not allowed in template multi-phi"); if (N<10) @@ -126,42 +126,42 @@ inline Dart GMap2::phi(Dart d) const } } -template -inline Dart GMap2::alpha0(Dart d) const +template +inline Dart GMap2::alpha0(Dart d) const { return beta2(this->beta0(d)) ; } -template -inline Dart GMap2::alpha1(Dart d) const +template +inline Dart GMap2::alpha1(Dart d) const { return beta2(this->beta1(d)) ; } -template -inline Dart GMap2::alpha_1(Dart d) const +template +inline Dart GMap2::alpha_1(Dart d) const { return beta1(beta2(d)) ; } -template -inline void GMap2::beta2sew(Dart d, Dart e) +template +inline void GMap2::beta2sew(Dart d, Dart e) { - MAP::template involutionSew<2>(d,e); + MAP_IMPL::template involutionSew<2>(d,e); } -template -inline void GMap2::beta2unsew(Dart d) +template +inline void GMap2::beta2unsew(Dart d) { - MAP::template involutionUnsew<2>(d); + MAP_IMPL::template involutionUnsew<2>(d); } /*! @name Constructors and Destructors * To generate or delete faces in a 2-G-map *************************************************************************/ -template -Dart GMap2::newFace(unsigned int nbEdges, bool withBoundary) +template +Dart GMap2::newFace(unsigned int nbEdges, bool withBoundary) { Dart d = ParentMap::newCycle(nbEdges); if (withBoundary) @@ -180,10 +180,10 @@ Dart GMap2::newFace(unsigned int nbEdges, bool withBoundary) return d; } -template -void GMap2::deleteFace(Dart d) +template +void GMap2::deleteFace(Dart d) { - assert(!this->isBoundaryMarked2(d)) ; + assert(!this->template isBoundaryMarked<2>(d)) ; Dart it = d ; do { @@ -196,10 +196,10 @@ void GMap2::deleteFace(Dart d) ParentMap::deleteCycle(dd) ; } -template -void GMap2::deleteCC(Dart d) +template +void GMap2::deleteCC(Dart d) { - DartMarkerStore mark(*this); + DartMarkerStore mark(*this); std::vector visited; visited.reserve(1024) ; @@ -232,22 +232,22 @@ void GMap2::deleteCC(Dart d) this->deleteDart(*it) ; } -template -void GMap2::fillHole(Dart d) +template +void GMap2::fillHole(Dart d) { assert(isBoundaryEdge(d)) ; Dart dd = d ; - if(!this->isBoundaryMarked2(dd)) + if(!this->template isBoundaryMarked<2>(dd)) dd = phi2(dd) ; - this->template boundaryUnmarkOrbit(dd) ; + this->template boundaryUnmarkOrbit(dd) ; } /*! @name Topological Operators * Topological operations on 2-G-maps *************************************************************************/ -template -void GMap2::splitVertex(Dart d, Dart e) +template +void GMap2::splitVertex(Dart d, Dart e) { assert(sameVertex(d, e)); @@ -268,8 +268,8 @@ void GMap2::splitVertex(Dart d, Dart e) beta2sew(e, this->beta0(ee)) ; } -template -Dart GMap2::deleteVertex(Dart d) +template +Dart GMap2::deleteVertex(Dart d) { if(isBoundaryVertex(d)) return NIL ; @@ -296,8 +296,8 @@ Dart GMap2::deleteVertex(Dart d) return res ; } -template -Dart GMap2::cutEdge(Dart d) +template +Dart GMap2::cutEdge(Dart d) { Dart e = phi2(d) ; Dart nd = ParentMap::cutEdge(d) ; @@ -309,8 +309,8 @@ Dart GMap2::cutEdge(Dart d) return nd ; } -template -bool GMap2::uncutEdge(Dart d) +template +bool GMap2::uncutEdge(Dart d) { if(vertexDegree(this->phi1(d)) == 2) { @@ -321,8 +321,8 @@ bool GMap2::uncutEdge(Dart d) return false ; } -template -Dart GMap2::collapseEdge(Dart d, bool delDegenerateFaces) +template +Dart GMap2::collapseEdge(Dart d, bool delDegenerateFaces) { Dart resV = NIL ; @@ -363,8 +363,8 @@ Dart GMap2::collapseEdge(Dart d, bool delDegenerateFaces) return resV ; } -template -bool GMap2::flipEdge(Dart d) +template +bool GMap2::flipEdge(Dart d) { if (!isBoundaryEdge(d)) { @@ -395,8 +395,8 @@ bool GMap2::flipEdge(Dart d) return false ; // cannot flip a border edge } -template -bool GMap2::flipBackEdge(Dart d) +template +bool GMap2::flipBackEdge(Dart d) { if (!isBoundaryEdge(d)) { @@ -427,24 +427,24 @@ bool GMap2::flipBackEdge(Dart d) return false ; // cannot flip a border edge } -//template -//void GMap2::insertEdgeInVertex(Dart d, Dart e) +//template +//void GMap2::insertEdgeInVertex(Dart d, Dart e) //{ // assert(!sameVertex(d,e) && phi2(e)==phi_1(e)); // // phi1sew(phi_1(d),phi_1(e)); //} // -//template -//void GMap2::removeEdgeFromVertex(Dart d) +//template +//void GMap2::removeEdgeFromVertex(Dart d) //{ // assert(phi2(d)!=d); // // phi1sew(phi_1(d),phi2(d)); //} -template -void GMap2::sewFaces(Dart d, Dart e, bool withBoundary) +template +void GMap2::sewFaces(Dart d, Dart e, bool withBoundary) { // if sewing with fixed points if (!withBoundary) @@ -489,8 +489,8 @@ void GMap2::sewFaces(Dart d, Dart e, bool withBoundary) beta2sew(e, this->beta0(d)) ; } -template -void GMap2::unsewFaces(Dart d) +template +void GMap2::unsewFaces(Dart d) { assert(!isBoundaryEdge(d)) ; @@ -530,8 +530,8 @@ void GMap2::unsewFaces(Dart d) beta2sew(ee, this->beta0(dd)) ; } -template -bool GMap2::collapseDegeneratedFace(Dart d) +template +bool GMap2::collapseDegeneratedFace(Dart d) { Dart e = this->phi1(d); // Check if the face is a loop if (this->phi1(e) == d) // Yes: it contains one or two edge(s) @@ -563,8 +563,8 @@ bool GMap2::collapseDegeneratedFace(Dart d) return false ; } -template -void GMap2::splitFace(Dart d, Dart e) +template +void GMap2::splitFace(Dart d, Dart e) { assert(d != e && sameFace(d, e)) ; @@ -589,8 +589,8 @@ void GMap2::splitFace(Dart d, Dart e) beta2sew(this->beta0(eprev), this->beta0(beta2(eprev))) ; } -template -bool GMap2::mergeFaces(Dart d) +template +bool GMap2::mergeFaces(Dart d) { if (!isBoundaryEdge(d)) { @@ -605,8 +605,8 @@ bool GMap2::mergeFaces(Dart d) return false ; } -template -void GMap2::extractTrianglePair(Dart d) +template +void GMap2::extractTrianglePair(Dart d) { Dart e = phi2(d) ; @@ -632,8 +632,8 @@ void GMap2::extractTrianglePair(Dart d) beta2sew(e2, this->beta0(e1)) ; } -template -void GMap2::insertTrianglePair(Dart d, Dart v1, Dart v2) +template +void GMap2::insertTrianglePair(Dart d, Dart v1, Dart v2) { Dart e = phi2(d) ; @@ -657,10 +657,10 @@ void GMap2::insertTrianglePair(Dart d, Dart v1, Dart v2) beta2sew(this->beta0(this->phi1(e)), vv2) ; } -template -bool GMap2::mergeVolumes(Dart d, Dart e) +template +bool GMap2::mergeVolumes(Dart d, Dart e) { - assert(!this->isBoundaryMarked2(d) && !this->isBoundaryMarked2(e)) ; + assert(!this->template isBoundaryMarked<2>(d) && !this->template isBoundaryMarked<2>(e)) ; if (GMap2::isBoundaryFace(d) || GMap2::isBoundaryFace(e)) return false; @@ -710,8 +710,8 @@ bool GMap2::mergeVolumes(Dart d, Dart e) return true ; } -template -void GMap2::splitSurface(std::vector& vd, bool firstSideClosed, bool secondSideClosed) +template +void GMap2::splitSurface(std::vector& vd, bool firstSideClosed, bool secondSideClosed) { //assert(checkSimpleOrientedPath(vd)) ; Dart e = vd.front() ; @@ -735,8 +735,8 @@ void GMap2::splitSurface(std::vector& vd, bool firstSideClosed, bool * Return or set various topological information *************************************************************************/ -template -bool GMap2::sameOrientedVertex(Dart d, Dart e) const +template +bool GMap2::sameOrientedVertex(Dart d, Dart e) const { Dart it = d; do @@ -748,14 +748,14 @@ bool GMap2::sameOrientedVertex(Dart d, Dart e) const return false; // None is equal to e => vertices are distinct } -template -inline bool GMap2::sameVertex(Dart d, Dart e) const +template +inline bool GMap2::sameVertex(Dart d, Dart e) const { return sameOrientedVertex(d, e) || sameOrientedVertex(beta2(d), e) ; } -template -unsigned int GMap2::vertexDegree(Dart d) const +template +unsigned int GMap2::vertexDegree(Dart d) const { unsigned int count = 0 ; Dart it = d ; @@ -767,8 +767,8 @@ unsigned int GMap2::vertexDegree(Dart d) const return count ; } -template -int GMap2::checkVertexDegree(Dart d, unsigned int vd) const +template +int GMap2::checkVertexDegree(Dart d, unsigned int vd) const { unsigned int count = 0 ; Dart it = d ; @@ -781,85 +781,85 @@ int GMap2::checkVertexDegree(Dart d, unsigned int vd) const return count-vd; } -template -bool GMap2::isBoundaryVertex(Dart d) const +template +bool GMap2::isBoundaryVertex(Dart d) const { Dart it = d ; do { - if (this->isBoundaryMarked2(it)) + if (this->template isBoundaryMarked<2>(it)) return true ; it = alpha1(it) ; } while (it != d) ; return false ; } -template -Dart GMap2::findBoundaryEdgeOfVertex(Dart d) const +template +Dart GMap2::findBoundaryEdgeOfVertex(Dart d) const { Dart it = d ; do { - if (this->isBoundaryMarked2(it)) + if (this->template isBoundaryMarked<2>(it)) return it ; it = alpha1(it) ; } while (it != d) ; return NIL ; } -template -inline bool GMap2::sameEdge(Dart d, Dart e) const +template +inline bool GMap2::sameEdge(Dart d, Dart e) const { return d == e || beta2(d) == e || this->beta0(d) == e || beta2(this->beta0(d)) == e ; } -template -inline bool GMap2::isBoundaryEdge(Dart d) const +template +inline bool GMap2::isBoundaryEdge(Dart d) const { - return this->isBoundaryMarked2(d) || this->isBoundaryMarked2(beta2(d)); + return this->template isBoundaryMarked<2>(d) || this->template isBoundaryMarked<2>(beta2(d)); } -template -inline bool GMap2::sameOrientedFace(Dart d, Dart e) const +template +inline bool GMap2::sameOrientedFace(Dart d, Dart e) const { return ParentMap::sameOrientedCycle(d, e) ; } -template -inline bool GMap2::sameFace(Dart d, Dart e) const +template +inline bool GMap2::sameFace(Dart d, Dart e) const { return ParentMap::sameCycle(d, e) ; } -template -inline unsigned int GMap2::faceDegree(Dart d) const +template +inline unsigned int GMap2::faceDegree(Dart d) const { return ParentMap::cycleDegree(d) ; } -template -inline int GMap2::checkFaceDegree(Dart d, unsigned int le) const +template +inline int GMap2::checkFaceDegree(Dart d, unsigned int le) const { return ParentMap::checkCycleDegree(d,le) ; } -template -bool GMap2::isBoundaryFace(Dart d) const +template +bool GMap2::isBoundaryFace(Dart d) const { Dart it = d ; do { - if (this->isBoundaryMarked2(beta2(it))) + if (this->template isBoundaryMarked<2>(beta2(it))) return true ; it = this->phi1(it) ; } while (it != d) ; return false ; } -template -bool GMap2::sameOrientedVolume(Dart d, Dart e) const +template +bool GMap2::sameOrientedVolume(Dart d, Dart e) const { - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::list visitedFaces; // Faces that are traversed visitedFaces.push_back(d); // Start with the face of d @@ -887,17 +887,17 @@ bool GMap2::sameOrientedVolume(Dart d, Dart e) const return false; } -template -inline bool GMap2::sameVolume(Dart d, Dart e) const +template +inline bool GMap2::sameVolume(Dart d, Dart e) const { return sameOrientedVolume(d, e) || sameOrientedVolume(beta2(d), e) ; } -template -unsigned int GMap2::volumeDegree(Dart d) const +template +unsigned int GMap2::volumeDegree(Dart d) const { unsigned int count = 0; - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(16); @@ -908,7 +908,7 @@ unsigned int GMap2::volumeDegree(Dart d) const for (unsigned int i = 0; i != visitedFaces.size(); ++i) { Dart df = visitedFaces[i]; - if (!this->isBoundaryMarked2(df) && !mark.isMarked(df)) // Face has not been visited yet + if (!this->template isBoundaryMarked<2>(df) && !mark.isMarked(df)) // Face has not been visited yet { ++count; Dart it = df ; @@ -926,11 +926,11 @@ unsigned int GMap2::volumeDegree(Dart d) const return count; } -template -int GMap2::checkVolumeDegree(Dart d, unsigned int volDeg) const +template +int GMap2::checkVolumeDegree(Dart d, unsigned int volDeg) const { unsigned int count = 0; - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(16); @@ -941,7 +941,7 @@ int GMap2::checkVolumeDegree(Dart d, unsigned int volDeg) const for (unsigned int i = 0; i != visitedFaces.size(); ++i) { Dart df = visitedFaces[i]; - if (!this->isBoundaryMarked2(df) && !mark.isMarked(df)) // Face has not been visited yet + if (!this->template isBoundaryMarked<2>(df) && !mark.isMarked(df)) // Face has not been visited yet { ++count; Dart it = df ; @@ -961,8 +961,8 @@ int GMap2::checkVolumeDegree(Dart d, unsigned int volDeg) const return count - volDeg; } -template -bool GMap2::isTriangular() const +template +bool GMap2::isTriangular() const { TraversorF t(*this) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) @@ -973,8 +973,8 @@ bool GMap2::isTriangular() const return true ; } -template -bool GMap2::check() const +template +bool GMap2::check() const { CGoGNout << "Check: topology begin" << CGoGNendl; for(Dart d = this->begin(); d != this->end(); this->next(d)) @@ -1008,16 +1008,16 @@ bool GMap2::check() const return true; } -template -bool GMap2::checkSimpleOrientedPath(std::vector& vd) +template +bool GMap2::checkSimpleOrientedPath(std::vector& vd) { - DartMarkerStore dm(*this) ; + DartMarkerStore dm(*this) ; for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) { if(dm.isMarked(*it)) return false ; - dm.markOrbit(*it) ; + dm.template markOrbit(*it) ; std::vector::iterator prev ; if(it == vd.begin()) @@ -1035,8 +1035,8 @@ bool GMap2::checkSimpleOrientedPath(std::vector& vd) * Apply functors to all darts of a cell *************************************************************************/ -template -bool GMap2::foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +bool GMap2::foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const { Dart it = d; do @@ -1048,14 +1048,14 @@ bool GMap2::foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigne return false; } -template -inline bool GMap2::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap2::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const { - return GMap2::foreach_dart_of_oriented_vertex(d, f, thread) || GMap2::foreach_dart_of_oriented_vertex(this->beta1(d), f, thread) ; + return GMap2::foreach_dart_of_oriented_vertex(d, f, thread) || GMap2::foreach_dart_of_oriented_vertex(this->beta1(d), f, thread) ; } -template -bool GMap2::foreach_dart_of_oriented_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +bool GMap2::foreach_dart_of_oriented_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const { if (f(d)) return true ; @@ -1066,8 +1066,8 @@ bool GMap2::foreach_dart_of_oriented_edge(Dart d, FunctorType& f, unsigned return false ; } -template -bool GMap2::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +bool GMap2::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const { if (f(d)) return true ; @@ -1084,22 +1084,22 @@ bool GMap2::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thr return false ; } -template -inline bool GMap2::foreach_dart_of_oriented_face(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap2::foreach_dart_of_oriented_face(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_oriented_cc(d, f, thread); } -template -inline bool GMap2::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap2::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_cc(d, f, thread); } -template -bool GMap2::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsigned int thread) const +template +bool GMap2::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mark(*this, thread); // Lock a marker + DartMarkerStore mark(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector visitedFaces; // Faces that are traversed @@ -1133,20 +1133,20 @@ bool GMap2::foreach_dart_of_oriented_cc(Dart d, FunctorType& f, unsigned in return found; } -template -inline bool GMap2::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap2::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const { - return GMap2::foreach_dart_of_oriented_cc(d, f, thread) || GMap2::foreach_dart_of_oriented_cc(this->beta0(d), f, thread) ; + return GMap2::foreach_dart_of_oriented_cc(d, f, thread) || GMap2::foreach_dart_of_oriented_cc(this->beta0(d), f, thread) ; } -template -inline bool GMap2::foreach_dart_of_vertex1(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap2::foreach_dart_of_vertex1(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_vertex(d,f,thread); } -template -inline bool GMap2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_edge(d,f,thread); } @@ -1155,16 +1155,16 @@ inline bool GMap2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned i * These functions must be used with care, generally only by import/creation algorithms *************************************************************************/ -template -Dart GMap2::newBoundaryCycle(unsigned int nbE) +template +Dart GMap2::newBoundaryCycle(unsigned int nbE) { Dart d = ParentMap::newCycle(nbE); - this->template boundaryMarkOrbit(d); + this->template boundaryMarkOrbit(d); return d; } -template -unsigned int GMap2::closeHole(Dart d, bool forboundary) +template +unsigned int GMap2::closeHole(Dart d, bool forboundary) { assert(beta2(d) == d); // Nothing to close @@ -1206,8 +1206,8 @@ unsigned int GMap2::closeHole(Dart d, bool forboundary) return countEdges ; } -template -unsigned int GMap2::closeMap() +template +unsigned int GMap2::closeMap() { // Search the map for topological holes (fix points of phi2) unsigned int nb = 0 ; @@ -1226,8 +1226,8 @@ unsigned int GMap2::closeMap() * These functions compute the dual mesh *************************************************************************/ -template -void GMap2::computeDual() +template +void GMap2::computeDual() { // DartAttribute old_beta0 = this->getAttribute("beta0"); // DartAttribute old_beta2 = this->getAttribute("beta2") ; diff --git a/include/Topology/gmap/gmap3.h b/include/Topology/gmap/gmap3.h index 65739a9d3b8547109f4e58e8652b821e9537c5d3..7367fd5d189c6ef292040b676cb7b7ad113e047e 100644 --- a/include/Topology/gmap/gmap3.h +++ b/include/Topology/gmap/gmap3.h @@ -33,14 +33,15 @@ namespace CGoGN /** * The class of 3-GMap */ -template -class GMap3 : public GMap2 +template +class GMap3 : public GMap2 { protected: void init() ; public: - typedef GMap2 ParentMap; + typedef MAP_IMPL IMPL; + typedef GMap2 ParentMap; inline static unsigned int ORBIT_IN_PARENT(unsigned int o) { return o+7; } inline static unsigned int ORBIT_IN_PARENT2(unsigned int o) { return o+5; } @@ -274,6 +275,12 @@ public: bool isBoundaryVolume(Dart d) const; virtual bool check() const; + + template + unsigned int getNbOrbits() + { + return MapCommon::template getNbOrbits(); + } //@} /*! @name Cell Functors diff --git a/include/Topology/gmap/gmap3.hpp b/include/Topology/gmap/gmap3.hpp index 0ea6e9356bb785572df8507cccf4b242b78eeb6e..5487fd5ddb6852b092216bff7ad9b7c03b4e47e8 100644 --- a/include/Topology/gmap/gmap3.hpp +++ b/include/Topology/gmap/gmap3.hpp @@ -27,40 +27,40 @@ namespace CGoGN { -template -inline void GMap3::init() +template +inline void GMap3::init() { - MAP::addInvolution() ; + MAP_IMPL::addInvolution() ; } -template -inline GMap3::GMap3() : GMap2() +template +inline GMap3::GMap3() : GMap2() { init() ; } -template -inline std::string GMap3::mapTypeName() const +template +inline std::string GMap3::mapTypeName() const { return "GMap3"; } -template -inline unsigned int GMap3::dimension() const +template +inline unsigned int GMap3::dimension() const { return 3; } -template -inline void GMap3::clear(bool removeAttrib) +template +inline void GMap3::clear(bool removeAttrib) { ParentMap::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void GMap3::update_topo_shortcuts() +template +inline void GMap3::update_topo_shortcuts() { ParentMap::update_topo_shortcuts(); // m_beta3 = getRelation("beta3"); @@ -70,15 +70,15 @@ inline void GMap3::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart GMap3::beta3(Dart d) const +template +inline Dart GMap3::beta3(Dart d) const { - return MAP::template getInvolution<3>(d); + return MAP_IMPL::template getInvolution<3>(d); } -template +template template -inline Dart GMap3::beta(const Dart d) const +inline Dart GMap3::beta(const Dart d) const { assert( (N > 0) || !"negative parameters not allowed in template multi-beta"); if (N<10) @@ -102,15 +102,15 @@ inline Dart GMap3::beta(const Dart d) const } } -template -inline Dart GMap3::phi3(Dart d) const +template +inline Dart GMap3::phi3(Dart d) const { return beta3(this->beta0(d)) ; } -template +template template -inline Dart GMap3::phi(Dart d) const +inline Dart GMap3::phi(Dart d) const { assert( (N >0) || !"negative parameters not allowed in template multi-phi"); if (N<10) @@ -132,50 +132,50 @@ inline Dart GMap3::phi(Dart d) const } } -template -inline Dart GMap3::alpha0(Dart d) const +template +inline Dart GMap3::alpha0(Dart d) const { return beta3(this->beta0(d)) ; } -template -inline Dart GMap3::alpha1(Dart d) const +template +inline Dart GMap3::alpha1(Dart d) const { return beta3(this->beta1(d)) ; } -template -inline Dart GMap3::alpha2(Dart d) const +template +inline Dart GMap3::alpha2(Dart d) const { return beta3(this->beta2(d)) ; } -template -inline Dart GMap3::alpha_2(Dart d) const +template +inline Dart GMap3::alpha_2(Dart d) const { return beta2(beta3(d)) ; } -template -inline void GMap3::beta3sew(Dart d, Dart e) +template +inline void GMap3::beta3sew(Dart d, Dart e) { - MAP::template involutionSew<3>(d,e); + MAP_IMPL::template involutionSew<3>(d,e); } -template -inline void GMap3::beta3unsew(Dart d) +template +inline void GMap3::beta3unsew(Dart d) { - MAP::template involutionUnsew<3>(d); + MAP_IMPL::template involutionUnsew<3>(d); } /*! @name Generator and Deletor * To generate or delete volumes in a 3-G-map *************************************************************************/ -template -void GMap3::deleteVolume(Dart d) +template +void GMap3::deleteVolume(Dart d) { - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(512); @@ -207,12 +207,12 @@ void GMap3::deleteVolume(Dart d) ParentMap::deleteCC(dd) ; } -template -void GMap3::fillHole(Dart d) +template +void GMap3::fillHole(Dart d) { assert(isBoundaryFace(d)) ; Dart dd = d ; - if(!this->isBoundaryMarked3(dd)) + if(!this->template isBoundaryMarked<3>(dd)) dd = phi3(dd) ; this->template boundaryUnmarkOrbit(dd) ; } @@ -221,8 +221,8 @@ void GMap3::fillHole(Dart d) * Topological operations on 3-G-maps *************************************************************************/ -template -Dart GMap3::deleteVertex(Dart d) +template +Dart GMap3::deleteVertex(Dart d) { if(isBoundaryVertex(d)) return NIL ; @@ -237,12 +237,12 @@ Dart GMap3::deleteVertex(Dart d) // just one dart per face std::vector fstore; fstore.reserve(128); - DartMarker mf(*this); + DartMarker mf(*this); for(unsigned int i = 0; i < fstoretmp.size(); ++i) { if(!mf.isMarked(fstoretmp[i])) { - mf.markOrbit(fstoretmp[i]); + mf.template markOrbit(fstoretmp[i]); fstore.push_back(fstoretmp[i]); } } @@ -282,8 +282,8 @@ Dart GMap3::deleteVertex(Dart d) return res ; } -template -Dart GMap3::cutEdge(Dart d) +template +Dart GMap3::cutEdge(Dart d) { Dart prev = d ; Dart dd = alpha2(d) ; @@ -308,8 +308,8 @@ Dart GMap3::cutEdge(Dart d) return nd ; } -template -bool GMap3::uncutEdge(Dart d) +template +bool GMap3::uncutEdge(Dart d) { if(vertexDegree(this->phi1(d)) == 2) { @@ -329,16 +329,16 @@ bool GMap3::uncutEdge(Dart d) return false; } -template -bool GMap3::deleteEdgePreCond(Dart d) +template +bool GMap3::deleteEdgePreCond(Dart d) { unsigned int nb1 = vertexDegree(d); unsigned int nb2 = vertexDegree(this->phi1(d)); return (nb1!=2) && (nb2!=2); } -template -Dart GMap3::deleteEdge(Dart d) +template +Dart GMap3::deleteEdge(Dart d) { assert(deleteEdgePreCond(d)); @@ -381,14 +381,14 @@ Dart GMap3::deleteEdge(Dart d) return res ; } -template -bool GMap3::splitFacePreCond(Dart d, Dart e) +template +bool GMap3::splitFacePreCond(Dart d, Dart e) { return (d != e && ParentMap::sameFace(d, e)) ; } -template -void GMap3::splitFace(Dart d, Dart e) +template +void GMap3::splitFace(Dart d, Dart e) { assert(splitFacePreCond(d, e)); @@ -421,8 +421,8 @@ void GMap3::splitFace(Dart d, Dart e) beta3sew(this->beta0(eeprev), this->beta0(beta3(eeprev))) ; } -template -void GMap3::sewVolumes(Dart d, Dart e, bool withBoundary) +template +void GMap3::sewVolumes(Dart d, Dart e, bool withBoundary) { assert(this->faceDegree(d) == this->faceDegree(e)); @@ -482,8 +482,8 @@ void GMap3::sewVolumes(Dart d, Dart e, bool withBoundary) } while(fitD != d) ; } -template -void GMap3::unsewVolumes(Dart d) +template +void GMap3::unsewVolumes(Dart d) { assert(!isBoundaryFace(d)) ; @@ -530,8 +530,8 @@ void GMap3::unsewVolumes(Dart d) } while(fitB1 != b1) ; } -template -bool GMap3::mergeVolumes(Dart d) +template +bool GMap3::mergeVolumes(Dart d) { if(!GMap3::isBoundaryFace(d)) { @@ -541,8 +541,8 @@ bool GMap3::mergeVolumes(Dart d) return false ; } -template -void GMap3::splitVolume(std::vector& vd) +template +void GMap3::splitVolume(std::vector& vd) { assert(ParentMap::checkSimpleOrientedPath(vd)) ; @@ -572,10 +572,10 @@ void GMap3::splitVolume(std::vector& vd) * Return or set various topological information *************************************************************************/ -template -bool GMap3::sameOrientedVertex(Dart d, Dart e) const +template +bool GMap3::sameOrientedVertex(Dart d, Dart e) const { - DartMarkerStore mv(*this); // Lock a marker + DartMarkerStore mv(*this); // Lock a marker std::vector darts; // Darts that are traversed darts.reserve(256); @@ -606,10 +606,10 @@ bool GMap3::sameOrientedVertex(Dart d, Dart e) const return false; } -template -bool GMap3::sameVertex(Dart d, Dart e) const +template +bool GMap3::sameVertex(Dart d, Dart e) const { - DartMarkerStore mv(*this); // Lock a marker + DartMarkerStore mv(*this); // Lock a marker std::vector darts; // Darts that are traversed darts.reserve(256); @@ -643,8 +643,8 @@ bool GMap3::sameVertex(Dart d, Dart e) const return false; } -//template -//unsigned int GMap3::vertexDegree(Dart d) +//template +//unsigned int GMap3::vertexDegree(Dart d) //{ // unsigned int count = 0; // DartMarkerStore mv(*this); // Lock a marker @@ -686,12 +686,12 @@ bool GMap3::sameVertex(Dart d, Dart e) const // return count; //} -template -unsigned int GMap3::vertexDegree(Dart d) const +template +unsigned int GMap3::vertexDegree(Dart d) const { unsigned int count = 0; - Traversor3VE > trav3VE(*this, d); + Traversor3VE > trav3VE(*this, d); for(Dart dit = trav3VE.begin() ; dit != trav3VE.end() ; dit = trav3VE.next()) { ++count; @@ -701,12 +701,12 @@ unsigned int GMap3::vertexDegree(Dart d) const } -template -int GMap3::checkVertexDegree(Dart d, unsigned int vd) const +template +int GMap3::checkVertexDegree(Dart d, unsigned int vd) const { unsigned int count = 0; - Traversor3VE > trav3VE(*this, d); + Traversor3VE > trav3VE(*this, d); Dart dit = trav3VE.begin(); for( ; (count<=vd) && (dit != trav3VE.end()) ; dit = trav3VE.next()) { @@ -716,10 +716,10 @@ int GMap3::checkVertexDegree(Dart d, unsigned int vd) const return count - vd; } -template -bool GMap3::isBoundaryVertex(Dart d) const +template +bool GMap3::isBoundaryVertex(Dart d) const { - DartMarkerStore mv(*this); // Lock a marker + DartMarkerStore mv(*this); // Lock a marker std::vector darts; // Darts that are traversed darts.reserve(256); @@ -728,7 +728,7 @@ bool GMap3::isBoundaryVertex(Dart d) const for(unsigned int i = 0; i < darts.size(); ++i) { - if(this->isBoundaryMarked3(darts[i])) + if(this->template isBoundaryMarked<3>(darts[i])) return true ; //add phi21 and phi23 successor if they are not marked yet @@ -750,8 +750,8 @@ bool GMap3::isBoundaryVertex(Dart d) const return false ; } -template -bool GMap3::sameOrientedEdge(Dart d, Dart e) const +template +bool GMap3::sameOrientedEdge(Dart d, Dart e) const { Dart it = d; do @@ -763,8 +763,8 @@ bool GMap3::sameOrientedEdge(Dart d, Dart e) const return false; } -template -bool GMap3::sameEdge(Dart d, Dart e) const +template +bool GMap3::sameEdge(Dart d, Dart e) const { Dart it = d; do @@ -777,8 +777,8 @@ bool GMap3::sameEdge(Dart d, Dart e) const return false; } -template -unsigned int GMap3::edgeDegree(Dart d) const +template +unsigned int GMap3::edgeDegree(Dart d) const { unsigned int deg = 0; Dart it = d; @@ -790,34 +790,34 @@ unsigned int GMap3::edgeDegree(Dart d) const return deg; } -template -bool GMap3::isBoundaryEdge(Dart d) const +template +bool GMap3::isBoundaryEdge(Dart d) const { Dart it = d; do { - if(this->isBoundaryMarked3(it)) + if(this->template isBoundaryMarked<3>(it)) return true ; it = alpha2(it); } while(it != d); return false; } -template -Dart GMap3::findBoundaryFaceOfEdge(Dart d) const +template +Dart GMap3::findBoundaryFaceOfEdge(Dart d) const { Dart it = d; do { - if (this->isBoundaryMarked3(it)) + if (this->template isBoundaryMarked<3>(it)) return it ; it = alpha2(it); } while(it != d); return NIL ; } -template -bool GMap3::sameOrientedFace(Dart d, Dart e) const +template +bool GMap3::sameOrientedFace(Dart d, Dart e) const { Dart it = d; do @@ -829,22 +829,22 @@ bool GMap3::sameOrientedFace(Dart d, Dart e) const return false; } -template -inline bool GMap3::sameFace(Dart d, Dart e) const +template +inline bool GMap3::sameFace(Dart d, Dart e) const { return ParentMap::sameFace(d, e) || ParentMap::sameFace(beta3(d), e) ; } -template -inline bool GMap3::isBoundaryFace(Dart d) const +template +inline bool GMap3::isBoundaryFace(Dart d) const { - return this->isBoundaryMarked3(d) || this->isBoundaryMarked3(beta3(d)); + return this->template isBoundaryMarked<3>(d) || this->template isBoundaryMarked<3>(beta3(d)); } -template -bool GMap3::isBoundaryVolume(Dart d) const +template +bool GMap3::isBoundaryVolume(Dart d) const { - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces ; visitedFaces.reserve(128) ; @@ -871,11 +871,11 @@ bool GMap3::isBoundaryVolume(Dart d) const return false; } -template -bool GMap3::check() const +template +bool GMap3::check() const { CGoGNout << "Check: topology begin" << CGoGNendl; - DartMarker m(*this); + DartMarker m(*this); m.unmarkAll(); for(Dart d = this->begin(); d != this->end(); this->next(d)) { @@ -955,10 +955,10 @@ bool GMap3::check() const * Apply functors to all darts of a cell *************************************************************************/ -template -bool GMap3::foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigned int thread) const +template +bool GMap3::foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mv(*this, thread); // Lock a marker + DartMarkerStore mv(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector darts; // Darts that are traversed @@ -989,10 +989,10 @@ bool GMap3::foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigne return found; } -template -bool GMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const +template +bool GMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mv(*this, thread); // Lock a marker + DartMarkerStore mv(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector darts; // Darts that are traversed @@ -1026,8 +1026,8 @@ bool GMap3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thr return found; } -template -bool GMap3::foreach_dart_of_oriented_edge(Dart d, FunctorType& f, unsigned int thread) const +template +bool GMap3::foreach_dart_of_oriented_edge(Dart d, FunctorType& f, unsigned int thread) const { Dart it = d; do @@ -1039,8 +1039,8 @@ bool GMap3::foreach_dart_of_oriented_edge(Dart d, FunctorType& f, unsigned return false; } -template -bool GMap3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread) const +template +bool GMap3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread) const { Dart it = d; do @@ -1052,28 +1052,28 @@ bool GMap3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int threa return false; } -template -inline bool GMap3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_face(d, f, thread) || ParentMap::foreach_dart_of_face(beta3(d), f, thread); } -template -inline bool GMap3::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap3::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_cc(d, f, thread); } -template -inline bool GMap3::foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap3::foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_oriented_cc(d, f, thread); } -template -bool GMap3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const +template +bool GMap3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mv(*this,thread); // Lock a marker + DartMarkerStore mv(*this,thread); // Lock a marker bool found = false; // Last functor return value std::vector darts; // Darts that are traversed @@ -1113,20 +1113,20 @@ bool GMap3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) return found; } -template -inline bool GMap3::foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap3::foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_vertex(d, f, thread); } -template -inline bool GMap3::foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap3::foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_edge(d, f, thread); } -template -inline bool GMap3::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool GMap3::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_face(d, f, thread); } @@ -1135,24 +1135,24 @@ inline bool GMap3::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned i * These functions must be used with care, generally only by import/creation algorithms *************************************************************************/ -template -Dart GMap3::newBoundaryCycle(unsigned int nbE) +template +Dart GMap3::newBoundaryCycle(unsigned int nbE) { - Dart d = GMap1::newCycle(nbE); - this->template boundaryMarkOrbit(d); + Dart d = GMap1::newCycle(nbE); + this->template boundaryMarkOrbit(d); return d; } -template -unsigned int GMap3::closeHole(Dart d, bool forboundary) +template +unsigned int GMap3::closeHole(Dart d, bool forboundary) { assert(beta3(d) == d); // Nothing to close - DartMarkerStore m(*this) ; + DartMarkerStore m(*this) ; std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(1024) ; visitedFaces.push_back(d); // Start with the face of d - m.markOrbit(d) ; + m.template markOrbit(d) ; unsigned int count = 0 ; @@ -1177,10 +1177,10 @@ unsigned int GMap3::closeHole(Dart d, bool forboundary) if(!m.isMarked(e)) { visitedFaces.push_back(e) ; - m.markOrbit(e) ; + m.template markOrbit(e) ; } } - else if(this->isBoundaryMarked3(e)) + else if(this->template isBoundaryMarked<3>(e)) { found = true ; this->beta2sew(e, bit) ; @@ -1200,8 +1200,8 @@ unsigned int GMap3::closeHole(Dart d, bool forboundary) return count ; } -template -unsigned int GMap3::closeMap() +template +unsigned int GMap3::closeMap() { // Search the map for topological holes (fix points of beta3) unsigned int nb = 0 ; @@ -1220,8 +1220,8 @@ unsigned int GMap3::closeMap() * These functions compute the dual mesh *************************************************************************/ -template -void GMap3::computeDual() +template +void GMap3::computeDual() { // DartAttribute old_beta0 = getAttribute("beta0"); // DartAttribute old_beta1 = getAttribute("beta1"); diff --git a/include/Topology/ihmap/ihm2.h b/include/Topology/ihmap/ihm2.h index 8c60447102726caf70eeb1bd9db07c823bf78bda..9b21426fb78fd826a314a9f6ba10e21ebe12b919 100644 --- a/include/Topology/ihmap/ihm2.h +++ b/include/Topology/ihmap/ihm2.h @@ -32,6 +32,8 @@ namespace CGoGN template class AttributeHandler_IHM ; +typedef EmbeddedMap2::IMPL EMap2_IMPL; + class ImplicitHierarchicalMap2 : public EmbeddedMap2 { template friend class AttributeHandler_IHM ; @@ -41,8 +43,8 @@ private: unsigned int m_maxLevel ; unsigned int m_idCount ; - DartAttribute m_dartLevel ; - DartAttribute m_edgeId ; + DartAttribute m_dartLevel ; + DartAttribute m_edgeId ; AttributeMultiVector* m_nextLevelCell[NB_ORBITS] ; @@ -231,25 +233,25 @@ public: } ; template -class AttributeHandler_IHM : public AttributeHandler +class AttributeHandler_IHM : public AttributeHandler { public: typedef T DATA_TYPE ; - AttributeHandler_IHM() : AttributeHandler() + AttributeHandler_IHM() : AttributeHandler() {} - AttributeHandler_IHM(GenericMap* m, AttributeMultiVector* amv) : AttributeHandler(m, amv) + AttributeHandler_IHM(ImplicitHierarchicalMap2* m, AttributeMultiVector* amv) : AttributeHandler(m, amv) {} AttributeMultiVector* getDataVector() const { - return AttributeHandler::getDataVector() ; + return AttributeHandler::getDataVector() ; } bool isValid() const { - return AttributeHandler::isValid() ; + return AttributeHandler::isValid() ; } T& operator[](Dart d) ; @@ -258,12 +260,12 @@ public: T& operator[](unsigned int a) { - return AttributeHandler::operator[](a) ; + return AttributeHandler::operator[](a) ; } const T& operator[](unsigned int a) const { - return AttributeHandler::operator[](a) ; + return AttributeHandler::operator[](a) ; } } ; diff --git a/include/Topology/ihmap/ihm2.hpp b/include/Topology/ihmap/ihm2.hpp index 72aad1fc50628164d1181f98c2733df8bd740f8a..15673ff8aa4bcc9f9f9833986eb3180372e27939 100644 --- a/include/Topology/ihmap/ihm2.hpp +++ b/include/Topology/ihmap/ihm2.hpp @@ -36,7 +36,7 @@ AttributeHandler_IHM ImplicitHierarchicalMap2::addAttribute(const std: if(!isOrbitEmbedded()) addNextLevelCell = true ; - AttributeHandler h = Map2::addAttribute(nameAttr) ; + AttributeHandler h = Map2::addAttribute(nameAttr) ; if(addNextLevelCell) { @@ -53,7 +53,7 @@ AttributeHandler_IHM ImplicitHierarchicalMap2::addAttribute(const std: template AttributeHandler_IHM ImplicitHierarchicalMap2::getAttribute(const std::string& nameAttr) { - AttributeHandler h = Map2::getAttribute(nameAttr) ; + AttributeHandler h = Map2::getAttribute(nameAttr) ; return AttributeHandler_IHM(this, h.getDataVector()) ; } @@ -208,7 +208,7 @@ inline bool ImplicitHierarchicalMap2::foreach_dart_of_face(Dart d, FunctorType& inline bool ImplicitHierarchicalMap2::foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mark(*this, thread); // Lock a marker + DartMarkerStore mark(*this, thread); // Lock a marker bool found = false; // Last functor return value std::list visitedFaces; // Faces that are traversed diff --git a/include/Topology/map/embeddedMap2.h b/include/Topology/map/embeddedMap2.h index ed3899bb63909c377c2a88eed1c02af356b19f34..6b560a2ece5fd42efbf8eea8d5f0656665bcbda5 100644 --- a/include/Topology/map/embeddedMap2.h +++ b/include/Topology/map/embeddedMap2.h @@ -37,6 +37,7 @@ namespace CGoGN class EmbeddedMap2 : public Map2 { public: + typedef MapMono IMPL; typedef Map2 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; diff --git a/include/Topology/map/embeddedMap3.h b/include/Topology/map/embeddedMap3.h index c9619dbe35ba6f39cd7e5c365cc1209eb67948b8..d8e1a899c08e15618a695ac9031dc81612764a22 100644 --- a/include/Topology/map/embeddedMap3.h +++ b/include/Topology/map/embeddedMap3.h @@ -35,6 +35,7 @@ namespace CGoGN class EmbeddedMap3 : public Map3 { public: + typedef MapMono IMPL; typedef Map3 TOPO_MAP; static const unsigned int DIMENSION = TOPO_MAP::DIMENSION ; diff --git a/include/Topology/map/map1.h b/include/Topology/map/map1.h index 25e4b2df5b3635156efc4c6f9327e0480fd15dea..c35bc1cda172cd6525646be8cf0fa096c6d05ea7 100644 --- a/include/Topology/map/map1.h +++ b/include/Topology/map/map1.h @@ -25,7 +25,7 @@ #ifndef __MAP1_H__ #define __MAP1_H__ -#include "Topology/generic/mapMono.h" +#include "Topology/generic/mapCommon.h" #include "Topology/generic/dartmarker.h" #include "Topology/generic/cellmarker.h" @@ -40,13 +40,15 @@ namespace CGoGN * - Faces with only one edge (sometime called loops) are accepted. * - Degenerated faces with only two edges are accepted. */ -template -class Map1 : public MAP +template +class Map1 : public MapCommon { protected: void init() ; public: + typedef MAP_IMPL IMPL; + Map1(); static const unsigned int DIMENSION = 1 ; @@ -189,6 +191,12 @@ public: * @return a boolean indicating if the cycle is a triangle */ bool isCycleTriangle(Dart d) const; + + template + unsigned int getNbOrbits() + { + return MapCommon::template getNbOrbits(); + } //@} /*! @name Cell Functors diff --git a/include/Topology/map/map1.hpp b/include/Topology/map/map1.hpp index f76f6378aaf0a1ec173e100ab5b9b80e893ae429..0ec6f2d760c7a9536d81d2843e4073829b5b2f3c 100644 --- a/include/Topology/map/map1.hpp +++ b/include/Topology/map/map1.hpp @@ -27,42 +27,42 @@ namespace CGoGN /// INLINE FUNCTIONS -template -inline void Map1::init() +template +inline void Map1::init() { - MAP::addPermutation() ; + MAP_IMPL::addPermutation() ; } -template -inline Map1::Map1() : MAP() +template +inline Map1::Map1() : MapCommon() { init() ; } -template -inline std::string Map1::mapTypeName() const +template +inline std::string Map1::mapTypeName() const { return "Map1" ; } -template -inline unsigned int Map1::dimension() const +template +inline unsigned int Map1::dimension() const { return 1 ; } -template -inline void Map1::clear(bool removeAttrib) +template +inline void Map1::clear(bool removeAttrib) { - MAP::clear(removeAttrib) ; + MAP_IMPL::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void Map1::update_topo_shortcuts() +template +inline void Map1::update_topo_shortcuts() { - MAP::update_topo_shortcuts(); + MAP_IMPL::update_topo_shortcuts(); // m_phi1 = MAP::getRelation("phi1"); // m_phi_1 = MAP::getRelation("phi_1"); } @@ -71,21 +71,21 @@ inline void Map1::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart Map1::phi1(Dart d) const +template +inline Dart Map1::phi1(Dart d) const { - return MAP::template getPermutation<0>(d); + return MAP_IMPL::template getPermutation<0>(d); } -template -inline Dart Map1::phi_1(Dart d) const +template +inline Dart Map1::phi_1(Dart d) const { - return MAP::template getPermutationInv<0>(d); + return MAP_IMPL::template getPermutationInv<0>(d); } -template +template template -inline Dart Map1::phi(Dart d) const +inline Dart Map1::phi(Dart d) const { assert((N > 0) || !"negative parameters not allowed in template multi-phi"); if (N < 10) @@ -103,46 +103,46 @@ inline Dart Map1::phi(Dart d) const } } -template -inline Dart Map1::alpha1(Dart d) const +template +inline Dart Map1::alpha1(Dart d) const { return phi1(d) ; } -template -inline Dart Map1::alpha_1(Dart d) const +template +inline Dart Map1::alpha_1(Dart d) const { return phi_1(d) ; } -template -inline void Map1::phi1sew(Dart d, Dart e) +template +inline void Map1::phi1sew(Dart d, Dart e) { - MAP::template permutationSew<0>(d,e); + MAP_IMPL::template permutationSew<0>(d,e); } -template -inline void Map1::phi1unsew(Dart d) +template +inline void Map1::phi1unsew(Dart d) { - MAP::template permutationUnsew<0>(d); + MAP_IMPL::template permutationUnsew<0>(d); } /*! @name Generator and Deletor * To generate or delete faces in a 1-map *************************************************************************/ -template -Dart Map1::newCycle(unsigned int nbEdges) +template +Dart Map1::newCycle(unsigned int nbEdges) { assert(nbEdges > 0 || !"Cannot create a face with no edge") ; Dart d = this->newDart() ; // Create the first edge for (unsigned int i = 1 ; i < nbEdges ; ++i) - Map1::cutEdge(d) ; // Subdivide nbEdges-1 times this edge + Map1::cutEdge(d) ; // Subdivide nbEdges-1 times this edge return d ; } -template -void Map1::deleteCycle(Dart d) +template +void Map1::deleteCycle(Dart d) { Dart e = phi1(d) ; while (e != d) @@ -158,61 +158,61 @@ void Map1::deleteCycle(Dart d) * Topological operations on 1-maps *************************************************************************/ -template -inline Dart Map1::cutEdge(Dart d) +template +inline Dart Map1::cutEdge(Dart d) { Dart e = this->newDart() ; // Create a new dart phi1sew(d, e) ; // Insert dart e between d and phi1(d) - if (this->isBoundaryMarked2(d)) - this->boundaryMark2(e); + if (this->template isBoundaryMarked<2>(d)) + this->template boundaryMark<2>(e); - if (this->isBoundaryMarked3(d)) - this->boundaryMark3(e); + if (this->template isBoundaryMarked<3>(d)) + this->template boundaryMark<3>(e); return e ; } -template -inline void Map1::uncutEdge(Dart d) +template +inline void Map1::uncutEdge(Dart d) { Dart d1 = phi1(d) ; phi1unsew(d) ; // Dart d is linked to the successor of its successor this->deleteDart(d1) ; // Dart d1 is erased } -template -inline void Map1::collapseEdge(Dart d) +template +inline void Map1::collapseEdge(Dart d) { phi1unsew(phi_1(d)) ; // Dart before d is linked to its successor this->deleteDart(d) ; // Dart d is erased } -template -inline void Map1::splitCycle(Dart d, Dart e) +template +inline void Map1::splitCycle(Dart d, Dart e) { assert(d != e && sameCycle(d, e)) ; phi1sew(phi_1(d), phi_1(e)) ; } -template -inline void Map1::mergeCycles(Dart d, Dart e) +template +inline void Map1::mergeCycles(Dart d, Dart e) { assert(!sameCycle(d, e)) ; phi1sew(phi_1(d), phi_1(e)) ; } -template -inline void Map1::linkCycles(Dart d, Dart e) +template +inline void Map1::linkCycles(Dart d, Dart e) { assert(d != e && !sameCycle(d, e)) ; - Map1::cutEdge(phi_1(d)); // cut the edge before d (insert a new dart before d) - Map1::cutEdge(phi_1(e)); // cut the edge before e (insert a new dart before e) + Map1::cutEdge(phi_1(d)); // cut the edge before d (insert a new dart before d) + Map1::cutEdge(phi_1(e)); // cut the edge before e (insert a new dart before e) phi1sew(phi_1(d), phi_1(e)) ; // phi1sew between the 2 new inserted darts } -template -void Map1::reverseCycle(Dart d) +template +void Map1::reverseCycle(Dart d) { Dart e = phi1(d) ; // Dart e is the first edge of the new face if (e == d) return ; // Only one edge: nothing to do @@ -234,8 +234,8 @@ void Map1::reverseCycle(Dart d) * Return or set various topological information *************************************************************************/ -template -inline bool Map1::sameCycle(Dart d, Dart e) const +template +inline bool Map1::sameCycle(Dart d, Dart e) const { Dart it = d ; do @@ -247,8 +247,8 @@ inline bool Map1::sameCycle(Dart d, Dart e) const return false ; } -template -inline unsigned int Map1::cycleDegree(Dart d) const +template +inline unsigned int Map1::cycleDegree(Dart d) const { unsigned int count = 0 ; Dart it = d ; @@ -260,8 +260,8 @@ inline unsigned int Map1::cycleDegree(Dart d) const return count ; } -template -inline int Map1::checkCycleDegree(Dart d, unsigned int degree) const +template +inline int Map1::checkCycleDegree(Dart d, unsigned int degree) const { unsigned int count = 0 ; Dart it = d ; @@ -274,8 +274,8 @@ inline int Map1::checkCycleDegree(Dart d, unsigned int degree) const return count-degree; } -template -inline bool Map1::isCycleTriangle(Dart d) const +template +inline bool Map1::isCycleTriangle(Dart d) const { return (phi1(d) != d) && (phi1(phi1(phi1(d))) == d) ; } @@ -284,20 +284,20 @@ inline bool Map1::isCycleTriangle(Dart d) const * Apply functors to all darts of a cell *************************************************************************/ -template -inline bool Map1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool Map1::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const { return f(d) ; } -template -inline bool Map1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool Map1::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int /*thread*/) const { return f(d) ; } -template -inline bool Map1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +inline bool Map1::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int /*thread*/) const { Dart it = d ; do diff --git a/include/Topology/map/map2.h b/include/Topology/map/map2.h index 00a7601f39bc4e76312aea2563680d41de5aa519..4c293355f159496af1d49961981ad46a307f44b2 100644 --- a/include/Topology/map/map2.h +++ b/include/Topology/map/map2.h @@ -45,14 +45,15 @@ namespace CGoGN * - When every edge is phi2-linked, the map is closed. In this case * some optimizations are enabled that speed up the processing of vertices. */ -template -class Map2 : public Map1 +template +class Map2 : public Map1 { protected: void init() ; public: - typedef Map1 ParentMap; + typedef MAP_IMPL IMPL; + typedef Map1 ParentMap; inline static unsigned int ORBIT_IN_PARENT(unsigned int o) { return o+5; } @@ -437,6 +438,12 @@ public: * Check if a serie of darts is an oriented simple close path */ virtual bool checkSimpleOrientedPath(std::vector& vd); + + template + unsigned int getNbOrbits() + { + return MapCommon::template getNbOrbits(); + } //@} /*! @name Cell Functors diff --git a/include/Topology/map/map2.hpp b/include/Topology/map/map2.hpp index 3c72a334e4e28ea630ce0c7c9e89d00850ea12a1..dbf0b5ade27147da8b5b51cc77d01bcc1f6fdc79 100644 --- a/include/Topology/map/map2.hpp +++ b/include/Topology/map/map2.hpp @@ -25,40 +25,40 @@ namespace CGoGN { -template -inline void Map2::init() +template +inline void Map2::init() { - MAP::addInvolution() ; + MAP_IMPL::addInvolution() ; } -template -inline Map2::Map2() : Map1() +template +inline Map2::Map2() : Map1() { init() ; } -template -inline std::string Map2::mapTypeName() const +template +inline std::string Map2::mapTypeName() const { return "Map2" ; } -template -inline unsigned int Map2::dimension() const +template +inline unsigned int Map2::dimension() const { return 2 ; } -template -inline void Map2::clear(bool removeAttrib) +template +inline void Map2::clear(bool removeAttrib) { ParentMap::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void Map2::update_topo_shortcuts() +template +inline void Map2::update_topo_shortcuts() { ParentMap::update_topo_shortcuts(); // m_phi2 = getRelation("phi2"); @@ -68,15 +68,15 @@ inline void Map2::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart Map2::phi2(Dart d) const +template +inline Dart Map2::phi2(Dart d) const { - return MAP::template getInvolution<0>(d); + return MAP_IMPL::template getInvolution<0>(d); } -template +template template -inline Dart Map2::phi(Dart d) const +inline Dart Map2::phi(Dart d) const { assert( (N > 0) || !"negative parameters not allowed in template multi-phi"); if (N < 10) @@ -96,54 +96,54 @@ inline Dart Map2::phi(Dart d) const } } -template -inline Dart Map2::alpha0(Dart d) const +template +inline Dart Map2::alpha0(Dart d) const { return phi2(d) ; } -template -inline Dart Map2::alpha1(Dart d) const +template +inline Dart Map2::alpha1(Dart d) const { return phi2(this->phi_1(d)) ; } -template -inline Dart Map2::alpha_1(Dart d) const +template +inline Dart Map2::alpha_1(Dart d) const { return this->phi1(phi2(d)) ; } -template -inline Dart Map2::phi2_1(Dart d) const +template +inline Dart Map2::phi2_1(Dart d) const { return phi2(this->phi_1(d)) ; } -template -inline Dart Map2::phi12(Dart d) const +template +inline Dart Map2::phi12(Dart d) const { return phi1(phi2(d)) ; } -template -inline void Map2::phi2sew(Dart d, Dart e) +template +inline void Map2::phi2sew(Dart d, Dart e) { - MAP::template involutionSew<0>(d,e); + MAP_IMPL::template involutionSew<0>(d,e); } -template -inline void Map2::phi2unsew(Dart d) +template +inline void Map2::phi2unsew(Dart d) { - MAP::template involutionUnsew<0>(d); + MAP_IMPL::template involutionUnsew<0>(d); } /*! @name Generator and Deletor * To generate or delete faces in a 2-map *************************************************************************/ -template -Dart Map2::newPolyLine(unsigned int nbEdges) +template +Dart Map2::newPolyLine(unsigned int nbEdges) { Dart d = ParentMap::newCycle(2*nbEdges); { @@ -159,8 +159,8 @@ Dart Map2::newPolyLine(unsigned int nbEdges) return d; } -template -Dart Map2::newFace(unsigned int nbEdges, bool withBoundary) +template +Dart Map2::newFace(unsigned int nbEdges, bool withBoundary) { Dart d = ParentMap::newCycle(nbEdges); if (withBoundary) @@ -178,10 +178,10 @@ Dart Map2::newFace(unsigned int nbEdges, bool withBoundary) return d; } -template -void Map2::deleteFace(Dart d, bool withBoundary) +template +void Map2::deleteFace(Dart d, bool withBoundary) { - assert(!this->isBoundaryMarked2(d)) ; + assert(!this->template isBoundaryMarked<2>(d)) ; if (withBoundary) { Dart it = d ; @@ -206,10 +206,10 @@ void Map2::deleteFace(Dart d, bool withBoundary) ParentMap::deleteCycle(d); } -template -void Map2::deleteCC(Dart d) +template +void Map2::deleteCC(Dart d) { - DartMarkerStore mark(*this); + DartMarkerStore mark(*this); std::vector visited; visited.reserve(1024) ; @@ -236,18 +236,18 @@ void Map2::deleteCC(Dart d) this->deleteDart(*it) ; } -template -void Map2::fillHole(Dart d) +template +void Map2::fillHole(Dart d) { assert(isBoundaryEdge(d)) ; Dart dd = d ; - if(!this->isBoundaryMarked2(dd)) + if(!this->template isBoundaryMarked<2>(dd)) dd = phi2(dd) ; this->template boundaryUnmarkOrbit(dd) ; } -template -void Map2::createHole(Dart d) +template +void Map2::createHole(Dart d) { assert(!isBoundaryEdge(d)) ; this->template boundaryMarkOrbit(d) ; @@ -257,8 +257,8 @@ void Map2::createHole(Dart d) * Topological operations on 2-maps *************************************************************************/ -template -void Map2::splitVertex(Dart d, Dart e) +template +void Map2::splitVertex(Dart d, Dart e) { assert(sameVertex(d, e)) ; Dart d2 = phi2(d) ; assert(d != d2) ; @@ -268,8 +268,8 @@ void Map2::splitVertex(Dart d, Dart e) phi2sew(nd, ne) ; // Sew the two faces along the new edge } -template -Dart Map2::deleteVertex(Dart d) +template +Dart Map2::deleteVertex(Dart d) { //TODO utile ? if(isBoundaryVertex(d)) @@ -291,8 +291,8 @@ Dart Map2::deleteVertex(Dart d) return res ; } -template -Dart Map2::cutEdge(Dart d) +template +Dart Map2::cutEdge(Dart d) { Dart e = phi2(d); phi2unsew(d); // remove old phi2 links @@ -303,8 +303,8 @@ Dart Map2::cutEdge(Dart d) return nd; } -template -bool Map2::uncutEdge(Dart d) +template +bool Map2::uncutEdge(Dart d) { if(vertexDegree(this->phi1(d)) == 2) { @@ -319,8 +319,8 @@ bool Map2::uncutEdge(Dart d) return false ; } -template -Dart Map2::collapseEdge(Dart d, bool delDegenerateFaces) +template +Dart Map2::collapseEdge(Dart d, bool delDegenerateFaces) { Dart resV = NIL ; @@ -360,8 +360,8 @@ Dart Map2::collapseEdge(Dart d, bool delDegenerateFaces) return resV ; } -template -bool Map2::flipEdge(Dart d) +template +bool Map2::flipEdge(Dart d) { if (!isBoundaryEdge(d)) { @@ -379,8 +379,8 @@ bool Map2::flipEdge(Dart d) return false ; // cannot flip a border edge } -template -bool Map2::flipBackEdge(Dart d) +template +bool Map2::flipBackEdge(Dart d) { if (!isBoundaryEdge(d)) { @@ -396,8 +396,8 @@ bool Map2::flipBackEdge(Dart d) return false ; // cannot flip a border edge } -template -void Map2::swapEdges(Dart d, Dart e) +template +void Map2::swapEdges(Dart d, Dart e) { assert(!Map2::isBoundaryEdge(d) && !Map2::isBoundaryEdge(e)); @@ -411,16 +411,16 @@ void Map2::swapEdges(Dart d, Dart e) phi2sew(d2, e2); } -template -void Map2::insertEdgeInVertex(Dart d, Dart e) +template +void Map2::insertEdgeInVertex(Dart d, Dart e) { assert(!sameVertex(d,e)); assert(phi2(e) == this->phi_1(e)); this->phi1sew(this->phi_1(d), this->phi_1(e)); } -template -bool Map2::removeEdgeFromVertex(Dart d) +template +bool Map2::removeEdgeFromVertex(Dart d) { if (!isBoundaryEdge(d)) { @@ -430,8 +430,8 @@ bool Map2::removeEdgeFromVertex(Dart d) return false ; } -template -void Map2::sewFaces(Dart d, Dart e, bool withBoundary) +template +void Map2::sewFaces(Dart d, Dart e, bool withBoundary) { // if sewing with fixed points if (!withBoundary) @@ -458,8 +458,8 @@ void Map2::sewFaces(Dart d, Dart e, bool withBoundary) phi2sew(d, e) ; // sew the faces } -template -void Map2::unsewFaces(Dart d, bool withBoundary) +template +void Map2::unsewFaces(Dart d, bool withBoundary) { if (!withBoundary) { @@ -489,8 +489,8 @@ void Map2::unsewFaces(Dart d, bool withBoundary) phi2sew(dd, ee) ; // to the boundary } -template -bool Map2::collapseDegeneratedFace(Dart d) +template +bool Map2::collapseDegeneratedFace(Dart d) { Dart e = this->phi1(d) ; // Check if the face is degenerated if (this->phi1(e) == d) // Yes: it contains one or two edge(s) @@ -514,18 +514,18 @@ bool Map2::collapseDegeneratedFace(Dart d) return false ; } -template -void Map2::splitFace(Dart d, Dart e) +template +void Map2::splitFace(Dart d, Dart e) { - assert(d != e && Map2::sameFace(d, e)) ; + assert(d != e && Map2::sameFace(d, e)) ; Dart dd = ParentMap::cutEdge(this->phi_1(d)) ; Dart ee = ParentMap::cutEdge(this->phi_1(e)) ; ParentMap::splitCycle(dd, ee) ; phi2sew(dd, ee); } -template -bool Map2::mergeFaces(Dart d) +template +bool Map2::mergeFaces(Dart d) { if (!isBoundaryEdge(d)) { @@ -539,8 +539,8 @@ bool Map2::mergeFaces(Dart d) return false ; } -template -void Map2::extractTrianglePair(Dart d) +template +void Map2::extractTrianglePair(Dart d) { Dart e = phi2(d) ; @@ -560,8 +560,8 @@ void Map2::extractTrianglePair(Dart d) phi2sew(e1, e2) ; } -template -void Map2::insertTrianglePair(Dart d, Dart v1, Dart v2) +template +void Map2::insertTrianglePair(Dart d, Dart v1, Dart v2) { Dart e = phi2(d) ; @@ -579,12 +579,12 @@ void Map2::insertTrianglePair(Dart d, Dart v1, Dart v2) phi2sew(this->phi1(e), vv2) ; } -template -bool Map2::mergeVolumes(Dart d, Dart e, bool deleteFace) +template +bool Map2::mergeVolumes(Dart d, Dart e, bool deleteFace) { - assert(!this->isBoundaryMarked2(d) && !this->isBoundaryMarked2(e)) ; + assert(!this->template isBoundaryMarked<2>(d) && !this->template isBoundaryMarked<2>(e)) ; - if (Map2::isBoundaryFace(d) || Map2::isBoundaryFace(e)) + if (Map2::isBoundaryFace(d) || Map2::isBoundaryFace(e)) return false; // First traversal of both faces to check the face sizes @@ -633,8 +633,8 @@ bool Map2::mergeVolumes(Dart d, Dart e, bool deleteFace) return true ; } -template -void Map2::splitSurface(std::vector& vd, bool firstSideClosed, bool secondSideClosed) +template +void Map2::splitSurface(std::vector& vd, bool firstSideClosed, bool secondSideClosed) { // assert(checkSimpleOrientedPath(vd)) ; @@ -644,23 +644,23 @@ void Map2::splitSurface(std::vector& vd, bool firstSideClosed, bool s //unsew the edge path for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) { - //if(!Map2::isBoundaryEdge(*it)) + //if(!Map2::isBoundaryEdge(*it)) unsewFaces(*it) ; } if(firstSideClosed) - Map2::fillHole(e) ; + Map2::fillHole(e) ; if(secondSideClosed) - Map2::fillHole(e2) ; + Map2::fillHole(e2) ; } /*! @name Topological Queries * Return or set various topological information *************************************************************************/ -template -bool Map2::sameOrientedVertex(Dart d, Dart e) const +template +bool Map2::sameOrientedVertex(Dart d, Dart e) const { Dart it = d; // Foreach dart dNext in the vertex of d do @@ -672,14 +672,14 @@ bool Map2::sameOrientedVertex(Dart d, Dart e) const return false; // None is equal to e => vertices are distinct } -template -inline bool Map2::sameVertex(Dart d, Dart e) const +template +inline bool Map2::sameVertex(Dart d, Dart e) const { return sameOrientedVertex(d, e) ; } -template -unsigned int Map2::vertexDegree(Dart d) const +template +unsigned int Map2::vertexDegree(Dart d) const { unsigned int count = 0 ; Dart it = d ; @@ -691,8 +691,8 @@ unsigned int Map2::vertexDegree(Dart d) const return count ; } -template -int Map2::checkVertexDegree(Dart d, unsigned int vd) const +template +int Map2::checkVertexDegree(Dart d, unsigned int vd) const { unsigned int count = 0 ; Dart it = d ; @@ -705,83 +705,83 @@ int Map2::checkVertexDegree(Dart d, unsigned int vd) const return count - vd; } -template -bool Map2::isBoundaryVertex(Dart d) const +template +bool Map2::isBoundaryVertex(Dart d) const { Dart it = d ; do { - if (this->isBoundaryMarked2(it)) + if (this->template isBoundaryMarked<2>(it)) return true ; it = phi2(this->phi_1(it)) ; } while (it != d) ; return false ; } -template -Dart Map2::findBoundaryEdgeOfVertex(Dart d) const +template +Dart Map2::findBoundaryEdgeOfVertex(Dart d) const { Dart it = d ; do { - if (this->isBoundaryMarked2(it)) + if (this->template isBoundaryMarked<2>(it)) return it ; it = phi2(this->phi_1(it)) ; } while (it != d) ; return NIL ; } -template -inline bool Map2::sameEdge(Dart d, Dart e) const +template +inline bool Map2::sameEdge(Dart d, Dart e) const { return d == e || phi2(d) == e ; } -template -inline bool Map2::isBoundaryEdge(Dart d) const +template +inline bool Map2::isBoundaryEdge(Dart d) const { - return this->isBoundaryMarked2(d) || this->isBoundaryMarked2(phi2(d)); + return this->template isBoundaryMarked<2>(d) || this->template isBoundaryMarked<2>(phi2(d)); } -template -inline bool Map2::sameOrientedFace(Dart d, Dart e) const +template +inline bool Map2::sameOrientedFace(Dart d, Dart e) const { return ParentMap::sameCycle(d, e) ; } -template -inline bool Map2::sameFace(Dart d, Dart e) const +template +inline bool Map2::sameFace(Dart d, Dart e) const { return sameOrientedFace(d, e) ; } -template -inline unsigned int Map2::faceDegree(Dart d) const +template +inline unsigned int Map2::faceDegree(Dart d) const { return ParentMap::cycleDegree(d) ; } -template -inline int Map2::checkFaceDegree(Dart d, unsigned int le) const +template +inline int Map2::checkFaceDegree(Dart d, unsigned int le) const { return ParentMap::checkCycleDegree(d,le) ; } -template -bool Map2::isBoundaryFace(Dart d) const +template +bool Map2::isBoundaryFace(Dart d) const { Dart it = d ; do { - if (this->isBoundaryMarked2(phi2(it))) + if (this->template isBoundaryMarked<2>(phi2(it))) return true ; it = this->phi1(it) ; } while (it != d) ; return false ; } -template -Dart Map2::findBoundaryEdgeOfFace(Dart d) const +template +Dart Map2::findBoundaryEdgeOfFace(Dart d) const { Dart it = d ; do @@ -793,10 +793,10 @@ Dart Map2::findBoundaryEdgeOfFace(Dart d) const return NIL ; } -template -bool Map2::sameOrientedVolume(Dart d, Dart e) const +template +bool Map2::sameOrientedVolume(Dart d, Dart e) const { - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::list visitedFaces; // Faces that are traversed visitedFaces.push_back(d); // Start with the face of d @@ -805,7 +805,7 @@ bool Map2::sameOrientedVolume(Dart d, Dart e) const // For every face added to the list for (face = visitedFaces.begin(); face != visitedFaces.end(); ++face) { - if (!this->isBoundaryMarked2(*face) && !mark.isMarked(*face)) // Face has not been visited yet + if (!this->template isBoundaryMarked<2>(*face) && !mark.isMarked(*face)) // Face has not been visited yet { Dart it = *face ; do @@ -824,17 +824,17 @@ bool Map2::sameOrientedVolume(Dart d, Dart e) const return false; } -template -inline bool Map2::sameVolume(Dart d, Dart e) const +template +inline bool Map2::sameVolume(Dart d, Dart e) const { return sameOrientedVolume(d, e) ; } -template -unsigned int Map2::volumeDegree(Dart d) const +template +unsigned int Map2::volumeDegree(Dart d) const { unsigned int count = 0; - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(16); @@ -845,7 +845,7 @@ unsigned int Map2::volumeDegree(Dart d) const for (unsigned int i = 0; i != visitedFaces.size(); ++i) { Dart df = visitedFaces[i]; - if (!this->isBoundaryMarked2(df) && !mark.isMarked(df)) // Face has not been visited yet + if (!this->template isBoundaryMarked<2>(df) && !mark.isMarked(df)) // Face has not been visited yet { ++count; Dart it = df ; @@ -863,11 +863,11 @@ unsigned int Map2::volumeDegree(Dart d) const return count; } -template -int Map2::checkVolumeDegree(Dart d, unsigned int volDeg) const +template +int Map2::checkVolumeDegree(Dart d, unsigned int volDeg) const { unsigned int count = 0; - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(16); @@ -877,7 +877,7 @@ int Map2::checkVolumeDegree(Dart d, unsigned int volDeg) const for (unsigned int i = 0; i != visitedFaces.size(); ++i) { Dart df = visitedFaces[i]; - if (!this->isBoundaryMarked2(df) && !mark.isMarked(df)) // Face has not been visited yet + if (!this->template isBoundaryMarked<2>(df) && !mark.isMarked(df)) // Face has not been visited yet { ++count; Dart it = df ; @@ -897,10 +897,10 @@ int Map2::checkVolumeDegree(Dart d, unsigned int volDeg) const return count - volDeg; } -template -bool Map2::isTriangular() const +template +bool Map2::isTriangular() const { - TraversorF > t(*this) ; + TraversorF > t(*this) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) { if(faceDegree(d) != 3) @@ -909,11 +909,11 @@ bool Map2::isTriangular() const return true ; } -template -bool Map2::check() const +template +bool Map2::check() const { CGoGNout << "Check: topology begin" << CGoGNendl; - DartMarker m(*this); + DartMarker m(*this); for(Dart d = Map2::begin(); d != Map2::end(); Map2::next(d)) { Dart d2 = phi2(d); @@ -964,15 +964,15 @@ bool Map2::check() const return true; } -template -bool Map2::checkSimpleOrientedPath(std::vector& vd) +template +bool Map2::checkSimpleOrientedPath(std::vector& vd) { - DartMarkerStore dm(*this) ; + DartMarkerStore dm(*this) ; for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) { if(dm.isMarked(*it)) return false ; - dm.markOrbit(*it) ; + dm.template markOrbit(*it) ; std::vector::iterator prev ; if(it == vd.begin()) @@ -990,8 +990,8 @@ bool Map2::checkSimpleOrientedPath(std::vector& vd) * Apply functors to all darts of a cell *************************************************************************/ -template -bool Map2::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const +template +bool Map2::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*thread*/) const { Dart dNext = d; do @@ -1003,30 +1003,30 @@ bool Map2::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int /*th return false; } -template -bool Map2::foreach_dart_of_edge(Dart d, FunctorType& fonct, unsigned int /*thread*/) const +template +bool Map2::foreach_dart_of_edge(Dart d, FunctorType& fonct, unsigned int /*thread*/) const { if (fonct(d)) return true; return fonct(phi2(d)); } -template -inline bool Map2::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map2::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_cc(d, f, thread); } -template -inline bool Map2::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map2::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const { return foreach_dart_of_cc(d, f, thread); } -template -bool Map2::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const +template +bool Map2::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mark(*this, thread); // Lock a marker + DartMarkerStore mark(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector visitedFaces; // Faces that are traversed @@ -1060,14 +1060,14 @@ bool Map2::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) return found; } -template -inline bool Map2::foreach_dart_of_vertex1(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map2::foreach_dart_of_vertex1(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_vertex(d,f,thread); } -template -inline bool Map2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_edge(d,f,thread); } @@ -1076,16 +1076,16 @@ inline bool Map2::foreach_dart_of_edge1(Dart d, FunctorType& f, unsigned in * These functions must be used with care, generally only by import/creation algorithms *************************************************************************/ -template -Dart Map2::newBoundaryCycle(unsigned int nbE) +template +Dart Map2::newBoundaryCycle(unsigned int nbE) { Dart d = ParentMap::newCycle(nbE); this->template boundaryMarkOrbit(d); return d; } -template -unsigned int Map2::closeHole(Dart d, bool forboundary) +template +unsigned int Map2::closeHole(Dart d, bool forboundary) { assert(phi2(d) == d); // Nothing to close @@ -1119,8 +1119,8 @@ unsigned int Map2::closeHole(Dart d, bool forboundary) return countEdges ; } -template -unsigned int Map2::closeMap(bool forboundary) +template +unsigned int Map2::closeMap(bool forboundary) { // Search the map for topological holes (fix points of phi2) unsigned int nb = 0 ; @@ -1139,13 +1139,13 @@ unsigned int Map2::closeMap(bool forboundary) * These functions compute the dual mesh *************************************************************************/ -template -void Map2::reverseOrientation() +template +void Map2::reverseOrientation() { - DartAttribute emb0(this, this->template getEmbeddingAttributeVector()) ; + DartAttribute emb0(this, this->template getEmbeddingAttributeVector()) ; if(emb0.isValid()) { - DartAttribute new_emb0 = this->template addAttribute("new_EMB_0") ; + DartAttribute new_emb0 = this->template addAttribute("new_EMB_0") ; for(Dart d = this->begin(); d != this->end(); this->next(d)) new_emb0[d] = emb0[this->phi1(d)] ; @@ -1153,18 +1153,18 @@ void Map2::reverseOrientation() this->removeAttribute(new_emb0) ; } - DartAttribute n_phi1 = this->template getAttribute("phi1") ; - DartAttribute n_phi_1 = this->template getAttribute("phi_1") ; + DartAttribute n_phi1 = this->template getAttribute("phi1") ; + DartAttribute n_phi_1 = this->template getAttribute("phi_1") ; this->template swapAttributes(n_phi1, n_phi_1) ; } -template -void Map2::computeDual() +template +void Map2::computeDual() { - DartAttribute old_phi1 = this->template getAttribute("phi1"); - DartAttribute old_phi_1 = this->template getAttribute("phi_1") ; - DartAttribute new_phi1 = this->template addAttribute("new_phi1") ; - DartAttribute new_phi_1 = this->template addAttribute("new_phi_1") ; + DartAttribute old_phi1 = this->template getAttribute("phi1"); + DartAttribute old_phi_1 = this->template getAttribute("phi_1") ; + DartAttribute new_phi1 = this->template addAttribute("new_phi1") ; + DartAttribute new_phi_1 = this->template addAttribute("new_phi_1") ; for(Dart d = this->begin(); d != this->end(); this->next(d)) { @@ -1188,9 +1188,7 @@ void Map2::computeDual() for(Dart d = this->begin(); d != this->end(); this->next(d)) { if(this->isBoundaryMarked2(d)) - { this->template boundaryMarkOrbit(deleteVertex(phi2(d))); - } } } diff --git a/include/Topology/map/map3.h b/include/Topology/map/map3.h index f4ab168ace039050cfd777927ff2448133ac9785..9395ad231c2927588cf2001e5bce8783aff64495 100644 --- a/include/Topology/map/map3.h +++ b/include/Topology/map/map3.h @@ -47,14 +47,15 @@ namespace CGoGN * some optimizations are enable that speed up the processing of cells. * @param DART the type of dart used in the class */ -template -class Map3 : public Map2 +template +class Map3 : public Map2 { protected: void init() ; public: - typedef Map2 ParentMap; + typedef MAP_IMPL IMPL; + typedef Map2 ParentMap; inline static unsigned int ORBIT_IN_PARENT(unsigned int o){ return o+7; } inline static unsigned int ORBIT_IN_PARENT2(unsigned int o) { return o+5; } @@ -373,6 +374,12 @@ public: /*! Test if phi3 and phi2 ares involutions and if phi1 is a permutation */ virtual bool check() const; + + template + unsigned int getNbOrbits() + { + return MapCommon::template getNbOrbits(); + } //@} /*! @name Cell Functors diff --git a/include/Topology/map/map3.hpp b/include/Topology/map/map3.hpp index 62fb6e551b5c8edad80dc07e4ad035f46177c67e..b3ee9a98b5dc2ef2849df0c5247d326fba13d974 100644 --- a/include/Topology/map/map3.hpp +++ b/include/Topology/map/map3.hpp @@ -27,40 +27,40 @@ namespace CGoGN { -template -inline void Map3::init() +template +inline void Map3::init() { - MAP::addInvolution() ; + MAP_IMPL::addInvolution() ; } -template -inline Map3::Map3() : Map2() +template +inline Map3::Map3() : Map2() { init() ; } -template -inline std::string Map3::mapTypeName() const +template +inline std::string Map3::mapTypeName() const { return "Map3"; } -template -inline unsigned int Map3::dimension() const +template +inline unsigned int Map3::dimension() const { return 3; } -template -inline void Map3::clear(bool removeAttrib) +template +inline void Map3::clear(bool removeAttrib) { ParentMap::clear(removeAttrib) ; if (removeAttrib) init() ; } -template -inline void Map3::update_topo_shortcuts() +template +inline void Map3::update_topo_shortcuts() { ParentMap::update_topo_shortcuts(); // m_phi3 = getRelation("phi3"); @@ -70,15 +70,15 @@ inline void Map3::update_topo_shortcuts() * Access and Modification *************************************************************************/ -template -inline Dart Map3::phi3(Dart d) const +template +inline Dart Map3::phi3(Dart d) const { - return MAP::template getInvolution<1>(d); + return MAP_IMPL::template getInvolution<1>(d); } -template +template template -inline Dart Map3::phi(Dart d) const +inline Dart Map3::phi(Dart d) const { assert( (N >0) || !"negative parameters not allowed in template multi-phi"); if (N<10) @@ -100,58 +100,58 @@ inline Dart Map3::phi(Dart d) const } } -template -inline Dart Map3::alpha0(Dart d) const +template +inline Dart Map3::alpha0(Dart d) const { return phi3(d) ; } -template -inline Dart Map3::alpha1(Dart d) const +template +inline Dart Map3::alpha1(Dart d) const { return phi3(this->phi_1(d)) ; } -template -inline Dart Map3::alpha2(Dart d) const +template +inline Dart Map3::alpha2(Dart d) const { return phi3(this->phi2(d)); } -template -inline Dart Map3::alpha_2(Dart d) const +template +inline Dart Map3::alpha_2(Dart d) const { return this->phi2(phi3(d)); } -template -inline void Map3::phi3sew(Dart d, Dart e) +template +inline void Map3::phi3sew(Dart d, Dart e) { - MAP::template involutionSew<1>(d,e); + MAP_IMPL::template involutionSew<1>(d,e); } -template -inline void Map3::phi3unsew(Dart d) +template +inline void Map3::phi3unsew(Dart d) { - MAP::template involutionUnsew<1>(d); + MAP_IMPL::template involutionUnsew<1>(d); } /*! @name Generator and Deletor * To generate or delete volumes in a 3-map *************************************************************************/ -template -void Map3::deleteVolume(Dart d, bool withBoundary) +template +void Map3::deleteVolume(Dart d, bool withBoundary) { if(withBoundary) { - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(512); visitedFaces.push_back(d); // Start with the face of d - mark.markOrbit(d) ; + mark.template markOrbit(d) ; for(unsigned int i = 0; i < visitedFaces.size(); ++i) { @@ -166,7 +166,7 @@ void Map3::deleteVolume(Dart d, bool withBoundary) if(!mark.isMarked(ee)) // not already marked { visitedFaces.push_back(ee) ; - mark.markOrbit(ee) ; + mark.template markOrbit(ee) ; } e = this->phi1(e) ; } while(e != visitedFaces[i]) ; @@ -180,13 +180,13 @@ void Map3::deleteVolume(Dart d, bool withBoundary) } //else remove the CC and create fixed points - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(512); visitedFaces.push_back(d); // Start with the face of d - mark.markOrbit(d) ; + mark.template markOrbit(d) ; for(unsigned int i = 0; i < visitedFaces.size(); ++i) { @@ -205,7 +205,7 @@ void Map3::deleteVolume(Dart d, bool withBoundary) if(!mark.isMarked(ee)) // not already marked { visitedFaces.push_back(ee) ; - mark.markOrbit(ee) ; + mark.template markOrbit(ee) ; } e = this->phi1(e) ; } while(e != visitedFaces[i]) ; @@ -214,18 +214,18 @@ void Map3::deleteVolume(Dart d, bool withBoundary) ParentMap::deleteCC(d) ; //deleting the volume } -template -void Map3::fillHole(Dart d) +template +void Map3::fillHole(Dart d) { assert(isBoundaryFace(d)) ; Dart dd = d ; - if(!this->isBoundaryMarked3(dd)) + if(!this->template isBoundaryMarked<3>(dd)) dd = phi3(dd) ; this->template boundaryUnmarkOrbit(dd) ; } -template -void Map3::createHole(Dart d) +template +void Map3::createHole(Dart d) { assert(!isBoundaryFace(d)) ; this->template boundaryMarkOrbit(d) ; @@ -235,8 +235,8 @@ void Map3::createHole(Dart d) * Topological operations on 3-maps *************************************************************************/ -template -Dart Map3::splitVertex(std::vector& vd) +template +Dart Map3::splitVertex(std::vector& vd) { //assert(checkPathAroundVertex(vd)) ; @@ -286,8 +286,8 @@ Dart Map3::splitVertex(std::vector& vd) return this->phi_1(this->phi2(this->phi_1(prev))); } -template -Dart Map3::deleteVertex(Dart d) +template +Dart Map3::deleteVertex(Dart d) { //if(isBoundaryVertex(d)) // return NIL ; @@ -302,12 +302,12 @@ Dart Map3::deleteVertex(Dart d) // just one dart per face std::vector fstore; fstore.reserve(128); - DartMarker mf(*this); + DartMarker mf(*this); for(unsigned int i = 0; i < fstoretmp.size(); ++i) { if(!mf.isMarked(fstoretmp[i])) { - mf.markOrbit(fstoretmp[i]); + mf.template markOrbit(fstoretmp[i]); fstore.push_back(fstoretmp[i]); } } @@ -369,8 +369,8 @@ Dart Map3::deleteVertex(Dart d) return res ; } -template -Dart Map3::cutEdge(Dart d) +template +Dart Map3::cutEdge(Dart d) { Dart prev = d; Dart dd = this->alpha2(d); @@ -397,8 +397,8 @@ Dart Map3::cutEdge(Dart d) return nd; } -template -bool Map3::uncutEdge(Dart d) +template +bool Map3::uncutEdge(Dart d) { if(vertexDegree(this->phi1(d)) == 2) { @@ -422,16 +422,16 @@ bool Map3::uncutEdge(Dart d) return false; } -template -bool Map3::deleteEdgePreCond(Dart d) +template +bool Map3::deleteEdgePreCond(Dart d) { unsigned int nb1 = vertexDegree(d); unsigned int nb2 = vertexDegree(this->phi1(d)); return (nb1!=2) && (nb2!=2); } -template -Dart Map3::deleteEdge(Dart d) +template +Dart Map3::deleteEdge(Dart d) { assert(deleteEdgePreCond(d)); @@ -469,8 +469,8 @@ Dart Map3::deleteEdge(Dart d) return res ; } -template -Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes) +template +Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes) { Dart resV = NIL; Dart dit = d; @@ -503,14 +503,14 @@ Dart Map3::collapseEdge(Dart d, bool delDegenerateVolumes) } -template -bool Map3::splitFacePreCond(Dart d, Dart e) +template +bool Map3::splitFacePreCond(Dart d, Dart e) { return (d != e && this->sameOrientedFace(d, e)) ; } -template -void Map3::splitFace(Dart d, Dart e) +template +void Map3::splitFace(Dart d, Dart e) { // assert(d != e && sameOrientedFace(d, e)) ; assert(splitFacePreCond(d,e)); @@ -525,8 +525,8 @@ void Map3::splitFace(Dart d, Dart e) phi3sew(this->phi_1(e), this->phi_1(dd)); } -template -bool Map3::mergeFaces(Dart d) +template +bool Map3::mergeFaces(Dart d) { assert(edgeDegree(d)==2); @@ -540,21 +540,21 @@ bool Map3::mergeFaces(Dart d) // Map2::mergeFaces(d); Dart e = this->phi2(d) ; this->phi2unsew(d) ; - Map1::mergeCycles(d, this->phi1(e)) ; - Map1::splitCycle(e, this->phi1(d)) ; - Map1::deleteCycle(d) ; + Map1::mergeCycles(d, this->phi1(e)) ; + Map1::splitCycle(e, this->phi1(d)) ; + Map1::deleteCycle(d) ; // ParentMap::mergeFaces(dd); e = this->phi2(dd) ; this->phi2unsew(dd) ; - Map1::mergeCycles(dd, this->phi1(e)) ; - Map1::splitCycle(e, this->phi1(dd)) ; - Map1::deleteCycle(dd); + Map1::mergeCycles(dd, this->phi1(e)) ; + Map1::splitCycle(e, this->phi1(dd)) ; + Map1::deleteCycle(dd); return true; } -template -Dart Map3::collapseFace(Dart d, bool delDegenerateVolumes) +template +Dart Map3::collapseFace(Dart d, bool delDegenerateVolumes) { Dart resV = NIL; Dart stop = this->phi_1(d); @@ -575,8 +575,8 @@ Dart Map3::collapseFace(Dart d, bool delDegenerateVolumes) return resV; } -template -bool Map3::collapseDegeneretedVolume(Dart d) +template +bool Map3::collapseDegeneretedVolume(Dart d) { Dart e1 = d; Dart e2 = this->phi2(d); @@ -608,14 +608,14 @@ bool Map3::collapseDegeneretedVolume(Dart d) return true; } -template -bool Map3::sewVolumesPreCond(Dart d, Dart e) +template +bool Map3::sewVolumesPreCond(Dart d, Dart e) { return (this->faceDegree(d) == this->faceDegree(e)); } -template -void Map3::sewVolumes(Dart d, Dart e, bool withBoundary) +template +void Map3::sewVolumes(Dart d, Dart e, bool withBoundary) { assert(sewVolumesPreCond(d,e)); @@ -667,14 +667,14 @@ void Map3::sewVolumes(Dart d, Dart e, bool withBoundary) } while(fitD != d) ; } -template -bool Map3::unsewVolumesPreCond(Dart d) +template +bool Map3::unsewVolumesPreCond(Dart d) { return (!this->isBoundaryFace(d)) ; } -template -void Map3::unsewVolumes(Dart d, bool withBoundary) +template +void Map3::unsewVolumes(Dart d, bool withBoundary) { assert(unsewVolumesPreCond(d)) ; @@ -723,10 +723,10 @@ void Map3::unsewVolumes(Dart d, bool withBoundary) } while(fitB1 != b1) ; } -template -bool Map3::mergeVolumes(Dart d, bool deleteFace) +template +bool Map3::mergeVolumes(Dart d, bool deleteFace) { - if(!Map3::isBoundaryFace(d)) + if(!Map3::isBoundaryFace(d)) { ParentMap::mergeVolumes(d, phi3(d), deleteFace); // merge the two volumes along common face return true ; @@ -734,8 +734,8 @@ bool Map3::mergeVolumes(Dart d, bool deleteFace) return false ; } -template -void Map3::splitVolume(std::vector& vd) +template +void Map3::splitVolume(std::vector& vd) { //assert(checkSimpleOrientedPath(vd)) ; @@ -745,11 +745,11 @@ void Map3::splitVolume(std::vector& vd) ParentMap::splitSurface(vd, true, true); //sew the two connected components - Map3::sewVolumes(this->phi2(e), this->phi2(e2), false); + Map3::sewVolumes(this->phi2(e), this->phi2(e2), false); } -template -void Map3::splitVolumeWithFace(std::vector& vd, Dart d) +template +void Map3::splitVolumeWithFace(std::vector& vd, Dart d) { assert(vd.size() == this->faceDegree(d)); @@ -768,8 +768,8 @@ void Map3::splitVolumeWithFace(std::vector& vd, Dart d) } } -template -Dart Map3::collapseVolume(Dart d, bool delDegenerateVolumes) +template +Dart Map3::collapseVolume(Dart d, bool delDegenerateVolumes) { Dart resV = NIL; std::vector vd; @@ -787,13 +787,13 @@ Dart Map3::collapseVolume(Dart d, bool delDegenerateVolumes) // vd.pop_back(); for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) - resV = Map3::collapseEdge(*it, delDegenerateVolumes); + resV = Map3::collapseEdge(*it, delDegenerateVolumes); return resV; } -template -Dart Map3::faceToEdge(Dart d) +template +Dart Map3::faceToEdge(Dart d) { Dart dc = this->phi2(this->phi1(d)); Dart dc1 = this->phi_1(d); @@ -814,10 +814,10 @@ Dart Map3::faceToEdge(Dart d) * Return or set various topological information *************************************************************************/ -template -bool Map3::sameVertex(Dart d, Dart e) const +template +bool Map3::sameVertex(Dart d, Dart e) const { - DartMarkerStore mv(*this); // Lock a marker + DartMarkerStore mv(*this); // Lock a marker std::vector darts; // Darts that are traversed darts.reserve(256); @@ -848,24 +848,24 @@ bool Map3::sameVertex(Dart d, Dart e) const return false; } -template -unsigned int Map3::vertexDegree(Dart d) const +template +unsigned int Map3::vertexDegree(Dart d) const { unsigned int count = 0; - Traversor3VE > trav3VE(*this, d); + Traversor3VE > trav3VE(*this, d); for(Dart dit = trav3VE.begin() ; dit != trav3VE.end() ; dit = trav3VE.next()) ++count; return count; } -template -int Map3::checkVertexDegree(Dart d, unsigned int vd) const +template +int Map3::checkVertexDegree(Dart d, unsigned int vd) const { unsigned int count = 0; - Traversor3VE > trav3VE(*this, d); + Traversor3VE > trav3VE(*this, d); Dart dit = trav3VE.begin(); for( ; (count <= vd) && (dit != trav3VE.end()) ; dit = trav3VE.next()) ++count; @@ -873,17 +873,17 @@ int Map3::checkVertexDegree(Dart d, unsigned int vd) const return count - vd; } -template -unsigned int Map3::vertexDegreeOnBoundary(Dart d) const +template +unsigned int Map3::vertexDegreeOnBoundary(Dart d) const { assert(Map3::isBoundaryVertex(d)); return ParentMap::vertexDegree(d); } -template -bool Map3::isBoundaryVertex(Dart d) const +template +bool Map3::isBoundaryVertex(Dart d) const { - DartMarkerStore mv(*this); // Lock a marker + DartMarkerStore mv(*this); // Lock a marker std::vector darts; // Darts that are traversed darts.reserve(256); @@ -914,10 +914,10 @@ bool Map3::isBoundaryVertex(Dart d) const return false ; } -template -Dart Map3::findBoundaryFaceOfVertex(Dart d) const +template +Dart Map3::findBoundaryFaceOfVertex(Dart d) const { - DartMarkerStore mv(*this); // Lock a marker + DartMarkerStore mv(*this); // Lock a marker std::vector darts; // Darts that are traversed darts.reserve(256); @@ -948,8 +948,8 @@ Dart Map3::findBoundaryFaceOfVertex(Dart d) const return NIL ; } -template -bool Map3::sameOrientedEdge(Dart d, Dart e) const +template +bool Map3::sameOrientedEdge(Dart d, Dart e) const { Dart it = d; do @@ -961,68 +961,68 @@ bool Map3::sameOrientedEdge(Dart d, Dart e) const return false; } -template -inline bool Map3::sameEdge(Dart d, Dart e) const +template +inline bool Map3::sameEdge(Dart d, Dart e) const { return sameOrientedEdge(d, e) || sameOrientedEdge(this->phi2(d), e) ; } -template -unsigned int Map3::edgeDegree(Dart d) const +template +unsigned int Map3::edgeDegree(Dart d) const { unsigned int deg = 0; Dart it = d; do { - if(!this->isBoundaryMarked3(it)) + if(!this->template isBoundaryMarked<3>(it)) ++deg; it = alpha2(it); } while(it != d); return deg; } -template -bool Map3::isBoundaryEdge(Dart d) const +template +bool Map3::isBoundaryEdge(Dart d) const { Dart it = d; do { - if(this->isBoundaryMarked3(it)) + if(this->template isBoundaryMarked<3>(it)) return true ; it = alpha2(it); } while(it != d); return false; } -template -Dart Map3::findBoundaryFaceOfEdge(Dart d) const +template +Dart Map3::findBoundaryFaceOfEdge(Dart d) const { Dart it = d; do { - if (this->isBoundaryMarked3(it)) + if (this->template isBoundaryMarked<3>(it)) return it ; it = alpha2(it); } while(it != d); return NIL ; } -template -inline bool Map3::sameFace(Dart d, Dart e) const +template +inline bool Map3::sameFace(Dart d, Dart e) const { return ParentMap::sameOrientedFace(d, e) || ParentMap::sameOrientedFace(phi3(d), e) ; } -template -inline bool Map3::isBoundaryFace(Dart d) const +template +inline bool Map3::isBoundaryFace(Dart d) const { - return this->isBoundaryMarked3(d) || this->isBoundaryMarked3(phi3(d)); + return this->template isBoundaryMarked<3>(d) || this->template isBoundaryMarked<3>(phi3(d)); } -template -bool Map3::isBoundaryVolume(Dart d) const +template +bool Map3::isBoundaryVolume(Dart d) const { - Traversor3WF > tra(*this, d); + Traversor3WF > tra(*this, d); for(Dart dit = tra.begin() ; dit != tra.end() ; dit = tra.next()) { if(isBoundaryMarked3(phi3(dit))) @@ -1031,10 +1031,10 @@ bool Map3::isBoundaryVolume(Dart d) const return false; } -template -bool Map3::hasBoundaryEdge(Dart d) const +template +bool Map3::hasBoundaryEdge(Dart d) const { - Traversor3WE > tra(*this, d); + Traversor3WE > tra(*this, d); for(Dart dit = tra.begin() ; dit != tra.end() ; dit = tra.next()) { if(isBoundaryEdge(dit)) @@ -1044,11 +1044,11 @@ bool Map3::hasBoundaryEdge(Dart d) const return false; } -template -bool Map3::check() const +template +bool Map3::check() const { std::cout << "Check: topology begin" << std::endl; - DartMarkerStore m(*this); + DartMarkerStore m(*this); for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d)) { Dart d3 = phi3(d); @@ -1060,7 +1060,7 @@ bool Map3::check() const if(this->phi1(d3) != phi3(this->phi_1(d))) { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - Check: phi3 , faces are not entirely sewn" << std::endl; else std::cout << "Check: phi3 , faces are not entirely sewn" << std::endl; @@ -1071,7 +1071,7 @@ bool Map3::check() const Dart d2 = this->phi2(d); if (this->phi2(d2) != d) // phi2 involution ? { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: phi2 is not an involution" << std::endl; return false; @@ -1080,7 +1080,7 @@ bool Map3::check() const Dart d1 = this->phi1(d); if (this->phi_1(d1) != d) // phi1 a une image correcte ? { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: unconsistent phi_1 link" << std::endl; return false; @@ -1088,7 +1088,7 @@ bool Map3::check() const if (m.isMarked(d1)) // phi1 a un seul antécédent ? { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: dart with two phi1 predecessors" << std::endl; return false; @@ -1097,28 +1097,28 @@ bool Map3::check() const if (d1 == d) { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: (warning) face loop (one edge)" << std::endl; } if (this->phi1(d1) == d) { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: (warning) face with only two edges" << std::endl; } if (this->phi2(d1) == d) { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: (warning) dandling edge (phi2)" << std::endl; } if (phi3(d1) == d) { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: (warning) dandling edge (phi3)" << std::endl; } @@ -1128,7 +1128,7 @@ bool Map3::check() const { if (!m.isMarked(d)) // phi1 a au moins un antécédent ? { - if(this->isBoundaryMarked3(d)) + if(this->template isBoundaryMarked<3>(d)) std::cout << "Boundary case - "; std::cout << "Check: dart with no phi1 predecessor" << std::endl; return false; @@ -1144,10 +1144,10 @@ bool Map3::check() const * Apply functors to all darts of a cell *************************************************************************/ -template -bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const +template +bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mv(*this, thread); // Lock a marker + DartMarkerStore mv(*this, thread); // Lock a marker bool found = false; // Last functor return value std::vector darts; // Darts that are traversed @@ -1178,8 +1178,8 @@ bool Map3::foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thre return found; } -template -bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread) const +template +bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread) const { Dart it = d; do @@ -1191,22 +1191,22 @@ bool Map3::foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread return false; } -template -inline bool Map3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map3::foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_face(d, f, thread) || ParentMap::foreach_dart_of_face(phi3(d), f, thread); } -template -inline bool Map3::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map3::foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_cc(d, f, thread); } -template -bool Map3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const +template +bool Map3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) const { - DartMarkerStore mv(*this,thread); // Lock a marker + DartMarkerStore mv(*this,thread); // Lock a marker bool found = false; // Last functor return value std::vector darts; // Darts that are traversed @@ -1242,20 +1242,20 @@ bool Map3::foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread) return found; } -template -inline bool Map3::foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map3::foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_vertex(d, f, thread); } -template -inline bool Map3::foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map3::foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_edge(d, f, thread); } -template -inline bool Map3::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread) const +template +inline bool Map3::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread) const { return ParentMap::foreach_dart_of_face(d, f, thread); } @@ -1264,24 +1264,24 @@ inline bool Map3::foreach_dart_of_face2(Dart d, FunctorType& f, unsigned in * These functions must be used with care, generally only by import/creation algorithms *************************************************************************/ -template -Dart Map3::newBoundaryCycle(unsigned int nbE) +template +Dart Map3::newBoundaryCycle(unsigned int nbE) { - Dart d = Map1::newCycle(nbE); + Dart d = Map1::newCycle(nbE); this->template boundaryMarkOrbit(d); return d; } -template -unsigned int Map3::closeHole(Dart d, bool forboundary) +template +unsigned int Map3::closeHole(Dart d, bool forboundary) { assert(phi3(d) == d); // Nothing to close - DartMarkerStore m(*this) ; + DartMarkerStore m(*this) ; std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(1024) ; visitedFaces.push_back(d); // Start with the face of d - m.markOrbit(d) ; + m.template markOrbit(d) ; unsigned int count = 0 ; @@ -1308,10 +1308,10 @@ unsigned int Map3::closeHole(Dart d, bool forboundary) if(!m.isMarked(e)) { visitedFaces.push_back(e) ; - m.markOrbit(e) ; + m.template markOrbit(e) ; } } - else if(this->isBoundaryMarked3(e)) + else if(this->template isBoundaryMarked<3>(e)) { found = true ; this->phi2sew(e, bit) ; @@ -1329,8 +1329,8 @@ unsigned int Map3::closeHole(Dart d, bool forboundary) return count ; } -template -unsigned int Map3::closeMap() +template +unsigned int Map3::closeMap() { // Search the map for topological holes (fix points of phi3) unsigned int nb = 0 ; @@ -1349,22 +1349,22 @@ unsigned int Map3::closeMap() * These functions compute the dual mesh *************************************************************************/ -template -void Map3::reverseOrientation() +template +void Map3::reverseOrientation() { } -template -void Map3::computeDual() +template +void Map3::computeDual() { - DartAttribute old_phi1 = this->template getAttribute("phi1") ; - DartAttribute old_phi_1 = this->template getAttribute("phi_1") ; - DartAttribute new_phi1 = this->template addAttribute("new_phi1") ; - DartAttribute new_phi_1 = this->template addAttribute("new_phi_1") ; + DartAttribute old_phi1 = this->template getAttribute("phi1") ; + DartAttribute old_phi_1 = this->template getAttribute("phi_1") ; + DartAttribute new_phi1 = this->template addAttribute("new_phi1") ; + DartAttribute new_phi_1 = this->template addAttribute("new_phi_1") ; - DartAttribute old_phi2 = this->template getAttribute("phi2") ; - DartAttribute new_phi2 = this->template addAttribute("new_phi2") ; + DartAttribute old_phi2 = this->template getAttribute("phi2") ; + DartAttribute new_phi2 = this->template addAttribute("new_phi2") ; for(Dart d = this->begin(); d != this->end(); this->next(d)) { @@ -1528,14 +1528,14 @@ void Map3::computeDual() //std::cout << "Map closed (" << closeMap() <<" boundary faces)" << std::endl; } -template -Dart Map3::explodBorderTopo(Dart d) +template +Dart Map3::explodBorderTopo(Dart d) { std::vector > ve; ve.reserve(1024); //stocke un brin par face du bord - DartMarker me(*this); + DartMarker me(*this); for(Dart dit = this->begin() ; dit != this->end() ; this->next(dit)) { if(this->isBoundaryMarked3(dit) && !me.isMarked(dit)) @@ -1552,7 +1552,7 @@ Dart Map3::explodBorderTopo(Dart d) } //triangule chaque face - DartMarker mf(*this); + DartMarker mf(*this); for(std::vector >::iterator it = ve.begin() ; it != ve.end() ; ++it) { Dart first = (*it).first; @@ -1641,7 +1641,7 @@ Dart Map3::explodBorderTopo(Dart d) { Dart dit1 = this->phi2((*it).first); Dart dit2 = this->phi2((*it).second); - Map3::sewVolumes(dit1, dit2, false); + Map3::sewVolumes(dit1, dit2, false); } this->template setOrbitEmbeddingOnNewCell(this->phi_1(this->phi2(ve.front().first))); @@ -1649,8 +1649,8 @@ Dart Map3::explodBorderTopo(Dart d) return this->phi_1(this->phi2(ve.front().first)); } -template -void Map3::computeDualTest() +template +void Map3::computeDualTest() { // unsigned int count = 0; // CellMarkerNoUnmark cv(*this); @@ -1669,13 +1669,13 @@ void Map3::computeDualTest() // std::cout << "boundary vertices : " << count << std::endl; - DartAttribute old_phi1 = this->template getAttribute("phi1") ; - DartAttribute old_phi_1 = this->template getAttribute("phi_1") ; - DartAttribute new_phi1 = this->template addAttribute("new_phi1") ; - DartAttribute new_phi_1 = this->template addAttribute("new_phi_1") ; + DartAttribute old_phi1 = this->template getAttribute("phi1") ; + DartAttribute old_phi_1 = this->template getAttribute("phi_1") ; + DartAttribute new_phi1 = this->template addAttribute("new_phi1") ; + DartAttribute new_phi_1 = this->template addAttribute("new_phi_1") ; - DartAttribute old_phi2 = this->template getAttribute("phi2") ; - DartAttribute new_phi2 = this->template addAttribute("new_phi2") ; + DartAttribute old_phi2 = this->template getAttribute("phi2") ; + DartAttribute new_phi2 = this->template addAttribute("new_phi2") ; for(Dart d = this->begin(); d != this->end(); this->next(d)) { @@ -1701,7 +1701,7 @@ void Map3::computeDualTest() for(Dart d = this->begin(); d != this->end(); this->next(d)) { if(this->isBoundaryMarked3(d)) - Map3::deleteVolume(d, false); + Map3::deleteVolume(d, false); } closeMap(); diff --git a/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp b/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp index 1deeb596414142103b68b9a2940a07560b39f235..38a05a24060a3785d363d84013d995ba28091128 100644 --- a/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp +++ b/src/Algo/ImplicitHierarchicalMesh/ihm3.cpp @@ -274,7 +274,7 @@ void ImplicitHierarchicalMap3::deleteVertexSubdividedFace(Dart d) void ImplicitHierarchicalMap3::initEdgeId() { - DartMarkerStore edgeMark(*this) ; + DartMarkerStore edgeMark(*this) ; for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d)) { if(!edgeMark.isMarked(d)) @@ -298,7 +298,7 @@ void ImplicitHierarchicalMap3::initEdgeId() void ImplicitHierarchicalMap3::initFaceId() { - DartMarkerStore faceMark(*this) ; + DartMarkerStore faceMark(*this) ; for(Dart d = Map3::begin(); d != Map3::end(); Map3::next(d)) { if(!faceMark.isMarked(d)) @@ -378,7 +378,7 @@ unsigned int ImplicitHierarchicalMap3::volumeLevel(Dart d) //First : the level of a volume is the //minimum of the levels of its faces - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(512); diff --git a/src/Algo/Render/topo3PrimalRender.cpp b/src/Algo/Render/topo3PrimalRender.cpp deleted file mode 100644 index 6397f96f78a4e62229d8eb3ecbf84f94095fa135..0000000000000000000000000000000000000000 --- a/src/Algo/Render/topo3PrimalRender.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#include "Algo/Render/GL2/topo3PrimalRender.h" -#include "Topology/generic/dart.h" -#include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderColorPerVertex.h" - -#include - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Render -{ - -namespace GL2 -{ - -Topo3PrimalRender::Topo3PrimalRender(): - m_nbDarts(0), - m_nbRel2(0), - m_topo_dart_width(2.0f), - m_topo_relation_width(3.0f), - m_color_save(NULL), - m_dartsColor(1.0f,1.0f,1.0f), - m_boundaryDartsColor(0.5f,0.5f,0.5f), - m_bufferDartPosition(NULL) -{ - m_vbo0 = new Utils::VBO(); - m_vbo1 = new Utils::VBO(); - m_vbo2 = new Utils::VBO(); - - m_vbo0->setDataSize(3); - m_vbo1->setDataSize(3); - m_vbo2->setDataSize(3); - - - m_shader1 = new Utils::ShaderSimpleColor(); - m_shader2 = new Utils::ShaderColorPerVertex(); - - // binding VBO - VA - m_vaId = m_shader1->setAttributePosition(m_vbo1); - - m_shader2->setAttributePosition(m_vbo0); - m_shader2->setAttributeColor(m_vbo2); - - // registering for auto matrices update - Utils::GLSLShader::registerShader(NULL, m_shader1); - Utils::GLSLShader::registerShader(NULL, m_shader2); -} - -Topo3PrimalRender::~Topo3PrimalRender() -{ - Utils::GLSLShader::unregisterShader(NULL, m_shader2); - Utils::GLSLShader::unregisterShader(NULL, m_shader1); - - delete m_shader2; - delete m_shader1; - delete m_vbo2; - delete m_vbo1; - delete m_vbo0; - - if (m_attIndex.map() != NULL) - static_cast(m_attIndex.map())->removeAttribute(m_attIndex); - - if (m_color_save!=NULL) - { - delete[] m_color_save; - } - - if (m_bufferDartPosition!=NULL) - delete[] m_bufferDartPosition; -} - -void Topo3PrimalRender::setDartWidth(float dw) -{ - m_topo_dart_width = dw; -} - -void Topo3PrimalRender::setRelationWidth(float pw) -{ - m_topo_relation_width = pw; -} - -void Topo3PrimalRender::setDartColor(Dart d, float r, float g, float b) -{ - float RGB[6]; - RGB[0]=r; RGB[1]=g; RGB[2]=b; - RGB[3]=r; RGB[4]=g; RGB[5]=b; - m_vbo2->bind(); - glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); -} - -void Topo3PrimalRender::setAllDartsColor(float r, float g, float b) -{ - m_vbo2->bind(); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - for (unsigned int i=0; i < 2*m_nbDarts; ++i) - { - *colorDartBuf++ = r; - *colorDartBuf++ = g; - *colorDartBuf++ = b; - } - glUnmapBufferARB(GL_ARRAY_BUFFER); -} - -void Topo3PrimalRender::setInitialDartsColor(float r, float g, float b) -{ - m_dartsColor = Geom::Vec3f(r,g,b); -} - -void Topo3PrimalRender::setInitialBoundaryDartsColor(float r, float g, float b) -{ - m_boundaryDartsColor = Geom::Vec3f(r,g,b); -} - - -void Topo3PrimalRender::drawDarts() -{ - if (m_nbDarts==0) - return; - - m_shader2->enableVertexAttribs(); - - glLineWidth(m_topo_dart_width); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - // change the stride to take 1/2 vertices - m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); - - glPointSize(2.0f*m_topo_dart_width); - glDrawArrays(GL_POINTS, 0, m_nbDarts); - - m_shader2->disableVertexAttribs(); - - -} - - -void Topo3PrimalRender::drawRelation2() -{ - if (m_nbRel2==0) - return; - - m_shader1->changeVA_VBO(m_vaId, m_vbo1); - m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glLineWidth(m_topo_relation_width); - glDrawArrays(GL_LINES, 0, m_nbRel2*2); - - m_shader1->disableVertexAttribs(); -} - - - -void Topo3PrimalRender::drawTopo() -{ - drawDarts(); - drawRelation2(); -} - - -void Topo3PrimalRender::overdrawDart(Dart d, float width, float r, float g, float b) -{ - unsigned int indexDart = m_attIndex[d]; - - m_shader1->changeVA_VBO(m_vaId, m_vbo0); - m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); - m_shader1->enableVertexAttribs(); - - glLineWidth(width); - glDrawArrays(GL_LINES, indexDart, 2); - - glPointSize(2.0f*width); - glDrawArrays(GL_POINTS, indexDart, 1); - - m_shader2->disableVertexAttribs(); - - -} - - -void Topo3PrimalRender::pushColors() -{ - m_color_save = new float[6*m_nbDarts]; - m_vbo2->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); -} - - -void Topo3PrimalRender::popColors() -{ - m_vbo2->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); - - delete[] m_color_save; - m_color_save=0; -} - - -Dart Topo3PrimalRender::colToDart(float* color) -{ - unsigned int r = (unsigned int)(color[0]*255.0f); - unsigned int g = (unsigned int)(color[1]*255.0f); - unsigned int b = (unsigned int)(color[2]*255.0f); - - unsigned int id = r + 255*g +255*255*b; - - if (id == 0) - return NIL; - return Dart(id-1); -} - - -void Topo3PrimalRender::dartToCol(Dart d, float& r, float& g, float& b) -{ - // here use dart.index beacause it is what we want (and not map.dartIndex(d) !!) - unsigned int lab = d.index + 1; // add one to avoid picking the black of screen - - r = float(lab%255) / 255.0f; lab = lab/255; - g = float(lab%255) / 255.0f; lab = lab/255; - b = float(lab%255) / 255.0f; lab = lab/255; - if (lab!=0) - CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; -} - - - - -Dart Topo3PrimalRender::pickColor(unsigned int x, unsigned int y) -{ - //more easy picking for - unsigned int dw = m_topo_dart_width; - m_topo_dart_width+=2; - - // save clear color and set to zero - float cc[4]; - glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); - - glClearColor(0.0f,0.0f,0.0f,0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glDisable(GL_LIGHTING); - // draw in back buffer (not shown on screen) - - drawDarts(); - - // restore dart with - m_topo_dart_width = dw; - - // read the pixel under the mouse in back buffer - glReadBuffer(GL_BACK); - float color[3]; - glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); - - glClearColor(cc[0], cc[1], cc[2], cc[3]); - - - std::cout << color[0] << ", "<(m_vbo1->lockPtr()); - svg2->setWidth(m_topo_relation_width); - svg2->beginLines(); - for (unsigned int i=0; iaddLine(P, Q, Geom::Vec3f(0.8f,0.0f,0.0f)); - } - svg2->endLines(); - m_vbo1->releasePtr(); - svg.addGroup(svg2); - - const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo2->lockPtr()); - ptr= reinterpret_cast(m_vbo0->lockPtr()); - - Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); - svg4->setWidth(m_topo_dart_width); - - svg4->beginLines(); - for (unsigned int i=0; i2.9f) - col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg4->addLine(ptr[2*i], ptr[2*i+1], col); - } - svg4->endLines(); - - svg.addGroup(svg4); - - Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); - svg5->setWidth(m_topo_dart_width); - svg5->beginPoints(); - for (unsigned int i=0; i2.9f) - col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg5->addPoint(ptr[2*i], col); - } - svg5->endPoints(); - svg.addGroup(svg5); - - m_vbo0->releasePtr(); - m_vbo2->releasePtr(); - -} - - -}//end namespace GL2 - -}//end namespace Render - -}//end namespace Algo - -}//end namespace CGoGN diff --git a/src/Algo/Render/topo3Render.cpp b/src/Algo/Render/topo3Render.cpp deleted file mode 100644 index 275f0cbb0b752946d61c77f69b0c592abe62f254..0000000000000000000000000000000000000000 --- a/src/Algo/Render/topo3Render.cpp +++ /dev/null @@ -1,476 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#include "Algo/Render/GL2/topo3Render.h" -#include "Topology/generic/dart.h" -#include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderColorPerVertex.h" - -#include - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Render -{ - -namespace GL2 -{ - -Topo3Render::Topo3Render(): - m_nbDarts(0), - m_nbRel1(0), - m_nbRel2(0), - m_nbRel3(0), - m_topo_dart_width(2.0f), - m_topo_relation_width(3.0f), - m_color_save(NULL), - m_dartsColor(1.0f,1.0f,1.0f), - m_bufferDartPosition(NULL) -{ - m_vbo0 = new Utils::VBO(); - m_vbo1 = new Utils::VBO(); - m_vbo2 = new Utils::VBO(); - m_vbo3 = new Utils::VBO(); - m_vbo4 = new Utils::VBO(); - - m_vbo0->setDataSize(3); - m_vbo1->setDataSize(3); - m_vbo2->setDataSize(3); - m_vbo3->setDataSize(3); - m_vbo4->setDataSize(3); - - m_shader1 = new Utils::ShaderSimpleColor(); - m_shader2 = new Utils::ShaderColorPerVertex(); - - // binding VBO - VA - m_vaId = m_shader1->setAttributePosition(m_vbo1); - - m_shader2->setAttributePosition(m_vbo0); - m_shader2->setAttributeColor(m_vbo4); - - // registering for auto matrices update - Utils::GLSLShader::registerShader(NULL, m_shader1); - Utils::GLSLShader::registerShader(NULL, m_shader2); -} - -Topo3Render::~Topo3Render() -{ - Utils::GLSLShader::unregisterShader(NULL, m_shader2); - Utils::GLSLShader::unregisterShader(NULL, m_shader1); - - delete m_shader2; - delete m_shader1; - delete m_vbo4; - delete m_vbo3; - delete m_vbo2; - delete m_vbo1; - delete m_vbo0; - - if (m_attIndex.map() != NULL) - static_cast(m_attIndex.map())->removeAttribute(m_attIndex); - - if (m_color_save!=NULL) - { - delete[] m_color_save; - } - - if (m_bufferDartPosition!=NULL) - delete[] m_bufferDartPosition; -} - -void Topo3Render::setDartWidth(float dw) -{ - m_topo_dart_width = dw; -} - -void Topo3Render::setRelationWidth(float pw) -{ - m_topo_relation_width = pw; -} - -void Topo3Render::setDartColor(Dart d, float r, float g, float b) -{ - float RGB[6]; - RGB[0]=r; RGB[1]=g; RGB[2]=b; - RGB[3]=r; RGB[4]=g; RGB[5]=b; - m_vbo4->bind(); - glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); -} - -void Topo3Render::setAllDartsColor(float r, float g, float b) -{ - m_vbo4->bind(); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - for (unsigned int i=0; i < 2*m_nbDarts; ++i) - { - *colorDartBuf++ = r; - *colorDartBuf++ = g; - *colorDartBuf++ = b; - } - glUnmapBufferARB(GL_ARRAY_BUFFER); - -} - -void Topo3Render::setInitialDartsColor(float r, float g, float b) -{ - m_dartsColor = Geom::Vec3f(r,g,b); -} - -void Topo3Render::drawDarts() -{ - if (m_nbDarts==0) - return; - - m_shader2->enableVertexAttribs(); - - glLineWidth(m_topo_dart_width); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - // change the stride to take 1/2 vertices - m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); - - glPointSize(2.0f*m_topo_dart_width); - glDrawArrays(GL_POINTS, 0, m_nbDarts); - - m_shader2->disableVertexAttribs(); - -// -//// glColor3f(1.0f,1.0f,1.0f); -// glLineWidth(m_topo_dart_width); -// glPointSize(2.0f*m_topo_dart_width); -// -// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); -// glColorPointer(3, GL_FLOAT, 0, 0); -// glEnableClientState(GL_COLOR_ARRAY); -// -// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[0]); -// glVertexPointer(3, GL_FLOAT, 0, 0); -// glEnableClientState(GL_VERTEX_ARRAY); -// glDrawArrays(GL_LINES, 0, m_nbDarts*2); -// -// glVertexPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); -// -// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[4]); -// glColorPointer(3, GL_FLOAT, 6*sizeof(GL_FLOAT), 0); -// glDrawArrays(GL_POINTS, 0, m_nbDarts) -// ; -// glDisableClientState(GL_COLOR_ARRAY); -// glDisableClientState(GL_VERTEX_ARRAY); - -} - - - -void Topo3Render::drawRelation1() -{ - if (m_nbDarts==0) - return; - - glLineWidth(m_topo_relation_width); - - m_shader1->changeVA_VBO(m_vaId, m_vbo1); - m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_LINES, 0, m_nbRel1*2); - - m_shader1->disableVertexAttribs(); - -// glLineWidth(m_topo_relation_width); -// glColor3f(0.0f,1.0f,1.0f); -// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[1]); -// glVertexPointer(3, GL_FLOAT, 0, 0); -// -// glEnableClientState(GL_VERTEX_ARRAY); -// glDrawArrays(GL_LINES, 0, m_nbDarts*2); -// glDisableClientState(GL_VERTEX_ARRAY); -} - - -void Topo3Render::drawRelation2() -{ - if (m_nbRel2==0) - return; - - m_shader1->changeVA_VBO(m_vaId, m_vbo2); - m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_QUADS, 0, m_nbRel2*4); - - m_shader1->disableVertexAttribs(); - -// glLineWidth(m_topo_relation_width); -// glColor3f(1.0f,0.0f,0.0f); -// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[2]); -// glVertexPointer(3, GL_FLOAT, 0, 0); -// -// glEnableClientState(GL_VERTEX_ARRAY); -// glDrawArrays(GL_QUADS, 0, m_nbRel2*4); -// glDisableClientState(GL_VERTEX_ARRAY); -} - - -void Topo3Render::drawRelation3(Geom::Vec4f c) -{ - if (m_nbRel3==0) - return; - - m_shader1->changeVA_VBO(m_vaId, m_vbo3); - m_shader1->setColor(c); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_QUADS, 0, m_nbRel3*4); - - m_shader1->disableVertexAttribs(); - -// glLineWidth(m_topo_relation_width); -// glColor3f(1.0f,1.0f,0.0f); -// glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[3]); -// glVertexPointer(3, GL_FLOAT, 0, 0); -// -// glEnableClientState(GL_VERTEX_ARRAY); -// glDrawArrays(GL_QUADS, 0, m_nbRel3*4); -// glDisableClientState(GL_VERTEX_ARRAY); -} - - -void Topo3Render::drawTopo() -{ - drawDarts(); - drawRelation1(); - drawRelation2(); - drawRelation3(Geom::Vec4f(1.0f,1.0f,0.0f,0.0f)); -} - - -void Topo3Render::overdrawDart(Dart d, float width, float r, float g, float b) -{ - unsigned int indexDart = m_attIndex[d]; - - m_shader1->changeVA_VBO(m_vaId, m_vbo0); - m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); - m_shader1->enableVertexAttribs(); - - glLineWidth(width); - glDrawArrays(GL_LINES, indexDart, 2); - - glPointSize(2.0f*width); - glDrawArrays(GL_POINTS, indexDart, 1); - - m_shader2->disableVertexAttribs(); - - -} - - -void Topo3Render::pushColors() -{ - m_color_save = new float[6*m_nbDarts]; - m_vbo4->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); -} - - -void Topo3Render::popColors() -{ - m_vbo4->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); - - delete[] m_color_save; - m_color_save=0; -} - - -Dart Topo3Render::colToDart(float* color) -{ - unsigned int r = (unsigned int)(color[0]*255.0f); - unsigned int g = (unsigned int)(color[1]*255.0f); - unsigned int b = (unsigned int)(color[2]*255.0f); - - unsigned int id = r + 255*g +255*255*b; - - if (id == 0) - return NIL; - return Dart(id-1); -} - - -void Topo3Render::dartToCol(Dart d, float& r, float& g, float& b) -{ - // here use dart.index beacause it is what we want (and not map.dartIndex(d) !!) - unsigned int lab = d.index + 1; // add one to avoid picking the black of screen - - r = float(lab%255) / 255.0f; lab = lab/255; - g = float(lab%255) / 255.0f; lab = lab/255; - b = float(lab%255) / 255.0f; lab = lab/255; - if (lab!=0) - CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; -} - - - - -Dart Topo3Render::pickColor(unsigned int x, unsigned int y) -{ - //more easy picking for - unsigned int dw = m_topo_dart_width; - m_topo_dart_width+=2; - - // save clear color and set to zero - float cc[4]; - glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); - - glClearColor(0.0f,0.0f,0.0f,0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glDisable(GL_LIGHTING); - // draw in back buffer (not shown on screen) - - drawDarts(); - - // restore dart with - m_topo_dart_width = dw; - - // read the pixel under the mouse in back buffer - glReadBuffer(GL_BACK); - float color[3]; - glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); - - glClearColor(cc[0], cc[1], cc[2], cc[3]); - - - std::cout << color[0] << ", "<(m_vbo3->lockPtr()); - svg1->setWidth(m_topo_relation_width); - svg1->beginLines(); - for (unsigned int i=0; iaddLine(P, Q,Geom::Vec3f(0.8f,0.8f,0.0f)); - } - svg1->endLines(); - m_vbo3->releasePtr(); - - svg.addGroup(svg1); - - // PHI2 / beta2 - Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); - ptr = reinterpret_cast(m_vbo2->lockPtr()); - svg2->setWidth(m_topo_relation_width); - svg2->beginLines(); - for (unsigned int i=0; iaddLine(P, Q,Geom::Vec3f(0.8f,0.0f,0.0f)); - } - svg2->endLines(); - m_vbo2->releasePtr(); - - svg.addGroup(svg2); - - //PHI1 /beta1 - Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); - ptr = reinterpret_cast(m_vbo1->lockPtr()); - svg3->setWidth(m_topo_relation_width); - svg3->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); - svg3->endLines(); - m_vbo1->releasePtr(); - - svg.addGroup(svg3); - - const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo4->lockPtr()); - ptr= reinterpret_cast(m_vbo0->lockPtr()); - - Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); - svg4->setWidth(m_topo_dart_width); - - svg4->beginLines(); - for (unsigned int i=0; i2.9f) - col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg4->addLine(ptr[2*i], ptr[2*i+1], col); - } - svg4->endLines(); - - svg.addGroup(svg4); - - Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); - svg5->setWidth(m_topo_dart_width); - svg5->beginPoints(); - for (unsigned int i=0; i2.9f) - col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg5->addPoint(ptr[2*i], col); - } - svg5->endPoints(); - - svg.addGroup(svg5); - - m_vbo0->releasePtr(); - m_vbo4->releasePtr(); -} - - -}//end namespace GL2 - -}//end namespace Render - -}//end namespace Algo - -}//end namespace CGoGN diff --git a/src/Algo/Render/topoPrimalRender.cpp b/src/Algo/Render/topoPrimalRender.cpp deleted file mode 100644 index faa6382fa2a4e0b8b5542fcdea0f7fffcfc39501..0000000000000000000000000000000000000000 --- a/src/Algo/Render/topoPrimalRender.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#include "Algo/Render/GL2/topoPrimalRender.h" -#include "Topology/generic/dart.h" -#include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderColorPerVertex.h" - -#include - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Render -{ - -namespace GL2 -{ - -TopoPrimalRender::TopoPrimalRender(): - m_nbDarts(0), - m_nbRel1(0), - m_topo_dart_width(2.0f), - m_topo_relation_width(3.0f), - m_color_save(NULL), - m_dartsColor(1.0f,1.0f,1.0f), - m_boundaryDartsColor(0.5f,0.5f,0.5f), - m_bufferDartPosition(NULL) -{ - m_vbo0 = new Utils::VBO(); - m_vbo1 = new Utils::VBO(); - m_vbo2 = new Utils::VBO(); - - m_vbo0->setDataSize(3); - m_vbo1->setDataSize(3); - m_vbo2->setDataSize(3); - - - m_shader1 = new Utils::ShaderSimpleColor(); - m_shader2 = new Utils::ShaderColorPerVertex(); - - // binding VBO - VA - m_vaId = m_shader1->setAttributePosition(m_vbo1); - - m_shader2->setAttributePosition(m_vbo0); - m_shader2->setAttributeColor(m_vbo2); - - // registering for auto matrices update - Utils::GLSLShader::registerShader(NULL, m_shader1); - Utils::GLSLShader::registerShader(NULL, m_shader2); -} - -TopoPrimalRender::~TopoPrimalRender() -{ - Utils::GLSLShader::unregisterShader(NULL, m_shader2); - Utils::GLSLShader::unregisterShader(NULL, m_shader1); - - delete m_shader2; - delete m_shader1; - delete m_vbo2; - delete m_vbo1; - delete m_vbo0; - - if (m_attIndex.map() != NULL) - static_cast(m_attIndex.map())->removeAttribute(m_attIndex); - - if (m_color_save!=NULL) - { - delete[] m_color_save; - } - - if (m_bufferDartPosition!=NULL) - delete[] m_bufferDartPosition; -} - -void TopoPrimalRender::setDartWidth(float dw) -{ - m_topo_dart_width = dw; -} - -void TopoPrimalRender::setRelationWidth(float pw) -{ - m_topo_relation_width = pw; -} - -void TopoPrimalRender::setDartColor(Dart d, float r, float g, float b) -{ - float RGB[6]; - RGB[0]=r; RGB[1]=g; RGB[2]=b; - RGB[3]=r; RGB[4]=g; RGB[5]=b; - m_vbo2->bind(); - glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); -} - -void TopoPrimalRender::setAllDartsColor(float r, float g, float b) -{ - m_vbo2->bind(); - GLvoid* ColorDartsBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - for (unsigned int i=0; i < 2*m_nbDarts; ++i) - { - *colorDartBuf++ = r; - *colorDartBuf++ = g; - *colorDartBuf++ = b; - } - glUnmapBufferARB(GL_ARRAY_BUFFER); -} - -void TopoPrimalRender::setInitialDartsColor(float r, float g, float b) -{ - m_dartsColor = Geom::Vec3f(r,g,b); -} - -void TopoPrimalRender::setInitialBoundaryDartsColor(float r, float g, float b) -{ - m_boundaryDartsColor = Geom::Vec3f(r,g,b); -} - - -void TopoPrimalRender::drawDarts() -{ - if (m_nbDarts==0) - return; - - m_shader2->enableVertexAttribs(); - - glLineWidth(m_topo_dart_width); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - // change the stride to take 1/2 vertices - m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); - - glPointSize(2.0f*m_topo_dart_width); - glDrawArrays(GL_POINTS, 0, m_nbDarts); - - m_shader2->disableVertexAttribs(); - - -} - - -void TopoPrimalRender::drawRelation1() -{ - if (m_nbRel1==0) - return; - - m_shader1->changeVA_VBO(m_vaId, m_vbo1); - m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glLineWidth(m_topo_relation_width); - glDrawArrays(GL_LINES, 0, m_nbRel1*2); - - m_shader1->disableVertexAttribs(); -} - - - -void TopoPrimalRender::drawTopo() -{ - drawDarts(); - drawRelation1(); -} - - -void TopoPrimalRender::overdrawDart(Dart d, float width, float r, float g, float b) -{ - unsigned int indexDart = m_attIndex[d]; - - m_shader1->changeVA_VBO(m_vaId, m_vbo0); - m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); - m_shader1->enableVertexAttribs(); - - glLineWidth(width); - glDrawArrays(GL_LINES, indexDart, 2); - - glPointSize(2.0f*width); - glDrawArrays(GL_POINTS, indexDart, 1); - - m_shader2->disableVertexAttribs(); - - -} - - -void TopoPrimalRender::pushColors() -{ - m_color_save = new float[6*m_nbDarts]; - m_vbo2->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); -} - - -void TopoPrimalRender::popColors() -{ - m_vbo2->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); - - delete[] m_color_save; - m_color_save=0; -} - - -Dart TopoPrimalRender::colToDart(float* color) -{ - unsigned int r = (unsigned int)(color[0]*255.0f); - unsigned int g = (unsigned int)(color[1]*255.0f); - unsigned int b = (unsigned int)(color[2]*255.0f); - - unsigned int id = r + 255*g +255*255*b; - - if (id == 0) - return NIL; - return Dart(id-1); -} - - -void TopoPrimalRender::dartToCol(Dart d, float& r, float& g, float& b) -{ - // here use dart.index beacause it is what we want (and not map.dartIndex(d) !!) - unsigned int lab = d.index + 1; // add one to avoid picking the black of screen - - r = float(lab%255) / 255.0f; lab = lab/255; - g = float(lab%255) / 255.0f; lab = lab/255; - b = float(lab%255) / 255.0f; lab = lab/255; - if (lab!=0) - CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; -} - - - - -Dart TopoPrimalRender::pickColor(unsigned int x, unsigned int y) -{ - //more easy picking for - unsigned int dw = m_topo_dart_width; - m_topo_dart_width+=2; - - // save clear color and set to zero - float cc[4]; - glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); - - glClearColor(0.0f,0.0f,0.0f,0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glDisable(GL_LIGHTING); - // draw in back buffer (not shown on screen) - - drawDarts(); - - // restore dart with - m_topo_dart_width = dw; - - // read the pixel under the mouse in back buffer - glReadBuffer(GL_BACK); - float color[3]; - glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); - - glClearColor(cc[0], cc[1], cc[2], cc[3]); - - - std::cout << color[0] << ", "<(m_vbo1->lockPtr()); - svg2->setWidth(m_topo_relation_width); - svg2->beginLines(); - for (unsigned int i=0; iaddLine(P, Q, Geom::Vec3f(0.8f,0.0f,0.0f)); - } - svg2->endLines(); - m_vbo1->releasePtr(); - svg.addGroup(svg2); - - const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo2->lockPtr()); - ptr= reinterpret_cast(m_vbo0->lockPtr()); - - Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); - svg4->setWidth(m_topo_dart_width); - - svg4->beginLines(); - for (unsigned int i=0; i2.9f) - col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg4->addLine(ptr[2*i], ptr[2*i+1], col); - } - svg4->endLines(); - - svg.addGroup(svg4); - - Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); - svg5->setWidth(m_topo_dart_width); - svg5->beginPoints(); - for (unsigned int i=0; i2.9f) - col = Geom::Vec3f(1.0f,1.0f,1.0f) - col; - svg5->addPoint(ptr[2*i], col); - } - svg5->endPoints(); - svg.addGroup(svg5); - - m_vbo0->releasePtr(); - m_vbo2->releasePtr(); - -} - - -}//end namespace GL2 - -}//end namespace Render - -}//end namespace Algo - -}//end namespace CGoGN diff --git a/src/Algo/Render/topoRender.cpp b/src/Algo/Render/topoRender.cpp deleted file mode 100644 index c27d706e16e1cd4e935f5bac284b8a8dd172cf23..0000000000000000000000000000000000000000 --- a/src/Algo/Render/topoRender.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/******************************************************************************* -* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * -* version 0.1 * -* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * -* * -* This library is free software; you can redistribute it and/or modify it * -* under the terms of the GNU Lesser General Public License as published by the * -* Free Software Foundation; either version 2.1 of the License, or (at your * -* option) any later version. * -* * -* This library is distributed in the hope that it will be useful, but WITHOUT * -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * -* for more details. * -* * -* You should have received a copy of the GNU Lesser General Public License * -* along with this library; if not, write to the Free Software Foundation, * -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * -* * -* Web site: http://cgogn.unistra.fr/ * -* Contact information: cgogn@unistra.fr * -* * -*******************************************************************************/ - -#include "Algo/Render/GL2/topoRender.h" -#include "Utils/Shaders/shaderSimpleColor.h" -#include "Utils/Shaders/shaderColorPerVertex.h" - -namespace CGoGN -{ - -namespace Algo -{ - -namespace Render -{ - -namespace GL2 -{ - -TopoRender::TopoRender(float bs): - m_nbDarts(0), - m_nbRel2(0), - m_topo_dart_width(2.0f), - m_topo_relation_width(3.0f), - m_normalShift(0.0f), - m_boundShift(bs), - m_dartsColor(1.0f,1.0f,1.0f), - m_dartsBoundaryColor(0.7f,1.0f,0.7f), - m_bufferDartPosition(NULL) -{ - m_vbo0 = new Utils::VBO(); - m_vbo1 = new Utils::VBO(); - m_vbo2 = new Utils::VBO(); - m_vbo3 = new Utils::VBO(); - - m_vbo0->setDataSize(3); - m_vbo1->setDataSize(3); - m_vbo2->setDataSize(3); - m_vbo3->setDataSize(3); - - m_shader1 = new Utils::ShaderSimpleColor(); - m_shader2 = new Utils::ShaderColorPerVertex(); - - // binding VBO - VA - m_vaId = m_shader1->setAttributePosition(m_vbo1); - - m_shader2->setAttributePosition(m_vbo0); - m_shader2->setAttributeColor(m_vbo3); - - // registering for auto matrices update - Utils::GLSLShader::registerShader(NULL, m_shader1); - Utils::GLSLShader::registerShader(NULL, m_shader2); -} - -TopoRender::~TopoRender() -{ - Utils::GLSLShader::unregisterShader(NULL, m_shader2); - Utils::GLSLShader::unregisterShader(NULL, m_shader1); - - delete m_shader2; - delete m_shader1; - delete m_vbo3; - delete m_vbo2; - delete m_vbo1; - delete m_vbo0; - - if (m_attIndex.map() != NULL) - static_cast(m_attIndex.map())->removeAttribute(m_attIndex); - - if (m_bufferDartPosition!=NULL) - delete[] m_bufferDartPosition; -} - -void TopoRender::setDartWidth(float dw) -{ - m_topo_dart_width = dw; -} - -void TopoRender::setRelationWidth(float pw) -{ - m_topo_relation_width = pw; -} - -void TopoRender::setDartColor(Dart d, float r, float g, float b) -{ - float RGB[6]; - RGB[0]=r; RGB[1]=g; RGB[2]=b; - RGB[3]=r; RGB[4]=g; RGB[5]=b; - m_vbo3->bind(); - glBufferSubData(GL_ARRAY_BUFFER, m_attIndex[d]*3*sizeof(float), 6*sizeof(float),RGB); -} - -void TopoRender::setAllDartsColor(float r, float g, float b) -{ - m_vbo3->bind(); - GLvoid* ColorDartsBuffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); - float* colorDartBuf = reinterpret_cast(ColorDartsBuffer); - for (unsigned int i=0; i < 2*m_nbDarts; ++i) - { - *colorDartBuf++ = r; - *colorDartBuf++ = g; - *colorDartBuf++ = b; - } - - m_vbo3->bind(); - glUnmapBuffer(GL_ARRAY_BUFFER); -} - -void TopoRender::setInitialDartsColor(float r, float g, float b) -{ - m_dartsColor = Geom::Vec3f(r,g,b); -} - - -void TopoRender::setInitialBoundaryDartsColor(float r, float g, float b) -{ - m_dartsBoundaryColor = Geom::Vec3f(r,g,b); -} - -void TopoRender::drawDarts() -{ - if (m_nbDarts==0) - return; - - m_shader2->enableVertexAttribs(); - - glLineWidth(m_topo_dart_width); - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - // change the stride to take 1/2 vertices - m_shader2->enableVertexAttribs(6*sizeof(GL_FLOAT)); - - glPointSize(2.0f*m_topo_dart_width); - glDrawArrays(GL_POINTS, 0, m_nbDarts); - - m_shader2->disableVertexAttribs(); -} - -void TopoRender::drawRelation1() -{ - if (m_nbDarts==0) - return; - - glLineWidth(m_topo_relation_width); - - m_shader1->changeVA_VBO(m_vaId, m_vbo1); - m_shader1->setColor(Geom::Vec4f(0.0f,1.0f,1.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_LINES, 0, m_nbDarts*2); - - m_shader1->disableVertexAttribs(); -} - -void TopoRender::drawRelation2() -{ - if (m_nbRel2==0) - return; - - glLineWidth(m_topo_relation_width); - - m_shader1->changeVA_VBO(m_vaId, m_vbo2); - m_shader1->setColor(Geom::Vec4f(1.0f,0.0f,0.0f,0.0f)); - m_shader1->enableVertexAttribs(); - - glDrawArrays(GL_LINES, 0, m_nbRel2*2); - - m_shader1->disableVertexAttribs(); -} - -void TopoRender::drawTopo() -{ - drawDarts(); - drawRelation1(); - drawRelation2(); -} - -void TopoRender::overdrawDart(Dart d, float width, float r, float g, float b) -{ - unsigned int indexDart = m_attIndex[d]; - - m_shader1->changeVA_VBO(m_vaId, m_vbo0); - m_shader1->setColor(Geom::Vec4f(r,g,b,0.0f)); - m_shader1->enableVertexAttribs(); - - glLineWidth(width); - glDrawArrays(GL_LINES, indexDart, 2); - - glPointSize(2.0f*width); - glDrawArrays(GL_POINTS, indexDart, 1); - - m_shader2->disableVertexAttribs(); -} - -Dart TopoRender::colToDart(float* color) -{ - unsigned int r = (unsigned int)(color[0]*255.0f); - unsigned int g = (unsigned int)(color[1]*255.0f); - unsigned int b = (unsigned int)(color[2]*255.0f); - - unsigned int id = r + 255*g +255*255*b; - - if (id == 0) - return NIL; - return Dart(id-1); - -} - -void TopoRender::dartToCol(Dart d, float& r, float& g, float& b) -{ - // here use d.index beacause it is what we want (and not map.dartIndex(d) !!) - unsigned int lab = d.index + 1; // add one to avoid picking the black of screen - - r = float(lab%255) / 255.0f; lab = lab/255; - g = float(lab%255) / 255.0f; lab = lab/255; - b = float(lab%255) / 255.0f; lab = lab/255; - if (lab!=0) - CGoGNerr << "Error picking color, too many darts"<< CGoGNendl; -} - - - -Dart TopoRender::pickColor(unsigned int x, unsigned int y) -{ - //more easy picking for - unsigned int dw = m_topo_dart_width; - m_topo_dart_width+=2; - - // save clear color and set to zero - float cc[4]; - glGetFloatv(GL_COLOR_CLEAR_VALUE,cc); - - glClearColor(0.0f,0.0f,0.0f,0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glDisable(GL_LIGHTING); - // draw in back buffer (not shown on screen) - drawDarts(); - - // restore dart width - m_topo_dart_width = dw; - - // read the pixel under the mouse in back buffer - glReadBuffer(GL_BACK); - float color[3]; - glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color); - - glClearColor(cc[0], cc[1], cc[2], cc[3]); - - return colToDart(color); -} - -void TopoRender::pushColors() -{ - m_color_save = new float[6*m_nbDarts]; - m_vbo3->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(m_color_save, colorBuffer, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); -} - -void TopoRender::popColors() -{ - m_vbo3->bind(); - void* colorBuffer = glMapBufferARB(GL_ARRAY_BUFFER, GL_READ_WRITE); - - memcpy(colorBuffer, m_color_save, 6*m_nbDarts*sizeof(float)); - glUnmapBuffer(GL_ARRAY_BUFFER); - - delete[] m_color_save; - m_color_save=NULL; -} - -void TopoRender::svgout2D(const std::string& filename, const glm::mat4& model, const glm::mat4& proj) -{ - Utils::SVG::SVGOut svg(filename,model,proj); - toSVG(svg); - svg.write(); -} - -void TopoRender::toSVG(Utils::SVG::SVGOut& svg) -{ -// svg.setWidth(m_topo_relation_width); -// -// // PHI2 / beta2 -// const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); -// svg.beginLines(); -// for (unsigned int i=0; ireleasePtr(); -// -// //PHI1 /beta1 -// ptr = reinterpret_cast(m_vbo1->lockPtr()); -// svg.beginLines(); -// for (unsigned int i=0; ireleasePtr(); -// -// -// const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); -// ptr= reinterpret_cast(m_vbo0->lockPtr()); -// -// svg.setWidth(m_topo_dart_width); -// svg.beginLines(); -// for (unsigned int i=0; ireleasePtr(); -// m_vbo3->releasePtr(); - - - // PHI2 / beta2 - Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj); - svg1->setToLayer(); - const Geom::Vec3f* ptr = reinterpret_cast(m_vbo2->lockPtr()); - svg1->setWidth(m_topo_relation_width); - svg1->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.8f,0.0f,0.0f)); - svg1->endLines(); - m_vbo2->releasePtr(); - - svg.addGroup(svg1); - - //PHI1 /beta1 - Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj); - svg2->setToLayer(); - ptr = reinterpret_cast(m_vbo1->lockPtr()); - svg2->setWidth(m_topo_relation_width); - svg2->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f)); - svg2->endLines(); - m_vbo1->releasePtr(); - - svg.addGroup(svg2); - - const Geom::Vec3f* colorsPtr = reinterpret_cast(m_vbo3->lockPtr()); - ptr= reinterpret_cast(m_vbo0->lockPtr()); - - Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj); - svg3->setToLayer(); - svg3->setWidth(m_topo_dart_width); - svg3->beginLines(); - for (unsigned int i=0; iaddLine(ptr[2*i], ptr[2*i+1], colorsPtr[2*i]); - svg3->endLines(); - - svg.addGroup(svg3); - - Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj); - svg4->setWidth(m_topo_dart_width); - svg4->setToLayer(); - svg4->beginPoints(); - for (unsigned int i=0; iaddPoint(ptr[2*i], colorsPtr[2*i]); - svg4->endPoints(); - - svg.addGroup(svg4); - - m_vbo0->releasePtr(); - m_vbo3->releasePtr(); -} - - -void TopoRender::setNormalShift(float ns) -{ - m_normalShift = ns; -} - -void TopoRender::setBoundaryShift(float bs) -{ - m_boundShift = bs; -} - - - -}//end namespace GL2 - -}//end namespace Render - -}//end namespace Algo - -}//end namespace CGoGN diff --git a/src/Topology/generic/attribmap.cpp b/src/Topology/generic/attribmap.cpp index 0b1198ec71c4ec286251a28650fb2a0029e03240..15df2180ad9433aab9fa16a41b42ddd684272f99 100644 --- a/src/Topology/generic/attribmap.cpp +++ b/src/Topology/generic/attribmap.cpp @@ -29,36 +29,6 @@ namespace CGoGN void AttribMap::init() { - for(unsigned int orbit = 0; orbit < NB_ORBITS; ++orbit) - { - AttributeContainer& cont = m_attribs[orbit]; - for (unsigned int t = 0; t < m_nbThreads; ++t) - { - std::stringstream ss ; - ss << "Mark_" << t ; - AttributeMultiVector* amvMark = cont.addAttribute(ss.str()) ; - for(unsigned int i = cont.begin(); i < cont.end(); cont.next(i)) - amvMark->operator[](i).clear() ; - m_markTables[orbit][t] = amvMark ; - } - } - - for (unsigned int j = 0; j < NB_THREAD; ++j) - { - std::vector& cmg = cellMarkers[j]; - for(unsigned int i = 0; i < cmg.size(); ++i) - { - CellMarkerGen* cm = cmg[i] ; - cm->updateMarkVector(m_markTables[cm->getCell()][cm->getThread()]) ; - } - - std::vector& dmg = dartMarkers[j]; - for(unsigned int i = 0; i < dmg.size(); ++i) - { - DartMarkerGen* dm = dmg[i] ; - dm->updateMarkVector(m_markTables[DART][dm->getThread()]) ; - } - } } AttribMap::AttribMap() : GenericMap() @@ -73,9 +43,4 @@ void AttribMap::clear(bool removeAttrib) init() ; } -AttributeMultiVectorGen* AttribMap::getAttributeVectorGen(unsigned int orbit, const std::string& nameAttr) -{ - return m_attribs[orbit].getVirtualDataVector(nameAttr) ; -} - } // namespace CGoGN diff --git a/src/Topology/generic/genericmap.cpp b/src/Topology/generic/genericmap.cpp index 96fba7a08f40745d43b00fe1a08acf011a0b1bd4..d07ef035978790275d34880a404d69566b94ca4a 100644 --- a/src/Topology/generic/genericmap.cpp +++ b/src/Topology/generic/genericmap.cpp @@ -80,21 +80,15 @@ GenericMap::GenericMap() : m_nbThreads(1) { m_attribs[i].setOrbit(i) ; m_attribs[i].setRegistry(m_attributes_registry_map) ; - m_embeddings[i] = NULL ; - m_quickTraversal[i] = NULL ; for(unsigned int j = 0; j < NB_THREAD; ++j) { 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 ; - } } + init(); + for (unsigned int i = 0; i < NB_THREAD; ++i) { dartMarkers[i].reserve(16) ; @@ -102,8 +96,8 @@ GenericMap::GenericMap() : m_nbThreads(1) } // get & lock marker for boundary - m_boundaryMarkers[0] = m_marksets[DART][0].getNewMark(); - m_boundaryMarkers[1] = m_marksets[DART][0].getNewMark(); + m_boundaryMarkers[0] = m_marksets[DART][0].getNewMark(); + m_boundaryMarkers[1] = m_marksets[DART][0].getNewMark(); } GenericMap::~GenericMap() @@ -145,26 +139,58 @@ GenericMap::~GenericMap() } } -void GenericMap::clear(bool removeAttrib) +void GenericMap::init() { - if (removeAttrib) + for(unsigned int i = 0; i < NB_ORBITS; ++i) { - for(unsigned int i = 0; i < NB_ORBITS; ++i) + m_attribs[i].clear(true) ; + m_embeddings[i] = NULL ; + m_quickTraversal[i] = NULL; + + for(unsigned int j = 0; j < NB_ORBITS; ++j) { - m_attribs[i].clear(true) ; - m_embeddings[i] = NULL ; - m_quickTraversal[i] = NULL; - for(unsigned int j = 0; j < NB_ORBITS; ++j) - { - m_quickLocalIncidentTraversal[i][j] = NULL ; - m_quickLocalAdjacentTraversal[i][j] = NULL ; - } + m_quickLocalIncidentTraversal[i][j] = NULL ; + m_quickLocalAdjacentTraversal[i][j] = NULL ; } - for(std::multimap::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it) - (*it).second->setInvalid() ; - attributeHandlers.clear() ; + AttributeContainer& cont = m_attribs[i]; + for (unsigned int t = 0; t < m_nbThreads; ++t) + { + std::stringstream ss ; + ss << "Mark_" << t ; + AttributeMultiVector* amvMark = cont.addAttribute(ss.str()) ; + for(unsigned int idx = cont.begin(); idx < cont.end(); cont.next(idx)) + amvMark->operator[](idx).clear() ; + m_markTables[i][t] = amvMark ; + } + } + + for (unsigned int j = 0; j < NB_THREAD; ++j) + { + std::vector& cmg = cellMarkers[j]; + for(unsigned int i = 0; i < cmg.size(); ++i) + { + CellMarkerGen* cm = cmg[i] ; + cm->updateMarkVector(m_markTables[cm->getCell()][cm->getThread()]) ; + } + + std::vector& dmg = dartMarkers[j]; + for(unsigned int i = 0; i < dmg.size(); ++i) + { + DartMarkerGen* dm = dmg[i] ; + dm->updateMarkVector(m_markTables[DART][dm->getThread()]) ; + } } + + for(std::multimap::iterator it = attributeHandlers.begin(); it != attributeHandlers.end(); ++it) + (*it).second->setInvalid() ; + attributeHandlers.clear() ; +} + +void GenericMap::clear(bool removeAttrib) +{ + if (removeAttrib) + init(); else { for(unsigned int i = 0; i < NB_ORBITS; ++i) diff --git a/src/Topology/gmap/embeddedGMap2.cpp b/src/Topology/gmap/embeddedGMap2.cpp index 67dabf71fdf2b5aa5896b8148c8e9f817e77aa9e..e46c9ad64d9ceab324b9051be3c575548acb2885 100644 --- a/src/Topology/gmap/embeddedGMap2.cpp +++ b/src/Topology/gmap/embeddedGMap2.cpp @@ -41,20 +41,20 @@ Dart EmbeddedGMap2::newFace(unsigned int nbEdges, bool withBoundary) { Traversor2FV t(*this, d); for(Dart it = t.begin(); it != t.end(); it = t.next()) - initOrbitEmbeddingNewCell(it) ; + initOrbitEmbeddingOnNewCell(it) ; } if(isOrbitEmbedded()) { Traversor2FE t(*this, d); for(Dart it = t.begin(); it != t.end(); it = t.next()) - initOrbitEmbeddingNewCell(it) ; + initOrbitEmbeddingOnNewCell(it) ; } if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(d) ; - initOrbitEmbeddingNewCell(phi2(d)) ; + initOrbitEmbeddingOnNewCell(d) ; + initOrbitEmbeddingOnNewCell(phi2(d)) ; } } @@ -95,7 +95,7 @@ void EmbeddedGMap2::splitVertex(Dart d, Dart e) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(phi1(dd)) ; + initOrbitEmbeddingOnNewCell(phi1(dd)) ; } if(isOrbitEmbedded()) @@ -128,7 +128,7 @@ Dart EmbeddedGMap2::cutEdge(Dart d) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(nd) ; + initOrbitEmbeddingOnNewCell(nd) ; } if (isOrbitEmbedded()) @@ -353,7 +353,7 @@ void EmbeddedGMap2::sewFaces(Dart d, Dart e, bool withBoundary) GMap2::sewFaces(d, e, false) ; if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(d) ; + initOrbitEmbeddingOnNewCell(d) ; } return ; } @@ -440,7 +440,7 @@ void EmbeddedGMap2::splitFace(Dart d, Dart e) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(beta1(d)) ; + initOrbitEmbeddingOnNewCell(beta1(d)) ; } if (isOrbitEmbedded()) @@ -537,7 +537,7 @@ unsigned int EmbeddedGMap2::closeHole(Dart d, bool forboundary) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(dd) ; + initOrbitEmbeddingOnNewCell(dd) ; } return nbE ; @@ -582,13 +582,13 @@ bool EmbeddedGMap2::check() CGoGNout << "Check: embedding ok" << CGoGNendl ; - std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; std::cout << "nb vertex cells : " << m_attribs[VERTEX].size() << std::endl ; - std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; std::cout << "nb edge cells : " << m_attribs[EDGE].size() << std::endl ; - std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; std::cout << "nb face cells : " << m_attribs[FACE].size() << std::endl ; return true ; diff --git a/src/Topology/gmap/embeddedGMap3.cpp b/src/Topology/gmap/embeddedGMap3.cpp index 0cfacf9ef2f53c73a791d388de9ba8177cf4b8bf..a4348c450771197a9283465f90fabc300f77567b 100644 --- a/src/Topology/gmap/embeddedGMap3.cpp +++ b/src/Topology/gmap/embeddedGMap3.cpp @@ -358,7 +358,7 @@ unsigned int EmbeddedGMap3::closeHole(Dart d, bool forboundary) { unsigned int nbF = GMap3::closeHole(d, forboundary) ; - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(1024) ; @@ -461,16 +461,16 @@ bool EmbeddedGMap3::check() CGoGNout << "Check: embedding ok" << CGoGNendl ; - std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; std::cout << "nb vertex cells : " << m_attribs[VERTEX].size() << std::endl ; - std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; std::cout << "nb edge cells : " << m_attribs[EDGE].size() << std::endl ; - std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; std::cout << "nb face cells : " << m_attribs[FACE].size() << std::endl ; - std::cout << "nb volume orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb volume orbits : " << getNbOrbits() << std::endl ; std::cout << "nb volume cells : " << m_attribs[VOLUME].size() << std::endl ; return true ; diff --git a/src/Topology/ihmap/ihm2.cpp b/src/Topology/ihmap/ihm2.cpp index 81068e4f8cff7d399049f5872797b1f64e5b3217..e99b033311502d2b488f7eb97ce42d2d28acf116 100644 --- a/src/Topology/ihmap/ihm2.cpp +++ b/src/Topology/ihmap/ihm2.cpp @@ -79,7 +79,7 @@ void ImplicitHierarchicalMap2::initImplicitProperties() void ImplicitHierarchicalMap2::initEdgeId() { m_idCount = 0 ; - DartMarker edgeMark(*this) ; + DartMarker edgeMark(*this) ; for(Dart d = Map2::begin(); d != Map2::end(); Map2::next(d)) { if(!edgeMark.isMarked(d)) diff --git a/src/Topology/map/embeddedMap2.cpp b/src/Topology/map/embeddedMap2.cpp index 0bf210c1de0b10157a9509c868d6641b999a7c22..888042355e1b33fee59a987329fd70826fb7cac1 100644 --- a/src/Topology/map/embeddedMap2.cpp +++ b/src/Topology/map/embeddedMap2.cpp @@ -40,7 +40,7 @@ Dart EmbeddedMap2::newPolyLine(unsigned int nbEdges) Dart e = d ; for (unsigned int i = 0 ; i <= nbEdges ; ++i) { - initOrbitEmbeddingNewCell(e) ; + initOrbitEmbeddingOnNewCell(e) ; e = this->phi1(e) ; } } @@ -50,14 +50,14 @@ Dart EmbeddedMap2::newPolyLine(unsigned int nbEdges) Dart e = d ; for (unsigned int i = 0 ; i < nbEdges ; ++i) { - initOrbitEmbeddingNewCell(e) ; + initOrbitEmbeddingOnNewCell(e) ; e = this->phi1(e) ; } } if (isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(d) ; + initOrbitEmbeddingOnNewCell(d) ; } return d ; } @@ -73,12 +73,12 @@ Dart EmbeddedMap2::newFace(unsigned int nbEdges, bool withBoundary) /* Traversor2FV t(*this, d); for(Dart it = t.begin(); it != t.end(); it = t.next()) - initOrbitEmbeddingNewCell(it) ; + initOrbitEmbeddingOnNewCell(it) ; */ Dart e = d; do { - initOrbitEmbeddingNewCell(e) ; + initOrbitEmbeddingOnNewCell(e) ; e = this->phi1(e); } while (d!=e); } @@ -88,20 +88,20 @@ Dart EmbeddedMap2::newFace(unsigned int nbEdges, bool withBoundary) /* Traversor2FE t(*this, d); for(Dart it = t.begin(); it != t.end(); it = t.next()) - initOrbitEmbeddingNewCell(it) ; + initOrbitEmbeddingOnNewCell(it) ; */ Dart e = d; do { - initOrbitEmbeddingNewCell(e) ; + initOrbitEmbeddingOnNewCell(e) ; e = this->phi1(e); } while (d!=e); } if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(d) ; - initOrbitEmbeddingNewCell(phi2(d)) ; + initOrbitEmbeddingOnNewCell(d) ; + initOrbitEmbeddingOnNewCell(phi2(d)) ; } } // else @@ -111,7 +111,7 @@ Dart EmbeddedMap2::newFace(unsigned int nbEdges, bool withBoundary) ///* // Traversor2FV t(*this, d); // for(Dart it = t.begin(); it != t.end(); it = t.next()) -// initOrbitEmbeddingNewCell(it) ; +// initOrbitEmbeddingOnNewCell(it) ; //*/ // Dart e = d; // do @@ -122,7 +122,7 @@ Dart EmbeddedMap2::newFace(unsigned int nbEdges, bool withBoundary) // } // // if(isOrbitEmbedded()) -// initOrbitEmbeddingNewCell(d) ; +// initOrbitEmbeddingOnNewCell(d) ; // // } return d ; @@ -144,7 +144,7 @@ void EmbeddedMap2::splitVertex(Dart d, Dart e) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(phi1(dd)) ; + initOrbitEmbeddingOnNewCell(phi1(dd)) ; } if(isOrbitEmbedded()) @@ -173,7 +173,7 @@ Dart EmbeddedMap2::cutEdge(Dart d) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(nd) ; + initOrbitEmbeddingOnNewCell(nd) ; } if (isOrbitEmbedded()) @@ -403,7 +403,7 @@ void EmbeddedMap2::sewFaces(Dart d, Dart e, bool withBoundary) // if(isOrbitEmbedded()) // { ///* -// initOrbitEmbeddingNewCell(d) ; +// initOrbitEmbeddingOnNewCell(d) ; //*/ // unsigned int emb = newCell(); // initDartEmbedding(d,emb); @@ -495,7 +495,7 @@ void EmbeddedMap2::splitFace(Dart d, Dart e) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(phi_1(d)) ; + initOrbitEmbeddingOnNewCell(phi_1(d)) ; } if (isOrbitEmbedded()) @@ -621,7 +621,7 @@ unsigned int EmbeddedMap2::closeHole(Dart d, bool forboundary) { unsigned int emb = getEmbedding(phi1(phi2(f))); if (emb == EMBNULL) - initOrbitEmbeddingNewCell(f) ; + initOrbitEmbeddingOnNewCell(f) ; else initDartEmbedding(f, emb) ; } @@ -630,7 +630,7 @@ unsigned int EmbeddedMap2::closeHole(Dart d, bool forboundary) { unsigned int emb = getEmbedding(phi2(f)); if (emb == EMBNULL) - initOrbitEmbeddingNewCell(f) ; + initOrbitEmbeddingOnNewCell(f) ; else initDartEmbedding(f, emb) ; } @@ -640,7 +640,7 @@ unsigned int EmbeddedMap2::closeHole(Dart d, bool forboundary) if(isOrbitEmbedded()) { - initOrbitEmbeddingNewCell(dd) ; + initOrbitEmbeddingOnNewCell(dd) ; } return nbE ; @@ -706,15 +706,15 @@ bool EmbeddedMap2::check() CGoGNout << "Check: embedding ok" << CGoGNendl ; - std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; if (isOrbitEmbedded()) std::cout << "nb vertex cells : " << m_attribs[VERTEX].size() << std::endl ; - std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; if (isOrbitEmbedded()) std::cout << "nb edge cells : " << m_attribs[EDGE].size() << std::endl ; - std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; if (isOrbitEmbedded()) std::cout << "nb face cells : " << m_attribs[FACE].size() << std::endl ; diff --git a/src/Topology/map/embeddedMap3.cpp b/src/Topology/map/embeddedMap3.cpp index b49ae40b9b37dc8cf2bca97f819593c39c6fcfec..fb48d48e042420599f6b1e5ecf7c5b1a008f4916 100644 --- a/src/Topology/map/embeddedMap3.cpp +++ b/src/Topology/map/embeddedMap3.cpp @@ -45,16 +45,12 @@ Dart EmbeddedMap3::splitVertex(std::vector& vd) } if(isOrbitEmbedded()) - { - initOrbitEmbeddingNewCell(dres) ; // TODO : check if dres is a dart of the new edge - } + initOrbitEmbeddingOnNewCell(dres) ; // TODO : check if dres is a dart of the new edge if(isOrbitEmbedded()) { for(std::vector::iterator it = vd.begin() ; it != vd.end() ; ++it) - { setOrbitEmbedding( *it, getEmbedding(*it)) ; - } } return dres; @@ -168,7 +164,7 @@ bool EmbeddedMap3::edgeCanCollapse(Dart d) // if(isBoundaryEdge(d)) // return false; - CellMarkerStore mv(*this); + CellMarkerStore mv(*this); Traversor3VVaE t3VVaE_v1(*this,d); for(Dart dit = t3VVaE_v1.begin() ; dit != t3VVaE_v1.end() ; dit = t3VVaE_v1.next()) @@ -563,7 +559,7 @@ unsigned int EmbeddedMap3::closeHole(Dart d, bool forboundary) { unsigned int nbF = Map3::closeHole(d, forboundary) ; - DartMarkerStore mark(*this); // Lock a marker + DartMarkerStore mark(*this); // Lock a marker std::vector visitedFaces; // Faces that are traversed visitedFaces.reserve(1024) ; @@ -606,19 +602,18 @@ unsigned int EmbeddedMap3::closeHole(Dart d, bool forboundary) bool EmbeddedMap3::check() { - std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb vertex orbits : " << getNbOrbits() << std::endl ; std::cout << "nb vertex cells : " << m_attribs[VERTEX].size() << std::endl ; - std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb edge orbits : " << getNbOrbits() << std::endl ; std::cout << "nb edge cells : " << m_attribs[EDGE].size() << std::endl ; - std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb face orbits : " << getNbOrbits() << std::endl ; std::cout << "nb face cells : " << m_attribs[FACE].size() << std::endl ; - std::cout << "nb volume orbits : " << getNbOrbits() << std::endl ; + std::cout << "nb volume orbits : " << getNbOrbits() << std::endl ; std::cout << "nb volume cells : " << m_attribs[VOLUME].size() << std::endl ; - bool topo = Map3::check() ; if (!topo) return false ;