particle_cell_2D.h 2.3 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
#ifndef PARTCELL_H
#define PARTCELL_H

4
#include "Algo/MovingObjects/particle_base.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
David Cazier's avatar
-  
David Cazier committed
7 8 9 10 11 12
#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
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
13 14 15 16 17 18 19

namespace CGoGN
{

namespace Algo
{

20 21 22
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
23 24 25
namespace MovingObjects
{

David Cazier's avatar
-  
David Cazier committed
26 27 28 29
enum
{
	NO_CROSS, CROSS_EDGE, CROSS_OTHER
} ;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
30

Pierre Kraemer's avatar
Pierre Kraemer committed
31
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
32
class ParticleCell2D : public ParticleBase<PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
33
{
David Cazier's avatar
-  
David Cazier committed
34
public:
David Cazier's avatar
David Cazier committed
35 36 37
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef VertexAttribute<VEC3> TAB_POS ;
Pierre Kraemer's avatar
Pierre Kraemer committed
38

David Cazier's avatar
David Cazier committed
39
	MAP& m ;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
40

David Cazier's avatar
-  
David Cazier committed
41
	const TAB_POS& positionAttribut ;
Pierre Kraemer's avatar
Pierre Kraemer committed
42

David Cazier's avatar
-  
David Cazier committed
43 44
	Dart d ;
	Dart lastCrossed ;
Pierre Kraemer's avatar
Pierre Kraemer committed
45

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
46
	unsigned int crossCell ;
Pierre Kraemer's avatar
Pierre Kraemer committed
47

David Cazier's avatar
David Cazier committed
48
	ParticleCell2D(MAP& map, Dart belonging_cell, const VEC3& pos, const TAB_POS& tabPos) :
David Cazier's avatar
-  
David Cazier committed
49 50 51 52 53 54 55 56
		ParticleBase<PFP>(pos),
		m(map),
		positionAttribut(tabPos),
		d(belonging_cell),
		lastCrossed(belonging_cell),
		crossCell(NO_CROSS)
	{
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
57

David Cazier's avatar
-  
David Cazier committed
58 59 60 61
	Dart getCell()
	{
		return d ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
62

David Cazier's avatar
-  
David Cazier committed
63
	Geom::Orientation2D getOrientationEdge(const VEC3& point, Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

David Cazier's avatar
-  
David Cazier committed
65
	void display() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67 68 69

// 	template <unsigned int DD, typename TT>
// 	friend std::istream& operator>> (std::istream& in, Vector<DD,TT>& v) ;

David Cazier's avatar
-  
David Cazier committed
70
	VEC3 pointInFace(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
71

David Cazier's avatar
-  
David Cazier committed
72
	VEC3 intersectLineEdge(const VEC3& pA, const VEC3& pB, Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
73

David Cazier's avatar
David Cazier committed
74
	Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
75

76
	virtual void vertexState(const VEC3& current) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
77

78
	virtual void edgeState(const VEC3& current, Geom::Orientation2D sideOfEdge = Geom::ALIGNED) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
79

80
	//just an orientation test : check which dart is aimed to leave the current face to reach an other position
David Cazier's avatar
-  
David Cazier committed
81
	Dart faceOrientationState(const VEC3& toward) ;
82

83
	virtual void faceState(const VEC3& current) ;
Thomas's avatar
Thomas committed
84

David Cazier's avatar
-  
David Cazier committed
85
	void move(const VEC3& goal)
Pierre Kraemer's avatar
Pierre Kraemer committed
86
	{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
87
		crossCell = NO_CROSS ;
David Cazier's avatar
-  
David Cazier committed
88
		if (!Geom::arePointsEquals(goal, this->getPosition()))
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
89
		{
David Cazier's avatar
-  
David Cazier committed
90 91 92 93 94 95 96 97 98 99 100
			switch (this->getState())
			{
				case VERTEX :
					vertexState(goal) ;
					break ;
				case EDGE :
					edgeState(goal) ;
					break ;
				case FACE :
					faceState(goal) ;
					break ;
101
			}
102

David Cazier's avatar
-  
David Cazier committed
103
			display() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
104
		}
Thomas's avatar
Thomas committed
105
		else
David Cazier's avatar
David Cazier committed
106 107
		{
			// TODO Des petits pas répétés peuvent faire sortir de la cellule actuelle
David Cazier's avatar
-  
David Cazier committed
108
			this->ParticleBase<PFP>::move(goal) ;
David Cazier's avatar
David Cazier committed
109
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
110
	}
David Cazier's avatar
-  
David Cazier committed
111
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113 114 115

}
}
}
116 117 118
}

#include "particle_cell_2D.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120

#endif