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

7

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

pitiot's avatar
init  
pitiot committed
11

Jund Thomas's avatar
Jund Thomas committed
12

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

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

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

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

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

pitiot's avatar
pitiot committed
47 48 49

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


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

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


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

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

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

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

pitiot's avatar
pitiot committed
90

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

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

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

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

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

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

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

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


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

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

pitiot's avatar
pitiot committed
143 144

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

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


    return true;
pitiot's avatar
pitiot committed
156 157


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



pitiot's avatar
pitiot committed
162 163 164 165 166





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

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

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

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


191 192 193



Thomas's avatar
Thomas committed
194 195 196 197




pitiot's avatar
init  
pitiot committed
198 199
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
200
{
pitiot's avatar
pitiot committed
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    map.clear(true);
    std::vector<std::string> attrNames ;

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

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

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


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

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

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

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

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

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

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

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


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

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

            pushSegmentInSetOfCells(o, memo);
        }
    }
}

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

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

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

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

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

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

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
355
    //    assert( memo_cross.size() > 1);
pitiot's avatar
pitiot committed
356
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
357 358


359 360 361 362 363 364
    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
365
#ifdef DEBUG_affichage
366
        CGoGNout<<"cellule du belong :"<<(d)<<CGoGNendl;
pitiot's avatar
pitiot committed
367
#endif
pitiot's avatar
pitiot committed
368 369

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

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

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

pitiot's avatar
pitiot committed
388
#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 430 431 432 433 434 435 436
/////////////////////////////enregistrement des triangles



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

    Surface * mo = o->surf;

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

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

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
444 445

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

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

        }

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


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


    }
}


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


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

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

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

            }
        }

    }
}


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


}

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

        int n = mo->indexTriangle[cell];



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

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

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

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

pitiot's avatar
up  
pitiot committed
548

549
    map.setCurrentLevel(map.getMaxLevel()) ;
550 551
    unsigned int vLevel = map.volumeLevel(dglobal);
    Dart old = map.volumeOldestDart(dglobal);
Thomas Pitiot 's avatar
Thomas Pitiot committed
552
    Dart centerDart=old;
pitiot's avatar
up  
pitiot committed
553 554 555
#ifdef DEBUG_affichage
    int count = 0;
#endif
556 557
    // la subdivision ne doit pas mettre plus d'un level de différence entre des cellules adjacentes
    // on commence donc par subdiviser les voisins qui ont trop de différence
pitiot's avatar
up  
pitiot committed
558 559 560
//    Traversor3WF<typename PFP::MAP> traF(map, old, true);
//    for(Dart dit = traF.begin(); dit != traF.end(); dit = traF.next())
//    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
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
                {
Thomas Pitiot 's avatar
Thomas Pitiot committed
584
//                    CGoGNout<<"neighbor not subdivided :"<<nv<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
585 586
                    if(map.checkForSurrounded(nv))
                    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
587
//                        CGoGNout<<"subdiv to avoid"<<CGoGNendl;
Thomas Pitiot 's avatar
Thomas Pitiot committed
588 589 590 591
                        subdivideVolume(nv,false);

                    }
                }
592 593
            }
        }
Thomas Pitiot 's avatar
Thomas Pitiot committed
594
//        CGoGNout<<"\n";
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
Thomas Pitiot 's avatar
Thomas Pitiot committed
600
//    map.check();
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 608 609

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

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

612 613
    for (Segment * o : oldNeighborObst)
    {
614
//        this->popSegment(o) ; // old version
Etienne Schmitt's avatar
Etienne Schmitt committed
615
//        removeElementFromVector(RegisteredNeighborEdges[old], o) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
616 617 618 619 620 621 622 623 624 625 626 627
//        CGoGNout<<"tentative de pop voisin "<<o->index<<" : ";
        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;
        }

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
631
    const TRIANGLES oldTrian(RegisteredTriangles[dglobal]) ;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
632 633 634 635 636 637

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

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

    for (Triangle * o : oldTrianNeighbor)
    {
642
//        this->popTriangle(o) ; // old version
Etienne Schmitt's avatar
Etienne Schmitt committed
643
//        removeElementFromVector(RegisteredNeighborTriangles[old], o) ;
644 645
        removeElementFromVector(o->surf->neighbor_cells[o->indexTri],old);
        o->surf->removeGeneralNeighbor (old);
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
646
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
647
    RegisteredNeighborTriangles[old].clear();
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
648

Etienne Schmitt's avatar
Etienne Schmitt committed
649 650
    const std::chrono::time_point<std::chrono::system_clock> endPop = std::chrono::system_clock::now();
    duration_pop = endPop - startPop;
Thomas Pitiot 's avatar
Thomas Pitiot committed
651
    if(duration_pop.count()>0.035)std::cout << "pop duration : " << duration_pop.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
652 653 654

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
655
    if(!map.isBoundaryMarked(3,dglobal) && map.getDartLevel(dglobal) <= map.getMaxLevel() && !map.volumeIsSubdivided(dglobal) )
pitiot's avatar
up  
pitiot committed
656
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
657 658
        centerDart =Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position,false);

pitiot's avatar
up  
pitiot committed
659
        res=true;
pitiot's avatar
up  
pitiot committed
660 661
    }

Etienne Schmitt's avatar
Etienne Schmitt committed
662 663
    const std::chrono::time_point<std::chrono::system_clock> endSubdiv = std::chrono::system_clock::now();
    duration_subdiv = endSubdiv - startSubdiv;
Thomas Pitiot 's avatar
Thomas Pitiot committed
664
    if(duration_subdiv.count()>0.035)std::cout << "subdiv duration : " << duration_subdiv.count()  << "s\n";
Etienne Schmitt's avatar
Etienne Schmitt committed
665

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
680

681 682


Thomas Pitiot 's avatar
Thomas Pitiot committed
683 684 685 686 687 688 689 690
//    Dart start = old;
//    do                  // on marque les nouvelles cellules ! attention TODO cas des volumes qui n'ont aucune arete en commun avec le volume d'origine
//    {
//        map.setCurrentLevel(vLevel+1);
//        newVolumes.mark(map.volumeOldestDart(start));
//        map.setCurrentLevel(vLevel);
//        start=map.phi1(start);
//    }while(start !=old);
691

Thomas Pitiot 's avatar
Thomas Pitiot committed
692 693 694 695 696 697

    //    map.check();



//    CGoGNout<<"nombre de sous cellules markées :"<<newVolumes.get_markedCells().size()<<CGoGNendl;
698
    for (Dart d : newVolumes.get_markedCells())
Thomas Pitiot 's avatar
Thomas Pitiot committed
699
    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
700 701
//        CGoGNout<<"markée :"<<d<<CGoGNendl;

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

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

710 711 712 713 714 715

        // reenregistrement des voisins
        for(Vol v : volumesAdjacentByVertex3(map,d))
        {
            if(!newVolumes.isMarked(v))
            {
Thomas Pitiot 's avatar
Thomas Pitiot committed
716
//                CGoGNout<<"reenregistrement des voisins de : "<<v<<CGoGNendl;
717 718
                for(Segment * s : RegisteredEdges[v])
                {
Thomas Pitiot 's avatar
Thomas Pitiot committed
719
//                    CGoGNout<<"tentative ajout de : "<<s->index<<CGoGNendl;
720 721
                    if(addElementToVector(RegisteredNeighborEdges[d],s))
                    {
Thomas Pitiot 's avatar
Thomas Pitiot committed
722
//                        CGoGNout<<"reussie car non présent"<<CGoGNendl;
723 724 725 726 727 728 729 730 731 732 733 734
                           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
735 736
    }

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

739 740 741 742 743 744 745 746


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

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

Etienne Schmitt's avatar
Etienne Schmitt committed
748

Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
749 750 751 752 753 754
    //same for triangles // optimiser
    for (Triangle * o : oldTrian)
    {
        resetPartSubdiv(o);
        this->FirstRegistrationTriangle(o) ;
    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
755

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

Thomas Pitiot 's avatar
Thomas Pitiot committed
758

759 760 761 762 763
//    //same for adjacent obstacles // optimiser
//    for (Segment * o : oldNeighborObst)
//    {
////        FirstRegistrationSegment(o) ; // old version
//    }
Thomas Pitiot 's avatar
Thomas Pitiot committed
764 765

    const std::chrono::time_point<std::chrono::system_clock> endPushSegmentNeighbors = std::chrono::system_clock::now();
pitiot's avatar
up  
pitiot committed
766
    //same for obstacles contained
767
    for (Segment * o : oldobst)
pitiot's avatar
up  
pitiot committed
768
    {
769 770
        resetPartSubdiv(o);
        FirstRegistrationSegment(o);
pitiot's avatar
up  
pitiot committed
771 772 773

    }

Etienne Schmitt's avatar
Etienne Schmitt committed
774 775
    const std::chrono::time_point<std::chrono::system_clock> endPush = std::chrono::system_clock::now();
    duration_push = endPush - startPush;
Thomas Pitiot 's avatar
Thomas Pitiot committed
776 777 778 779 780
    std::chrono::duration<double> duration_triangle= (endPushTriangle - startPush);
    std::chrono::duration<double> duration_segment= (endPush - endPushSegmentNeighbors);
    std::chrono::duration<double> duration_segmentNeighbor= (endPushSegmentNeighbors - endPushTriangle);
     if(duration_triangle.count()>0.035)std::cout << "push triangle duration : " << duration_triangle.count()  << "s\n";
    if(duration_push.count()>0.035)std::cout << "push duration : " << duration_push.count() << "\n dont pour les segments présents : "<<duration_segment.count() <<"s\n et pour les voisins :"<<duration_segmentNeighbor.count() <<"s\n";
pitiot's avatar
up  
pitiot committed
781 782


pitiot's avatar
up  
pitiot committed
783 784
#endif
    return res;
pitiot's avatar
up  
pitiot committed
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801

}

void EnvMap::resetPartSubdiv(Segment* o)
{

    ArticulatedObject * mo = o->nid;

    if (mo != NULL)
    {

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

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

#endif

        mo->parts_[o->indexPart1]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
808
        mo->parts_[o->indexPart1]->reset_positionFace();
pitiot's avatar
up  
pitiot committed
809
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
810
        CGoGNout<<"part1 moved to centroid ,d : "<< mo->parts_[o->indexPart1]->getPosition()<<" || "<<mo->parts_[o->indexPart1]->d<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
811 812 813 814 815

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

#endif
        mo->parts_[o->indexPart2]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d2,position)) ;
Thomas Pitiot 's avatar
Thomas Pitiot committed
820
        mo->parts_[o->indexPart2]->reset_positionFace();
pitiot's avatar
up  
pitiot committed
821
#ifdef DEBUG_affichage
Thomas Pitiot 's avatar
Thomas Pitiot committed
822
        CGoGNout<<"part2 moved to centroid ,d : "<< mo->parts_[o->indexPart2]->getPosition()<<" || "<<mo->parts_[o->indexPart2]->d<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
823 824 825 826 827

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

#endif
    }

pitiot's avatar
up  
pitiot committed
833

Thomas Pitiot 's avatar
Thomas Pitiot committed
834 835 836 837 838 839 840 841 842
}

void EnvMap::resetPartSubdiv(Triangle * o)
{

    Surface * mo = o->surf;
    Dart cell =o->cell;
    Dart cell2 = mo->surfaceMap.phi1(cell);
    Dart cell3 = mo->surfaceMap.phi1(cell2);
Etienne Schmitt's avatar
Etienne Schmitt committed
843 844 845
    Particule * p = mo->parts_[mo->indexParticule[cell]];
    Particule * p2 = mo->parts_[mo->indexParticule[cell2]];
    Particule * p3 = mo->parts_[mo->indexParticule[cell3]];
Thomas Pitiot 's avatar
Thomas Pitiot committed
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863

    if (mo != NULL)
    {

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

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

#endif

        p->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
Thomas Pitiot 's avatar
up2  
Thomas Pitiot committed
864
        p->reset_positionFace(); // attention avec les particules 3D on doit mettre a jour la position_face !!!
Thomas Pitiot 's avatar
Thomas Pitiot committed
865 866 867 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
#ifdef DEBUG_affichage
        CGoGNout<<"part1 moved to centroid ,d : "<< p->getPosition()<<" || "<<p->d<<CGoGNendl;

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

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

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

#endif

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

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

#endif
    }


pitiot's avatar
up  
pitiot committed
903 904
}

pitiot's avatar
init  
pitiot committed
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 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
//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
977 978
//		PFP::SegmentVECT obst ;
//		PFP::SegmentVECT neighborObst ;
pitiot's avatar
init  
pitiot committed
979 980 981 982 983 984 985 986 987
//		//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
988
//				PFP::SegmentVECT resetob = RegisteredEdges[nf] ;
pitiot's avatar
init  
pitiot committed
989 990 991 992
//				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
993
//				for (PFP::SegmentVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
//				{
//
//						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
1009
//			PFP::SegmentVECT ob(RegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
1010 1011
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
pitiot's avatar
pitiot committed
1012
//
pitiot's avatar
init  
pitiot committed
1013
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1014
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
1015 1016
//			{
////				resetObstPartInFace(*ait, fit,fLevel);
pitiot's avatar
pitiot committed
1017
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
//				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
1035
//			PFP::SegmentVECT ob(RegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
1036 1037 1038
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1039
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
1040 1041
//			{
////				resetObstPartInFace(*ait, fit,Level);
pitiot's avatar
pitiot committed
1042
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
//				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
1054
//			PFP::SegmentVECT nob(neighborRegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
1055 1056
//
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1057
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
1058
//			{
pitiot's avatar
pitiot committed
1059
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
//				neighborObst.push_back(*ait);
//			}
//			map.setCurrentLevel(fLevel - 1) ;
//
//			fit = map.phi1(fit) ;
//		} while (fit != old) ;
//
//		if (degree == 3)
//		{
//			map.setCurrentLevel(fLevel) ;
//			Dart centerFace = map.phi2(map.phi1(old)) ;
pitiot's avatar
pitiot committed
1071
//			PFP::SegmentVECT nob(neighborRegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
1072
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
1073
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
1074
//			{
pitiot's avatar
pitiot committed
1075
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
1076 1077 1078 1079 1080 1081 1082 1083 1084