Vanetza
 
Loading...
Searching...
No Matches
region.hpp
1#ifndef REGION_HPP_NUISLPMU
2#define REGION_HPP_NUISLPMU
3
4#include <vanetza/geonet/units.hpp>
5#include <vanetza/security/v2/int_x.hpp>
6#include <vanetza/units/angle.hpp>
7#include <vanetza/units/length.hpp>
8#include <boost/variant/variant.hpp>
9#include <array>
10#include <list>
11
12namespace vanetza
13{
14namespace security
15{
16namespace v2
17{
18
19/// ThreeDLocation specified in TS 103 097 v1.2.1, section 4.2.19
21{
22 using Elevation = std::array<uint8_t, 2>;
23 static const Elevation unknown_elevation;
24 static const Elevation min_elevation;
25 static const Elevation max_elevation;
26
27 ThreeDLocation() = default;
28 ThreeDLocation(geonet::geo_angle_i32t latitude, geonet::geo_angle_i32t longitude) :
29 latitude(latitude), longitude(longitude), elevation(unknown_elevation) {}
30 ThreeDLocation(units::GeoAngle latitude, units::GeoAngle longitude) :
31 latitude(latitude), longitude(longitude), elevation(unknown_elevation) {}
32 ThreeDLocation(geonet::geo_angle_i32t latitude, geonet::geo_angle_i32t longitude, Elevation elevation) :
33 latitude(latitude), longitude(longitude), elevation(elevation) {}
34 ThreeDLocation(units::GeoAngle latitude, units::GeoAngle longitude, Elevation elevation) :
35 latitude(latitude), longitude(longitude), elevation(elevation) {}
36
37 geonet::geo_angle_i32t latitude;
38 geonet::geo_angle_i32t longitude;
39 Elevation elevation;
40
41 bool operator==(const ThreeDLocation&) const;
42 bool operator!=(const ThreeDLocation&) const;
43};
44
45/// TwoDLocation specified in TS 103 097 v1.2.1, section 4.2.18
47{
48 TwoDLocation() = default;
49 TwoDLocation(geonet::geo_angle_i32t latitude, geonet::geo_angle_i32t longitude) :
50 latitude(latitude), longitude(longitude) {}
51 TwoDLocation(units::GeoAngle latitude, units::GeoAngle longitude) :
52 latitude(latitude), longitude(longitude) {}
53 explicit TwoDLocation(const ThreeDLocation& threeD) :
54 latitude(threeD.latitude), longitude(threeD.longitude) {}
55
56 geonet::geo_angle_i32t latitude;
57 geonet::geo_angle_i32t longitude;
58
59 bool operator==(const TwoDLocation&) const;
60 bool operator!=(const TwoDLocation&) const;
61};
62
63/// Specified in TS 103 097 v1.2.1, section 4.2.20
65{
66 // empty
67
68 bool operator==(const NoneRegion&) const;
69 bool operator!=(const NoneRegion&) const;
70};
71
72/// CircularRegion specified in TS 103 097 v1.2.1, section 4.2.22
74{
75 CircularRegion() = default;
76 CircularRegion(const TwoDLocation& center, geonet::distance_u16t radius) :
77 center(center), radius(radius) {}
78 CircularRegion(const TwoDLocation& center, units::Length radius) :
79 center(center), radius(radius) {}
80
81 TwoDLocation center;
82 geonet::distance_u16t radius;
83
84 bool operator==(const CircularRegion&) const;
85 bool operator!=(const CircularRegion&) const;
86};
87
88/// RectangularRegion specified in TS 103 097 v1.2.1, section 4.2.23
90{
91 TwoDLocation northwest;
92 TwoDLocation southeast;
93
94 bool operator==(const RectangularRegion&) const;
95 bool operator!=(const RectangularRegion&) const;
96};
97
98/// PolygonalRegion specified in TS 103 097 v1.2.1, section 4.2.24
99using PolygonalRegion = std::list<TwoDLocation>;
100
101/// RegionDictionary specified in TS 103 097 v1.2.1, section 4.2.26
102enum class RegionDictionary : uint8_t
103{
104 ISO_3166_1 = 0,
105 UN_Stats = 1,
106};
107
108/// IdentifiedRegion specified in TS 103 097 v1.2.1, section 4.2.25
110{
111 RegionDictionary region_dictionary;
112 int16_t region_identifier;
113 IntX local_region;
114
115 bool operator==(const IdentifiedRegion&) const;
116 bool operator!=(const IdentifiedRegion&) const;
117};
118
119/// RegionType specified in TS 103 097 v1.2.1, section 4.2.21
120enum class RegionType : uint8_t
121{
122 None = 0, // nothing
123 Circle = 1, // CircularRegion
124 Rectangle = 2, // std::list<RectangularRegion>
125 Polygon = 3, // PolygonalRegion
126 ID = 4, // IdentifiedRegion
127};
128
129/// GeographicRegion specified in TS 103 097 v1.2.1, section 4.2.20
130using GeographicRegion = boost::variant<
131 NoneRegion,
133 std::list<RectangularRegion>,
136>;
137
138/**
139 * \brief Determines RegionType of a GeographicRegion
140 * \param region
141 * \return RegionType
142 */
143RegionType get_type(const GeographicRegion&);
144
145/**
146 * \brief Calculates size of a TwoDLocation
147 * \param loc
148 * \return number of octets needed to serialize the TwoDLocation
149 */
150size_t get_size(const TwoDLocation&);
151
152/**
153 * \brief Calculates size of a ThreeDLocation
154 * \param log
155 * \return number of octets needed to serialize the ThreeDLocation
156 */
157size_t get_size(const ThreeDLocation&);
158
159/**
160 * \brief Calculates size of a CircularRegion
161 * \param reg
162 * \return number of octets needed to serialize the CiruclarRegion
163 */
164size_t get_size(const CircularRegion&);
165
166/**
167 * \brief Calculates size of a RectangularRegion
168 * \param reg
169 * \return number of octets needed to serialize the RectangularRegion
170 */
171size_t get_size(const RectangularRegion&);
172
173/**
174 * \brief Calculates size of a list of CircularRegion
175 * \param list
176 * \return number of octets needed to serialize the list of CircularRegion
177 */
178size_t get_size(const std::list<CircularRegion>&);
179
180/**
181 * \brief Calculates size of a list of RectangularRegion
182 * \param list
183 * \return number of octets needed to serialize the list of RectangularRegion
184 */
185size_t get_size(const std::list<RectangularRegion>&);
186
187/**
188 * \brief Calculates size of a PolygonalRegion
189 * \param reg
190 * \return number of octets needed to serialize the PolygonalRegion
191 */
192size_t get_size(const PolygonalRegion&);
193
194/**
195 * \brief Calculates size of a GeographicRegion
196 * \param reg
197 * \return number of octets needed to serialize the GeographicRegion
198 */
199size_t get_size(const GeographicRegion&);
200
201/**
202 * \brief Serializes a TwoDLocation into a binary archive
203 * \param ar to serialize in
204 * \param loc to serialize
205 */
206void serialize(OutputArchive&, const TwoDLocation&);
207
208/**
209 * \brief Serializes a ThreeDLocation into a binary archive
210 * \param ar to serialize in
211 * \param loc to serialize
212 */
213void serialize(OutputArchive&, const ThreeDLocation&);
214
215/**
216 * \brief Serializes a CiruclarRegion into a binary archive
217 * \param ar to serialize in
218 * \param reg to serialize
219 */
220void serialize(OutputArchive&, const CircularRegion&);
221
222/**
223 * \brief Serializes a RectangularRegion into a binary archive
224 * \param ar to serialize in
225 * \param reg to serialize
226 */
227void serialize(OutputArchive&, const RectangularRegion&);
228
229/**
230 * \brief Serializes a list of RectangularRegions into a binary archive
231 * \param ar to serialize in
232 * \param list to serialize
233 */
234void serialize(OutputArchive&, const std::list<RectangularRegion>&);
235
236/**
237 * \brief Serializes a PolygonalRegion into a binary archive
238 * \param ar to serialize in
239 * \param reg to serialize
240 */
241void serialize(OutputArchive&, const PolygonalRegion&);
242
243/**
244 * \brief Serializes an IdentifiedRegion into a binary archive
245 * \param ar to serialize in
246 * \param reg to serialize
247 */
248void serialize(OutputArchive&, const IdentifiedRegion&);
249
250/**
251 * \brief Serializes a GeographicRegion into a binary archive
252 * \param ar to serialize in
253 * \param reg to serialize
254 */
255void serialize(OutputArchive&, const GeographicRegion&);
256
257/**
258 * \brief Deserializes a TwoDLocation from a binary archive
259 * \param ar with a serialized TwoDLocation at the beginning
260 * \param loc to deserialize
261 * \return size of the deserialized TwoDLocation
262 */
263size_t deserialize(InputArchive&, TwoDLocation&);
264
265/**
266 * \brief Deserializes a ThreeDLocation from a binary archive
267 * \param ar with a serialized ThreeDLocation at the beginning
268 * \param loc to deserialize
269 * \return size of the deserialized ThreeDLocation
270 */
271size_t deserialize(InputArchive&, ThreeDLocation&);
272
273/**
274 * \brief Deserializes a CircularRegion from a binary archive
275 * \param ar with a serialized CiruclarRegion at the beginning
276 * \param reg to deserialize
277 * \return size of the deserialized CiruclarRegion
278 */
279size_t deserialize(InputArchive&, CircularRegion&);
280
281/**
282 * \brief Deserializes a list of RectangularRegions from a binary archive
283 * \param ar with a serialized RectangularRegion list at the beginning
284 * \param list to deserialize
285 * \return size of the deserialized list
286 */
287size_t deserialize(InputArchive&, std::list<RectangularRegion>&);
288
289/**
290 * \brief Deserializes a PolygonalRegion from a binary archive
291 * \param ar with a serialized PolygonalRegion at the beginning
292 * \param reg to deserialize
293 * \return size of the deserialized PolygonalRegion
294 */
295size_t deserialize(InputArchive&, PolygonalRegion&);
296
297/**
298 * \brief Deserializes an IdentifiedRegion from a binary archive
299 * \param ar with a serialized IdentifiedRegion at the beginning
300 * \param reg to deserialize
301 * \return size of the deserialized IdentifiedRegion
302 */
303size_t deserialize(InputArchive&, IdentifiedRegion&);
304
305/**
306 * \brief Deserializes a GeographicRegion from a binary archive
307 * \param ar with a serialized GeographicRegion at the beginning
308 * \param reg to deserialize
309 * \return size of the deserialized GeographicRegion
310 */
311size_t deserialize(InputArchive&, GeographicRegion&);
312
313/**
314 * \brief Check if position is within geographic region
315 * \param pos position
316 * \param r region
317 * \true if pos is within region
318 */
319bool is_within(const TwoDLocation&, const GeographicRegion&);
320
321/**
322 * \brief Check if position is within circular region
323 * \param pos position
324 * \param c cicrular region
325 * \true if pos is within region
326 */
327bool is_within(const TwoDLocation&, const CircularRegion&);
328
329/**
330 * \brief Check if position is within set of rectangular regions
331 * \param pos position
332 * \param r rectangular regions
333 * \true if pos is within region
334 */
335bool is_within(const TwoDLocation&, const std::list<RectangularRegion>&);
336
337/**
338 * \brief Check if position is within rectangular region
339 * \param pos position
340 * \param r rectangular region
341 * \true if pos is within region
342 */
343bool is_within(const TwoDLocation&, const RectangularRegion&);
344
345/**
346 * \brief Check if position is within polygonal region
347 * \param pos position
348 * \param c cicrular region
349 * \true if pos is within region
350 */
351bool is_within(const TwoDLocation&, const PolygonalRegion&);
352
353/**
354 * \brief Check if position is within identified region
355 * \param pos position
356 * \param i identified region
357 * \true if pos is within region
358 */
359bool is_within(const TwoDLocation&, const IdentifiedRegion&);
360
361/**
362 * \brief Check if a region is within another geographic region
363 * \param reg region
364 * \param r region
365 * \true if pos is within region
366 */
367bool is_within(const GeographicRegion&, const GeographicRegion&);
368
369/**
370 * \brief Check if a region is within a circular region
371 * \param reg region
372 * \param c cicrular region
373 * \true if pos is within region
374 */
375bool is_within(const GeographicRegion&, const CircularRegion&);
376
377/**
378 * \brief Check if a region is within a set of rectangular regions
379 * \param reg region
380 * \param r rectangular regions
381 * \true if pos is within region
382 */
383bool is_within(const GeographicRegion&, const std::list<RectangularRegion>&);
384
385/**
386 * \brief Check if a region is within a polygonal region
387 * \param reg region
388 * \param c cicrular region
389 * \true if pos is within region
390 */
391bool is_within(const GeographicRegion&, const PolygonalRegion&);
392
393/**
394 * \brief Check if a region is within an identified region
395 * \param reg region
396 * \param i identified region
397 * \true if pos is within region
398 */
399bool is_within(const GeographicRegion&, const IdentifiedRegion&);
400
401/**
402 * \brief Convert WGS84 altitude to elevation
403 * \see TS 103 097 v1.2.1, section 4.2.19
404 * \param altitude altitude above ellipsoid (accepts NaN)
405 * \return encoded elevation
406 */
407ThreeDLocation::Elevation to_elevation(units::Length);
408
409} // namespace v2
410} // namespace security
411} // namespace vanetza
412
413#endif /* REGION_HPP_NUISLPMU */
IntX specified in TS 103 097 v1.2.1, section 4.2.1.
Definition: int_x.hpp:21
CircularRegion specified in TS 103 097 v1.2.1, section 4.2.22.
Definition: region.hpp:74
IdentifiedRegion specified in TS 103 097 v1.2.1, section 4.2.25.
Definition: region.hpp:110
Specified in TS 103 097 v1.2.1, section 4.2.20.
Definition: region.hpp:65
RectangularRegion specified in TS 103 097 v1.2.1, section 4.2.23.
Definition: region.hpp:90
ThreeDLocation specified in TS 103 097 v1.2.1, section 4.2.19.
Definition: region.hpp:21
TwoDLocation specified in TS 103 097 v1.2.1, section 4.2.18.
Definition: region.hpp:47