ADTF Device Toolbox SDK
Loading...
Searching...
No Matches
pointcloud_types.h
Go to the documentation of this file.
1
16
17#pragma once
18
19#include <algorithm>
20#include <cinttypes>
21#include <string>
22#include <tuple>
23#include <unordered_map>
24#include <vector>
25
29namespace adtf
30{
34namespace devicetb
35{
39namespace sdk
40{
44namespace pointcloud
45{
46
47namespace navigation
48{
49#pragma pack(push, 1)
50
51// Memory layout description for each individual axis.
53{
54 enum struct tDataType : size_t
55 {
56 // 8 bit boolean.
57 dt_boolean = 0,
58 // Fixed size integers.
59 dt_uint8 = 1,
60 dt_int8 = 2,
61 dt_uint16 = 3,
62 dt_int16 = 4,
63 dt_uint32 = 5,
64 dt_int32 = 6,
65 dt_uint64 = 7,
66 dt_int64 = 8,
67 // IEEE754 floating point types.
68 dt_float16 = 9,
69 dt_float32 = 10,
70 dt_float64 = 11,
71 dt_computed_from_index = 12
72 };
73
74 tDataType type = tDataType::dt_boolean;
75
76 static constexpr size_t Size(const tDataType& eType) noexcept
77 {
78 switch (eType)
79 {
80 case tDataType::dt_boolean:
81 case tDataType::dt_uint8:
82 case tDataType::dt_int8:
83 {
84 return 1;
85 }
86 case tDataType::dt_uint16:
87 case tDataType::dt_int16:
88 case tDataType::dt_float16:
89 {
90 return 2;
91 }
92 case tDataType::dt_uint32:
93 case tDataType::dt_int32:
94 case tDataType::dt_float32:
95 {
96 return 4;
97 }
98 case tDataType::dt_uint64:
99 case tDataType::dt_int64:
100 case tDataType::dt_float64:
101 {
102 return 8;
103 }
104 case tDataType::dt_computed_from_index:
105 {
106 return 0;
107 }
108 }
109 return 0;
110 }
111
113 {
114 enum struct eEndianess : size_t
115 {
116 endian_big = 0,
117 endian_little
118 };
119
120 eEndianess endianess = eEndianess::endian_little;
121
122 // In BYTES, relative to payload past pointcloud header.
123 size_t offset = 0;
124 // Increment in BYTES to next element position.
125 size_t stride = 0;
126
127 constexpr bool operator==(const tInMemory& oOther) const noexcept
128 {
129 return oOther.endianess == endianess && oOther.offset == offset && oOther.stride == stride;
130 }
131
132 constexpr bool operator!=(const tInMemory& oOther) const noexcept
133 {
134 return !(oOther == *this);
135 }
136 };
137
138 tInMemory sInMemory = {};
139
141 {
142 // After how many elements increment is applied
143 size_t stride_to_increment = 1;
144 // After how many elements reset occurs
145 size_t stride_to_reset = 0;
146 //
147 double increment = 0.0;
148 //
149 double offset = 0.0;
150
151 double Get(size_t index) const
152 {
153 return ((index % stride_to_reset) / stride_to_increment) * increment + offset;
154 }
155
156 constexpr bool operator==(const tComputedFromIndex& oOther) const noexcept
157 {
158 return oOther.stride_to_increment == stride_to_increment && oOther.stride_to_reset == stride_to_reset &&
159 oOther.increment == increment && oOther.offset == offset;
160 }
161
162 constexpr bool operator!=(const tComputedFromIndex& oOther) const noexcept
163 {
164 return !(oOther == *this);
165 }
166 };
167
168 tComputedFromIndex sComputed = {};
169
170 constexpr size_t Size() const noexcept
171 {
172 return Size(type);
173 }
174
175 constexpr bool operator==(const tAttribute& oOther) const noexcept
176 {
177 if (type == tDataType::dt_computed_from_index)
178 {
179 return oOther.type == type && oOther.sComputed == sComputed;
180 }
181 else
182 {
183 return oOther.type == type && oOther.sInMemory == sInMemory;
184 }
185 }
186
187 constexpr bool operator!=(const tAttribute& oOther) const noexcept
188 {
189 return !(oOther == *this);
190 }
191};
192
194{
195 float x = 0.0f;
196 float y = 0.0f;
197 float z = 0.0f;
198 float roll = 0.0f; // x - rotation
199 float pitch = 0.0f; // y - rotation
200 float yaw = 0.0f; // z - rotation
201
202 constexpr bool operator==(const tSensorTransformation& oOther) const noexcept
203 {
204 return oOther.x == x && oOther.y == y && oOther.z == z && oOther.roll == roll && oOther.pitch == pitch &&
205 oOther.yaw == yaw;
206 }
207
208 constexpr bool operator!=(const tSensorTransformation& oOther) const noexcept
209 {
210 return !(oOther == *this);
211 }
212};
213
214#pragma pack(pop)
215
216/*
217 * Helper class for stable storage with amortized element access of O(1).
218 */
219template<class T>
221{
222public:
223 using value_type = std::tuple<std::string, T>;
224
225 bool add(const std::string& name, T attribute)
226 {
227 if (exists(name))
228 {
229 return false;
230 }
231
232 attributes.emplace_back(name, std::move(attribute));
233 return indices.try_emplace(name, attributes.size() - 1).second;
234 }
235
236 const T& at(const std::string& key) const
237 {
238 return std::get<T>(attributes.at(indices.at(key)));
239 }
240
241 const T& at(size_t index) const
242 {
243 return std::get<T>(attributes.at(index));
244 }
245
246 size_t size() const
247 {
248 return attributes.size();
249 }
250
251 bool exists(const std::string& key) const
252 {
253 return indices.find(key) != indices.end();
254 }
255
256 bool empty() const
257 {
258 return attributes.empty();
259 }
260
261 void clear()
262 {
263 attributes.clear();
264 indices.clear();
265 }
266
267 typename std::vector<value_type>::iterator begin()
268 {
269 return attributes.begin();
270 }
271
272 typename std::vector<value_type>::iterator end()
273 {
274 return attributes.end();
275 }
276
277 typename std::vector<value_type>::const_iterator begin() const
278 {
279 return attributes.cbegin();
280 }
281
282 typename std::vector<value_type>::const_iterator end() const
283 {
284 return attributes.cend();
285 }
286
287 bool operator==(const indexed_vector& oOther) const noexcept
288 {
289 return oOther.attributes == attributes;
290 }
291
292 bool operator!=(const indexed_vector& oOther) const noexcept
293 {
294 return !(*this == oOther);
295 }
296
297private:
298 std::vector<value_type> attributes;
299 std::unordered_map<std::string, size_t> indices;
300};
301
302using tAttributes = indexed_vector<tAttribute>;
303
304namespace detail
305{
306struct tBuffer
307{
308 constexpr tBuffer(void* pData, size_t nSize) noexcept: pData(pData), nSize(nSize)
309 {
310 }
311 void* const pData;
312 const size_t nSize;
313};
314
315struct tConstBuffer
316{
317 constexpr tConstBuffer(const void* pData, size_t nSize) noexcept: pData(pData), nSize(nSize)
318 {
319 }
320 const void* const pData;
321 const size_t nSize;
322};
323} // namespace detail
324
325
326} // namespace navigation
327
328using tAttribute = navigation::tAttribute;
329using tSensorTransformation = navigation::tSensorTransformation;
330using tAttributes = navigation::tAttributes;
331
332} // namespace pointcloud
333} // namespace sdk
334} // namespace devicetb
335} // namespace adtf
Namespace for functionality provided by 3.13.0.
Definition pointcloud_access.h:52
Namespace for pointcloud in ADTF-Devicetoolbox.
Definition pointcloud_access.h:49
Namespace for SDK of ADTF-Devicetoolbox.
Definition bus_database_intf.h:42
Devicetoolbox - Namespace.
Definition bus_database_intf.h:36
ADTF - Namespace.
Definition bus_database_intf.h:30