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 3.91 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
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

#include <iostream>
#include <algorithm>

#include "Topology/generic/parameters.h"
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"

#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"

#include "Container/fakeAttribute.h"

#include "env_generator.h"

#include "Algo/Parallel/parallel_foreach.h"

using namespace CGoGN;

class Agent;

struct PFP: public PFP_STANDARD
{
	// definition de la carte
// 	typedef EmbeddedMap2<Map2> MAP;
 	typedef Algo::IHM::ImplicitHierarchicalMap MAP;

	// definition des listes d'agent
	typedef std::vector<Agent*> AGENTS;
	typedef std::vector<Dart> OBSTACLES;
	typedef NoMathIONameAttribute<AGENTS> AGENTVECT;
	typedef NoMathIONameAttribute<OBSTACLES> OBSTACLEVECT;
	typedef AttributeHandler<AGENTVECT> TAB_AGENTVECT;
	typedef AttributeHandler<OBSTACLEVECT> TAB_OBSTACLEVECT;
43
44

	typedef NoMathIONameAttribute<std::pair<bool,bool> > BOOLATTRIB;
Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
};

typedef PFP::VEC3 VEC3;

class EnvMap
{
public :
	EnvMap();
	
	unsigned int mapMemoryCost();
	Dart getBelongingCell(const PFP::VEC3& pos);
	
	void init();
	
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
	void foreach_neighborFace(Dart d, FunctorType& f);

Pierre Kraemer's avatar
Pierre Kraemer committed
61
62
63
64
65
	void registerObstaclesInFaces();
	void addNeighborObstacles(PFP::OBSTACLES& obst, Dart d, bool edgeNeighbor);
	
	void setAgentNeighborsAndObstacles(Agent* agent);
	
66
//	void agentChangeFaceThroughEdge(Agent* agent);
Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
	void agentChangeFace(Agent* agent, Dart oldFace);

Pierre Kraemer's avatar
Pierre Kraemer committed
69
70
	void pushAgentInCells(Agent* agent, Dart d);
	void popAgentInCells(Agent* agent, Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
71
72
73
74
75
76
77
78
79
80
81
	
	void clearUpdateCandidates();
	void updateMap();

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

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

82
83
	AttributeHandler<PFP::BOOLATTRIB> subdivisableFace;

Pierre Kraemer's avatar
Pierre Kraemer committed
84
	PFP::TAB_AGENTVECT agentvect;
Pierre Kraemer's avatar
Pierre Kraemer committed
85
86
	PFP::TAB_AGENTVECT neighborAgentvect;
	
Pierre Kraemer's avatar
Pierre Kraemer committed
87
88
89
90
91
	PFP::TAB_OBSTACLEVECT obstvect;

	CellMarker obstacleMark;
	CellMarker buildingMark;

92
	static const unsigned int nbAgentsToSubdivide = 7;
Pierre Kraemer's avatar
Pierre Kraemer committed
93
	static const unsigned int nbAgentsToSimplify = 7;
Pierre Kraemer's avatar
Pierre Kraemer committed
94

95
96
97
98
99
100
//	std::map<unsigned int, Dart> refineCandidate;
//	std::map<unsigned int, Dart> coarsenCandidate;

	CellMarker refineMark;
	std::vector<Dart> refineCandidate;
//	std::vector<Dart> coarsenCandidate;
Pierre Kraemer's avatar
Pierre Kraemer committed
101
102
103
104
105
106
};

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

Pierre Kraemer's avatar
Pierre Kraemer committed
107
inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
108
109
110
111
112
{
	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
113
114
115
116
117
118
119
120
121
122
123
124

	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
125
126
}

Pierre Kraemer's avatar
Pierre Kraemer committed
127
inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
128
129
130
131
{
	assert(map.getCurrentLevel() == map.getMaxLevel());
	assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) != agentvect[d].end());
	
Pierre Kraemer's avatar
Pierre Kraemer committed
132
133
	PFP::AGENTS& a = agentvect[d];
	PFP::AGENTS::iterator end = a.end();
Pierre Kraemer's avatar
Pierre Kraemer committed
134
	bool found = false;
Pierre Kraemer's avatar
Pierre Kraemer committed
135
	for(PFP::AGENTS::iterator it = a.begin(); it != end && !found; ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
138
	{
		if(*it == agent)
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
			*it = a.back();
			a.pop_back();
Pierre Kraemer's avatar
Pierre Kraemer committed
141
			found = true;
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
144
145
146
147
148
149
150
151

	Dart dd = d;
	do
	{
		Dart ddd = map.alpha1(map.alpha1(dd));
		while(ddd != dd)
		{
			bool found = false;
Pierre Kraemer's avatar
Pierre Kraemer committed
152
153
154
			PFP::AGENTS& na = neighborAgentvect[ddd];
			PFP::AGENTS::iterator end = na.end();
			for(PFP::AGENTS::iterator it = na.begin(); it != end && !found; ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
155
156
157
			{
				if(*it == agent)
				{
Pierre Kraemer's avatar
Pierre Kraemer committed
158
159
					*it = na.back();
					na.pop_back();
Pierre Kraemer's avatar
Pierre Kraemer committed
160
161
162
163
164
165
166
					found = true;
				}
			}
			ddd = map.alpha1(ddd);
		}
		dd = map.phi1(dd);
	} while(dd != d);
Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
169
170
171
}

inline void EnvMap::clearUpdateCandidates()
{
	refineCandidate.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
172
//	coarsenCandidate.clear();
Pierre Kraemer's avatar
Pierre Kraemer committed
173
174
175
}

#endif