Commit 773d5647 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'master' of cgogn:~cazier/CGoGN

Conflicts:
	Apps/deprecated/tutoriel.cpp
	include/Topology/generic/dartmarker.h
parents 42cca519 58dd1c2f
This diff is collapsed.
......@@ -27,7 +27,7 @@
#include <iostream>
#include "Utils/qtSimple.h"
#include "Utils/Qt/qtSimple.h"
// forward definitions (minimize includes)
namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; } } } }
......
#ifndef PARTBASE_H
#define PARTBASE_H
#include "Geometry/vector_gen.h"
//#include "Geometry/vector_gen.h"
namespace CGoGN
{
......@@ -12,41 +12,42 @@ namespace Algo
namespace MovingObjects
{
typedef Geom::Vec3f VEC3;
/* A particle base defines a position with a displacement function */
template <typename PFP>
class ParticleBase
{
public :
VEC3 m_position;
private:
typename PFP::VEC3 m_position ;
unsigned int m_state ;
ParticleBase()
public:
ParticleBase(const typename PFP::VEC3& position) :
m_position(position), m_state(FACE)
{
m_position.zero();
}
ParticleBase(VEC3 position)
void setState(unsigned int state)
{
m_position = position;
m_state = state ;
}
virtual unsigned int getState()
unsigned int getState()
{
return 0;
return m_state ;
}
/**
* @param newPosition new position to reach
*/
virtual bool move(VEC3 position)
bool move(const typename PFP::VEC3& position)
{
m_position = position;
return true;
m_position = position ;
return true ;
}
VEC3 getPosition() { return m_position; }
};
const typename PFP::VEC3& getPosition() const
{
return m_position ;
}
} ;
} // namespace MovingObjects
......
......@@ -2,14 +2,14 @@
#define PARTCELL_H
#include "Algo/MovingObjects/particle_base.h"
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
#include <iostream>
#include "Algo/Geometry/orientation.h"
/* 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 */
/* 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
{
......@@ -20,84 +20,92 @@ namespace Algo
namespace MovingObjects
{
enum {
NO_CROSS,
CROSS_EDGE,
CROSS_OTHER
};
enum
{
NO_CROSS, CROSS_EDGE, CROSS_OTHER
} ;
template <typename PFP>
class ParticleCell2D : public ParticleBase
class ParticleCell2D : public ParticleBase<PFP>
{
public :
typedef typename PFP::MAP Map;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS;
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3 ;
typedef VertexAttribute<VEC3> TAB_POS ;
Map& m;
MAP& m ;
const TAB_POS& m_positions;
Dart d;
Dart lastCrossed;
const TAB_POS& positionAttribut ;
unsigned int state;
Dart d ;
Dart lastCrossed ;
unsigned int crossCell ;
ParticleCell2D(Map& map) : m(map)
{}
ParticleCell2D(Map& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) :
ParticleBase(pos), m(map), m_positions(tabPos), d(belonging_cell), lastCrossed(belonging_cell), state(FACE), crossCell(NO_CROSS)
{}
ParticleCell2D(MAP& map, Dart belonging_cell, const VEC3& pos, const TAB_POS& tabPos) :
ParticleBase<PFP>(pos),
m(map),
positionAttribut(tabPos),
d(belonging_cell),
lastCrossed(belonging_cell),
crossCell(NO_CROSS)
{
}
Dart getCell() { return d; }
Dart getCell()
{
return d ;
}
Geom::Orientation2D getOrientationEdge(const VEC3& point, Dart d);
Geom::Orientation2D getOrientationEdge(const VEC3& point, Dart d) ;
void display();
void display() ;
// template <unsigned int DD, typename TT>
// friend std::istream& operator>> (std::istream& in, Vector<DD,TT>& v) ;
VEC3 pointInFace(Dart d);
VEC3 pointInFace(Dart d) ;
VEC3 intersectLineEdge(const VEC3& pA, const VEC3& pB, Dart d);
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);
void vertexState(const VEC3& current) ;
void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge=Geom::ALIGNED);
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);
Dart faceOrientationState(const VEC3& toward) ;
virtual unsigned int getState()
{
return state;
}
void faceState(const VEC3& current) ;
void move(const VEC3& newCurrent)
void move(const VEC3& goal)
{
crossCell = NO_CROSS ;
if(!Geom::arePointsEquals(newCurrent, m_position))
if (!Geom::arePointsEquals(goal, this->getPosition()))
{
switch(state) {
case VERTEX : vertexState(newCurrent); break;
case EDGE : edgeState(newCurrent); break;
case FACE : faceState(newCurrent); break;
switch (this->getState())
{
case VERTEX :
vertexState(goal) ;
break ;
case EDGE :
edgeState(goal) ;
break ;
case FACE :
faceState(goal) ;
break ;
}
display();
display() ;
}
else
m_position = newCurrent;
{
// TODO Des petits pas répétés peuvent faire sortir de la cellule actuelle
this->ParticleBase<PFP>::move(goal) ;
}
}
};
} ;
#include "particle_cell_2D.hpp"
......
......@@ -9,7 +9,7 @@
#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 */
after each displacement wherein lies the new position of the particle */
namespace CGoGN
{
......@@ -24,29 +24,42 @@ template <typename PFP>
class ParticleCell2DMemo : public ParticleCell2D<PFP>
{
public :
typedef typename PFP::MAP Map;
public:
typedef typename PFP::MAP MAP ;
typedef typename PFP::VEC3 VEC3;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS;
typedef VertexAttribute<typename PFP::VEC3> TAB_POS ;
std::list<Dart> memo_cross;
std::list<Dart> memo_cross ;
bool detect_vertex ;
bool detect_edge ;
bool detect_face ;
ParticleCell2DMemo() {};
private:
ParticleCell2DMemo() :
detect_vertex(false), detect_edge(false), detect_face(true)
{
}
ParticleCell2DMemo(Map& map, Dart belonging_cell, VEC3 pos, TAB_POS tabPos, DartMarker& obst) : ParticleCell2D<PFP>(map,belonging_cell,pos,tabPos,obst)
{};
public:
void vertexState(const VEC3& current);
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)
{
}
void edgeState(const VEC3& current,Geom::Orientation2D sideOfEdge=Geom::ALIGNED);
void vertexState(const VEC3& current) ;
void faceState(const VEC3& current);
void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
void move(const VEC3& newCurrent);
};
void faceState(const VEC3& current) ;
void move(const VEC3& goal) ;
} ;
#include "particle_cell_2D_memo.hpp"
//namespace
}
......
......@@ -82,19 +82,19 @@ Geom::Orientation3D ParticleCell2DAndHalf<PFP>::getOrientationFace(VEC3 point, V
}
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 goal)
{
#ifdef DEBUG
CGoGNout << "vertexState" << d << CGoGNendl;
#endif
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
assert(gola.isfinite()) ;
crossCell = CROSS_OTHER;
if(Algo::Geometry::isPointOnVertex<PFP>(m,d,m_positions,current))
if(Algo::Geometry::isPointOnVertex<PFP>(m,d,m_positions,goal))
{
state = VERTEX;
m_position = current;
m_position = goal;
return;
}
else
......@@ -122,7 +122,7 @@ void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
}
else
{
m_position = current;
m_position = goal;
state = VERTEX;
return;
}
......@@ -140,24 +140,24 @@ void ParticleCell2DAndHalf<PFP>::vertexState(VEC3 current)
}
//displacement step
if(getOrientationEdge(current, d) == Geom::ON && Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, current))
edgeState(current);
if(getOrientationEdge(goal, d) == Geom::ON && Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, goal))
edgeState(goal);
else
{
d = m.phi1(d);
faceState(current);
faceState(goal);
}
}
}
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sideOfEdge)
void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 goal, Geom::Orientation3D sideOfEdge)
{
#ifdef DEBUG
CGoGNout << "edgeState" << d << CGoGNendl;
#endif
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
assert(goal.isfinite()) ;
// assert(Algo::Geometry::isPointOnEdge<PFP>(m,d,m_positions,m_position));
if(crossCell == NO_CROSS)
......@@ -169,21 +169,21 @@ void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sid
crossCell = CROSS_OTHER;
if(sideOfEdge == Geom::ON)
sideOfEdge = getOrientationEdge(current, d);
sideOfEdge = getOrientationEdge(goal, d);
switch(sideOfEdge)
{
case Geom::UNDER :
{
d = m.phi1(d);
faceState(current);
faceState(goal);
return;
}
case Geom::OVER:
{
//transform the displacement into the new entered face
VEC3 displ = current - m_position;
VEC3 displ = goal - m_position;
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m, d, m_positions);
VEC3 n2 = Algo::Geometry::faceNormal<PFP>(m, m.phi2(d), m_positions);
......@@ -192,10 +192,10 @@ void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sid
float angle = Geom::angle(n1, n2) ;
displ = Geom::rotate(axis, angle, displ) ;
current = m_position + displ;
goal = m_position + displ;
d = m.phi1(m.phi2(d));
faceState(current);
faceState(goal);
return;
}
......@@ -203,35 +203,35 @@ void ParticleCell2DAndHalf<PFP>::edgeState(VEC3 current, Geom::Orientation3D sid
state = EDGE;
}
if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, current))
if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, d, m_positions, goal))
{
m_position = m_positions[d];
vertexState(current);
vertexState(goal);
return;
}
else if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, m.phi2(d), m_positions, current))
else if(!Algo::Geometry::isPointOnHalfEdge<PFP>(m, m.phi2(d), m_positions, goal))
{
d = m.phi2(d);
m_position = m_positions[d];
vertexState(current);
vertexState(goal);
return;
}
m_position = current;
m_position = goal;
}
template <typename PFP>
void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
void ParticleCell2DAndHalf<PFP>::faceState(VEC3 goal)
{
#ifdef DEBUG
CGoGNout << "faceState" << d << CGoGNendl;
#endif
assert(std::isfinite(m_position[0]) && std::isfinite(m_position[1]) && std::isfinite(m_position[2]));
assert(std::isfinite(current[0]) && std::isfinite(current[1]) && std::isfinite(current[2]));
assert(goal.isfinite()) ;
assert(this->getPosition().isFinite()) ;
// assert(Algo::Geometry::isPointInConvexFace2D<PFP>(m,d,m_positions,m_position,true));
//project current within face plane
//project goal within face plane
VEC3 n1 = Algo::Geometry::faceNormal<PFP>(m,d,m_positions);
VEC3 n2 = current - m_position;
// n1.normalize();
......@@ -242,17 +242,17 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
//track new position within map
Dart dd = d;
float wsoe = getOrientationFace(current, m_position, m.phi1(d));
float wsoe = getOrientationFace(goal, m_position, m.phi1(d));
// orientation step
if(wsoe != Geom::UNDER)
{
d = m.phi1(d);
wsoe = getOrientationFace(current, m_position, m.phi1(d));
wsoe = getOrientationFace(goal, m_position, m.phi1(d));
while(wsoe != Geom::UNDER && dd != d)
{
d = m.phi1(d);
wsoe = getOrientationFace(current, m_position, m.phi1(d));
wsoe = getOrientationFace(goal, m_position, m.phi1(d));
}
// source and position to reach are the same : verify if no edge is crossed due to numerical approximation
......@@ -260,15 +260,15 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
{
do
{
switch (getOrientationEdge(current, d))
switch (getOrientationEdge(goal, d))
{
case Geom::UNDER: d = m.phi1(d);
break;
case Geom::ON: m_position = current;
edgeState(current);
edgeState(goal);
return;
case Geom::OVER:
// CGoGNout << "smthg went bad " << m_position << " " << current << CGoGNendl;
// CGoGNout << "smthg went bad " << m_position << " " << goal << CGoGNendl;
// CGoGNout << "d1 " << m_positions[d] << " d2 " << m_positions[m.phi1(d)] << CGoGNendl;
m_position = intersectLineEdge(current, m_position, d);
// CGoGNout << " " << m_position << CGoGNendl;
......@@ -277,13 +277,13 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
return;
}
} while(d != dd);
m_position = current;
m_position = goal;
state = FACE;
// m_position = Algo::Geometry::faceCentroid<PFP>(m,d,m_positions);
// d = m.phi1(d);
// m_position = pointInFace(d);
// faceState(current);
// faceState(goal);
// m_position = m_positions[d];
// vertexState(current);
......@@ -294,11 +294,11 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
}
else
{
wsoe = getOrientationFace(current,m_position,d);
wsoe = getOrientationFace(goal,m_position,d);
while(wsoe == Geom::UNDER && m.phi_1(d) != dd)
{
d = m.phi_1(d);
wsoe = getOrientationFace(current, m_position, d);
wsoe = getOrientationFace(goal, m_position, d);
}
// in case of numerical incoherence
......@@ -307,37 +307,37 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
d = m.phi_1(d);
do
{
switch (getOrientationEdge(current, d))
switch (getOrientationEdge(goal, d))
{
case Geom::UNDER :
d = m.phi1(d);
break;
case Geom::ON :
// CGoGNout << "pic" << CGoGNendl;
m_position = current;
edgeState(current);
m_position = goal;
edgeState(goal);
return;
case Geom::OVER:
// CGoGNout << "smthg went bad(2) " << m_position << CGoGNendl;
m_position = intersectLineEdge(current, m_position, d);
m_position = intersectLineEdge(goal, m_position, d);
// CGoGNout << " " << m_position << CGoGNendl;
edgeState(current, Geom::OVER);
return;
}
} while(d != dd);
m_position = current;
m_position = goal;
state = FACE;
return;
}
}
//displacement step
switch (getOrientationEdge(current, d))
switch (getOrientationEdge(goal, d))
{
case Geom::UNDER :
distance += (current - m_position).norm();
m_position = current;
distance += (goal - m_position).norm();
m_position = goal;
state = FACE;
break;
default :
......@@ -347,7 +347,7 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
// d = m.phi1(d); //to check
// m_position = m_positions[d];
//
// vertexState(current);
// vertexState(goal);
}
else
{
......@@ -358,7 +358,7 @@ void ParticleCell2DAndHalf<PFP>::faceState(VEC3 current)
distance += (isect - m_position).norm();
m_position = isect;
// CGoGNout << " inter : " << m_position << CGoGNendl;
edgeState(current, Geom::OVER);
edgeState(goal, Geom::OVER);
}
}
}
......
#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(