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-2024 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#define TRIANGLE_RTREE_QUAL RTree<NBHeightMapper::Triangle*, NBHeightMapper::Triangle, float, 2, NBHeightMapper::QueryResult>
38
39// ===========================================================================
40// class declarations
41// ===========================================================================
42class OptionsCont;
43
44
45// ===========================================================================
46// class definitions
47// ===========================================================================
56
57 friend class NBHeightMapperTest;
58
59public:
65 static void loadIfSet(OptionsCont& oc);
66
68 static const NBHeightMapper& get();
69
71 bool ready() const;
72
76 }
77
79 double getZ(const Position& geo) const;
80
81 class QueryResult;
82 /* @brief content class for the rtree. Since we wish to be able to use the
83 * rtree for spatial querying we have to jump through some minor hoops:
84 * We let each found triangle callback the NBHeightMapper and add itself the
85 * the query result
86 * */
87 class Triangle {
88
89 public:
90 Triangle(const PositionVector& corners);
92
94 void addSelf(const QueryResult& queryResult) const;
95
97 bool contains(const Position& pos) const;
98
100 double getZ(const Position& geo) const;
101
103 Position normalVector() const;
104
107
108 };
109
110 typedef std::vector<const Triangle*> Triangles;
111
114 public:
117 // @brief method not realy const
118 void add(Triangle* triangle) const {
119 triangles.push_back(triangle);
120 };
122 };
123
124private:
125
126 struct RasterData {
127 int16_t* raster;
129 int xSize;
130 int ySize;
131 };
132
135
137
140
142 std::vector<RasterData> myRasters;
143
146
149
150private:
154
156 void addTriangle(PositionVector corners);
157
162 int loadShapeFile(const std::string& file);
163
168 int loadTiff(const std::string& file);
169
171 void clearData();
172
175
178
179};
180
181
182// ===========================================================================
183// RTree specialization for speedup and avoiding warnings (ripped from SUMORTree.h)
184// ===========================================================================
185template<>
186inline float TRIANGLE_RTREE_QUAL::RectSphericalVolume(Rect* a_rect) {
187 ASSERT(a_rect);
188 const float extent0 = a_rect->m_max[0] - a_rect->m_min[0];
189 const float extent1 = a_rect->m_max[1] - a_rect->m_min[1];
190 return .78539816f * (extent0 * extent0 + extent1 * extent1);
191}
192
193template<>
194inline TRIANGLE_RTREE_QUAL::Rect TRIANGLE_RTREE_QUAL::CombineRect(Rect* a_rectA, Rect* a_rectB) {
195 ASSERT(a_rectA && a_rectB);
196 Rect newRect;
197 newRect.m_min[0] = rtree_min(a_rectA->m_min[0], a_rectB->m_min[0]);
198 newRect.m_max[0] = rtree_max(a_rectA->m_max[0], a_rectB->m_max[0]);
199 newRect.m_min[1] = rtree_min(a_rectA->m_min[1], a_rectB->m_min[1]);
200 newRect.m_max[1] = rtree_max(a_rectA->m_max[1], a_rectB->m_max[1]);
201 return newRect;
202}
#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.