CVB++ 15.0
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
33 class SparsePointCloud : public PointCloud
34 {
35 friend class PointCloud;
36
37 public:
38 static SparsePointCloudPtr FromHandle(HandleGuard<PointCloud> &&guard)
39 {
40 if (IsDense(guard.Handle()))
41 throw std::runtime_error("handle is not a sparse point cloud");
42 return std::make_shared<SparsePointCloud>(std::move(guard), PrivateTag{});
43 }
44
45 template <class T>
46 static SparsePointCloudPtr FromHandle(HandleGuard<PointCloud> &&guard)
47 {
48 return FromHandle(std::move(guard));
49 }
50
51 SparsePointCloud(HandleGuard<PointCloud> &&guard, PrivateTag) noexcept
52 : PointCloud(std::move(guard))
53 {
54 }
55
57
64 static SparsePointCloudPtr FromDensePointCloud(const DensePointCloud &densePointCloud);
65
67
76
78
93 DensePointCloudPtr ToDensePointCloud(size_t &numDroppedPoints,
94 ConversionMode conversionMode = ConversionMode::Automatic) const
95 {
96 (void)conversionMode; // just to suppress warning 4100, unreferenced formal parameter
97
98 return Internal::DoResCallShareOut<DensePointCloud>([&](void *&handle) {
99 return CVB_CALL_CAPI(CVC3DConvertSparseToDensePointCloudAutomatic(Handle(), handle, numDroppedPoints);)
100 });
101 }
102
104
119 {
120 size_t numDroppedPoints = 0;
121 return ToDensePointCloud(numDroppedPoints, conversionMode);
122 }
123
125 SparsePointCloudPtr Crop(const Cuboid &clipBox) const
126 {
127 return Internal::DoResCallShareOut<SparsePointCloud>([&](void *&handle) {
128 return CVB_CALL_CAPI(
129 CVC3DCreateCroppedPointCloud(Handle(), *reinterpret_cast<const CExports::CVC3DCuboid *>(&clipBox), handle));
130 });
131 }
132
134 SparsePointCloudPtr FrustumCrop(const Cuboid &clipBox, Angle theta, Angle phi) const
135 {
136 return Internal::DoResCallShareOut<SparsePointCloud>([&](void *&handle) {
137 return CVB_CALL_CAPI(CVC3DCreateFrustumCroppedPointCloud(
138 Handle(), *reinterpret_cast<const CExports::CVC3DCuboid *>(&clipBox), theta.Deg(), phi.Deg(), handle));
139 });
140 }
141
144
167 SparsePointCloudPtr PlaneCrop(const Plane3D &plane, const ValueRange<double> &range, CropRange cropRange) const
168 {
169 return PointCloud::PlaneCrop<SparsePointCloud>(plane, range, cropRange);
170 }
171
174
199 SparsePointCloudPtr PlaneCrop(const Plane3D &plane, double threshold,
200 CropDirection cropBelowAbove = CropDirection::Below) const
201 {
202 return PointCloud::PlaneCrop<SparsePointCloud>(plane, threshold, cropBelowAbove);
203 }
204
206
210 template <class T>
212 {
213 ComponentsPointers3D rawComponents;
214 auto error = PointCloud::TryPointComponents<T>(rawComponents);
215 if (error)
217 return SparseComponentsPointers3D<T>(rawComponents);
218 }
219
221
228 template <class T>
229 bool TryPointComponents(SparseComponentsPointers3D<T> &components) const noexcept
230 {
231 ComponentsPointers3D rawComponents;
232 auto error = PointCloud::TryPointComponents<T>(rawComponents);
233 if (error)
234 return false;
235 components = SparseComponentsPointers3D<T>(rawComponents);
236 return true;
237 }
238 };
239
240 CVB_END_INLINE_NS
241
242} // 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
An organized dense Cartesian 3D point cloud object.
Definition decl_dense_point_cloud.hpp:35
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:391
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:764
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:229
SparseComponentsPointers3D< T > PointComponents() const
Get the point components from the given point cloud.
Definition decl_sparse_point_cloud.hpp:211
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:93
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:167
static SparsePointCloudPtr FromComposite(CompositePtr object)
Creates a sparse point cloud from a composite.
Definition decl_sparse_point_cloud.hpp:72
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:125
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:199
DensePointCloudPtr ToDensePointCloud(ConversionMode conversionMode=ConversionMode::Automatic) const
Creates a dense point cloud from a sparse point cloud.
Definition decl_sparse_point_cloud.hpp:118
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:134
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)