env_map.cpp 25.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"
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
}

void EnvMap::subdivideVolume(Dart dglobal)
{
    unsigned int max = map.getMaxLevel() ;
    map.setCurrentLevel(max) ;


    std::cout << "dglobal = " << dglobal << std::endl;
    if(!map.isBoundaryMarked(3,dglobal) && map.getDartLevel(dglobal) <= max && !map.volumeIsSubdivided(dglobal))
      Algo::Volume::IHM::subdivideVolumeClassic<PFP>(map, dglobal, position);

    map.setCurrentLevel(map.getMaxLevel()) ;

    CGoGNout << "current level : " <<  map.getCurrentLevel() << CGoGNendl;



pitiot's avatar
pitiot committed
155
}
pitiot's avatar
up  
pitiot committed
156

pitiot's avatar
pitiot committed
157
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
158 159 160 161 162 163 164 165
{
     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
166
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
167 168 169
{
    if(insideVolume(pos, neighborhood))
        return true;
pitiot's avatar
pitiot committed
170 171

    for (Vol d : volumesAdjacentByVertex3(map,neighborhood))
pitiot's avatar
up  
pitiot committed
172 173 174 175 176 177 178
    {
        if (!map.isBoundaryMarked<3>(d) )
        {
            if(insideVolume(pos, d))
                return true;
        }
    }
pitiot's avatar
pitiot committed
179 180


pitiot's avatar
up  
pitiot committed
181 182 183
    return false;
}

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

pitiot's avatar
pitiot committed
187 188

    for(Face d : facesIncidentToVolume3(map,volume))
pitiot's avatar
up  
pitiot committed
189 190 191 192 193 194 195 196 197 198 199
    {
        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
200 201


pitiot's avatar
up  
pitiot committed
202 203 204 205
}



pitiot's avatar
pitiot committed
206 207 208 209 210





pitiot's avatar
pitiot committed
211
///// a coder
pitiot's avatar
up  
pitiot committed
212

pitiot's avatar
pitiot committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
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
231 232


233 234 235



Thomas's avatar
Thomas committed
236 237 238 239




pitiot's avatar
init  
pitiot committed
240 241
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
242
{
pitiot's avatar
pitiot committed
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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    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
305 306
}

David Cazier's avatar
David Cazier committed
307

pitiot's avatar
init  
pitiot committed
308 309 310 311 312 313 314 315 316 317 318
//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
319
//				{
pitiot's avatar
init  
pitiot committed
320 321
//					subd.mark(d) ;
//					if (!buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
322
//					{
pitiot's avatar
init  
pitiot committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
//						//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
353
//					}
pitiot's avatar
init  
pitiot committed
354
//				}
355
//			}
pitiot's avatar
init  
pitiot committed
356 357 358 359 360 361 362 363 364 365 366 367 368
//		}
//	} 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))
369
//			{
pitiot's avatar
init  
pitiot committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383
//				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) ;
//						}
//					}
//				}
384
//			}
pitiot's avatar
init  
pitiot committed
385 386 387 388 389 390 391
//			subd.unmarkAll() ;
//		}
//		updateMap() ;
//		refineCandidate.clear() ;
//		map.setCurrentLevel(map.getMaxLevel()) ;
//	} while (subdiv) ;
//}
392

pitiot's avatar
init  
pitiot committed
393 394
//
//
pitiot's avatar
pitiot committed
395 396
void EnvMap::FirstRegistrationSegment(Segment * o)// réenregistre l'Segment en question
{
pitiot's avatar
init  
pitiot committed
397

pitiot's avatar
pitiot committed
398
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
399 400
    if (mo != NULL)
    {
pitiot's avatar
pitiot committed
401 402
        int n1 = o->indexPart1;
        int n2 = o->indexPart2;
pitiot's avatar
pitiot committed
403 404 405 406 407 408 409 410 411
#ifdef DEBUG_affichage
        CGoGNout<<"First Registration arete "<<n<<CGoGNendl;
#endif
        VEC3 p1 = o->p1;
        VEC3 p2 =  o->p2;

        Dart d1=NIL;
        Dart d2=NIL;
        std::vector<Dart> memo;
pitiot's avatar
pitiot committed
412 413
        d1=mo->parts_[n1]->d;
        d2=mo->parts_[n2]->d;
pitiot's avatar
pitiot committed
414 415


pitiot's avatar
pitiot committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
        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
438
    return o->nid->parts_[o->indexPart1]->d;;
pitiot's avatar
pitiot committed
439 440 441 442 443
}

void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
    int n = o->index;
pitiot's avatar
pitiot committed
444
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
445 446 447 448 449 450 451 452 453
#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
454
    for (Vol volume : volumesAdjacentByVertex3(map,d))
pitiot's avatar
pitiot committed
455
    {
pitiot's avatar
pitiot committed
456
        if (!map.isBoundaryMarked<3>(volume))
pitiot's avatar
pitiot committed
457
        {
pitiot's avatar
pitiot committed
458 459
            pushSegmentInCellAsNeighbor(o, volume);
             mo->neighbor_cells[n].push_back(volume);
pitiot's avatar
pitiot committed
460 461 462
        }
    }

pitiot's avatar
pitiot committed
463 464 465
#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
466 467 468 469 470 471 472 473 474
}

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
475
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
476 477 478 479 480 481 482

    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
483 484 485
#ifdef DEBUG_affichage
    CGoGNout<<"cellule du belong :"<<(*it)<<CGoGNendl;
#endif
pitiot's avatar
pitiot committed
486 487 488 489 490 491 492 493 494 495 496

    }
    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
497 498 499
#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
500 501 502 503
}

void EnvMap::popSegment(Segment* o)
{
pitiot's avatar
pitiot committed
504
    ArticulatedObject * mo = o->nid;
pitiot's avatar
pitiot committed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
    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
init  
pitiot committed
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
//
//
//void EnvMap::refine()
//{
////	CGoGNout<<"refine"<<CGoGNendl;
//	for (std::vector<Dart>::iterator it = refineCandidate.begin(); it != refineCandidate.end(); ++it)
//	{
//		Dart d = (*it) ;
//		refineMark.unmark(d) ;
//
//		//if the number of agents is big enough
//		if (agentvect[d].size() > nbAgentsToSubdivide)
//		{
//			int fLevel = -1 ;
//			Dart old = map.faceOldestDart(d) ;
//
//			bool subdivisable = true ;
//
//			//check if faces resulting from a subdivision are big enough
//			std::pair<bool, bool>& sf = subdivisableFace[old] ;
//			if (sf.first == true)
//				subdivisable = sf.second ;
//			else
//			{
////				float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
//				float minSizeSq = Agent::neighborDistSq_;
//
//				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() < minSizeSq)
David Cazier's avatar
David Cazier committed
563
//					{
pitiot's avatar
init  
pitiot committed
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
//						subdivisable = false ;
//						break ;
//					}
//					fd = map.phi1(fd) ;
//				} while (fd != old) ;
//				map.setCurrentLevel(map.getMaxLevel()) ;
//
//				sf.first = true ;
//				sf.second = subdivisable ;
//			}
//
//			if (subdivisable)
//			{
//				if (fLevel == -1)
//					fLevel = map.faceLevel(old) ;
//
//				sf.first = false ;
//
//				PFP::AGENTS oldAgents(agentvect[old]) ;
pitiot's avatar
pitiot committed
583 584
//				PFP::SegmentVECT oldObst(RegisteredEdges[old]) ;
//				PFP::SegmentVECT oldNeighborObst(neighborRegisteredEdges[old]) ;
pitiot's avatar
init  
pitiot committed
585 586 587 588 589
//
//				for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
//				{
//					popAgentInCells(*ait, old) ;
//				}
pitiot's avatar
pitiot committed
590 591 592 593
//				for (PFP::SegmentVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
//					this->popSegment(*ait) ;
//				for (PFP::SegmentVECT::iterator ait = oldNeighborObst.begin();ait != oldNeighborObst.end(); ++ait)
//					this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
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 625
//				neighborAgentvect[old].clear() ;
//
//				map.setCurrentLevel(fLevel) ;
//				Algo::Surface::IHM::subdivideFace<PFP>(map, old, position) ;
//				CellMarkerStore<FACE> newF(map) ;
//				unsigned int degree = 0 ;
//				Dart dd = old ;
//				do
//				{
//					++degree ;
//					newF.mark(dd) ;
//					dd = map.phi1(dd) ;
//				} while (dd != old) ;
//				map.setCurrentLevel(fLevel+1) ;
//				if (degree == 3)
//				{
//					Dart centerFace = map.phi2(map.phi1(old)) ;
//					newF.mark(centerFace) ;
//				}
//
//				map.setCurrentLevel(map.getMaxLevel()) ;
//				//retrieve neighbors agents from onering cells
//				dd = old ;
//				do
//				{
//					Dart d3 = dd ;
//
//					do
//					{
//						Dart d4 = map.alpha1(map.alpha1(d3)) ;
//						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
//						while (d4 != d3)
626
//						{
pitiot's avatar
init  
pitiot committed
627 628 629 630 631 632
//							if (!newF.isMarked(d4))
//							{
//								PFP::AGENTS& ad4 = agentvect[d4] ;
//								nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
//							}
//							d4 = map.alpha1(d4) ;
633
//						}
pitiot's avatar
init  
pitiot committed
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
//						d3 = map.phi1(d3) ;
//					} while (d3 != dd) ;
//
//					map.setCurrentLevel(fLevel) ;
//					dd = map.phi1(dd) ;
//					map.setCurrentLevel(map.getMaxLevel()) ;
//				} while (dd != old) ;
//
//
//
//				if (degree == 3)
//				{
//					map.setCurrentLevel(fLevel+1) ;
//					Dart centerFace = map.phi2(map.phi1(old)) ;
//					map.setCurrentLevel(map.getMaxLevel()) ;
//					Dart d3 = centerFace ;
//					do
651
//					{
pitiot's avatar
init  
pitiot committed
652 653 654
//						Dart d4 = map.alpha1(map.alpha1(d3)) ;
//						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
//						while (d4 != d3)
655
//						{
pitiot's avatar
init  
pitiot committed
656 657 658 659 660 661
//							if (!newF.isMarked(d4))
//							{
//								PFP::AGENTS& ad4 = agentvect[d4] ;
//								nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
//							}
//							d4 = map.alpha1(d4) ;
662
//						}
pitiot's avatar
init  
pitiot committed
663 664 665 666 667 668 669 670 671 672 673 674
//						d3 = map.phi1(d3) ;
//					} while (d3 != centerFace) ;
//				}
//
//				//agents contained in the subdivided cell are pushed correctly
//				for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
//				{
////					CGoGNout<<"reseting Agents"<<CGoGNendl;
//					resetAgentInFace(*ait) ;
//					pushAgentInCells(*ait, (*ait)->part_.d) ;
//				}
//
pitiot's avatar
pitiot committed
675 676
//				//same for Segments contained
//				for (PFP::SegmentVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
677
//				{
pitiot's avatar
pitiot committed
678
////					CGoGNout<<"reseting Segments"<<CGoGNendl;
pitiot's avatar
init  
pitiot committed
679
//					resetPartSubdiv(*ait);
pitiot's avatar
pitiot committed
680
//					pushSegmentInSetOfCells(*ait);
pitiot's avatar
init  
pitiot committed
681 682 683
//
//				}
//
pitiot's avatar
pitiot committed
684 685
//				//same for adjacent Segments
//				for (PFP::SegmentVECT::iterator ait = oldNeighborObst.begin();
pitiot's avatar
init  
pitiot committed
686 687
//					ait != oldNeighborObst.end(); ++ait)
//				{
pitiot's avatar
pitiot committed
688
//					pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
//				}
//
//
////				CGoGNout<<"fin refine"<<CGoGNendl;
//			}
//		}
//	}
//	refineCandidate.clear() ;
//
//}
//
//
//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
773 774
//		PFP::SegmentVECT obst ;
//		PFP::SegmentVECT neighborObst ;
pitiot's avatar
init  
pitiot committed
775 776 777 778 779 780 781 782 783
//		//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
784
//				PFP::SegmentVECT resetob = RegisteredEdges[nf] ;
pitiot's avatar
init  
pitiot committed
785 786 787 788
//				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
789
//				for (PFP::SegmentVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
//				{
//
//						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
805
//			PFP::SegmentVECT ob(RegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
806 807
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
pitiot's avatar
pitiot committed
808
//
pitiot's avatar
init  
pitiot committed
809
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
810
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
811 812
//			{
////				resetObstPartInFace(*ait, fit,fLevel);
pitiot's avatar
pitiot committed
813
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
//				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
831
//			PFP::SegmentVECT ob(RegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
832 833 834
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
835
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
836 837
//			{
////				resetObstPartInFace(*ait, fit,Level);
pitiot's avatar
pitiot committed
838
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
839 840 841 842 843 844 845 846 847 848 849
//				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
850
//			PFP::SegmentVECT nob(neighborRegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
851 852
//
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
853
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
854
//			{
pitiot's avatar
pitiot committed
855
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
856 857 858 859 860 861 862 863 864 865 866
//				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
867
//			PFP::SegmentVECT nob(neighborRegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
868
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
869
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
870
//			{
pitiot's avatar
pitiot committed
871
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
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
//				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
898
//		for (PFP::SegmentVECT::iterator ait = obst.begin(); ait != obst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
899 900
//		{
//			resetObstPartInFace(*ait, old);
pitiot's avatar
pitiot committed
901
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
902
//		}
pitiot's avatar
pitiot committed
903
//		for (PFP::SegmentVECT::iterator ait = neighborObst.begin(); ait != neighborObst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
904
//		{
pitiot's avatar
pitiot committed
905
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
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
//		}
//
//		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
941

David Cazier's avatar
David Cazier committed
942