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

6

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

pitiot's avatar
init  
pitiot committed
10

Jund Thomas's avatar
Jund Thomas committed
11

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

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

//	refineCandidate.reserve(100) ;
//	coarsenCandidate.reserve(100) ;
20 21 22
#endif
}

pitiot's avatar
init  
pitiot committed
23
void EnvMap::init(int argc, char **argv)
24 25
{
	std::cout << "Init EnvMap" << std::endl ;
pitiot's avatar
pitiot committed
26
    if (argc>2)
David Cazier's avatar
David Cazier committed
27
	{
pitiot's avatar
pitiot committed
28
        std::string filename(argv[2]);
pitiot's avatar
pitiot committed
29
        open_file(filename);
30
	}
pitiot's avatar
init  
pitiot committed
31
	else
32
	{
pitiot's avatar
pitiot committed
33
//Intialisation map
pitiot's avatar
pitiot committed
34 35 36
#ifdef IHMap
        map.initImplicitProperties();  // Si map MR
#endif
pitiot's avatar
init  
pitiot committed
37

pitiot's avatar
pitiot committed
38 39 40

        ///// initialisation attributs
        position = map.addAttribute<VEC3, VERTEX, MAP>("position");
pitiot's avatar
up  
pitiot committed
41
        facecenter = map.addAttribute<VEC3, FACE, MAP>("facecenter");
pitiot's avatar
pitiot committed
42 43 44
        color = map.addAttribute<VEC3, VOLUME, MAP>("color");
        RegisteredEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredEdges");
        RegisteredNeighborEdges=map.addAttribute<ARETES,VOLUME, MAP>("RegisteredNeighborEdges");
pitiot's avatar
pitiot committed
45 46 47 48 49



        int nb = 5;
        Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(map, nb, nb, nb);
pitiot's avatar
pitiot committed
50
        cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
pitiot's avatar
pitiot committed
51

pitiot's avatar
pitiot committed
52
//        subdivideVolume(map.begin());
pitiot's avatar
pitiot committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88


//        Algo::Surface::Modelisation::createTetrahedron<PFP>(map,true);
//        Algo::Surface::Modelisation::embedPyramid<PFP>(map,position,3,true,1.0f,1.0f);
//        Algo::Volume::Modelisation::sqrt3Vol<PFP>(map,position);

        map.check();
//        Dart d1=map.indexDart(0);
//        Dart d2=map.indexDart(1);
//        Dart d3=map.indexDart(8);
//        Geom::Plane3D<PFP::REAL> pl (position[d1],position[d2],position[d3]);
//        Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,d2,pl);
//        map.check();


//        VEC3 center = Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,map.indexDart(0),position);
//        VEC3 norm = Algo::Surface::Geometry::faceNormal<PFP, VertexAttribute<VEC3, MAP>>(map,map.indexDart(0),position);
//        VEC3 norm2 = Algo::Surface::Geometry::faceNormal<PFP, VertexAttribute<VEC3, MAP>>(map,map.indexDart(4),position);
//        VEC3 norm3 = Algo::Surface::Geometry::faceNormal<PFP, VertexAttribute<VEC3, MAP>>(map,map.indexDart(16),position);
//        Geom::Plane3D<PFP::REAL> pl (norm,center);
//        Geom::Plane3D<PFP::REAL> pl2 (norm2,center);
//        Geom::Plane3D<PFP::REAL> pl3 (norm3,center);
//        Dart newd = Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,map.indexDart(0),pl);
//        map.check();
//        Dart newd2 =Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,map.indexDart(0),pl2);
//        Dart newd3 =Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,newd,pl2);
//        map.check();
//        Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,map.indexDart(0),pl3);
//        Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,newd,pl3);
//        Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,map.indexDart(3),pl3);
//        Algo::Volume::Modelisation::sliceConvexVolume<PFP>(map,position,map.indexDart(15),pl3);
//        map.check();
//        CGoGNout<<" darts : 0 , "<<newd<<" , "<<newd2<<" , "<<newd3<<CGoGNendl;



pitiot's avatar
pitiot committed
89 90 91 92 93
        TraversorV<MAP> tv(map);
        for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
        {
            position[d] *= 10;
        }
pitiot's avatar
up  
pitiot committed
94 95 96 97 98 99 100
        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
101 102 103 104 105 106 107

        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
108 109 110



pitiot's avatar
pitiot committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
//        //// affichage positions
//        CellMarkerStore<MAP, VOLUME> m(map) ;
//        for (Dart d = map.begin(); d != map.end(); map.next(d))
//        {
//            if (!m.isMarked(d))
//            {
//                m.mark(d) ;
//               CGoGNout<<"Dart "<<d.index<<" en : "<<position[d]<<CGoGNendl;
//            }
//        }



/////////////////////////// Subdivision
//		std::cout << "level :"<<map.getCurrentLevel() << std::endl ;
//		Dart d =Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map,map.phi2(map.begin()), position);
//		std::cout << "centralDart : "<< d.index << std::endl ;
//		map.setCurrentLevel(1);
//		std::cout << "level :"<<map.getCurrentLevel() << std::endl ;




134
	}
135

136

pitiot's avatar
pitiot committed
137 138
}

pitiot's avatar
up  
pitiot committed
139

pitiot's avatar
pitiot committed
140
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
141 142 143 144 145 146 147 148
{
     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
pitiot committed
149
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
150 151 152
{
    if(insideVolume(pos, neighborhood))
        return true;
pitiot's avatar
pitiot committed
153 154

    for (Vol d : volumesAdjacentByVertex3(map,neighborhood))
pitiot's avatar
up  
pitiot committed
155 156 157 158 159 160 161
    {
        if (!map.isBoundaryMarked<3>(d) )
        {
            if(insideVolume(pos, d))
                return true;
        }
    }
pitiot's avatar
pitiot committed
162 163


pitiot's avatar
up  
pitiot committed
164 165 166
    return false;
}

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

pitiot's avatar
pitiot committed
170 171

    for(Face d : facesIncidentToVolume3(map,volume))
pitiot's avatar
up  
pitiot committed
172 173 174 175 176 177 178 179 180 181 182
    {
        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
183 184


pitiot's avatar
up  
pitiot committed
185 186 187 188
}



pitiot's avatar
pitiot committed
189 190 191 192 193





pitiot's avatar
pitiot committed
194
///// a coder
pitiot's avatar
up  
pitiot committed
195

pitiot's avatar
pitiot committed
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
Dart EnvMap::getBelongingCell(const PFP::VEC3& pos)
{
    assert(map.getCurrentLevel() == map.getMaxLevel()) ;

    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
214 215


216 217 218



Thomas's avatar
Thomas committed
219 220 221 222




pitiot's avatar
init  
pitiot committed
223 224
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
225
{
pitiot's avatar
pitiot committed
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 279 280 281 282 283 284 285 286 287
    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
288 289
}

David Cazier's avatar
David Cazier committed
290

pitiot's avatar
init  
pitiot committed
291 292 293 294 295 296 297 298 299 300 301
//void EnvMap::subdivideAllToMaxLevel()
//{
//	bool subdiv ;
//	do
//	{
//		subdiv = false ;
//		{
//			CellMarker<FACE> subd(map) ;
//			for (Dart d = map.begin(); d != map.end(); map.next(d))
//			{
//				if (!subd.isMarked(d))
David Cazier's avatar
David Cazier committed
302
//				{
pitiot's avatar
init  
pitiot committed
303 304
//					subd.mark(d) ;
//					if (!buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
305
//					{
pitiot's avatar
init  
pitiot committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
//						//check if subdivision is authorized
//						float minDistSq = Agent::neighborDistSq_ ;
//						bool subdivisable = true ;
//						Dart old = map.faceOldestDart(d) ;
//						unsigned int fLevel = map.faceLevel(old) ;
//						map.setCurrentLevel(fLevel) ;
//						PFP::VEC3 fCenter = Algo::Surface::Geometry::faceCentroid<PFP>(map, old, position) ;
//						Dart fd = old ;
//						do
//						{
//							PFP::VEC3& p = position[fd] ;
//							PFP::VEC3 edge = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, fd,
//							                                                      position) ;
//							PFP::VEC3 proj = fCenter
//							    - (p + (edge * (fCenter - p) / edge.norm2()) * edge) ;
//							if (proj.norm2() < minDistSq)
//							{
//								subdivisable = false ;
//								break ;
//							}
//							fd = map.phi1(fd) ;
//						} while (fd != old) ;
//
//						if (subdivisable)
//						{
//							map.setCurrentLevel(fLevel) ;
//							Algo::Surface::IHM::subdivideFace<PFP>(map, old, position) ;
//							subdiv = true ;
//						}
//						map.setCurrentLevel(map.getMaxLevel()) ;
David Cazier's avatar
David Cazier committed
336
//					}
pitiot's avatar
init  
pitiot committed
337
//				}
338
//			}
pitiot's avatar
init  
pitiot committed
339 340 341 342 343 344 345 346 347 348 349 350 351
//		}
//	} while (subdiv) ;
//}
//
//void EnvMap::subdivideToProperLevel()
//{
//	bool subdiv ;
//	do
//	{
//		subdiv = false ;
//		{
//			CellMarker<FACE> subd(map) ;
//			for (Dart d = map.begin(); d != map.end(); map.next(d))
352
//			{
pitiot's avatar
init  
pitiot committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366
//				if (!subd.isMarked(d))
//				{
//					subd.mark(d) ;
//					if (!refineMark.isMarked(d) && agentvect[d].size() > nbAgentsToSubdivide)
//					{
//						std::pair<bool, bool>& sf = subdivisableFace[d] ;
//						if (sf.first == false || (sf.first == true && sf.second))
//						{
//							subdiv = true ;
//							refineMark.mark(d) ;
//							refineCandidate.push_back(d) ;
//						}
//					}
//				}
367
//			}
pitiot's avatar
init  
pitiot committed
368 369 370 371 372 373 374
//			subd.unmarkAll() ;
//		}
//		updateMap() ;
//		refineCandidate.clear() ;
//		map.setCurrentLevel(map.getMaxLevel()) ;
//	} while (subdiv) ;
//}
375

pitiot's avatar
init  
pitiot committed
376 377
//
//
pitiot's avatar
pitiot committed
378 379
void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en question
{
pitiot's avatar
init  
pitiot committed
380

pitiot's avatar
pitiot committed
381
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
382 383
    if (mo != NULL)
    {
pitiot's avatar
pitiot committed
384 385
        int n1 = o->indexPart1;
        int n2 = o->indexPart2;
pitiot's avatar
pitiot committed
386
#ifdef DEBUG_affichage
pitiot's avatar
up  
pitiot committed
387
        CGoGNout<<"First Registration arete "<<o->index<<CGoGNendl;
pitiot's avatar
pitiot committed
388 389 390 391 392 393 394
#endif
        VEC3 p1 = o->p1;
        VEC3 p2 =  o->p2;

        Dart d1=NIL;
        Dart d2=NIL;
        std::vector<Dart> memo;
pitiot's avatar
pitiot committed
395 396
        d1=mo->parts_[n1]->d;
        d2=mo->parts_[n2]->d;
pitiot's avatar
pitiot committed
397 398


pitiot's avatar
pitiot committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
        memo = getMemoCross(p1,p2,d1);

        if(map.sameVolume(d1,d2))
        {
            pushAOneCellSegment(o , d1);
        }
        else
        {

            pushSegmentInSetOfCells(o, memo);
        }
    }
}

Dart EnvMap::popAndPushSegment(Segment* o)// maj de l'enregistrement
{
#ifdef DEBUG_affichage
        CGoGNout<<"pop&push arete "<<o->index<<CGoGNendl;
#endif
    popSegment(o);
    FirstRegistrationSegment(o);

pitiot's avatar
pitiot committed
421
    return o->nid->parts_[o->indexPart1]->d;;
pitiot's avatar
pitiot committed
422 423 424 425 426
}

void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
    int n = o->index;
pitiot's avatar
pitiot committed
427
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
428 429 430 431 432 433 434 435 436
#ifdef DEBUG_affichage
    CGoGNout<<"Push in one cell segment arete "<<n<<CGoGNendl;
#endif
    assert(map.getCurrentLevel() == map.getMaxLevel());

    addElementToVector<Segment*>(RegisteredEdges[d],o);

    mo->belonging_cells[n].push_back(d);
    mo->addGeneralCell (d);
pitiot's avatar
pitiot committed
437
    for (Vol volume : volumesAdjacentByVertex3(map,d))
pitiot's avatar
pitiot committed
438
    {
pitiot's avatar
pitiot committed
439
        if (!map.isBoundaryMarked<3>(volume))
pitiot's avatar
pitiot committed
440
        {
pitiot's avatar
pitiot committed
441 442
            pushSegmentInCellAsNeighbor(o, volume);
             mo->neighbor_cells[n].push_back(volume);
pitiot's avatar
pitiot committed
443 444 445
        }
    }

pitiot's avatar
pitiot committed
446 447
#ifdef DEBUG_affichage
    CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
448 449 450 451 452 453 454 455
//    if(mo->neighbor_cells[n].size()>26)
//    {
//        for(auto d : mo->neighbor_cells[n])
//        {
//            CGoGNout<<" || "<<d<<" || "<<CGoGNendl;
//        }
//    }

pitiot's avatar
pitiot committed
456
#endif
pitiot's avatar
pitiot committed
457 458 459 460 461 462 463 464 465
}

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
    assert(!memo_cross.empty());
pitiot's avatar
pitiot committed
466
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
467 468 469 470 471 472 473

    mo->belonging_cells[n] = memo_cross;
    for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin();	it != mo->belonging_cells[n].end(); ++it)
    {

            addElementToVector<Segment*>(RegisteredEdges[*it],o);
            mo->addGeneralCell (*it);
pitiot's avatar
pitiot committed
474 475 476
#ifdef DEBUG_affichage
    CGoGNout<<"cellule du belong :"<<(*it)<<CGoGNendl;
#endif
pitiot's avatar
pitiot committed
477 478 479 480 481 482 483 484 485 486 487

    }
    FindNeighborCellsOfSegment(mo->belonging_cells[n], &(mo->neighbor_cells[n]));

    for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin(); it != mo->neighbor_cells[n].end(); ++it)
    {
        if (!map.isBoundaryMarked<3>(*it))
        {
            addElementToVector<Segment*>(RegisteredNeighborEdges[*it],o);
        }
    }
pitiot's avatar
pitiot committed
488 489
#ifdef DEBUG_affichage
    CGoGNout<<"fin du push , etat du belong/neighbor : "<<mo->belonging_cells[n].size()<<"/"<<mo->neighbor_cells[n].size()<<CGoGNendl;
pitiot's avatar
up  
pitiot committed
490 491 492 493 494 495 496 497
//    if(mo->neighbor_cells[n].size()>26)
//    {
//        for(auto d : mo->neighbor_cells[n])
//        {
//            CGoGNout<<" || "<<d<<" || "<<CGoGNendl;
//        }
//    }

pitiot's avatar
pitiot committed
498
#endif
pitiot's avatar
pitiot committed
499 500 501 502
}

void EnvMap::popSegment(Segment* o)
{
pitiot's avatar
pitiot committed
503
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
    int n = o->index;
    assert(map.getCurrentLevel() == map.getMaxLevel()) ;

    if (mo != NULL)
    {
        for (std::vector<Dart>::iterator it = mo->belonging_cells[n].begin();	it != mo->belonging_cells[n].end(); ++it)
        {
            removeElementFromVector<Segment*>(RegisteredEdges[*it], o) ;
            mo->removeGeneralCell (*it);
        }
        for (std::vector<Dart>::iterator it = mo->neighbor_cells[n].begin(); it != mo->neighbor_cells[n].end(); ++it)
        {
            if (!map.isBoundaryMarked<3>(*it))
            {
                removeElementFromVector<Segment*>(RegisteredNeighborEdges[*it], o) ;
            }
        }
        mo->belonging_cells[n].clear();
        mo->neighbor_cells[n].clear();
    }
}
pitiot's avatar
up  
pitiot committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624


void EnvMap::subdivideVolume(Dart dglobal)
{

    CGoGNout<<"debut refine"<<CGoGNendl;
    unsigned int max = map.getMaxLevel() ;
    map.setCurrentLevel(max) ;


    std::cout << "dglobal = " << dglobal << "level = "<< max << std::endl;


    ARETES oldobst(RegisteredEdges[dglobal]) ;
    ARETES oldNeighborObst(RegisteredNeighborEdges[dglobal]) ;

    for (Segment * s : oldobst)
        this->popSegment(s) ;
    for (Segment * s : oldNeighborObst)
        this->popSegment(s) ;

    if(!map.isBoundaryMarked(3,dglobal) )
    {
#ifdef DEBUG_affichage
    CGoGNout<<"debut subdivision"<< CGoGNendl;
#endif
        Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position);

    }

    map.setCurrentLevel(map.getMaxLevel()) ;
    map.check();
    std::cout << "after level = "<< map.getMaxLevel() << std::endl;

    //same for adjacent obstacles // optimiser
    for (Segment * s : oldNeighborObst)
    {
        FirstRegistrationSegment(s) ;
    }
    //same for obstacles contained
    for (Segment * s : oldobst)
    {
//					CGoGNout<<"reseting Obstacles"<<CGoGNendl;
        resetPartSubdiv(s);
        FirstRegistrationSegment(s);

    }




                CGoGNout<<"fin refine"<<CGoGNendl;

}

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
    CGoGNout<<"Reset part subdiv (segment ,ind1, pos1, d1, ind2, pos2, d2) : "<<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

        mo->parts_[o->indexPart1]->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::volumeCentroid<PFP,VertexAttribute<VEC3,MAP>>(map,d1,position)) ;
#ifdef DEBUG_affichage
      CGoGNout<<"part1 moved to centroid ,d : "<< mo->parts_[o->indexPart1]->getPosition()<<" || "<<mo->parts_[o->indexPart1]->d<<CGoGNendl;

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

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

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

#endif
    }

}

pitiot's avatar
init  
pitiot committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
//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
697 698
//		PFP::SegmentVECT obst ;
//		PFP::SegmentVECT neighborObst ;
pitiot's avatar
init  
pitiot committed
699 700 701 702 703 704 705 706 707
//		//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
708
//				PFP::SegmentVECT resetob = RegisteredEdges[nf] ;
pitiot's avatar
init  
pitiot committed
709 710 711 712
//				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
713
//				for (PFP::SegmentVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
//				{
//
//						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
729
//			PFP::SegmentVECT ob(RegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
730 731
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
pitiot's avatar
pitiot committed
732
//
pitiot's avatar
init  
pitiot committed
733
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
734
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
735 736
//			{
////				resetObstPartInFace(*ait, fit,fLevel);
pitiot's avatar
pitiot committed
737
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
//				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
755
//			PFP::SegmentVECT ob(RegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
756 757 758
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
759
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
760 761
//			{
////				resetObstPartInFace(*ait, fit,Level);
pitiot's avatar
pitiot committed
762
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
763 764 765 766 767 768 769 770 771 772 773
//				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
774
//			PFP::SegmentVECT nob(neighborRegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
775 776
//
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
777
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
778
//			{
pitiot's avatar
pitiot committed
779
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
780 781 782 783 784 785 786 787 788 789 790
//				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
791
//			PFP::SegmentVECT nob(neighborRegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
792
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
793
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
794
//			{
pitiot's avatar
pitiot committed
795
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
//				neighborObst.push_back(*ait);
//			}
//			map.setCurrentLevel(fLevel - 1) ;
//		}
//
//
//
//
//
//		map.setCurrentLevel(fLevel - 1) ;
//
//		Algo::Surface::IHM::coarsenFace<PFP>(map, old, position) ;
//
//		std::pair<bool, bool>& sf = subdivisableFace[old] ;
//		sf.first = true ;
//		sf.second = true ;
//
//		map.setCurrentLevel(map.getMaxLevel()) ;
//
//		neighborAgentvect[old].clear() ;
//
//		for (PFP::AGENTS::iterator itA = agents.begin(); itA != agents.end(); ++itA)
//		{
//			(*itA)->part_.d = old ;
//			pushAgentInCells(*itA, old) ;
//		}
pitiot's avatar
pitiot committed
822
//		for (PFP::SegmentVECT::iterator ait = obst.begin(); ait != obst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
823 824
//		{
//			resetObstPartInFace(*ait, old);
pitiot's avatar
pitiot committed
825
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
826
//		}
pitiot's avatar
pitiot committed
827
//		for (PFP::SegmentVECT::iterator ait = neighborObst.begin(); ait != neighborObst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
828
//		{
pitiot's avatar
pitiot committed
829
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
//		}
//
//		Dart dd = old ;
//		do
//		{
//			Dart ddd = map.alpha1(map.alpha1(dd)) ;
//			while (ddd != dd)
//			{
//				neighborAgentvect[old].insert(neighborAgentvect[old].end(), agentvect[ddd].begin(), agentvect[ddd].end()) ;
//				ddd = map.alpha1(ddd) ;
//			}
//			dd = map.phi1(dd) ;
//		} while (dd != old) ;
//
//		if (fLevel > 1 && !coarsenMark.isMarked(old) && agentvect[old].size() < nbAgentsToSimplify)
//		{
//			coarsenMark.mark(old) ;
//			coarsenCandidate.push_back(map.faceOldestDart(old)) ;
//		}
//
//		map.setCurrentLevel(cur) ;
//	}
//	map.setCurrentLevel(map.getMaxLevel()) ;
//
//	if (coarsenCandidate.size() > 0)
//		updateMap() ;
//}
//
//void EnvMap::updateMap()
//{
//	assert(map.getCurrentLevel() == map.getMaxLevel()) ;
//
//	refine();
//	coarse();
//}
David Cazier's avatar
David Cazier committed
865

David Cazier's avatar
David Cazier committed
866