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 /****************************************************************************/
16 // Set z-values for all network positions based on data from a height map
17 /****************************************************************************/
18 #ifndef NBHeightMapper_h
19 #define NBHeightMapper_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #ifdef _MSC_VER
28 typedef __int16 int16_t;
29 #else
30 #include <stdint.h>
31 #endif
32 
33 #include <string>
34 #include <foreign/rtree/RTree.h>
36 #include <utils/geom/Boundary.h>
38 
39 #define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class OptionsCont;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
58 
59  friend class NBHeightMapperTest;
60 
61 public:
67  static void loadIfSet(OptionsCont& oc);
68 
70  static const NBHeightMapper& get();
71 
73  bool ready() const;
74 
76  const Boundary& getBoundary() {
77  return Singleton.myBoundary;
78  }
79 
81  double getZ(const Position& geo) const;
82 
83  class QueryResult;
84  /* @brief content class for the rtree. Since we wish to be able to use the
85  * rtree for spatial querying we have to jump through some minor hoops:
86  * We let each found triangle callback the NBHeightMapper and add itself the
87  * the query result
88  * */
89  class Triangle {
90 
91  public:
92  Triangle(const PositionVector& corners);
93  ~Triangle() {};
94 
96  void addSelf(const QueryResult& queryResult) const;
97 
99  bool contains(const Position& pos) const;
100 
102  double getZ(const Position& geo) const;
103 
105  Position normalVector() const;
106 
109 
110  };
111 
112  typedef std::vector<const Triangle*> Triangles;
113 
115  class QueryResult {
116  public:
119  // @brief method not realy const
120  void add(Triangle* triangle) const {
121  triangles.push_back(triangle);
122  };
124  };
125 
126 private:
129 
131 
134 
136  std::vector<std::pair<Boundary, int16_t*> > myRasters;
137 
140 
143 
144 private:
146  NBHeightMapper();
147  ~NBHeightMapper();
148 
150  void addTriangle(PositionVector corners);
151 
156  int loadShapeFile(const std::string& file);
157 
162  int loadTiff(const std::string& file);
163 
165  void clearData();
166 
169 
172 
173 };
174 
175 
176 // ===========================================================================
177 // RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
178 // ===========================================================================
179 template<>
180 inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
181  ASSERT(a_rect);
182  const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
183  const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
184  return .78539816f * (extent0 * extent0 + extent1 * extent1);
185 }
186 
187 template<>
188 inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
189  ASSERT(a_rectA && a_rectB);
190  Rect newRect;
191  newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
192  newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
193  newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
194  newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
195  return newRect;
196 }
197 
198 
199 #endif
200 
201 /****************************************************************************/
202 
Boundary.h
NBHeightMapper::Triangle::contains
bool contains(const Position &pos) const
checks whether pos lies within triangle (only checks x,y)
Definition: NBHeightMapper.cpp:363
NBHeightMapper::myRTree
TRIANGLE_RTREE_QUAL myRTree
The RTree for spatial queries.
Definition: NBHeightMapper.h:133
NBHeightMapper::get
static const NBHeightMapper & get()
return the singleton instance (maybe 0)
Definition: NBHeightMapper.cpp:69
NBHeightMapper
Set z-values for all network positions based on data from a height map.
Definition: NBHeightMapper.h:57
NBHeightMapper::Triangle::addSelf
void addSelf(const QueryResult &queryResult) const
callback for RTree search
Definition: NBHeightMapper.cpp:357
NBHeightMapper::ready
bool ready() const
returns whether the NBHeightMapper has data
Definition: NBHeightMapper.cpp:75
NBHeightMapper::operator=
NBHeightMapper & operator=(const NBHeightMapper &)
Invalidated assignment operator.
NBHeightMapper::myBoundary
Boundary myBoundary
convex boundary of all known triangles;
Definition: NBHeightMapper.h:142
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:275
NBHeightMapper::Triangle::myCorners
PositionVector myCorners
the corners of the triangle
Definition: NBHeightMapper.h:108
PositionVector
A list of positions.
Definition: PositionVector.h:45
NBHeightMapper::QueryResult::~QueryResult
~QueryResult()
Definition: NBHeightMapper.h:118
NBHeightMapper::mySizeOfPixel
Position mySizeOfPixel
dimensions of one pixel in raster data
Definition: NBHeightMapper.h:139
rtree_min
#define rtree_min(a, b)
Definition: RTree.h:20
RTree.h
NBHeightMapper::Triangle::~Triangle
~Triangle()
Definition: NBHeightMapper.h:93
NBHeightMapper::Triangle::normalVector
Position normalVector() const
returns the normal vector for this triangles plane
Definition: NBHeightMapper.cpp:380
NBHeightMapper::Triangle::getZ
double getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
Definition: NBHeightMapper.cpp:369
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
NBHeightMapper::NBHeightMapper
NBHeightMapper(const NBHeightMapper &)
Invalidated copy constructor.
UtilExceptions.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NBHeightMapper::QueryResult::add
void add(Triangle *triangle) const
Definition: NBHeightMapper.h:120
rtree_max
#define rtree_max(a, b)
Definition: RTree.h:21
NBHeightMapper::NBHeightMapper
NBHeightMapper()
private constructor and destructor (Singleton)
Definition: NBHeightMapper.cpp:58
ASSERT
#define ASSERT
Definition: RTree.h:12
NBHeightMapper::Singleton
static NBHeightMapper Singleton
the singleton instance
Definition: NBHeightMapper.h:128
NBHeightMapper::QueryResult::triangles
Triangles triangles
Definition: NBHeightMapper.h:122
NBHeightMapper::QueryResult
class for cirumventing the const-restriction of RTree::Search-context
Definition: NBHeightMapper.h:115
NBHeightMapper::addTriangle
void addTriangle(PositionVector corners)
adds one triangles worth of height data
Definition: NBHeightMapper.cpp:137
NBHeightMapper::myRasters
std::vector< std::pair< Boundary, int16_t * > > myRasters
raster height information in m for all loaded files
Definition: NBHeightMapper.h:136
TRIANGLE_RTREE_QUAL
#define TRIANGLE_RTREE_QUAL
Definition: NBHeightMapper.h:39
NBHeightMapper::~NBHeightMapper
~NBHeightMapper()
Definition: NBHeightMapper.cpp:63
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:175
NBHeightMapper::NBHeightMapperTest
friend class NBHeightMapperTest
Definition: NBHeightMapper.h:59
config.h
NBHeightMapper::Triangle
Definition: NBHeightMapper.h:89
NBHeightMapper::loadIfSet
static void loadIfSet(OptionsCont &oc)
loads heigh map data if any loading options are set
Definition: NBHeightMapper.cpp:148
NBHeightMapper::Triangle::Triangle
Triangle(const PositionVector &corners)
Definition: NBHeightMapper.cpp:349
NBHeightMapper::getZ
double getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
Definition: NBHeightMapper.cpp:81
PositionVector.h
NBHeightMapper::myTriangles
Triangles myTriangles
Definition: NBHeightMapper.h:130
NBHeightMapper::getBoundary
const Boundary & getBoundary()
returns the convex boundary of all known triangles
Definition: NBHeightMapper.h:76
NBHeightMapper::QueryResult::QueryResult
QueryResult()
Definition: NBHeightMapper.h:117
NBHeightMapper::clearData
void clearData()
clears loaded data
Definition: NBHeightMapper.cpp:331
NBHeightMapper::Triangles
std::vector< const Triangle * > Triangles
Definition: NBHeightMapper.h:112