env_map.h 8.25 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 128 129 130 131 132 133
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
134
template <typename T>
pitiot's avatar
maj  
pitiot committed
135
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
136
{
Etienne Schmitt's avatar
Etienne Schmitt committed
137 138 139 140 141 142 143 144 145 146
    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
147 148
}

pitiot's avatar
pitiot committed
149
/////////////////////////////////////////////////////////////////////REGISTRATIONS
David Cazier's avatar
David Cazier committed
150

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

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

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

162

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

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

pitiot's avatar
pitiot committed
182 183 184 185 186 187
            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
188 189

    }
pitiot's avatar
pitiot committed
190 191 192 193

}


Thomas Pitiot 's avatar
Thomas Pitiot committed
194

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


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

260

Pierre Kraemer's avatar
Pierre Kraemer committed
261 262

#endif