UnivFFviaFM.cpp 77.2 KB
Newer Older
Arne Graf's avatar
Arne Graf committed
1 2 3
//
// Created by arne on 5/9/17.
//
Qiancheng Xu's avatar
Qiancheng Xu committed
4
#define NOMINMAX
Arne Graf's avatar
Arne Graf committed
5
#include <unordered_set>
Arne Graf's avatar
Arne Graf committed
6 7 8 9
#include "UnivFFviaFM.h"
#include "../../geometry/Line.h"
#include "../../geometry/Building.h"
#include "../../geometry/SubRoom.h"
10
#include "../../pedestrian/Pedestrian.h"
Arne Graf's avatar
Arne Graf committed
11 12 13
#include "mesh/RectGrid.h"


Arne Graf's avatar
Arne Graf committed
14 15
UnivFFviaFM::~UnivFFviaFM() {
     if (_grid) delete _grid;
16
     //size_t speedsize = _speedFieldSelector.size();
Arne Graf's avatar
Arne Graf committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
     for (auto speedPtr : _speedFieldSelector) {
          if (speedPtr) delete[] speedPtr;
     }
     if (_gridCode) delete[] _gridCode;
     if (_subrooms) delete[] _subrooms;

     std::map<int, double*>::reverse_iterator delIterCost;

     for (delIterCost = _costFieldWithKey.rbegin();
          delIterCost != _costFieldWithKey.rend();
          ++delIterCost) {
          delete[] delIterCost->second;
     }
     std::map<int, Point*>::reverse_iterator delIterDir;
     for (delIterDir = _directionFieldWithKey.rbegin();
          delIterDir != _directionFieldWithKey.rend();
          ++delIterDir) {
          delete[] delIterDir->second;
     }
}

38 39
UnivFFviaFM::UnivFFviaFM(Room* r, Building* b, double hx, double wallAvoid, bool useWallDistances)
          : UnivFFviaFM(r, b->GetConfig(), hx, wallAvoid, useWallDistances) {
Arne Graf's avatar
Arne Graf committed
40 41 42
     _building = b;
}

43 44
UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Building* b, double hx, double wallAvoid, bool useWallDistances)
          : UnivFFviaFM(sr, b->GetConfig(), hx, wallAvoid, useWallDistances) {
Arne Graf's avatar
Arne Graf committed
45 46 47
     _building = b;
}

48 49
UnivFFviaFM::UnivFFviaFM(Room* r, Configuration* const conf, double hx, double wallAvoid, bool useWallDistances)
          : UnivFFviaFM(r, conf, hx, wallAvoid, useWallDistances, std::vector<int>()){
Arne Graf's avatar
Arne Graf committed
50 51
}

52
UnivFFviaFM::UnivFFviaFM(Room* roomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors) {
Arne Graf's avatar
Arne Graf committed
53 54 55
     //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

Arne Graf's avatar
Arne Graf committed
56 57
     _configuration = confArg;
     _scope = FF_ROOM_SCALE;
Arne Graf's avatar
Arne Graf committed
58
     _room = roomArg->GetID();
Arne Graf's avatar
Arne Graf committed
59 60
     std::vector<Line> lines;
     std::map<int, Line> tmpDoors;
Arne Graf's avatar
Arne Graf committed
61
     Line anyDoor = Line{};
Arne Graf's avatar
Arne Graf committed
62
     for (auto& subroomMap : roomArg->GetAllSubRooms()) {
Arne Graf's avatar
Arne Graf committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
          SubRoom* subRoomPtr = subroomMap.second.get();
          std::vector<Wall> walls = std::vector<Wall>(subRoomPtr->GetAllWalls());
          for (auto& wall : walls) {
               lines.emplace_back((Line)wall);
          }

          std::vector<Obstacle*> tmpObsPtrVec = subRoomPtr->GetAllObstacles();
          for (Obstacle* ptrObs : tmpObsPtrVec) {
               const std::vector<Wall> obsWalls = ptrObs->GetAllWalls();
               for (auto& owall : obsWalls) {
                    lines.emplace_back((Line)owall);
               }
          }

          const std::vector<Crossing*> tmpCross = subRoomPtr->GetAllCrossings();
          const std::vector<Transition*> tmpTrans = subRoomPtr->GetAllTransitions();

Arne Graf's avatar
Arne Graf committed
80
          int uidNotConst = 0;
81
          bool isOpen = false;
Arne Graf's avatar
Arne Graf committed
82
          for (auto& cross : tmpCross) {
Arne Graf's avatar
Arne Graf committed
83
               uidNotConst = cross->GetUniqueID();
84 85
               //TODO isOpen = cross->IsOpen();
               isOpen = !cross->IsClose();
86 87 88
               if (!isOpen) {
                    //will be added twice! is it a problem?
                    lines.emplace_back((Line)*cross);
89 90 91 92 93
               } else {
                   anyDoor = Line{*cross};
                   if (tmpDoors.count(uidNotConst) == 0) {
                       tmpDoors.emplace(std::make_pair(uidNotConst, (Line) *cross));
                   }
Arne Graf's avatar
Arne Graf committed
94
               }
Arne Graf's avatar
Arne Graf committed
95 96
          }
          for (auto& trans : tmpTrans) {
Arne Graf's avatar
Arne Graf committed
97
               uidNotConst = trans->GetUniqueID();
98 99
               //TODO isOpen = trans->IsOpen();
               isOpen = !trans->IsClose();
100 101 102
               if (!isOpen) {
                    //will be added twice! is it a problem?
                    lines.emplace_back((Line)*trans);
103 104 105 106 107
               } else {
                   anyDoor = Line{*trans};
                   if (tmpDoors.count(uidNotConst) == 0) {
                       tmpDoors.emplace(std::make_pair(uidNotConst, (Line) *trans));
                   }
Arne Graf's avatar
Arne Graf committed
108
               }
Arne Graf's avatar
Arne Graf committed
109
          }
110 111
          //find insidePoint and save it, together with UID
          Point normalVec = anyDoor.NormalVec();
112
          double length = normalVec.Norm();
113
          Point midPoint = anyDoor.GetCentre();
114 115 116 117
          Point candidate01 = midPoint + (normalVec * 0.25);
          Point candidate02 = midPoint - (normalVec * 0.25);
          if (subRoomPtr->IsInSubRoom(candidate01)) {
               _subRoomPtrTOinsidePoint.emplace(std::make_pair(subRoomPtr, candidate01));
118
          } else {
119 120 121
               //candidate = candidate - (normalVec * 0.25);
               if (subRoomPtr->IsInSubRoom(candidate02)) {
                    _subRoomPtrTOinsidePoint.emplace(std::make_pair(subRoomPtr, candidate02));
122 123
               } else {
                    Log->Write("ERROR:\t In UnivFF InsidePoint Analysis");
124 125
                    bool a = subRoomPtr->IsInSubRoom(candidate01);
                    bool b = subRoomPtr->IsInSubRoom(candidate02);
Arne Graf's avatar
Arne Graf committed
126
                    a = b && a; //ignore this line. only to have a codeline after initialization of bools (to place a breakpoint)
127 128 129
               }
          }
          //_subroomUIDtoSubRoomPtr.emplace(std::make_pair(subRoomPtr->GetUID(), subRoomPtr));
Arne Graf's avatar
Arne Graf committed
130
     }
Arne Graf's avatar
Arne Graf committed
131 132 133 134 135 136
     //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);
     }
Arne Graf's avatar
Arne Graf committed
137 138
}

139 140
UnivFFviaFM::UnivFFviaFM(SubRoom* sr, Configuration* const conf, double hx, double wallAvoid, bool useWallDistances)
          : UnivFFviaFM(sr, conf, hx, wallAvoid, useWallDistances, std::vector<int>()){
Arne Graf's avatar
Arne Graf committed
141 142
}

143
UnivFFviaFM::UnivFFviaFM(SubRoom* subRoomArg, Configuration* const confArg, double hx, double wallAvoid, bool useWallDistances, std::vector<int> wantedDoors) {
Arne Graf's avatar
Arne Graf committed
144 145
     //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
Arne Graf's avatar
Arne Graf committed
146 147
     _configuration = confArg;
     _scope = FF_SUBROOM_SCALE;
Arne Graf's avatar
Arne Graf committed
148
     _room = subRoomArg->GetRoomID();
Arne Graf's avatar
Arne Graf committed
149
     std::vector<Line> lines;
Arne Graf's avatar
Arne Graf committed
150 151 152
     std::map<int, Line> tmpDoors;

     std::vector<Wall> walls = std::vector<Wall> (subRoomArg->GetAllWalls());
Arne Graf's avatar
Arne Graf committed
153 154 155 156
     for (auto& wall : walls) {
          lines.emplace_back((Line)wall);
     }

Arne Graf's avatar
Arne Graf committed
157
     std::vector<Obstacle*> tmpObsPtrVec = subRoomArg->GetAllObstacles();
Arne Graf's avatar
Arne Graf committed
158 159 160 161 162 163 164
     for (Obstacle* ptrObs : tmpObsPtrVec) {
          const std::vector<Wall> obsWalls = ptrObs->GetAllWalls();
          for (auto& owall : obsWalls) {
               lines.emplace_back((Line)owall);
          }
     }

Arne Graf's avatar
Arne Graf committed
165 166
     const std::vector<Crossing*> tmpCross = subRoomArg->GetAllCrossings();
     const std::vector<Transition*> tmpTrans = subRoomArg->GetAllTransitions();
Arne Graf's avatar
Arne Graf committed
167

Arne Graf's avatar
Arne Graf committed
168
     int uidNotConst = 0;
169
     bool isOpen = false;
Arne Graf's avatar
Arne Graf committed
170
     for (auto& cross : tmpCross) {
Arne Graf's avatar
Arne Graf committed
171
          uidNotConst = cross->GetUniqueID();
172 173
          //TODO isOpen = cross->IsOpen();
          isOpen = !cross->IsClose();
174 175 176 177 178
          if (!isOpen) {
               lines.emplace_back((Line)*cross);
          } else {
               tmpDoors.emplace(std::make_pair(uidNotConst, (Line) *cross));
          }
Arne Graf's avatar
Arne Graf committed
179 180
     }
     for (auto& trans : tmpTrans) {
Arne Graf's avatar
Arne Graf committed
181
          uidNotConst = trans->GetUniqueID();
182 183
          //TODO  isOpen = trans->IsOpen();
          isOpen = !trans->IsClose();
184 185 186 187 188
          if (!isOpen) {
               lines.emplace_back((Line)*trans);
          } else {
               tmpDoors.emplace(std::make_pair(uidNotConst, (Line) *trans));
          }
Arne Graf's avatar
Arne Graf committed
189 190
     }

191
     //find insidePoint and save it, together with UID
Arne Graf's avatar
Arne Graf committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    Line anyDoor = Line{(--tmpDoors.end())->second};
    Point normalVec = anyDoor.NormalVec();
    double length = normalVec.Norm();
    Point midPoint = anyDoor.GetCentre();
    Point candidate01 = midPoint + (normalVec * 0.25);
    Point candidate02 = midPoint - (normalVec * 0.25);
    if (subRoomArg->IsInSubRoom(candidate01)) {
        _subRoomPtrTOinsidePoint.emplace(std::make_pair(subRoomArg, candidate01));
    } else {
        //candidate = candidate - (normalVec * 0.25);
        if (subRoomArg->IsInSubRoom(candidate02)) {
            _subRoomPtrTOinsidePoint.emplace(std::make_pair(subRoomArg, candidate02));
        } else {
            Log->Write("ERROR:\t In UnivFF InsidePoint Analysis");
            bool a = subRoomArg->IsInSubRoom(candidate01);
            bool b = subRoomArg->IsInSubRoom(candidate02);
            a = b && a;
        }
    }

212 213
     //_subroomUIDtoSubRoomPtr.emplace(std::make_pair(subRoomArg->GetUID(), subRoomArg));

Arne Graf's avatar
Arne Graf committed
214 215 216 217 218 219
     //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);
     }
Arne Graf's avatar
Arne Graf committed
220 221
}

Arne Graf's avatar
Arne Graf committed
222
void UnivFFviaFM::create(std::vector<Line>& walls, std::map<int, Line>& doors, std::vector<int> targetUIDs, int mode,
223
                         double spacing, double wallAvoid, bool useWallDistances) {
Arne Graf's avatar
Arne Graf committed
224 225

     _wallAvoidDistance = wallAvoid;
226
     _useWallDistances = useWallDistances;
Arne Graf's avatar
Arne Graf committed
227 228
     _speedmode = mode;

Arne Graf's avatar
Arne Graf committed
229 230 231 232 233 234 235
     //find circumscribing rectangle (x_min/max, y_min/max) //create RectGrid
     createRectGrid(walls, doors, spacing);
     _nPoints = _grid->GetnPoints();

     //allocate _gridCode and  _speedFieldSelector and initialize them ("draw" walls and doors)
     _gridCode = new int[_nPoints];
     processGeometry(walls, doors);
Arne Graf's avatar
Arne Graf committed
236
     _speedFieldSelector.emplace(_speedFieldSelector.begin()+INITIAL_SPEED, new double[_nPoints]);
Arne Graf's avatar
Arne Graf committed
237 238
     std::fill(_speedFieldSelector[INITIAL_SPEED], _speedFieldSelector[INITIAL_SPEED]+_nPoints, 1.0);

239 240 241
     _speedFieldSelector.emplace(_speedFieldSelector.begin()+REDU_WALL_SPEED, nullptr);
     _speedFieldSelector.emplace(_speedFieldSelector.begin()+PED_SPEED, nullptr);

242 243 244 245 246
     //mark Inside areas (dont write outside areas)
     for (auto subRoomPointPair : _subRoomPtrTOinsidePoint) {
          markSubroom(subRoomPointPair.second, subRoomPointPair.first);
     }

247 248
     //allocate _modifiedSpeed
     if ((_speedmode == FF_WALL_AVOID) || (useWallDistances)) {
Arne Graf's avatar
Arne Graf committed
249 250 251 252 253 254
          double* cost_alias_walldistance = new double[_nPoints];
          _costFieldWithKey[0] = cost_alias_walldistance;
          Point* gradient_alias_walldirection = new Point[_nPoints];
          _directionFieldWithKey[0] = gradient_alias_walldirection;

          //create wall distance field
Arne Graf's avatar
Arne Graf committed
255 256 257 258 259 260 261 262 263 264 265
          //init costarray
          for (int i = 0; i < _nPoints; ++i) {
               if (_gridCode[i] == WALL) {
                    cost_alias_walldistance[i] = magicnum(WALL_ON_COSTARRAY);
               } else {
                    cost_alias_walldistance[i] = magicnum(UNKNOWN_COST);
               }
          }
          drawLinesOnWall(walls, cost_alias_walldistance, magicnum(TARGET_REGION));
          calcDF(cost_alias_walldistance, gradient_alias_walldirection, _speedFieldSelector[INITIAL_SPEED]);
          //_uids.emplace_back(0);
Arne Graf's avatar
Arne Graf committed
266 267

          double* temp_reduWallSpeed = new double[_nPoints];
268
          if (_speedFieldSelector[REDU_WALL_SPEED]) { //free memory before overwriting
Arne Graf's avatar
Arne Graf committed
269 270 271 272
               delete[] _speedFieldSelector[REDU_WALL_SPEED];
          }
          _speedFieldSelector[REDU_WALL_SPEED] = temp_reduWallSpeed;
          //init _reducedWallSpeed by using distance field
Arne Graf's avatar
Arne Graf committed
273
          createReduWallSpeed(temp_reduWallSpeed);
Arne Graf's avatar
Arne Graf committed
274 275
     }

276 277 278 279
     // parallel call
     if (!targetUIDs.empty()) {
          addTargetsParallel(targetUIDs);
     }
Arne Graf's avatar
Arne Graf committed
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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
}

void UnivFFviaFM::createRectGrid(std::vector<Line>& walls, std::map<int, Line>& doors, double spacing) {
     double x_min = DBL_MAX;  double x_max = DBL_MIN;
     double y_min = DBL_MAX;  double y_max = DBL_MIN;

     for(auto& wall : walls) {
          if (wall.GetPoint1()._x < x_min) x_min = wall.GetPoint1()._x;
          if (wall.GetPoint1()._y < y_min) y_min = wall.GetPoint1()._y;
          if (wall.GetPoint2()._x < x_min) x_min = wall.GetPoint2()._x;
          if (wall.GetPoint2()._y < y_min) y_min = wall.GetPoint2()._y;

          if (wall.GetPoint1()._x > x_max) x_max = wall.GetPoint1()._x;
          if (wall.GetPoint1()._y > y_max) y_max = wall.GetPoint1()._y;
          if (wall.GetPoint2()._x > x_max) x_max = wall.GetPoint2()._x;
          if (wall.GetPoint2()._y > y_max) y_max = wall.GetPoint2()._y;
     }

     for(auto& doorPair:doors) {
          Line& door = doorPair.second;
          if (door.GetPoint1()._x < x_min) x_min = door.GetPoint1()._x;
          if (door.GetPoint1()._y < y_min) y_min = door.GetPoint1()._y;
          if (door.GetPoint2()._x < x_min) x_min = door.GetPoint2()._x;
          if (door.GetPoint2()._y < y_min) y_min = door.GetPoint2()._y;

          if (door.GetPoint1()._x > x_max) x_max = door.GetPoint1()._x;
          if (door.GetPoint1()._y > y_max) y_max = door.GetPoint1()._y;
          if (door.GetPoint2()._x > x_max) x_max = door.GetPoint2()._x;
          if (door.GetPoint2()._y > y_max) y_max = door.GetPoint2()._y;
     }

     //create Rect Grid
     _grid = new RectGrid();
     _grid->setBoundaries(x_min, y_min, x_max, y_max);
     _grid->setSpacing(spacing, spacing);
     _grid->createGrid();
}

void UnivFFviaFM::processGeometry(std::vector<Line>&walls, std::map<int, Line>& doors) {
     for (int i = 0; i < _nPoints; ++i) {
          _gridCode[i] = OUTSIDE;
     }

Arne Graf's avatar
Arne Graf committed
323 324 325 326
     for (auto mapentry : doors) {
          _doors.insert(mapentry);
     }
     //_doors = doors;
Arne Graf's avatar
Arne Graf committed
327 328 329 330 331

     drawLinesOnGrid<int>(walls, _gridCode, WALL);
     drawLinesOnGrid(doors, _gridCode); //UIDs of doors will be drawn on _gridCode
}

Arne Graf's avatar
Arne Graf committed
332 333 334
void UnivFFviaFM::markSubroom(const Point& insidePoint, SubRoom* const value) {
     //value must not be nullptr. it would lead to infinite loop
     if (!value) return;
335 336 337

     if(!_grid->includesPoint(insidePoint)) return;

Arne Graf's avatar
Arne Graf committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
     //alloc mem if needed
     if (!_subrooms) {
          _subrooms = new SubRoom*[_nPoints];
          for (long i = 0; i < _nPoints; ++i) {
               _subrooms[i] = nullptr;
          }
     }

     //init start
     _subrooms[_grid->getKeyAtPoint(insidePoint)] = value;
     _gridCode[_grid->getKeyAtPoint(insidePoint)] = INSIDE;

     std::unordered_set<long> wavefront;
     wavefront.reserve(_nPoints);

     directNeighbor _neigh = _grid->getNeighbors(_grid->getKeyAtPoint(insidePoint));
     long aux = _neigh.key[0];
     if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE)) {
          wavefront.insert(aux);
          _subrooms[aux] = value;
     }

     aux = _neigh.key[1];
     if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE)) {
          wavefront.insert(aux);
          _subrooms[aux] = value;
     }

     aux = _neigh.key[2];
     if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE)) {
          wavefront.insert(aux);
          _subrooms[aux] = value;
     }

     aux = _neigh.key[3];
     if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE)) {
          wavefront.insert(aux);
          _subrooms[aux] = value;
     }

     while(!wavefront.empty()) {
          long current = *(wavefront.begin());
          wavefront.erase(current);
          _gridCode[current] = INSIDE;

383 384
          _neigh = _grid->getNeighbors(current);
          aux = _neigh.key[0];
Arne Graf's avatar
Arne Graf committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
          if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE) && _subrooms[aux] == nullptr) {
               wavefront.insert(aux);
               _subrooms[aux] = value;
          }

          aux = _neigh.key[1];
          if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE) && _subrooms[aux] == nullptr) {
               wavefront.insert(aux);
               _subrooms[aux] = value;
          }

          aux = _neigh.key[2];
          if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE) && _subrooms[aux] == nullptr) {
               wavefront.insert(aux);
               _subrooms[aux] = value;
          }

          aux = _neigh.key[3];
          if ((aux != -2) && (_gridCode[aux] == INSIDE || _gridCode[aux] == OUTSIDE) && _subrooms[aux] == nullptr) {
               wavefront.insert(aux);
               _subrooms[aux] = value;
          }
     }
}

Arne Graf's avatar
Arne Graf committed
410 411 412 413 414 415 416 417 418 419
void UnivFFviaFM::createReduWallSpeed(double* reduWallSpeed){
     double factor = 1/_wallAvoidDistance;
     double* wallDstAlias = _costFieldWithKey[0];

     for (long int i = 0; i < _nPoints; ++i) {
          if (wallDstAlias[i] > 0.) {
               reduWallSpeed[i] = (wallDstAlias[i] > _wallAvoidDistance) ? 1.0 : (factor * wallDstAlias[i]);
          }
     }
}
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

void UnivFFviaFM::recreateAllForQuickest() {
     //allocate if neccessary (should not be!)
     for (int doorUID : _uids) {
          if (!_costFieldWithKey[doorUID]) {
               _costFieldWithKey[doorUID] = new double[_nPoints];
          }
          if (_user == DISTANCE_MEASUREMENTS_ONLY) {
               if (_directionFieldWithKey.count(doorUID) != 0 && _directionFieldWithKey[doorUID]){
                    delete[] _directionFieldWithKey[doorUID];
               }
               _directionFieldWithKey[doorUID] = nullptr;
          }
          if (_user == DISTANCE_AND_DIRECTIONS_USED) {
               //check if not in map OR (in map but) nullptr)
               if ((_directionFieldWithKey.count(doorUID) == 0) || (!_directionFieldWithKey[doorUID])) {
                    _directionFieldWithKey[doorUID] = new Point[_nPoints];
               }
          }
     }

     //parallel region
#pragma omp parallel
     {
#pragma omp for
Qiancheng Xu's avatar
Qiancheng Xu committed
445
          for (signed int i = 0; i < _doors.size(); ++i) {
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
               auto doorPair = _doors.begin();
               std::advance(doorPair, i);
               addTarget(doorPair->first, _costFieldWithKey[doorPair->first], _directionFieldWithKey[doorPair->first]);
          }
     };
}

void UnivFFviaFM::createPedSpeed(Pedestrian *const *pedsArg, int nsize, int modechoice, double radius) {
     long int delta = radius / _grid->Gethx();
     long int posIndex = 0;
     long int pos_i = 0;
     long int pos_j = 0;
     long int i_start = 0;
     long int j_start = 0;
     long int i_end = 0;
     long int j_end = 0;
     long int iStride = _grid->GetiMax();
     double indexDistance = 0.0;
464
     double newWaveSpeed = 0.0;
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

//     if (nsize == 0) {
//          Log->Write("WARNING: \tcreatePedSpeed: nsize is ZERO");
//     } else {
//          Log->Write("INFO: \t\tNumber of Peds used in createPedSpeed: %d",nsize);
//     }

     if ((modechoice == quickest) && (!_speedFieldSelector[PED_SPEED])) {
          _speedFieldSelector[PED_SPEED] = new double[_grid->GetnPoints()];
     }

     //we assume, that this function is only used by router and is not using REDU_WALL_SPEED
     for (long int i = 0; i < _grid->GetnPoints(); ++i) {
          _speedFieldSelector[PED_SPEED][i] = _speedFieldSelector[INITIAL_SPEED][i];
     }
480 481
     if (_speedFieldSelector[REDU_WALL_SPEED] && _mode == LINESEGMENT) { //indicates, that the direction strat is using it
          for (long int i = 0; i < _grid->GetnPoints(); ++i) {
482
               _speedFieldSelector[PED_SPEED][i] = _speedFieldSelector[REDU_WALL_SPEED][i];
483 484
          }
     }
485 486 487 488 489 490 491

     for (int i = 0; i < nsize; ++i) {
          //the following check is not 3D proof, we require the caller of this function to provide a list with "valid"
          //pedestrian-pointer
          if (!_grid->includesPoint(pedsArg[i]->GetPos())) {
               continue;
          }
492

Arne Graf's avatar
Arne Graf committed
493
          newWaveSpeed = pedsArg[i]->GetEllipse().GetV().Norm()/pedsArg[i]->GetEllipse().GetV0(); //   (current speed)/(desired speed)
494 495 496 497
          newWaveSpeed *= 0.8;
          if (newWaveSpeed < 0.1) {
               newWaveSpeed = 0.1;
          }
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
          posIndex = _grid->getKeyAtPoint(pedsArg[i]->GetPos());
          pos_i = _grid->get_i_fromKey(posIndex);
          pos_j = _grid->get_j_fromKey(posIndex);

          i_start = ((pos_i - delta) < 0)               ? 0               : (pos_i - delta);
          i_end   = ((pos_i + delta) >= iStride) ? iStride-1 : (pos_i + delta);

          j_start = ((pos_j - delta) < 0)               ? 0               : (pos_j - delta);
          j_end   = ((pos_j + delta) >= _grid->GetjMax()) ? _grid->GetjMax()-1 : (pos_j + delta);

          for     (long int curr_i = i_start; curr_i < i_end; ++curr_i) {
               for (long int curr_j = j_start; curr_j < j_end; ++curr_j) {
                    //indexDistance holds the square
                    indexDistance = ( (curr_i - pos_i)*(curr_i - pos_i) + (curr_j - pos_j)*(curr_j - pos_j) );

                    if (indexDistance < (delta*delta)) {
514 515
                         //_speedFieldSelector[PED_SPEED][curr_j*iStride + curr_i] = 0.2;
                         _speedFieldSelector[PED_SPEED][curr_j*iStride + curr_i] = std::min(newWaveSpeed, _speedFieldSelector[PED_SPEED][curr_j*iStride + curr_i]);
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 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
void UnivFFviaFM::finalizeTargetLine(const int uid, const Line& line, Point* target, Point& value) {
    // i~x; j~y;
//http://stackoverflow.com/questions/10060046/drawing-lines-with-bresenhams-line-algorithm
//src in answer of "Avi"; adapted to fit this application

    //grid handeling local vars:
    long int iMax  = _grid->GetiMax();

    long int iStart, iEnd;
    long int jStart, jEnd;
    long int iDot, jDot;
    long int key;
    long int deltaX, deltaY, deltaX1, deltaY1, px, py, xe, ye, i; //Bresenham Algorithm

    long int goodneighbor;
    directNeighbor neigh;


    key = _grid->getKeyAtPoint(line.GetPoint1());
    iStart = (long) _grid->get_i_fromKey(key);
    jStart = (long) _grid->get_j_fromKey(key);

    key = _grid->getKeyAtPoint(line.GetPoint2());
    iEnd = (long) _grid->get_i_fromKey(key);
    jEnd = (long) _grid->get_j_fromKey(key);

    deltaX = (int) (iEnd - iStart);
    deltaY = (int) (jEnd - jStart);
    deltaX1 = abs( (int) (iEnd - iStart));
    deltaY1 = abs( (int) (jEnd - jStart));

    px = 2*deltaY1 - deltaX1;
    py = 2*deltaX1 - deltaY1;

    if(deltaY1<=deltaX1) {
        if(deltaX>=0) {
            iDot = iStart;
            jDot = jStart;
            xe = iEnd;
        } else {
            iDot = iEnd;
            jDot = jEnd;
            xe = iStart;
        }
        if (_gridCode[jDot*iMax + iDot] == uid) {
            /* //find a good neighborvalue
             neigh = _grid->getNeighbors(jDot*iMax + iDot);
             if ((neigh.key[0] >= 0) && (_gridCode[neigh.key[0]] == INSIDE)) {
                 goodneighbor = neigh.key[0];
             } else if ((neigh.key[1] >= 0) && (_gridCode[neigh.key[1]] == INSIDE)) {
                 goodneighbor = neigh.key[1];
             } else if ((neigh.key[2] >= 0) && (_gridCode[neigh.key[2]] == INSIDE)) {
                 goodneighbor = neigh.key[2];
             } else if ((neigh.key[3] >= 0) && (_gridCode[neigh.key[3]] == INSIDE)) {
                 goodneighbor = neigh.key[3];
             } else {
                 //ERROR - should have an inside neighbor
                 Log->Write("ERROR:\t In finalizeTargetLine");
             }
             //write the value on targetline
             if ((target[goodneighbor]._x == 0.) && (target[goodneighbor]._y == 0.)) {
                 //ERROR - should have a true vector
                 Log->Write("ERROR:\t (0;0) In finalizeTargetLine");
             }*/
            target[jDot * iMax + iDot] = value;
        } else if (_gridCode[jDot*iMax + iDot] == WALL) {
            //do nothing
        } else {
590 591
            target[jDot * iMax + iDot] = value;
            //Log->Write("ERROR:\t in finalizingTargetLine");
592 593 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 626 627 628
        }
        for (i=0; iDot < xe; ++i) {
            ++iDot;
            if (px < 0) {
                px += 2 * deltaY1;
            } else {
                if ((deltaX < 0 && deltaY < 0) || (deltaX > 0 && deltaY > 0)) {
                    ++jDot;
                } else {
                    --jDot;
                }
                px += 2 * (deltaY1 - deltaX1);
            }
            if (_gridCode[jDot * iMax + iDot] == uid) {
                /*//find a good neighborvalue
                neigh = _grid->getNeighbors(jDot*iMax + iDot);
                if ((neigh.key[0] >= 0) && (_gridCode[neigh.key[0]] == INSIDE)) {
                    goodneighbor = neigh.key[0];
                } else if ((neigh.key[1] >= 0) && (_gridCode[neigh.key[1]] == INSIDE)) {
                    goodneighbor = neigh.key[1];
                } else if ((neigh.key[2] >= 0) && (_gridCode[neigh.key[2]] == INSIDE)) {
                    goodneighbor = neigh.key[2];
                } else if ((neigh.key[3] >= 0) && (_gridCode[neigh.key[3]] == INSIDE)) {
                    goodneighbor = neigh.key[3];
                } else {
                    //ERROR - should have an inside neighbor
                    Log->Write("ERROR:\t In finalizeTargetLine");
                }
                //write the value on targetline
                if ((target[goodneighbor]._x == 0.) && (target[goodneighbor]._y == 0.)) {
                    //ERROR - should have a true vector
                    Log->Write("ERROR:\t (0;0) In finalizeTargetLine");
                }*/
                target[jDot * iMax + iDot] = value;
            } else if (_gridCode[jDot*iMax + iDot] == WALL) {
                //do nothing
            } else {
629 630
                target[jDot * iMax + iDot] = value;
                //Log->Write("ERROR:\t in finalizingTargetLine");
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
            }
        }
    } else {
        if(deltaY>=0) {
            iDot = iStart;
            jDot = jStart;
            ye = jEnd;
        } else {
            iDot = iEnd;
            jDot = jEnd;
            ye = jStart;
        }
        if (_gridCode[jDot*iMax + iDot] == uid) {
            /*//find a good neighborvalue
            neigh = _grid->getNeighbors(jDot*iMax + iDot);
            if ((neigh.key[0] >= 0) && (_gridCode[neigh.key[0]] == INSIDE)) {
                goodneighbor = neigh.key[0];
            } else if ((neigh.key[1] >= 0) && (_gridCode[neigh.key[1]] == INSIDE)) {
                goodneighbor = neigh.key[1];
            } else if ((neigh.key[2] >= 0) && (_gridCode[neigh.key[2]] == INSIDE)) {
                goodneighbor = neigh.key[2];
            } else if ((neigh.key[3] >= 0) && (_gridCode[neigh.key[3]] == INSIDE)) {
                goodneighbor = neigh.key[3];
            } else {
                //ERROR - should have an inside neighbor
                Log->Write("ERROR:\t In finalizeTargetLine");
            }
            //write the value on targetline
            if ((target[goodneighbor]._x == 0.) && (target[goodneighbor]._y == 0.)) {
                //ERROR - should have a true vector
                Log->Write("ERROR:\t (0;0) In finalizeTargetLine");
            }*/
            target[jDot * iMax + iDot] = value;
        } else if (_gridCode[jDot*iMax + iDot] == WALL) {
            //do nothing
        }  else {
667 668
            target[jDot * iMax + iDot] = value;
            //Log->Write("ERROR:\t in finalizingTargetLine");
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
        }
        for(i=0; jDot<ye; ++i) {
            ++jDot;
            if (py<=0) {
                py+=2*deltaX1;
            } else {
                if((deltaX<0 && deltaY<0) || (deltaX>0 && deltaY>0)) {
                    ++iDot;
                } else {
                    --iDot;
                }
                py+=2*(deltaX1-deltaY1);
            }
            if (_gridCode[jDot*iMax + iDot] == uid) {
                /*//find a good neighborvalue
                neigh = _grid->getNeighbors(jDot*iMax + iDot);
                if ((neigh.key[0] >= 0) && (_gridCode[neigh.key[0]] == INSIDE)) {
                    goodneighbor = neigh.key[0];
                } else if ((neigh.key[1] >= 0) && (_gridCode[neigh.key[1]] == INSIDE)) {
                    goodneighbor = neigh.key[1];
                } else if ((neigh.key[2] >= 0) && (_gridCode[neigh.key[2]] == INSIDE)) {
                    goodneighbor = neigh.key[2];
                } else if ((neigh.key[3] >= 0) && (_gridCode[neigh.key[3]] == INSIDE)) {
                    goodneighbor = neigh.key[3];
                } else {
                    //ERROR - should have an inside neighbor
                    Log->Write("ERROR:\t In finalizeTargetLine");
                }
                //write the value on targetline
                if ((target[goodneighbor]._x == 0.) && (target[goodneighbor]._y == 0.)) {
                    //ERROR - should have a true vector
                    Log->Write("ERROR:\t (0;0) In finalizeTargetLine");
                }*/
                target[jDot * iMax + iDot] = value;
            } else if (_gridCode[jDot*iMax + iDot] == WALL) {
                //do nothing
            } else {
706 707
                target[jDot * iMax + iDot] = value;
                //Log->Write("ERROR:\t in finalizingTargetLine");
708 709 710 711 712
            }
        }
    }
}

Arne Graf's avatar
Arne Graf committed
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 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
void UnivFFviaFM::drawLinesOnGrid(std::map<int, Line>& doors, int *const grid) {
     for (auto&& doorPair : doors) {
          int tempUID = doorPair.first;
          Line tempDoorLine = Line(doorPair.second);
          drawLinesOnGrid(tempDoorLine, grid, tempUID);
     }
}

template <typename T>
void UnivFFviaFM::drawLinesOnGrid(std::vector<Line>& wallArg, T* const target, const T value) { //no init, plz init elsewhere

     for (auto& line : wallArg) {
          drawLinesOnGrid(line, target, value);
     } //loop over all walls

} //drawLinesOnGrid

template <typename T>
void UnivFFviaFM::drawLinesOnGrid(Line& line, T* const target, const T value) { //no init, plz init elsewhere
// i~x; j~y;
//http://stackoverflow.com/questions/10060046/drawing-lines-with-bresenhams-line-algorithm
//src in answer of "Avi"; adapted to fit this application

     //grid handeling local vars:
     long int iMax  = _grid->GetiMax();

     long int iStart, iEnd;
     long int jStart, jEnd;
     long int iDot, jDot;
     long int key;
     long int deltaX, deltaY, deltaX1, deltaY1, px, py, xe, ye, i; //Bresenham Algorithm


     key = _grid->getKeyAtPoint(line.GetPoint1());
     iStart = (long) _grid->get_i_fromKey(key);
     jStart = (long) _grid->get_j_fromKey(key);

     key = _grid->getKeyAtPoint(line.GetPoint2());
     iEnd = (long) _grid->get_i_fromKey(key);
     jEnd = (long) _grid->get_j_fromKey(key);

     deltaX = (int) (iEnd - iStart);
     deltaY = (int) (jEnd - jStart);
     deltaX1 = abs( (int) (iEnd - iStart));
     deltaY1 = abs( (int) (jEnd - jStart));

     px = 2*deltaY1 - deltaX1;
     py = 2*deltaX1 - deltaY1;

     if(deltaY1<=deltaX1) {
          if(deltaX>=0) {
               iDot = iStart;
               jDot = jStart;
               xe = iEnd;
          } else {
               iDot = iEnd;
               jDot = jEnd;
               xe = iStart;
          }
          if ((_gridCode[jDot*iMax + iDot] != WALL) && (_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
               target[jDot * iMax + iDot] = value;
          }
          for (i=0; iDot < xe; ++i) {
               ++iDot;
               if(px<0) {
                    px+=2*deltaY1;
               } else {
                    if((deltaX<0 && deltaY<0) || (deltaX>0 && deltaY>0)) {
                         ++jDot;
                    } else {
                         --jDot;
                    }
                    px+=2*(deltaY1-deltaX1);
               }
               if ((_gridCode[jDot*iMax + iDot] != WALL) && (_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
                    target[jDot * iMax + iDot] = value;
               }
          }
     } else {
          if(deltaY>=0) {
               iDot = iStart;
               jDot = jStart;
               ye = jEnd;
          } else {
               iDot = iEnd;
               jDot = jEnd;
               ye = jStart;
          }
          if ((_gridCode[jDot*iMax + iDot] != WALL) && (_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
               target[jDot * iMax + iDot] = value;
          }
          for(i=0; jDot<ye; ++i) {
               ++jDot;
               if (py<=0) {
                    py+=2*deltaX1;
               } else {
                    if((deltaX<0 && deltaY<0) || (deltaX>0 && deltaY>0)) {
                         ++iDot;
                    } else {
                         --iDot;
                    }
                    py+=2*(deltaX1-deltaY1);
               }
               if ((_gridCode[jDot*iMax + iDot] != WALL) && (_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
                    target[jDot * iMax + iDot] = value;
               }
          }
     }
} //drawLinesOnGrid

Arne Graf's avatar
Arne Graf committed
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 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 877 878 879 880 881 882 883 884 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 920 921 922 923 924
template <typename T>
void UnivFFviaFM::drawLinesOnWall(std::vector<Line>& wallArg, T* const target, const T value) { //no init, plz init elsewhere

     for (auto& line : wallArg) {
          drawLinesOnWall(line, target, value);
     } //loop over all walls

} //drawLinesOnWall

template <typename T>
void UnivFFviaFM::drawLinesOnWall(Line& line, T* const target, const T value) { //no init, plz init elsewhere
// i~x; j~y;
//http://stackoverflow.com/questions/10060046/drawing-lines-with-bresenhams-line-algorithm
//src in answer of "Avi"; adapted to fit this application

     //grid handeling local vars:
     long int iMax  = _grid->GetiMax();

     long int iStart, iEnd;
     long int jStart, jEnd;
     long int iDot, jDot;
     long int key;
     long int deltaX, deltaY, deltaX1, deltaY1, px, py, xe, ye, i; //Bresenham Algorithm


     key = _grid->getKeyAtPoint(line.GetPoint1());
     iStart = (long) _grid->get_i_fromKey(key);
     jStart = (long) _grid->get_j_fromKey(key);

     key = _grid->getKeyAtPoint(line.GetPoint2());
     iEnd = (long) _grid->get_i_fromKey(key);
     jEnd = (long) _grid->get_j_fromKey(key);

     deltaX = (int) (iEnd - iStart);
     deltaY = (int) (jEnd - jStart);
     deltaX1 = abs( (int) (iEnd - iStart));
     deltaY1 = abs( (int) (jEnd - jStart));

     px = 2*deltaY1 - deltaX1;
     py = 2*deltaX1 - deltaY1;

     if(deltaY1<=deltaX1) {
          if(deltaX>=0) {
               iDot = iStart;
               jDot = jStart;
               xe = iEnd;
          } else {
               iDot = iEnd;
               jDot = jEnd;
               xe = iStart;
          }
          if ((_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
               target[jDot * iMax + iDot] = value;
          }
          for (i=0; iDot < xe; ++i) {
               ++iDot;
               if(px<0) {
                    px+=2*deltaY1;
               } else {
                    if((deltaX<0 && deltaY<0) || (deltaX>0 && deltaY>0)) {
                         ++jDot;
                    } else {
                         --jDot;
                    }
                    px+=2*(deltaY1-deltaX1);
               }
               if ((_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
                    target[jDot * iMax + iDot] = value;
               }
          }
     } else {
          if(deltaY>=0) {
               iDot = iStart;
               jDot = jStart;
               ye = jEnd;
          } else {
               iDot = iEnd;
               jDot = jEnd;
               ye = jStart;
          }
          if ((_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
               target[jDot * iMax + iDot] = value;
          }
          for(i=0; jDot<ye; ++i) {
               ++jDot;
               if (py<=0) {
                    py+=2*deltaX1;
               } else {
                    if((deltaX<0 && deltaY<0) || (deltaX>0 && deltaY>0)) {
                         ++iDot;
                    } else {
                         --iDot;
                    }
                    py+=2*(deltaX1-deltaY1);
               }
               if ((_gridCode[jDot*iMax + iDot] != CLOSED_CROSSING) && (_gridCode[jDot*iMax + iDot] != CLOSED_TRANSITION)) {
                    target[jDot * iMax + iDot] = value;
               }
          }
     }
} //drawLinesOnWall

Arne Graf's avatar
Arne Graf committed
925
void UnivFFviaFM::calcFF(double* costOutput, Point* directionOutput, const double *const speed) {
926 927 928
     //CompareCostTrips comp = CompareCostTrips(costOutput);
     std::priority_queue<long int, std::vector<long int>, CompareCostTrips> trialfield(costOutput); //pass the argument for the constr of CompareCostTrips
     //std::priority_queue<long int, std::vector<long int>, CompareCostTrips> trialfield2(comp);      //pass the CompareCostTrips object directly
Arne Graf's avatar
Arne Graf committed
929 930 931 932 933 934 935 936 937 938 939

     directNeighbor local_neighbor = _grid->getNeighbors(0);
     long int aux = 0;
     //init trial field
     for (long int i = 0; i < _nPoints; ++i) {
          if (costOutput[i] == 0.0) {
               //check for negative neighbours, calc that ones and add to queue trialfield
               local_neighbor = _grid->getNeighbors(i);

               //check for valid neigh
               aux = local_neighbor.key[0];
940
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
941 942
                    calcCost(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
943
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
944 945
               }
               aux = local_neighbor.key[1];
946
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
947 948
                    calcCost(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
949
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
950 951
               }
               aux = local_neighbor.key[2];
952
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
953 954
                    calcCost(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
955
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
956 957
               }
               aux = local_neighbor.key[3];
958
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
959 960
                    calcCost(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
961
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
962 963 964 965 966 967 968 969 970 971
               }
          }
     }

     while(!trialfield.empty()) {
          local_neighbor = _grid->getNeighbors(trialfield.top());
          trialfield.pop();

          //check for valid neigh
          aux = local_neighbor.key[0];
972
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
973 974
               calcCost(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
975
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
976 977
          }
          aux = local_neighbor.key[1];
978
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
979 980
               calcCost(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
981
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
982 983
          }
          aux = local_neighbor.key[2];
984
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
985 986
               calcCost(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
987
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
988 989
          }
          aux = local_neighbor.key[3];
990
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
991 992
               calcCost(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
993
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
          }
     }
}

void UnivFFviaFM::calcCost(const long int key, double* cost, Point* dir, const double* const speed) {
     //adapt from calcFloorfield
     double row = DBL_MAX;
     double col = DBL_MAX;
     long int aux = -1; //will be set below
     bool pointsUp = false;
     bool pointsRight = false;

     directNeighbor dNeigh = _grid->getNeighbors(key);

     aux = dNeigh.key[0];
     //hint: trialfield[i].cost = dist2Wall + i; <<< set in resetGoalAndCosts
     if  ((aux != -2) &&                                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE)) &&  //gridpoint holds a calculated value
          (_gridCode[aux] != WALL))                                                              //gridpoint holds a calculated value
     {
          row = cost[aux];
          pointsRight = true;
          if (row < 0) {
               std::cerr << "hier ist was schief " << row << " " << aux << " " <<  std::endl;
               row = DBL_MAX;
          }
     }
     aux = dNeigh.key[2];
     if  ((aux != -2) &&                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE)) &&  //gridpoint holds a calculated value
          (_gridCode[aux] != WALL) &&
          (cost[aux] < row))                                       //calculated value promises smaller cost
     {
          row = cost[aux];
          pointsRight = false;
     }

     aux = dNeigh.key[1];
     //hint: trialfield[i].cost = dist2Wall + i; <<< set in parseBuilding after linescan call
     if  ((aux != -2) &&                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE)) &&  //gridpoint holds a calculated value
          (_gridCode[aux] != WALL))
     {
          col = cost[aux];
          pointsUp = true;
          if (col < 0) {
               std::cerr << "hier ist was schief " << col << " " << aux << " "  << std::endl;
               col = DBL_MAX;
          }
     }
     aux = dNeigh.key[3];
     if  ((aux != -2) &&                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE)) &&  //gridpoint holds a calculated value
          (_gridCode[aux] != WALL) &&
          (cost[aux] < col))                                       //calculated value promises smaller cost
     {
          col = cost[aux];
          pointsUp = false;
     }
     if (col == DBL_MAX) { //one sided update with row
          cost[key] = onesidedCalc(row, _grid->Gethx()/speed[key]);
          //flag[key] = FM_SINGLE;
Arne Graf's avatar
Arne Graf committed
1056 1057 1058
          if (!dir) {
               return;
          }
Arne Graf's avatar
Arne Graf committed
1059 1060 1061 1062 1063 1064 1065
          if (pointsRight) {
               dir[key]._x = (-(cost[key+1]-cost[key])/_grid->Gethx());
               dir[key]._y = (0.);
          } else {
               dir[key]._x = (-(cost[key]-cost[key-1])/_grid->Gethx());
               dir[key]._y = (0.);
          }
Arne Graf's avatar
Arne Graf committed
1066
          dir[key] = dir[key].Normalized();
Arne Graf's avatar
Arne Graf committed
1067 1068 1069 1070 1071 1072
          return;
     }

     if (row == DBL_MAX) { //one sided update with col
          cost[key] = onesidedCalc(col, _grid->Gethy()/speed[key]);
          //flag[key] = FM_SINGLE;
Arne Graf's avatar
Arne Graf committed
1073 1074 1075
          if (!dir) {
               return;
          }
Arne Graf's avatar
Arne Graf committed
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
          if (pointsUp) {
               dir[key]._x = (0.);
               dir[key]._y = (-(cost[key+(_grid->GetiMax())]-cost[key])/_grid->Gethy());
          } else {
               dir[key]._x = (0.);
               dir[key]._y = (-(cost[key]-cost[key-(_grid->GetiMax())])/_grid->Gethy());
          }
          dir[key] = dir[key].Normalized();
          return;
     }

     //two sided update
     double precheck = twosidedCalc(row, col, _grid->Gethx()/speed[key]);
     if (precheck >= 0) {
          cost[key] = precheck;
          //flag[key] = FM_DOUBLE;
Arne Graf's avatar
Arne Graf committed
1092 1093 1094
          if (!dir) {
               return;
          }
Arne Graf's avatar
Arne Graf committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
          if (pointsUp && pointsRight) {
               dir[key]._x = (-(cost[key+1]-cost[key])/_grid->Gethx());
               dir[key]._y = (-(cost[key+(_grid->GetiMax())]-cost[key])/_grid->Gethy());
          }
          if (pointsUp && !pointsRight) {
               dir[key]._x = (-(cost[key]-cost[key-1])/_grid->Gethx());
               dir[key]._y = (-(cost[key+(_grid->GetiMax())]-cost[key])/_grid->Gethy());
          }
          if (!pointsUp && pointsRight) {
               dir[key]._x = (-(cost[key+1]-cost[key])/_grid->Gethx());
               dir[key]._y = (-(cost[key]-cost[key-(_grid->GetiMax())])/_grid->Gethy());
          }
          if (!pointsUp && !pointsRight) {
               dir[key]._x = (-(cost[key]-cost[key-1])/_grid->Gethx());
               dir[key]._y = (-(cost[key]-cost[key-(_grid->GetiMax())])/_grid->Gethy());
          }
     } else {
          std::cerr << "else in twosided Dist " << std::endl;
     }
     dir[key] = dir[key].Normalized();
}

Arne Graf's avatar
Arne Graf committed
1117
void UnivFFviaFM::calcDF(double* costOutput, Point* directionOutput, const double *const speed) {
1118 1119 1120
     //CompareCostTrips comp = CompareCostTrips(costOutput);
     std::priority_queue<long int, std::vector<long int>, CompareCostTrips> trialfield(costOutput); //pass the argument for the constr of CompareCostTrips
     //std::priority_queue<long int, std::vector<long int>, CompareCostTrips> trialfield2(comp);      //pass the CompareCostTrips object directly
Arne Graf's avatar
Arne Graf committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131

     directNeighbor local_neighbor = _grid->getNeighbors(0);
     long int aux = 0;
     //init trial field
     for (long int i = 0; i < _nPoints; ++i) {
          if (costOutput[i] == 0.0) {
               //check for negative neighbours, calc that ones and add to queue trialfield
               local_neighbor = _grid->getNeighbors(i);

               //check for valid neigh
               aux = local_neighbor.key[0];
1132
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1133 1134
                    calcDist(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1135
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1136 1137
               }
               aux = local_neighbor.key[1];
1138
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1139 1140
                    calcDist(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1141
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1142 1143
               }
               aux = local_neighbor.key[2];
1144
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1145 1146
                    calcDist(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1147
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1148 1149
               }
               aux = local_neighbor.key[3];
1150
               if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1151 1152
                    calcDist(aux, costOutput, directionOutput, speed);
                    trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1153
                    //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
               }
          }
     }

     while(!trialfield.empty()) {
          local_neighbor = _grid->getNeighbors(trialfield.top());
          trialfield.pop();

          //check for valid neigh
          aux = local_neighbor.key[0];
1164
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1165 1166
               calcDist(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1167
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1168 1169
          }
          aux = local_neighbor.key[1];
1170
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1171 1172
               calcDist(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1173
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1174 1175
          }
          aux = local_neighbor.key[2];
1176
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1177 1178
               calcDist(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1179
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1180 1181
          }
          aux = local_neighbor.key[3];
1182
          if ((aux != -2) && (_gridCode[aux] != WALL) && (_gridCode[aux] != OUTSIDE) && (costOutput[aux] < 0.0)) {
Arne Graf's avatar
Arne Graf committed
1183 1184
               calcDist(aux, costOutput, directionOutput, speed);
               trialfield.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1185
               //trialfield2.emplace(aux);
Arne Graf's avatar
Arne Graf committed
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
          }
     }
}

void UnivFFviaFM::calcDist(const long int key, double* cost, Point* dir, const double* const speed) {
     //adapt from calcFloorfield
     double row = DBL_MAX;
     double col = DBL_MAX;
     long int aux = -1; //will be set below
     bool pointsUp = false;
     bool pointsRight = false;

     directNeighbor dNeigh = _grid->getNeighbors(key);

     aux = dNeigh.key[0];
     //hint: trialfield[i].cost = dist2Wall + i; <<< set in resetGoalAndCosts
     if  ((aux != -2) &&                                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE))     //gridpoint holds a calculated value
          )                                                              //gridpoint holds a calculated value
     {
          row = cost[aux];
          pointsRight = true;
          if (row < 0) {
               std::cerr << "hier ist was schief " << row << " " << aux << " " <<  std::endl;
               row = DBL_MAX;
          }
     }
     aux = dNeigh.key[2];
     if  ((aux != -2) &&                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE))   //gridpoint holds a calculated value
           &&
          (cost[aux] < row))                                       //calculated value promises smaller cost
     {
          row = cost[aux];
          pointsRight = false;
     }

     aux = dNeigh.key[1];
     //hint: trialfield[i].cost = dist2Wall + i; <<< set in parseBuilding after linescan call
     if  ((aux != -2) &&                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE))   //gridpoint holds a calculated value
          )
     {
          col = cost[aux];
          pointsUp = true;
          if (col < 0) {
               std::cerr << "hier ist was schief " << col << " " << aux << " "  << std::endl;
               col = DBL_MAX;
          }
     }
     aux = dNeigh.key[3];
     if  ((aux != -2) &&                                                         //neighbor is a gridpoint
          (cost[aux] != magicnum(UNKNOWN_COST)) && (cost[aux] != magicnum(UNKNOWN_DISTANCE)) &&  //gridpoint holds a calculated value

          (cost[aux] < col))                                       //calculated value promises smaller cost
     {
          col = cost[aux];
          pointsUp = false;
     }
     if (col == DBL_MAX) { //one sided update with row
          cost[key] = onesidedCalc(row, _grid->Gethx()/speed[key]);
          //flag[key] = FM_SINGLE;
Arne Graf's avatar
Arne Graf committed
1248 1249 1250
          if (!dir) {
               return;
          }
Arne Graf's avatar
Arne Graf committed
1251 1252 1253 1254 1255 1256 1257
          if (pointsRight) {
               dir[key]._x = (-(cost[key+1]-cost[key])/_grid->Gethx());
               dir[key]._y = (0.);
          } else {
               dir[key]._x = (-(cost[key]-cost[key-1])/_grid->Gethx());
               dir[key]._y = (0.);
          }
Arne Graf's avatar
Arne Graf committed
1258
          dir[key] = dir[key].Normalized();
Arne Graf's avatar
Arne Graf committed
1259 1260 1261 1262 1263 1264
          return;
     }

     if (row == DBL_MAX) { //one sided update with col
          cost[key] = onesidedCalc(col, _grid->Gethy()/speed[key]);
          //flag[key] = FM_SINGLE;
Arne Graf's avatar
Arne Graf committed
1265 1266 1267
          if (!dir) {
               return;
          }
Arne Graf's avatar
Arne Graf committed
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
          if (pointsUp) {
               dir[key]._x = (0.);
               dir[key]._y = (-(cost[key+(_grid->GetiMax())]-cost[key])/_grid->Gethy());
          } else {
               dir[key]._x = (0.);
               dir[key]._y = (-(cost[key]-cost[key-(_grid->GetiMax())])/_grid->Gethy());
          }
          dir[key] = dir[key].Normalized();
          return;
     }

     //two sided update
     double precheck = twosidedCalc(row, col, _grid->Gethx()/speed[key]);
     if (precheck >= 0) {
          cost[key] = precheck;
          //flag[key] = FM_DOUBLE;
Arne Graf's avatar
Arne Graf committed
1284 1285 1286
          if (!dir) {
               return;
          }
Arne Graf's avatar
Arne Graf committed
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
          if (pointsUp && pointsRight) {
               dir[key]._x = (-(cost[key+1]-cost[key])/_grid->Gethx());
               dir[key]._y = (-(cost[key+(_grid->GetiMax())]-cost[key])/_grid->Gethy());
          }
          if (pointsUp && !pointsRight) {
               dir[key]._x = (-(cost[key]-cost[key-1])/_grid->Gethx());
               dir[key]._y = (-(cost[key+(_grid->GetiMax())]-cost[key])/_grid->Gethy());
          }
          if (!pointsUp && pointsRight) {
               dir[key]._x = (-(cost[key+1]-cost[key])/_grid->Gethx());
               dir[key]._y = (-(cost[key]-cost[key-(_grid->GetiMax())])/_grid->Gethy());
          }
          if (!pointsUp && !pointsRight) {
               dir[key]._x = (-(cost[key]-cost[key-1])/_grid->Gethx());
               dir[key]._y = (-(cost[key]-cost[key-(_grid->GetiMax())])/_grid->Gethy());
          }
     } else {
          std::cerr << "else in twosided Dist " << std::endl;
     }
     dir[key] = dir[key].Normalized();
}

Arne Graf's avatar
Arne Graf committed
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
inline double UnivFFviaFM::onesidedCalc(double xy, double hDivF) {
     //if ( (xy+hDivF) > 10000) std::cerr << "error in onesided " << xy << std::endl;
     return xy + hDivF;
}

inline double UnivFFviaFM::twosidedCalc(double x, double y, double hDivF) { //on error return -2
     double determinante = (2*hDivF*hDivF - (x-y)*(x-y));
     if (determinante >= 0) {
          return (x + y + sqrt(determinante))/2;
     } else {
          return (x < y) ? (x + hDivF) : (y + hDivF);
     }
     std::cerr << "error in two-sided 2!!!!!!!!!!!!!!!!!!!!!!! o_O??" << std::endl;
     return -2.; //this line should never execute
} //twosidedCalc

Arne Graf's avatar
Arne Graf committed
1325 1326 1327 1328 1329
void UnivFFviaFM::addTarget(const int uid, double* costarrayDBL, Point* gradarrayPt) {
     if (_doors.count(uid) == 0) {
          Log->Write("ERROR: \tCould not find door with uid %d in Room %d", uid, _room);
          return;
     }
Arne Graf's avatar
Arne Graf committed
1330 1331
     Line tempTargetLine = Line(_doors[uid]);
     Point tempCenterPoint = Point(tempTargetLine.GetCentre());
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
     if (_mode == LINESEGMENT) {
          if (tempTargetLine.GetLength() > 0.6) { //shorten line from both Points to avoid targeting edges of real door
               const Point &p1 = tempTargetLine.GetPoint1();
               const Point &p2 = tempTargetLine.GetPoint2();
               double length = tempTargetLine.GetLength();
               double u = 0.2 / length;
               tempTargetLine = Line(p1 + (p2 - p1) * u, p1 + (p2 - p1) * (1 - u), 0);
          } else if (tempTargetLine.GetLength() > 0.2) {
               const Point &p1 = tempTargetLine.GetPoint1();
               const Point &p2 = tempTargetLine.GetPoint2();
               double length = tempTargetLine.GetLength();
               double u = 0.05 / length;
               tempTargetLine = Line(p1 + (p2 - p1) * u, p1 + (p2 - p1) * (1 - u), 0);
          }
1346
     }
Arne Graf's avatar
Arne Graf committed
1347

Arne Graf's avatar
Arne Graf committed
1348
     //this allocation must be on shared heap! to be accessible by any thread later (should be shared in openmp)
Arne Graf's avatar
Arne Graf committed
1349
     double* newArrayDBL = (costarrayDBL)? costarrayDBL : new double[_nPoints];
Arne Graf's avatar
Arne Graf committed
1350 1351
     Point* newArrayPt = nullptr;
     if (_user == DISTANCE_AND_DIRECTIONS_USED) {
Arne Graf's avatar
Arne Graf committed
1352
          newArrayPt = (gradarrayPt)? gradarrayPt : new Point[_nPoints];
Arne Graf's avatar
Arne Graf committed
1353 1354
     }

Arne Graf's avatar
Arne Graf committed
1355
     if ((_costFieldWithKey[uid]) && (_costFieldWithKey[uid] != costarrayDBL))
Arne Graf's avatar
Arne Graf committed
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
          delete[] _costFieldWithKey[uid];
     _costFieldWithKey[uid] = newArrayDBL;

     //init costarray
     for (int i = 0; i < _nPoints; ++i) {
          if (_gridCode[i] == WALL) {
               newArrayDBL[i] = magicnum(WALL_ON_COSTARRAY);
          } else {
               newArrayDBL[i] = magicnum(UNKNOWN_COST);
          }
     }

Arne Graf's avatar
Arne Graf committed
1368
     if ((_directionFieldWithKey[uid]) && (_directionFieldWithKey[uid] != gradarrayPt))