diff --git a/include/Algo/MovingObjects/particle_cell_2D.hpp b/include/Algo/MovingObjects/particle_cell_2D.hpp index f826326a8a903ec53dffd28c31a531476feaad85..feadf168bfca67fa839c412c76e906848fec09f7 100644 --- a/include/Algo/MovingObjects/particle_cell_2D.hpp +++ b/include/Algo/MovingObjects/particle_cell_2D.hpp @@ -100,7 +100,8 @@ void ParticleCell2D::vertexState(const VEC3& goal) do { if(Algo::Geometry::isPointOnHalfEdge(m,d,positionAttribut,goal) - && Algo::Geometry::isPointOnHalfEdge(m,this->m.phi2(d),positionAttribut,goal)) + && Algo::Geometry::isPointOnHalfEdge(m,this->m.phi2(d),positionAttribut,goal) + && this->getOrientationEdge(current, this->d) == Geom::ALIGNED) { edgeState(goal) ; return; diff --git a/include/Algo/MovingObjects/particle_cell_2D_memo.h b/include/Algo/MovingObjects/particle_cell_2D_memo.h index bed19153e26465ed37be4b389747de1fee18ec46..c2a937c462b00dfa837b32002ef252238f9bc47b 100644 --- a/include/Algo/MovingObjects/particle_cell_2D_memo.h +++ b/include/Algo/MovingObjects/particle_cell_2D_memo.h @@ -1,6 +1,6 @@ #ifndef PARTCELL2DMEMO_H #define PARTCELL2DMEMO_H - +//#define DEBUG #include "particle_cell_2D.h" #include "Algo/Geometry/inclusion.h" @@ -29,34 +29,27 @@ public: typedef typename PFP::VEC3 VEC3; typedef VertexAttribute TAB_POS ; - std::list memo_cross ; - bool detect_vertex ; - bool detect_edge ; - bool detect_face ; private: - ParticleCell2DMemo() : - detect_vertex(false), detect_edge(false), detect_face(true) - { + ParticleCell2DMemo(){ } public: ParticleCell2DMemo(MAP& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) : - ParticleCell2D(map, belonging_cell, pos, tabPos), - detect_vertex(false), - detect_edge(false), - detect_face(true) + ParticleCell2D(map, belonging_cell, pos, tabPos) { + } - void vertexState(const VEC3& current) ; + void vertexState(const VEC3& current, CellMarkerMemo * memo_cross) ; - void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ; + void edgeState(const VEC3& current, CellMarkerMemo * memo_cross, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ; - void faceState(const VEC3& current) ; + void faceState(const VEC3& current, CellMarkerMemo * memo_cross) ; - void move(const VEC3& goal) ; + void move(const VEC3& goal, CellMarkerMemo * memo_cross) ; + std::vector get_memo(const VEC3& goal); } ; #include "particle_cell_2D_memo.hpp" diff --git a/include/Algo/MovingObjects/particle_cell_2D_memo.hpp b/include/Algo/MovingObjects/particle_cell_2D_memo.hpp index 5caa6c97bf580ccad2217a9e1e5a14042b912274..575d6ac6447b7fc96d1023126fc6763ddd94aa77 100644 --- a/include/Algo/MovingObjects/particle_cell_2D_memo.hpp +++ b/include/Algo/MovingObjects/particle_cell_2D_memo.hpp @@ -1,5 +1,5 @@ template -void ParticleCell2DMemo::move(const VEC3& goal) +void ParticleCell2DMemo::move(const VEC3& goal, CellMarkerMemo * memo_cross) { this->crossCell = NO_CROSS ; if (!Geom::arePointsEquals(goal, this->getPosition())) @@ -7,13 +7,13 @@ void ParticleCell2DMemo::move(const VEC3& goal) switch (this->getState()) { case VERTEX : - vertexState(goal) ; + vertexState(goal,memo_cross) ; break ; case EDGE : - edgeState(goal) ; + edgeState(goal,memo_cross) ; break ; case FACE : - faceState(goal) ; + faceState(goal,memo_cross) ; break ; } } @@ -22,13 +22,22 @@ void ParticleCell2DMemo::move(const VEC3& goal) } template -void ParticleCell2DMemo::vertexState(const VEC3& current) +std::vector ParticleCell2DMemo::get_memo(const VEC3& goal) +{ + CellMarkerMemo memo_cross(this->m); + memo_cross.mark(this->d); + this->move(goal,&memo_cross); + return memo_cross.get_markedCells(); +} + +template +void ParticleCell2DMemo::vertexState(const VEC3& current, CellMarkerMemo * memo_cross) { #ifdef DEBUG - CGoGNout << "vertexState" << d << CGoGNendl ; + CGoGNout << "vertexState" << this->d << CGoGNendl ; #endif assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2])) ; - + (*memo_cross).mark(this->d); this->crossCell = CROSS_OTHER ; if (Algo::Geometry::isPointOnVertex < PFP > (this->m, this->d, this->positionAttribut, current)) @@ -67,9 +76,12 @@ void ParticleCell2DMemo::vertexState(const VEC3& current) do { if(Algo::Geometry::isPointOnHalfEdge(this->m,this->d,this->positionAttribut,current) - && Algo::Geometry::isPointOnHalfEdge(this->m,this->m.phi2(this->d),this->positionAttribut,current)) + && Algo::Geometry::isPointOnHalfEdge(this->m,this->m.phi2(this->d),this->positionAttribut,current) + && this->getOrientationEdge(current, this->d) == Geom::ALIGNED) { - this->edgeState(current) ; + + this->edgeState(current,memo_cross) ; + return; } this->d = this->m.phi2_1(this->d) ; @@ -94,31 +106,28 @@ void ParticleCell2DMemo::vertexState(const VEC3& current) } //displacement step - if (detect_vertex) - memo_cross.push_back(this->d) ; + if (this->getOrientationEdge(current, this->d) == Geom::ALIGNED && Algo::Geometry::isPointOnHalfEdge(this->m, this->d, this->positionAttribut, current)) - edgeState(current) ; + edgeState(current,memo_cross) ; else { this->d = this->m.phi1(this->d) ; - faceState(current) ; + faceState(current,memo_cross) ; } } } template -void ParticleCell2DMemo::edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge) +void ParticleCell2DMemo::edgeState(const VEC3& current, CellMarkerMemo* memo_cross, Geom::Orientation2D sideOfEdge) { #ifdef DEBUG - CGoGNout << "edgeState" << d << CGoGNendl ; + CGoGNout << "edgeState" << this->d << CGoGNendl ; #endif - if (detect_edge) - memo_cross.push_back(this->d) ; assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2])) ; // assert(Algo::Geometry::isPointOnEdge(m,d,m_positions,m_position)); - + (*memo_cross).mark(this->d); if (this->crossCell == NO_CROSS) { this->crossCell = CROSS_EDGE ; @@ -133,11 +142,11 @@ void ParticleCell2DMemo::edgeState(const VEC3& current, Geom::Orientation2D { case Geom::LEFT : this->d = this->m.phi1(this->d) ; - faceState(current) ; + faceState(current,memo_cross) ; return ; case Geom::RIGHT : this->d = this->m.phi1(this->m.phi2(this->d)) ; - faceState(current) ; + faceState(current,memo_cross) ; return ; default : this->setState(EDGE) ; @@ -148,7 +157,7 @@ void ParticleCell2DMemo::edgeState(const VEC3& current, Geom::Orientation2D > (this->m, this->d, this->positionAttribut, current)) { this->ParticleBase::move(this->positionAttribut[this->d]) ; - vertexState(current) ; + vertexState(current,memo_cross) ; return ; } else if (!Algo::Geometry::isPointOnHalfEdge < PFP @@ -156,7 +165,7 @@ void ParticleCell2DMemo::edgeState(const VEC3& current, Geom::Orientation2D { this->d = this->m.phi2(this->d) ; this->ParticleBase::move(this->positionAttribut[this->d]) ; - vertexState(current) ; + vertexState(current,memo_cross) ; return ; } @@ -164,18 +173,18 @@ void ParticleCell2DMemo::edgeState(const VEC3& current, Geom::Orientation2D } template -void ParticleCell2DMemo::faceState(const VEC3& current) +void ParticleCell2DMemo::faceState(const VEC3& current, CellMarkerMemo * memo_cross) { #ifdef DEBUG - CGoGNout << "faceState" << d << CGoGNendl ; + CGoGNout << "faceState" << this->d << CGoGNendl ; #endif - if (detect_face) memo_cross.push_back(this->d) ; + assert( std::isfinite(this->getPosition()[0]) && std::isfinite(this->getPosition()[1]) && std::isfinite(this->getPosition()[2])) ; assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2])) ; // assert(Algo::Geometry::isPointInConvexFace2D(m,d,m_positions,m_position,true)); - + (*memo_cross).mark(this->d); Dart dd = this->d ; float wsoe = this->getOrientationFace(current, this->m.phi1(this->d)) ; @@ -202,16 +211,16 @@ void ParticleCell2DMemo::faceState(const VEC3& current) break ; case Geom::ALIGNED : this->ParticleBase::move(current) ; - edgeState(current) ; + edgeState(current,memo_cross) ; return ; case Geom::RIGHT : // CGoGNout << "smthg went bad " << m_position << " " << current << CGoGNendl; // CGoGNout << "d1 " << m_positions[d] << " d2 " << m_positions[m.phi1(d)] << CGoGNendl; - this->ParticleBase::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ; + this->ParticleBase::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ; // CGoGNout << " " << m_position << CGoGNendl; - edgeState(current, Geom::RIGHT) ; - return ; + edgeState(current,memo_cross, Geom::RIGHT) ; + return ; } } while (this->d != dd) ; this->ParticleBase::move(current); @@ -252,13 +261,13 @@ void ParticleCell2DMemo::faceState(const VEC3& current) case Geom::ALIGNED : // CGoGNout << "pic" << CGoGNendl; this->ParticleBase::move(current) ; - edgeState(current) ; + edgeState(current,memo_cross) ; return ; case Geom::RIGHT : // CGoGNout << "smthg went bad(2) " << m_position << CGoGNendl; this->ParticleBase::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ; // CGoGNout << " " << m_position << CGoGNendl; - edgeState(current, Geom::RIGHT) ; + edgeState(current,memo_cross ,Geom::RIGHT) ; return ; } } while (this->d != dd) ; @@ -294,12 +303,12 @@ void ParticleCell2DMemo::faceState(const VEC3& current) this->d = this->m.phi1(this->d) ; //to check this->ParticleBase::move(this->positionAttribut[this->d]) ; - vertexState(current) ; + vertexState(current,memo_cross) ; } else { this->ParticleBase::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ; - edgeState(current, Geom::RIGHT) ; + edgeState(current,memo_cross, Geom::RIGHT) ; } } diff --git a/include/Topology/generic/cellmarker.h b/include/Topology/generic/cellmarker.h index a5da0fd529e1c07109fcd6518db884a6564846ec..ae518426eaa62813ce49626297faed54fd916bb4 100644 --- a/include/Topology/generic/cellmarker.h +++ b/include/Topology/generic/cellmarker.h @@ -307,7 +307,55 @@ public: this->m_markVector->operator[](*it).unsetMark(this->m_mark) ; } }; +/** + * class that allows the marking of Darts + * the marked Darts are stored to optimize the unmarking task at destruction + * \warning no default constructor + */ +template +class CellMarkerMemo: public CellMarkerBase +{ +protected: + std::vector m_markedDarts ; + +public: + CellMarkerMemo(GenericMap& map, unsigned int thread = 0) : CellMarkerBase(map, thread) + {} + + virtual ~CellMarkerMemo() + { + unmarkAll() ; +// assert(isAllUnmarked); + CGoGN_ASSERT(this->isAllUnmarked()) + } + +protected: + CellMarkerMemo(const CellMarkerMemo& cm) : CellMarkerBase(cm) + {} +public: + void mark(Dart d) + { + if(!this->isMarked(d)) + { + CellMarkerBase::mark(d) ; + m_markedDarts.push_back(d) ; + } + } + + void unmarkAll() + { + assert(this->m_map.template getMarkerSet(this->m_thread).testMark(this->m_mark)); + assert(this->m_markVector != NULL); + + for (std::vector::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it) + this->m_markVector->operator[](this->m_map.template getEmbedding(*it)).unsetMark(this->m_mark) ; + } + std::vector get_markedCells() + { + return m_markedDarts; + } +}; /** * class that allows the marking of cells * the markers are not unmarked at destruction