Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

env_map.h 4.32 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

#include "Container/fakeAttribute.h"

#include "Algo/Parallel/parallel_foreach.h"

David Cazier's avatar
David Cazier committed
24
using namespace CGoGN ;
Pierre Kraemer's avatar
Pierre Kraemer committed
25

David Cazier's avatar
David Cazier committed
26
27
class Agent ;
class Obstacle ;
Pierre Kraemer's avatar
Pierre Kraemer committed
28

David Cazier's avatar
David Cazier committed
29
struct PFP : public PFP_STANDARD
Pierre Kraemer's avatar
Pierre Kraemer committed
30
31
{
	// definition de la carte
David Cazier's avatar
David Cazier committed
32
	typedef Algo::IHM::ImplicitHierarchicalMap MAP ;
Pierre Kraemer's avatar
Pierre Kraemer committed
33
34

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

David Cazier's avatar
David Cazier committed
42
43
	typedef NoMathIONameAttribute<std::pair<bool, bool> > BOOLATTRIB ;
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44

David Cazier's avatar
David Cazier committed
45
typedef PFP::VEC3 VEC3 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48

class EnvMap
{
David Cazier's avatar
David Cazier committed
49
50
	public:
	EnvMap() ;
51

David Cazier's avatar
David Cazier committed
52
	void markPedWay() ;
Thomas's avatar
Thomas committed
53

David Cazier's avatar
David Cazier committed
54
55
	unsigned int mapMemoryCost() ;
	void scale(float scaleVal) ;
Thomas's avatar
Thomas committed
56

David Cazier's avatar
David Cazier committed
57
	Dart getBelongingCell(const PFP::VEC3& pos) ;
Thomas's avatar
Thomas committed
58

David Cazier's avatar
David Cazier committed
59
60
	void subdivideAllToMaxLevel() ;
	void subdivideToProperLevel() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
61

David Cazier's avatar
David Cazier committed
62
63
64
65
66
67
68
69
70
71
72
73
	void init(unsigned int config) ;

	void foreach_neighborFace(Dart d, FunctorType& f) ;

	void registerObstaclesInFaces() ;
	void addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor) ;

	void pushObstacleInCells(Obstacle* o, Dart d) ;
	void popObstacleInCells(Obstacle* o, Dart d) ;
	void obstacleChangeFace(Obstacle* agent, Dart newFace, Dart oldFace) ;

	void setAgentNeighborsAndObstacles(Agent* agent) ;
74

75
//	void agentChangeFaceThroughEdge(Agent* agent);
David Cazier's avatar
David Cazier committed
76
77
78
79
80
81
82
	void agentChangeFace(Agent* agent, Dart oldFace) ;

	void pushAgentInCells(Agent* agent, Dart d) ;
	void popAgentInCells(Agent* agent, Dart d) ;

	template<typename T>
	inline void removeElementFromVector(std::vector<T>& a, T ag) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
83

David Cazier's avatar
David Cazier committed
84
85
	void clearUpdateCandidates() ;
	void updateMap() ;
86

David Cazier's avatar
David Cazier committed
87
	void resetAgentInFace(Agent* agent) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
88

David Cazier's avatar
David Cazier committed
89
	PFP::MAP map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
90

David Cazier's avatar
David Cazier committed
91
92
	PFP::TVEC3 position ;
	PFP::TVEC3 normal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93

David Cazier's avatar
David Cazier committed
94
95
96
97
98
	PFP::MAP mapScenary ;
	PFP::TVEC3 positionScenary ;
	PFP::TVEC3 normalScenary ;
	CellMarker obstacleMarkS ;
	CellMarker buildingMarkS ;
99

David Cazier's avatar
David Cazier committed
100
	AttributeHandler<PFP::BOOLATTRIB> subdivisableFace ;
101

David Cazier's avatar
David Cazier committed
102
	std::vector<Dart> newBuildings ;
103

David Cazier's avatar
David Cazier committed
104
105
	PFP::TAB_AGENTVECT agentvect ;
	PFP::TAB_AGENTVECT neighborAgentvect ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106

David Cazier's avatar
David Cazier committed
107
	PFP::TAB_OBSTACLEVECT obstvect ;
Pierre Kraemer's avatar
Pierre Kraemer committed
108

David Cazier's avatar
David Cazier committed
109
110
111
	CellMarker obstacleMark ;
	CellMarker buildingMark ;
	CellMarker pedWayMark ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112

David Cazier's avatar
David Cazier committed
113
114
115
116
117
118
119
120
	static const unsigned int nbAgentsToSubdivide = 5 ;
	static const unsigned int nbAgentsToSimplify = 4 ;

	CellMarker refineMark ;
	CellMarker coarsenMark ;
	std::vector<Dart> refineCandidate ;
	std::vector<Dart> coarsenCandidate ;
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
121
122

/**************************************
David Cazier's avatar
David Cazier committed
123
124
 *           INLINE FUNCTIONS          *
 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
125

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

	agentvect[d].push_back(agent) ;

	Dart dd = d ;
	do {
		Dart ddd = map.alpha1(map.alpha1(dd)) ;
		while (ddd != dd) {
			neighborAgentvect[ddd].push_back(agent) ;
			ddd = map.alpha1(ddd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
139
		}
David Cazier's avatar
David Cazier committed
140
141
		dd = map.phi1(dd) ;
	} while (dd != d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
}

Thomas's avatar
Thomas committed
144
145
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
{
David Cazier's avatar
David Cazier committed
146
147
148
149
150
151
152
153
154
155
156
	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
	assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end()) ;

	removeElementFromVector<Agent*>(agentvect[d], agent) ;

	Dart dd = d ;
	do {
		Dart ddd = map.alpha1(map.alpha1(dd)) ;
		while (ddd != dd) {
			removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
			ddd = map.alpha1(ddd) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
157
		}
David Cazier's avatar
David Cazier committed
158
159
		dd = map.phi1(dd) ;
	} while (dd != d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
160
161
}

David Cazier's avatar
David Cazier committed
162
template<typename T>
163
inline void EnvMap::removeElementFromVector(std::vector<T>& a, T ag)
164
{
David Cazier's avatar
David Cazier committed
165
166
167
168
169
170
	typename std::vector<T>::iterator end = a.template end() ;
	for (typename std::vector<T>::iterator it = a.begin(); it != end; ++it) {
		if (*it == ag) {
			*it = a.back() ;
			a.pop_back() ;
			return ;
171
172
173
174
		}
	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
175
176
inline void EnvMap::clearUpdateCandidates()
{
David Cazier's avatar
David Cazier committed
177
178
	refineCandidate.clear() ;
	coarsenCandidate.clear() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
179
180
181
}

#endif