particle_cell_2DandHalf.h 2.35 KB
Newer Older
1 2
#ifndef PARTCELL25D_H
#define PARTCELL25D_H
Thomas's avatar
Thomas committed
3

Pierre Kraemer's avatar
Pierre Kraemer committed
4
#include "Algo/MovingObjects/particle_base.h"
Thomas's avatar
Thomas committed
5 6

#include "Algo/Geometry/inclusion.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
7
#include "Algo/Geometry/plane.h"
Thomas's avatar
Thomas committed
8 9
#include "Geometry/intersection.h"
#include "Geometry/orientation.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
10

Thomas's avatar
Thomas committed
11 12 13 14 15 16 17 18 19 20 21
#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
{

22 23 24
namespace Surface
{

Thomas's avatar
Thomas committed
25 26 27
namespace MovingObjects
{

28
#ifndef PARTCELL_H
Pierre Kraemer's avatar
Pierre Kraemer committed
29 30
enum
{
Thomas's avatar
Thomas committed
31 32 33 34
	NO_CROSS,
	CROSS_EDGE,
	CROSS_OTHER
};
35
#endif
Thomas's avatar
Thomas committed
36 37

template <typename PFP>
38
class ParticleCell2DAndHalf : public Algo::MovingObjects::ParticleBase<PFP>
Thomas's avatar
Thomas committed
39 40
{
public :
Pierre Kraemer's avatar
Pierre Kraemer committed
41
	typedef typename PFP::MAP MAP;
Thomas's avatar
Thomas committed
42
	typedef typename PFP::VEC3 VEC3;
43
	typedef VertexAttribute<VEC3, MAP> TAB_POS;
Thomas's avatar
Thomas committed
44

Pierre Kraemer's avatar
Pierre Kraemer committed
45
	MAP& m;
Thomas's avatar
Thomas committed
46 47 48 49 50 51 52 53 54 55

	const TAB_POS& m_positions;

	Dart d;
	Dart lastCrossed;

	unsigned int state;

	unsigned int crossCell ;

Pierre Kraemer's avatar
Pierre Kraemer committed
56 57
	float distance;

Pierre Kraemer's avatar
Pierre Kraemer committed
58
	ParticleCell2DAndHalf(MAP& map) : m(map)
Thomas's avatar
Thomas committed
59 60
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63 64 65 66 67 68 69
	ParticleCell2DAndHalf(MAP& map, Dart belonging_cell, VEC3 pos, const TAB_POS& tabPos) :
		Algo::MovingObjects::ParticleBase<PFP>(pos),
		m(map),
		m_positions(tabPos),
		d(belonging_cell),
		lastCrossed(belonging_cell),
		state(FACE),
		crossCell(NO_CROSS),
		distance(0)
Thomas's avatar
Thomas committed
70 71 72 73
	{}

	Dart getCell() { return d; }

Pierre Kraemer's avatar
Pierre Kraemer committed
74 75
	float getDistance() { return distance; }

Thomas's avatar
Thomas committed
76 77 78 79 80 81 82 83 84 85 86 87
	Geom::Orientation3D getOrientationEdge(const VEC3& point, Dart d);

	void display();

	VEC3 pointInFace(Dart d);

	VEC3 intersectLineEdge(const VEC3& pA, const VEC3& pB, Dart d);

	Geom::Orientation3D getOrientationFace(VEC3 sourcePoint, VEC3 point, Dart d);

	void vertexState(VEC3 current);

Pierre Kraemer's avatar
Pierre Kraemer committed
88
	void edgeState(VEC3 current, Geom::Orientation3D sideOfEdge = Geom::ON);
Thomas's avatar
Thomas committed
89 90 91

	void faceState(VEC3 current);

Thomas's avatar
Thomas committed
92 93 94 95 96
	virtual unsigned int getState()
	{
		return state;
	}

Thomas's avatar
Thomas committed
97 98
	void move(const VEC3& newCurrent)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
99
		distance = 0 ;
Thomas's avatar
Thomas committed
100
		crossCell = NO_CROSS ;
101
		if(!Geom::arePointsEquals(newCurrent, this->getPosition()))
Thomas's avatar
Thomas committed
102 103
		{
			switch(state) {
Pierre Kraemer's avatar
Pierre Kraemer committed
104 105 106
				case VERTEX : 	vertexState(newCurrent); break;
				case EDGE : 	edgeState(newCurrent);   break;
				case FACE : 	faceState(newCurrent);   break;
Thomas's avatar
Thomas committed
107 108
			}

Pierre Kraemer's avatar
Pierre Kraemer committed
109
//			display();
Thomas's avatar
Thomas committed
110 111
		}
		else
112
			this->Algo::MovingObjects::ParticleBase<PFP>::move(newCurrent);
Thomas's avatar
Thomas committed
113 114 115
	}
};

Pierre Kraemer's avatar
Pierre Kraemer committed
116
} // namespace MovingObjects
Thomas's avatar
Thomas committed
117

Pierre Kraemer's avatar
Pierre Kraemer committed
118
} // namespace Surface
119

Pierre Kraemer's avatar
Pierre Kraemer committed
120
} // namespace Algo
Thomas's avatar
Thomas committed
121

Pierre Kraemer's avatar
Pierre Kraemer committed
122
} // namespace CGoGN
Thomas's avatar
Thomas committed
123

Pierre Kraemer's avatar
Pierre Kraemer committed
124
#include "Algo/MovingObjects/particle_cell_2DandHalf.hpp"
Thomas's avatar
Thomas committed
125 126

#endif