Commit d535317d authored by tobias schroedter's avatar tobias schroedter

WIP commit before testing some changes

parent 7000c18b
......@@ -1636,6 +1636,13 @@ bool IniFileParser::ParseStrategyNodeToObject(const TiXmlNode& strategyNode)
};
_config->set_dirSubLocalTrips(dynamic_cast<DirectionSubLocalFloorfieldTrips*>(_exit_strategy.get()));
break;
case 11:
_exit_strategy = std::shared_ptr<DirectionStrategy>(new DirectionSubLocalFloorfieldTripsVoronoi());
if(!ParseFfOpts(strategyNode)) {
return false;
};
_config->set_dirSubLocalTripsVoronoi(dynamic_cast<DirectionSubLocalFloorfieldTripsVoronoi*>(_exit_strategy.get()));
break;
default:
_exit_strategy = std::shared_ptr<DirectionStrategy>(new DirectionMinSeperationShorterLine());
......
......@@ -47,6 +47,7 @@ class AgentsParameters;
class DirectionSubLocalFloorfield;
class DirectionLocalFloorfield;
class DirectionSubLocalFloorfieldTrips;
class DirectionSubLocalFloorfieldTripsVoronoi;
#ifdef _JPS_AS_A_SERVICE
......@@ -129,6 +130,8 @@ public:
//for random numbers
_rdGenerator=RandomNumberGenerator();
}
std::shared_ptr<WalkingSpeed> GetWalkingSpeed () {return _walkingSpeed; };
void SetWalkingSpeed(std::shared_ptr<WalkingSpeed> & w) {_walkingSpeed = w; };
......@@ -293,10 +296,13 @@ public:
void set_dirSubLocalTrips(DirectionSubLocalFloorfieldTrips* dir) {_dirSubLocalTrips = dir;}
void set_dirSubLocalTripsVoronoi(DirectionSubLocalFloorfieldTripsVoronoi* dir) {_dirSubLocalTripsVoronoi = dir;}
DirectionSubLocalFloorfield* get_dirSubLocal() const {return _dirSubLocal;}
DirectionLocalFloorfield* get_dirLocal() const {return _dirLocal;}
DirectionSubLocalFloorfieldTrips* get_dirSubLocalTrips() const {return _dirSubLocalTrips;}
DirectionSubLocalFloorfieldTripsVoronoi* get_dirSubLocalTripsVoronoi() const {return _dirSubLocalTripsVoronoi;}
const std::string& GetHostname() const { return _hostname; };
......@@ -420,6 +426,7 @@ private:
DirectionSubLocalFloorfield* _dirSubLocal;
DirectionLocalFloorfield* _dirLocal;
DirectionSubLocalFloorfieldTrips* _dirSubLocalTrips;
DirectionSubLocalFloorfieldTripsVoronoi* _dirSubLocalTripsVoronoi;
std::string _hostname;
std::string _trajectoriesFile;
......
......@@ -70,45 +70,41 @@ VelocityModel::~VelocityModel()
bool VelocityModel::Init (Building* building)
{
double _deltaH = building->GetConfig()->get_deltaH();
double _wallAvoidDistance = building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = building->GetConfig()->get_use_wall_avoidance();
//FIXME really???
if(auto dirff = dynamic_cast<DirectionFloorfield*>(_direction.get())){
Log->Write("INFO:\t Init DirectionFloorfield starting ...");
double _deltaH = building->GetConfig()->get_deltaH();
double _wallAvoidDistance = building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = building->GetConfig()->get_use_wall_avoidance();
dirff->Init(building, _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionFloorfield done");
}
if(auto dirlocff = dynamic_cast<DirectionLocalFloorfield*>(_direction.get())){
Log->Write("INFO:\t Init DirectionLOCALFloorfield starting ...");
double _deltaH = building->GetConfig()->get_deltaH();
double _wallAvoidDistance = building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = building->GetConfig()->get_use_wall_avoidance();
dirlocff->Init(building, _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionLOCALFloorfield done");
}
if(auto dirsublocff = dynamic_cast<DirectionSubLocalFloorfield*>(_direction.get())){
Log->Write("INFO:\t Init DirectionSubLOCALFloorfield starting ...");
double _deltaH = building->GetConfig()->get_deltaH();
double _wallAvoidDistance = building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = building->GetConfig()->get_use_wall_avoidance();
dirsublocff->Init(building, _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionSubLOCALFloorfield done");
}
if(auto dirsublocffTrips = dynamic_cast<DirectionSubLocalFloorfieldTrips*>(_direction.get())){
Log->Write("INFO:\t Init DirectionSubLOCALFloorfieldTrips starting ...");
double _deltaH = building->GetConfig()->get_deltaH();
double _wallAvoidDistance = building->GetConfig()->get_wall_avoid_distance();
bool _useWallAvoidance = building->GetConfig()->get_use_wall_avoidance();
dirsublocffTrips->Init(building, _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionSubLOCALFloorfieldTrips done");
}
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
if(auto dirsublocffTripsVoronoi = dynamic_cast<DirectionSubLocalFloorfieldTripsVoronoi*>(_direction.get())){
Log->Write("INFO:\t Init DirectionSubLOCALFloorfieldTripsVoronoi starting ...");
dirsublocffTripsVoronoi->Init(building, _deltaH, _wallAvoidDistance, _useWallAvoidance);
Log->Write("INFO:\t Init DirectionSubLOCALFloorfieldTripsVoronoi done");
}
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
size_t peds_size = allPeds.size();
std::cout << "Building has " << peds_size << " peds\n";
for(unsigned int p=0;p < peds_size;p++)
......
......@@ -630,7 +630,7 @@ void DirectionSubLocalFloorfieldTrips::Init(Building* buildingArg, double stepsi
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
Log->Write("INFO: \tCalling Construtor of UnivFFviaFM(Subroom-scale)");
Log->Write("INFO: \tCalling Construtor of UnivFFviaFMTrips(Subroom-scale)");
for (auto& roomPair : _building->GetAllRooms()) {
for (auto& subPair : roomPair.second->GetAllSubRooms()) {
......@@ -694,3 +694,138 @@ DirectionSubLocalFloorfieldTrips::~DirectionSubLocalFloorfieldTrips() {
delete pair.second;
}
}
///11
Point DirectionSubLocalFloorfieldTripsVoronoi::GetTarget(Room* room, Pedestrian* ped) const
{
Goal* goal = ped->GetBuilding()->GetFinalGoal(ped->GetFinalDestination());
// Pedestrian is inside a waiting area
if (goal->IsInsideGoal(ped->GetPos())){
std::vector<Point> polygon(goal->GetPolygon());
std::set<Point> triangle;
int min=0, max;
// Get randomly 3 points of polygon (
while (triangle.size() < 3){
max = polygon.size()-1;
int index = min + (std::rand() % static_cast<int>(max - min + 1));
triangle.insert(polygon.at(index));
}
double r1, r2;
r1 = ((double) std::rand() / (RAND_MAX));
r2 = ((double) std::rand() / (RAND_MAX));
Point p1 = polygon[0] * (1. - sqrt(r1));
Point p2 = polygon[1] * (sqrt(r1) * (1 - r2));
Point p3 = polygon[2] * (sqrt(r1) * r2);
Point p = p1 + p2 + p3;
// UnivFFviaFM* floorfield = _locffviafm.at(ped->GetSubRoomUID());
// floorfield->getDirectionToUID(ped->GetExitIndex(), ped->GetPos(),p);
// return (p + ped->GetPos());
return p;
} else {
Point p;
UnivFFviaFM* floorfield = _locffviafm.at(ped->GetSubRoomUID());
floorfield->getDirectionToUID(ped->GetExitIndex(), ped->GetPos(),p);
return (p + ped->GetPos());
}
}
Point DirectionSubLocalFloorfieldTripsVoronoi::GetDir2Wall(Pedestrian* ped) const
{
Point p;
int key = ped->GetSubRoomUID();
_locffviafm.at(key)->getDir2WallAt(ped->GetPos(), p);
return p;
}
double DirectionSubLocalFloorfieldTripsVoronoi::GetDistance2Wall(Pedestrian* ped) const
{
return _locffviafm.at(ped->GetSubRoomUID())->getDistance2WallAt(ped->GetPos());
}
double DirectionSubLocalFloorfieldTripsVoronoi::GetDistance2Target(Pedestrian* ped, int UID) {
int subroomUID = ped->GetSubRoomUID();
return _locffviafm.at(subroomUID)->getCostToDestination(UID, ped->GetPos());
}
void DirectionSubLocalFloorfieldTripsVoronoi::Init(Building* buildingArg, double stepsize,
double threshold, bool useDistanceMap) {
_stepsize = stepsize;
_building = buildingArg;
_wallAvoidDistance = threshold;
_useDistancefield = useDistanceMap;
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
Log->Write("INFO: \tCalling Construtor of UnivFFviaFMTripsVoronoi(Subroom-scale)");
for (auto& roomPair : _building->GetAllRooms()) {
for (auto& subPair : roomPair.second->GetAllSubRooms()) {
int subUID = subPair.second->GetUID();
UnivFFviaFM* floorfield = new UnivFFviaFM(subPair.second.get(), _building, stepsize, _wallAvoidDistance, _useDistancefield);
_locffviafm[subUID] = floorfield;
floorfield->setUser(DISTANCE_AND_DIRECTIONS_USED);
floorfield->setMode(LINESEGMENT);
if (useDistanceMap) {
floorfield->setSpeedMode(FF_WALL_AVOID);
} else {
floorfield->setSpeedMode(FF_HOMO_SPEED);
}
floorfield->addAllTargetsParallel();
}
}
if (_building->GetConfig()->get_write_VTK_files_direction()) {
for (unsigned int i = 0; i < _locffviafm.size(); ++i) {
auto iter = _locffviafm.begin();
std::advance(iter, i);
int roomNr = iter->first;
iter->second->writeFF("direction" + std::to_string(roomNr) + ".vtk", iter->second->getKnownDoorUIDs());
}
}
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;
//_locffviafm[0]->writeFF()
//write floorfields to file, one file per subroom //ar.graf: [SWITCH writevtk ON/OFF]
// for(unsigned int i = 0; i < subUIDs.size(); ++i) {
// std::vector<int> targets = {};
// targets.clear();
// int subroomUID = subUIDs[i];
// //if (subroomUID != 26) continue;
//
// for (auto pair : subAndTarget) {
// if (pair.first == subroomUID) {
// targets.emplace_back(pair.second);
// }
// }
// std::string filename1 = "floorfield" + std::to_string(subroomUID) + ".vtk";
// if (targets.size() > 0)
// _locffviafm[subroomUID]->writeFF(filename1, targets);
// }
}
DirectionSubLocalFloorfieldTripsVoronoi::DirectionSubLocalFloorfieldTripsVoronoi() {
_initDone = false;
}
DirectionSubLocalFloorfieldTripsVoronoi::~DirectionSubLocalFloorfieldTripsVoronoi() {
for (auto pair : _locffviafm) {
delete pair.second;
}
}
......@@ -156,5 +156,27 @@ protected:
std::string _filename;
};
class DirectionSubLocalFloorfieldTripsVoronoi : public DirectionStrategy {
public:
DirectionSubLocalFloorfieldTripsVoronoi();
void Init(Building* building, double stepsize, double threshold,
bool useDistanceMap);
~DirectionSubLocalFloorfieldTripsVoronoi();
virtual Point GetTarget(Room* room, Pedestrian* ped) const;
virtual Point GetDir2Wall(Pedestrian* ped) const;
virtual double GetDistance2Wall(Pedestrian* ped) const;
virtual double GetDistance2Target(Pedestrian* ped, int UID);
protected:
std::map<int, UnivFFviaFM*> _locffviafm;
bool _initDone;
Building* _building;
double _stepsize;
double _wallAvoidDistance;
bool _useDistancefield;
std::string _filename;
};
#endif /* _DIRECTIONSTRATEGY_H */
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