Commit 0f35dc93 authored by Thomas Jund's avatar Thomas Jund

adding new type of particle for safe vertices tracking

parent 412ec0b9
......@@ -273,6 +273,9 @@ void readCoordAndStyle(xmlNode* cur_path,
template <typename PFP>
bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttribute<typename PFP::VEC3>& position, CellMarker<EDGE>& obstacleMark, CellMarker<FACE>& buildingMark)
{
//TODO : remove auto-intersecting faces
//TODO : handling polygons with holes
typedef typename PFP::VEC3 VEC3;
typedef std::vector<VEC3> POLYGON;
......@@ -437,7 +440,7 @@ bool importSVG(typename PFP::MAP& map, const std::string& filename, VertexAttrib
if(!buildingMark.isMarked(d))
{
bool canSimplify = true ;
while ( canSimplify && ((position[map.phi1(d)] - position[d]).norm() < edgeWidth[d]) )
while ( canSimplify && (Geometry::edgeLength<PFP>(map,d,position) < edgeWidth[d]) )
{
if (map.vertexDegree(map.phi1(d)) == 2)
{
......
......@@ -70,14 +70,14 @@ public:
Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, Dart d) ;
void vertexState(const VEC3& current) ;
virtual void vertexState(const VEC3& current) ;
void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
virtual void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
//just an orientation test : check which dart is aimed to leave the current face to reach an other position
Dart faceOrientationState(const VEC3& toward) ;
void faceState(const VEC3& current) ;
virtual void faceState(const VEC3& current) ;
void move(const VEC3& goal)
{
......
......@@ -42,11 +42,11 @@ public:
}
void vertexState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross) ;
virtual void vertexState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross) ;
void edgeState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
virtual void edgeState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
void faceState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross) ;
virtual void faceState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross) ;
std::vector<Dart> move(const VEC3& goal) ;
std::vector<Dart> move(const VEC3& goal, CellMarkerMemo<FACE>& memo_cross) ;
......
#ifndef PARTCELL2DMEMOSECURED_H
#define PARTCELL2DMEMOSECURED_H
//#define DEBUG
#include "particle_cell_2D_memo.h"
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
#include <iostream>
/* A particle cell secured : version of particle cell-memo where particles might go outside the navigation map
* this class should be used for debug mode only */
namespace CGoGN
{
namespace Algo
{
namespace MovingObjects
{
template <typename PFP>
class ParticleCell2DSecured : public ParticleCell2DMemo<PFP>
{
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS ;
private:
ParticleCell2DSecured(){
std::cout << "Particle Secured : for debugging (unoptimized)" << std::endl;
}
public:
ParticleCell2DSecured(MAP& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) :
ParticleCell2DMemo<PFP>(map, belonging_cell, pos, tabPos)
{
std::cout << "Particle Memo : for debugging (unoptimized)" << std::endl;
}
virtual void vertexState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross) ;
virtual void edgeState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
virtual void faceState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross) ;
std::vector<Dart> move(const VEC3& goal) ;
std::vector<Dart> move(const VEC3& goal, CellMarkerMemo<FACE>& memo_cross) ;
} ;
#include "particle_cell_2D_secured.hpp"
} //MovingObject
} //Algo
} //CGoGN
#endif
template <typename PFP>
std::vector<Dart> ParticleCell2DSecured<PFP>::move(const VEC3& goal)
{
this->crossCell = NO_CROSS ;
if (!Geom::arePointsEquals(goal, this->getPosition()))
{
CellMarkerMemo<FACE> memo_cross(this->m);
// memo_cross.mark(this->d);
switch (this->getState())
{
case VERTEX :
vertexState(goal,memo_cross) ;
break ;
case EDGE :
edgeState(goal,memo_cross) ;
break ;
case FACE :
faceState(goal,memo_cross) ;
break ;
}
return memo_cross.get_markedCells();
}
else
this->ParticleBase<PFP>::move(goal) ;
std::vector<Dart> res;
res.push_back(this->d);
return res;
}
template <typename PFP>
void ParticleCell2DSecured<PFP>::vertexState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross)
{
#ifdef DEBUG
CGoGNout << "vertexState" << this->d << CGoGNendl ;
#endif
// std::vector<Dart> mc = memo_cross.get_markedCells();
// if(std::find(mc.begin(),mc.end(),this->d)!=mc.end())
// {
// std::cout << "Error : particle outside map (vertex) " << std::endl;
// return;
// }
// else
{
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2])) ;
this->crossCell = CROSS_OTHER ;
if (Algo::Geometry::isPointOnVertex < PFP > (this->m, this->d, this->positionAttribut, current))
{
this->setState(VERTEX) ;
this->ParticleBase<PFP>::move(current) ;
return ;
}
else
{
//orientation step
if (this->positionAttribut[this->d][0] == this->positionAttribut[this->m.phi1(this->d)][0] && this->positionAttribut[this->d][1] == this->positionAttribut[this->m.phi1(this->d)][1])
this->d = this->m.phi2_1(this->d) ;
if (this->getOrientationEdge(current, this->m.phi2_1(this->d)) != Geom::RIGHT)
{
Dart dd_vert = this->d ;
do
{
this->d = this->m.phi2_1(this->d) ;
if (this->positionAttribut[this->d][0] == this->positionAttribut[this->m.phi1(this->d)][0]
&& this->positionAttribut[this->d][1]== this->positionAttribut[this->m.phi1(this->d)][1])
this->d = this->m.phi2_1(this->d) ;
} while (this->getOrientationEdge(current, this->m.phi2_1(this->d)) != Geom::RIGHT && dd_vert != this->d) ;
if (dd_vert == this->d)
{
//orbit with 2 edges : point on one edge
if (this->m.phi2_1(this->m.phi2_1(this->d)) == this->d)
{
if (!Algo::Geometry::isPointOnHalfEdge<PFP>(this->m, this->d, this->positionAttribut, current))
this->d = this->m.phi2_1(this->d) ;
}
else
{
//checking : case with 3 orthogonal darts and point on an edge
do
{
if(Algo::Geometry::isPointOnHalfEdge<PFP>(this->m,this->d,this->positionAttribut,current)
&& Algo::Geometry::isPointOnHalfEdge<PFP>(this->m,this->m.phi2(this->d),this->positionAttribut,current)
&& this->getOrientationEdge(current, this->d) == Geom::ALIGNED)
{
this->edgeState(current,memo_cross) ;
return;
}
this->d = this->m.phi2_1(this->d) ;
} while (this->getOrientationEdge(current, this->m.phi2_1(this->d)) != Geom::RIGHT && dd_vert != this->d) ;
this->ParticleBase<PFP>::move(current) ;
this->setState(VERTEX) ;
return ;
}
}
}
else
{
Dart dd_vert = this->m.phi2_1(this->d) ;
while (this->getOrientationEdge(current, this->d) == Geom::RIGHT && dd_vert != this->d)
{
this->d = this->m.phi12(this->d) ;
if (this->positionAttribut[this->d][0] == this->positionAttribut[this->m.phi1(this->d)][0]
&& this->positionAttribut[this->d][1] == this->positionAttribut[this->m.phi1(this->d)][1])
this->d = this->m.phi12(this->d) ;
}
}
//displacement step
if (this->getOrientationEdge(current, this->d) == Geom::ALIGNED
&& Algo::Geometry::isPointOnHalfEdge<PFP>(this->m, this->d, this->positionAttribut, current))
edgeState(current,memo_cross) ;
else
{
this->d = this->m.phi1(this->d) ;
faceState(current,memo_cross) ;
}
}
}
}
template <typename PFP>
void ParticleCell2DSecured<PFP>::edgeState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross, Geom::Orientation2D sideOfEdge)
{
#ifdef DEBUG
CGoGNout << "edgeState" << this->d << CGoGNendl ;
#endif
// std::vector<Dart> mc = memo_cross.get_markedCells();
// if(std::find(mc.begin(),mc.end(),this->d)!=mc.end())
// {
// std::cout << "Error : particle outside map (edge)" << std::endl;
// return;
// }
// else
{
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2])) ;
// assert(Algo::Geometry::isPointOnEdge<PFP>(m,d,m_positions,m_position));
if (this->crossCell == NO_CROSS)
{
this->crossCell = CROSS_EDGE ;
this->lastCrossed = this->d ;
}
else
this->crossCell = CROSS_OTHER ;
if (sideOfEdge == Geom::ALIGNED) sideOfEdge = this->getOrientationEdge(current, this->d) ;
switch (sideOfEdge)
{
case Geom::LEFT :
this->d = this->m.phi1(this->d) ;
faceState(current,memo_cross) ;
return ;
case Geom::RIGHT :
this->d = this->m.phi1(this->m.phi2(this->d)) ;
faceState(current,memo_cross) ;
return ;
default :
this->setState(EDGE) ;
break ;
}
if (!Algo::Geometry::isPointOnHalfEdge < PFP
> (this->m, this->d, this->positionAttribut, current))
{
this->ParticleBase<PFP>::move(this->positionAttribut[this->d]) ;
vertexState(current,memo_cross) ;
return ;
}
else if (!Algo::Geometry::isPointOnHalfEdge < PFP
> (this->m, this->m.phi2(this->d), this->positionAttribut, current))
{
this->d = this->m.phi2(this->d) ;
this->ParticleBase<PFP>::move(this->positionAttribut[this->d]) ;
vertexState(current,memo_cross) ;
return ;
}
this->ParticleBase<PFP>::move(current) ;
}
}
template <typename PFP>
void ParticleCell2DSecured<PFP>::faceState(const VEC3& current, CellMarkerMemo<FACE>& memo_cross)
{
#ifdef DEBUG
CGoGNout << "faceState" << this->d << CGoGNendl ;
#endif
std::vector<Dart> mc = memo_cross.get_markedCells();
if(std::find(mc.begin(),mc.end(),this->d)!=mc.end())
{
std::cout << "Error : particle outside map (face)" << std::endl;
return;
}
else
{
ParticleCell2DMemo<PFP>::faceState(current,memo_cross);
}
}
......@@ -35,7 +35,7 @@ Orientation2D testOrientation2D(const VEC3& P, const VEC3& Pa, const VEC3& Pb)
{
typedef typename VEC3::DATA_TYPE T ;
const T zero = 0.0001 ;
const T zero = 0.00001 ;
T p = (P[0] - Pa[0]) * (Pb[1] - Pa[1]) - (Pb[0] - Pa[0]) * (P[1] - Pa[1]) ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment