env_map.h 6.77 KB
Newer Older
1 2
#ifndef ENV_MAP_H
#define ENV_MAP_H
Pierre Kraemer's avatar
Pierre Kraemer committed
3

pitiot's avatar
init  
pitiot committed
4 5


Pierre Kraemer's avatar
Pierre Kraemer committed
6 7 8 9
#include <iostream>
#include <algorithm>
#include "Topology/generic/parameters.h"

pitiot's avatar
init  
pitiot committed
10

Pierre Kraemer's avatar
Pierre Kraemer committed
11 12 13 14 15 16

#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
17
#include "Geometry/bounding_box.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
18 19

#include "Container/fakeAttribute.h"
pitiot's avatar
init  
pitiot committed
20 21 22 23 24
#include "Algo/Tiling/Volume/cubic.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Import/import.h"
#include "Algo/Geometry/volume.h"
#include "Algo/Geometry/area.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
25

pitiot's avatar
init  
pitiot committed
26
#include "Algo/ImplicitHierarchicalMesh/subdivision3.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
27

Pierre Kraemer's avatar
Pierre Kraemer committed
28 29


pitiot's avatar
init  
pitiot committed
30
using namespace CGoGN ;
David Cazier's avatar
David Cazier committed
31
#include "pfp.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32

pitiot's avatar
merging  
pitiot committed
33

34 35 36 37




pitiot's avatar
init  
pitiot committed
38
class Agent;
Pierre Kraemer's avatar
Pierre Kraemer committed
39 40
class EnvMap
{
41
public:
Arash HABIBI's avatar
Arash HABIBI committed
42

43

David Cazier's avatar
David Cazier committed
44
	EnvMap() ;
pitiot's avatar
init  
pitiot committed
45 46
	void init(int argc, char **argv) ;
	void open_file(std::string filename);
47

Pierre Kraemer's avatar
Pierre Kraemer committed
48

pitiot's avatar
init  
pitiot committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//	void pushAgentInCells(Agent* agent, Dart d) ;
//	void popAgentInCells(Agent* agent, Dart d) ;
//	void agentChangeFace(Agent* agent, Dart oldFace) ;
//
//	Dart popAndPushObstacleInCells(Obstacle* o, int n);
//	void pushObstacleInCells(Obstacle * mo);
//	void pushObstacleInOneRingCells(Obstacle * o, Dart d, int n);
//	void pushObstacleInCells(Obstacle* o, int n, const std::vector<Dart>& memo_cross);
//	void popObstacleInCells(Obstacle* o, int n);
//	void popObstacleInCells(Obstacle* o, Dart d) ;
//
//
//	void refine() ;
//	void coarse() ;
//	void updateMap() ;
//
//	void resetAgentInFace(Agent* agent) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66

pitiot's avatar
init  
pitiot committed
67
	PFP::MAP map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68

pitiot's avatar
init  
pitiot committed
69 70
	VertexAttribute<VEC3, MAP> position ;
	VolumeAttribute<VEC3, MAP> color ;
71 72
	Geom::BoundingBox<PFP::VEC3> bb;

Pierre Kraemer's avatar
Pierre Kraemer committed
73

David Cazier's avatar
David Cazier committed
74

pitiot's avatar
init  
pitiot committed
75
//	CellMarker<FACE> buildingMarkS ;
Pierre Kraemer's avatar
Pierre Kraemer committed
76

pitiot's avatar
init  
pitiot committed
77 78 79 80 81 82
	// ajout moving obst
//	void addObstAsNeighbor (Obstacle *  o, const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
//
//	void pushObstNeighborInCells(Obstacle* o, Dart d);
//	void popObstNeighborInCells(Obstacle* o, Dart d);
//	void find_next(Obstacle* o,Dart * d, CellMarkerMemo<FACE>& cms);
Pierre Kraemer's avatar
Pierre Kraemer committed
83

pitiot's avatar
init  
pitiot committed
84 85 86 87 88 89 90 91
//
//	static const unsigned int nbAgentsToSubdivide = 1 ;
//	static const unsigned int nbAgentsToSimplify = 0 ;
//
//	CellMarker<FACE> refineMark ;
//	CellMarker<FACE> coarsenMark ;
//	std::vector<Dart> refineCandidate ;
//	std::vector<Dart> coarsenCandidate ;
pitiot's avatar
maj  
pitiot committed
92 93 94



95
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
96

pitiot's avatar
init  
pitiot committed
97 98 99 100 101 102 103
//void update_registration(Obstacle * o);
//void register_pop(Obstacle* o, int n);
//void resetPartSubdiv(Obstacle* o);
////void resetObstPartInFace(Obstacle* o, Dart d, unsigned int fLevel);// empeche de viser une dart ayant disparu
//void resetObstPartInFace(Obstacle* o, Dart d);// empeche de viser une dart ayant disparu
//void resetPart(Obstacle * mo, Dart d); // empeche de viser une dart ayant disparu pour les voisins

pitiot's avatar
maj  
pitiot committed
104

Pierre Kraemer's avatar
Pierre Kraemer committed
105
/**************************************
David Cazier's avatar
David Cazier committed
106 107
 *           INLINE FUNCTIONS          *
 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
108

109 110 111 112 113 114 115
template <typename T>
inline void addElementToVector(std::vector<T>& a, T ag)
{
	assert(std::find(a.begin(), a.end(), ag) == a.end());
	a.push_back(ag) ;
}

David Cazier's avatar
David Cazier committed
116
template <typename T>
pitiot's avatar
maj  
pitiot committed
117
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
118
{
119 120
	assert(std::find(a.begin(), a.end(), ag) != a.end());

121
	typename std::vector<T>::iterator end = a.template end() ;
David Cazier's avatar
David Cazier committed
122 123 124 125
	for (typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
	{
		if (*it == ag)
		{
126 127
			*it = a.back() ;
			a.pop_back() ;
pitiot's avatar
maj  
pitiot committed
128
			return true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130
		}
	}
pitiot's avatar
maj  
pitiot committed
131
	return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133
}

134

pitiot's avatar
init  
pitiot committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
//
//inline void EnvMap::nbAgentsIncrease(Dart d)
//{
//	if (refineMark.isMarked(d)) return ;
//	if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
//
//	std::pair<bool, bool>& sf = subdivisableFace[d] ;
//	if (sf.first == false || (sf.first == true && sf.second))
//	{
//		refineMark.mark(d) ;
//		refineCandidate.push_back(d) ;
//	}
//}
//
//inline void EnvMap::nbAgentsDecrease(Dart d)
//{
//	if (coarsenMark.isMarked(d) || refineMark.isMarked(d)) return ;
//	if (totalNeighborSize(d) > nbAgentsToSimplify) return ;
//
//	coarsenMark.mark(d) ;
//	coarsenCandidate.push_back(map.faceOldestDart(d)) ;
//}
David Cazier's avatar
David Cazier committed
157

pitiot's avatar
init  
pitiot committed
158 159 160 161 162 163
//inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
//	addElementToVector<Agent*>(agentvect[d],agent);
//
//
pitiot's avatar
pitiot committed
164
//
pitiot's avatar
init  
pitiot committed
165 166 167 168 169 170 171 172 173
//	Dart dd = d ;
//	do
//	{
//		Dart ddd = map.alpha1(map.alpha1(dd)) ;
//		while (ddd != dd)
//		{
//			if (!map.isBoundaryMarked2(ddd))
//				addElementToVector<Agent*>(neighborAgentvect[ddd],agent);
//			ddd = map.alpha1(ddd) ;
pitiot's avatar
pitiot committed
174
//		}
pitiot's avatar
init  
pitiot committed
175 176 177
//		dd = map.phi1(dd) ;
//	} while (dd != d) ;
//}
David Cazier's avatar
David Cazier committed
178

pitiot's avatar
init  
pitiot committed
179 180 181 182 183 184 185 186 187
//inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
//	removeElementFromVector<Agent*>(agentvect[d], agent) ;
//	Dart dd = d ;
//	do
//	{
//		Dart ddd = map.alpha1(map.alpha1(dd)) ;
//		while (ddd != dd)
pitiot's avatar
pitiot committed
188
//		{
pitiot's avatar
init  
pitiot committed
189 190
//			if (!map.isBoundaryMarked2(ddd))
//				removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
pitiot's avatar
pitiot committed
191
//
pitiot's avatar
init  
pitiot committed
192
//			ddd = map.alpha1(ddd) ;
pitiot's avatar
pitiot committed
193
//		}
pitiot's avatar
init  
pitiot committed
194 195 196 197
//		dd = map.phi1(dd) ;
//	} while (dd != d) ;
//
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
198

pitiot's avatar
maj  
pitiot committed
199 200 201

//ajout moving obst///////////////////////////////////////////////////////////////////////////////////////////////////////

202

pitiot's avatar
init  
pitiot committed
203 204 205 206 207 208 209 210 211
//inline void EnvMap::addObstAsNeighbor (Obstacle *  o, const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel());
//	assert(!belonging_cells.empty());
//	neighbor_cells->clear();
////	CellMarkerMemo<FACE> memo_mark_speed(map);//marqueur additionnel (vitesse)
//	CellMarkerMemo<FACE> memo_mark(map); //marqueur des cellules "présentes"
//	CellMarkerMemo<FACE> OneRingMark(map); // marquer des cellules voisines
//
pitiot's avatar
pitiot committed
212
//	for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
pitiot's avatar
init  
pitiot committed
213 214 215
//			memo_mark.mark(*it);
//
//
pitiot's avatar
pitiot committed
216
//
pitiot's avatar
init  
pitiot committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
//
//
//
//	std::vector<Dart>::const_iterator it=belonging_cells.begin();
//	Dart beg = NIL;
//	Dart first =NIL;
//	Dart d=NIL;
//	Dart dd=NIL;
//
//
//	/////////////////////////////////////////////boucle pour trouver une face du voisinage de l'obstacle ne contenant pas l'obstacle
////	CGoGNout<<"debut neighbors cellules : ";
////	for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
////		CGoGNout<<(*it).index<<" ; ";
////	CGoGNout<<CGoGNendl;
//
//	do
pitiot's avatar
pitiot committed
234 235 236 237 238 239 240 241 242
//		{
//			beg = *it;
//			first = NIL;
//			d=beg;
//			do {
//				dd=map.alpha1(map.alpha1(d));
//				do {
//					if (!memo_mark.isMarked(dd) && !OneRingMark.isMarked(dd))
//					{
pitiot's avatar
init  
pitiot committed
243 244 245
//						OneRingMark.mark(dd);
//						(*neighbor_cells).push_back(dd);
//
pitiot's avatar
pitiot committed
246 247
//					}
//					dd=map.alpha1(dd);
pitiot's avatar
init  
pitiot committed
248
//				}while (dd!=d);
pitiot's avatar
pitiot committed
249 250 251
//
//				d=map.phi1(d);
//
pitiot's avatar
init  
pitiot committed
252
//			} while(d!=beg);
pitiot's avatar
pitiot committed
253
//			++it;
pitiot's avatar
init  
pitiot committed
254
//		}while(it!=belonging_cells.end());
pitiot's avatar
pitiot committed
255
//
pitiot's avatar
init  
pitiot committed
256
//}
pitiot's avatar
pitiot committed
257 258
//
//
pitiot's avatar
init  
pitiot committed
259 260 261 262
//inline void EnvMap::pushObstNeighborInCells(Obstacle* o, Dart d)
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel());
//	assert(std::find(neighborObstvect[d].begin(), neighborObstvect[d].end(), o) == neighborObstvect[d].end());
pitiot's avatar
pitiot committed
263
//
pitiot's avatar
init  
pitiot committed
264 265
//	addElementToVector<Obstacle*>(neighborObstvect[d],o);
//}
pitiot's avatar
pitiot committed
266 267
//
//
pitiot's avatar
init  
pitiot committed
268
//inline void EnvMap::clearUpdateCandidates()
269
//{
pitiot's avatar
init  
pitiot committed
270 271
//	refineCandidate.clear() ;
//	coarsenCandidate.clear() ;
272
//}
273

Pierre Kraemer's avatar
Pierre Kraemer committed
274 275

#endif