env_map.h 7.26 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
#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
#include "segment.h"
#include "triangle.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
39

pitiot's avatar
merging  
pitiot committed
40

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

Pierre Kraemer's avatar
Pierre Kraemer committed
44 45
class EnvMap
{
46
public:
Etienne Schmitt's avatar
Etienne Schmitt committed
47
    std::chrono::duration<double> duration_pop, duration_subdiv, duration_push;
48

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

66

Pierre Kraemer's avatar
Pierre Kraemer committed
67

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

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

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
82 83
    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
84

David Cazier's avatar
David Cazier committed
85

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
100 101 102
    //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
103
    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
104
    void popTriangle(Triangle* o);
pitiot's avatar
pitiot committed
105

Thomas Pitiot 's avatar
Thomas Pitiot committed
106 107 108 109 110
    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
111 112


113
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
114

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

pitiot's avatar
maj  
pitiot committed
122

Pierre Kraemer's avatar
Pierre Kraemer committed
123
/**************************************
David Cazier's avatar
David Cazier committed
124 125
 *           INLINE FUNCTIONS          *
 **************************************/
pitiot's avatar
pitiot committed
126
//////////////////// BASIC OPERATIONS ////////////////////////////////////////////////////////////////
127
template <typename T>
Etienne Schmitt's avatar
Etienne Schmitt committed
128
inline bool addElementToVector(std::vector<T>& a, T ag)
129
{
Etienne Schmitt's avatar
Etienne Schmitt committed
130 131 132 133 134 135
    if (std::find(a.begin(), a.end(), ag) == a.end())
    {
        a.push_back(ag) ;
        return true;
    }
    return false;
136 137
}

David Cazier's avatar
David Cazier committed
138
template <typename T>
pitiot's avatar
maj  
pitiot committed
139
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
140
{
Etienne Schmitt's avatar
Etienne Schmitt committed
141 142 143 144 145 146 147 148 149 150
    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
151 152
}

pitiot's avatar
pitiot committed
153
/////////////////////////////////////////////////////////////////////REGISTRATIONS
David Cazier's avatar
David Cazier committed
154

pitiot's avatar
pitiot committed
155 156
inline std::vector<Dart> EnvMap::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
{
Etienne Schmitt's avatar
Etienne Schmitt committed
157 158
    typedef CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP> ParticleCell3DMemo;
    return ParticleCell3DMemo(map, d1, pos,position).move(dest);
pitiot's avatar
pitiot committed
159
}
pitiot's avatar
maj  
pitiot committed
160

161

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

pitiot's avatar
pitiot committed
169 170 171 172 173 174 175
    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
176 177 178
   for( Dart dd : belonging_cells)
   {
        for (Vol d : volumesAdjacentByVertex3(map,dd))
pitiot's avatar
pitiot committed
179
        {
pitiot's avatar
pitiot committed
180

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

    }
pitiot's avatar
pitiot committed
189 190 191 192

}


Thomas Pitiot 's avatar
Thomas Pitiot committed
193

pitiot's avatar
pitiot committed
194 195
inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
196
#ifdef IHMap
pitiot's avatar
pitiot committed
197
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
198
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
199
    addElementToVector(RegisteredNeighborEdges[d],o);
pitiot's avatar
pitiot committed
200 201 202 203 204

}

inline void EnvMap::popSegmentInCellAsNeighbor(Segment* o, Dart d)
{
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
Etienne Schmitt's avatar
Etienne Schmitt committed
208
    removeElementFromVector(RegisteredNeighborEdges[d],o);
pitiot's avatar
pitiot committed
209 210
}

Thomas Pitiot 's avatar
Thomas Pitiot committed
211 212 213 214 215
inline void EnvMap::pushTriangleInCellAsNeighbor(Triangle*  o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
216
    addElementToVector(RegisteredNeighborTriangles[d],o);
Thomas Pitiot 's avatar
Thomas Pitiot committed
217 218 219 220 221 222 223 224

}

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

pitiot's avatar
pitiot committed
228 229


Thomas Pitiot 's avatar
Thomas Pitiot committed
230 231 232 233 234
inline void EnvMap::pushTriangleInCell(Triangle * o, Dart d)
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
Etienne Schmitt's avatar
Etienne Schmitt committed
235
    addElementToVector(RegisteredTriangles[d],o);
Thomas Pitiot 's avatar
Thomas Pitiot committed
236 237 238 239 240 241 242 243

}

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

247

Pierre Kraemer's avatar
Pierre Kraemer committed
248 249

#endif