SUMO - Simulation of Urban MObility
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-2016 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 #ifdef _MSC_VER
36 typedef __int16 int16_t;
37 #else
38 #include <stdint.h>
39 #endif
40 
41 #include <string>
42 #include <foreign/rtree/RTree.h>
44 #include <utils/geom/Boundary.h>
46 
47 #define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class OptionsCont;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
66 
67  friend class NBHeightMapperTest;
68 
69 public:
75  static void loadIfSet(OptionsCont& oc);
76 
78  static const NBHeightMapper& get();
79 
81  bool ready() const;
82 
84  const Boundary& getBoundary() {
85  return Singleton.myBoundary;
86  }
87 
89  SUMOReal getZ(const Position& geo) const;
90 
91  class QueryResult;
92  /* @brief content class for the rtree. Since we wish to be able to use the
93  * rtree for spatial querying we have to jump through some minor hoops:
94  * We let each found triangle callback the NBHeightMapper and add itself the
95  * the query result
96  * */
97  class Triangle {
98 
99  public:
100  Triangle(const PositionVector& corners);
101  ~Triangle() {};
102 
104  void addSelf(const QueryResult& queryResult) const;
105 
107  bool contains(const Position& pos) const;
108 
110  SUMOReal getZ(const Position& geo) const;
111 
113  Position normalVector() const;
114 
117 
118  };
119 
120  typedef std::vector<const Triangle*> Triangles;
121 
123  class QueryResult {
124  public:
127  // @brief method not realy const
128  void add(Triangle* triangle) const {
129  triangles.push_back(triangle);
130  };
131  mutable Triangles triangles;
132  };
133 
134 private:
137 
138  Triangles myTriangles;
139 
142 
144  int16_t* myRaster;
145 
148 
151 
152 private:
154  NBHeightMapper();
155  ~NBHeightMapper();
156 
158  void addTriangle(PositionVector corners);
159 
164  int loadShapeFile(const std::string& file);
165 
170  int loadTiff(const std::string& file);
171 
173  void clearData();
174 
177 
180 
181 };
182 
183 
184 // ===========================================================================
185 // RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
186 // ===========================================================================
187 template<>
188 inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
189  ASSERT(a_rect);
190  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
191  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
192  return .78539816f * (extent0 * extent0 + extent1 * extent1);
193 }
194 
195 template<>
196 inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
197  ASSERT(a_rectA && a_rectB);
198  Rect newRect;
199  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
200  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
201  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
202  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
203  return newRect;
204 }
205 
206 
207 #endif
208 
209 /****************************************************************************/
210 
SUMOReal getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
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:48
int loadTiff(const std::string &file)
load height data from GeoTIFF file and returns the number of non void pixels
friend class NBHeightMapperTest
SUMOReal getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
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:46
#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:99
#define SUMOReal
Definition: config.h:213
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.