Commit 2f40b778 authored by David Cazier's avatar David Cazier
Browse files

Merge cgogn:~pitiot/CGoGN

Conflicts:
	include/Algo/MovingObjects/particle_cell_2D_memo.h
	include/Algo/MovingObjects/particle_cell_2D_memo.hpp
parents d57bdab0 ac66f55e
......@@ -68,7 +68,7 @@ public:
VEC3 intersectLineEdge(const VEC3& pA, const VEC3& pB, Dart d) ;
Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, VEC3 point, Dart d) ;
Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, Dart d) ;
void vertexState(const VEC3& current) ;
......
......@@ -48,10 +48,11 @@ typename PFP::VEC3 ParticleCell2D<PFP>::intersectLineEdge(const VEC3& pA, const
}
template <typename PFP>
Geom::Orientation2D ParticleCell2D<PFP>::getOrientationFace(VEC3 point, VEC3 sourcePoint, Dart d)
Geom::Orientation2D ParticleCell2D<PFP>::getOrientationFace(VEC3 goal, Dart d)
{
const VEC3& dPoint = positionAttribut[d] ;
return Geom::testOrientation2D(point, sourcePoint, dPoint) ;
const VEC3& p1 = this->getPosition() ;
const VEC3& p2 = positionAttribut[d] ;
return Geom::testOrientation2D(goal, p1, p2) ;
}
template <typename PFP>
......@@ -188,17 +189,17 @@ Dart ParticleCell2D<PFP>::faceOrientationState(const VEC3& toward)
Dart res = d ;
Dart dd = d ;
float wsoe = getOrientationFace(toward, this->getPosition(), m.phi1(res)) ;
float wsoe = getOrientationFace(toward, m.phi1(res)) ;
// orientation step
if (wsoe != Geom::RIGHT)
{
res = m.phi1(res) ;
wsoe = getOrientationFace(toward, this->getPosition(), m.phi1(res)) ;
wsoe = getOrientationFace(toward, m.phi1(res)) ;
while (wsoe != Geom::RIGHT && dd != res)
{
res = m.phi1(res) ;
wsoe = getOrientationFace(toward, this->getPosition(), m.phi1(res)) ;
wsoe = getOrientationFace(toward, m.phi1(res)) ;
}
// source and position to reach are the same : verify if no edge is crossed due to numerical approximation
......@@ -222,11 +223,11 @@ Dart ParticleCell2D<PFP>::faceOrientationState(const VEC3& toward)
}
else
{
wsoe = getOrientationFace(toward, this->getPosition(), d) ;
wsoe = getOrientationFace(toward, d) ;
while (wsoe == Geom::RIGHT && m.phi_1(res) != dd)
{
res = m.phi_1(res) ;
wsoe = getOrientationFace(toward, this->getPosition(), res) ;
wsoe = getOrientationFace(toward, res) ;
}
// in case of numerical incoherence
......@@ -266,17 +267,17 @@ void ParticleCell2D<PFP>::faceState(const VEC3& goal)
// assert(Algo::Geometry::isPointInConvexFace2D<PFP>(m,d,m_positions,m_position,true));
Dart dd = d ;
float wsoe = getOrientationFace(goal, this->getPosition(), m.phi1(d)) ;
float wsoe = getOrientationFace(goal, m.phi1(d)) ;
// orientation step
if (wsoe != Geom::RIGHT)
{
d = m.phi1(d) ;
wsoe = getOrientationFace(goal, this->getPosition(), m.phi1(d)) ;
wsoe = getOrientationFace(goal, m.phi1(d)) ;
while (wsoe != Geom::RIGHT && dd != d)
{
d = m.phi1(d) ;
wsoe = getOrientationFace(goal, this->getPosition(), m.phi1(d)) ;
wsoe = getOrientationFace(goal, m.phi1(d)) ;
}
// source and position to reach are the same : verify if no edge is crossed due to numerical approximation
......@@ -312,15 +313,15 @@ void ParticleCell2D<PFP>::faceState(const VEC3& goal)
return ;
}
// take the orientation with d1 : in case we are going through a vertex
wsoe = getOrientationFace(goal, this->getPosition(), d) ;
wsoe = getOrientationFace(goal, d) ;
}
else
{
wsoe = getOrientationFace(goal, this->getPosition(), d) ;
wsoe = getOrientationFace(goal, d) ;
while (wsoe == Geom::RIGHT && m.phi_1(d) != dd)
{
d = m.phi_1(d) ;
wsoe = getOrientationFace(goal, this->getPosition(), d) ;
wsoe = getOrientationFace(goal, d) ;
}
// in case of numerical incoherence
......
......@@ -26,19 +26,27 @@ class ParticleCell2DMemo : public ParticleCell2D<PFP>
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS ;
std::list<Dart> memo_cross ;
bool detect_vertex ;
bool detect_edge ;
bool detect_face ;
private:
ParticleCell2DMemo()
ParticleCell2DMemo() :
detect_vertex(false), detect_edge(false), detect_face(true)
{
}
public:
ParticleCell2DMemo(MAP& map, Dart belonging_cell, const VEC3& pos, const TAB_POS& tabPos,
DartMarker& obst) :
ParticleCell2D<PFP>(map, belonging_cell, pos, tabPos, obst)
ParticleCell2DMemo(MAP& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) :
ParticleCell2D<PFP>(map, belonging_cell, pos, tabPos),
detect_vertex(false),
detect_edge(false),
detect_face(true)
{
}
......@@ -52,7 +60,6 @@ public:
} ;
#include "particle_cell_2D_memo.hpp"
//namespace
}
......
template <typename PFP>
void ParticleCell2DMemo<PFP>::move(const VEC3& goal)
{
switch (this->getState())
this->crossCell = NO_CROSS ;
if (!Geom::arePointsEquals(goal, this->getPosition()))
{
case VERTEX :
vertexState(goal) ;
break ;
case EDGE :
edgeState(goal) ;
break ;
case FACE :
faceState(goal) ;
break ;
switch (this->getState())
{
case VERTEX :
vertexState(goal) ;
break ;
case EDGE :
edgeState(goal) ;
break ;
case FACE :
faceState(goal) ;
break ;
}
}
this->display() ;
else
this->ParticleBase<PFP>::move(goal) ;
}
template <typename PFP>
void ParticleCell2DMemo<PFP>::vertexState(const VEC3& current)
{
#ifdef DEBUG
CGoGNout << "vertexState" << this->d << CGoGNendl ;
CGoGNout << "vertexState" << d << CGoGNendl ;
#endif
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)
{
this->setState(VERTEX) ;
return ;
//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
{
this->ParticleBase<PFP>::move(current) ;
this->setState(VERTEX) ;
return ;
}
}
}
else
{
while (this->getOrientationEdge(current, this->d) == Geom::RIGHT)
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
memo_cross.push_back(this->d) ;
// if(!this->m.isMarked(this->d,this->obstacle)) {
if (this->getOrientationEdge(current, this->d) == Geom::ALIGNED)
if (detect_vertex) memo_cross.push_back(this->d) ;
if (this->getOrientationEdge(current, this->d) == Geom::ALIGNED
&& Algo::Geometry::isPointOnHalfEdge < PFP
> (this->m, this->d, this->positionAttribut, current))
edgeState(current) ;
else
{
this->d = this->m.phi1(this->d) ;
faceState(current) ;
}
}
// }
}
template <typename PFP>
void ParticleCell2DMemo<PFP>::edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge)
{
#ifdef DEBUG
CGoGNout << "edgeState" << this->d << CGoGNendl ;
CGoGNout << "edgeState" << d << CGoGNendl ;
#endif
memo_cross.push_back(this->d) ;
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<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 :
if (!this->obstacle.isMarked(this->d))
{
this->d = this->m.phi1(this->d) ;
faceState(current) ;
return ;
}
this->d = this->m.phi1(this->d) ;
faceState(current) ;
return ;
case Geom::RIGHT :
if (!this->obstacle.isMarked(this->m.phi2(this->d)))
{
this->d = this->m.phi1(this->m.phi2(this->d)) ;
faceState(current) ;
return ;
}
this->d = this->m.phi1(this->m.phi2(this->d)) ;
faceState(current) ;
return ;
default :
this->setState(EDGE) ;
}
if (!Algo::Geometry::isPointOnHalfEdge<PFP> (this->m, this->d, this->positionAttribut, current))
if (!Algo::Geometry::isPointOnHalfEdge < PFP
> (this->m, this->d, this->positionAttribut, current))
{
this->ParticleBase<PFP>::move(this->positionAttribut[this->d]) ;
vertexState(current) ;
return ;
}
else if (!Algo::Geometry::isPointOnHalfEdge<PFP> (this->m, this->m.phi2(this->d), this->positionAttribut, current))
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]) ;
......@@ -110,26 +152,37 @@ void ParticleCell2DMemo<PFP>::edgeState(const VEC3& current, Geom::Orientation2D
return ;
}
this->ParticleBase<PFP>::move(current) ;
}
template <typename PFP>
void ParticleCell2DMemo<PFP>::faceState(const VEC3& current)
{
#ifdef DEBUG
CGoGNout << "faceState" << this->d << CGoGNendl ;
CGoGNout << "faceState" << d << CGoGNendl ;
#endif
memo_cross.push_back(this->d) ;
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<PFP>(m,d,m_positions,m_position,true));
Dart dd = this->d ;
float wsoe = this->getOrientationFace(current, this->m.phi1(this->d)) ;
//orientation step
if (this->getOrientationFace(current, this->getPosition(), this->m.phi1(this->d)) != Geom::RIGHT)
// orientation step
if (wsoe != Geom::RIGHT)
{
this->d = this->m.phi1(this->d) ;
while (this->getOrientationFace(current, this->getPosition(), this->m.phi1(this->d)) != Geom::RIGHT
&& dd != this->d)
wsoe = this->getOrientationFace(current, this->m.phi1(this->d)) ;
while (wsoe != Geom::RIGHT && dd != this->d)
{
this->d = this->m.phi1(this->d) ;
wsoe = this->getOrientationFace(current, this->m.phi1(this->d)) ;
}
//source and position to reach are the same : verify if no edge is crossed this->due to numerical approximation
// source and position to reach are the same : verify if no edge is crossed due to numerical approximation
if (dd == this->d)
{
do
......@@ -143,28 +196,42 @@ void ParticleCell2DMemo<PFP>::faceState(const VEC3& current)
this->ParticleBase<PFP>::move(current) ;
edgeState(current) ;
return ;
default :
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<PFP>::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ;
if (!this->obstacle.isMarked(this->m.phi2(this->d)))
edgeState(current) ;
else
this->setState(EDGE) ;
// CGoGNout << " " << m_position << CGoGNendl;
edgeState(current, Geom::RIGHT) ;
return ;
}
} while (this->d != dd) ;
this->ParticleBase<PFP>::move(current) ;
this->ParticleBase<PFP>::move(current);
this->setState(FACE) ;
// m_position = Algo::Geometry::faceCentroid<PFP>(m,d,m_positions);
// d = m.phi1(d);
// m_position = pointInFace(d);
// faceState(current);
// m_position = m_positions[d];
// vertexState(current);
return ;
}
// take the orientation with d1 : in case we are going through a vertex
wsoe = this->getOrientationFace(current, this->d) ;
}
else
{
while (this->getOrientationFace(current, this->getPosition(), this->d) == Geom::RIGHT
&& this->m.phi_1(this->d) != dd)
wsoe = this->getOrientationFace(current, this->d) ;
while (wsoe == Geom::RIGHT && this->m.phi_1(this->d) != dd)
{
this->d = this->m.phi_1(this->d) ;
wsoe = this->getOrientationFace(current, this->d) ;
}
//in case of numerical incoherence
if (this->m.phi_1(this->d) == dd)
// in case of numerical incoherence
if (this->m.phi_1(this->d) == dd && wsoe == Geom::RIGHT)
{
this->d = this->m.phi_1(this->d) ;
do
......@@ -175,15 +242,15 @@ void ParticleCell2DMemo<PFP>::faceState(const VEC3& current)
this->d = this->m.phi1(this->d) ;
break ;
case Geom::ALIGNED :
// CGoGNout << "pic" << CGoGNendl;
this->ParticleBase<PFP>::move(current) ;
edgeState(current) ;
return ;
default :
case Geom::RIGHT :
// CGoGNout << "smthg went bad(2) " << m_position << CGoGNendl;
this->ParticleBase<PFP>::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ;
if (!this->obstacle.isMarked(this->m.phi2(this->d)))
edgeState(current) ;
else
this->setState(EDGE) ;
// CGoGNout << " " << m_position << CGoGNendl;
edgeState(current, Geom::RIGHT) ;
return ;
}
} while (this->d != dd) ;
......@@ -194,7 +261,7 @@ void ParticleCell2DMemo<PFP>::faceState(const VEC3& current)
}
}
//displacement step
//displacement step
switch (this->getOrientationEdge(current, this->d))
{
case Geom::LEFT :
......@@ -202,15 +269,30 @@ void ParticleCell2DMemo<PFP>::faceState(const VEC3& current)
this->setState(FACE) ;
;
break ;
case Geom::ALIGNED :
this->ParticleBase<PFP>::move(current) ;
this->setState(EDGE) ;
break ;
// case Geom::ALIGNED :
// if(wsoe==Geom::ALIGNED) {
// m_position = m_positions[d];
// vertexState(current);
// }
// else {
// CGoGNout << "poc" << CGoGNendl;
// m_position = current;
// state = EDGE;
// }
// break;
default :
this->ParticleBase<PFP>::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ;
if (!this->obstacle.isMarked(this->m.phi2(this->d)))
edgeState(current) ;
if (wsoe == Geom::ALIGNED)
{
this->d = this->m.phi1(this->d) ; //to check
this->ParticleBase<PFP>::move(this->positionAttribut[this->d]) ;
vertexState(current) ;
}
else
this->setState(EDGE) ;
{
this->ParticleBase<PFP>::move(this->intersectLineEdge(current, this->getPosition(), this->d)) ;
edgeState(current, Geom::RIGHT) ;
}
}
}
#ifndef PARTCELL2DANDHALFMEMO_H
#define PARTCELL2DANDHALFMEMO_H
#include "particle_cell_2DandHalf.h"
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
#include <iostream>
/* A particle cell is a particle base within a map, within a precise cell, the displacement function should indicate
after each displacement wherein lies the new position of the particle */
namespace CGoGN
{
namespace Algo
{
namespace MovingObjects
{
template <typename PFP>
class ParticleCell2DAndHalfMemo : public ParticleCell2DAndHalf<PFP>
{
public :
typedef typename PFP::MAP Map;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS;
std::list<Dart> memo_cross;
bool detect_vertex;
bool detect_edge;
bool detect_face;
ParticleCell2DAndHalfMemo() {};
ParticleCell2DAndHalfMemo(Map& map, Dart belonging_cell, VEC3 pos,const TAB_POS& tabPos) : ParticleCell2DAndHalf<PFP>(map,belonging_cell,pos,tabPos),detect_vertex(false),detect_edge(false),detect_face(true)
{
// memo_cross.push_back(this->d);
};
void vertexState(VEC3 current);
void edgeState(VEC3 current,Geom::Orientation3D sideOfEdge=Geom::ALIGNED);
void faceState(VEC3 current);
void move(const VEC3& newCurrent);
};
#include "particle_cell_2DandHalf_memo.hpp"
//namespace
}
}
}
#endif
//#define DEBUG
#include "Geometry/frame.h"
template <typename PFP>
void ParticleCell2DAndHalfMemo<PFP>::move(const VEC3& newCurrent)
{
this->distance=0;
this->crossCell = NO_CROSS ;
if(!Geom::arePointsEquals(newCurrent, this->m_position))
{
switch(this->state) {
case VERTEX : vertexState(newCurrent); break;
case EDGE : edgeState(newCurrent); break;
case FACE : faceState(newCurrent); break;
}
// display();
}
else
this->m_position = newCurrent;
// this->display();
}
template <typename PFP>
void ParticleCell2DAndHalfMemo<PFP>::vertexState(VEC3 current)
{
#ifdef DEBUG
CGoGNout << "vertexState" << d << CGoGNendl;
#endif
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));