CVB++ 15.0
Loading...
Searching...
No Matches
decl_sparse_point_cloud.hpp
1#pragma once
2
3#include <type_traits>
4#include <stdexcept>
5
6#include "decl_point_cloud.hpp"
7
8#include "../sparse_components_pointers_3d.hpp"
9
10namespace Cvb
11{
12
13 CVB_BEGIN_INLINE_NS
14
28 class SparsePointCloud : public PointCloud
29 {
30 friend class PointCloud;
31
32 public:
33 static SparsePointCloudPtr FromHandle(HandleGuard<PointCloud> &&guard)
34 {
35 if (IsDense(guard.Handle()))
36 throw std::runtime_error("handle is not a sparse point cloud");
37 return std::make_shared<SparsePointCloud>(std::move(guard), PrivateTag{});
38 }
39
40 template <class T>
41 static SparsePointCloudPtr FromHandle(HandleGuard<PointCloud> &&guard)
42 {
43 return FromHandle(std::move(guard));
44 }
45
46 SparsePointCloud(HandleGuard<PointCloud> &&guard, PrivateTag) noexcept
47 : PointCloud(std::move(guard))
48 {
49 }
50
52
59 static SparsePointCloudPtr FromDensePointCloud(const DensePointCloud &densePointCloud);
60
62
71
73
88 DensePointCloudPtr ToDensePointCloud(size_t &numDroppedPoints,
89 ConversionMode conversionMode = ConversionMode::Automatic) const
90 {
91 (void)conversionMode; // just to suppress warning 4100, unreferenced formal parameter
92
93 return Internal::DoResCallShareOut<DensePointCloud>([&](void *&handle) {
94 return CVB_CALL_CAPI(CVC3DConvertSparseToDensePointCloudAutomatic(Handle(), handle, numDroppedPoints);)
95 });
96 }
97
99
114 {
115 size_t numDroppedPoints = 0;
116 return ToDensePointCloud(numDroppedPoints, conversionMode);
117 }
118
120 SparsePointCloudPtr Crop(const Cuboid &clipBox) const
121 {
122 return Internal::DoResCallShareOut<SparsePointCloud>([&](void *&handle) {
123 return CVB_CALL_CAPI(
124 CVC3DCreateCroppedPointCloud(Handle(), *reinterpret_cast<const CExports::CVC3DCuboid *>(&clipBox), handle));
125 });
126 }
127
129 SparsePointCloudPtr FrustumCrop(const Cuboid &clipBox, Angle theta, Angle phi) const
130 {
131 return Internal::DoResCallShareOut<SparsePointCloud>([&](void *&handle) {
132 return CVB_CALL_CAPI(CVC3DCreateFrustumCroppedPointCloud(
133 Handle(), *reinterpret_cast<const CExports::CVC3DCuboid *>(&clipBox), theta.Deg(), phi.Deg(), handle));
134 });
135 }
136
139
162 SparsePointCloudPtr PlaneCrop(const Plane3D &plane, const ValueRange<double> &range, CropRange cropRange) const
163 {
164 return PointCloud::PlaneCrop<SparsePointCloud>(plane, range, cropRange);
165 }
166
169
194 SparsePointCloudPtr PlaneCrop(const Plane3D &plane, double threshold,
195 CropDirection cropBelowAbove = CropDirection::Below) const
196 {
197 return PointCloud::PlaneCrop<SparsePointCloud>(plane, threshold, cropBelowAbove);
198 }
199
201
205 template <class T>
207 {
208 ComponentsPointers3D rawComponents;
209 auto error = PointCloud::TryPointComponents<T>(rawComponents);
210 if (error)
212 return SparseComponentsPointers3D<T>(rawComponents);
213 }
214
216
223 template <class T>
224 bool TryPointComponents(SparseComponentsPointers3D<T> &components) const noexcept
225 {
226 ComponentsPointers3D rawComponents;
227 auto error = PointCloud::TryPointComponents<T>(rawComponents);
228 if (error)
229 return false;
230 components = SparseComponentsPointers3D<T>(rawComponents);
231 return true;
232 }
233 };
234
235 CVB_END_INLINE_NS
236
237} // namespace Cvb
Object for convenient and type - safe handling of angles.
Definition angle.hpp:16
double Deg() const noexcept
Get the value in degrees.
Definition angle.hpp:89
Point components of the point cloud.
Definition components_pointers_3d.hpp:18
3D rectangle in the X, Y and Z domain.
Definition cuboid.hpp:19
A dense Cartesian 3D point cloud object.
Definition decl_dense_point_cloud.hpp:30
A plane in 3D space in Hessian normal form.
Definition plane_3d.hpp:19
std::shared_ptr< T > PlaneCrop(const Plane3D &plane, const ValueRange< double > &range, CropRange cropRange) const
Creates a new point cloud where points within or outside a range parallel to given plane are cropped.
Definition decl_point_cloud.hpp:377
static std::shared_ptr< T > FromComposite(CompositePtr object)
Creates a point cloud from a composite.
Definition detail_point_cloud.hpp:27
void * Handle() const noexcept
Returns C-API style handle to Node Object.
Definition decl_point_cloud.hpp:773
Point components of a sparse point cloud.
Definition sparse_components_pointers_3d.hpp:14
bool TryPointComponents(SparseComponentsPointers3D< T > &components) const noexcept
Tries to get the point components from the given point cloud.
Definition decl_sparse_point_cloud.hpp:224
SparseComponentsPointers3D< T > PointComponents() const
Get the point components from the given point cloud.
Definition decl_sparse_point_cloud.hpp:206
DensePointCloudPtr ToDensePointCloud(size_t &numDroppedPoints, ConversionMode conversionMode=ConversionMode::Automatic) const
Creates a dense point cloud from a sparse point cloud.
Definition decl_sparse_point_cloud.hpp:88
SparsePointCloudPtr PlaneCrop(const Plane3D &plane, const ValueRange< double > &range, CropRange cropRange) const
Creates a new point cloud where points within or outside a range parallel to given plane are cropped.
Definition decl_sparse_point_cloud.hpp:162
static SparsePointCloudPtr FromComposite(CompositePtr object)
Creates a sparse point cloud from a composite.
Definition decl_sparse_point_cloud.hpp:67
SparsePointCloudPtr Crop(const Cuboid &clipBox) const
Creates a new point cloud which only consists of the points inside the clip box.
Definition decl_sparse_point_cloud.hpp:120
SparsePointCloudPtr PlaneCrop(const Plane3D &plane, double threshold, CropDirection cropBelowAbove=CropDirection::Below) const
Creates a new point cloud which only consists of the points below or above given plane.
Definition decl_sparse_point_cloud.hpp:194
DensePointCloudPtr ToDensePointCloud(ConversionMode conversionMode=ConversionMode::Automatic) const
Creates a dense point cloud from a sparse point cloud.
Definition decl_sparse_point_cloud.hpp:113
static SparsePointCloudPtr FromDensePointCloud(const DensePointCloud &densePointCloud)
Creates a sparse point cloud from a dense point cloud with confidence plane.
Definition detail_sparse_point_cloud.hpp:10
SparsePointCloudPtr FrustumCrop(const Cuboid &clipBox, Angle theta, Angle phi) const
Creates a new point cloud which only consists of the points inside the clipBox, where the orientation...
Definition decl_sparse_point_cloud.hpp:129
Container for range definitions.
Definition value_range.hpp:17
T make_shared(T... args)
T move(T... args)
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
CropRange
Indicates cropping range.
Definition core_3d.hpp:288
std::shared_ptr< SparsePointCloud > SparsePointCloudPtr
Convenience shared pointer for SparsePointCloud.
Definition core_3d.hpp:48
ConversionMode
Mode used by conversion to dense point cloud.
Definition global.hpp:524
@ Automatic
Definition global.hpp:528
CropDirection
Indicates cropping direction.
Definition core_3d.hpp:301
@ Below
Crop below given plane.
Definition core_3d.hpp:305
std::shared_ptr< Composite > CompositePtr
Convenience shared pointer for Composite.
Definition global.hpp:102
std::shared_ptr< DensePointCloud > DensePointCloudPtr
Convenience shared pointer for DensePointCloud.
Definition core_3d.hpp:44
T rethrow_exception(T... args)