diff --git a/routing/ff_router/UnivFFviaFM.cpp b/routing/ff_router/UnivFFviaFM.cpp index c30d30795d1dd7658c6c81472f4caca856c7d8c4..a6e75530abdeb3b88266a9e65ecbee44c1886c4c 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 917eff462bf9ed7c881f494ff29d2fe3c17b63b7..7ed3e697830d16ce3fee39dc5a4fe02ba48b7e7e 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 6da682a016dbde9f461aa7efeb04d172e4f07fea..fdee8e08ad34375e6c5e52d79f3440c27c49ae61 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));