env_map.cpp 31.9 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 ;
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");
Thomas Pitiot 's avatar
Thomas Pitiot committed
51
        volumecenter=map.addAttribute<VEC3, VOLUME, MAP>("volumecenter");
pitiot's avatar
pitiot committed
52 53 54
        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
55 56
        RegisteredTriangles=map.addAttribute<TRIANGLES,VOLUME, MAP>("RegisteredTriangles");
        RegisteredNeighborTriangles=map.addAttribute<TRIANGLES,VOLUME, MAP>("RegisteredNeighborTriangles");
pitiot's avatar
pitiot committed
57 58


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

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


pitiot's avatar
pitiot committed
66 67 68 69
        TraversorV<MAP> tv(map);
        for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
        {
            position[d] *= 10;
70 71 72 73 74 75
            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
76
        }
pitiot's avatar
up  
pitiot committed
77 78 79 80 81 82 83
        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
84 85 86 87 88

        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);
Thomas Pitiot 's avatar
Thomas Pitiot committed
89
            volumecenter[d]=Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3, MAP>>(map,d,position);
pitiot's avatar
pitiot committed
90 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
}
pitiot's avatar
pitiot committed
96

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

101
    VEC3 center = volumecenter[d];
102

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

pitiot's avatar
pitiot committed
115
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
116
{
117
    VEC3 center = volumecenter[volume];
Thomas Pitiot 's avatar
Thomas Pitiot committed
118 119 120 121
    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
122 123
}

pitiot's avatar
pitiot committed
124
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
125 126
{
    if(insideVolume(pos, neighborhood))
127 128
    {
//        CGoGNout<<"checkPos : inside the original volume"<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
129
        return true;
130
    }
pitiot's avatar
pitiot committed
131
    for (Vol d : volumesAdjacentByVertex3(map,neighborhood))
pitiot's avatar
up  
pitiot committed
132 133 134
    {
        if (!map.isBoundaryMarked<3>(d) )
        {
135
//            CGoGNout<<"checkPos : test volume d :"<<d<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
136
            if(insideVolume(pos, d))
137 138
            {
//                CGoGNout<<" TRUE !"<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
139
                return true;
140 141

            }
pitiot's avatar
up  
pitiot committed
142 143
        }
    }
pitiot's avatar
pitiot committed
144 145


pitiot's avatar
up  
pitiot committed
146 147 148
    return false;
}

149 150 151 152 153 154 155

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
156
bool EnvMap::insideVolume(VEC3 pos, Dart volume) // définit si le point pos est dans le volume convexe
pitiot's avatar
up  
pitiot committed
157 158
{

pitiot's avatar
pitiot committed
159 160

    for(Face d : facesIncidentToVolume3(map,volume))
pitiot's avatar
up  
pitiot committed
161 162 163 164 165 166 167 168 169 170 171
    {
        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
172 173


pitiot's avatar
up  
pitiot committed
174 175 176 177
}



pitiot's avatar
pitiot committed
178 179 180 181 182





pitiot's avatar
pitiot committed
183
///// a coder
pitiot's avatar
up  
pitiot committed
184

pitiot's avatar
pitiot committed
185 186
Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
Thomas Pitiot 's avatar
Thomas Pitiot committed
187 188 189
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
pitiot's avatar
pitiot committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

    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
205 206


207 208 209



Thomas's avatar
Thomas committed
210 211 212 213




pitiot's avatar
init  
pitiot committed
214 215
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
216
{
pitiot's avatar
pitiot committed
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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
    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
279
}
Thomas Pitiot 's avatar
Thomas Pitiot committed
280
//////////////////////////////////enregistrement des segments
Pierre Kraemer's avatar
Pierre Kraemer committed
281

pitiot's avatar
pitiot committed
282 283
void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en question
{
pitiot's avatar
init  
pitiot committed
284

pitiot's avatar
pitiot committed
285
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
286 287
    if (mo != NULL)
    {
pitiot's avatar
pitiot committed
288
        int n1 = o->indexPart1;
Thomas Pitiot 's avatar
Thomas Pitiot committed
289
//        int n2 = o->indexPart2;
pitiot's avatar
pitiot committed
290
#ifdef DEBUG_affichage
pitiot's avatar
up  
pitiot committed
291
        CGoGNout<<"First Registration arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
292 293 294 295
#endif
        VEC3 p1 = o->p1;
        VEC3 p2 =  o->p2;

296 297
        Dart d1=mo->getParticule(n1)->getCell();
//        Dart d2=mo->getParticule(n2)->getCell();
pitiot's avatar
pitiot committed
298
        std::vector<Dart> memo;
pitiot's avatar
pitiot committed
299 300


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

Etienne Schmitt's avatar
Etienne Schmitt committed
303
        if(memo.size() == 1u)
pitiot's avatar
pitiot committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317
        {
            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
318
    CGoGNout<<"pop&push arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
319 320 321 322
#endif
    popSegment(o);
    FirstRegistrationSegment(o);

323
    return o->nid->getParticule(o->indexPart1)->getCell();
pitiot's avatar
pitiot committed
324 325 326 327 328
}

void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
    int n = o->index;
pitiot's avatar
pitiot committed
329
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
330 331 332
#ifdef DEBUG_affichage
    CGoGNout<<"Push in one cell segment arete "<<n<<CGoGNendl;
#endif
Thomas Pitiot 's avatar
Thomas Pitiot committed
333
#ifdef IHMap
pitiot's avatar
pitiot committed
334
    assert(map.getCurrentLevel() == map.getMaxLevel());
Thomas Pitiot 's avatar
Thomas Pitiot committed
335
#endif
336
    d=map.volumeOldestDart(d);
Etienne Schmitt's avatar
Etienne Schmitt committed
337
    addElementToVector(RegisteredEdges[d],o);
pitiot's avatar
pitiot committed
338 339

    mo->belonging_cells[n].push_back(d);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
340
    mo->addGeneralCell (d);
pitiot's avatar
pitiot committed
341
    for (Vol volume : volumesAdjacentByVertex3(map,d))
pitiot's avatar
pitiot committed
342
    {
pitiot's avatar
pitiot committed
343
        if (!map.isBoundaryMarked<3>(volume))
pitiot's avatar
pitiot committed
344
        {
Thomas Pitiot 's avatar
Thomas Pitiot committed
345
            volume=map.volumeOldestDart(volume);
pitiot's avatar
pitiot committed
346
            pushSegmentInCellAsNeighbor(o, volume);
Thomas Pitiot 's avatar
Thomas Pitiot committed
347
            mo->neighbor_cells[n].push_back(volume);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
348
            mo->addGeneralNeighbor ( d);
pitiot's avatar
pitiot committed
349 350 351
        }
    }

pitiot's avatar
pitiot committed
352 353 354
#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
355 356 357 358 359 360 361 362
}

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
363
    //    assert( memo_cross.size() > 1);
pitiot's avatar
pitiot committed
364
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
365 366


367 368 369 370 371 372
    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
373
#ifdef DEBUG_affichage
374
        CGoGNout<<"cellule du belong :"<<(d)<<CGoGNendl;
pitiot's avatar
pitiot committed
375
#endif
pitiot's avatar
pitiot committed
376 377

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

380
    for (Dart d : mo->neighbor_cells[n])
pitiot's avatar
pitiot committed
381
    {
382 383 384
            addElementToVector<Segment*>(RegisteredNeighborEdges[d],o);
             mo->addGeneralNeighbor ( (d));

pitiot's avatar
pitiot committed
385
    }
pitiot's avatar
pitiot committed
386 387 388
#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
389 390 391 392
}

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

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

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


Thomas Pitiot 's avatar
Thomas Pitiot committed
418 419 420 421 422 423 424 425 426 427 428 429
/////////////////////////////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
430
        CGoGNout<<"First Registration Triangle "<<o->indexTri<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
431 432 433 434 435 436
#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
437
        for(Edge e : edgesIncidentToFace2<SurfaceMap>(mo->getSurfaceMap(),cell)) // first mark inside
Thomas Pitiot 's avatar
Thomas Pitiot committed
438
        {
Etienne Schmitt's avatar
Etienne Schmitt committed
439
            Dart cell2=mo->getSurfaceMap().phi1(e);
Thomas Pitiot 's avatar
Thomas Pitiot committed
440 441
            // on récupère les aprticules correspondant a chaque edge du triangle a enregistrer

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
444

Thomas Pitiot 's avatar
Thomas Pitiot committed
445

446
            Dart d1=p1->getCell(); // darts de la carte 3D contenant les particules
Thomas Pitiot 's avatar
Thomas Pitiot committed
447 448 449 450
#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
451

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
452 453
            for (Dart d : memo)
                   inside.mark(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
454 455 456

        }

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
457 458 459


        for(Dart d : inside.get_markedCells()) // and register them
Thomas Pitiot 's avatar
Thomas Pitiot committed
460
        {
461
            d=map.volumeOldestDart(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
462
            pushTriangleInCell(o,d);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
463 464
            (mo->belonging_cells[o->indexTri]).push_back(d);
            mo->addGeneralCell ( d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
465
        }
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
466 467
        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
468
        {
469
            d=map.volumeOldestDart(d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
470
            pushTriangleInCellAsNeighbor(o,d);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
471 472
            (mo->neighbor_cells[o->indexTri]).push_back(d);
            mo->addGeneralNeighbor ( d);
Thomas Pitiot 's avatar
Thomas Pitiot committed
473 474 475 476 477 478 479
        }


    }
}


Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
480
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
481 482 483 484 485 486 487
{
#ifdef IHMap
    assert(map.getCurrentLevel() == map.getMaxLevel());
#endif
    assert(!memo_cross.empty());


Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
488
    for(Dart  e : memo_cross)
Thomas Pitiot 's avatar
Thomas Pitiot committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
    {

        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
508
    CGoGNout<<"pop&push arete "<<o->indexTri<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
#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
526
        int n = mo->getIndexOfTriangle(cell);
Thomas Pitiot 's avatar
Thomas Pitiot committed
527 528


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

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
540 541 542 543 544 545
        }
        mo->belonging_cells[n].clear();
        mo->neighbor_cells[n].clear();
    }
}

Thomas Pitiot 's avatar
Thomas Pitiot committed
546
bool EnvMap::subdivideVolume(Dart dglobal, bool OneLevelDifference)
pitiot's avatar
up  
pitiot committed
547
{
548 549 550
    bool res =false;
#ifdef IHMap

pitiot's avatar
up  
pitiot committed
551

552
    map.setCurrentLevel(map.getMaxLevel()) ;
553 554
    unsigned int vLevel = map.volumeLevel(dglobal);
    Dart old = map.volumeOldestDart(dglobal);
Thomas Pitiot 's avatar
Thomas Pitiot committed
555
    Dart centerDart=old;
pitiot's avatar
up  
pitiot committed
556 557 558
#ifdef DEBUG_affichage
    int count = 0;
#endif
559 560
    // 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
561

Thomas Pitiot 's avatar
Thomas Pitiot committed
562
    if(OneLevelDifference)
563
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
564
        map.setCurrentLevel(vLevel) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
565
        for ( Face dit : facesIncidentToVolume3(map,old))
566
        {
Thomas Pitiot 's avatar
Thomas Pitiot committed
567 568 569 570 571
    #ifdef DEBUG_affichage
            count++;
    #endif
            Dart nv = map.phi3(dit);
            if(!map.isBoundaryMarked(3, nv))
572
            {
Thomas Pitiot 's avatar
Thomas Pitiot committed
573 574 575 576 577 578 579 580 581 582 583
                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
                {
584

Thomas Pitiot 's avatar
Thomas Pitiot committed
585 586
                    if(map.checkForSurrounded(nv))
                    {
587

Thomas Pitiot 's avatar
Thomas Pitiot committed
588 589 590 591
                        subdivideVolume(nv,false);

                    }
                }
592 593
            }
        }
594

595 596
    }

pitiot's avatar
up  
pitiot committed
597

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

601
    map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
up  
pitiot committed
602

Thomas Pitiot 's avatar
Thomas Pitiot committed
603
    const ARETES oldobst(RegisteredEdges[dglobal]) ;
604 605 606 607

    for (Segment * o : oldobst)
    {
        this->popSegment(o) ;
608
        o->nid->needResetSegment(o);
609 610
    }

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

613 614
    for (Segment * o : oldNeighborObst)
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
615 616 617 618 619 620 621 622 623 624 625
        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;
        }

626
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
627
    RegisteredNeighborEdges[old].clear();
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
628

Thomas Pitiot 's avatar
Thomas Pitiot committed
629
    const TRIANGLES oldTrian(RegisteredTriangles[dglobal]) ;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
630 631 632 633

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
637
    TRIANGLES oldTrianNeighbor(RegisteredNeighborTriangles[old]) ;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
638 639 640

    for (Triangle * o : oldTrianNeighbor)
    {
641 642 643 644 645 646 647 648 649 650
        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
651
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
652
    RegisteredNeighborTriangles[old].clear();
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
653

Etienne Schmitt's avatar
Etienne Schmitt committed
654 655
    const std::chrono::time_point<std::chrono::system_clock> endPop = std::chrono::system_clock::now();
    duration_pop = endPop - startPop;
656
    if(duration_pop.count()>0.01)CGoGNout << "pop duration : " << duration_pop.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
657 658 659

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
660
    if(!map.isBoundaryMarked(3,dglobal) && map.getDartLevel(dglobal) <= map.getMaxLevel() && !map.volumeIsSubdivided(dglobal) )
pitiot's avatar
up  
pitiot committed
661
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
662
        centerDart =Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position,false);
pitiot's avatar
up  
pitiot committed
663
        res=true;
pitiot's avatar
up  
pitiot committed
664 665
    }

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
670
    map.setCurrentLevel(map.getMaxLevel()) ;
671
    CellMarkerMemo<MAP,VOLUME> newVolumes(map);
Thomas Pitiot 's avatar
Thomas Pitiot committed
672 673 674 675 676 677 678 679
    if(res)
    {
        for(Vol vo : VolumesIncidentToVertex3(map,centerDart))
        {
            newVolumes.mark(map.volumeOldestDart(vo));
        }
    }
    else
680
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
681 682
        newVolumes.mark(old);
    }
Etienne Schmitt's avatar
Etienne Schmitt committed
683

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

688
    for (Dart d : newVolumes.get_markedCells())
Thomas Pitiot 's avatar
Thomas Pitiot committed
689
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
690 691
//        CGoGNout<<"markée :"<<d<<CGoGNendl;

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

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

701 702 703 704 705 706

        // reenregistrement des voisins
        for(Vol v : volumesAdjacentByVertex3(map,d))
        {
            if(!newVolumes.isMarked(v))
            {
Thomas Pitiot 's avatar
Thomas Pitiot committed
707
//                CGoGNout<<"reenregistrement des voisins de : "<<v<<CGoGNendl;
708 709
                for(Segment * s : RegisteredEdges[v])
                {
Thomas Pitiot 's avatar
Thomas Pitiot committed
710
//                    CGoGNout<<"tentative ajout de : "<<s->index<<CGoGNendl;
711 712
                    if(addElementToVector(RegisteredNeighborEdges[d],s))
                    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
713
//                        CGoGNout<<"reussie car non présent"<<CGoGNendl;
714 715 716 717 718 719 720 721 722 723 724 725
                           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
726
    }
727
    const std::chrono::time_point<std::chrono::system_clock> endPushNeighbors = std::chrono::system_clock::now();
Thomas Pitiot 's avatar
Thomas Pitiot committed
728

Etienne Schmitt's avatar
Etienne Schmitt committed
729

730

731 732
    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
733

Thomas Pitiot 's avatar
Thomas Pitiot committed
734
    //same for triangles //
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
735 736
    for (Triangle * o : oldTrian)
    {
737
        start_particule= std::chrono::system_clock::now();
738
        resetPartSubdiv(o);
739 740
        stop_particule= std::chrono::system_clock::now();
        duration_particules+=stop_particule-start_particule;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
741 742
        this->FirstRegistrationTriangle(o) ;
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
743

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
746

pitiot's avatar
up  
pitiot committed
747
    //same for obstacles contained
748
    for (Segment * o : oldobst)
pitiot's avatar
up  
pitiot committed
749
    {
750
        start_particule= std::chrono::system_clock::now();
751
        resetPartSubdiv(o);
752 753
        stop_particule= std::chrono::system_clock::now();
        duration_particules+=stop_particule-start_particule;
754
        FirstRegistrationSegment(o);
pitiot's avatar
up  
pitiot committed
755 756

    }
757
//    CGoGNout << "particules duration : " << duration_particules.count()  << "s "<<CGoGNendl;
Etienne Schmitt's avatar
Etienne Schmitt committed
758 759
    const std::chrono::time_point<std::chrono::system_clock> endPush = std::chrono::system_clock::now();
    duration_push = endPush - startPush;
760 761 762
    std::chrono::duration<double> duration_triangle= (endPushTriangle -endPushNeighbors );
    std::chrono::duration<double> duration_segment= (endPush - endPushTriangle);
    std::chrono::duration<double> duration_neighbors= (endPushNeighbors - startPush );
763 764
    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
765 766


pitiot's avatar
up  
pitiot committed
767 768
#endif
    return res;
pitiot's avatar
up  
pitiot committed
769 770 771

}

772
void EnvMap::resetPartSubdiv(Segment* o)
pitiot's avatar
up  
pitiot committed
773 774 775 776 777 778
{

    ArticulatedObject * mo = o->nid;

    if (mo != NULL)
    {
779 780
        int indPart=o->indexPart1;
        int indPart2=o->indexPart2;
pitiot's avatar
up  
pitiot committed
781 782

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

#endif
787 788 789 790
        if(mo->getNeedForSubd(indPart))
        {
           mo->getParticule(indPart)->resetParticule();
           mo->setNeedForSubd(indPart,0);
Thomas Pitiot 's avatar
Thomas Pitiot committed
791 792
    #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
793

Thomas Pitiot 's avatar
Thomas Pitiot committed
794
    #endif
pitiot's avatar
up  
pitiot committed
795

796 797 798 799 800
        }
        if(mo->getNeedForSubd(indPart2))
        {
           mo->getParticule(indPart2)->resetParticule();
           mo->setNeedForSubd(indPart2,0);
Thomas Pitiot 's avatar
Thomas Pitiot committed
801 802 803 804
    #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
805

806
        }
pitiot's avatar
up  
pitiot committed
807 808
    }

pitiot's avatar
up  
pitiot committed
809

Thomas Pitiot 's avatar
Thomas Pitiot committed
810 811
}

812
void EnvMap::resetPartSubdiv(Triangle * o)
Thomas Pitiot 's avatar
Thomas Pitiot committed
813 814 815 816 817
{

    Surface * mo = o->surf;
    if (mo != NULL)
    {
818 819 820 821 822 823 824 825 826
        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
827 828 829



830 831 832
    #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
833

834 835 836 837 838 839 840
    #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
841

842
    #endif
Thomas Pitiot 's avatar
Thomas Pitiot committed
843

844 845 846 847 848 849 850
        }
        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
851

852 853 854 855 856 857 858 859
    #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
860

861 862
    #endif
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
863 864 865
    }


pitiot's avatar
up  
pitiot committed
866 867
}

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