Ocean
Loading...
Searching...
No Matches
Mesher.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_IO_MAPS_RENDERING_MESHER_H
9#define META_OCEAN_IO_MAPS_RENDERING_MESHER_H
10
12
14
16
17#include "ocean/math/Vector3.h"
18
19namespace Ocean
20{
21
22namespace IO
23{
24
25namespace Maps
26{
27
28namespace Rendering
29{
30
31/**
32 * This class implements functions to creates meshes from map objects.
33 * @ingroup iomapsrendering
34 */
35class OCEAN_IO_MAPS_RENDERING_EXPORT Mesher
36{
37 public:
38
39 /**
40 * This class defines a mesh.
41 */
42 class Mesh
43 {
44 public:
45
46 /**
47 * Default constructor.
48 */
49 Mesh() = default;
50
51 /**
52 * Creates a new mesh object.
53 * @param vertices The vertices of the mesh
54 * @param perVertexNormals The per-vertex normals of the mesh
55 * @param triangleFaces The triangle faces of the mesh, three consecutive indices define one triangle
56 */
57 inline Mesh(Vectors3&& vertices, Vectors3&& perVertexNormals, Indices32&& triangleFaces);
58
59 /**
60 * Returns the vertices of this mesh.
61 * @return The mesh's vertices
62 */
63 inline const Vectors3& vertices() const;
64
65 /**
66 * Returns the per-vertex normals of this mesh.
67 * @return The mesh's per-vertex normals
68 */
69 inline const Vectors3& perVertexNormals() const;
70
71 /**
72 * Returns the triangle faces of this mesh.
73 * @return The mesh's triangle faces, three consecutive indices define one triangle
74 */
75 inline const Indices32& triangleFaces() const;
76
77 /**
78 * Returns whether this mesh holds at least one valid triangle.
79 * @return True, if so
80 */
81 inline bool isValid() const;
82
83 protected:
84
85 /// The vertices of the mesh.
87
88 /// The per-vertex normals of the mesh.
90
91 /// The triangle faces of the mesh, three consecutive indices define one triangle.
93 };
94
95 public:
96
97 /**
98 * Creates a triangle object containing all buildings of a tile.
99 * @param objects The tile objects, objects not being a building are ignored
100 * @param titleMetricExtent The metric extent of the tile owning the buildings, in meter, with range (0, infinity)
101 * @param targetSize The target size of the tile in the rendering domain, with range (0, infinity)
102 * @param volumetric True, to create a volumetic building if the building's height is known; False, to create a flat object
103 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
104 * @return The Triangles object containing all rendering element, invalid in case of an error
105 */
106 static Mesh createBuildings(const Basemap::SharedObjects& objects, const double titleMetricExtent, const Scalar targetSize, const bool volumetric, const Scalar groundPlaneOffset = Scalar(0));
107
108 /**
109 * Creates a triangle object containing one building.
110 * @param building The building for which the triangle object will be created
111 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
112 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
113 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
114 * @param volumetric True, to create a volumetic building if the building's height is known; False, to create a flat object
115 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
116 * @return The Triangles object containing all rendering element, invalid in case of an error
117 */
118 static Mesh createBuilding(const Basemap::Building& building, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, const bool volumetric, const Scalar groundPlaneOffset = Scalar(0));
119
120 /**
121 * Creates a triangle object containing all roads of a tile.
122 * @param objects The tile objects, objects not being a road are ignored
123 * @param titleMetricExtent The metric extent of the tile owning the roads, in meter, with range (0, infinity)
124 * @param targetSize The target size of the tile in the rendering domain, with range (0, infinity)
125 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
126 * @param roadWidthMap The map mapping road type to road widths in meter
127 * @return The Triangles object containing all rendering element, invalid in case of an error
128 */
129 static Mesh createRoads(const Basemap::SharedObjects& objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset = Scalar(0), const Basemap::Road::RoadWidthMap& roadWidthMap = Basemap::Road::defaultRoadWidthMap());
130
131 /**
132 * Creates a triangle object containing all transits of a tile.
133 * @param objects The tile objects, objects not being a transit are ignored
134 * @param titleMetricExtent The metric extent of the tile owning the transits, in meter, with range (0, infinity)
135 * @param targetSize The target size of the tile in the rendering domain, with range (0, infinity)
136 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
137 * @return The Triangles object containing all rendering element, invalid in case of an error
138 */
139 static Mesh createTransits(const Basemap::SharedObjects& objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset = Scalar(0));
140
141 /**
142 * Creates a triangle object containing all waters of a tile.
143 * @param objects The tile objects, objects not being a water are ignored
144 * @param titleMetricExtent The metric extent of the tile owning the buildings, in meter, with range (0, infinity)
145 * @param targetSize The target size of the tile in the rendering domain, with range (0, infinity)
146 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
147 * @return The Triangles object containing all rendering element, invalid in case of an error
148 */
149 static Mesh createWaters(const Basemap::SharedObjects& objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset = Scalar(0));
150
151 /**
152 * Creates a triangle object containing all land uses of a tile.
153 * @param objects The tile objects, objects not being a land use are ignored
154 * @param titleMetricExtent The metric extent of the tile owning the buildings, in meter, with range (0, infinity)
155 * @param targetSize The target size of the tile in the rendering domain, with range (0, infinity)
156 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
157 * @return The Triangles object containing all rendering element, invalid in case of an error
158 */
159 static Mesh createLandUses(const Basemap::SharedObjects& objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset = Scalar(0));
160
161 /**
162 * Creates a triangle object containing all land covers of a tile.
163 * @param objects The tile objects, objects not being a land cover are ignored
164 * @param titleMetricExtent The metric extent of the tile owning the buildings, in meter, with range (0, infinity)
165 * @param targetSize The target size of the tile in the rendering domain, with range (0, infinity)
166 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
167 * @return The Triangles object containing all rendering element, invalid in case of an error
168 */
169 static Mesh createLandCovers(const Basemap::SharedObjects& objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset = Scalar(0));
170
171 /**
172 * Adds vertices for a building forming a 3D object.
173 * @param building The building for which the vertices will be added
174 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
175 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
176 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
177 * @param vertices The vertices to which the new vertices will be added
178 * @param normals The normals to which the new normals will be added
179 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
180 * @param volumetric True, to create a volumetic building if the building's height is known; False, to create a flat object
181 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
182 * @return True, if succeeded
183 */
184 static bool addBuilding(const Basemap::Building& building, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const bool volumetric, const Scalar groundPlaneOffset = Scalar(0));
185
186 /**
187 * Adds vertices for a road forming a flat band.
188 * @param road The road for which the vertices will be added
189 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
190 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
191 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
192 * @param vertices The vertices to which the new vertices will be added
193 * @param normals The normals to which the new normals will be added
194 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
195 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
196 * @param roadWidthMap The map mapping road type to road widths in meter
197 * @return True, if succeeded
198 */
199 static bool addRoad(const Basemap::Road& road, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar groundPlaneOffset = Scalar(0), const Basemap::Road::RoadWidthMap& roadWidthMap = Basemap::Road::defaultRoadWidthMap());
200
201 /**
202 * Adds vertices for a transit forming a flat band.
203 * @param transit The transit for which the vertices will be added
204 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
205 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
206 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
207 * @param vertices The vertices to which the new vertices will be added
208 * @param normals The normals to which the new normals will be added
209 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
210 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
211 * @return True, if succeeded
212 */
213 static bool addTransit(const Basemap::Transit& transit, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar groundPlaneOffset = Scalar(0));
214
215 /**
216 * Adds vertices for a water forming a flat geometry.
217 * @param water The water for which the vertices will be added
218 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
219 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
220 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
221 * @param vertices The vertices to which the new vertices will be added
222 * @param normals The normals to which the new normals will be added
223 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
224 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
225 * @return True, if succeeded
226 */
227 static bool addWater(const Basemap::Water& water, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar groundPlaneOffset = Scalar(0));
228
229 /**
230 * Adds vertices for a land use forming a flat geometry.
231 * @param landUse The land use for which the vertices will be added
232 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
233 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
234 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
235 * @param vertices The vertices to which the new vertices will be added
236 * @param normals The normals to which the new normals will be added
237 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
238 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
239 * @return True, if succeeded
240 */
241 static bool addLandUse(const Basemap::LandUse& landUse, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar groundPlaneOffset = Scalar(0));
242
243 /**
244 * Adds vertices for a land cover forming a flat geometry.
245 * @param landCover The land cover for which the vertices will be added
246 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
247 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
248 * @param metricNormalization The normalization function to be applied to each metric value, with range (0, infinity)
249 * @param vertices The vertices to which the new vertices will be added
250 * @param normals The normals to which the new normals will be added
251 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
252 * @param groundPlaneOffset The offset of the ground plane in metric y-space, with range (-infinity, infinity)
253 * @return True, if succeeded
254 */
255 static bool addLandCover(const Basemap::LandCover& landCover, const CV::PixelPositionI& origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar groundPlaneOffset = Scalar(0));
256
257 /**
258 * Adds vertices for a polygon to form a 3D object.
259 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
260 * @param outerPolygon The outer polygon of the object, with at least two points
261 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
262 * @param normalizedHeight The height of the 3D object in normalized space, with range [0, infinity)
263 * @param vertices The vertices to which the new vertices will be added
264 * @param normals The normals to which the new normals will be added
265 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
266 * @param normalizedGroundPlaneOffset The offset of the ground plane in normalized y-space, with range (-infinity, infinity)
267 * @return True, if succeeded
268 */
269 static bool addPolygon(const CV::PixelPositionI& origin, const CV::PixelPositionsI& outerPolygon, const Scalar pixelPositionNormalization, const Scalar normalizedHeight, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar normalizedGroundPlaneOffset);
270
271 protected:
272
273 /**
274 * Adds vertices for a line string to form a flat band.
275 * @param origin The explicit origin in the layer domain, with range (-infinity, infinity)x(-infinity, infinity)
276 * @param lineString The line string to form the flat band from, with at least two points
277 * @param pixelPositionNormalization The normalization function to be applied to each coordinate of the line string, with range (0, infinity)
278 * @param normalizedWidth The width of the band in normalized space, with range (0, infinity)
279 * @param vertices The vertices to which the new vertices will be added
280 * @param normals The normals to which the new normals will be added
281 * @param triangleFaces The triangle faces to which the new triangle faces will be added, three consecutive indices define one triangle
282 * @param normalizedGroundPlaneOffset The offset of the ground plane in normalized y-space, with range (-infinity, infinity)
283 * @return True, if succeeded
284 */
285 static bool addLineString(const CV::PixelPositionI& origin, const CV::PixelPositionsI& lineString, const Scalar pixelPositionNormalization, const Scalar normalizedWidth, Vectors3& vertices, Vectors3& normals, Indices32& triangleFaces, const Scalar normalizedGroundPlaneOffset);
286};
287
288inline Mesher::Mesh::Mesh(Vectors3&& vertices, Vectors3&& perVertexNormals, Indices32&& triangleFaces) :
289 vertices_(std::move(vertices)),
290 perVertexNormals_(std::move(perVertexNormals)),
291 triangleFaces_(std::move(triangleFaces))
292{
293 ocean_assert(vertices_.size() == perVertexNormals_.size());
294 ocean_assert(triangleFaces_.size() % 3 == 0);
295}
296
297inline const Vectors3& Mesher::Mesh::vertices() const
298{
299 return vertices_;
300}
301
303{
304 return perVertexNormals_;
305}
306
308{
309 return triangleFaces_;
310}
311
312inline bool Mesher::Mesh::isValid() const
313{
314 return !triangleFaces_.empty() && triangleFaces_.size() % 3 == 0;
315}
316
317}
318
319}
320
321}
322
323}
324
325#endif // META_OCEAN_IO_MAPS_RENDERING_MESHER_H
This class implements a 2D pixel position with pixel precision.
Definition PixelPosition.h:65
This class implements a building object.
Definition Basemap.h:365
This class implements a land use object.
Definition Basemap.h:551
This class implements a land use object.
Definition Basemap.h:486
This class implements a road object.
Definition Basemap.h:124
std::unordered_map< RoadType, float > RoadWidthMap
Definition of an unordered map mapping road types to road widths.
Definition Basemap.h:209
This class implements a transit object.
Definition Basemap.h:271
This class implements a water object.
Definition Basemap.h:409
std::vector< SharedObject > SharedObjects
Definition of a vector holding shared objects.
Definition Basemap.h:610
This class defines a mesh.
Definition Mesher.h:43
bool isValid() const
Returns whether this mesh holds at least one valid triangle.
Definition Mesher.h:312
Mesh()=default
Default constructor.
const Vectors3 & perVertexNormals() const
Returns the per-vertex normals of this mesh.
Definition Mesher.h:302
const Indices32 & triangleFaces() const
Returns the triangle faces of this mesh.
Definition Mesher.h:307
Vectors3 vertices_
The vertices of the mesh.
Definition Mesher.h:86
Indices32 triangleFaces_
The triangle faces of the mesh, three consecutive indices define one triangle.
Definition Mesher.h:92
Vectors3 perVertexNormals_
The per-vertex normals of the mesh.
Definition Mesher.h:89
const Vectors3 & vertices() const
Returns the vertices of this mesh.
Definition Mesher.h:297
This class implements functions to creates meshes from map objects.
Definition Mesher.h:36
static Mesh createRoads(const Basemap::SharedObjects &objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset=Scalar(0), const Basemap::Road::RoadWidthMap &roadWidthMap=Basemap::Road::defaultRoadWidthMap())
Creates a triangle object containing all roads of a tile.
static bool addLineString(const CV::PixelPositionI &origin, const CV::PixelPositionsI &lineString, const Scalar pixelPositionNormalization, const Scalar normalizedWidth, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar normalizedGroundPlaneOffset)
Adds vertices for a line string to form a flat band.
static bool addLandUse(const Basemap::LandUse &landUse, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar groundPlaneOffset=Scalar(0))
Adds vertices for a land use forming a flat geometry.
static bool addPolygon(const CV::PixelPositionI &origin, const CV::PixelPositionsI &outerPolygon, const Scalar pixelPositionNormalization, const Scalar normalizedHeight, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar normalizedGroundPlaneOffset)
Adds vertices for a polygon to form a 3D object.
static Mesh createTransits(const Basemap::SharedObjects &objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset=Scalar(0))
Creates a triangle object containing all transits of a tile.
static bool addTransit(const Basemap::Transit &transit, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar groundPlaneOffset=Scalar(0))
Adds vertices for a transit forming a flat band.
static Mesh createBuilding(const Basemap::Building &building, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, const bool volumetric, const Scalar groundPlaneOffset=Scalar(0))
Creates a triangle object containing one building.
static Mesh createBuildings(const Basemap::SharedObjects &objects, const double titleMetricExtent, const Scalar targetSize, const bool volumetric, const Scalar groundPlaneOffset=Scalar(0))
Creates a triangle object containing all buildings of a tile.
static bool addBuilding(const Basemap::Building &building, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const bool volumetric, const Scalar groundPlaneOffset=Scalar(0))
Adds vertices for a building forming a 3D object.
static bool addLandCover(const Basemap::LandCover &landCover, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar groundPlaneOffset=Scalar(0))
Adds vertices for a land cover forming a flat geometry.
static bool addRoad(const Basemap::Road &road, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar groundPlaneOffset=Scalar(0), const Basemap::Road::RoadWidthMap &roadWidthMap=Basemap::Road::defaultRoadWidthMap())
Adds vertices for a road forming a flat band.
static Mesh createLandUses(const Basemap::SharedObjects &objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset=Scalar(0))
Creates a triangle object containing all land uses of a tile.
static bool addWater(const Basemap::Water &water, const CV::PixelPositionI &origin, const Scalar pixelPositionNormalization, const Scalar metricNormalization, Vectors3 &vertices, Vectors3 &normals, Indices32 &triangleFaces, const Scalar groundPlaneOffset=Scalar(0))
Adds vertices for a water forming a flat geometry.
static Mesh createWaters(const Basemap::SharedObjects &objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset=Scalar(0))
Creates a triangle object containing all waters of a tile.
static Mesh createLandCovers(const Basemap::SharedObjects &objects, const double titleMetricExtent, const Scalar targetSize, const Scalar groundPlaneOffset=Scalar(0))
Creates a triangle object containing all land covers of a tile.
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
std::vector< PixelPositionI > PixelPositionsI
Definition of a vector holding pixel positions (with positive and negative coordinate values).
Definition PixelPosition.h:55
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
The namespace covering the entire Ocean framework.
Definition Accessor.h:15