IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
peak_icv_point_cloud.hpp
Go to the documentation of this file.
1
11#pragma once
12
13#include <peak_common_c/detail/peak_common_defines.h>
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{
30namespace detail
31{
32
57template <typename PointCloudType, typename InnerPointType>
58class PointCloud
59 : private detail::IBackendAccessible<PointCloud<PointCloudType, InnerPointType>>
60 , private detail::IBackendExchangeable<PointCloud<PointCloudType, InnerPointType>>
61{
62 static_assert(
63 std::is_base_of<PointXYZ, InnerPointType>::value, "The given PointType is invalid. Please use a class which derives from Point3d");
64
65public:
66 using PointType = InnerPointType;
67
68 ~PointCloud() override;
69
70 PointCloud(const PointCloud& other);
71
72 PointCloud(PointCloud&& other) noexcept;
73
75
76 PointCloud& operator=(PointCloud&& other) noexcept;
77
78 bool operator==(const PointCloud& rhs) const;
79
80 bool operator!=(const PointCloud& rhs) const;
81
85 const std::vector<PointType>& GetPoints() const;
86
94 PEAK_COMMON_NO_DISCARD PointCloudType Transform(const TransformationMatrix3D& matrix) const;
95
107 PEAK_COMMON_NO_DISCARD PointCloudType TransformToWorkspace(const ExtrinsicParameters& extrinsicParameters) const;
108
112 typename std::vector<PointType>::const_iterator cbegin() const;
113
117 typename std::vector<PointType>::const_iterator cend() const;
118
119protected:
120 PointCloud();
121 explicit PointCloud(peak_icv_point_cloud_handle handle);
122
123 PEAK_COMMON_NO_DISCARD detail::handle_of_t<PointCloud> GetHandle() const override;
124
130 PEAK_COMMON_NO_DISCARD detail::handle_of_t<PointCloud>* GetHandleAddress() override;
131
132private:
134
135 peak_icv_point_cloud_handle m_pointCloudHandle{};
136 mutable std::unique_ptr<std::vector<PointType>> m_points{};
137
138 peak_icv_point_cloud_handle CreateEmptyPointCloud();
139};
140
141template <typename PointCloudType, typename InnerPointType>
143{
144 if (m_pointCloudHandle != nullptr)
145 {
146 std::ignore = PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Destroy(m_pointCloudHandle);
147 }
148}
149
150template <typename PointCloudType, typename InnerPointType>
151PointCloud<PointCloudType, InnerPointType>::PointCloud(peak_icv_point_cloud_handle handle)
152 : m_pointCloudHandle{ handle }
153{}
154
155template <typename PointCloudType, typename InnerPointType>
157{
158 if (m_pointCloudHandle != other.m_pointCloudHandle)
159 {
161 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_IncreaseUseCount(other.m_pointCloudHandle);
162 });
163 m_pointCloudHandle = other.m_pointCloudHandle;
164 }
165}
166
167template <typename PointCloudType, typename InnerPointType>
169{
170 if (m_pointCloudHandle != other.m_pointCloudHandle)
171 {
172 m_pointCloudHandle = other.m_pointCloudHandle;
173 other.m_pointCloudHandle = nullptr;
174 }
175}
176
177template <typename PointCloudType, typename InnerPointType>
179{
180 if (m_pointCloudHandle != other.m_pointCloudHandle)
181 {
182 if (m_pointCloudHandle != nullptr)
183 {
185 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Destroy(m_pointCloudHandle);
186 });
187 }
189 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_IncreaseUseCount(other.m_pointCloudHandle);
190 });
191 m_pointCloudHandle = other.m_pointCloudHandle;
192 m_points = std::make_unique<std::vector<InnerPointType>>(other.GetPoints());
193 }
194
195 return *this;
196}
197
198template <typename PointCloudType, typename InnerPointType>
200{
201 if (m_pointCloudHandle != other.m_pointCloudHandle)
202 {
203 if (m_pointCloudHandle != nullptr)
204 {
206 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Destroy(m_pointCloudHandle);
207 });
208 }
209
210 m_pointCloudHandle = other.m_pointCloudHandle;
211 m_points = std::make_unique<std::vector<InnerPointType>>(other.GetPoints());
212 other.m_pointCloudHandle = nullptr;
213 other.m_points = nullptr;
214 }
215
216 return *this;
217}
218
219template <typename PointCloudType, typename InnerPointType>
221{
222 if (m_pointCloudHandle == rhs.m_pointCloudHandle)
223 {
224 return true;
225 }
226
227 auto pointLhs = this->GetPoints();
228 auto pointRhs = rhs.GetPoints();
229
230 if (pointLhs.size() != pointRhs.size())
231 {
232 return false;
233 }
234
235 return std::is_permutation(pointLhs.begin(), pointLhs.end(), pointRhs.begin());
236}
237
238template <typename PointCloudType, typename InnerPointType>
240{
241 return !(*this == rhs);
242}
243
244template <typename PointCloudType, typename InnerPointType>
245const std::vector<InnerPointType>& PointCloud<PointCloudType, InnerPointType>::GetPoints() const
246{
247 if (m_points)
248 {
249 return *m_points;
250 }
251
252 size_t numPoints = 0;
254 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_GetPoints_GetCount(m_pointCloudHandle, &numPoints);
255 });
256
257 if (numPoints == 0)
258 {
259 m_points = std::make_unique<std::vector<PointType>>(0);
260 return *m_points;
261 }
262
263 std::vector<PointTypeC> points(numPoints);
265 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_GetPoints(m_pointCloudHandle, points.data(), sizeof(PointTypeC) * numPoints);
266 });
267
268 m_points = std::make_unique<std::vector<PointType>>(numPoints);
269 std::transform(points.begin(), points.end(), m_points->begin(), [](const auto& point) {
270 return peak::common::detail::BackendAccessor<PointType>::CreateInstance(point);
271 });
272
273 return *m_points;
274}
275
276template <typename PointCloudType, typename InnerPointType>
278{
279 peak_icv_transformation_matrix_3d cMatrix{};
280 std::memcpy(&cMatrix, matrix.GetData(), sizeof(cMatrix));
281
282 PointCloudType outputPointCloud{};
283 auto outputHandle = peak::common::detail::BackendAccessor<PointCloudType>::BackendHandleAddress(outputPointCloud);
285 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Transform(this->GetHandle(), cMatrix, outputHandle);
286 });
287 return outputPointCloud;
288}
289
290template <typename PointCloudType, typename InnerPointType>
292{
293 const auto extrinsicParametersC = peak::common::detail::BackendAccessor<ExtrinsicParameters>::CreateCType(extrinsicParameters);
294
295 PointCloudType outputPointCloud{};
296 auto outputHandle = peak::common::detail::BackendAccessor<PointCloudType>::BackendHandleAddress(outputPointCloud);
298 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_TransformToWorkspace(
299 this->GetHandle(), extrinsicParametersC, sizeof(peak_icv_extrinsic_parameters), outputHandle);
300 });
301 return outputPointCloud;
302}
303
304template <typename PointCloudType, typename InnerPointType>
305typename std::vector<InnerPointType>::const_iterator PointCloud<PointCloudType, InnerPointType>::cbegin() const
306{
307 return GetPoints().cbegin();
308}
309
310template <typename PointCloudType, typename InnerPointType>
311typename std::vector<InnerPointType>::const_iterator PointCloud<PointCloudType, InnerPointType>::cend() const
312{
313 return GetPoints().cend();
314}
315
316template <typename PointCloudType, typename InnerPointType>
318 : m_pointCloudHandle{ CreateEmptyPointCloud() }
319{}
320
321template <typename PointCloudType, typename InnerPointType>
322detail::handle_of_t<PointCloud<PointCloudType, InnerPointType>> PointCloud<PointCloudType, InnerPointType>::GetHandle() const
323{
324 return m_pointCloudHandle;
325}
326
327template <typename PointCloudType, typename InnerPointType>
328detail::handle_of_t<PointCloud<PointCloudType, InnerPointType>>* PointCloud<PointCloudType, InnerPointType>::GetHandleAddress()
329{
330 return &m_pointCloudHandle;
331}
332
333template <typename PointCloudType, typename InnerPointType>
334peak_icv_point_cloud_handle PointCloud<PointCloudType, InnerPointType>::CreateEmptyPointCloud()
335{
336 peak_icv_point_cloud_handle handle{};
338 return PEAK_ICV_C_ABI_PREFIX peak_icv_PointCloud_Create(&handle);
339 });
340 return handle;
341}
342
343} // namespace detail
344} /* namespace icv */
345} /* namespace peak */
constexpr const Type * GetData() const
Returns a pointer to the underlying data of the array.
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...
Represents a generic point cloud interface for spatial data types.
PointCloudType TransformToWorkspace(const ExtrinsicParameters &extrinsicParameters) const
Transforms the point cloud to workspace coordinates using the specified extrinsic parameters.
PointCloud & operator=(const PointCloud &other)
PointCloud(const PointCloud &other)
PointCloudType Transform(const TransformationMatrix3D &matrix) const
Applies the specified transformation matrix to the point cloud.
bool operator==(const PointCloud &rhs) const
bool operator!=(const PointCloud &rhs) const
std::vector< PointType >::const_iterator cbegin() const
const std::vector< PointType > & GetPoints() const
PointCloud(PointCloud &&other) noexcept
PointCloud & operator=(PointCloud &&other) noexcept
std::vector< PointType >::const_iterator cend() const
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