env_map.h 8.38 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
//#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
#include <iostream>
#include <algorithm>
Etienne Schmitt's avatar
Etienne Schmitt committed
10 11
#include <chrono>
#include <ctime>
Pierre Kraemer's avatar
Pierre Kraemer committed
12 13
#include "Topology/generic/parameters.h"

pitiot's avatar
init  
pitiot committed
14

Pierre Kraemer's avatar
Pierre Kraemer committed
15 16 17 18 19 20

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

#include "Container/fakeAttribute.h"
pitiot's avatar
init  
pitiot committed
24 25 26 27 28
#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
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 ;
David Cazier's avatar
David Cazier committed
36
#include "pfp.h"
Thomas Pitiot 's avatar
Thomas Pitiot committed
37 38 39 40

typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3D<PFP> Particule;
typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticuleMemo;

Thomas Pitiot 's avatar
Thomas Pitiot committed
41 42
#include "segment.h"
#include "triangle.h"
Thomas Pitiot 's avatar
Thomas Pitiot committed
43 44
#include "agent.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
45

pitiot's avatar
merging  
pitiot committed
46

47

Pierre Kraemer's avatar
Pierre Kraemer committed
48 49
class EnvMap
{
50
public:
Etienne Schmitt's avatar
Etienne Schmitt committed
51
    std::chrono::duration<double> duration_pop, duration_subdiv, duration_push;
52

David Cazier's avatar
David Cazier committed
53
	EnvMap() ;
pitiot's avatar
init  
pitiot committed
54
	void init(int argc, char **argv) ;
pitiot's avatar
up  
pitiot committed
55
    bool checkPointInMap(VEC3 pos,Dart neighborhood);
56
    bool checkPointInCube(VEC3 pos);
57
    bool checkFaces();  // vérifie que tous les points des faces sont bien coplanaires si ce n'eest pas le cas renvoie true
pitiot's avatar
up  
pitiot committed
58
    bool insideVolume(VEC3 pos, Dart d);
pitiot's avatar
up  
pitiot committed
59
    REAL volumeMaxdistance(Vol volume);
pitiot's avatar
up  
pitiot committed
60
    VEC3 normaleFromVolume(Dart volume,Dart face);
pitiot's avatar
init  
pitiot committed
61
	void open_file(std::string filename);
62 63 64 65 66 67
    float mapMinX;
    float mapMaxX;
    float mapMinY;
    float mapMaxY;
    float mapMinZ;
    float mapMaxZ;
68
    float maxCellRay;
Thomas Pitiot 's avatar
Thomas Pitiot committed
69
    bool subdivideVolume(Dart d , bool OneLevelDifference=true);
pitiot's avatar
pitiot committed
70
    Dart getBelongingCell(const PFP::VEC3& pos);
pitiot's avatar
pitiot committed
71

72

pitiot's avatar
init  
pitiot committed
73
	PFP::MAP map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
74

pitiot's avatar
init  
pitiot committed
75
	VertexAttribute<VEC3, MAP> position ;
pitiot's avatar
up  
pitiot committed
76
    FaceAttribute<VEC3, MAP> facecenter;
pitiot's avatar
init  
pitiot committed
77
	VolumeAttribute<VEC3, MAP> color ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
78
    VolumeAttribute<VEC3, MAP> volumecenter;
Thomas Pitiot 's avatar
Thomas Pitiot committed
79 80
    VolumeAttribute<AGENTS,MAP> RegisteredAgents;
    VolumeAttribute<AGENTS,MAP> RegisteredNeighborAgents;
pitiot's avatar
pitiot committed
81 82
    VolumeAttribute<ARETES, MAP> RegisteredEdges ;
    VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
83 84
    VolumeAttribute<TRIANGLES, MAP> RegisteredTriangles ;
    VolumeAttribute<TRIANGLES, MAP> RegisteredNeighborTriangles ;
85 86
	Geom::BoundingBox<PFP::VEC3> bb;

Thomas Pitiot 's avatar
Thomas Pitiot committed
87
    std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1, unsigned int state);
Thomas Pitiot 's avatar
Thomas Pitiot committed
88
    void FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
Pierre Kraemer's avatar
Pierre Kraemer committed
89

David Cazier's avatar
David Cazier committed
90

pitiot's avatar
pitiot committed
91
// Enregistrement Aretes//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thomas Pitiot 's avatar
Thomas Pitiot committed
92
   //
pitiot's avatar
pitiot committed
93 94 95 96 97 98 99 100 101
    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);
102
    void resetPartSubdiv(Segment* o);
pitiot's avatar
pitiot committed
103 104
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thomas Pitiot 's avatar
Thomas Pitiot committed
105 106 107
    //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
108
    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
109
    void popTriangle(Triangle* o);
pitiot's avatar
pitiot committed
110

Thomas Pitiot 's avatar
Thomas Pitiot committed
111 112 113 114
    void pushTriangleInCell(Triangle*  o, Dart d);
    void popTriangleInCell(Triangle*  o, Dart d);
    void pushTriangleInCellAsNeighbor(Triangle* cell, Dart d);
    void popTriangleInCellAsNeighbor(Triangle* cell, Dart d);
115
    void resetPartSubdiv(Triangle* cell);
pitiot's avatar
maj  
pitiot committed
116

Thomas Pitiot 's avatar
Thomas Pitiot committed
117 118 119 120 121 122 123 124 125 126
    /// enregistrement des agents

    void agentChangeFace(Agent * ag , Dart oldCell);
    void popAgent(Agent * agent,Dart  oldCell) ;
    void pushAgent(Agent * agent,Dart newVolume) ;

    void pushAgentInCell(Agent*  o, Dart d);
    void popAgentInCell(Agent*  o, Dart d);
    void pushAgentInCellAsNeighbor(Agent* cell, Dart d);
    void popAgentInCellAsNeighbor(Agent* cell, Dart d);
pitiot's avatar
maj  
pitiot committed
127

128
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130

/**************************************
David Cazier's avatar
David Cazier committed
131 132
 *           INLINE FUNCTIONS          *
 **************************************/
pitiot's avatar
pitiot committed
133
//////////////////// BASIC OPERATIONS ////////////////////////////////////////////////////////////////
134
template <typename T>
Etienne Schmitt's avatar
Etienne Schmitt committed
135
inline bool addElementToVector(std::vector<T>& a, T ag)
136
{
Etienne Schmitt's avatar
Etienne Schmitt committed
137 138 139 140 141 142
    if (std::find(a.begin(), a.end(), ag) == a.end())
    {
        a.push_back(ag) ;
        return true;
    }
    return false;
143 144
}

David Cazier's avatar
David Cazier committed
145
template <typename T>
pitiot's avatar
maj  
pitiot committed
146
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
147
{
Etienne Schmitt's avatar
Etienne Schmitt committed
148 149 150 151 152 153 154 155 156 157
    typedef  typename std::vector<T>::iterator iterator;
    iterator it = std::find(a.begin(), a.end(), ag);
    if (it == a.end())
    {
        return false;
    } else {
        *it = a.back();
        a.pop_back();
    }
    return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
158 159
}

pitiot's avatar
pitiot committed
160
/////////////////////////////////////////////////////////////////////REGISTRATIONS
David Cazier's avatar
David Cazier committed
161

Thomas Pitiot 's avatar
Thomas Pitiot committed
162
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1 , unsigned int state)
pitiot's avatar
pitiot committed
163
{
Etienne Schmitt's avatar
Etienne Schmitt committed
164
    typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticleCell3DMemo;
Thomas Pitiot 's avatar
Thomas Pitiot committed
165 166 167
    ParticleCell3DMemo part(map, d1, pos,position,&facecenter,&volumecenter);
    part.setState(state);
    return part.move(dest);
pitiot's avatar
pitiot committed
168
}
pitiot's avatar
maj  
pitiot committed
169

170

Thomas Pitiot 's avatar
Thomas Pitiot committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

inline void EnvMap::pushAgentInCell(Agent*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    addElementToVector(RegisteredAgents[d],o);
}

inline void EnvMap::popAgentInCell(Agent*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    removeElementFromVector(RegisteredAgents[d],o);
}
inline void EnvMap::pushAgentInCellAsNeighbor(Agent* o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    addElementToVector(RegisteredNeighborAgents[d],o);
}
inline void EnvMap::popAgentInCellAsNeighbor(Agent* o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    removeElementFromVector(RegisteredNeighborAgents[d],o);
}


Thomas Pitiot 's avatar
Thomas Pitiot committed
203
inline void EnvMap::FindNeighborCells (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
pitiot's avatar
pitiot committed
204
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
205
#ifdef IHMap
pitiot's avatar
pitiot committed
206
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
207
#endif
pitiot's avatar
pitiot committed
208
    assert(!belonging_cells.empty());
Thomas Pitiot 's avatar
Thomas Pitiot committed
209

pitiot's avatar
pitiot committed
210 211 212 213 214 215 216
    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
217 218 219
   for( Dart dd : belonging_cells)
   {
        for (Vol d : volumesAdjacentByVertex3(map,dd))
pitiot's avatar
pitiot committed
220
        {
pitiot's avatar
pitiot committed
221

pitiot's avatar
pitiot committed
222 223 224
            if (!map.isBoundaryMarked<3>(d) && !memo_mark.isMarked(d) && !OneRingMark.isMarked(d) )
            {
                OneRingMark.mark(d);
225
                (*neighbor_cells).push_back(map.volumeOldestDart(d));
pitiot's avatar
pitiot committed
226 227
            }
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
228 229

    }
pitiot's avatar
pitiot committed
230 231 232 233

}


Thomas Pitiot 's avatar
Thomas Pitiot committed
234

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

}

inline void EnvMap::popSegmentInCellAsNeighbor(Segment* o, Dart d)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
246
#ifdef IHMap
pitiot's avatar
pitiot committed
247
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
248
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
249
    removeElementFromVector(RegisteredNeighborEdges[d],o);
pitiot's avatar
pitiot committed
250 251
}

Thomas Pitiot 's avatar
Thomas Pitiot committed
252 253 254 255 256
inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
257
    addElementToVector(RegisteredNeighborTriangles[d],o);
Thomas Pitiot 's avatar
Thomas Pitiot committed
258 259 260 261 262 263 264 265

}

inline void EnvMap::popTriangleInCellAsNeighbor(Triangle*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
266
    removeElementFromVector(RegisteredNeighborTriangles[d],o);
Thomas Pitiot 's avatar
Thomas Pitiot committed
267 268
}

pitiot's avatar
pitiot committed
269 270


Thomas Pitiot 's avatar
Thomas Pitiot committed
271 272 273 274 275
inline void EnvMap::pushTriangleInCell(Triangle * o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
276
    addElementToVector(RegisteredTriangles[d],o);
Thomas Pitiot 's avatar
Thomas Pitiot committed
277 278 279 280 281 282 283 284

}

inline void EnvMap::popTriangleInCell(Triangle* o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
285
    removeElementFromVector(RegisteredTriangles[d],o);
Thomas Pitiot 's avatar
Thomas Pitiot committed
286 287
}

288

Pierre Kraemer's avatar
Pierre Kraemer committed
289 290

#endif