Commit d65740a5 authored by Arne Graf's avatar Arne Graf

refac: useWallAvoid -> useWallDistances

parent d0fd5d08
Pipeline #3877 failed with stages
in 7 seconds
......@@ -314,28 +314,16 @@ double DirectionFloorfield::GetDistance2Wall(Pedestrian* ped) const
void DirectionFloorfield::Init(Building* building, double stepsize,
double threshold, bool useDistancMap) {
//implement mechanic, that can read-in an existing floorfield (from a previous run)
string s = building->GetGeometryFilename();
Log->Write("INFO: \tGeometryFilename <" + s + ">");
s.erase(s.find_last_of(".", string::npos)); // delete ending
if (s.find_last_of("/") != string::npos) {
s.erase(0, s.find_last_of("/")+1); // delete directories before filename (espacially "..")
}
string FF_filename = (building->GetProjectRootDir() + "FF_" + s + "_" + std::to_string(threshold) + ".vtk").c_str();
std::ifstream test(FF_filename);
if (test.good()) {
Log->Write("INFO: \tRead Floorfield from file <" + FF_filename + ">");
_ffviafm = new FloorfieldViaFM(FF_filename);
} else {
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
Log->Write("INFO: \tCalling Construtor of FloorfieldViaFM");
_ffviafm = new FloorfieldViaFM(building, stepsize, stepsize, threshold,
useDistancMap, false);
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
Log->Write("INFO: \tTaken time: " + std::to_string(elapsed_seconds.count()));
}
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
Log->Write("INFO: \tCalling Construtor of FloorfieldViaFM");
_ffviafm = new FloorfieldViaFM(building, stepsize, stepsize, threshold,
useDistancMap, false);
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
Log->Write("INFO: \tTaken time: " + std::to_string(elapsed_seconds.count()));
_initDone = true;
}
......
......@@ -35,21 +35,21 @@ UnivFFviaFM::~UnivFFviaFM() {
}
}
UnivFFviaFM::UnivFFviaFM(Room* r, Building* b, double hx, double wallAvoid, bool useWallAvoid)
: UnivFFviaFM(r, b->GetConfig(), hx, wallAvoid, useWallAvoid) {
UnivFFviaFM::UnivFFviaFM(Room* r, Building* b, double hx, double wallAvoid, bool useWallDistances)
: UnivFFviaFM(r, b->GetConfig(), hx, wallAvoid, useWallDistances) {
_building = b;
}
UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Building* b, double hx, double wallAvoid, bool useWallAvoid)
: UnivFFviaFM(sr, b->GetConfig(), hx, wallAvoid, useWallAvoid) {
UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Building* b, double hx, double wallAvoid, bool useWallDistances)
: UnivFFviaFM(sr, b->GetConfig(), hx, wallAvoid, useWallDistances) {
_building = b;
}
UnivFFviaFM::UnivFFviaFM(Room* r, Configuration* const conf, double hx, double wallAvoid, bool useWallAvoid)
: UnivFFviaFM(r, conf, hx, wallAvoid, useWallAvoid, std::vector<int>()){
UnivFFviaFM::UnivFFviaFM(Room* r, Configuration* const conf, double hx, double wallAvoid, bool useWallDistances)
: UnivFFviaFM(r, conf, hx, wallAvoid, useWallDistances, std::vector<int>()){
}
UnivFFviaFM::UnivFFviaFM(Room* roomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallAvoid, std::vector<int> wantedDoors) {
UnivFFviaFM::UnivFFviaFM(Room* roomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors) {
//build the vector with walls(wall or obstacle), the map with <UID, Door(Cross or Trans)>, the vector with targets(UIDs)
//then call other constructor including the mode
......@@ -92,15 +92,15 @@ UnivFFviaFM::UnivFFviaFM(Room* roomArg, Configuration* const confArg, double hx,
}
}
create(lines, tmpDoors, wantedDoors, FF_HOMO_SPEED, hx, wallAvoid, useWallAvoid);
//create(lines, tmpDoors, wantedDoors, FF_WALL_AVOID, hx, wallAvoid, useWallAvoid);
create(lines, tmpDoors, wantedDoors, FF_HOMO_SPEED, hx, wallAvoid, useWallDistances);
//create(lines, tmpDoors, wantedDoors, FF_WALL_AVOID, hx, wallAvoid, useWallDistances);
}
UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Configuration* const conf, double hx, double wallAvoid, bool useWallAvoid)
: UnivFFviaFM(sr, conf, hx, wallAvoid, useWallAvoid, std::vector<int>()){
UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Configuration* const conf, double hx, double wallAvoid, bool useWallDistances)
: UnivFFviaFM(sr, conf, hx, wallAvoid, useWallDistances, std::vector<int>()){
}
UnivFFviaFM::UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallAvoid, std::vector<int> wantedDoors) {
UnivFFviaFM::UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors) {
//build the vector with walls(wall or obstacle), the map with <UID, Door(Cross or Trans)>, the vector with targets(UIDs)
//then call other constructor including the mode
_configuration = confArg;
......@@ -135,14 +135,14 @@ 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, useWallAvoid);
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,
double spacing, double wallAvoid, bool useWallAvoid) {
double spacing, double wallAvoid, bool useWallDistances) {
_wallAvoidDistance = wallAvoid;
_useWallAvoidance = useWallAvoid;
_useWallDistances = useWallDistances;
_speedmode = mode;
//find circumscribing rectangle (x_min/max, y_min/max) //create RectGrid
......@@ -156,7 +156,7 @@ void UnivFFviaFM::create(std::vector<Line>& walls, std::map<int, Line>& doors, s
std::fill(_speedFieldSelector[INITIAL_SPEED], _speedFieldSelector[INITIAL_SPEED]+_nPoints, 1.0);
//allocate _initalSpeed and maybe _modifiedSpeed
if (mode == FF_WALL_AVOID) {
if ((mode == FF_WALL_AVOID) || (useWallDistances)) {
double* cost_alias_walldistance = new double[_nPoints];
_costFieldWithKey[0] = cost_alias_walldistance;
Point* gradient_alias_walldirection = new Point[_nPoints];
......@@ -995,7 +995,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 _useWallAvoidance which are redundant
//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) {
......@@ -1288,6 +1288,21 @@ void UnivFFviaFM::getDirectionToUID(int destID, const long int key, Point& direc
return;
}
double UnivFFviaFM::getDistance2WallAt(const Point &pos) {
if (_useWallDistances || (_speedmode == FF_WALL_AVOID)) {
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)];
} else {
p = Point(0.0, 0.0);
}
}
/* Log:
* todo:
* - implement error treatment: extend fctns to throw errors and handle them
......
......@@ -81,12 +81,12 @@ class UnivFFviaFM {
public:
UnivFFviaFM(Room* a, Building* b, double c, double e, bool f);
UnivFFviaFM(SubRoom* a, Building* b, double c, double e, bool f);
UnivFFviaFM(Room* a, Configuration* const b, double hx, double wallAvoid, bool useWallAvoid);
UnivFFviaFM(Room* a, Configuration* const b, double hx, double wallAvoid, bool useWallAvoid, std::vector<int> wantedDoors);
UnivFFviaFM(SubRoom* sr, Configuration* const conf, double hx, double wallAvoid, bool useWallAvoid);
UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallAvoid, std::vector<int> wantedDoors);
UnivFFviaFM(Room* a, Configuration* const b, double hx, double wallAvoid, bool useWallDistances);
UnivFFviaFM(Room* a, Configuration* const b, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors);
UnivFFviaFM(SubRoom* sr, Configuration* const conf, double hx, double wallAvoid, bool useWallDistances);
UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors);
void create(std::vector<Line>& walls, std::map<int, Line>& doors, std::vector<int> targetUIDs, int mode,
double spacing, double wallAvoidDist, bool useWallAvoid);
double spacing, double wallAvoidDist, bool useWallDistances);
UnivFFviaFM() {};
UnivFFviaFM(UnivFFviaFM&){};
virtual ~UnivFFviaFM();
......@@ -106,6 +106,9 @@ public:
RectGrid* getGrid();
virtual void getDirectionToUID(int destID, const long int key, Point& direction, int mode);
void getDirectionToUID(int destID, const long int key, Point& direction);
double getDistance2WallAt(const Point& pos);
void getDir2WallAt(const Point& pos, Point& p);
void writeFF(const std::string&, std::vector<int> targetID);
void createRectGrid(std::vector<Line>& walls, std::map<int, Line>& doors, double spacing);
......@@ -147,7 +150,7 @@ private:
SubRoom* * _subrooms = nullptr; // this is an array (first asterisk) of pointers (second asterisk)
double _wallAvoidDistance = 0.;
bool _useWallAvoidance = false;
bool _useWallDistances = false;
//the following maps are responsible for dealloc the arrays
std::map<int, double*> _costFieldWithKey;
......
......@@ -517,7 +517,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));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment