SUMO - Simulation of Urban MObility
NBHeightMapper.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2011-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Set z-values for all network positions based on data from a height map
20 /****************************************************************************/
21 #ifndef NBHeightMapper_h
22 #define NBHeightMapper_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #ifdef _MSC_VER
35 typedef __int16 int16_t;
36 #else
37 #include <stdint.h>
38 #endif
39 
40 #include <string>
41 #include <foreign/rtree/RTree.h>
43 #include <utils/geom/Boundary.h>
45 
46 #define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
47 
48 // ===========================================================================
49 // class declarations
50 // ===========================================================================
51 class OptionsCont;
52 
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
65 
66  friend class NBHeightMapperTest;
67 
68 public:
74  static void loadIfSet(OptionsCont& oc);
75 
77  static const NBHeightMapper& get();
78 
80  bool ready() const;
81 
83  const Boundary& getBoundary() {
84  return Singleton.myBoundary;
85  }
86 
88  double getZ(const Position& geo) const;
89 
90  class QueryResult;
91  /* @brief content class for the rtree. Since we wish to be able to use the
92  * rtree for spatial querying we have to jump through some minor hoops:
93  * We let each found triangle callback the NBHeightMapper and add itself the
94  * the query result
95  * */
96  class Triangle {
97 
98  public:
99  Triangle(const PositionVector& corners);
100  ~Triangle() {};
101 
103  void addSelf(const QueryResult& queryResult) const;
104 
106  bool contains(const Position& pos) const;
107 
109  double getZ(const Position& geo) const;
110 
112  Position normalVector() const;
113 
116 
117  };
118 
119  typedef std::vector<const Triangle*> Triangles;
120 
122  class QueryResult {
123  public:
126  // @brief method not realy const
127  void add(Triangle* triangle) const {
128  triangles.push_back(triangle);
129  };
130  mutable Triangles triangles;
131  };
132 
133 private:
136 
137  Triangles myTriangles;
138 
141 
143  int16_t* myRaster;
144 
147 
150 
151 private:
153  NBHeightMapper();
154  ~NBHeightMapper();
155 
157  void addTriangle(PositionVector corners);
158 
163  int loadShapeFile(const std::string& file);
164 
169  int loadTiff(const std::string& file);
170 
172  void clearData();
173 
176 
179 
180 };
181 
182 
183 // ===========================================================================
184 // RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
185 // ===========================================================================
186 template<>
187 inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
188  ASSERT(a_rect);
189  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
190  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
191  return .78539816f * (extent0 * extent0 + extent1 * extent1);
192 }
193 
194 template<>
195 inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
196  ASSERT(a_rectA && a_rectB);
197  Rect newRect;
198  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
199  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
200  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
201  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
202  return newRect;
203 }
204 
205 
206 #endif
207 
208 /****************************************************************************/
209 
Triangles myTriangles
int loadShapeFile(const std::string &file)
load height data from Arcgis-shape file and returns the number of parsed features ...
Position normalVector() const
returns the normal vector for this triangles plane
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:47
int loadTiff(const std::string &file)
load height data from GeoTIFF file and returns the number of non void pixels
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.
void addSelf(const QueryResult &queryResult) const
callback for RTree search
#define ASSERT
Definition: RTree.h:12
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
#define rtree_min(a, b)
Definition: RTree.h:20
void add(Triangle *triangle) const
A list of positions.
bool contains(const Position &pos) const
checks whether pos lies within triangle (only checks x,y)
std::vector< const Triangle * > Triangles
int16_t * myRaster
raster height information in m
#define rtree_max(a, b)
Definition: RTree.h:21
Position mySizeOfPixel
dimensions of one pixel in raster data
Boundary myBoundary
convex boundary of all known triangles;
NBHeightMapper & operator=(const NBHeightMapper &)
Invalidated assignment operator.
PositionVector myCorners
the corners of the triangle
A storage for options typed value containers)
Definition: OptionsCont.h:98
double getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
double getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
const Boundary & getBoundary()
returns the convex boundary of all known triangles
bool ready() const
returns whether the NBHeightMapper has data
Set z-values for all network positions based on data from a height map.