particle_cell_2DandHalf.cpp 2.35 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
#ifndef PARTCELL25D_H
#define PARTCELL25D_H

#include "Algo/MovingObjects/particle_base.h"

#include "Algo/Geometry/inclusion.h"
#include "Algo/Geometry/plane.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 Surface
{

namespace MovingObjects
{

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

template <typename PFP>
class ParticleCell2DAndHalf : 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& m_positions;

	Dart d;
	Dart lastCrossed;

	unsigned int state;

	unsigned int crossCell ;

	float distance;

	ParticleCell2DAndHalf(MAP& map) : m(map)
	{}

	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)
	{}

	Dart getCell() { return d; }

	float getDistance() { return distance; }

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

	void edgeState(VEC3 current, Geom::Orientation3D sideOfEdge = Geom::ON);

	void faceState(VEC3 current);

	virtual unsigned int getState()
	{
		return state;
	}

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

//			display();
		}
		else
			this->Algo::MovingObjects::ParticleBase<PFP>::move(newCurrent);
	}
};

} // namespace MovingObjects

} // namespace Surface

} // namespace Algo

} // namespace CGoGN

#include "Algo/MovingObjects/particle_cell_2DandHalf.hpp"

#endif