env_map.h 4.28 KB
Newer Older
1 2
#ifndef ENV_MAP_H
#define ENV_MAP_H
Pierre Kraemer's avatar
Pierre Kraemer committed
3 4 5 6 7

#include <iostream>
#include <algorithm>

#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
update  
Pierre Kraemer committed
8
#include "Topology/map/embeddedMap2.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
9 10 11 12 13 14 15 16 17

#include "Algo/ImplicitHierarchicalMesh/ihm.h"
#include "Algo/ImplicitHierarchicalMesh/subdivision.h"

#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/extrusion.h"
#include "Algo/Modelisation/subdivision.h"
#include "Algo/Geometry/centroid.h"
#include "Algo/Geometry/area.h"
Thomas's avatar
Thomas committed
18
#include "Geometry/bounding_box.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
19 20 21 22 23 24 25 26

#include "Container/fakeAttribute.h"

#include "Algo/Parallel/parallel_foreach.h"

using namespace CGoGN;

class Agent;
Pierre Kraemer's avatar
Pierre Kraemer committed
27
class Obstacle;
Pierre Kraemer's avatar
Pierre Kraemer committed
28 29 30 31

struct PFP: public PFP_STANDARD
{
	// definition de la carte
Pierre Kraemer's avatar
update  
Pierre Kraemer committed
32
// 	typedef EmbeddedMap2 MAP;
Pierre Kraemer's avatar
Pierre Kraemer committed
33 34 35 36
 	typedef Algo::IHM::ImplicitHierarchicalMap MAP;

	// definition des listes d'agent
	typedef std::vector<Agent*> AGENTS;
Pierre Kraemer's avatar
Pierre Kraemer committed
37
	typedef std::vector<Obstacle*> OBSTACLES;
Pierre Kraemer's avatar
Pierre Kraemer committed
38 39 40 41
	typedef NoMathIONameAttribute<AGENTS> AGENTVECT;
	typedef NoMathIONameAttribute<OBSTACLES> OBSTACLEVECT;
	typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT;
	typedef AttributeHandler<OBSTACLEVECT> TAB_OBSTACLEVECT;
42 43

	typedef NoMathIONameAttribute<std::pair<bool,bool> > BOOLATTRIB;
Pierre Kraemer's avatar
Pierre Kraemer committed
44 45 46 47 48 49 50 51 52
};

typedef PFP::VEC3 VEC3;

class EnvMap
{
public :
	EnvMap();
	
53 54
	void markPedWay();

Pierre Kraemer's avatar
Pierre Kraemer committed
55
	unsigned int mapMemoryCost();
Thomas's avatar
Thomas committed
56 57
	void scale(float scaleVal);

Pierre Kraemer's avatar
Pierre Kraemer committed
58
	Dart getBelongingCell(const PFP::VEC3& pos);
Thomas's avatar
Thomas committed
59

Thomas's avatar
Thomas committed
60 61 62
	void subdivideAllToMaxLevel();
	void subdivideToProperLevel();

Thomas's avatar
Thomas committed
63
	void init(unsigned int config);
Pierre Kraemer's avatar
Pierre Kraemer committed
64
	
Pierre Kraemer's avatar
Pierre Kraemer committed
65 66
	void foreach_neighborFace(Dart d, FunctorType& f);

Pierre Kraemer's avatar
Pierre Kraemer committed
67 68 69
	void registerObstaclesInFaces();
	void addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor);
	
70 71 72 73
	void pushObstacleInCells(Obstacle* o, Dart d);
	void popObstacleInCells(Obstacle* o, Dart d);
	void obstacleChangeFace(Obstacle* agent, Dart newFace, Dart oldFace);

Pierre Kraemer's avatar
Pierre Kraemer committed
74 75
	void setAgentNeighborsAndObstacles(Agent* agent);
	
76
//	void agentChangeFaceThroughEdge(Agent* agent);
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78
	void agentChangeFace(Agent* agent, Dart oldFace);

Pierre Kraemer's avatar
Pierre Kraemer committed
79 80
	void pushAgentInCells(Agent* agent, Dart d);
	void popAgentInCells(Agent* agent, Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
81
	
82 83 84
	template <typename T>
	inline void removeElementFromVector(std::vector<T>& a, T ag);

Pierre Kraemer's avatar
Pierre Kraemer committed
85 86 87 88 89 90 91 92 93 94
	void clearUpdateCandidates();
	void updateMap();

	void resetAgentInFace(Agent* agent);
	
	PFP::MAP map;

	PFP::TVEC3 position;
	PFP::TVEC3 normal;

95 96 97 98 99 100
	PFP::MAP mapScenary;
	PFP::TVEC3 positionScenary;
	PFP::TVEC3 normalScenary;
	CellMarker obstacleMarkS;
	CellMarker buildingMarkS;

101 102
	AttributeHandler<PFP::BOOLATTRIB> subdivisableFace;

103 104
	std::vector<Dart> newBuildings;

Pierre Kraemer's avatar
Pierre Kraemer committed
105
	PFP::TAB_AGENTVECT agentvect;
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107
	PFP::TAB_AGENTVECT neighborAgentvect;
	
Pierre Kraemer's avatar
Pierre Kraemer committed
108 109 110 111
	PFP::TAB_OBSTACLEVECT obstvect;

	CellMarker obstacleMark;
	CellMarker buildingMark;
112
	CellMarker pedWayMark;
Pierre Kraemer's avatar
Pierre Kraemer committed
113

Pierre Kraemer's avatar
Pierre Kraemer committed
114 115
	static const unsigned int nbAgentsToSubdivide = 5;
	static const unsigned int nbAgentsToSimplify = 4;
Pierre Kraemer's avatar
Pierre Kraemer committed
116

117
	CellMarker refineMark;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
	CellMarker coarsenMark;
119
	std::vector<Dart> refineCandidate;
Pierre Kraemer's avatar
Pierre Kraemer committed
120
	std::vector<Dart> coarsenCandidate;
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122 123 124 125 126
};

/**************************************
*           INLINE FUNCTIONS          *
**************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
127
inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
128 129 130 131 132
{
	assert(map.getCurrentLevel() == map.getMaxLevel());
	assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) == agentvect[d].end());
	
	agentvect[d].push_back(agent);
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134 135 136 137 138 139 140 141 142 143 144

	Dart dd = d;
	do
	{
		Dart ddd = map.alpha1(map.alpha1(dd));
		while(ddd != dd)
		{
			neighborAgentvect[ddd].push_back(agent);
			ddd = map.alpha1(ddd);
		}
		dd = map.phi1(dd);
	} while(dd != d);
Pierre Kraemer's avatar
Pierre Kraemer committed
145 146
}

Thomas's avatar
Thomas committed
147 148 149 150 151
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
{
	assert(map.getCurrentLevel() == map.getMaxLevel());
	assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());

152
	removeElementFromVector<Agent* >(agentvect[d], agent);
Pierre Kraemer's avatar
Pierre Kraemer committed
153 154 155 156 157 158 159

	Dart dd = d;
	do
	{
		Dart ddd = map.alpha1(map.alpha1(dd));
		while(ddd != dd)
		{
160
			removeElementFromVector<Agent* >(neighborAgentvect[ddd], agent);
Pierre Kraemer's avatar
Pierre Kraemer committed
161 162 163 164
			ddd = map.alpha1(ddd);
		}
		dd = map.phi1(dd);
	} while(dd != d);
Pierre Kraemer's avatar
Pierre Kraemer committed
165 166
}

167 168
template <typename T>
inline void EnvMap::removeElementFromVector(std::vector<T>& a, T ag)
169
{
170 171
	typename std::vector<T>::iterator end = a.template end();
	for(typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
172 173 174 175 176 177 178 179 180 181
	{
		if(*it == ag)
		{
			*it = a.back();
			a.pop_back();
			return;
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
182 183 184
inline void EnvMap::clearUpdateCandidates()
{
	refineCandidate.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
185
	coarsenCandidate.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
186 187 188
}

#endif