SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBHeightMapper.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Set z-values for all network positions based on data from a height map
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2011-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NBHeightMapper_h
23 #define NBHeightMapper_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <foreign/rtree/RTree.h>
38 #include <utils/geom/Boundary.h>
40 
41 #define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class OptionsCont;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
60 
61  friend class NBHeightMapperTest;
62 
63 public:
69  static void loadIfSet(OptionsCont& oc);
70 
72  static const NBHeightMapper& get();
73 
75  bool ready() const;
76 
78  const Boundary& getBoundary() {
79  return Singleton.myBoundary;
80  }
81 
83  SUMOReal getZ(const Position& geo) const;
84 
85  class QueryResult;
86  /* @brief content class for the rtree. Since we wish to be able to use the
87  * rtree for spatial querying we have to jump through some minor hoops:
88  * We let each found triangle callback the NBHeightMapper and add itself the
89  * the query result
90  * */
91  class Triangle {
92 
93  public:
94  Triangle(const PositionVector& corners);
95  ~Triangle() {};
96 
98  void addSelf(const QueryResult& queryResult) const;
99 
101  bool contains(const Position& pos) const;
102 
104  SUMOReal getZ(const Position& geo) const;
105 
107  Position normalVector() const;
108 
111 
112  };
113 
114  typedef std::vector<const Triangle*> Triangles;
115 
117  class QueryResult {
118  public:
121  // @brief method not realy const
122  void add(Triangle* triangle) const {
123  triangles.push_back(triangle);
124  };
125  mutable Triangles triangles;
126  };
127 
128 private:
131 
133 
136 
139 
140 private:
142  NBHeightMapper();
143  ~NBHeightMapper();
144 
146  void addTriangle(PositionVector corners);
147 
152  int loadShapeFile(const std::string& file);
153 
155  void clearData();
156 
159 
162 
163 };
164 
165 
166 // ===========================================================================
167 // RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
168 // ===========================================================================
169 template<>
170 inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
171  ASSERT(a_rect);
172  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
173  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
174  return .78539816f * (extent0 * extent0 + extent1 * extent1);
175 }
176 
177 template<>
178 inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
179  ASSERT(a_rectA && a_rectB);
180  Rect newRect;
181  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
182  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
183  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
184  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
185  return newRect;
186 }
187 
188 
189 #endif
190 
191 /****************************************************************************/
192 
SUMOReal getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
Triangles myTriangles
bool ready() const
returns whether the NBHeightMapper has data
Position normalVector() const
returns the normal vector for this triangles plane
int loadShapeFile(const std::string &file)
load height data from Arcgis-shape file and returns the number of
SUMOReal getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
Triangle(const PositionVector &corners)
void addTriangle(PositionVector corners)
adds one triangles worth of height data
void clearData()
clears loaded data
static NBHeightMapper Singleton
the singleton instance
NBHeightMapper()
private constructor and destructor (Singleton)
#define TRIANGLE_RTREE_QUAL
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
friend class NBHeightMapperTest
class for cirumventing the const-restriction of RTree::Search-context
static void loadIfSet(OptionsCont &oc)
loads heigh map data if any loading options are set
TRIANGLE_RTREE_QUAL myRTree
The RTree for spatial queries.
#define ASSERT
Definition: RTree.h:12
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
#define rtree_min(a, b)
Definition: RTree.h:20
A list of positions.
std::vector< const Triangle * > Triangles
bool contains(const Position &pos) const
checks whether pos lies within triangle (only checks x,y)
#define rtree_max(a, b)
Definition: RTree.h:21
Boundary myBoundary
convex boundary of all known triangles;
Definition: Test.cpp:10
void add(Triangle *triangle) const
NBHeightMapper & operator=(const NBHeightMapper &)
Invalidated assignment operator.
PositionVector myCorners
the corners of the triangle
A storage for options typed value containers)
Definition: OptionsCont.h:108
void addSelf(const QueryResult &queryResult) const
callback for RTree search
#define SUMOReal
Definition: config.h:218
const Boundary & getBoundary()
returns the convex boundary of all known triangles
Set z-values for all network positions based on data from a height map.