Obstacle.h 3.42 KB
Newer Older
1
/**
2 3
 * \file        Obstacle.h
 * \date        Jul 31, 2012
4 5
 * \version     v0.7
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
6
 *
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12 13 14 15 16 17 18 19
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21 22
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
23
 * \section Description
24 25
 *
 *
26 27
 **/

28 29 30 31

#ifndef OBSTACLE_H_
#define OBSTACLE_H_

32 33
#include <string>
#include <vector>
34

Ulrich Kemloh's avatar
Ulrich Kemloh committed
35 36 37 38
//forward declarations
class Point;
class Wall;
class Line;
39 40 41

class Obstacle {

42 43 44 45 46 47 48 49
private:
     double _height;
     int _id;
     std::string _caption;
     std::vector<Wall> _walls;
     std::vector<Point> _poly;

public:
50 51 52
     /**
      * Constructor
      */
53
     Obstacle();
54 55 56 57

     /**
      * Destructor
      */
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
     virtual ~Obstacle();

     /**
      * Set/Get the obstacles' caption
      */
     std::string GetCaption() const;

     /**
      * Set/Get the obstacles' caption
      */
     void SetCaption(std::string caption);

     /**
      * Set/Get the height of the obstacle.
      * Is used for computing visibility
      */
     double GetHeight() const;

     /**
      * Set/Get the height of the obstacle.
      * Is used for computing visibility
      */
     void SetHeight(double height);

     /**
      * Set/Get the id of the obstacle
      */
     int GetId() const;

     /**
      * Set/Get the id of the obstacle
      */
     void SetId(int id);

     /**
      * construct the obstacle by adding more walls
      */
     void AddWall(const Wall& w);

     /**
      * @return All walls that constitute the obstacle
      */
     const std::vector<Wall>& GetAllWalls() const;

     /**
      * @return true if the point p is contained within the Closed Obstacle
      * @see Setclose
      */
     bool Contains(const Point& p) const;

     /**
      * Create the obstacles polygonal structure from the walls
      */
111
     bool ConvertLineToPoly();
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

     /**
      * @return the obstacle as a polygon
      */
     const std::vector<Point>&  GetPolygon() const;

     /**
      * @return the centroid of the obstacle
      */
     const Point GetCentroid() const;

     /**
      * return true if the given line intersects
      * or share common vertex with the obstacle
      */
     bool IntersectWithLine(const Line & line) const;

     /**
      * @return a nicely formatted string representation of the obstacle
      */
     std::string Write();

134 135 136 137 138
     /**
      * @return true if the polygon is clockwise oriented
      */
     bool IsClockwise() const;

139 140 141 142 143
     /**
      * @return true if the point is part of the polygon, also considering the geometry precision.
      */
     bool IsPartOfPolygon(const Point& ptw);

144 145 146 147 148 149
private:
     int WhichQuad(const Point& vertex, const Point& hitPos) const;

     // x-Koordinate der Linie von einer Eccke zur nächsten
     double Xintercept(const Point& point1, const Point& point2,
                       double hitY) const;
150

151 152 153
};

#endif /* OBSTACLE_H_ */