Building.h 6.63 KB
Newer Older
1
/**
2 3
 * \file        Building.h
 * \date        Oct 1, 2010
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

#ifndef _BUILDING_H
30
#define _BUILDING_H
31 32 33 34 35 36

#include <string>
#include <vector>
#include <fstream>
#include <cfloat>
#include <map>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
37
#include <memory>
38 39 40 41 42 43 44

#include "Room.h"
#include "NavLine.h"
#include "Transition.h"
#include "Hline.h"
#include "Obstacle.h"
#include "Goal.h"
45
#include "../tinyxml/tinyxml.h"
46 47 48 49 50 51

// train schedules: Trains get deleted and added.




52 53 54 55
class RoutingEngine;
class Pedestrian;
class Transition;
class LCGrid;
56
class ForceModel;
57
class PedDistributor;
58

59 60
class Building
{
61
private:
62 63 64 65 66 67 68 69
     std::string _caption;
     std::string _projectFilename;
     std::string _projectRootDir;
     std::string _geometryFilename;
     RoutingEngine* _routingEngine;
     LCGrid* _linkedCellGrid;
     std::vector<Pedestrian*> _allPedestians;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
70
     std::map<int, std::unique_ptr<Room> > _rooms;
71 72 73 74 75
     std::map<int, Crossing*> _crossings;
     std::map<int, Transition*> _transitions;
     std::map<int, Hline*> _hLines;
     std::map<int, Goal*>_goals;

76 77


78 79 80
     /// pedestrians pathway
     bool _savePathway;
     std::ofstream _pathWayStream;
81 82

public:
83 84
     /// constructor
     Building();
85
     Building(const std::string&, const std::string&, RoutingEngine&, PedDistributor&, double);
86 87 88 89 90 91 92 93 94 95
     /// destructor
     virtual ~Building();

     void SetCaption(const std::string& s);
     void SetRoutingEngine(RoutingEngine* r);

     /// delete the ped from the ped vector
     void DeletePedestrian(Pedestrian* &ped);
     /// delete the ped from the simulation
     void AddPedestrian(Pedestrian* ped);
96
     void GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds) const;
97 98 99

     std::string GetCaption() const;
     RoutingEngine* GetRoutingEngine() const;
100
     const std::map<int, std::unique_ptr<Room> >& GetAllRooms() const;
101 102 103 104 105 106 107 108 109
     const std::vector<Pedestrian*>& GetAllPedestrians() const;
     Pedestrian* GetPedestrian( int pedID) const;
     int GetNumberOfRooms() const;
     int GetNumberOfGoals()const;
     Room* GetRoom(int index) const;
     Room* GetRoom(std::string caption)const;

     Transition* GetTransition(std::string caption) const;
     Transition* GetTransition(int id) ;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
110
     Transition* ParseTransitionNode(TiXmlElement * xTrans);
111

112 113 114



115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
     /**
      * Not implemented
      */
     Crossing* GetCrossing(int id);

     /**
      * Not implemented
      */
     Hline* GetHline(int id);

     /**
      * return the subroom with the corresponding unique identifier
      * @param uid ,the unique identifier
      * @return NULL if no exists with that identifier.
      */
     SubRoom* GetSubRoomByUID( int uid);

     /**
      * @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, can can be considered transparent
      */
137
     //bool IsVisible(Line* l1, Line* l2, bool considerHlines=false);
138 139 140 141 142 143

     /**
      * @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
      */
144
     bool IsVisible(const Point& p1, const Point& p2, const std::vector<SubRoom*>& subrooms, bool considerHlines=false);
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

     /**
      * @return a crossing or a transition matching the given caption.
      * Return NULL if none is found
      */
     Crossing* GetTransOrCrossByName(std::string caption) const;

     /**
      * @return a crossing or a transition or a hline matching the given uid.
      * Return NULL if none is found
      */
     Hline* GetTransOrCrossByUID(int uid) const;

     /**
      * @return the transition matching the uid
      */
     Transition* GetTransitionByUID(int uid) const;

     //TOD0: rename later to GetGoal
     Goal* GetFinalGoal(int id);

     /**
      * @return the linked-cell grid used for spatial query
      */
     LCGrid* GetGrid() const;

     // convenience methods
     bool InitGeometry();
     void InitGrid(double cellSize);
     //void InitRoomsAndSubroomsMap();
     void InitSavePedPathway(const std::string &filename);
     void AddRoom(Room* room);
     void UpdateGrid();
     void AddSurroundingRoom(); // add a final room (outside or world), that encompasses the complete geometry

     const std::map<int, Crossing*>& GetAllCrossings() const;
     const std::map<int, Transition*>& GetAllTransitions() const;
     const std::map<int, Hline*>& GetAllHlines() const;
     const std::map<int, Goal*>& GetAllGoals() const;

185
     bool AddCrossing(Crossing* line);
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
     void AddTransition(Transition* line);
     void AddHline(Hline* line);
     void AddGoal(Goal* goal);

     const std::string& GetProjectRootDir() const;
     const std::string& GetProjectFilename() const;
     const std::string& GetGeometryFilename() const;
     void SetProjectFilename(const std::string &filename) ;
     void SetProjectRootDir(const std::string &filename);

     /**
      * Load and parse the geometry file into the building object.
      * If no geometry file is provided, one is searched in the the project file
      *
      * @param filename, the geometry file
      */
     bool LoadGeometry(const std::string &geometryfile="");

     /**
      * Write the geometry to the given file.
      * That will be useful in the geometry editor.
      * @param filename the relative location of the file
      * @return true if everything went fine.
      */
     bool SaveGeometry(const std::string &filename);

     bool LoadTrafficInfo();
     bool LoadRoutingInfo(const std::string &filename);
     void WriteToErrorLog() const;

     /**
      * Check the scenario for possible errors and
      * output user specific informations.
      */
     bool SanityCheck();
221 222 223


private:
224
     void StringExplode(std::string str, std::string separator, std::vector<std::string>* results);
225 226 227

};

228
#endif  /* _BUILDING_H */