CVB++ 14.0
point_cloud_factory.hpp
1#pragma once
2
3#include "_cexports/c_core_3d.h"
4
5#include "global.hpp"
6#include "string.hpp"
7#include "core_3d.hpp"
8#include "sparse_point_cloud.hpp"
9#include "dense_point_cloud.hpp"
10#include "calibrator_3d.hpp"
11#include "sensor_settings.hpp"
12
13namespace Cvb
14{
15
16CVB_BEGIN_INLINE_NS
17
19
21{
22 public:
23
25
31 template <class T>
32 static std::shared_ptr<T> Load(const String& fileName, PointCloudFlags flags)
33 {
34 static_assert(std::is_base_of<PointCloud, T>::value, "CVB: PointCloud must be a base of T");
35 auto pointCloud = std::dynamic_pointer_cast<T>(Load(fileName, flags));
36 if (!pointCloud)
37 throw std::runtime_error("point cloud does not match type");
38 return pointCloud;
39 }
40
42
48 static PointCloudPtr Load(const String& fileName, PointCloudFlags flags)
49 {
50 return Internal::DoResCallShareOut<PointCloud>([&](void* & handle)
51 {
52 return CVB_CALL_CAPI(CVC3DLoadFileTyped(fileName.c_str(), static_cast<CExports::cvbval_t>(flags), handle));
53 });
54 }
55
57
66 template <class T>
67 static std::shared_ptr<T> Create(const ImagePlane& rangeMap, const Calibrator3D& calibrator, PointCloudFlags flags)
68 {
69 static_assert(std::is_base_of<PointCloud, T>::value, "CVB: PointCloud must be a base of T");
70 auto pointCloud = Create(rangeMap, calibrator, flags);
71 auto typedPointCloud = std::dynamic_pointer_cast<T>(pointCloud);
72 if (!typedPointCloud)
73 typedPointCloud = TypeConvert<T>::Convert(*pointCloud);
74 return typedPointCloud;
75 }
76
78
92 static PointCloudPtr Create(const ImagePlane& rangeMap, const Calibrator3D& calibrator, PointCloudFlags flags)
93 {
94 return Internal::DoResCallShareOut<PointCloud>([&](void* & handle)
95 {
96 return CVB_CALL_CAPI(CVC3DCreateCalibratedPointCloudFromRangeMap(rangeMap.Map()->Handle(), calibrator.Handle(), static_cast<CExports::cvbval_t>(flags), handle));
97 });
98 }
99
101
113 template <class T>
114 static std::shared_ptr<T> CreateWithSettings(const ImagePlane& rangeMap, const Calibrator3D& calibrator, PointCloudFlags flags, const SensorSettings& settings, double encoderStep)
115 {
116 static_assert(std::is_base_of<PointCloud, T>::value, "CVB: PointCloud must be a base of T");
117 auto pointCloud = CreateWithSettings(rangeMap, calibrator, flags, settings, encoderStep);
118 auto typedPointCloud = std::dynamic_pointer_cast<T>(pointCloud);
119 if (!typedPointCloud)
120 typedPointCloud = TypeConvert<T>::Convert(*pointCloud);
121 return typedPointCloud;
122 }
123
125
144 static PointCloudPtr CreateWithSettings(const ImagePlane& rangeMap, const Calibrator3D& calibrator, PointCloudFlags flags, const SensorSettings& settings, double encoderStep)
145 {
146 return Internal::DoResCallShareOut<PointCloud>([&](void*& handle)
147 {
148 return CVB_CALL_CAPI(CVC3DCreateCalibratedPointCloudFromRangeMapWithSettings(
149 rangeMap.Map()->Handle(),
150 calibrator.Handle(),
151 *reinterpret_cast<CExports::CVC3DSensorSettings*>(const_cast<SensorSettings*>(&settings)),
152 encoderStep,
153 static_cast<CExports::cvbval_t>(flags), handle));
154 });
155 }
156
158
172 {
173 return std::dynamic_pointer_cast<SparsePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void * & handle)
174 {
175 return CVB_CALL_CAPI(CVC3DCreateSparsePointCloud(
176 static_cast<CExports::cvbint64_t>(numPoints),
177 static_cast<CExports::cvbval_t>(flags),
178 handle));
179 }));
180 }
181
183
194 static SparsePointCloudPtr CreateSparse(const std::vector<void*> & planeBasePtrs, int numPlanes, Cvb::DataType dataType, std::size_t numPoints, const std::vector<std::intptr_t> & planeIncs)
195 {
196 return std::dynamic_pointer_cast<SparsePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void * & handle)
197 {
198 std::intptr_t tmpPlaneIncs[4] = {};
199 std::copy(planeIncs.begin(), planeIncs.end(), tmpPlaneIncs);
200 return CVB_CALL_CAPI(CVC3DCreateSparsePointCloudFromPointer(
201 const_cast<void**>(planeBasePtrs.data()),
202 static_cast<CExports::cvbdim_t>(numPlanes),
203 static_cast<CExports::cvbdatatype_t>(dataType.NativeDescriptor()),
204 static_cast<std::size_t>(numPoints),
205 tmpPlaneIncs,
206 [](void *, void *) {},
207 nullptr,
208 handle));
209 }));
210 }
211
213
227 {
228 return std::dynamic_pointer_cast<DensePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void * & handle)
229 {
230 return CVB_CALL_CAPI(CVC3DCreateDensePointCloud(size.Width(), size.Height(), static_cast<CExports::cvbval_t>(flags), handle));
231 }));
232 }
233
234
236
244 {
245 return std::dynamic_pointer_cast<DensePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void* & handle)
246 {
247 return CVB_CALL_CAPI(CVC3DCreateDensePointCloudFromRangeMap(rangeMap.Map()->Handle(),
248 *reinterpret_cast<CExports::CVC3DFactors*>(&factors), static_cast<CExports::cvbval_t>(flags),
249 handle));
250 }));
251
252 }
253
254 private:
255
256 template <class T>
257 struct TypeConvert{};
258};
259
260
261template <>
262struct PointCloudFactory::TypeConvert<DensePointCloud>
263{
264 static DensePointCloudPtr Convert(const PointCloud& pointCloud)
265 {
266 const auto& sparse = dynamic_cast<const SparsePointCloud&>(pointCloud);
267 return sparse.ToDensePointCloud();
268 }
269};
270
271template <>
272struct PointCloudFactory::TypeConvert<SparsePointCloud>
273{
274 static SparsePointCloudPtr Convert(const PointCloud& pointCloud)
275 {
276 const auto& dense = dynamic_cast<const DensePointCloud&>(pointCloud);
277 return dense.ToSparsePointCloud();
278 }
279};
280
281
282CVB_END_INLINE_NS
283
284}
Base calibration class to apply 3D calibration to point clouds.
Definition: decl_calibrator_3d.hpp:67
void * Handle() const noexcept
Returns C-API style handle to Node Object.
Definition: decl_calibrator_3d.hpp:176
Data type description for an image plane.
Definition: data_type.hpp:28
int NativeDescriptor() const noexcept
Native data type descriptor.
Definition: data_type.hpp:322
Image plane information container.
Definition: decl_image_plane.hpp:33
std::unique_ptr< Image > Map() const
Create a map from a single image plane that shares its memory with the original plane.
Definition: detail_image_plane.hpp:100
Factory object for creating point cloud objects.
Definition: point_cloud_factory.hpp:21
static SparsePointCloudPtr CreateSparse(const std::vector< void * > &planeBasePtrs, int numPlanes, Cvb::DataType dataType, std::size_t numPoints, const std::vector< std::intptr_t > &planeIncs)
Creates a point cloud from the given memory without copying the data.
Definition: point_cloud_factory.hpp:194
static PointCloudPtr Load(const String &fileName, PointCloudFlags flags)
Loads a 3D point, polygon or mesh file.
Definition: point_cloud_factory.hpp:48
static SparsePointCloudPtr CreateSparse(std::size_t numPoints, PointCloudFlags flags)
Creates a new sparse Cartesian 3D point cloud.
Definition: point_cloud_factory.hpp:171
static std::shared_ptr< T > Load(const String &fileName, PointCloudFlags flags)
Loads a 3D point, polygon or mesh file (typed).
Definition: point_cloud_factory.hpp:32
static std::shared_ptr< T > Create(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image (typed).
Definition: point_cloud_factory.hpp:67
static DensePointCloudPtr CreateDense(const Cvb::ImagePlane &rangeMap, Factors3D factors, PointCloudFlags flags)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image.
Definition: point_cloud_factory.hpp:243
static DensePointCloudPtr CreateDense(Size2D< int > size, PointCloudFlags flags)
Creates a new dense Cartesian 3D point cloud.
Definition: point_cloud_factory.hpp:226
static PointCloudPtr CreateWithSettings(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags, const SensorSettings &settings, double encoderStep)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image with modified camera setti...
Definition: point_cloud_factory.hpp:144
static std::shared_ptr< T > CreateWithSettings(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags, const SensorSettings &settings, double encoderStep)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image with modified camera setti...
Definition: point_cloud_factory.hpp:114
static PointCloudPtr Create(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags)
Creates a new Cartesian 3D point cloud from the given 2.5D range map image.
Definition: point_cloud_factory.hpp:92
Class to store camera sensor settings.
Definition: sensor_settings.hpp:26
T Height() const noexcept
Gets the vertical component of the size.
Definition: size_2d.hpp:79
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
PointCloudFlags
Flags for creating point clouds.
Definition: core_3d.hpp:90
std::shared_ptr< SparsePointCloud > SparsePointCloudPtr
Convenience shared pointer for SparsePointCloud.
Definition: core_3d.hpp:48
std::shared_ptr< DensePointCloud > DensePointCloudPtr
Convenience shared pointer for DensePointCloud.
Definition: core_3d.hpp:44
Factor components to be applied in the 3D domain.
Definition: core_3d.hpp:17