env_map.h 6.79 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
up  
pitiot committed
26 27 28
#include "Algo/ImplicitHierarchicalMesh/subdivision3.hxx"


Pierre Kraemer's avatar
Pierre Kraemer committed
29

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31


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

pitiot's avatar
merging  
pitiot committed
35

36 37 38 39




pitiot's avatar
init  
pitiot committed
40
class Agent;
pitiot's avatar
up  
pitiot committed
41
class Segment;
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43
class EnvMap
{
44
public:
Arash HABIBI's avatar
Arash HABIBI committed
45

46

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

Pierre Kraemer's avatar
Pierre Kraemer committed
51

pitiot's avatar
init  
pitiot committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
//	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
69

pitiot's avatar
init  
pitiot committed
70
	PFP::MAP map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
71

pitiot's avatar
init  
pitiot committed
72 73
	VertexAttribute<VEC3, MAP> position ;
	VolumeAttribute<VEC3, MAP> color ;
74 75
	Geom::BoundingBox<PFP::VEC3> bb;

Pierre Kraemer's avatar
Pierre Kraemer committed
76

David Cazier's avatar
David Cazier committed
77

pitiot's avatar
init  
pitiot committed
78
//	CellMarker<FACE> buildingMarkS ;
Pierre Kraemer's avatar
Pierre Kraemer committed
79

pitiot's avatar
init  
pitiot committed
80 81 82 83 84 85
	// 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
86

pitiot's avatar
init  
pitiot committed
87 88 89 90 91 92 93 94
//
//	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
95 96 97



98
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99

pitiot's avatar
init  
pitiot committed
100 101 102 103 104 105 106
//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
107

Pierre Kraemer's avatar
Pierre Kraemer committed
108
/**************************************
David Cazier's avatar
David Cazier committed
109 110
 *           INLINE FUNCTIONS          *
 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
111

112 113 114 115 116 117 118
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
119
template <typename T>
pitiot's avatar
maj  
pitiot committed
120
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
121
{
122 123
	assert(std::find(a.begin(), a.end(), ag) != a.end());

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

137

pitiot's avatar
init  
pitiot committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
//
//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
160

pitiot's avatar
init  
pitiot committed
161 162 163 164 165 166
//inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
//	addElementToVector<Agent*>(agentvect[d],agent);
//
//
pitiot's avatar
pitiot committed
167
//
pitiot's avatar
init  
pitiot committed
168 169 170 171 172 173 174 175 176
//	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
177
//		}
pitiot's avatar
init  
pitiot committed
178 179 180
//		dd = map.phi1(dd) ;
//	} while (dd != d) ;
//}
David Cazier's avatar
David Cazier committed
181

pitiot's avatar
init  
pitiot committed
182 183 184 185 186 187 188 189 190
//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
191
//		{
pitiot's avatar
init  
pitiot committed
192 193
//			if (!map.isBoundaryMarked2(ddd))
//				removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
pitiot's avatar
pitiot committed
194
//
pitiot's avatar
init  
pitiot committed
195
//			ddd = map.alpha1(ddd) ;
pitiot's avatar
pitiot committed
196
//		}
pitiot's avatar
init  
pitiot committed
197 198 199 200
//		dd = map.phi1(dd) ;
//	} while (dd != d) ;
//
//}
Pierre Kraemer's avatar
Pierre Kraemer committed
201

pitiot's avatar
maj  
pitiot committed
202 203 204

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

205

pitiot's avatar
init  
pitiot committed
206 207 208 209 210 211 212 213 214
//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
215
//	for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
pitiot's avatar
init  
pitiot committed
216 217 218
//			memo_mark.mark(*it);
//
//
pitiot's avatar
pitiot committed
219
//
pitiot's avatar
init  
pitiot committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
//
//
//
//	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
237 238 239 240 241 242 243 244 245
//		{
//			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
246 247 248
//						OneRingMark.mark(dd);
//						(*neighbor_cells).push_back(dd);
//
pitiot's avatar
pitiot committed
249 250
//					}
//					dd=map.alpha1(dd);
pitiot's avatar
init  
pitiot committed
251
//				}while (dd!=d);
pitiot's avatar
pitiot committed
252 253 254
//
//				d=map.phi1(d);
//
pitiot's avatar
init  
pitiot committed
255
//			} while(d!=beg);
pitiot's avatar
pitiot committed
256
//			++it;
pitiot's avatar
init  
pitiot committed
257
//		}while(it!=belonging_cells.end());
pitiot's avatar
pitiot committed
258
//
pitiot's avatar
init  
pitiot committed
259
//}
pitiot's avatar
pitiot committed
260 261
//
//
pitiot's avatar
init  
pitiot committed
262 263 264 265
//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
266
//
pitiot's avatar
init  
pitiot committed
267 268
//	addElementToVector<Obstacle*>(neighborObstvect[d],o);
//}
pitiot's avatar
pitiot committed
269 270
//
//
pitiot's avatar
init  
pitiot committed
271
//inline void EnvMap::clearUpdateCandidates()
272
//{
pitiot's avatar
init  
pitiot committed
273 274
//	refineCandidate.clear() ;
//	coarsenCandidate.clear() ;
275
//}
276

Pierre Kraemer's avatar
Pierre Kraemer committed
277 278

#endif