env_map.cpp 32.2 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
#include "env_map.h"
pitiot's avatar
pitiot committed
2
#include "MovingObject.h"
Thomas Pitiot 's avatar
Thomas Pitiot committed
3
#include "surface.h"
pitiot's avatar
pitiot committed
4
#include "segment.h"
5
using namespace CGoGN ;
Pierre Kraemer's avatar
Pierre Kraemer committed
6

7

pitiot's avatar
init    
pitiot committed
8
EnvMap::EnvMap()
Pierre Kraemer's avatar
Pierre Kraemer committed
9
{
Pierre Kraemer's avatar
Pierre Kraemer committed
10

pitiot's avatar
init    
pitiot committed
11

Jund Thomas's avatar
Jund Thomas committed
12

Pierre Kraemer's avatar
Pierre Kraemer committed
13
#ifndef SPATIAL_HASHING
Thomas's avatar
Thomas committed
14

Thomas Pitiot 's avatar
Thomas Pitiot committed
15
16
17
    //	RegisteredEdges = map.addAttribute<PFP::SegmentVECT, FACE>("Segments") ;
    //	neighborRegisteredEdges = map.addAttribute<PFP::SegmentVECT, FACE>("neighborSegments") ;
    //	subdivisableFace = map.addAttribute<PFP::BOOLATTRIB, FACE>("subdivisableFace") ;
pitiot's avatar
init    
pitiot committed
18

Thomas Pitiot 's avatar
Thomas Pitiot committed
19
20
    //	refineCandidate.reserve(100) ;
    //	coarsenCandidate.reserve(100) ;
21
22
23
#endif
}

pitiot's avatar
init    
pitiot committed
24
void EnvMap::init(int argc, char **argv)
25
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
26
    maxCellRay = 1.0f;
27
28
29
30
31
32
33
    mapMinX=0;
    mapMaxX=0;
    mapMinY=0;
    mapMaxY=0;
    mapMinZ=0;
    mapMaxZ=0;

Thomas Pitiot 's avatar
Thomas Pitiot committed
34
    std::cout << "Init EnvMap" << std::endl ;
pitiot's avatar
pitiot committed
35
    if (argc>2)
Thomas Pitiot 's avatar
Thomas Pitiot committed
36
    {
pitiot's avatar
pitiot committed
37
        std::string filename(argv[2]);
pitiot's avatar
pitiot committed
38
        open_file(filename);
Thomas Pitiot 's avatar
Thomas Pitiot committed
39
40
41
42
    }
    else
    {
        //Intialisation map
pitiot's avatar
pitiot committed
43
44
45
#ifdef IHMap
        map.initImplicitProperties();  // Si map MR
#endif
pitiot's avatar
init    
pitiot committed
46

pitiot's avatar
pitiot committed
47
48
49

        ///// initialisation attributs
        position = map.addAttribute<VEC3, VERTEX, MAP>("position");
pitiot's avatar
up    
pitiot committed
50
        facecenter = map.addAttribute<VEC3, FACE, MAP>("facecenter");
pitiot's avatar
pitiot committed
51
52
53
        color = map.addAttribute<VEC3, VOLUME, MAP>("color");
        RegisteredEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredEdges");
        RegisteredNeighborEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredNeighborEdges");
Thomas Pitiot 's avatar
Thomas Pitiot committed
54
55
        RegisteredTriangles=map.addAttribute<TRIANGLES,VOLUME, MAP>("RegisteredTriangles");
        RegisteredNeighborTriangles=map.addAttribute<TRIANGLES,VOLUME, MAP>("RegisteredNeighborTriangles");
pitiot's avatar
pitiot committed
56
57


58
        int nb = 1;
pitiot's avatar
pitiot committed
59
        Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(map, nb, nb, nb);
pitiot's avatar
pitiot committed
60
        cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
pitiot's avatar
pitiot committed
61

Thomas Pitiot 's avatar
Thomas Pitiot committed
62
//        map.check();
pitiot's avatar
pitiot committed
63
64


pitiot's avatar
pitiot committed
65
66
67
68
        TraversorV<MAP> tv(map);
        for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
        {
            position[d] *= 10;
69
70
71
72
73
74
            if(position[d][0]<mapMinX) mapMinX=position[d][0];
            if(position[d][0]>mapMaxX) mapMaxX=position[d][0];
            if(position[d][1]<mapMinY) mapMinY=position[d][1];
            if(position[d][1]>mapMaxY) mapMaxY=position[d][1];
            if(position[d][2]<mapMinZ) mapMinZ=position[d][2];
            if(position[d][2]>mapMaxZ) mapMaxZ=position[d][2];
pitiot's avatar
pitiot committed
75
        }
pitiot's avatar
up    
pitiot committed
76
77
78
79
80
81
82
        TraversorF<MAP> tf(map);
        for(Dart d = tf.begin() ; d != tf.end() ; d = tf.next())
        {

            facecenter[d]=Algo::Surface::Geometry::faceCentroid<PFP, VertexAttribute<VEC3, MAP>>(map,d,position);

        }
pitiot's avatar
pitiot committed
83
84
85
86
87
88
89

        TraversorW<MAP> tra(map);
        for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
        {
            color[d] = position[d]/10 + VEC3(0.5,0.5,0.5);
        }

pitiot's avatar
pitiot committed
90

pitiot's avatar
up    
pitiot committed
91
    }
pitiot's avatar
pitiot committed
92

pitiot's avatar
up    
pitiot committed
93
}
pitiot's avatar
pitiot committed
94

pitiot's avatar
up    
pitiot committed
95
96
97
REAL EnvMap::volumeMaxdistance(Vol volume)
{
    Dart d = volume;
98

pitiot's avatar
up    
pitiot committed
99
    VEC3 center = Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,volume,position);
100

pitiot's avatar
up    
pitiot committed
101
102
103
104
105
106
107
108
109
110
    REAL res = (position[d]-center).norm2();
    for ( Vertex vert : verticesIncidentToVolume3(map,volume))
    {
        REAL size=(position[vert]-center).norm2();
        if(size>res)
        {
            res=size;
        }
    }
    return res;
pitiot's avatar
pitiot committed
111
112
}

pitiot's avatar
pitiot committed
113
VEC3 EnvMap::normaleFromVolume(Dart volume,Dart face) // renvoie la normale a la face pointant vers l'extérieur du volume
pitiot's avatar
up    
pitiot committed
114
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
115
116
117
118
119
    VEC3 center = Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,volume,position);
    VEC3 norm = Algo::Surface::Geometry::faceNormal<PFP, VertexAttribute<VEC3, MAP>>(map,face,position);
    VEC3 temp =center-facecenter[face];
    if(norm*temp>0) norm*=-1;
    return norm;
pitiot's avatar
up    
pitiot committed
120
121
}

pitiot's avatar
pitiot committed
122
bool EnvMap::checkPointInMap(VEC3 pos,Dart neighborhood) // definit si le point pos est dans le voisinage interne a la carte du volume "neighborhood"
pitiot's avatar
up    
pitiot committed
123
124
125
{
    if(insideVolume(pos, neighborhood))
        return true;
pitiot's avatar
pitiot committed
126
127

    for (Vol d : volumesAdjacentByVertex3(map,neighborhood))
pitiot's avatar
up    
pitiot committed
128
129
130
131
132
133
134
    {
        if (!map.isBoundaryMarked<3>(d) )
        {
            if(insideVolume(pos, d))
                return true;
        }
    }
pitiot's avatar
pitiot committed
135
136


pitiot's avatar
up    
pitiot committed
137
138
139
    return false;
}

pitiot's avatar
pitiot committed
140
bool EnvMap::insideVolume(VEC3 pos, Dart volume) // définit si le point pos est dans le volume convexe
pitiot's avatar
up    
pitiot committed
141
142
{

pitiot's avatar
pitiot committed
143
144

    for(Face d : facesIncidentToVolume3(map,volume))
pitiot's avatar
up    
pitiot committed
145
146
147
148
149
150
151
152
153
154
155
    {
        VEC3 normal = normaleFromVolume(volume,d);
        VEC3 center = facecenter[d];
        VEC3 dirPoint = pos-center;

        if(normal*dirPoint>0)
            return false;
    }


    return true;
pitiot's avatar
pitiot committed
156
157


pitiot's avatar
up    
pitiot committed
158
159
160
161
}



pitiot's avatar
pitiot committed
162
163
164
165
166





pitiot's avatar
pitiot committed
167
///// a coder
pitiot's avatar
up    
pitiot committed
168

pitiot's avatar
pitiot committed
169
170
Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
171
172
173
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
pitiot's avatar
pitiot committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

    CellMarkerStore<MAP, VOLUME> m(map) ;
    for (Dart d = map.begin(); d != map.end(); map.next(d))
    {
        if (!m.isMarked(d))
        {
            m.mark(d) ;
            if (insideVolume(pos, d))
                return d ;
        }
    }

    std::cout << "ERROR : pos not in map for getBelongingCell " << pos << std::endl ;
    return map.begin() ;
}
pitiot's avatar
up    
pitiot committed
189
190


191
192
193



Thomas's avatar
Thomas committed
194
195
196
197




pitiot's avatar
init    
pitiot committed
198
199
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
200
{
pitiot's avatar
pitiot committed
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
    map.clear(true);
    std::vector<std::string> attrNames ;

    size_t pos = filename.rfind(".");    // position of "." in filename
    std::string extension = filename.substr(pos);

    if(extension == std::string(".off"))
    {
        if(!Algo::Volume::Import::importMeshToExtrude<PFP>(map, filename, attrNames))
        {
            std::cerr << "could not import " << filename << std::endl ;

        }
        else
        {
            position = map.getAttribute<VEC3, VERTEX, MAP>(attrNames[0]) ;
            map.closeMap();
        }
    }
    else
    {


        if(extension == std::string(".map"))
        {
            map.loadMapBin(filename);
            position = map.getAttribute<VEC3, VERTEX, MAP>("position") ;
        }
        else
        {
            //			if(!Algo::Volume::Import::importMesh<PFP>(map, filename, attrNames))
            //			{
            //				std::cerr << "could not import " << filename << std::endl ;
            //				return ;
            //			}
            //			else
            //                position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
        }

        color = map.addAttribute<VEC3, VOLUME, MAP>("colorVol");

        TraversorCell<MAP, VOLUME> tra(map);
        float maxV = 0.0f;
        for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
        {
            float v = Algo::Geometry::tetrahedronVolume<PFP>(map, d, position);
            color[d] = VEC3(v,0,0);
            if (v>maxV)
                maxV=v;

            //			if(envMap.map.isVolumeIncidentToBoundary(d))
            //				color[d] = VEC3(0,0,0);
            //			else
            color[d] = VEC3(v,0,0);
        }

        for (unsigned int i = color.begin(); i != color.end(); color.next(i))
        {
            color[i][0] /= maxV;
            color[i][2] = 1.0f - color[i][0];
        }
    }
Pierre Kraemer's avatar
Pierre Kraemer committed
263
}
Thomas Pitiot 's avatar
Thomas Pitiot committed
264
//////////////////////////////////enregistrement des segments
Pierre Kraemer's avatar
Pierre Kraemer committed
265

pitiot's avatar
pitiot committed
266
267
void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en question
{
pitiot's avatar
init    
pitiot committed
268

pitiot's avatar
pitiot committed
269
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
270
271
    if (mo != NULL)
    {
pitiot's avatar
pitiot committed
272
        int n1 = o->indexPart1;
273
//        int n2 = o->indexPart2;
pitiot's avatar
pitiot committed
274
#ifdef DEBUG_affichage
pitiot's avatar
up    
pitiot committed
275
        CGoGNout<<"First Registration arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
276
277
278
279
#endif
        VEC3 p1 = o->p1;
        VEC3 p2 =  o->p2;

280
        Dart d1=mo->parts_[n1]->d;
281
//        Dart d2=mo->parts_[n2]->d;
pitiot's avatar
pitiot committed
282
        std::vector<Dart> memo;
pitiot's avatar
pitiot committed
283
284


pitiot's avatar
pitiot committed
285
286
        memo = getMemoCross(p1,p2,d1);

Etienne Schmitt's avatar
Etienne Schmitt committed
287
        if(memo.size() == 1u)
pitiot's avatar
pitiot committed
288
289
290
291
292
293
294
295
296
297
298
299
300
301
        {
            pushAOneCellSegment(o , d1);
        }
        else
        {

            pushSegmentInSetOfCells(o, memo);
        }
    }
}

Dart EnvMap::popAndPushSegment(Segment* o)// maj de l'enregistrement
{
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
302
    CGoGNout<<"pop&push arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
303
304
305
306
#endif
    popSegment(o);
    FirstRegistrationSegment(o);

Etienne Schmitt's avatar
Etienne Schmitt committed
307
    return o->nid->parts_[o->indexPart1]->d;
pitiot's avatar
pitiot committed
308
309
310
311
312
}

void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
    int n = o->index;
pitiot's avatar
pitiot committed
313
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
314
315
316
#ifdef DEBUG_affichage
    CGoGNout<<"Push in one cell segment arete "<<n<<CGoGNendl;
#endif
Thomas Pitiot 's avatar
Thomas Pitiot committed
317
#ifdef IHMap
pitiot's avatar
pitiot committed
318
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
319
#endif
320
    d=map.volumeOldestDart(d);
Etienne Schmitt's avatar
Etienne Schmitt committed
321
    addElementToVector(RegisteredEdges[d],o);
pitiot's avatar
pitiot committed
322
323

    mo->belonging_cells[n].push_back(d);
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
324
    mo->addGeneralCell (d);
pitiot's avatar
pitiot committed
325
    for (Vol volume : volumesAdjacentByVertex3(map,d))
pitiot's avatar
pitiot committed
326
    {
pitiot's avatar
pitiot committed
327
        if (!map.isBoundaryMarked<3>(volume))
pitiot's avatar
pitiot committed
328
        {
pitiot's avatar
pitiot committed
329
            pushSegmentInCellAsNeighbor(o, volume);
Thomas Pitiot 's avatar
Thomas Pitiot committed
330
            mo->neighbor_cells[n].push_back(volume);
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
331
            mo->addGeneralNeighbor ( d);
pitiot's avatar
pitiot committed
332
333
334
        }
    }

pitiot's avatar
pitiot committed
335
336
#ifdef DEBUG_affichage
    CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
337
338
339
340
341
342
343
    //    if(mo->neighbor_cells[n].size()>26)
    //    {
    //        for(auto d : mo->neighbor_cells[n])
    //        {
    //            CGoGNout<<" || "<<d<<" || "<<CGoGNendl;
    //        }
    //    }
pitiot's avatar
up    
pitiot committed
344

pitiot's avatar
pitiot committed
345
#endif
pitiot's avatar
pitiot committed
346
347
348
349
350
351
352
353
}

void EnvMap::pushSegmentInSetOfCells(Segment* o, const std::vector<Dart>& memo_cross)
{
    int n = o->index;
#ifdef DEBUG_affichage
    CGoGNout<<"Push in set of cells segment arete "<<n<<CGoGNendl;
#endif
Thomas Pitiot 's avatar
Thomas Pitiot committed
354
    //    assert( memo_cross.size() > 1);
pitiot's avatar
pitiot committed
355
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
356
357


358
359
360
361
362
363
    for (Dart d :memo_cross)
    {
        d=map.volumeOldestDart(d);
        mo->belonging_cells[n].push_back(d);
        addElementToVector(RegisteredEdges[d],o);
        mo->addGeneralCell (d);
pitiot's avatar
pitiot committed
364
#ifdef DEBUG_affichage
365
        CGoGNout<<"cellule du belong :"<<(d)<<CGoGNendl;
pitiot's avatar
pitiot committed
366
#endif
pitiot's avatar
pitiot committed
367
368

    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
369
    FindNeighborCells(mo->belonging_cells[n], &(mo->neighbor_cells[n]));
pitiot's avatar
pitiot committed
370

371
    for (Dart d : mo->neighbor_cells[n])
pitiot's avatar
pitiot committed
372
    {
373
374
375
            addElementToVector<Segment*>(RegisteredNeighborEdges[d],o);
             mo->addGeneralNeighbor ( (d));

pitiot's avatar
pitiot committed
376
    }
pitiot's avatar
pitiot committed
377
378
#ifdef DEBUG_affichage
    CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
379
380
381
382
383
384
385
    //    if(mo->neighbor_cells[n].size()>26)
    //    {
    //        for(auto d : mo->neighbor_cells[n])
    //        {
    //            CGoGNout<<" || "<<d<<" || "<<CGoGNendl;
    //        }
    //    }
pitiot's avatar
up    
pitiot committed
386

pitiot's avatar
pitiot committed
387
#endif
pitiot's avatar
pitiot committed
388
389
390
391
}

void EnvMap::popSegment(Segment* o)
{
pitiot's avatar
pitiot committed
392
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
393
    int n = o->index;
Thomas Pitiot 's avatar
Thomas Pitiot committed
394
395
396
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
pitiot's avatar
pitiot committed
397
398
399

    if (mo != NULL)
    {
400
        for (Dart d : mo->belonging_cells[n])
pitiot's avatar
pitiot committed
401
        {
402
403
            removeElementFromVector(RegisteredEdges[d], o) ;
            mo->removeGeneralCell (d);
pitiot's avatar
pitiot committed
404
        }
405
        for (Dart d : mo->neighbor_cells[n])
pitiot's avatar
pitiot committed
406
        {
407
408
409
                removeElementFromVector(RegisteredNeighborEdges[d], o) ;
                mo->removeGeneralNeighbor (d);

pitiot's avatar
pitiot committed
410
411
412
413
414
        }
        mo->belonging_cells[n].clear();
        mo->neighbor_cells[n].clear();
    }
}
pitiot's avatar
up    
pitiot committed
415
416


Thomas Pitiot 's avatar
Thomas Pitiot committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/////////////////////////////enregistrement des triangles



void EnvMap::FirstRegistrationTriangle(Triangle * o)// réenregistre l'Triangle en question
{

    Surface * mo = o->surf;

    if (mo != NULL)
    {
#ifdef DEBUG_affichage
        CGoGNout<<"First Registration Triangle "<<o->d<<CGoGNendl;
#endif
        CellMarkerMemo<MAP, VOLUME> inside(map);
        CellMarkerMemo<MAP, VOLUME> neighbor(map);
        Dart cell =o->cell;
        std::vector<Dart> memo;

Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
436
        for(Edge e : edgesIncidentToFace2<SURFACE>(mo->surfaceMap,cell)) // first mark inside
Thomas Pitiot 's avatar
Thomas Pitiot committed
437
438
439
440
        {
            Dart cell2=mo->surfaceMap.phi1(e);
            // on récupère les aprticules correspondant a chaque edge du triangle a enregistrer

Etienne Schmitt's avatar
Etienne Schmitt committed
441
            Particule * p1 = mo->parts_[mo->indexParticule[cell]];
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
442

Thomas Pitiot 's avatar
Thomas Pitiot committed
443
444

            Dart d1=p1->d; // darts de la carte 3D contenant les particules
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
445
            memo = getMemoCross(p1->getPosition(),mo->positionSurface[cell2],d1);
Thomas Pitiot 's avatar
Thomas Pitiot committed
446

Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
447
448
            for (Dart d : memo)
                   inside.mark(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
449
450
451

        }

Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
452
453
454


        for(Dart d : inside.get_markedCells()) // and register them
Thomas Pitiot 's avatar
Thomas Pitiot committed
455
        {
456
            d=map.volumeOldestDart(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
457
            pushTriangleInCell(o,d);
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
458
459
            (mo->belonging_cells[o->indexTri]).push_back(d);
            mo->addGeneralCell ( d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
460
        }
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
461
462
        markNeighbors(&inside,&neighbor,(mo->belonging_cells[o->indexTri])); // then mark neighbors
        for(Dart d : neighbor.get_markedCells())    // and register them
Thomas Pitiot 's avatar
Thomas Pitiot committed
463
        {
464
            d=map.volumeOldestDart(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
465
            pushTriangleInCellAsNeighbor(o,d);
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
466
467
            (mo->neighbor_cells[o->indexTri]).push_back(d);
            mo->addGeneralNeighbor ( d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
468
469
470
471
472
473
474
        }


    }
}


Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
475
void EnvMap::markNeighbors(CellMarkerMemo<MAP,VOLUME> * memo_mark, CellMarkerMemo<MAP,VOLUME>* OneRingMark, const std::vector<Dart>& memo_cross) // enregistrer une dart dans un ensemble de cellules
Thomas Pitiot 's avatar
Thomas Pitiot committed
476
477
478
479
480
481
482
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(!memo_cross.empty());


Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
483
    for(Dart  e : memo_cross)
Thomas Pitiot 's avatar
Thomas Pitiot committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
    {

        for (Vol d : volumesAdjacentByVertex3(map,e))
        {

            if (!map.isBoundaryMarked<3>(d) && !memo_mark->isMarked(d)  )
            {
                OneRingMark->mark(d);

            }
        }

    }
}


void EnvMap::popAndPushTriangle(Triangle* o)// maj de l'enregistrement
{
#ifdef DEBUG_affichage
    CGoGNout<<"pop&push arete "<<o->index<<CGoGNendl;
#endif
    popTriangle(o);
    FirstRegistrationTriangle(o);


}

void EnvMap::popTriangle(Triangle* o)
{
    Surface * mo = o->surf;
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    if (mo != NULL)
    {
        Dart cell =o->cell;

        int n = mo->indexTriangle[cell];



525
        for (Dart d : mo->belonging_cells[n])
Thomas Pitiot 's avatar
Thomas Pitiot committed
526
        {
527
528
            popTriangleInCell(o,d);
            mo->removeGeneralCell (d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
529
        }
530
        for (Dart d : mo->neighbor_cells[n])
Thomas Pitiot 's avatar
Thomas Pitiot committed
531
        {
532
533
534
535

                popTriangleInCellAsNeighbor(o,d);
                mo->removeGeneralNeighbor (d);

Thomas Pitiot 's avatar
Thomas Pitiot committed
536
537
538
539
540
541
        }
        mo->belonging_cells[n].clear();
        mo->neighbor_cells[n].clear();
    }
}

Thomas Pitiot 's avatar
Thomas Pitiot committed
542
bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
pitiot's avatar
up    
pitiot committed
543
{
544
545
546
    bool res =false;
#ifdef IHMap

pitiot's avatar
up    
pitiot committed
547

548
    map.setCurrentLevel(map.getMaxLevel()) ;
549
550
    unsigned int vLevel = map.volumeLevel(dglobal);
    Dart old = map.volumeOldestDart(dglobal);
pitiot's avatar
up    
pitiot committed
551
552
553
#ifdef DEBUG_affichage
    int count = 0;
#endif
554
555
    // la subdivision ne doit pas mettre plus d'un level de différence entre des cellules adjacentes
    // on commence donc par subdiviser les voisins qui ont trop de différence
pitiot's avatar
up    
pitiot committed
556
557
558
//    Traversor3WF<typename PFP::MAP> traF(map, old, true);
//    for(Dart dit = traF.begin(); dit != traF.end(); dit = traF.next())
//    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
559
    if(OneLevelDifference)
560
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
561
        for ( Face dit : facesIncidentToVolume3(map,old))
562
        {
Thomas Pitiot 's avatar
Thomas Pitiot committed
563
564
565
566
567
    #ifdef DEBUG_affichage
            count++;
    #endif
            Dart nv = map.phi3(dit);
            if(!map.isBoundaryMarked(3, nv))
568
            {
Thomas Pitiot 's avatar
Thomas Pitiot committed
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
                if(map.volumeLevel(nv) == vLevel - 1)
                {
    #ifdef DEBUG_affichage
                    std::cout << "OK pour cascade en : "<<nv<< std::endl;
    #endif
                    int currentLevel = map.getCurrentLevel();
                    subdivideVolume(nv);
                    map.setCurrentLevel(currentLevel);
                }
                else if(!map.volumeIsSubdivided(nv))  //check if neighboring volumes have to be subdivided first to avoid one cell surrounded by subdivided ones
                {

                    if(map.checkForSurrounded(nv))
                    {

                        subdivideVolume(nv,false);

                    }
                }
588
589
            }
        }
590
591
    }

pitiot's avatar
up    
pitiot committed
592

Etienne Schmitt's avatar
Etienne Schmitt committed
593
     const std::chrono::time_point<std::chrono::system_clock> startPop = std::chrono::system_clock::now();
594
    // on commence ensuite a subdiviser
Thomas Pitiot 's avatar
Thomas Pitiot committed
595
//    map.check();
596
    map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
up    
pitiot committed
597

Thomas Pitiot 's avatar
Thomas Pitiot committed
598
    const ARETES oldobst(RegisteredEdges[dglobal]) ;
599
600
601
602
603
604

    for (Segment * o : oldobst)
    {
        this->popSegment(o) ;
    }

Thomas Pitiot 's avatar
Thomas Pitiot committed
605
    ARETES oldNeighborObst(RegisteredNeighborEdges[old]) ;
pitiot's avatar
up    
pitiot committed
606

607
608
    for (Segment * o : oldNeighborObst)
    {
609
//        this->popSegment(o) ; // old version
Etienne Schmitt's avatar
Etienne Schmitt committed
610
//        removeElementFromVector(RegisteredNeighborEdges[old], o) ;
611
612
        removeElementFromVector(o->nid->neighbor_cells[o->index],old);
        o->nid->removeGeneralNeighbor (old);
613
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
614
    RegisteredNeighborEdges[old].clear();
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
615

Thomas Pitiot 's avatar
Thomas Pitiot committed
616
    const TRIANGLES oldTrian(RegisteredTriangles[dglobal]) ;
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
617
618
619
620
621
622

    for (Triangle * o : oldTrian)
    {
        this->popTriangle(o) ;
    }

Thomas Pitiot 's avatar
Thomas Pitiot committed
623
    TRIANGLES oldTrianNeighbor(RegisteredNeighborTriangles[old]) ;
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
624
625
626

    for (Triangle * o : oldTrianNeighbor)
    {
627
//        this->popTriangle(o) ; // old version
Etienne Schmitt's avatar
Etienne Schmitt committed
628
//        removeElementFromVector(RegisteredNeighborTriangles[old], o) ;
629
630
        removeElementFromVector(o->surf->neighbor_cells[o->indexTri],old);
        o->surf->removeGeneralNeighbor (old);
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
631
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
632
    RegisteredNeighborTriangles[old].clear();
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
633

Etienne Schmitt's avatar
Etienne Schmitt committed
634
635
    const std::chrono::time_point<std::chrono::system_clock> endPop = std::chrono::system_clock::now();
    duration_pop = endPop - startPop;
636
    if(duration_pop.count()>0.035)std::cout << "pop duration : " << duration_pop.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
637
638
639

    const std::chrono::time_point<std::chrono::system_clock> startSubdiv = std::chrono::system_clock::now();

Thomas Pitiot 's avatar
Thomas Pitiot committed
640
    if(!map.isBoundaryMarked(3,dglobal) && map.getDartLevel(dglobal) <= map.getMaxLevel() && !map.volumeIsSubdivided(dglobal) )
pitiot's avatar
up    
pitiot committed
641
    {
642
        Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position,false);
pitiot's avatar
up    
pitiot committed
643
        res=true;
pitiot's avatar
up    
pitiot committed
644
645
    }

Etienne Schmitt's avatar
Etienne Schmitt committed
646
647
    const std::chrono::time_point<std::chrono::system_clock> endSubdiv = std::chrono::system_clock::now();
    duration_subdiv = endSubdiv - startSubdiv;
648
    if(duration_subdiv.count()>0.035)std::cout << "subdiv duration : " << duration_subdiv.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
649

650
651
652
653
654
655
656
657
658
659
    map.setCurrentLevel(vLevel+1);
    CellMarkerMemo<MAP,VOLUME> newVolumes(map);
    Dart start = old;
    do                  // on marque les nouvelles cellules ! attention TODO cas des volumes qui n'ont aucune arete en commun avec le volume d'origine
    {
        map.setCurrentLevel(vLevel+1);
        newVolumes.mark(start);
        map.setCurrentLevel(vLevel);
        start=map.phi1(start);
    }while(start !=old);
Etienne Schmitt's avatar
Etienne Schmitt committed
660

pitiot's avatar
up    
pitiot committed
661
    map.setCurrentLevel(map.getMaxLevel()) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
662
663
    //    map.check();

664
665
666
667



    for (Dart d : newVolumes.get_markedCells())
Thomas Pitiot 's avatar
Thomas Pitiot committed
668
    {
669
        for ( Face f : facesIncidentToVolume3(map,d)) // maj des attributs de face et volume de la carte
Thomas Pitiot 's avatar
Thomas Pitiot committed
670
671
672
673
        {
            facecenter[f]=Algo::Surface::Geometry::faceCentroid<PFP, VertexAttribute<VEC3, MAP>>(map,f,position);

        }
674
675
        VEC3 center=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d,position);
        color[d] = VEC3((center[0]-mapMinX)/(mapMaxX-mapMinX),(center[1]-mapMinY)/(mapMaxY-mapMinY),(center[2]-mapMinZ)/(mapMaxZ-mapMinZ));
Thomas Pitiot 's avatar
Thomas Pitiot committed
676

677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698

        // reenregistrement des voisins
        for(Vol v : volumesAdjacentByVertex3(map,d))
        {
            if(!newVolumes.isMarked(v))
            {
                for(Segment * s : RegisteredEdges[v])
                {
                    if(addElementToVector(RegisteredNeighborEdges[d],s))
                    {
                           s->nid->neighbor_cells[s->index].push_back(d);
                    }
                }
                for(Triangle * t : RegisteredTriangles[v])
                {
                    if(addElementToVector(RegisteredNeighborTriangles[d],t))
                    {
                           t->surf->neighbor_cells[t->indexTri].push_back(d);
                    }
                }
            }
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
699
700
    }

Etienne Schmitt's avatar
Etienne Schmitt committed
701
702
    const std::chrono::time_point<std::chrono::system_clock> startPush = std::chrono::system_clock::now();

703
704
705
706
707
708
709
710


//    //same for adjacent triangles // optimiser
//    for (Triangle * o : oldTrianNeighbor)
//    {
////        this->FirstRegistrationTriangle(o) ; // old version

//    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
711

Etienne Schmitt's avatar
Etienne Schmitt committed
712

Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
713
714
715
716
717
718
    //same for triangles // optimiser
    for (Triangle * o : oldTrian)
    {
        resetPartSubdiv(o);
        this->FirstRegistrationTriangle(o) ;
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
719

Etienne Schmitt's avatar
Etienne Schmitt committed
720
721
    const std::chrono::time_point<std::chrono::system_clock> endPushTriangle = std::chrono::system_clock::now();

Thomas Pitiot 's avatar
Thomas Pitiot committed
722

723
724
725
726
727
//    //same for adjacent obstacles // optimiser
//    for (Segment * o : oldNeighborObst)
//    {
////        FirstRegistrationSegment(o) ; // old version
//    }
728
729

    const std::chrono::time_point<std::chrono::system_clock> endPushSegmentNeighbors = std::chrono::system_clock::now();
pitiot's avatar
up    
pitiot committed
730
    //same for obstacles contained
731
    for (Segment * o : oldobst)
pitiot's avatar
up    
pitiot committed
732
    {
733
734
        resetPartSubdiv(o);
        FirstRegistrationSegment(o);
pitiot's avatar
up    
pitiot committed
735
736
737

    }

Etienne Schmitt's avatar
Etienne Schmitt committed
738
739
    const std::chrono::time_point<std::chrono::system_clock> endPush = std::chrono::system_clock::now();
    duration_push = endPush - startPush;
740
741
742
743
744
    std::chrono::duration<double> duration_triangle= (endPushTriangle - startPush);
    std::chrono::duration<double> duration_segment= (endPush - endPushSegmentNeighbors);
    std::chrono::duration<double> duration_segmentNeighbor= (endPushSegmentNeighbors - endPushTriangle);
     if(duration_triangle.count()>0.035)std::cout << "push triangle duration : " << duration_triangle.count()  << "s\n";
    if(duration_push.count()>0.035)std::cout << "push duration : " << duration_push.count() << "\n dont pour les segments présents : "<<duration_segment.count() <<"s\n et pour les voisins :"<<duration_segmentNeighbor.count() <<"s\n";
pitiot's avatar
up    
pitiot committed
745
746


pitiot's avatar
up    
pitiot committed
747
748
#endif
    return res;
pitiot's avatar
up    
pitiot committed
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765

}

void EnvMap::resetPartSubdiv(Segment* o)
{

    ArticulatedObject * mo = o->nid;

    if (mo != NULL)
    {

        VEC3 pos = mo->parts_[o->indexPart1]->getPosition();
        VEC3 pos2 = mo->parts_[o->indexPart2]->getPosition();
        Dart d1 =mo->parts_[o->indexPart1]->d;
        Dart d2 =mo->parts_[o->indexPart2]->d;

#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
766
767
        CGoGNout<<"Reset part subdiv (index articul , segment ,ind1, pos1, d1, ind2, pos2, d2) : "<<mo->index_articulated<<" || "<<o->index<<" || "<<o->indexPart1<<" || "<<pos<<" || "<<d1<<" || "<<o->indexPart2<<" || "<<pos2<<" || "<<d2<<CGoGNendl;
        CGoGNout<<"Faces centroids : "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)<<" || "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)<<CGoGNendl;
pitiot's avatar
up    
pitiot committed
768
769
770
771

#endif

        mo->parts_[o->indexPart1]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
772
        mo->parts_[o->indexPart1]->reset_positionFace();
pitiot's avatar
up    
pitiot committed
773
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
774
        CGoGNout<<"part1 moved to centroid ,d : "<< mo->parts_[o->indexPart1]->getPosition()<<" || "<<mo->parts_[o->indexPart1]->d<<CGoGNendl;
pitiot's avatar
up    
pitiot committed
775
776
777
778
779

#endif
        mo->parts_[o->indexPart1]->setState(VOLUME) ;
        mo->parts_[o->indexPart1]->move(pos) ;
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
780
        CGoGNout<<"part1 moved in the end (destination, arrivée,d) : "<<pos<<" || "<< mo->parts_[o->indexPart1]->getPosition()<<" || "<<mo->parts_[o->indexPart1]->d<<CGoGNendl;
pitiot's avatar
up    
pitiot committed
781
782
783

#endif
        mo->parts_[o->indexPart2]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
784
        mo->parts_[o->indexPart2]->reset_positionFace();
pitiot's avatar
up    
pitiot committed
785
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
786
        CGoGNout<<"part2 moved to centroid ,d : "<< mo->parts_[o->indexPart2]->getPosition()<<" || "<<mo->parts_[o->indexPart2]->d<<CGoGNendl;
pitiot's avatar
up    
pitiot committed
787
788
789
790
791

#endif
        mo->parts_[o->indexPart2]->setState(VOLUME) ;
        mo->parts_[o->indexPart2]->move(pos2) ;
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
792
        CGoGNout<<"part2 moved in the end (destination, arrivée,d) : "<<pos2<<" || "<< mo->parts_[o->indexPart2]->getPosition()<<" || "<<mo->parts_[o->indexPart2]->d<<CGoGNendl;
pitiot's avatar
up    
pitiot committed
793
794
795
796

#endif
    }

pitiot's avatar
up    
pitiot committed
797

Thomas Pitiot 's avatar
Thomas Pitiot committed
798
799
800
801
802
803
804
805
806
}

void EnvMap::resetPartSubdiv(Triangle * o)
{

    Surface * mo = o->surf;
    Dart cell =o->cell;
    Dart cell2 = mo->surfaceMap.phi1(cell);
    Dart cell3 = mo->surfaceMap.phi1(cell2);
Etienne Schmitt's avatar
Etienne Schmitt committed
807
808
809
    Particule * p = mo->parts_[mo->indexParticule[cell]];
    Particule * p2 = mo->parts_[mo->indexParticule[cell2]];
    Particule * p3 = mo->parts_[mo->indexParticule[cell3]];
Thomas Pitiot 's avatar
Thomas Pitiot committed
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827

    if (mo != NULL)
    {

        VEC3 pos = p->getPosition();
        VEC3 pos2 = p2->getPosition();
        VEC3 pos3 = p3->getPosition();
        Dart d1 =p->d;
        Dart d2 =p2->d;
        Dart d3 = p3->d;

#ifdef DEBUG_affichage
        CGoGNout<<"Reset part subdiv (index articul , segment ,ind1, pos1, d1, ind2, pos2, d2) : "<<mo->index_articulated<<" || "<<o->index<<" || "<<o->indexPart1<<" || "<<pos<<" || "<<d1<<" || "<<o->indexPart2<<" || "<<pos2<<" || "<<d2<<CGoGNendl;
        CGoGNout<<"Faces centroids : "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)<<" || "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)<<CGoGNendl;

#endif

        p->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
Thomas Pitiot 's avatar
up2    
Thomas Pitiot committed
828
        p->reset_positionFace(); // attention avec les particules 3D on doit mettre a jour la position_face !!!
Thomas Pitiot 's avatar
Thomas Pitiot committed
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
#ifdef DEBUG_affichage
        CGoGNout<<"part1 moved to centroid ,d : "<< p->getPosition()<<" || "<<p->d<<CGoGNendl;

#endif
        p->setState(VOLUME) ;
        p->move(pos) ;
#ifdef DEBUG_affichage
        CGoGNout<<"part1 moved in the end (destination, arrivée,d) : "<<pos<<" || "<< p->getPosition()<<" || "<<p->d<<CGoGNendl;

#endif
        p2->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
        p2->reset_positionFace();
#ifdef DEBUG_affichage
        CGoGNout<<"part2 moved to centroid ,d : "<< p2->getPosition()<<" || "<<p2->d<<CGoGNendl;

#endif
        p2->setState(VOLUME) ;
        p2->move(pos2) ;
#ifdef DEBUG_affichage
        CGoGNout<<"part2 moved in the end (destination, arrivée,d) : "<<pos2<<" || "<< p2->getPosition()<<" || "<<p2->d<<CGoGNendl;

#endif

        p3->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d3,position)) ;
        p3->reset_positionFace();
#ifdef DEBUG_affichage
        CGoGNout<<"part3 moved to centroid ,d : "<< p3->getPosition()<<" || "<<p3->d<<CGoGNendl;

#endif
        p3->setState(VOLUME) ;
        p3->move(pos3) ;
#ifdef DEBUG_affichage
        CGoGNout<<"part3 moved in the end (destination, arrivée,d) : "<<pos3<<" || "<< p3->getPosition()<<" || "<<p3->d<<CGoGNendl;

#endif
    }


pitiot's avatar
up    
pitiot committed
867
868
}

pitiot's avatar
init    
pitiot committed
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
//void EnvMap::coarse()
//{
////	CGoGNout<<"coarse"<<CGoGNendl;
//	// On recrée une liste des faces à simplifier en empêchant les doublons
//	// On en profite pour vérifier les conditions de simplifications
//	std::vector<Dart> checkCoarsenCandidate ;
//	checkCoarsenCandidate.reserve(coarsenCandidate.size()) ;
//
//	for (unsigned int it = 0; it < coarsenCandidate.size(); ++it)
//	{
//		Dart old = coarsenCandidate[it] ;
//		bool oldIsMarked = coarsenMark.isMarked(old) ;
//		coarsenMark.unmark(old) ;
//
//		unsigned int fLevel = map.faceLevel(old) ;
//
//		if (oldIsMarked && fLevel > 0 && map.getDartLevel(old) < fLevel)
//		{
//			unsigned int cur = map.getCurrentLevel() ;
//			map.setCurrentLevel(fLevel - 1) ;
//
//			if (map.faceIsSubdividedOnce(old))
//			{
//				// on compte le nombre d'agents dans les sous-faces
//				// on en profite pour compter le degré de la face grossière
//				unsigned int degree = 0 ;
//				unsigned int nbAgents = 0 ;
//				Dart fit = old ;
//				do
//				{
//					nbAgents += agentvect[fit].size() ;
//					++degree ;
//					coarsenMark.unmark(fit) ;
//					fit = map.phi1(fit) ;
//				} while (fit != old) ;
//
//
//				//Loop subdivision
//				if (degree == 3)
//				{
//					map.setCurrentLevel(fLevel) ;
//					Dart centerFace = map.phi2(map.phi1(old)) ;
//					nbAgents += agentvect[centerFace].size() ;
//					coarsenMark.unmark(centerFace) ;
//					map.setCurrentLevel(fLevel - 1) ;
//				}
//				if (nbAgents < nbAgentsToSimplify) checkCoarsenCandidate.push_back(old) ;
//			}
//			map.setCurrentLevel(cur) ;
//		}
//	}
//	coarsenCandidate.clear() ;
//
////		 On réalise la simplification (les conditions ont déjà été vérifiées)
//	for (unsigned int it = 0; it < checkCoarsenCandidate.size(); ++it)
//	{
//		Dart old = checkCoarsenCandidate[it] ;
//
//		unsigned int fLevel = map.faceLevel(old) ;
//		unsigned int cur = map.getCurrentLevel() ;
//		map.setCurrentLevel(fLevel - 1) ;
//
//		// on compte le degré de la face grossière
//		unsigned int degree = 0 ;
//		Dart fit = old ;
//		do
//		{
//			++degree ;
//			fit = map.phi1(fit) ;
//		} while (fit != old) ;
//
//		PFP::AGENTS agents ;
pitiot's avatar
pitiot committed
941
942
//		PFP::SegmentVECT obst ;
//		PFP::SegmentVECT neighborObst ;
pitiot's avatar
init    
pitiot committed
943
944
945
946
947
948
949
950
951
//		//premier tour pour les darts qui vont disparaitre
//		fit = old ;
//		do
//		{
//			Dart nf = map.phi2(fit) ;
//			if (!map.faceIsSubdivided(nf))
//			{
//				map.setCurrentLevel(fLevel) ;
//				PFP::AGENTS& an = agentvect[nf] ;
pitiot's avatar
pitiot committed
952
//				PFP::SegmentVECT resetob = RegisteredEdges[nf] ;
pitiot's avatar
init    
pitiot committed
953
954
955
956
//				for (PFP::AGENTS::iterator ait = an.begin(); ait != an.end(); ++ait)
//				{
//					if ((*ait)->part_.d == map.phi1(nf)) (*ait)->part_.d = nf ;
//				}
pitiot's avatar
pitiot committed
957
//				for (PFP::SegmentVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
pitiot's avatar
init    
pitiot committed
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
//				{
//
//						resetPart(*ait,nf) ;
//
//				}
//				map.setCurrentLevel(fLevel - 1) ;
//			}
//
//			fit = map.phi1(fit) ;
//		} while (fit != old) ;
//		//deuxieme tour pour les présents
//		fit = old ;
//		do
//		{
//			PFP::AGENTS a(agentvect[fit]) ;
pitiot's avatar
pitiot committed
973
//			PFP::SegmentVECT ob(RegisteredEdges[fit]) ;
pitiot's avatar
init    
pitiot committed
974
975
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
pitiot's avatar
pitiot committed
976
//
pitiot's avatar
init    
pitiot committed
977
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
978
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init    
pitiot committed
979
980
//			{
////				resetObstPartInFace(*ait, fit,fLevel);
pitiot's avatar
pitiot committed
981
//				this->popSegment(*ait) ;
pitiot's avatar
init    
pitiot committed
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
//				obst.push_back(*ait);
//			}
//
//
//
//			for (PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
//				popAgentInCells(*ait, fit) ;
//			map.setCurrentLevel(fLevel - 1) ;
//
//			fit = map.phi1(fit) ;
//		} while (fit != old) ;
//
//		if (degree == 3)
//		{
//			map.setCurrentLevel(fLevel) ;
//			Dart centerFace = map.phi2(map.phi1(old)) ;
//			PFP::AGENTS a(agentvect[centerFace]) ;
pitiot's avatar
pitiot committed
999
//			PFP::SegmentVECT ob(RegisteredEdges[centerFace]) ;
pitiot's avatar
init    
pitiot committed
1000
1001
1002
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1003
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init    
pitiot committed
1004
1005
//			{
////				resetObstPartInFace(*ait, fit,Level);
pitiot's avatar
pitiot committed
1006
//				this->popSegment(*ait) ;
pitiot's avatar
init    
pitiot committed
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
//				obst.push_back(*ait);
//			}
//			for (PFP::AGENTS::iterator ait = a.begin(); ait != a.end(); ++ait)
//				popAgentInCells(*ait, centerFace) ;
//			map.setCurrentLevel(fLevel - 1) ;
//		}
//
//		//dernier tour concernant les voisins
//		fit = old ;
//		do
//		{
pitiot's avatar
pitiot committed
1018
//			PFP::SegmentVECT nob(neighborRegisteredEdges[fit]) ;
pitiot's avatar
init    
pitiot committed
1019
1020
//
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1021
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init    
pitiot committed
1022
//			{
pitiot's avatar
pitiot committed
1023
//				this->popSegment(*ait) ;
pitiot's avatar
init    
pitiot committed
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
//				neighborObst.push_back(*ait);
//			}
//			map.setCurrentLevel(fLevel - 1) ;
//
//			fit = map.phi1(fit) ;
//		} while (fit != old) ;
//
//		if (degree == 3)
//		{
//			map.setCurrentLevel(fLevel) ;
//			Dart centerFace = map.phi2(map.phi1(old)) ;
pitiot's avatar
pitiot committed
1035
//			PFP::SegmentVECT nob(neighborRegisteredEdges[centerFace]) ;
pitiot's avatar
init    
pitiot committed
1036
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1037
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init    
pitiot committed
1038
//			{
pitiot's avatar
pitiot committed
1039
//				this->popSegment(*ait) ;
pitiot's avatar
init    
pitiot committed
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
//				neighborObst.push_back(*ait);
//			}
//			map.setCurrentLevel(fLevel - 1) ;
//		}
//
//
//
//
//
//		map.setCurrentLevel(fLevel - 1) ;
//
//		Algo::Surface::IHM::coarsenFace<PFP>(map, old, position) ;
//
//		std::pair<bool, bool>& sf = subdivisableFace[old] ;
//		sf.first = true ;
//		sf.second = true ;
//
//		map.setCurrentLevel(map.getMaxLevel()) ;
//
//		neighborAgentvect[old].clear() ;
//
//		for (PFP::AGENTS::iterator itA = agents.begin(); itA != agents.end(); ++itA)
//		{
//			(*itA)->part_.d = old ;
//			pushAgentInCells(*itA, old) ;
//		}
pitiot's avatar
pitiot committed
1066
//		for (PFP::SegmentVECT::iterator ait = obst.begin(); ait != obst.end(); ++ait)
pitiot's avatar
init    
pitiot committed
1067
1068
//		{
//			resetObstPartInFace(*ait, old);
pitiot's avatar
pitiot committed
1069
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init    
pitiot committed
1070
//		}
pitiot's avatar
pitiot committed
1071
//		for (PFP::SegmentVECT::iterator ait = neighborObst.begin(); ait != neighborObst.end(); ++ait)
pitiot's avatar
init    
pitiot committed
1072
//		{
pitiot's avatar
pitiot committed
1073
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init    
pitiot committed
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
//		}
//
//		Dart dd = old ;
//		do
//		{
//			Dart ddd = map.alpha1(map.alpha1(dd)) ;
//			while (ddd != dd)
//			{
//				neighborAgentvect[old].insert(neighborAgentvect[old].end(), agentvect[ddd].begin(), agentvect[ddd].end()) ;
//				ddd = map.alpha1(ddd) ;
//			}
//			dd = map.phi1(dd) ;
//		} while (dd != old) ;
//
//		if (fLevel > 1 && !coarsenMark.isMarked(old) && agentvect[old].size() < nbAgentsToSimplify)
//		{
//			coarsenMark.mark(old) ;
//			coarsenCandidate.push_back(map.faceOldestDart(old)) ;
//		}
//
//		map.setCurrentLevel(cur) ;
//	}
//	map.setCurrentLevel(map.getMaxLevel()) ;
//
//	if (coarsenCandidate.size() > 0)
//		updateMap() ;
//}
//
//void EnvMap::updateMap()
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
//
//	refine();
//	coarse();
//}
David Cazier's avatar
David Cazier committed
1109

David Cazier's avatar
David Cazier committed
1110