Commit 1e191222 authored by Ulrich Kemloh's avatar Ulrich Kemloh

Cleaning and refactoring

parent 0390a0a5
......@@ -177,7 +177,7 @@ inline char xmltoc(const char * t, const char v = '\0')
* @return true if the element is present in the vector
*/
template<typename A>
inline bool IsElementInVector(const std::vector<A> &vec, A& el) {
inline bool IsElementInVector(const std::vector<A> &vec, const A& el) {
typename std::vector<A>::const_iterator it;
it = std::find (vec.begin(), vec.end(), el);
if(it==vec.end()) {
......
......@@ -298,6 +298,25 @@ bool Building::InitGeometry()
}
}
// look and save the neighbor subroom for improving the runtime
// that information is already present in the crossing/transitions
for(const auto & cross: _crossings)
{
SubRoom* s1=cross.second->GetSubRoom1();
SubRoom* s2=cross.second->GetSubRoom2();
if(s1) s1->AddNeighbor(s2);
if(s2) s2->AddNeighbor(s1);
}
for(const auto & trans: _transitions)
{
SubRoom* s1=trans.second->GetSubRoom1();
SubRoom* s2=trans.second->GetSubRoom2();
if(s1) s1->AddNeighbor(s2);
if(s2) s2->AddNeighbor(s1);
}
Log->Write("INFO: \tInit Geometry successful!!!\n");
return true;
......
This diff is collapsed.
......@@ -30,9 +30,7 @@
#define _SUBROOM_H
//#include "Line.h"
#include "Wall.h"
//#include "Point.h"
#include <vector>
#include <string>
......@@ -70,12 +68,12 @@ private:
double _cosAngleWithHorizontalPlane;
std::string _type;
std::vector<Obstacle*> _obstacles; // obstacles
//different types of navigation lines
std::vector<Crossing*> _crossings;
std::vector<Transition*> _transitions;
std::vector<Hline*> _hlines;
std::vector<SubRoom*>_neighbors;
/// storing and incrementing the total number of subrooms
static int _static_uid;
......@@ -83,11 +81,18 @@ private:
protected:
std::vector<Wall> _walls;
std::vector<Point> _poly; // Polygonal representation of the subroom
std::vector<Obstacle*> _obstacles;
public:
// constructors
/**
* Constructor
*/
SubRoom();
/**
* Destructor
*/
virtual ~SubRoom();
/**
......@@ -113,11 +118,6 @@ public:
*/
int GetSubRoomID() const;
/**
* @return the number of walls forming this subroom
*/
int GetNumberOfWalls() const;
/**
* @return all walls
*/
......@@ -128,11 +128,6 @@ public:
*/
std::vector<Wall> GetVisibleWalls(const Point & position);
/**
* @return a reference to the wall at position index
*/
const Wall& GetWall(int index) const;
/**
* @return the polygonal representation of the subroom
* counterclockwise
......@@ -178,7 +173,6 @@ public:
*/
void SetType(const std::string& type);
/**
* @return the status
*/
......@@ -248,6 +242,7 @@ public:
void AddCrossing(Crossing* line);
void AddTransition(Transition* line);
void AddHline(Hline* line);
void AddNeighbor(SubRoom* sub);
const std::vector<Crossing*>& GetAllCrossings() const;
const std::vector<Transition*>& GetAllTransitions() const;
......@@ -256,6 +251,17 @@ public:
const Transition* GetTransition(int i) const;
const Hline* GetHline(int i) const;
/**
* @return true if there is an overlapp between the walls of the subrooms and the
* supplied set of lines.
*/
bool Overlapp(const std::vector<Line*>& goals) const;
/**
* @return the adjacent subrooms
*/
const std::vector<SubRoom*>& GetNeighbors() const ;
/**
* Add a wall to the subroom
*/
......@@ -267,20 +273,20 @@ public:
*/
void AddObstacle(Obstacle* obs);
/**
* Add/remove a goal Id
*/
void AddGoalID(int ID);
void RemoveGoalID(int ID);
/**
* @return true if the two subrooms share a common walkable Edge (crossing or transition)
* Add/remove a goal Id
*/
bool IsDirectlyConnectedWith(const SubRoom* sub) const;
void RemoveGoalID(int ID);
/**
* @return true if the two segments 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 and can be considered transparent
* @return true if the two subrooms share a common walkable Edge (crossing or transition)
*/
bool IsVisible(Line* l1, Line* l2, bool considerHlines=false);
bool IsDirectlyConnectedWith(SubRoom* sub) const;
/**
* @return true if the two points are visible from each other.
......@@ -302,14 +308,11 @@ public:
virtual std::string WritePolyLine() const=0;
/// convert all walls and transitions(doors) into a polygon representing the subroom
virtual bool ConvertLineToPoly(std::vector<Line*> goals) = 0;
virtual bool ConvertLineToPoly(const std::vector<Line*>& goals) = 0;
///check whether the pedestrians is still in the subroom
virtual bool IsInSubRoom(const Point& ped) const = 0;
// MPI:
void ClearAllPedestrians();
#ifdef _SIMULATOR
virtual bool IsInSubRoom(Pedestrian* ped) const;
......@@ -338,7 +341,7 @@ public:
std::string WritePolyLine() const;
void WriteToErrorLog() const;
bool ConvertLineToPoly(std::vector<Line*> goals);
bool ConvertLineToPoly(const std::vector<Line*>& goals);
bool IsInSubRoom(const Point& ped) const;
};
......@@ -373,7 +376,7 @@ public:
std::string WriteSubRoom() const;
std::string WritePolyLine() const;
virtual void WriteToErrorLog() const;
virtual bool ConvertLineToPoly(std::vector<Line*> goals);
virtual bool ConvertLineToPoly(const std::vector<Line*>& goals);
bool IsInSubRoom(const Point& ped) const;
};
......
......@@ -46,7 +46,14 @@ private:
public:
/**
* Cosntructor
*/
Transition();
/**
* Destructor
*/
virtual ~Transition();
/**
......
......@@ -34,8 +34,19 @@
class Wall : public Line {
public:
/**
* Constructor
*/
Wall();
/**
* Constructor
*/
Wall(const Point& p1, const Point& p2, const std::string& type="internal");
/**
* Constructor
*/
Wall(const Wall& orig);
/**
......
......@@ -84,7 +84,7 @@
</agents_distribution>
<agents_sources><!-- frequency in persons/seconds -->
<source id="1" frequency="1" agents_max="5" group_id="1" caption="source 1" />
<source id="1" frequency="1" agents_max="5" group_id="0" caption="source 1" />
<source id="2" frequency="1" agents_max="5" group_id="2" caption="source 2" />
<source id="3" frequency="1" agents_max="5" group_id="3" caption="source 3" />
<source id="4" frequency="1" agents_max="5" group_id="4" caption="source 4" />
......
......@@ -432,7 +432,7 @@ inline Point GCFMModel::ForceRepRoom(Pedestrian* ped, SubRoom* subroom) const
}
inline Point GCFMModel::ForceRepWall(Pedestrian* ped, const Wall& w) const
inline Point GCFMModel::ForceRepWall(Pedestrian* ped, const Line& w) const
{
Point F = Point(0.0, 0.0);
Point pt = w.ShortestPoint(ped->GetPos());
......
......@@ -118,7 +118,7 @@ private:
* @return
*/
Point ForceRepRoom(Pedestrian* ped, SubRoom* subroom) const;
Point ForceRepWall(Pedestrian* ped, const Wall& l) const;
Point ForceRepWall(Pedestrian* ped, const Line& l) const;
Point ForceRepStatPoint(Pedestrian* ped, const Point& p, double l, double vn) const;
Point ForceInterpolation(double v0, double K_ij, const Point& e, double v, double d, double r, double l) const;
......
This diff is collapsed.
......@@ -403,32 +403,32 @@ Point GompertzModel::ForceRepRoom(Pedestrian* ped, SubRoom* subroom) const
{
Point f(0., 0.);
//first the walls
const vector<Wall>& walls = subroom->GetAllWalls();
for (int i = 0; i < subroom->GetNumberOfWalls(); i++) {
f += ForceRepWall(ped, walls[i]);
for(const auto & wall: subroom->GetAllWalls())
{
f += ForceRepWall(ped, wall);
}
//then the obstacles
const vector<Obstacle*>& obstacles = subroom->GetAllObstacles();
for(unsigned int obs=0; obs<obstacles.size(); ++obs) {
const vector<Wall>&getAllWalls = obstacles[obs]->GetAllWalls();
for (unsigned int i = 0; i < getAllWalls.size(); i++) {
f += ForceRepWall(ped, getAllWalls[i]);
for(const auto & obst: subroom->GetAllObstacles())
{
for(const auto & wall: obst->GetAllWalls())
{
f += ForceRepWall(ped, wall);
}
}
// and finally the closed doors
const vector<Transition*>& transitions = subroom->GetAllTransitions();
for (unsigned int i = 0; i < transitions.size(); i++) {
Transition* goal=transitions[i];
for(auto & goal: subroom->GetAllTransitions())
{
if(! goal->IsOpen()) {
f += ForceRepWall(ped,*((Wall*)goal));
f += ForceRepWall(ped,*(static_cast<Line*>(goal)));
}
}
return f;
}
Point GompertzModel::ForceRepWall(Pedestrian* ped, const Wall& w) const
Point GompertzModel::ForceRepWall(Pedestrian* ped, const Line& w) const
{
#define DEBUG 0
Point F_wrep = Point(0.0, 0.0);
......
......@@ -97,7 +97,7 @@ private:
*
* @return Point
*/
Point ForceRepWall(Pedestrian* ped, const Wall& l) const;
Point ForceRepWall(Pedestrian* ped, const Line& l) const;
public:
......
......@@ -390,13 +390,16 @@ vector<Point> PedDistributor::PositionsOnFixX(double min_x, double max_x, double
while (y < max_y) {
Point pos = Point(x, y);
// Abstand zu allen Wänden prüfen
int k;
for (k = 0; k < r.GetNumberOfWalls(); k++) {
if (r.GetWall(k).DistTo(pos) < max(bufx, bufy) || !r.IsInSubRoom(pos)) {
bool ok=true;
for(auto&& w: r.GetAllWalls())
{
if (w.DistTo(pos) < max(bufx, bufy) || !r.IsInSubRoom(pos)) {
ok=false;
break; // Punkt ist zu nah an einer Wand oder nicht im Raum => ungültig
}
}
if (k == r.GetNumberOfWalls()) {
if (ok) {
//check all transitions
bool tooNear=false;
for(unsigned int t=0; t<r.GetAllTransitions().size(); t++) {
......@@ -432,13 +435,17 @@ vector<Point>PedDistributor::PositionsOnFixY(double min_x, double max_x, double
while (x < max_x) {
Point pos = Point(x, y);
// check distance to wall
int k;
for (k = 0; k < r.GetNumberOfWalls(); k++) {
if (r.GetWall(k).DistTo(pos) < max(bufx, bufy) || !r.IsInSubRoom(pos)) {
bool ok=true;
for(auto&& w: r.GetAllWalls())
{
if (w.DistTo(pos) < max(bufx, bufy) || !r.IsInSubRoom(pos)) {
ok=false;
break; // Punkt ist zu nah an einer Wand oder nicht im Raum => ungültig
}
}
if (k == r.GetNumberOfWalls()) {
if (ok) {
//check all transitions
bool tooNear=false;
for(unsigned int t=0; t<r.GetAllTransitions().size(); t++) {
......
......@@ -161,7 +161,7 @@ Point DirectionInRangeBottleneck::GetTarget(Room* room, Pedestrian* ped) const
//============================ WALLS ===========================
const vector<Wall>& walls = subroom->GetAllWalls();
for (int i = 0; i < subroom->GetNumberOfWalls(); i++) {
for (unsigned int i = 0; i < walls.size(); i++) {
dist = tmpDirection.GetIntersectionDistance(walls[i]);
if (dist < minDist) {
inear = i;
......
......@@ -939,10 +939,10 @@ bool MeshRouter::Init(Building* b)
meshfile>>tmp;
normvec[j]=tmp;
}
unsigned int countEdges=0;
meshfile>>countEdges;
unsigned int countEdges1=0;
meshfile>>countEdges1;
vector<int> edge_id;
for(unsigned int j=0; j<countEdges; j++) {
for(unsigned int j=0; j<countEdges1; j++) {
int tmp;
meshfile>>tmp;
edge_id.push_back(tmp);
......
......@@ -207,7 +207,7 @@ double QuickestPathRouter::TAP (double alpha)
}
int QuickestPathRouter::GetQuickestRoute(Pedestrian*ped, AccessPoint* nearestAP)
int QuickestPathRouter::GetQuickestRoute(Pedestrian*ped, AccessPoint* nearestAP __attribute__((unused)))
{
//int preferredExit=nearestAP->GetNearestTransitAPTO(ped->GetFinalDestination());
......
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