From f38f60935d077701f2a424eff5f4466f7b620d67 Mon Sep 17 00:00:00 2001 From: Arne Graf <ar.graf.cst@gmail.com> Date: Mon, 24 Jul 2017 17:32:25 +0200 Subject: [PATCH] cleaning --- routing/ff_router/UnivFFviaFM.cpp | 30 +++++++++++++++++++++++------- routing/ff_router/UnivFFviaFM.h | 3 ++- routing/ff_router/ffRouter.cpp | 3 ++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/routing/ff_router/UnivFFviaFM.cpp b/routing/ff_router/UnivFFviaFM.cpp index c30d3079..a6e75530 100644 --- a/routing/ff_router/UnivFFviaFM.cpp +++ b/routing/ff_router/UnivFFviaFM.cpp @@ -91,9 +91,12 @@ UnivFFviaFM::UnivFFviaFM(Room* roomArg, Configuration* const confArg, double hx, } } } - - create(lines, tmpDoors, wantedDoors, FF_HOMO_SPEED, hx, wallAvoid, useWallDistances); - //create(lines, tmpDoors, wantedDoors, FF_WALL_AVOID, hx, wallAvoid, useWallDistances); + //this will interpret "useWallDistances" as best as possible. Users should clearify with "setSpeedMode" before calling "AddTarget" + if (useWallDistances) { + create(lines, tmpDoors, wantedDoors, FF_WALL_AVOID, hx, wallAvoid, useWallDistances); + } else { + create(lines, tmpDoors, wantedDoors, FF_HOMO_SPEED, hx, wallAvoid, useWallDistances); + } } UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Configuration* const conf, double hx, double wallAvoid, bool useWallDistances) @@ -135,7 +138,12 @@ UnivFFviaFM::UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, doub tmpDoors.emplace(std::make_pair(uidNotConst, (Line) *trans)); } - create(lines, tmpDoors, wantedDoors, FF_HOMO_SPEED, hx, wallAvoid, useWallDistances); + //this will interpret "useWallDistances" as best as possible. Users should clearify with "setSpeedMode" before calling "AddTarget" + if (useWallDistances) { + create(lines, tmpDoors, wantedDoors, FF_WALL_AVOID, hx, wallAvoid, useWallDistances); + } else { + create(lines, tmpDoors, wantedDoors, FF_HOMO_SPEED, hx, wallAvoid, useWallDistances); + } } void UnivFFviaFM::create(std::vector<Line>& walls, std::map<int, Line>& doors, std::vector<int> targetUIDs, int mode, @@ -995,7 +1003,7 @@ void UnivFFviaFM::addTarget(const int uid, double* costarrayDBL, Point* gradarra if (_mode == CENTERPOINT) { newArrayDBL[_grid->getKeyAtPoint(tempCenterPoint)] = magicnum(TARGET_REGION); } - //the following condition is not clean: we have _speedmode and _useWallDistances which are redundant + if (_speedmode == FF_WALL_AVOID) { calcFF(newArrayDBL, newArrayPt, _speedFieldSelector[REDU_WALL_SPEED]); } else if (_speedmode == FF_HOMO_SPEED) { @@ -1074,6 +1082,10 @@ void UnivFFviaFM::setMode(int modeArg) { _mode=modeArg; } +void UnivFFviaFM::setSpeedMode(int speedModeArg) { + _speedmode = speedModeArg; +} + void UnivFFviaFM::writeFF(const std::string& filename, std::vector<int> targetID) { Log->Write("INFO: \tWrite Floorfield to file"); @@ -1290,14 +1302,18 @@ void UnivFFviaFM::getDirectionToUID(int destID, const long int key, Point& direc double UnivFFviaFM::getDistance2WallAt(const Point &pos) { if (_useWallDistances || (_speedmode == FF_WALL_AVOID)) { - return _costFieldWithKey[0][_grid->getKeyAtPoint(pos)]; + if (_costFieldWithKey[0]) { + return _costFieldWithKey[0][_grid->getKeyAtPoint(pos)]; + } } return DBL_MAX; } void UnivFFviaFM::getDir2WallAt(const Point &pos, Point &p) { if (_useWallDistances || (_speedmode == FF_WALL_AVOID)) { - p = _directionFieldWithKey[0][_grid->getKeyAtPoint(pos)]; + if (_directionFieldWithKey[0]) { + p = _directionFieldWithKey[0][_grid->getKeyAtPoint(pos)]; + } } else { p = Point(0.0, 0.0); } diff --git a/routing/ff_router/UnivFFviaFM.h b/routing/ff_router/UnivFFviaFM.h index 917eff46..7ed3e697 100644 --- a/routing/ff_router/UnivFFviaFM.h +++ b/routing/ff_router/UnivFFviaFM.h @@ -98,6 +98,7 @@ public: std::vector<int> getKnownDoorUIDs(); void setUser(int userArg); void setMode(int modeArg); + void setSpeedMode(int speedModeArg); SubRoom** getSubRoomFF(); SubRoom* getSubRoom(const Point& pos); @@ -150,7 +151,7 @@ private: SubRoom* * _subrooms = nullptr; // this is an array (first asterisk) of pointers (second asterisk) double _wallAvoidDistance = 0.; - bool _useWallDistances = false; + bool _useWallDistances = false; //could be used in DirectionStrategy even if mode _speedmode is FF_HOMO_SPEED //the following maps are responsible for dealloc the arrays std::map<int, double*> _costFieldWithKey; diff --git a/routing/ff_router/ffRouter.cpp b/routing/ff_router/ffRouter.cpp index 6da682a0..fdee8e08 100644 --- a/routing/ff_router/ffRouter.cpp +++ b/routing/ff_router/ffRouter.cpp @@ -189,6 +189,7 @@ bool FFRouter::Init(Building* building) // } locffptr->setUser(DISTANCE_AND_DIRECTIONS_USED); locffptr->setMode(CENTERPOINT); + locffptr->setSpeedMode(FF_HOMO_SPEED); locffptr->addAllTargetsParallel(); locffptr->writeFF("UnivFF"+std::to_string(pairRoomIt->first)+".vtk", locffptr->getKnownDoorUIDs()); Log->Write("INFO: \tAdding distances in Room %d to matrix", (*pairRoomIt).first); @@ -517,7 +518,7 @@ int FFRouter::FindExit(Pedestrian* p) #pragma omp critical(finalDoors) _finalDoors.emplace(std::make_pair(p->GetID(), bestFinalDoor)); - + if (_CroTrByUID.count(bestDoor)) { p->SetExitIndex(bestDoor); p->SetExitLine(_CroTrByUID.at(bestDoor)); -- GitLab