Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Set z-values for all network positions based on data from a height map
18 /****************************************************************************/
19 #ifndef NBHeightMapper_h
20 #define NBHeightMapper_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #ifdef _MSC_VER
29 typedef __int16 int16_t;
30 #else
31 #include <stdint.h>
32 #endif
33 
34 #include <string>
35 #include <foreign/rtree/RTree.h>
37 #include <utils/geom/Boundary.h>
39 
40 #define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class OptionsCont;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
59 
60  friend class NBHeightMapperTest;
61 
62 public:
68  static void loadIfSet(OptionsCont& oc);
69 
71  static const NBHeightMapper& get();
72 
74  bool ready() const;
75 
77  const Boundary& getBoundary() {
78  return Singleton.myBoundary;
79  }
80 
82  double getZ(const Position& geo) const;
83 
84  class QueryResult;
85  /* @brief content class for the rtree. Since we wish to be able to use the
86  * rtree for spatial querying we have to jump through some minor hoops:
87  * We let each found triangle callback the NBHeightMapper and add itself the
88  * the query result
89  * */
90  class Triangle {
91 
92  public:
93  Triangle(const PositionVector& corners);
94  ~Triangle() {};
95 
97  void addSelf(const QueryResult& queryResult) const;
98 
100  bool contains(const Position& pos) const;
101 
103  double getZ(const Position& geo) const;
104 
106  Position normalVector() const;
107 
110 
111  };
112 
113  typedef std::vector<const Triangle*> Triangles;
114 
116  class QueryResult {
117  public:
120  // @brief method not realy const
121  void add(Triangle* triangle) const {
122  triangles.push_back(triangle);
123  };
124  mutable Triangles triangles;
125  };
126 
127 private:
130 
132 
135 
137  std::vector<std::pair<Boundary, int16_t*> > myRasters;
138 
141 
144 
145 private:
147  NBHeightMapper();
148  ~NBHeightMapper();
149 
151  void addTriangle(PositionVector corners);
152 
157  int loadShapeFile(const std::string& file);
158 
163  int loadTiff(const std::string& file);
164 
166  void clearData();
167 
170 
173 
174 };
175 
176 
177 // ===========================================================================
178 // RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
179 // ===========================================================================
180 template<>
181 inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
182  ASSERT(a_rect);
183  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
184  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
185  return .78539816f * (extent0 * extent0 + extent1 * extent1);
186 }
187 
188 template<>
189 inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
190  ASSERT(a_rectA && a_rectB);
191  Rect newRect;
192  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
193  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
194  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
195  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
196  return newRect;
197 }
198 
199 
200 #endif
201 
202 /****************************************************************************/
203 
Boundary.h
NBHeightMapper::Triangle::contains
bool contains(const Position &pos) const
checks whether pos lies within triangle (only checks x,y)
Definition: NBHeightMapper.cpp:364
NBHeightMapper::myRTree
TRIANGLE_RTREE_QUAL myRTree
The RTree for spatial queries.
Definition: NBHeightMapper.h:134
NBHeightMapper::get
static const NBHeightMapper & get()
return the singleton instance (maybe 0)
Definition: NBHeightMapper.cpp:70
NBHeightMapper
Set z-values for all network positions based on data from a height map.
Definition: NBHeightMapper.h:58
NBHeightMapper::Triangle::addSelf
void addSelf(const QueryResult &queryResult) const
callback for RTree search
Definition: NBHeightMapper.cpp:358
NBHeightMapper::ready
bool ready() const
returns whether the NBHeightMapper has data
Definition: NBHeightMapper.cpp:76
NBHeightMapper::operator=
NBHeightMapper & operator=(const NBHeightMapper &)
Invalidated assignment operator.
NBHeightMapper::myBoundary
Boundary myBoundary
convex boundary of all known triangles;
Definition: NBHeightMapper.h:143
NBHeightMapper::loadTiff
int loadTiff(const std::string &file)
load height data from GeoTIFF file and returns the number of non void pixels
Definition: NBHeightMapper.cpp:276
NBHeightMapper::Triangle::myCorners
PositionVector myCorners
the corners of the triangle
Definition: NBHeightMapper.h:109
PositionVector
A list of positions.
Definition: PositionVector.h:46
NBHeightMapper::QueryResult::~QueryResult
~QueryResult()
Definition: NBHeightMapper.h:119
NBHeightMapper::mySizeOfPixel
Position mySizeOfPixel
dimensions of one pixel in raster data
Definition: NBHeightMapper.h:140
rtree_min
#define rtree_min(a, b)
Definition: RTree.h:20
RTree.h
NBHeightMapper::Triangle::~Triangle
~Triangle()
Definition: NBHeightMapper.h:94
NBHeightMapper::Triangle::normalVector
Position normalVector() const
returns the normal vector for this triangles plane
Definition: NBHeightMapper.cpp:381
NBHeightMapper::Triangle::getZ
double getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
Definition: NBHeightMapper.cpp:370
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
UtilExceptions.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
NBHeightMapper::QueryResult::add
void add(Triangle *triangle) const
Definition: NBHeightMapper.h:121
rtree_max
#define rtree_max(a, b)
Definition: RTree.h:21
NBHeightMapper::NBHeightMapper
NBHeightMapper()
private constructor and destructor (Singleton)
Definition: NBHeightMapper.cpp:59
ASSERT
#define ASSERT
Definition: RTree.h:12
NBHeightMapper::Singleton
static NBHeightMapper Singleton
the singleton instance
Definition: NBHeightMapper.h:129
NBHeightMapper::QueryResult::triangles
Triangles triangles
Definition: NBHeightMapper.h:123
NBHeightMapper::QueryResult
class for cirumventing the const-restriction of RTree::Search-context
Definition: NBHeightMapper.h:116
NBHeightMapper::addTriangle
void addTriangle(PositionVector corners)
adds one triangles worth of height data
Definition: NBHeightMapper.cpp:138
NBHeightMapper::myRasters
std::vector< std::pair< Boundary, int16_t * > > myRasters
raster height information in m for all loaded files
Definition: NBHeightMapper.h:137
TRIANGLE_RTREE_QUAL
#define TRIANGLE_RTREE_QUAL
Definition: NBHeightMapper.h:40
NBHeightMapper::~NBHeightMapper
~NBHeightMapper()
Definition: NBHeightMapper.cpp:64
NBHeightMapper::loadShapeFile
int loadShapeFile(const std::string &file)
load height data from Arcgis-shape file and returns the number of parsed features
Definition: NBHeightMapper.cpp:176
NBHeightMapper::NBHeightMapperTest
friend class NBHeightMapperTest
Definition: NBHeightMapper.h:60
config.h
NBHeightMapper::Triangle
Definition: NBHeightMapper.h:90
NBHeightMapper::loadIfSet
static void loadIfSet(OptionsCont &oc)
loads heigh map data if any loading options are set
Definition: NBHeightMapper.cpp:149
NBHeightMapper::Triangle::Triangle
Triangle(const PositionVector &corners)
Definition: NBHeightMapper.cpp:350
NBHeightMapper::getZ
double getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
Definition: NBHeightMapper.cpp:82
PositionVector.h
NBHeightMapper::myTriangles
Triangles myTriangles
Definition: NBHeightMapper.h:131
NBHeightMapper::getBoundary
const Boundary & getBoundary()
returns the convex boundary of all known triangles
Definition: NBHeightMapper.h:77
NBHeightMapper::QueryResult::QueryResult
QueryResult()
Definition: NBHeightMapper.h:118
NBHeightMapper::clearData
void clearData()
clears loaded data
Definition: NBHeightMapper.cpp:332
NBHeightMapper::Triangles
std::vector< const Triangle * > Triangles
Definition: NBHeightMapper.h:113