env_map.h 7.07 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 5


Pierre Kraemer's avatar
Pierre Kraemer committed
6 7 8 9
#include <iostream>
#include <algorithm>
#include "Topology/generic/parameters.h"

pitiot's avatar
init  
pitiot committed
10

Pierre Kraemer's avatar
Pierre Kraemer committed
11 12 13 14 15 16

#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
17
#include "Geometry/bounding_box.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
18 19

#include "Container/fakeAttribute.h"
pitiot's avatar
init  
pitiot committed
20 21 22 23 24
#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
25

pitiot's avatar
pitiot committed
26
//#include "Algo/ImplicitHierarchicalMesh/subdivision3.hxx"
pitiot's avatar
up  
pitiot committed
27

Pierre Kraemer's avatar
Pierre Kraemer committed
28

pitiot's avatar
pitiot committed
29 30 31 32
//#define DEBUG_affichage
//#define DEBUG
/////////////////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 ;
pitiot's avatar
pitiot committed
36
class Segment;
David Cazier's avatar
David Cazier committed
37
#include "pfp.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
38

pitiot's avatar
merging  
pitiot committed
39

40

Pierre Kraemer's avatar
Pierre Kraemer committed
41 42
class EnvMap
{
43
public:
Arash HABIBI's avatar
Arash HABIBI committed
44

45

David Cazier's avatar
David Cazier committed
46
	EnvMap() ;
pitiot's avatar
init  
pitiot committed
47 48
	void init(int argc, char **argv) ;
	void open_file(std::string filename);
pitiot's avatar
pitiot committed
49 50
//    Dart getBelongingCell(const PFP::VEC3& pos);

51

Pierre Kraemer's avatar
Pierre Kraemer committed
52

pitiot's avatar
init  
pitiot committed
53 54
//
//	void resetAgentInFace(Agent* agent) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
55

pitiot's avatar
init  
pitiot committed
56
	PFP::MAP map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
57

pitiot's avatar
init  
pitiot committed
58 59
	VertexAttribute<VEC3, MAP> position ;
	VolumeAttribute<VEC3, MAP> color ;
pitiot's avatar
pitiot committed
60 61
    VolumeAttribute<ARETES, MAP> RegisteredEdges ;
    VolumeAttribute<ARETES, MAP> RegisteredNeighborEdges ;
62 63
	Geom::BoundingBox<PFP::VEC3> bb;

Pierre Kraemer's avatar
Pierre Kraemer committed
64

David Cazier's avatar
David Cazier committed
65

pitiot's avatar
pitiot committed
66 67 68
// Enregistrement Aretes//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
    void FindNeighborCellsOfSegment (const std::vector<Dart>& belonging_cells, std::vector<Dart> * nieghbor_cells);
pitiot's avatar
init  
pitiot committed
69
//
pitiot's avatar
pitiot committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    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);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




//MULTIRES/////////////////////////////////////////////////////////////////////////////
Pierre Kraemer's avatar
Pierre Kraemer committed
86

pitiot's avatar
init  
pitiot committed
87 88
//	static const unsigned int nbAgentsToSubdivide = 1 ;
//	static const unsigned int nbAgentsToSimplify = 0 ;
pitiot's avatar
pitiot committed
89 90 91
//	void refine() ;
//	void coarse() ;
//	void updateMap() ;
pitiot's avatar
init  
pitiot committed
92 93 94 95
//	CellMarker<FACE> refineMark ;
//	CellMarker<FACE> coarsenMark ;
//	std::vector<Dart> refineCandidate ;
//	std::vector<Dart> coarsenCandidate ;
pitiot's avatar
pitiot committed
96
///////////////////////////////////////////////////////////////////////////////////////
pitiot's avatar
maj  
pitiot committed
97 98


99
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100

pitiot's avatar
pitiot committed
101 102 103 104 105 106
//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
107

pitiot's avatar
maj  
pitiot committed
108

Pierre Kraemer's avatar
Pierre Kraemer committed
109
/**************************************
David Cazier's avatar
David Cazier committed
110 111
 *           INLINE FUNCTIONS          *
 **************************************/
pitiot's avatar
pitiot committed
112
//////////////////// BASIC OPERATIONS ////////////////////////////////////////////////////////////////
113 114 115 116 117 118 119
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
120
template <typename T>
pitiot's avatar
maj  
pitiot committed
121
inline bool removeElementFromVector(std::vector<T>& a, T ag)
Pierre Kraemer's avatar
Pierre Kraemer committed
122
{
123 124
	assert(std::find(a.begin(), a.end(), ag) != a.end());

125
	typename std::vector<T>::iterator end = a.template end() ;
David Cazier's avatar
David Cazier committed
126 127 128 129
	for (typename std::vector<T>::iterator it = a.begin(); it != end; ++it)
	{
		if (*it == ag)
		{
130 131
			*it = a.back() ;
			a.pop_back() ;
pitiot's avatar
maj  
pitiot committed
132
			return true ;
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134
		}
	}
pitiot's avatar
maj  
pitiot committed
135
	return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137
}

pitiot's avatar
pitiot committed
138
///////////////////////////////////////////////////////////////MULTIRES
pitiot's avatar
init  
pitiot committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
//
//inline void EnvMap::nbAgentsIncrease(Dart d)
//{
//	if (refineMark.isMarked(d)) return ;
//	if (totalNeighborSize(d) < nbAgentsToSubdivide) return ;
//
//	std::pair<bool, bool>& sf = subdivisableFace[d] ;
//	if (sf.first == false || (sf.first == true && sf.second))
//	{
//		refineMark.mark(d) ;
//		refineCandidate.push_back(d) ;
//	}
//}
//
//inline void EnvMap::nbAgentsDecrease(Dart d)
//{
//	if (coarsenMark.isMarked(d) || refineMark.isMarked(d)) return ;
//	if (totalNeighborSize(d) > nbAgentsToSimplify) return ;
//
//	coarsenMark.mark(d) ;
//	coarsenCandidate.push_back(map.faceOldestDart(d)) ;
//}
David Cazier's avatar
David Cazier committed
161

pitiot's avatar
pitiot committed
162
//inline void EnvMap::clearUpdateCandidates()
pitiot's avatar
init  
pitiot committed
163
//{
pitiot's avatar
pitiot committed
164 165
//	refineCandidate.clear() ;
//	coarsenCandidate.clear() ;
pitiot's avatar
init  
pitiot committed
166
//}
pitiot's avatar
pitiot committed
167
/////////////////////////////////////////////////////////////////////REGISTRATIONS
David Cazier's avatar
David Cazier committed
168

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

pitiot's avatar
pitiot committed
172
    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
173

pitiot's avatar
pitiot committed
174 175 176 177 178
    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
179

180

pitiot's avatar
pitiot committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194
inline void EnvMap::FindNeighborCellsOfSegment (const std::vector<Dart>& belonging_cells, std::vector<Dart> *neighbor_cells)
{
    assert(map.getCurrentLevel() == map.getMaxLevel());
    assert(!belonging_cells.empty());
    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);

    std::vector<Dart>::const_iterator it=belonging_cells.begin();
    Dart dd=NIL;
//	CGoGNout<<"debut neighbors cellules : ";
pitiot's avatar
pitiot committed
195
//	for (std::vector<Dart>::const_iterator it =belonging_cells.begin();it<belonging_cells.end();++it)
pitiot's avatar
pitiot committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
//		CGoGNout<<(*it).index<<" ; ";
//	CGoGNout<<CGoGNendl;

    do
    {
        dd = *it;
        Traversor* tra = TraversorFactory<PFP::MAP>::createAdjacent(map,dd, 3, 4, 1);
        for (Dart d = tra->begin(); d != tra->end(); d = tra->next())
        {
            if (!map.isBoundaryMarked<3>(d) && !memo_mark.isMarked(d) && !OneRingMark.isMarked(d) )
            {
                OneRingMark.mark(d);
                (*neighbor_cells).push_back(d);
            }
        }
        tra->~Traversor();
        ++it;
    }while(it!=belonging_cells.end());

}


inline void EnvMap::pushSegmentInCellAsNeighbor(Segment* o, Dart d)
{
    assert(map.getCurrentLevel() == map.getMaxLevel());
    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)
{
    assert(map.getCurrentLevel() == map.getMaxLevel());
    assert(std::find(RegisteredNeighborEdges[d].begin(), RegisteredNeighborEdges[d].end(), o) != RegisteredNeighborEdges[d].end());

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



237

Pierre Kraemer's avatar
Pierre Kraemer committed
238 239

#endif