env_map.h 8.16 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 ;
David Cazier's avatar
David Cazier committed
34
#include "pfp.h"
Thomas Pitiot 's avatar
Thomas Pitiot committed
35 36
#include "segment.h"
#include "triangle.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
37

pitiot's avatar
merging  
pitiot committed
38

Thomas Pitiot 's avatar
Thomas Pitiot committed
39 40
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP> PARTICULE;
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> PARTICULEMEMO;
41

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

64

Pierre Kraemer's avatar
Pierre Kraemer committed
65

pitiot's avatar
init  
pitiot committed
66 67
//
//	void resetAgentInFace(Agent* agent) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68

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

pitiot's avatar
init  
pitiot committed
71
	VertexAttribute<VEC3, MAP> position ;
pitiot's avatar
up  
pitiot committed
72
    FaceAttribute<VEC3, MAP> facecenter;
pitiot's avatar
init  
pitiot committed
73
	VolumeAttribute<VEC3, MAP> color ;
pitiot's avatar
pitiot committed
74 75
    VolumeAttribute<ARETES, MAP> RegisteredEdges ;
    VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
76 77
    VolumeAttribute<TRIANGLES, MAP> RegisteredTriangles ;
    VolumeAttribute<TRIANGLES, MAP> RegisteredNeighborTriangles ;
78 79
	Geom::BoundingBox<PFP::VEC3> bb;

Thomas Pitiot 's avatar
Thomas Pitiot committed
80 81
    std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
    void FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
Pierre Kraemer's avatar
Pierre Kraemer committed
82

David Cazier's avatar
David Cazier committed
83

pitiot's avatar
pitiot committed
84
// Enregistrement Aretes//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thomas Pitiot 's avatar
Thomas Pitiot committed
85
   //
pitiot's avatar
pitiot committed
86 87 88 89 90 91 92 93 94
    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
95
    void resetPartSubdiv(Segment* o);
pitiot's avatar
pitiot committed
96 97
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thomas Pitiot 's avatar
Thomas Pitiot committed
98 99 100
    //Enregistrement Surfaces
    void popAndPushTriangle(Triangle* o);                // pop et push d'une Triangle
    void FirstRegistrationTriangle (Triangle* o);        // premier enregistrement d'une Triangle
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
101
    void markNeighbors(CellMarkerMemo<MAP,VOLUME> * memo_mark, CellMarkerMemo<MAP,VOLUME> * OneRingMark, const std::vector<Dart>& memo_cross); // marker les cellules voisines d'un ensemble de cellules retenu dans memo_cross
Thomas Pitiot 's avatar
Thomas Pitiot committed
102
    void popTriangle(Triangle* o);
pitiot's avatar
pitiot committed
103

Thomas Pitiot 's avatar
Thomas Pitiot committed
104 105 106 107 108
    void pushTriangleInCell(Triangle*  o, Dart d);
    void popTriangleInCell(Triangle*  o, Dart d);
    void pushTriangleInCellAsNeighbor(Triangle* cell, Dart d);
    void popTriangleInCellAsNeighbor(Triangle* cell, Dart d);
    void resetPartSubdiv(Triangle* cell);
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
/////////////////////////////////////////////////////////////////////REGISTRATIONS
David Cazier's avatar
David Cazier committed
151

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

pitiot's avatar
pitiot committed
155
    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
156

pitiot's avatar
pitiot committed
157 158 159 160 161
    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
162

163

Thomas Pitiot 's avatar
Thomas Pitiot committed
164
inline void EnvMap::FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
pitiot's avatar
pitiot committed
165
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
166
#ifdef IHMap
pitiot's avatar
pitiot committed
167
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
168
#endif
pitiot's avatar
pitiot committed
169
    assert(!belonging_cells.empty());
Thomas Pitiot 's avatar
Thomas Pitiot committed
170

pitiot's avatar
pitiot committed
171 172 173 174 175 176 177
    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);

Thomas Pitiot 's avatar
Thomas Pitiot committed
178 179 180
   for( Dart dd : belonging_cells)
   {
        for (Vol d : volumesAdjacentByVertex3(map,dd))
pitiot's avatar
pitiot committed
181
        {
pitiot's avatar
pitiot committed
182

pitiot's avatar
pitiot committed
183 184 185 186 187 188
            if (!map.isBoundaryMarked<3>(d) && !memo_mark.isMarked(d) && !OneRingMark.isMarked(d) )
            {
                OneRingMark.mark(d);
                (*neighbor_cells).push_back(d);
            }
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
189 190

    }
pitiot's avatar
pitiot committed
191 192 193 194

}


Thomas Pitiot 's avatar
Thomas Pitiot committed
195

pitiot's avatar
pitiot committed
196 197
inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
198
#ifdef IHMap
pitiot's avatar
pitiot committed
199
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
200
#endif
pitiot's avatar
pitiot committed
201 202 203 204 205 206 207 208
    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
209
#ifdef IHMap
pitiot's avatar
pitiot committed
210
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
211
#endif
pitiot's avatar
pitiot committed
212 213 214 215 216
    assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) != RegisteredNeighborEdges[d].end());

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(std::find(RegisteredNeighborTriangles[d].begin(), RegisteredNeighborTriangles[d].end(), o) == RegisteredNeighborTriangles[d].end());

    addElementToVector<Triangle *>(RegisteredNeighborTriangles[d],o);

}

inline void EnvMap::popTriangleInCellAsNeighbor(Triangle*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(std::find(RegisteredNeighborTriangles[d].begin(), RegisteredNeighborTriangles[d].end(), o) != RegisteredNeighborTriangles[d].end());

    removeElementFromVector<Triangle* >(RegisteredNeighborTriangles[d],o);
}

pitiot's avatar
pitiot committed
238 239


Thomas Pitiot 's avatar
Thomas Pitiot committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
inline void EnvMap::pushTriangleInCell(Triangle * o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(std::find(RegisteredTriangles[d].begin(), RegisteredTriangles[d].end(), o) == RegisteredTriangles[d].end());

    addElementToVector<Triangle* >(RegisteredTriangles[d],o);

}

inline void EnvMap::popTriangleInCell(Triangle* o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(std::find(RegisteredTriangles[d].begin(), RegisteredTriangles[d].end(), o) != RegisteredTriangles[d].end());

    removeElementFromVector<Triangle* >(RegisteredTriangles[d],o);
}

261

Pierre Kraemer's avatar
Pierre Kraemer committed
262 263

#endif