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

pitiot's avatar
up  
pitiot committed
5
#define DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
6
//#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

pitiot's avatar
pitiot committed
28
//#include "Algo/ImplicitHierarchicalMesh/subdivision3.hxx"
pitiot's avatar
up  
pitiot committed
29

Pierre Kraemer's avatar
Pierre Kraemer committed
30

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


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

pitiot's avatar
merging  
pitiot committed
39

40

Pierre Kraemer's avatar
Pierre Kraemer committed
41 42
class EnvMap
{
43
public:
Arash HABIBI's avatar
Arash HABIBI committed
44

45

David Cazier's avatar
David Cazier committed
46
	EnvMap() ;
pitiot's avatar
init  
pitiot committed
47
	void init(int argc, char **argv) ;
pitiot's avatar
up  
pitiot committed
48 49
    bool checkPointInMap(VEC3 pos,Dart neighborhood);
    bool insideVolume(VEC3 pos, Dart d);
pitiot's avatar
up  
pitiot committed
50
    REAL volumeMaxdistance(Vol volume);
pitiot's avatar
up  
pitiot committed
51
    VEC3 normaleFromVolume(Dart volume,Dart face);
pitiot's avatar
init  
pitiot committed
52
	void open_file(std::string filename);
pitiot's avatar
up  
pitiot committed
53 54 55 56 57 58
    VEC3 mapMinX;
    VEC3 mapMaxX;
    VEC3 mapMinY;
    VEC3 mapMaxY;
    VEC3 mapMinZ;
    VEC3 mapMaxZ;
59
    bool subdivideVolume(Dart d );
pitiot's avatar
pitiot committed
60
    Dart getBelongingCell(const PFP::VEC3& pos);
pitiot's avatar
pitiot committed
61

62

Pierre Kraemer's avatar
Pierre Kraemer committed
63

pitiot's avatar
init  
pitiot committed
64 65
//
//	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
	VertexAttribute<VEC3, MAP> position ;
pitiot's avatar
up  
pitiot committed
70
    FaceAttribute<VEC3, MAP> facecenter;
pitiot's avatar
init  
pitiot committed
71
	VolumeAttribute<VEC3, MAP> color ;
pitiot's avatar
pitiot committed
72 73
    VolumeAttribute<ARETES, MAP> RegisteredEdges ;
    VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
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
pitiot committed
78 79 80
// 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
81
//
pitiot's avatar
pitiot committed
82 83 84 85 86 87 88 89 90
    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
91
    void resetPartSubdiv(Segment* o);
pitiot's avatar
pitiot committed
92 93 94 95 96 97
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




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

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


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

pitiot's avatar
pitiot committed
113 114 115 116 117 118
//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
119

pitiot's avatar
maj  
pitiot committed
120

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

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

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

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

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

pitiot's avatar
pitiot committed
184
    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
185

pitiot's avatar
pitiot committed
186 187 188 189 190
    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
191

192

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

pitiot's avatar
pitiot committed
200 201 202 203 204 205 206 207 208 209
    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
210
//	for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
pitiot's avatar
pitiot committed
211 212 213 214 215 216
//		CGoGNout<<(*it).index<<" ; ";
//	CGoGNout<<CGoGNendl;

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

pitiot's avatar
pitiot committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233
            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
234
#ifdef IHMap
pitiot's avatar
pitiot committed
235
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
236
#endif
pitiot's avatar
pitiot committed
237 238 239 240 241 242 243 244
    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
245
#ifdef IHMap
pitiot's avatar
pitiot committed
246
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
247
#endif
pitiot's avatar
pitiot committed
248 249 250 251 252 253 254
    assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) != RegisteredNeighborEdges[d].end());

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



255

Pierre Kraemer's avatar
Pierre Kraemer committed
256 257

#endif