particle_cell_2D.cpp 2.52 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
#ifndef PARTCELL_H
#define PARTCELL_H

#include "Algo/MovingObjects/particle_base.h"
#include "Algo/Geometry/inclusion.h"
#include "Geometry/intersection.h"
#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
 */

namespace CGoGN
{

namespace Algo
{

namespace Surface
{

namespace MovingObjects
{

#ifndef PARTCELL25D_H
enum
{
	NO_CROSS, CROSS_EDGE, CROSS_OTHER
} ;
#endif

template <typename PFP>
class ParticleCell2D : public Algo::MovingObjects::ParticleBase<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef VertexAttribute<VEC3, MAP> TAB_POS ;

	MAP& m ;

	const TAB_POS& positionAttribut ;

	Dart d ;
	Dart lastCrossed ;

	unsigned int crossCell ;

	ParticleCell2D(MAP& map, Dart belonging_cell, const VEC3& pos, const TAB_POS& tabPos) :
		Algo::MovingObjects::ParticleBase<PFP>(pos),
		m(map),
		positionAttribut(tabPos),
		d(belonging_cell),
		lastCrossed(belonging_cell),
		crossCell(NO_CROSS)
	{
	}

	~ParticleCell2D()
	{
	}

	Dart getCell()
	{
		return d ;
	}

	Geom::Orientation2D getOrientationEdge(const VEC3& point, Dart d) ;

	void display() ;

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

	VEC3 pointInFace(Dart d) ;

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

	Geom::Orientation2D getOrientationFace(VEC3 sourcePoint, Dart d) ;

	virtual void vertexState(const VEC3& current) ;

	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) ;

	virtual void faceState(const VEC3& current) ;

	void move(const VEC3& goal)
	{
		crossCell = NO_CROSS ;
		if (!Geom::arePointsEquals(goal, this->getPosition()))
		{
			switch (this->getState())
			{
				case VERTEX :
					vertexState(goal) ;
					break ;
				case EDGE :
					edgeState(goal) ;
					break ;
				case FACE :
					faceState(goal) ;
					break ;
			}

			display() ;
		}
		else
		{
			// TODO Des petits pas répétés peuvent faire sortir de la cellule actuelle
			this->Algo::MovingObjects::ParticleBase<PFP>::move(goal) ;
		}
	}
} ;

} // namespace MovingObjects

} // namespace Surface

} // namespace Algo

} // namespace CGoGN

#include "Algo/MovingObjects/particle_cell_2D.hpp"

#endif