env_map.h 8.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>
128
inline bool addElementToVector(std::vector<T>& a, T ag)
129
{
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)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
157

Thomas Pitiot 's avatar
Thomas Pitiot committed
158
    CGoGN::Algo::Volume::MovingObjects::ParticleCell3DMemo<PFP>  registering_part (map, d1,pos,position);
pitiot's avatar
maj  
pitiot committed
159

Thomas Pitiot 's avatar
Thomas Pitiot committed
160
    std::vector<Dart> result =(registering_part.move(dest));
pitiot's avatar
pitiot committed
161 162 163 164
//    d2=registering_part->d;
//	CGoGNout<<"d1 : "<< *d1<<"|| d2 : "<< *d2<<"|| start : "<< pos<<"|| stop : "<< dest<<CGoGNendl;
    return result;
}
pitiot's avatar
maj  
pitiot committed
165

166

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

pitiot's avatar
pitiot committed
174 175 176 177 178 179 180
    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
181 182 183
   for( Dart dd : belonging_cells)
   {
        for (Vol d : volumesAdjacentByVertex3(map,dd))
pitiot's avatar
pitiot committed
184
        {
pitiot's avatar
pitiot committed
185

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

    }
pitiot's avatar
pitiot committed
194 195 196 197

}


Thomas Pitiot 's avatar
Thomas Pitiot committed
198

pitiot's avatar
pitiot committed
199 200
inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
201
#ifdef IHMap
pitiot's avatar
pitiot committed
202
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
203
#endif
pitiot's avatar
pitiot committed
204 205 206 207 208 209 210 211
    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
212
#ifdef IHMap
pitiot's avatar
pitiot committed
213
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
214
#endif
pitiot's avatar
pitiot committed
215 216 217 218 219
    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
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
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
241 242


Thomas Pitiot 's avatar
Thomas Pitiot committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
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);
}

264

Pierre Kraemer's avatar
Pierre Kraemer committed
265 266

#endif