env_map.cpp 32.6 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
{
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 ;
35 36 37 38 39 40 41 42 43 44

#ifdef IHMap
        map.initImplicitProperties();  // Si map MR
#endif





    if (argc>1)
Thomas Pitiot 's avatar
Thomas Pitiot committed
45
    {
46
        std::string filename(argv[1]);
pitiot's avatar
pitiot committed
47
        open_file(filename);
48 49 50 51 52
        TraversorV<MAP> tv(map);
        for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
        {
            position[d] /= 10;
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
53 54 55 56
    }
    else
    {
        //Intialisation map
pitiot's avatar
init  
pitiot committed
57

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

pitiot's avatar
pitiot committed
63 64 65 66 67
        TraversorV<MAP> tv(map);
        for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
        {
            position[d] *= 10;
        }
pitiot's avatar
up  
pitiot committed
68

69 70 71 72 73
//        map.check();
    }
    if(checkFaces())
        exit(0);
    ///// initialisation attributs
pitiot's avatar
up  
pitiot committed
74

75 76 77 78 79 80 81
    facecenter = map.addAttribute<VEC3, FACE, MAP>("facecenter");
    volumecenter=map.addAttribute<VEC3, VOLUME, MAP>("volumecenter");
    color = map.addAttribute<VEC3, VOLUME, MAP>("color");
    RegisteredEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredEdges");
    RegisteredNeighborEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredNeighborEdges");
    RegisteredTriangles=map.addAttribute<TRIANGLES,VOLUME, MAP>("RegisteredTriangles");
    RegisteredNeighborTriangles=map.addAttribute<TRIANGLES,VOLUME, MAP>("RegisteredNeighborTriangles");
pitiot's avatar
pitiot committed
82 83


84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    TraversorV<MAP> tv(map);
    for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
    {
        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];
    }
    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
99

pitiot's avatar
up  
pitiot committed
100
    }
pitiot's avatar
pitiot committed
101

102 103 104 105 106 107 108 109 110
    TraversorW<MAP> tra(map);
    for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
    {
        VEC3 pos =position[d];
        color[d] = VEC3((pos[0]-mapMinX)/(mapMaxX-mapMinX),(pos[1]-mapMinY)/(mapMaxY-mapMinY),(pos[2]-mapMinZ)/(mapMaxZ-mapMinZ));
        volumecenter[d]=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3, MAP>>(map,d,position);
    }

    map.check();
pitiot's avatar
up  
pitiot committed
111
}
pitiot's avatar
pitiot committed
112

pitiot's avatar
up  
pitiot committed
113 114 115
REAL EnvMap::volumeMaxdistance(Vol volume)
{
    Dart d = volume;
116

117
    VEC3 center = volumecenter[d];
118

119
    REAL res = (position[d]-center).norm();
pitiot's avatar
up  
pitiot committed
120 121
    for ( Vertex vert : verticesIncidentToVolume3(map,volume))
    {
122
        REAL size=(position[vert]-center).norm();
pitiot's avatar
up  
pitiot committed
123 124 125 126 127 128
        if(size>res)
        {
            res=size;
        }
    }
    return res;
pitiot's avatar
pitiot committed
129 130
}

pitiot's avatar
pitiot committed
131
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
132
{
133
    VEC3 center = volumecenter[volume];
Thomas Pitiot 's avatar
Thomas Pitiot committed
134 135 136 137
    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
138 139
}

pitiot's avatar
pitiot committed
140
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
141 142
{
    if(insideVolume(pos, neighborhood))
143 144
    {
//        CGoGNout<<"checkPos : inside the original volume"<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
145
        return true;
146
    }
pitiot's avatar
pitiot committed
147
    for (Vol d : volumesAdjacentByVertex3(map,neighborhood))
pitiot's avatar
up  
pitiot committed
148 149 150
    {
        if (!map.isBoundaryMarked<3>(d) )
        {
151
//            CGoGNout<<"checkPos : test volume d :"<<d<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
152
            if(insideVolume(pos, d))
153 154
            {
//                CGoGNout<<" TRUE !"<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
155
                return true;
156 157

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


pitiot's avatar
up  
pitiot committed
162 163 164
    return false;
}

165 166 167 168 169 170 171

bool EnvMap::checkPointInCube(VEC3 pos) // definit si le point pos est dans le voisinage interne a la carte du volume "neighborhood"
{
    return (pos[0]<=mapMaxX && pos[0]>=mapMinX&& pos[1]<=mapMaxY && pos[1]>=mapMinY && pos[2]<=mapMaxZ && pos[2]>=mapMinZ);
}


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

pitiot's avatar
pitiot committed
175 176

    for(Face d : facesIncidentToVolume3(map,volume))
pitiot's avatar
up  
pitiot committed
177 178 179 180 181 182 183 184 185 186 187
    {
        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
188 189


pitiot's avatar
up  
pitiot committed
190 191 192 193
}



pitiot's avatar
pitiot committed
194 195 196 197 198 199




Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
200 201 202
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
pitiot's avatar
pitiot committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217

    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
218 219


220 221 222 223
bool EnvMap::checkFaces()
{
    CGoGNout<<"check faces"<<CGoGNendl;
    TraversorF<MAP> tf(map);
224

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
    for(Dart d = tf.begin() ; d != tf.end() ; d = tf.next())
    {
        Dart d2 = map.phi1(d);
        Dart d3 = map.phi1(d2);
        Geom::Plane3D<typename PFP::REAL> plan(position[d],position[d2],position[d3]);
        do
        {
            d3=map.phi1(d3);
            if(plan.orient(position[d3])!=Geom::ON)
            {
               CGoGNout << " face non coplanaire !" <<d3<<CGoGNendl;
               return true;
            }
        }while(d3!=d);

    }

    return false;
}
244 245


Thomas's avatar
Thomas committed
246 247 248 249




pitiot's avatar
init  
pitiot committed
250 251
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
252
{
pitiot's avatar
pitiot committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    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
        {
283 284 285 286 287 288 289
            if(!Algo::Volume::Import::importMesh<PFP>(map, filename, attrNames))
            {
                std::cerr << "could not import " << filename << std::endl ;
                return ;
            }
            else
                position = map.getAttribute<VEC3, VERTEX, MAP>(attrNames[0]) ;
pitiot's avatar
pitiot committed
290 291 292
        }

    }
Pierre Kraemer's avatar
Pierre Kraemer committed
293
}
Thomas Pitiot 's avatar
Thomas Pitiot committed
294
//////////////////////////////////enregistrement des segments
Pierre Kraemer's avatar
Pierre Kraemer committed
295

pitiot's avatar
pitiot committed
296 297
void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en question
{
pitiot's avatar
init  
pitiot committed
298

pitiot's avatar
pitiot committed
299
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
300 301
    if (mo != NULL)
    {
pitiot's avatar
pitiot committed
302
        int n1 = o->indexPart1;
Thomas Pitiot 's avatar
Thomas Pitiot committed
303
//        int n2 = o->indexPart2;
pitiot's avatar
pitiot committed
304
#ifdef DEBUG_affichage
pitiot's avatar
up  
pitiot committed
305
        CGoGNout<<"First Registration arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
306 307 308 309
#endif
        VEC3 p1 = o->p1;
        VEC3 p2 =  o->p2;

310 311
        Dart d1=mo->getParticule(n1)->getCell();
//        Dart d2=mo->getParticule(n2)->getCell();
pitiot's avatar
pitiot committed
312
        std::vector<Dart> memo;
pitiot's avatar
pitiot committed
313 314


Thomas Pitiot 's avatar
Thomas Pitiot committed
315
        memo = getMemoCross(p1,p2,d1,mo->getParticule(n1)->getState());
pitiot's avatar
pitiot committed
316

Etienne Schmitt's avatar
Etienne Schmitt committed
317
        if(memo.size() == 1u)
pitiot's avatar
pitiot committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331
        {
            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
332
    CGoGNout<<"pop&push arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
333 334 335 336
#endif
    popSegment(o);
    FirstRegistrationSegment(o);

337
    return o->nid->getParticule(o->indexPart1)->getCell();
pitiot's avatar
pitiot committed
338 339 340 341 342
}

void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
    int n = o->index;
pitiot's avatar
pitiot committed
343
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
344 345 346
#ifdef DEBUG_affichage
    CGoGNout<<"Push in one cell segment arete "<<n<<CGoGNendl;
#endif
Thomas Pitiot 's avatar
Thomas Pitiot committed
347
#ifdef IHMap
pitiot's avatar
pitiot committed
348
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
349
#endif
350
    d=map.volumeOldestDart(d);
Etienne Schmitt's avatar
Etienne Schmitt committed
351
    addElementToVector(RegisteredEdges[d],o);
pitiot's avatar
pitiot committed
352 353

    mo->belonging_cells[n].push_back(d);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
354
    mo->addGeneralCell (d);
pitiot's avatar
pitiot committed
355
    for (Vol volume : volumesAdjacentByVertex3(map,d))
pitiot's avatar
pitiot committed
356
    {
pitiot's avatar
pitiot committed
357
        if (!map.isBoundaryMarked<3>(volume))
pitiot's avatar
pitiot committed
358
        {
Thomas Pitiot 's avatar
Thomas Pitiot committed
359
            volume=map.volumeOldestDart(volume);
pitiot's avatar
pitiot committed
360
            pushSegmentInCellAsNeighbor(o, volume);
Thomas Pitiot 's avatar
Thomas Pitiot committed
361
            mo->neighbor_cells[n].push_back(volume);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
362
            mo->addGeneralNeighbor ( d);
pitiot's avatar
pitiot committed
363 364 365
        }
    }

pitiot's avatar
pitiot committed
366 367 368
#ifdef DEBUG_affichage
    CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
#endif
pitiot's avatar
pitiot committed
369 370 371 372 373 374 375 376
}

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
377
    //    assert( memo_cross.size() > 1);
pitiot's avatar
pitiot committed
378
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
379 380


381 382 383 384 385 386
    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
387
#ifdef DEBUG_affichage
388
        CGoGNout<<"cellule du belong :"<<(d)<<CGoGNendl;
pitiot's avatar
pitiot committed
389
#endif
pitiot's avatar
pitiot committed
390 391

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

394
    for (Dart d : mo->neighbor_cells[n])
pitiot's avatar
pitiot committed
395
    {
396 397 398
            addElementToVector<Segment*>(RegisteredNeighborEdges[d],o);
             mo->addGeneralNeighbor ( (d));

pitiot's avatar
pitiot committed
399
    }
pitiot's avatar
pitiot committed
400 401 402
#ifdef DEBUG_affichage
    CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
#endif
pitiot's avatar
pitiot committed
403 404 405 406
}

void EnvMap::popSegment(Segment* o)
{
pitiot's avatar
pitiot committed
407
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
408
    int n = o->index;
Thomas Pitiot 's avatar
Thomas Pitiot committed
409 410 411
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
pitiot's avatar
pitiot committed
412 413 414

    if (mo != NULL)
    {
415
        for (Dart d : mo->belonging_cells[n])
pitiot's avatar
pitiot committed
416
        {
417 418
            removeElementFromVector(RegisteredEdges[d], o) ;
            mo->removeGeneralCell (d);
pitiot's avatar
pitiot committed
419
        }
420
        for (Dart d : mo->neighbor_cells[n])
pitiot's avatar
pitiot committed
421
        {
422 423 424
                removeElementFromVector(RegisteredNeighborEdges[d], o) ;
                mo->removeGeneralNeighbor (d);

pitiot's avatar
pitiot committed
425 426 427 428 429
        }
        mo->belonging_cells[n].clear();
        mo->neighbor_cells[n].clear();
    }
}
pitiot's avatar
up  
pitiot committed
430 431


Thomas Pitiot 's avatar
Thomas Pitiot committed
432 433 434 435 436 437 438 439 440 441 442 443
/////////////////////////////enregistrement des triangles



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

    Surface * mo = o->surf;

    if (mo != NULL)
    {
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
444
        CGoGNout<<"First Registration Triangle "<<o->indexTri<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
445 446 447 448 449 450
#endif
        CellMarkerMemo<MAP, VOLUME> inside(map);
        CellMarkerMemo<MAP, VOLUME> neighbor(map);
        Dart cell =o->cell;
        std::vector<Dart> memo;

Etienne Schmitt's avatar
Etienne Schmitt committed
451
        for(Edge e : edgesIncidentToFace2<SurfaceMap>(mo->getSurfaceMap(),cell)) // first mark inside
Thomas Pitiot 's avatar
Thomas Pitiot committed
452
        {
Etienne Schmitt's avatar
Etienne Schmitt committed
453
            Dart cell2=mo->getSurfaceMap().phi1(e);
Thomas Pitiot 's avatar
Thomas Pitiot committed
454 455
            // on récupère les aprticules correspondant a chaque edge du triangle a enregistrer

Etienne Schmitt's avatar
Etienne Schmitt committed
456
            const Particule * p1 = mo->getParticule(mo->getIndexOfParticuleAtVertex(cell));
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
457

Thomas Pitiot 's avatar
Thomas Pitiot committed
458

Thomas Pitiot 's avatar
Thomas Pitiot committed
459

460
            Dart d1=p1->getCell(); // darts de la carte 3D contenant les particules
Thomas Pitiot 's avatar
Thomas Pitiot committed
461 462 463 464
#ifdef DEBUG_affichage
        CGoGNout<<"Calcul memo_cross pour l'edge (p1,p2,d1,state) "<<p1->getPosition()<<" || "<<mo->getSurfacePosition(cell2)<<" || "<<d1<<" || "<<p1->getState()<<CGoGNendl;
#endif
            memo = getMemoCross(p1->getPosition(),mo->getSurfacePosition(cell2),d1,p1->getState());
Thomas Pitiot 's avatar
Thomas Pitiot committed
465

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
466 467
            for (Dart d : memo)
                   inside.mark(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
468 469 470

        }

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
471 472 473


        for(Dart d : inside.get_markedCells()) // and register them
Thomas Pitiot 's avatar
Thomas Pitiot committed
474
        {
475
            d=map.volumeOldestDart(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
476
            pushTriangleInCell(o,d);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
477 478
            (mo->belonging_cells[o->indexTri]).push_back(d);
            mo->addGeneralCell ( d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
479
        }
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
480 481
        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
482
        {
483
            d=map.volumeOldestDart(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
484
            pushTriangleInCellAsNeighbor(o,d);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
485 486
            (mo->neighbor_cells[o->indexTri]).push_back(d);
            mo->addGeneralNeighbor ( d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
487 488 489 490 491 492 493
        }


    }
}


Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
494
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
495 496 497 498 499 500 501
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(!memo_cross.empty());


Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
502
    for(Dart  e : memo_cross)
Thomas Pitiot 's avatar
Thomas Pitiot committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
    {

        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
Thomas Pitiot 's avatar
Thomas Pitiot committed
522
    CGoGNout<<"pop&push arete "<<o->indexTri<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
#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;

Etienne Schmitt's avatar
Etienne Schmitt committed
540
        int n = mo->getIndexOfTriangle(cell);
Thomas Pitiot 's avatar
Thomas Pitiot committed
541 542


543
        for (Dart d : mo->belonging_cells[n])
Thomas Pitiot 's avatar
Thomas Pitiot committed
544
        {
545 546
            popTriangleInCell(o,d);
            mo->removeGeneralCell (d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
547
        }
548
        for (Dart d : mo->neighbor_cells[n])
Thomas Pitiot 's avatar
Thomas Pitiot committed
549
        {
550 551 552 553

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
554 555 556 557 558 559
        }
        mo->belonging_cells[n].clear();
        mo->neighbor_cells[n].clear();
    }
}

Thomas Pitiot 's avatar
Thomas Pitiot committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
void EnvMap::agentChangeFace(Agent* agent, Dart oldCell)
{
    Dart newVolume = agent->part_->getCell();

    popAgent(agent, oldCell) ;
    pushAgent(agent, newVolume) ;

}

void EnvMap::popAgent(Agent *agent, Dart oldCell)
{
    popAgentInCell(agent, oldCell);
    for(Vol v : volumesAdjacentByVertex3<PFP::MAP>(map,oldCell))
    {
        popAgentInCellAsNeighbor(agent, v);
    }
}

void EnvMap::pushAgent(Agent *agent, Dart newVolume)
{
    pushAgentInCell(agent, newVolume);
    for(Vol v : volumesAdjacentByVertex3<PFP::MAP>(map,newVolume))
    {
        pushAgentInCellAsNeighbor(agent, v);
    }
}

Thomas Pitiot 's avatar
Thomas Pitiot committed
587
bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
pitiot's avatar
up  
pitiot committed
588
{
589 590 591
    bool res =false;
#ifdef IHMap

pitiot's avatar
up  
pitiot committed
592

593
    map.setCurrentLevel(map.getMaxLevel()) ;
594 595
    unsigned int vLevel = map.volumeLevel(dglobal);
    Dart old = map.volumeOldestDart(dglobal);
Thomas Pitiot 's avatar
Thomas Pitiot committed
596
    Dart centerDart=old;
pitiot's avatar
up  
pitiot committed
597 598 599
#ifdef DEBUG_affichage
    int count = 0;
#endif
600 601
    // 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
Thomas Pitiot 's avatar
Thomas Pitiot committed
602

Thomas Pitiot 's avatar
Thomas Pitiot committed
603
    if(OneLevelDifference)
604
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
605
        map.setCurrentLevel(vLevel) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
606
        for ( Face dit : facesIncidentToVolume3(map,old))
607
        {
Thomas Pitiot 's avatar
Thomas Pitiot committed
608 609 610 611 612
    #ifdef DEBUG_affichage
            count++;
    #endif
            Dart nv = map.phi3(dit);
            if(!map.isBoundaryMarked(3, nv))
613
            {
Thomas Pitiot 's avatar
Thomas Pitiot committed
614 615 616 617 618 619 620 621 622 623 624
                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
                {
625

Thomas Pitiot 's avatar
Thomas Pitiot committed
626 627
                    if(map.checkForSurrounded(nv))
                    {
628

Thomas Pitiot 's avatar
Thomas Pitiot committed
629 630 631 632
                        subdivideVolume(nv,false);

                    }
                }
633 634
            }
        }
635

636 637
    }

pitiot's avatar
up  
pitiot committed
638

Etienne Schmitt's avatar
Etienne Schmitt committed
639
     const std::chrono::time_point<std::chrono::system_clock> startPop = std::chrono::system_clock::now();
640
    // on commence ensuite a subdiviser
641

642
    map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
up  
pitiot committed
643

Thomas Pitiot 's avatar
Thomas Pitiot committed
644
    const ARETES oldobst(RegisteredEdges[dglobal]) ;
645 646 647 648

    for (Segment * o : oldobst)
    {
        this->popSegment(o) ;
649
        o->nid->needResetSegment(o);
650 651
    }

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

654 655
    for (Segment * o : oldNeighborObst)
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
656 657 658 659 660 661 662 663 664 665 666
        if(removeElementFromVector(o->nid->neighbor_cells[o->index],old))
        {
             o->nid->removeGeneralNeighbor (old);
        }
        else
        {
             CGoGNout<<"failed to remove... ";
             afficheVector(o->nid->neighbor_cells[o->index]);
             CGoGNout<<" et old :"<<old<<CGoGNendl;
        }

667
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
668
    RegisteredNeighborEdges[old].clear();
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
669

Thomas Pitiot 's avatar
Thomas Pitiot committed
670
    const TRIANGLES oldTrian(RegisteredTriangles[dglobal]) ;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
671 672 673 674

    for (Triangle * o : oldTrian)
    {
        this->popTriangle(o) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
675
        o->surf->needResetTriangle(o);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
676 677
    }

Thomas Pitiot 's avatar
Thomas Pitiot committed
678
    TRIANGLES oldTrianNeighbor(RegisteredNeighborTriangles[old]) ;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
679 680 681

    for (Triangle * o : oldTrianNeighbor)
    {
682 683 684 685 686 687 688 689 690 691
        if(removeElementFromVector(o->surf->neighbor_cells[o->indexTri],old))
        {
            o->surf->removeGeneralNeighbor (old);
        }
        else
        {
            CGoGNout<<"failed to remove... ";
            afficheVector(o->surf->neighbor_cells[o->indexTri]);
            CGoGNout<<" et old :"<<old<<CGoGNendl;
        }
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
692
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
693
    RegisteredNeighborTriangles[old].clear();
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
694

Etienne Schmitt's avatar
Etienne Schmitt committed
695 696
    const std::chrono::time_point<std::chrono::system_clock> endPop = std::chrono::system_clock::now();
    duration_pop = endPop - startPop;
697
    if(duration_pop.count()>0.01)CGoGNout << "pop duration : " << duration_pop.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
698 699 700

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
701
    if(!map.isBoundaryMarked(3,dglobal) && map.getDartLevel(dglobal) <= map.getMaxLevel() && !map.volumeIsSubdivided(dglobal) )
pitiot's avatar
up  
pitiot committed
702
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
703
        centerDart =Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position,false);
pitiot's avatar
up  
pitiot committed
704
        res=true;
pitiot's avatar
up  
pitiot committed
705 706
    }

Etienne Schmitt's avatar
Etienne Schmitt committed
707 708
    const std::chrono::time_point<std::chrono::system_clock> endSubdiv = std::chrono::system_clock::now();
    duration_subdiv = endSubdiv - startSubdiv;
709
    if(duration_subdiv.count()>0.01)CGoGNout << "subdiv duration : " << duration_subdiv.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
710

Thomas Pitiot 's avatar
Thomas Pitiot committed
711
    map.setCurrentLevel(map.getMaxLevel()) ;
712
    CellMarkerMemo<MAP,VOLUME> newVolumes(map);
Thomas Pitiot 's avatar
Thomas Pitiot committed
713 714 715 716 717 718 719 720
    if(res)
    {
        for(Vol vo : VolumesIncidentToVertex3(map,centerDart))
        {
            newVolumes.mark(map.volumeOldestDart(vo));
        }
    }
    else
721
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
722 723
        newVolumes.mark(old);
    }
Etienne Schmitt's avatar
Etienne Schmitt committed
724

725
//////push neighbors et maj des attributs couleur, facecenter et volumecenter
Thomas Pitiot 's avatar
Thomas Pitiot committed
726
//    CGoGNout<<"nombre de sous cellules markées :"<<newVolumes.get_markedCells().size()<<CGoGNendl;
727 728
    const std::chrono::time_point<std::chrono::system_clock> startPush = std::chrono::system_clock::now();

729
    for (Dart d : newVolumes.get_markedCells())
Thomas Pitiot 's avatar
Thomas Pitiot committed
730
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
731 732
//        CGoGNout<<"markée :"<<d<<CGoGNendl;

733
        for ( Face f : facesIncidentToVolume3(map,d)) // maj des attributs de face et volume de la carte
Thomas Pitiot 's avatar
Thomas Pitiot committed
734 735 736 737
        {
            facecenter[f]=Algo::Surface::Geometry::faceCentroid<PFP, VertexAttribute<VEC3, MAP>>(map,f,position);

        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
738 739
        volumecenter[d]=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d,position);
        VEC3 center=volumecenter[d];
740
        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
741

742 743 744 745 746 747

        // reenregistrement des voisins
        for(Vol v : volumesAdjacentByVertex3(map,d))
        {
            if(!newVolumes.isMarked(v))
            {
Thomas Pitiot 's avatar
Thomas Pitiot committed
748
//                CGoGNout<<"reenregistrement des voisins de : "<<v<<CGoGNendl;
749 750
                for(Segment * s : RegisteredEdges[v])
                {
Thomas Pitiot 's avatar
Thomas Pitiot committed
751
//                    CGoGNout<<"tentative ajout de : "<<s->index<<CGoGNendl;
752 753
                    if(addElementToVector(RegisteredNeighborEdges[d],s))
                    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
754
//                        CGoGNout<<"reussie car non présent"<<CGoGNendl;
755 756 757 758 759 760 761 762 763 764 765 766
                           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
767
    }
768
    const std::chrono::time_point<std::chrono::system_clock> endPushNeighbors = std::chrono::system_clock::now();
Thomas Pitiot 's avatar
Thomas Pitiot committed
769

Etienne Schmitt's avatar
Etienne Schmitt committed
770

771

772 773
    std::chrono::duration<double> duration_particules;
    std::chrono::time_point<std::chrono::system_clock> start_particule, stop_particule;
Thomas Pitiot 's avatar
Thomas Pitiot committed
774

Thomas Pitiot 's avatar
Thomas Pitiot committed
775
    //same for triangles //
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
776 777
    for (Triangle * o : oldTrian)
    {
778
        start_particule= std::chrono::system_clock::now();
779
        resetPartSubdiv(o);
780 781
        stop_particule= std::chrono::system_clock::now();
        duration_particules+=stop_particule-start_particule;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
782 783
        this->FirstRegistrationTriangle(o) ;
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
784

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
787

pitiot's avatar
up  
pitiot committed
788
    //same for obstacles contained
789
    for (Segment * o : oldobst)
pitiot's avatar
up  
pitiot committed
790
    {
791
        start_particule= std::chrono::system_clock::now();
792
        resetPartSubdiv(o);
793 794
        stop_particule= std::chrono::system_clock::now();
        duration_particules+=stop_particule-start_particule;
795
        FirstRegistrationSegment(o);
pitiot's avatar
up  
pitiot committed
796 797

    }
798
//    CGoGNout << "particules duration : " << duration_particules.count()  << "s "<<CGoGNendl;
Etienne Schmitt's avatar
Etienne Schmitt committed
799 800
    const std::chrono::time_point<std::chrono::system_clock> endPush = std::chrono::system_clock::now();
    duration_push = endPush - startPush;
801 802 803
    std::chrono::duration<double> duration_triangle= (endPushTriangle -endPushNeighbors );
    std::chrono::duration<double> duration_segment= (endPush - endPushTriangle);
    std::chrono::duration<double> duration_neighbors= (endPushNeighbors - startPush );
804 805
    if(duration_triangle.count()>0.03)CGoGNout << "push triangle duration : " << duration_triangle.count()  << "s\n";
    if(duration_push.count()>0.03)CGoGNout << "push duration : " << duration_push.count() << "\n dont pour les segments présents : "<<duration_segment.count() <<"s\n et pour les voisins :"<<duration_neighbors.count() <<"s\n";
pitiot's avatar
up  
pitiot committed
806 807


pitiot's avatar
up  
pitiot committed
808 809
#endif
    return res;
pitiot's avatar
up  
pitiot committed
810 811 812

}

813
void EnvMap::resetPartSubdiv(Segment* o)
pitiot's avatar
up  
pitiot committed
814 815 816 817 818 819
{

    ArticulatedObject * mo = o->nid;

    if (mo != NULL)
    {
820 821
        int indPart=o->indexPart1;
        int indPart2=o->indexPart2;
pitiot's avatar
up  
pitiot committed
822 823

#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
824
        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;
825
        CGoGNout<<"Faces centroids : "<<volumecenter[d]<<" || "<<Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
826 827

#endif
828 829 830 831
        if(mo->getNeedForSubd(indPart))
        {
           mo->getParticule(indPart)->resetParticule();
           mo->setNeedForSubd(indPart,0);
Thomas Pitiot 's avatar
Thomas Pitiot committed
832 833
    #ifdef DEBUG_affichage
            CGoGNout<<"part1 moved in the end (destination, arrivée,d,state) : "<<pos<<" || "<< mo->getParticule(o->indexPart1)->getPosition()<<" || "<<mo->parts_[o->indexPart1]->getCell()<<" || "<<mo->parts_[o->indexPart1]->getState()<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
834

Thomas Pitiot 's avatar
Thomas Pitiot committed
835
    #endif
pitiot's avatar
up  
pitiot committed
836

837 838 839 840 841
        }
        if(mo->getNeedForSubd(indPart2))
        {
           mo->getParticule(indPart2)->resetParticule();
           mo->setNeedForSubd(indPart2,0);
Thomas Pitiot 's avatar
Thomas Pitiot committed
842 843 844 845
    #ifdef DEBUG_affichage
            CGoGNout<<"part2 moved in the end (destination, arrivée,d,state) : "<<pos2<<" || "<< mo->getParticule(o->indexPart2)->getPosition()<<" || "<<mo->parts_[o->indexPart2]->getCell()<<" || "<<mo->parts_[o->indexPart2]->getState()<<CGoGNendl;

    #endif
pitiot's avatar
up  
pitiot committed
846

847
        }
pitiot's avatar
up  
pitiot committed
848 849
    }

pitiot's avatar
up  
pitiot committed
850

Thomas Pitiot 's avatar
Thomas Pitiot committed
851 852
}

853
void EnvMap::resetPartSubdiv(Triangle * o)
Thomas Pitiot 's avatar
Thomas Pitiot committed
854 855 856 857 858
{

    Surface * mo = o->surf;
    if (mo != NULL)
    {
859 860 861 862 863 864 865 866 867
        Dart cell =o->cell;
        Dart cell2 = mo->getSurfaceMap().phi1(cell);
        Dart cell3 = mo->getSurfaceMap().phi1(cell2);
        int indPart=mo->getIndexOfParticuleAtVertex(cell);
        int indPart2=mo->getIndexOfParticuleAtVertex(cell2);
        int indPart3=mo->getIndexOfParticuleAtVertex(cell3);
        Particule * p = mo->getParticule(indPart);
        Particule * p2 = mo->getParticule(indPart2);
        Particule * p3 = mo->getParticule(indPart3);
Thomas Pitiot 's avatar
Thomas Pitiot committed
868 869 870



871 872 873
    #ifdef DEBUG_affichage
            CGoGNout<<"Reset part subdiv (index triangle, pos1, d1, pos2, d2, pos3, d3) : "<<o->indexTri<<" || "<<pos<<" || "<<d1<<" || "<<pos2<<" || "<<d2<<" || "<<pos3<<" || "<<d3<<CGoGNendl;
            CGoGNout<<"Faces centroids : "<<volumecenter[d1]<<" || "<<volumecenter[d2]<<" || "<<volumecenter[d3]<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
874

875 876 877 878 879 880 881
    #endif
        if(mo->getNeedForSubd(indPart))
        {
            p->resetParticule();
            mo->setNeedForSubd(indPart,0);
    #ifdef DEBUG_affichage
            CGoGNout<<"part1 moved in the end (destination, arrivée,d,state) : "<<pos<<" || "<< p->getPosition()<<" || "<<p->getCell()<<" || "<<p->getState()<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
882

883
    #endif
Thomas Pitiot 's avatar
Thomas Pitiot committed
884

885 886 887 888 889 890 891
        }
        if(mo->getNeedForSubd(indPart2))
        {
            p2->resetParticule();
            mo->setNeedForSubd(indPart2,0);
    #ifdef DEBUG_affichage
            CGoGNout<<"part2 moved in the end (destination, arrivée,d,state) : "<<pos2<<" || "<< p2->getPosition()<<" || "<<p2->getCell()<<" || "<<p2->getState()<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
892

893 894 895 896 897 898 899 900
    #endif
        }
        if(mo->getNeedForSubd(indPart3))
        {
            p3->resetParticule();
            mo->setNeedForSubd(indPart3,0);
    #ifdef DEBUG_affichage
            CGoGNout<<"part3 moved in the end (destination, arrivée,d,state) : "<<pos3<<" || "<< p3->getPosition()<<" || "<<p3->getCell()<<" || "<<p3->getState()<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
901

902 903
    #endif
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
904 905 906
    }


pitiot's avatar
up  
pitiot committed
907 908
}

pitiot's avatar
init  
pitiot committed
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 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
//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
981 982
//		PFP::SegmentVECT obst ;
//		PFP::SegmentVECT neighborObst ;
pitiot's avatar
init  
pitiot committed
983 984 985 986 987 988 989 990 991
//		//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
992
//				PFP::SegmentVECT resetob = RegisteredEdges[nf] ;
pitiot's avatar
init  
pitiot committed
993 994 995 996
//				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
997
//				for (PFP::SegmentVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
//				{
//
//						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
1013
//			PFP::SegmentVECT ob(RegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
1014 1015
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
pitiot's avatar
pitiot committed
1016
//
pitiot's avatar
init  
pitiot committed
1017
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1018
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
1019 1020
//			{
////				resetObstPartInFace(*ait, fit,fLevel);
pitiot's avatar
pitiot committed
1021
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
//				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
1039
//			PFP::SegmentVECT ob(RegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
1040 1041 1042
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1043
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
1044 1045
//			{
////				resetObstPartInFace(*ait, fit,Level);
pitiot's avatar
pitiot committed
1046
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
1047 1048 1049 1050 1051 1052