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

checking if all walls were used when converting obstacles

parent 3eef4613
......@@ -39,8 +39,17 @@
#include <cmath>
#include <vector>
OutputHandler* Log;
BOOST_AUTO_TEST_SUITE(ObstacleTest)
struct Handler {
Handler() {Log = new STDIOHandler();}
~ Handler() {delete Log;}
};
BOOST_GLOBAL_FIXTURE(Handler)
BOOST_AUTO_TEST_CASE(Obstacle_Constr_setGet_Test)
{
BOOST_MESSAGE("starting obstacle_Constr_setGet_Test");
......
......@@ -46,7 +46,6 @@ using namespace std;
Obstacle::Obstacle()
{
_isClosed=0;
_height=0.0;
_id=-1;
_caption="obstacle";
......@@ -100,7 +99,6 @@ const vector<Point>& Obstacle::GetPolygon() const
string Obstacle::Write()
{
string s;
//Point pos;
for (unsigned int j = 0; j < _walls.size(); j++) {
const Wall& w = _walls[j];
......@@ -130,8 +128,30 @@ const vector<Wall>& Obstacle::GetAllWalls() const
int Obstacle::WhichQuad(const Point& vertex, const Point& hitPos) const
{
return (vertex.GetX() > hitPos.GetX()) ? ((vertex.GetY() > hitPos.GetY()) ? 1 : 4) :
((vertex.GetY() > hitPos.GetY()) ? 2 : 3);
return (vertex.GetX() > hitPos.GetX()) ?
((vertex.GetY() > hitPos.GetY()) ? 1 : 4) :
((vertex.GetY() > hitPos.GetY()) ? 2 : 3);
// if ((vertex.GetX() - hitPos.GetX())>J_EPS)
// {
// if ((vertex.GetY() - hitPos.GetY())>J_EPS)
// {
// return 1;
// } else
// {
// return 4;
// }
// } else
// {
// if ((vertex.GetY() - hitPos.GetY())>J_EPS)
// {
// return 2;
// } else
// {
// return 3;
// }
//
// }
}
......@@ -148,12 +168,6 @@ bool Obstacle::Contains(const Point& ped) const
// in the case the obstacle is not a close surface, allow
// pedestrians distribution 'inside'
if(_isClosed==0.0) {
char tmp[CLENGTH];
sprintf(tmp, "ERROR: \tObstacle::Contains(): the obstacle [%d] is open!!!\n", _id);
Log->Write(tmp);
exit(EXIT_FAILURE);
}
short edge, first, next;
short quad, next_quad, delta, total;
......@@ -199,23 +213,17 @@ bool Obstacle::Contains(const Point& ped) const
return false;
}
bool Obstacle::ConvertLineToPoly()
{
if(_isClosed==0)
{
char tmp[CLENGTH];
sprintf(tmp, "INFO: \tObstacle [%d] is not closed. Not converting to polyline.\n", _id);
Log->Write(tmp);
return true;
}
vector<Line*> copy;
vector<Point> tmpPoly;
Point point;
Line* line;
// Alle Linienelemente in copy speichern
for (unsigned int i = 0; i < _walls.size(); i++) {
copy.push_back(&_walls[i]);
for(auto& w: _walls)
{
copy.push_back(&w);
}
line = copy[0];
......@@ -243,9 +251,25 @@ bool Obstacle::ConvertLineToPoly()
char tmp[CLENGTH];
sprintf(tmp, "ERROR: \tObstacle::ConvertLineToPoly(): ID %d !!!\n", _id);
Log->Write(tmp);
sprintf(tmp, "ERROR: \tDistance between the points: %lf !!!\n", (tmpPoly[0] - point).Norm());
Log->Write(tmp);
return false;
}
_poly = tmpPoly;
//check if all walls and goals were used in the polygon
for (const auto& w: _walls)
{
for (const auto & ptw: {w.GetPoint1(),w.GetPoint2()})
{
if(IsPartOfPolygon(ptw)==false)
{
Log->Write("ERROR:\t Edge was not used during polygon creation for obstacle: %s",w.toString().c_str());
return false;
}
}
}
return true;
}
......@@ -317,3 +341,27 @@ bool Obstacle::IntersectWithLine(const Line& line) const
return false;
}
bool Obstacle::IsPartOfPolygon(const Point& ptw)
{
if ( false == IsElementInVector(_poly, ptw))
{
//maybe the point was too closed to other points and got replaced
//check that eventuality
bool near = false;
for (const auto & pt : _poly)
{
if ((pt - ptw).Norm() < J_TOLERANZ)
{
near = true;
break;
}
}
if(near==false)
{
return false;
}
}
return true;
}
......@@ -40,7 +40,6 @@ class Line;
class Obstacle {
private:
int _isClosed;
double _height;
int _id;
std::string _caption;
......@@ -137,6 +136,11 @@ public:
*/
bool IsClockwise() const;
/**
* @return true if the point is part of the polygon, also considering the geometry precision.
*/
bool IsPartOfPolygon(const Point& ptw);
private:
int WhichQuad(const Point& vertex, const Point& hitPos) const;
......
......@@ -872,7 +872,7 @@ bool NormalSubRoom::ConvertLineToPoly(const vector<Line*>& goals)
// private Funktionen
// gibt zuruck in welchen Quadranten vertex liegt, wobei hitPos der Koordinatenursprung ist
// gibt zurück in welchen Quadranten vertex liegt, wobei hitPos der Koordinatenursprung ist
int NormalSubRoom::WhichQuad(const Point& vertex, const Point& hitPos) const
{
......
......@@ -249,7 +249,6 @@ public:
const Hline* GetHline(int i) const;
/**
*
* @return true if the point is part of the polygon, also considering the geometry precision.
*/
bool IsPartOfPolygon(const Point& pt);
......
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