IDS peak ICV v1.0.0
Loading...
Searching...
No Matches
peak_icv_point_cloud.hpp
Go to the documentation of this file.
1
11#pragma once
12
20#include <peak_icv_c/types/peak_icv_point_cloud.h>
21#include <algorithm>
22#include <cstring>
23#include <memory>
24#include <vector>
25
26namespace peak
27{
28namespace icv
29{
30
31namespace detail
32{
33
42template <typename PointCloudType, typename InnerPointType>
43class PointCloud
44 : private detail::IBackendAccessible<PointCloud<PointCloudType, InnerPointType>>
45 , private detail::IBackendExchangeable<PointCloud<PointCloudType, InnerPointType>>
46{
47 static_assert(std::is_base_of<experimental::PointXYZ, InnerPointType>::value,
48 "The given PointType is invalid. Please use a class which derives from Point3d");
49
50public:
51 using PointType = InnerPointType;
52
58 ~PointCloud() override;
59
65 PointCloud(const PointCloud& other);
66
72 PointCloud(PointCloud&& other) noexcept;
73
80
86 PointCloud& operator=(PointCloud&& other) noexcept;
87
93 bool operator==(const PointCloud& rhs) const;
94
100 bool operator!=(const PointCloud& rhs) const;
101
105 const std::vector<PointType>& GetPoints() const;
106
114 PEAK_ICV_NO_DISCARD PointCloudType Transform(const experimental::TransformationMatrix3D& matrix) const;
115
116
128 PEAK_ICV_NO_DISCARD PointCloudType TransformToWorkspace(const experimental::ExtrinsicParameters& extrinsicParameters) const;
129
133 typename std::vector<PointType>::const_iterator cbegin() const;
134
138 typename std::vector<PointType>::const_iterator cend() const;
139
140protected:
141 PointCloud();
142 explicit PointCloud(peak_icv_point_cloud_handle handle);
143
144 PEAK_ICV_NO_DISCARD detail::handle_of_t<PointCloud> GetHandle() const override;
145
149 PEAK_ICV_NO_DISCARD detail::handle_of_t<PointCloud>* GetHandleAddress() override;
150
151private:
153
154 peak_icv_point_cloud_handle m_pointCloudHandle{};
155 mutable std::unique_ptr<std::vector<PointType>> m_points{};
156
157 peak_icv_point_cloud_handle CreateEmptyPointCloud();
158};
159
160template <typename PointCloudType, typename InnerPointType>
162{
163 if (m_pointCloudHandle != nullptr)
164 {
165 PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Destroy(m_pointCloudHandle);
166 }
167}
168
169template <typename PointCloudType, typename InnerPointType>
170PointCloud<PointCloudType, InnerPointType>::PointCloud(peak_icv_point_cloud_handle handle)
171 : m_pointCloudHandle{ handle }
172{}
173
174template <typename PointCloudType, typename InnerPointType>
176{
177 if (m_pointCloudHandle != other.m_pointCloudHandle)
178 {
180 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_IncreaseUseCount(other.m_pointCloudHandle);
181 });
182 m_pointCloudHandle = other.m_pointCloudHandle;
183 }
184}
185
186template <typename PointCloudType, typename InnerPointType>
188{
189 if (m_pointCloudHandle != other.m_pointCloudHandle)
190 {
191 m_pointCloudHandle = other.m_pointCloudHandle;
192 other.m_pointCloudHandle = nullptr;
193 }
194}
195
196template <typename PointCloudType, typename InnerPointType>
198{
199 if (m_pointCloudHandle != other.m_pointCloudHandle)
200 {
201 if (m_pointCloudHandle != nullptr)
202 {
204 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Destroy(m_pointCloudHandle);
205 });
206 }
208 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_IncreaseUseCount(other.m_pointCloudHandle);
209 });
210 m_pointCloudHandle = other.m_pointCloudHandle;
211 m_points = std::make_unique<std::vector<InnerPointType>>(other.GetPoints());
212 }
213
214 return *this;
215}
216
217template <typename PointCloudType, typename InnerPointType>
219{
220 if (m_pointCloudHandle != other.m_pointCloudHandle)
221 {
222 if (m_pointCloudHandle != nullptr)
223 {
225 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Destroy(m_pointCloudHandle);
226 });
227 }
228
229 m_pointCloudHandle = other.m_pointCloudHandle;
230 m_points = std::make_unique<std::vector<InnerPointType>>(other.GetPoints());
231 other.m_pointCloudHandle = nullptr;
232 other.m_points = nullptr;
233 }
234
235 return *this;
236}
237
238template <typename PointCloudType, typename InnerPointType>
240{
241 if (m_pointCloudHandle == rhs.m_pointCloudHandle)
242 {
243 return true;
244 }
245
246 auto pointLhs = this->GetPoints();
247 auto pointRhs = rhs.GetPoints();
248
249 if (pointLhs.size() != pointRhs.size())
250 {
251 return false;
252 }
253
254 return std::is_permutation(pointLhs.begin(), pointLhs.end(), pointRhs.begin());
255}
256
257template <typename PointCloudType, typename InnerPointType>
259{
260 return !(*this == rhs);
261}
262
263template <typename PointCloudType, typename InnerPointType>
264const std::vector<InnerPointType>& PointCloud<PointCloudType, InnerPointType>::GetPoints() const
265{
266 if (m_points)
267 {
268 return *m_points;
269 }
270
271 size_t numPoints = 0;
273 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_GetPoints_GetCount(m_pointCloudHandle, &numPoints);
274 });
275
276 if (numPoints == 0)
277 {
278 m_points = std::make_unique<std::vector<PointType>>(0);
279 return *m_points;
280 }
281
282 std::vector<PointTypeC> points(numPoints);
284 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_GetPoints(m_pointCloudHandle, points.data(), sizeof(PointTypeC) * numPoints);
285 });
286
287 m_points = std::make_unique<std::vector<PointType>>(numPoints);
288 std::transform(points.begin(), points.end(), m_points->begin(), [](const auto& point) {
289 return peak::common::detail::BackendAccessor<PointType>::CreateInstance(point);
290 });
291
292 return *m_points;
293}
294
295template <typename PointCloudType, typename InnerPointType>
297{
298 peak_icv_transformation_matrix_3d cMatrix{};
299 std::memcpy(&cMatrix, matrix.GetData(), sizeof(cMatrix));
300
301 PointCloudType outputPointCloud{};
302 auto outputHandle = peak::common::detail::BackendAccessor<PointCloudType>::BackendHandleAddress(outputPointCloud);
304 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Transform(this->GetHandle(), cMatrix, outputHandle);
305 });
306 return outputPointCloud;
307}
308
309template <typename PointCloudType, typename InnerPointType>
311 const experimental::ExtrinsicParameters& extrinsicParameters) const
312{
313 const auto extrinsicParametersC = peak::common::detail::BackendAccessor<experimental::ExtrinsicParameters>::CreateCType(
314 extrinsicParameters);
315
316 PointCloudType outputPointCloud{};
317 auto outputHandle = peak::common::detail::BackendAccessor<PointCloudType>::BackendHandleAddress(outputPointCloud);
319 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_TransformToWorkspace(this->GetHandle(), extrinsicParametersC, outputHandle);
320 });
321 return outputPointCloud;
322}
323
324template <typename PointCloudType, typename InnerPointType>
325typename std::vector<InnerPointType>::const_iterator PointCloud<PointCloudType, InnerPointType>::cbegin() const
326{
327 return GetPoints().cbegin();
328}
329
330template <typename PointCloudType, typename InnerPointType>
331typename std::vector<InnerPointType>::const_iterator PointCloud<PointCloudType, InnerPointType>::cend() const
332{
333 return GetPoints().cend();
334}
335
336template <typename PointCloudType, typename InnerPointType>
338 : m_pointCloudHandle{ CreateEmptyPointCloud() }
339{}
340
341template <typename PointCloudType, typename InnerPointType>
342detail::handle_of_t<PointCloud<PointCloudType, InnerPointType>> PointCloud<PointCloudType, InnerPointType>::GetHandle() const
343{
344 return m_pointCloudHandle;
345}
346
347template <typename PointCloudType, typename InnerPointType>
348detail::handle_of_t<PointCloud<PointCloudType, InnerPointType>>* PointCloud<PointCloudType, InnerPointType>::GetHandleAddress()
349{
350 return &m_pointCloudHandle;
351}
352
353template <typename PointCloudType, typename InnerPointType>
354peak_icv_point_cloud_handle PointCloud<PointCloudType, InnerPointType>::CreateEmptyPointCloud()
355{
356 peak_icv_point_cloud_handle handle{};
358 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Create(&handle);
359 });
360 return handle;
361}
362
363} // namespace detail
364
365
366} /* namespace icv */
367} /* namespace peak */
constexpr const Type * GetData() const
Returns a pointer to the underlying data of the array.
PointCloudType Transform(const experimental::TransformationMatrix3D &matrix) const
Applies a transformation to a point cloud based on the given matrix.
PointCloud & operator=(const PointCloud &other)
PointCloudType TransformToWorkspace(const experimental::ExtrinsicParameters &extrinsicParameters) const
Transforms a point cloud to the workspace coordinate system using the extrinsic parameters.
PointCloud(const PointCloud &other)
bool operator==(const PointCloud &rhs) const
bool operator!=(const PointCloud &rhs) const
std::vector< PointType >::const_iterator cbegin() const
Returns an iterator to the first point.
const std::vector< PointType > & GetPoints() const
Returns the points from a point cloud.
PointCloud(PointCloud &&other) noexcept
PointCloud & operator=(PointCloud &&other) noexcept
std::vector< PointType >::const_iterator cend() const
Returns an iterator to the end of the points (the point after the last point).
This class stores and provides access to the extrinsic parameters, which include the translation,...
A transformation matrix is a square matrix that, when multiplied by the coordinates of a geometric ob...
typename c_type_of_< Type >::type c_type_of_t
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak::common::detail::c_type_of_t< Type > * handle_of_t