env_map.cpp 25.3 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
init  
pitiot committed
34

pitiot's avatar
pitiot committed
35
//		map.initImplicitProperties();  // Si map MR
pitiot's avatar
pitiot committed
36 37 38

        ///// initialisation attributs
        position = map.addAttribute<VEC3, VERTEX, MAP>("position");
pitiot's avatar
up  
pitiot committed
39
        facecenter = map.addAttribute<VEC3, FACE, MAP>("facecenter");
pitiot's avatar
pitiot committed
40 41 42
        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
43 44 45 46 47



        int nb = 5;
        Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(map, nb, nb, nb);
pitiot's avatar
pitiot committed
48
        cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
pitiot's avatar
pitiot committed
49 50 51 52 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




//        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
87 88 89 90 91
        TraversorV<MAP> tv(map);
        for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
        {
            position[d] *= 10;
        }
pitiot's avatar
up  
pitiot committed
92 93 94 95 96 97 98
        TraversorF<MAP> tf(map);
        for(Dart d = tf.begin() ; d != tf.end() ; d = tf.next())
        {

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

        }
pitiot's avatar
pitiot committed
99 100 101 102 103 104 105

        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
106 107 108



pitiot's avatar
pitiot committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
//        //// 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 ;




132
	}
133

134

pitiot's avatar
pitiot committed
135
}
pitiot's avatar
up  
pitiot committed
136

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

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


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

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

pitiot's avatar
pitiot committed
167 168

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


pitiot's avatar
up  
pitiot committed
182 183 184 185
}



pitiot's avatar
pitiot committed
186 187 188 189 190





pitiot's avatar
pitiot committed
191
///// a coder
pitiot's avatar
up  
pitiot committed
192

pitiot's avatar
pitiot committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
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
211 212


213 214 215



Thomas's avatar
Thomas committed
216 217 218 219




pitiot's avatar
init  
pitiot committed
220 221
//
void EnvMap::open_file(std::string filename)
Pierre Kraemer's avatar
Pierre Kraemer committed
222
{
pitiot's avatar
pitiot committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    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
285 286
}

David Cazier's avatar
David Cazier committed
287

pitiot's avatar
init  
pitiot committed
288 289 290 291 292 293 294 295 296 297 298
//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
299
//				{
pitiot's avatar
init  
pitiot committed
300 301
//					subd.mark(d) ;
//					if (!buildingMark.isMarked(d))
David Cazier's avatar
David Cazier committed
302
//					{
pitiot's avatar
init  
pitiot committed
303 304 305 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
//						//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
333
//					}
pitiot's avatar
init  
pitiot committed
334
//				}
335
//			}
pitiot's avatar
init  
pitiot committed
336 337 338 339 340 341 342 343 344 345 346 347 348
//		}
//	} 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))
349
//			{
pitiot's avatar
init  
pitiot committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363
//				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) ;
//						}
//					}
//				}
364
//			}
pitiot's avatar
init  
pitiot committed
365 366 367 368 369 370 371
//			subd.unmarkAll() ;
//		}
//		updateMap() ;
//		refineCandidate.clear() ;
//		map.setCurrentLevel(map.getMaxLevel()) ;
//	} while (subdiv) ;
//}
372

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

pitiot's avatar
pitiot committed
378
    MovingObject * mo = o->nid;
pitiot's avatar
pitiot committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392
    if (mo != NULL)
    {
        int n = o->index;
#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;
        d1=mo->parts_[n]->d;
        d2=mo->parts_[n+1]->d;
pitiot's avatar
pitiot committed
393 394


pitiot's avatar
pitiot committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
        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);

    return o->nid->parts_[o->index]->d;;
}

void EnvMap::pushAOneCellSegment(Segment * o, Dart d)
{
    int n = o->index;
pitiot's avatar
pitiot committed
423
    MovingObject * mo = o->nid;
pitiot's avatar
pitiot committed
424 425 426 427 428 429 430 431 432
#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
433
    for (Vol volume : volumesAdjacentByVertex3(map,d))
pitiot's avatar
pitiot committed
434
    {
pitiot's avatar
pitiot committed
435
        if (!map.isBoundaryMarked<3>(volume))
pitiot's avatar
pitiot committed
436
        {
pitiot's avatar
pitiot committed
437 438
            pushSegmentInCellAsNeighbor(o, volume);
             mo->neighbor_cells[n].push_back(volume);
pitiot's avatar
pitiot committed
439 440 441
        }
    }

pitiot's avatar
pitiot committed
442 443 444
#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
445 446 447 448 449 450 451 452 453
}

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
454
    MovingObject * mo = o->nid;
pitiot's avatar
pitiot committed
455 456 457 458 459 460 461

    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
462 463 464
#ifdef DEBUG_affichage
    CGoGNout<<"cellule du belong :"<<(*it)<<CGoGNendl;
#endif
pitiot's avatar
pitiot committed
465 466 467 468 469 470 471 472 473 474 475

    }
    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
476 477 478
#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
479 480 481 482
}

void EnvMap::popSegment(Segment* o)
{
pitiot's avatar
pitiot committed
483
    MovingObject * mo = o->nid;
pitiot's avatar
pitiot committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
    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
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
//
//
//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
542
//					{
pitiot's avatar
init  
pitiot committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
//						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
562 563
//				PFP::SegmentVECT oldObst(RegisteredEdges[old]) ;
//				PFP::SegmentVECT oldNeighborObst(neighborRegisteredEdges[old]) ;
pitiot's avatar
init  
pitiot committed
564 565 566 567 568
//
//				for (PFP::AGENTS::iterator ait = oldAgents.begin(); ait != oldAgents.end(); ++ait)
//				{
//					popAgentInCells(*ait, old) ;
//				}
pitiot's avatar
pitiot committed
569 570 571 572
//				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
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
//				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)
605
//						{
pitiot's avatar
init  
pitiot committed
606 607 608 609 610 611
//							if (!newF.isMarked(d4))
//							{
//								PFP::AGENTS& ad4 = agentvect[d4] ;
//								nad3.insert(nad3.end(), ad4.begin(), ad4.end()) ;
//							}
//							d4 = map.alpha1(d4) ;
612
//						}
pitiot's avatar
init  
pitiot committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
//						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
630
//					{
pitiot's avatar
init  
pitiot committed
631 632 633
//						Dart d4 = map.alpha1(map.alpha1(d3)) ;
//						PFP::AGENTS& nad3 = neighborAgentvect[d3] ;
//						while (d4 != d3)
634
//						{
pitiot's avatar
init  
pitiot committed
635 636 637 638 639 640
//							if (!newF.isMarked(d4))
//							{
//								PFP::AGENTS& ad4 = agentvect[d4] ;
//								nad3.insert(neighborAgentvect[d3].end(), ad4.begin(), ad4.end()) ;
//							}
//							d4 = map.alpha1(d4) ;
641
//						}
pitiot's avatar
init  
pitiot committed
642 643 644 645 646 647 648 649 650 651 652 653
//						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
654 655
//				//same for Segments contained
//				for (PFP::SegmentVECT::iterator ait = oldObst.begin(); ait != oldObst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
656
//				{
pitiot's avatar
pitiot committed
657
////					CGoGNout<<"reseting Segments"<<CGoGNendl;
pitiot's avatar
init  
pitiot committed
658
//					resetPartSubdiv(*ait);
pitiot's avatar
pitiot committed
659
//					pushSegmentInSetOfCells(*ait);
pitiot's avatar
init  
pitiot committed
660 661 662
//
//				}
//
pitiot's avatar
pitiot committed
663 664
//				//same for adjacent Segments
//				for (PFP::SegmentVECT::iterator ait = oldNeighborObst.begin();
pitiot's avatar
init  
pitiot committed
665 666
//					ait != oldNeighborObst.end(); ++ait)
//				{
pitiot's avatar
pitiot committed
667
//					pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
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 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
//				}
//
//
////				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
752 753
//		PFP::SegmentVECT obst ;
//		PFP::SegmentVECT neighborObst ;
pitiot's avatar
init  
pitiot committed
754 755 756 757 758 759 760 761 762
//		//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
763
//				PFP::SegmentVECT resetob = RegisteredEdges[nf] ;
pitiot's avatar
init  
pitiot committed
764 765 766 767
//				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
768
//				for (PFP::SegmentVECT::iterator ait = resetob.begin(); ait != resetob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
//				{
//
//						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
784
//			PFP::SegmentVECT ob(RegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
785 786
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
pitiot's avatar
pitiot committed
787
//
pitiot's avatar
init  
pitiot committed
788
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
789
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
790 791
//			{
////				resetObstPartInFace(*ait, fit,fLevel);
pitiot's avatar
pitiot committed
792
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
//				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
810
//			PFP::SegmentVECT ob(RegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
811 812 813
//
//			agents.insert(agents.end(), a.begin(), a.end()) ;
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
814
//			for(PFP::SegmentVECT::iterator ait = ob.begin(); ait != ob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
815 816
//			{
////				resetObstPartInFace(*ait, fit,Level);
pitiot's avatar
pitiot committed
817
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
818 819 820 821 822 823 824 825 826 827 828
//				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
829
//			PFP::SegmentVECT nob(neighborRegisteredEdges[fit]) ;
pitiot's avatar
init  
pitiot committed
830 831
//
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
832
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
833
//			{
pitiot's avatar
pitiot committed
834
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
835 836 837 838 839 840 841 842 843 844 845
//				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
846
//			PFP::SegmentVECT nob(neighborRegisteredEdges[centerFace]) ;
pitiot's avatar
init  
pitiot committed
847
//			map.setCurrentLevel(map.getMaxLevel()) ;
pitiot's avatar
pitiot committed
848
//			for(PFP::SegmentVECT::iterator ait = nob.begin(); ait != nob.end(); ++ait)
pitiot's avatar
init  
pitiot committed
849
//			{
pitiot's avatar
pitiot committed
850
//				this->popSegment(*ait) ;
pitiot's avatar
init  
pitiot committed
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
//				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
877
//		for (PFP::SegmentVECT::iterator ait = obst.begin(); ait != obst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
878 879
//		{
//			resetObstPartInFace(*ait, old);
pitiot's avatar
pitiot committed
880
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
881
//		}
pitiot's avatar
pitiot committed
882
//		for (PFP::SegmentVECT::iterator ait = neighborObst.begin(); ait != neighborObst.end(); ++ait)
pitiot's avatar
init  
pitiot committed
883
//		{
pitiot's avatar
pitiot committed
884
//			pushSegmentInSetOfCells(*ait) ;
pitiot's avatar
init  
pitiot committed
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
//		}
//
//		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
920

David Cazier's avatar
David Cazier committed
921