Last part of correct train geometry

parent d184bcdf
...@@ -691,7 +691,7 @@ double Simulation::RunBody(double maxSimTime) ...@@ -691,7 +691,7 @@ double Simulation::RunBody(double maxSimTime)
if(trainOutflow[id] >= TrainTypes[type]->nmax) if(trainOutflow[id] >= TrainTypes[type]->nmax)
{ {
std::cout << "INFO:\tclosing train door "<< transType.c_str() << " at "<< Pedestrian::GetGlobalTime() << "\n"; std::cout << "INFO:\tclosing train door "<< transType.c_str() << " at "<< Pedestrian::GetGlobalTime() << "\n";
Log->Write("INFO:\tclosing train door %s at t=%.2f", transType.c_str(), Pedestrian::GetGlobalTime()); Log->Write("INFO:\tclosing train door %s at t=%.2f. Flow = %.2f (Train Capacity %.2f)", transType.c_str(), Pedestrian::GetGlobalTime(), trainOutflow[id], TrainTypes[type]->nmax);
Trans->Close(); Trans->Close();
} }
} }
...@@ -780,8 +780,8 @@ bool Simulation::correctGeometry(std::shared_ptr<Building> building, std::shared ...@@ -780,8 +780,8 @@ bool Simulation::correctGeometry(std::shared_ptr<Building> building, std::shared
subroom->GetUID(); subroom->GetUID();
auto walls = subroom->GetAllWalls(); auto walls = subroom->GetAllWalls();
// debugging
// std::cout << "------\n"; //---
for(auto pw: pws) for(auto pw: pws)
{ {
auto pw1 = pw.first; auto pw1 = pw.first;
...@@ -902,16 +902,57 @@ bool Simulation::correctGeometry(std::shared_ptr<Building> building, std::shared ...@@ -902,16 +902,57 @@ bool Simulation::correctGeometry(std::shared_ptr<Building> building, std::shared
else // disjoint else // disjoint
{ {
std::cout << "DISJOINT\n"; std::cout << "DISJOINT\n";
//------------ transition --------
Transition* e = new Transition();
e->SetID(transition_id++);
e->SetCaption(trainType);
e->SetPoint1(p1);
e->SetPoint2(p2);
std::string transType = "Train_"+std::to_string(tab->id)+"_"+std::to_string(tab->tin)+"_"+std::to_string(tab->tout);
e->SetType(transType);
room->AddTransitionID(e->GetUniqueID());// danger area
e->SetRoom1(room);
e->SetSubRoom1(subroom);
subroom->AddTransition(e);// danger area
building->AddTransition(e);// danger area
//--------------------------------
// find points on w1 and w2 between p1 and p2 // find points on w1 and w2 between p1 and p2
// (A, B) // (A, B)
// remove all walls connected to A Point A, B;
// move A forwards if(e->isBetween(w1.GetPoint1()))
// remove walls... until B is found A = w1.GetPoint2();
else
A = w1.GetPoint1();
if(e->isBetween(w2.GetPoint1()))
B = w2.GetPoint2();
else
B = w2.GetPoint1();
Wall NewWall(A, p1);
Wall NewWall1(B, p2);
NewWall.SetType(w1.GetType());
NewWall1.SetType(w2.GetType());
// remove walls between
for(auto wall: mytrack)
{
if(e->isBetween(wall.GetPoint1()) || e->isBetween(wall.GetPoint2()))
{
building->TempRemovedWalls[trainId].push_back(wall);
subroom->RemoveWall(wall);
}
}
// changes to building
building->TempAddedWalls[trainId].push_back(NewWall);
building->TempAddedWalls[trainId].push_back(NewWall1);
building->TempAddedDoors[trainId].push_back(*e);
subroom->AddWall(NewWall);
subroom->AddWall(NewWall1);
// remove walls w1 and w2 // remove walls w1 and w2
} }
} }
std::cout << "------\n";
/* getc(stdin); */
_routingEngine->setNeedUpdate(true); _routingEngine->setNeedUpdate(true);
return true; return true;
......
...@@ -201,6 +201,16 @@ Point Line::LotPoint(const Point& p) const ...@@ -201,6 +201,16 @@ Point Line::LotPoint(const Point& p) const
return f; return f;
} }
// return true if point the orthogonal projection of p on Line segment is on the
// line segment.
bool Line::isBetween(const Point& p) const
{
const Point& t = _point1-_point2;
double lambda = (p-_point2).ScalarProduct(t)/t.ScalarProduct(t);
return (lambda>0) && (lambda <1);
}
/* Punkt auf der Linie mit kürzestem Abstand zu p /* Punkt auf der Linie mit kürzestem Abstand zu p
* In der Regel Lotfußpunkt, Ist der Lotfußpunkt nicht im Segment * In der Regel Lotfußpunkt, Ist der Lotfußpunkt nicht im Segment
* wird der entsprechende Eckpunkt der Line genommen * wird der entsprechende Eckpunkt der Line genommen
...@@ -273,6 +283,12 @@ bool Line::operator!=(const Line& l) const ...@@ -273,6 +283,12 @@ bool Line::operator!=(const Line& l) const
return (!(*this==l)); return (!(*this==l));
} }
// this function is necessary to use std::set and is basically the same as !=
bool Line::operator<(const Line& l) const
{
return (!(*this==l));
}
double Line::GetLength() const double Line::GetLength() const
{ {
......
...@@ -161,6 +161,12 @@ public: ...@@ -161,6 +161,12 @@ public:
*/ */
bool Overlapp(const Line& l) const; bool Overlapp(const Line& l) const;
/**
* return true if point the orthogonal projection of p on Line segment is on the
* line segment.
*/
bool isBetween(const Point& p) const;
/** /**
* @return true if both segments are equal. The end points must be in the range of J_EPS. * @return true if both segments are equal. The end points must be in the range of J_EPS.
* @see Macro.h * @see Macro.h
...@@ -173,6 +179,15 @@ public: ...@@ -173,6 +179,15 @@ public:
*/ */
bool operator!=(const Line& l) const; bool operator!=(const Line& l) const;
/**
* @return true if this < l segments are not equal. The end points must be in the range of J_EPS.
* @see Macro.h
*/
bool operator<(const Line& l) const;
/** /**
* @see http://alienryderflex.com/intersect/ * @see http://alienryderflex.com/intersect/
* @see http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e5993847-c7a9-46ec-8edc-bfb86bd689e3/ * @see http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e5993847-c7a9-46ec-8edc-bfb86bd689e3/
......
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