Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBHeightMapper.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2011-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Set z-values for all network positions based on data from a height map
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#ifdef WIN32
26typedef __int16 int16_t;
27#else
28#include <stdint.h>
29#endif
30
31#include <string>
32#include <foreign/rtree/RTree.h>
34#include <utils/geom/Boundary.h>
36
37#ifdef HAVE_GDAL
38#include <ogr_spatialref.h>
39#endif
40
41#define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
42
43// ===========================================================================
44// class declarations
45// ===========================================================================
46class OptionsCont;
47
48
49// ===========================================================================
50// class definitions
51// ===========================================================================
60
61 friend class NBHeightMapperTest;
62
63public:
69 static void loadIfSet(OptionsCont& oc);
70
72 static const NBHeightMapper& get();
73
75 bool ready() const;
76
80 }
81
83 double 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);
96
98 void addSelf(const QueryResult& queryResult) const;
99
101 bool contains(const Position& pos) const;
102
104 double getZ(const Position& geo) const;
105
107 Position normalVector() const;
108
111
112 };
113
114 typedef std::vector<const Triangle*> Triangles;
115
118 public:
121 // @brief method not realy const
122 void add(Triangle* triangle) const {
123 triangles.push_back(triangle);
124 };
126 };
127
128private:
129
130 struct RasterData {
131 float* raster;
133 int xSize;
134 int ySize;
135#ifdef HAVE_GDAL
136 OGRCoordinateTransformation* transform;
137#endif
138 };
139
142
144
147
149 std::vector<RasterData> myRasters;
150
153
156
157private:
161
163 void addTriangle(PositionVector corners);
164
169 int loadShapeFile(const std::string& file);
170
175 int loadTiff(const std::string& file);
176
178 void clearData();
179
182
185
186};
187
188
189// ===========================================================================
190// RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
191// ===========================================================================
192template<>
193inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
194 ASSERT(a_rect);
195 const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
196 const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
197 return .78539816f * (extent0 * extent0 + extent1 * extent1);
198}
199
200template<>
201inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
202 ASSERT(a_rectA && a_rectB);
203 Rect newRect;
204 newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
205 newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
206 newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
207 newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
208 return newRect;
209}
#define TRIANGLE_RTREE_QUAL
#define rtree_min(a, b)
Definition RTree.h:20
#define rtree_max(a, b)
Definition RTree.h:21
#define ASSERT
Definition RTree.h:12
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
class for cirumventing the const-restriction of RTree::Search-context
void add(Triangle *triangle) const
Position normalVector() const
returns the normal vector for this triangles plane
double getZ(const Position &geo) const
returns the projection of the give geoCoordinate (WGS84) onto triangle plane
PositionVector myCorners
the corners of the triangle
void addSelf(const QueryResult &queryResult) const
callback for RTree search
bool contains(const Position &pos) const
checks whether pos lies within triangle (only checks x,y)
Set z-values for all network positions based on data from a height map.
std::vector< const Triangle * > Triangles
Triangles myTriangles
double getZ(const Position &geo) const
returns height for the given geo coordinate (WGS84)
NBHeightMapper & operator=(const NBHeightMapper &)
Invalidated assignment operator.
static const NBHeightMapper & get()
return the singleton instance (maybe 0)
int loadShapeFile(const std::string &file)
load height data from Arcgis-shape file and returns the number of parsed features
static NBHeightMapper myInstance
the singleton instance
bool ready() const
returns whether the NBHeightMapper has data
std::vector< RasterData > myRasters
raster height information in m for all loaded files
NBHeightMapper(const NBHeightMapper &)
Invalidated copy constructor.
NBHeightMapper()
private constructor and destructor (Singleton)
const Boundary & getBoundary()
returns the convex boundary of all known triangles
friend class NBHeightMapperTest
static void loadIfSet(OptionsCont &oc)
loads height map data if any loading options are set
void clearData()
clears loaded data
Position mySizeOfPixel
dimensions of one pixel in raster data
void addTriangle(PositionVector corners)
adds one triangles worth of height data
Boundary myBoundary
convex boundary of all known triangles;
TRIANGLE_RTREE_QUAL myRTree
The RTree for spatial queries.
int loadTiff(const std::string &file)
load height data from GeoTIFF file and returns the number of non void pixels
A storage for options typed value containers)
Definition OptionsCont.h:89
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.