Commit 3a468b8b authored by Ulrich Kemloh's avatar Ulrich Kemloh

The visibility check is now considering the 3D location of the points.

parent f58b9330
......@@ -158,6 +158,7 @@ void TrajectoriesJPSV04::WriteGeometry(Building* building)
// first the rooms
//to avoid writing navigation line twice
vector<int> navLineWritten;
//rooms_to_plot.push_back("Verteilerebene_001");
for (const auto& it:building->GetAllRooms())
{
......@@ -167,7 +168,7 @@ void TrajectoriesJPSV04::WriteGeometry(Building* building)
continue;
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k); //if(s->GetSubRoomID()!=0) continue;
SubRoom* s = r->GetSubRoom(k); //if(s->GetSubRoomID()!=25) continue;
geometry.append(s->WriteSubRoom());
// the hlines
......
......@@ -150,7 +150,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
case FORMAT_XML_PLAIN: {
OutputHandler* tofile = new FileHandler(
args.GetTrajectoriesFile().c_str());
Trajectories* output = new TrajectoriesJPSV05();
Trajectories* output = new TrajectoriesJPSV04();
output->SetOutputHandler(tofile);
_iod->AddIO(output);
break;
......
......@@ -232,7 +232,8 @@ bool EventManager::UpdateAgentKnowledge(Building* _b)
if( (ped1->GetPos()-ped2->GetPos()).Norm()<_updateRadius)
{
//maybe same room and subroom ?
if(_b->IsVisible(ped1->GetPos(),ped2->GetPos()))
vector<SubRoom*> empty;
if(_b->IsVisible(ped1->GetPos(),ped2->GetPos(),empty))
{
MergeKnowledge(ped1, ped2); //ped1->SetSpotlight(true);
ped2->SetNewEventFlag(true);
......
......@@ -72,7 +72,7 @@ Building::Building(const std::string& filename, const std::string& rootDir, Rout
//todo: what happens if any of these methods failed (return false)? throw exception ?
this->LoadGeometry();
this->LoadRoutingInfo(filename);
this->AddSurroundingRoom();
//this->AddSurroundingRoom();
this->InitGeometry();
this->LoadTrafficInfo();
distributor.Distribute(this);
......@@ -843,26 +843,37 @@ SubRoom* Building::GetSubRoomByUID( int uid)
return NULL;
}
bool Building::IsVisible(Line* l1, Line* l2, bool considerHlines)
//bool Building::IsVisible(Line* l1, Line* l2, bool considerHlines)
//{
//
// for(auto&& itr_room: _rooms)
// {
// for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
// {
// if(itr_subroom.second->IsVisible(l1,l2,considerHlines)==false) return false;
// }
// }
// return true;
//}
bool Building::IsVisible(const Point& p1, const Point& p2, const std::vector<SubRoom*>& subrooms, bool considerHlines)
{
for(auto&& itr_room: _rooms)
//loop over all subrooms if none is provided
if (subrooms.empty())
{
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
for(auto&& itr_room: _rooms)
{
if(itr_subroom.second->IsVisible(l1,l2,considerHlines)==false) return false;
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
{
if(itr_subroom.second->IsVisible(p1,p2,considerHlines)==false) return false;
}
}
}
return true;
}
bool Building::IsVisible(const Point& p1, const Point& p2, bool considerHlines)
{
for(auto&& itr_room: _rooms)
else
{
for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
for(auto&& sub: subrooms)
{
if(itr_subroom.second->IsVisible(p1,p2,considerHlines)==false) return false;
if(sub and sub->IsVisible(p1,p2,considerHlines)==false) return false;
}
}
......
......@@ -122,14 +122,14 @@ public:
* Alls walls and transitions and crossings are used in this check.
* The use of hlines is optional, because they are not real, can can be considered transparent
*/
bool IsVisible(Line* l1, Line* l2, bool considerHlines=false);
//bool IsVisible(Line* l1, Line* l2, bool considerHlines=false);
/**
* @return true if the two points are visible from each other.
* Alls walls and transitions and crossings are used in this check.
* The use of hlines is optional, because they are not real, can be considered transparent
*/
bool IsVisible(const Point& p1, const Point& p2, bool considerHlines=false);
bool IsVisible(const Point& p1, const Point& p2, const std::vector<SubRoom*>& subrooms, bool considerHlines=false);
/**
* @return a crossing or a transition matching the given caption.
......
......@@ -36,9 +36,6 @@ using namespace std;
Crossing::Crossing()
{
_id = -1;
_room1 = NULL;
_subRoom1 = NULL;
_subRoom2 = NULL;
}
Crossing::~Crossing()
......@@ -50,10 +47,10 @@ void Crossing::SetID(int ID)
_id = ID;
}
void Crossing::SetSubRoom2(SubRoom* r2)
{
_subRoom2 = r2;
}
//void Crossing::SetSubRoom2(SubRoom* r2)
//{
// _subRoom2 = r2;
//}
// Getter-Funktionen
......@@ -62,10 +59,10 @@ int Crossing::GetID() const
return _id;
}
SubRoom* Crossing::GetSubRoom2() const
{
return _subRoom2;
}
//SubRoom* Crossing::GetSubRoom2() const
//{
// return _subRoom2;
//}
// Sonstiges
......
......@@ -41,33 +41,42 @@ private:
/// TODO ? unique between crossings and transitions ?
int _id;
/// only one room needed, since a crossing only separates 2 subrooms
Room* _room1;
SubRoom* _subRoom1;
SubRoom* _subRoom2;
//Room* _room1;
//SubRoom* _subRoom1;
//SubRoom* _subRoom2;
public:
/**
* Constructor
*/
Crossing();
/**
* Destructor
*/
virtual ~Crossing();
/**
* Set/Get the Id of the crossing
* TODO: do you really want to shadow ?
*/
void SetID(int ID);
/**
* Set/Get the Id of the crossing
* TODO: do you really want to shadow ?
*/
int GetID () const;
/**
* Set/Get the second subroom
*/
void SetSubRoom2(SubRoom* r2);
//void SetSubRoom2(SubRoom* r2);
/**
* Set/Get the second subroom
*/
SubRoom* GetSubRoom2() const;
//SubRoom* GetSubRoom2() const;
/**
* \return true if the subroomID is associated with the current crossing
......
......@@ -33,8 +33,6 @@ using namespace std;
Hline::Hline()
{
_room1=NULL;
_subRoom1=NULL;
_id=-1;
}
......@@ -82,6 +80,17 @@ SubRoom* Hline::GetSubRoom1() const
return _subRoom1;
}
void Hline::SetSubRoom2(SubRoom* r2)
{
_subRoom2 = r2;
}
SubRoom* Hline::GetSubRoom2() const
{
return _subRoom2;
}
bool Hline::IsInSubRoom(int subroomID) const
{
return _subRoom1->GetSubRoomID() == subroomID;
......
......@@ -40,12 +40,24 @@ class Hline: public NavLine {
private:
int _id;
Room* _room1;
std::string _caption;
SubRoom* _subRoom1;
//TODO: these should be redesigned as private
//and accessed via functions in the derived classes.
protected:
Room* _room1=nullptr;
SubRoom* _subRoom1=nullptr;
SubRoom* _subRoom2=nullptr;
public:
/**
* Constructor
*/
Hline();
/**
* Destructor
*/
virtual ~Hline();
/**
......@@ -67,6 +79,10 @@ public:
* Set/Get the subroom containing this line
*/
void SetSubRoom1(SubRoom* r);
/**
* Set/Get the second subroom
*/
void SetSubRoom2(SubRoom* r2);
/**
* Set/Get the id of the line
......@@ -88,6 +104,11 @@ public:
*/
SubRoom* GetSubRoom1() const;
/**
* Set/Get the second subroom
*/
SubRoom* GetSubRoom2() const;
/**
* @return true if the line is in the given subroom
*/
......
......@@ -330,6 +330,7 @@ std::vector<Wall> SubRoom::GetVisibleWalls(const Point & position){
// like ped_is_visible() but here we can exclude checking intersection
// with the same wall. This function should check if <position> can see the <Wall>
//TODO: optimize
bool SubRoom::IsVisible(const Line &wall, const Point &position)
{
// printf("\tEnter wall_is_visible\n");
......@@ -373,40 +374,43 @@ bool SubRoom::IsVisible(const Line &wall, const Point &position)
// with the nearest point on the wall IS intersecting with the wall.
bool SubRoom::IsVisible(const Point& p1, const Point& p2, bool considerHlines)
{
// printf("\t\tEnter ped_is_visible\n");
// generate certain connection lines
// connecting p1 with p2
//Line cl(p1,p2);
//Line L2;
bool temp = true;
//check intersection with Walls
for(const auto& wall : _walls) {
if (wall.IntersectionWith(p1, p2)) {
for(const auto& wall : _walls)
{
if (wall.IntersectionWith(p1, p2))
{
return false;
}
}
// printf("\t\t -- ped_is_visible; check obstacles\n");
//check intersection with obstacles
for ( const auto obstacle : _obstacles) {
for ( const auto& wall : obstacle->GetAllWalls()) {
if (wall.IntersectionWith(p1, p2)) {
for ( const auto& obstacle : _obstacles)
{
for ( const auto& wall : obstacle->GetAllWalls())
{
if (wall.IntersectionWith(p1, p2))
{
return false;
}
}
}
// check intersection with other hlines in room
if(considerHlines)
for(unsigned int i = 0; i < _hlines.size(); i++) {
if(_hlines[i]->IsInLineSegment(p1)|| _hlines[i]->IsInLineSegment(p2)) continue;
if(temp && (Line*)_hlines[i]->IntersectionWith(p1, p2))
temp = false;
{
for(const auto& hline: _hlines)
{
if(hline->IsInLineSegment(p1)|| hline->IsInLineSegment(p2)) continue;
if(hline->IntersectionWith(p1, p2))
{
return false;
}
}
}
// printf("\t\tLeave ped_is_visible with %d\n",temp);
return temp;
return true;
}
bool SubRoom::IsVisible(Line* l1, Line* l2, bool considerHlines)
......
......@@ -157,13 +157,14 @@ void GCFMModel::ComputeNextTimeStep(double current, double deltaT, Building* bui
vector<Pedestrian*> neighbours;
building->GetGrid()->GetNeighbourhood(ped,neighbours);
//if(ped->GetID()==61) building->GetGrid()->HighlightNeighborhood(ped,building);
vector<SubRoom*> emptyVector;
int nSize=neighbours.size();
for (int i = 0; i < nSize; i++) {
Pedestrian* ped1 = neighbours[i];
Point p1 = ped->GetPos();
Point p2 = ped1->GetPos();
bool ped_is_visible = building->IsVisible(p1, p2, false);
bool ped_is_visible = building->IsVisible(p1, p2, emptyVector, false);
if (!ped_is_visible)
continue;
// if(debugPed == ped->GetID())
......
......@@ -198,7 +198,8 @@ void GompertzModel::ComputeNextTimeStep(double current, double deltaT, Building*
//if they are in the same subroom
Point p1 = ped->GetPos();
Point p2 = ped1->GetPos();
bool isVisible = building->IsVisible(p1, p2, false);
vector<SubRoom*> emptyVector;
bool isVisible = building->IsVisible(p1, p2, emptyVector, false);
if (!isVisible)
continue;
// if(debugPed == ped->GetID())
......
......@@ -269,7 +269,7 @@ bool GlobalRouter::Init(Building* building)
}
//collect all navigation objects
vector<NavLine*> allGoals;
vector<Hline*> allGoals;
const auto & crossings = sub->GetAllCrossings();
allGoals.insert(allGoals.end(), crossings.begin(), crossings.end());
const auto & transitions = sub->GetAllTransitions();
......@@ -283,13 +283,13 @@ bool GlobalRouter::Init(Building* building)
//process the transitions
for (unsigned int n1 = 0; n1 < allGoals.size(); n1++)
{
NavLine* nav1 = allGoals[n1];
Hline* nav1 = allGoals[n1];
AccessPoint* from_AP = _accessPoints[nav1->GetUniqueID()];
int from_door = _map_id_to_index[nav1->GetUniqueID()];
if(from_AP->IsClosed()) continue;
for (unsigned int n2 = 0; n2 < allGoals.size(); n2++) {
NavLine* nav2 = allGoals[n2];
Hline* nav2 = allGoals[n2];
AccessPoint* to_AP = _accessPoints[nav2->GetUniqueID()];
if(to_AP->IsClosed()) continue;
......@@ -298,7 +298,15 @@ bool GlobalRouter::Init(Building* building)
if (nav1->operator ==(*nav2))
continue;
if (building->IsVisible(nav1->GetCentre(), nav2->GetCentre(), true)) {
vector<SubRoom*> emptyVector;
emptyVector.push_back(nav1->GetSubRoom1());
emptyVector.push_back(nav1->GetSubRoom2());
emptyVector.push_back(nav2->GetSubRoom1());
emptyVector.push_back(nav2->GetSubRoom2());
if (building->IsVisible(nav1->GetCentre(), nav2->GetCentre(), emptyVector,true))
{
int to_door = _map_id_to_index[nav2->GetUniqueID()];
_distMatrix[from_door][to_door] = penalty*(nav1->GetCentre()
- nav2->GetCentre()).Norm();
......@@ -428,7 +436,7 @@ bool GlobalRouter::Init(Building* building)
" \tYou can solve this by enabling triangulation.",
from_AP->GetFriendlyName().c_str());
from_AP->Dump();
//return false;
return false;
}
}
_tmpPedPath.clear();
......@@ -485,7 +493,7 @@ bool GlobalRouter::Init(Building* building)
//DumpAccessPoints(20); //exit(0);
//DumpAccessPoints(-1); exit(0);
//vector<string> rooms;
//rooms.push_back("hall1");
//rooms.push_back("Verteilerebene_001");
//WriteGraphGV("routing_graph.gv",FINAL_DEST_OUT,rooms); exit(0);
//WriteGraphGV("routing_graph.gv",4,rooms);exit(0);
Log->Write("INFO:\tDone with the Global Router Engine!");
......
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