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

Thomas Pitiot 's avatar
Thomas Pitiot committed
5 6
//#define DEBUG_affichage
//#define DEBUG
pitiot's avatar
init  
pitiot committed
7

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

pitiot's avatar
init  
pitiot committed
12

Pierre Kraemer's avatar
Pierre Kraemer committed
13 14 15 16 17 18

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

#include "Container/fakeAttribute.h"
pitiot's avatar
init  
pitiot committed
22 23 24 25 26
#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
27

Pierre Kraemer's avatar
Pierre Kraemer committed
28

pitiot's avatar
pitiot committed
29 30
/////////////////particules
#include "Algo/MovingObjects/particle_cell_3D_memo.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
31 32


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

pitiot's avatar
merging  
pitiot committed
37

38

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
	void init(int argc, char **argv) ;
pitiot's avatar
up  
pitiot committed
46 47
    bool checkPointInMap(VEC3 pos,Dart neighborhood);
    bool insideVolume(VEC3 pos, Dart d);
pitiot's avatar
up  
pitiot committed
48
    REAL volumeMaxdistance(Vol volume);
pitiot's avatar
up  
pitiot committed
49
    VEC3 normaleFromVolume(Dart volume,Dart face);
pitiot's avatar
init  
pitiot committed
50
	void open_file(std::string filename);
pitiot's avatar
up  
pitiot committed
51 52 53 54 55 56
    VEC3 mapMinX;
    VEC3 mapMaxX;
    VEC3 mapMinY;
    VEC3 mapMaxY;
    VEC3 mapMinZ;
    VEC3 mapMaxZ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
57
    float maxCellSize;
58
    bool subdivideVolume(Dart d );
pitiot's avatar
pitiot committed
59
    Dart getBelongingCell(const PFP::VEC3& pos);
pitiot's avatar
pitiot committed
60

61

Pierre Kraemer's avatar
Pierre Kraemer committed
62

pitiot's avatar
init  
pitiot committed
63 64
//
//	void resetAgentInFace(Agent* agent) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
65

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

pitiot's avatar
init  
pitiot committed
68
	VertexAttribute<VEC3, MAP> position ;
pitiot's avatar
up  
pitiot committed
69
    FaceAttribute<VEC3, MAP> facecenter;
pitiot's avatar
init  
pitiot committed
70
	VolumeAttribute<VEC3, MAP> color ;
pitiot's avatar
pitiot committed
71 72
    VolumeAttribute<ARETES, MAP> RegisteredEdges ;
    VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
73 74
	Geom::BoundingBox<PFP::VEC3> bb;

Pierre Kraemer's avatar
Pierre Kraemer committed
75

David Cazier's avatar
David Cazier committed
76

pitiot's avatar
pitiot committed
77 78 79
// Enregistrement Aretes//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
    void FindNeighborCellsOfSegment (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
pitiot's avatar
init  
pitiot committed
80
//
pitiot's avatar
pitiot committed
81 82 83 84 85 86 87 88 89
    Dart popAndPushSegment(Segment* o);
    void FirstRegistrationSegment(Segment * mo);
    void pushAOneCellSegment(Segment * o, Dart d);
    void pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_cross);
    void popSegment(Segment* o);


    void pushSegmentInCellAsNeighbor(Segment* o, Dart d);
    void popSegmentInCellAsNeighbor(Segment* o, Dart d);
pitiot's avatar
up  
pitiot committed
90
    void resetPartSubdiv(Segment* o);
pitiot's avatar
pitiot committed
91 92 93 94 95 96
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//MULTIRES/////////////////////////////////////////////////////////////////////////////
Pierre Kraemer's avatar
Pierre Kraemer committed
97

pitiot's avatar
init  
pitiot committed
98 99
//	static const unsigned int nbAgentsToSubdivide = 1 ;
//	static const unsigned int nbAgentsToSimplify = 0 ;
pitiot's avatar
pitiot committed
100 101 102
//	void refine() ;
//	void coarse() ;
//	void updateMap() ;
pitiot's avatar
init  
pitiot committed
103 104 105 106
//	CellMarker<FACE> refineMark ;
//	CellMarker<FACE> coarsenMark ;
//	std::vector<Dart> refineCandidate ;
//	std::vector<Dart> coarsenCandidate ;
pitiot's avatar
pitiot committed
107
///////////////////////////////////////////////////////////////////////////////////////
pitiot's avatar
maj  
pitiot committed
108 109


110
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111

pitiot's avatar
pitiot committed
112 113 114 115 116 117
//void update_registration(Segment * o);
//void register_pop(Segment* o, int n);
//void resetPartSubdiv(Segment* o);
//void resetObstPartInFace(Segment* o, Dart d, unsigned int fLevel);// empeche de viser une dart ayant disparu
//void resetObstPartInFace(Segment* o, Dart d);// empeche de viser une dart ayant disparu
//void resetPart(Segment * mo, Dart d); // empeche de viser une dart ayant disparu pour les voisins
pitiot's avatar
init  
pitiot committed
118

pitiot's avatar
maj  
pitiot committed
119

Pierre Kraemer's avatar
Pierre Kraemer committed
120
/**************************************
David Cazier's avatar
David Cazier committed
121 122
 *           INLINE FUNCTIONS          *
 **************************************/
pitiot's avatar
pitiot committed
123
//////////////////// BASIC OPERATIONS ////////////////////////////////////////////////////////////////
124 125 126 127 128 129 130
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
131
template <typename T>
pitiot's avatar
maj  
pitiot committed
132
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
133
{
134 135
	assert(std::find(a.begin(), a.end(), ag) != a.end());

136
	typename std::vector<T>::iterator end = a.template end() ;
David Cazier's avatar
David Cazier committed
137 138 139 140
	for (typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
	{
		if (*it == ag)
		{
141 142
			*it = a.back() ;
			a.pop_back() ;
pitiot's avatar
maj  
pitiot committed
143
			return true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
144 145
		}
	}
pitiot's avatar
maj  
pitiot committed
146
	return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
147 148
}

pitiot's avatar
pitiot committed
149
///////////////////////////////////////////////////////////////MULTIRES
pitiot's avatar
init  
pitiot committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
//
//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
172

pitiot's avatar
pitiot committed
173
//inline void EnvMap::clearUpdateCandidates()
pitiot's avatar
init  
pitiot committed
174
//{
pitiot's avatar
pitiot committed
175 176
//	refineCandidate.clear() ;
//	coarsenCandidate.clear() ;
pitiot's avatar
init  
pitiot committed
177
//}
pitiot's avatar
pitiot committed
178
/////////////////////////////////////////////////////////////////////REGISTRATIONS
David Cazier's avatar
David Cazier committed
179

pitiot's avatar
pitiot committed
180 181
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
182

pitiot's avatar
pitiot committed
183
    CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> * registering_part = new CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP>(map, d1,pos,position);
pitiot's avatar
maj  
pitiot committed
184

pitiot's avatar
pitiot committed
185 186 187 188 189
    std::vector<Dart> result =(registering_part->move(dest));
//    d2=registering_part->d;
//	CGoGNout<<"d1 : "<< *d1<<"|| d2 : "<< *d2<<"|| start : "<< pos<<"|| stop : "<< dest<<CGoGNendl;
    return result;
}
pitiot's avatar
maj  
pitiot committed
190

191

pitiot's avatar
pitiot committed
192 193
inline void EnvMap::FindNeighborCellsOfSegment (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
194
#ifdef IHMap
pitiot's avatar
pitiot committed
195
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
196
#endif
pitiot's avatar
pitiot committed
197
    assert(!belonging_cells.empty());
Thomas Pitiot 's avatar
Thomas Pitiot committed
198

pitiot's avatar
pitiot committed
199 200 201 202 203 204 205 206 207 208
    neighbor_cells->clear();
    CellMarkerMemo<MAP,VOLUME> memo_mark(map); //marqueur des cellules "présentes"
    CellMarkerMemo<MAP,VOLUME> OneRingMark(map); // marquer des cellules voisines

    for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
            memo_mark.mark(*it);

    std::vector<Dart>::const_iterator it=belonging_cells.begin();
    Dart dd=NIL;
//	CGoGNout<<"debut neighbors cellules : ";
pitiot's avatar
pitiot committed
209
//	for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
pitiot's avatar
pitiot committed
210 211 212 213 214 215
//		CGoGNout<<(*it).index<<" ; ";
//	CGoGNout<<CGoGNendl;

    do
    {
        dd = *it;
pitiot's avatar
pitiot committed
216
        for (Vol d : volumesAdjacentByVertex3(map,(*it)))
pitiot's avatar
pitiot committed
217
        {
pitiot's avatar
pitiot committed
218

pitiot's avatar
pitiot committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232
            if (!map.isBoundaryMarked<3>(d) && !memo_mark.isMarked(d) && !OneRingMark.isMarked(d) )
            {
                OneRingMark.mark(d);
                (*neighbor_cells).push_back(d);
            }
        }
        ++it;
    }while(it!=belonging_cells.end());

}


inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
233
#ifdef IHMap
pitiot's avatar
pitiot committed
234
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
235
#endif
pitiot's avatar
pitiot committed
236 237 238 239 240 241 242 243
    assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) == RegisteredNeighborEdges[d].end());

    addElementToVector<Segment*>(RegisteredNeighborEdges[d],o);

}

inline void EnvMap::popSegmentInCellAsNeighbor(Segment* o, Dart d)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
244
#ifdef IHMap
pitiot's avatar
pitiot committed
245
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
246
#endif
pitiot's avatar
pitiot committed
247 248 249 250 251 252 253
    assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) != RegisteredNeighborEdges[d].end());

    removeElementFromVector<Segment*>(RegisteredNeighborEdges[d],o);
}



254

Pierre Kraemer's avatar
Pierre Kraemer committed
255 256

#endif