CVB++ 15.0
Loading...
Searching...
No Matches
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
16 CVB_BEGIN_INLINE_NS
17
19
32 {
33 public:
35
41 template <class T>
42 static std::shared_ptr<T> Load(const String &fileName, PointCloudFlags flags)
43 {
44 static_assert(std::is_base_of<PointCloud, T>::value, "CVB: PointCloud must be a base of T");
45 auto pointCloud = std::dynamic_pointer_cast<T>(Load(fileName, flags));
46 if (!pointCloud)
47 throw std::runtime_error("point cloud does not match type");
48 return pointCloud;
49 }
50
52
58 static PointCloudPtr Load(const String &fileName, PointCloudFlags flags)
59 {
60 return Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
61 return CVB_CALL_CAPI(CVC3DLoadFileTyped(fileName.c_str(), static_cast<CExports::cvbval_t>(flags), handle));
62 });
63 }
64
66
101 static PointCloudPtr Create(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags)
102 {
103 return Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
104 return CVB_CALL_CAPI(CVC3DCreateCalibratedPointCloudFromRangeMap(
105 rangeMap.Map()->Handle(), calibrator.Handle(), static_cast<CExports::cvbval_t>(flags), handle));
106 });
107 }
108
110
123 template <class T>
124 static std::shared_ptr<T> Create(const ImagePlane &rangeMap, const Calibrator3D &calibrator, PointCloudFlags flags)
125 {
126 static_assert(std::is_base_of<PointCloud, T>::value, "CVB: PointCloud must be a base of T");
127 auto pointCloud = Create(rangeMap, calibrator, flags);
128 auto typedPointCloud = std::dynamic_pointer_cast<T>(pointCloud);
129 if (!typedPointCloud)
130 typedPointCloud = TypeConvert<T>::Convert(*pointCloud);
131 return typedPointCloud;
132 }
133
135
171 static PointCloudPtr CreateWithSettings(const ImagePlane &rangeMap, const Calibrator3D &calibrator,
172 PointCloudFlags flags, const SensorSettings &settings, double encoderStep)
173 {
174 return Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
175 return CVB_CALL_CAPI(CVC3DCreateCalibratedPointCloudFromRangeMapWithSettings(
176 rangeMap.Map()->Handle(), calibrator.Handle(),
177 *reinterpret_cast<const CExports::CVC3DSensorSettings *>(&settings), encoderStep,
178 static_cast<CExports::cvbval_t>(flags), handle));
179 });
180 }
181
184
197 template <class T>
198 static std::shared_ptr<T> CreateWithSettings(const ImagePlane &rangeMap, const Calibrator3D &calibrator,
199 PointCloudFlags flags, const SensorSettings &settings,
200 double encoderStep)
201 {
202 static_assert(std::is_base_of<PointCloud, T>::value, "CVB: PointCloud must be a base of T");
203 auto pointCloud = CreateWithSettings(rangeMap, calibrator, flags, settings, encoderStep);
204 auto typedPointCloud = std::dynamic_pointer_cast<T>(pointCloud);
205 if (!typedPointCloud)
206 typedPointCloud = TypeConvert<T>::Convert(*pointCloud);
207 return typedPointCloud;
208 }
209
211
225 {
226 return std::dynamic_pointer_cast<SparsePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
227 return CVB_CALL_CAPI(CVC3DCreateSparsePointCloud(static_cast<CExports::cvbint64_t>(numPoints),
228 static_cast<CExports::cvbval_t>(flags), handle));
229 }));
230 }
231
233
244 static SparsePointCloudPtr CreateSparse(const std::vector<void *> &planeBasePtrs, int numPlanes,
245 Cvb::DataType dataType, std::size_t numPoints,
246 const std::vector<std::intptr_t> &planeIncs)
247 {
248 return std::dynamic_pointer_cast<SparsePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
249 std::intptr_t tmpPlaneIncs[4] = {}; // NOLINT(cppcoreguidelines-avoid-c-arrays)
250 std::copy(planeIncs.begin(), planeIncs.end(), std::begin(tmpPlaneIncs));
251 return CVB_CALL_CAPI(CVC3DCreateSparsePointCloudFromPointer(
252 const_cast<void **>(planeBasePtrs.data()), // NOLINT(cppcoreguidelines-pro-type-const-cast)
253 static_cast<CExports::cvbdim_t>(numPlanes),
254 static_cast<CExports::cvbdatatype_t>(dataType.NativeDescriptor()), static_cast<std::size_t>(numPoints),
255 tmpPlaneIncs, [](void *, void *) {}, nullptr, handle));
256 }));
257 }
258
260
274 {
275 return std::dynamic_pointer_cast<DensePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
276 return CVB_CALL_CAPI(
277 CVC3DCreateDensePointCloud(size.Width(), size.Height(), static_cast<CExports::cvbval_t>(flags), handle));
278 }));
279 }
280
282
296 {
297 return std::dynamic_pointer_cast<DensePointCloud>(Internal::DoResCallShareOut<PointCloud>([&](void *&handle) {
298 return CVB_CALL_CAPI(CVC3DCreateDensePointCloudFromRangeMap(
299 rangeMap.Map()->Handle(), *reinterpret_cast<CExports::CVC3DFactors *>(&factors),
300 static_cast<CExports::cvbval_t>(flags), handle));
301 }));
302 }
303
304 private:
305 template <class T>
306 struct TypeConvert
307 {
308 };
309 };
310
311 template <>
312 struct PointCloudFactory::TypeConvert<DensePointCloud>
313 {
314 static DensePointCloudPtr Convert(const PointCloud &pointCloud)
315 {
316 const auto &sparse = dynamic_cast<const SparsePointCloud &>(pointCloud);
317 return sparse.ToDensePointCloud();
318 }
319 };
320
321 template <>
322 struct PointCloudFactory::TypeConvert<SparsePointCloud>
323 {
324 static SparsePointCloudPtr Convert(const PointCloud &pointCloud)
325 {
326 const auto &dense = dynamic_cast<const DensePointCloud &>(pointCloud);
327 return dense.ToSparsePointCloud();
328 }
329 };
330
331 CVB_END_INLINE_NS
332
333} // namespace Cvb
T begin(T... args)
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:185
Data type description for an image plane.
Definition data_type.hpp:23
int NativeDescriptor() const noexcept
Native data type descriptor.
Definition data_type.hpp:312
An organized dense Cartesian 3D point cloud object.
Definition decl_dense_point_cloud.hpp:35
Image plane information container.
Definition decl_image_plane.hpp:29
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:32
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:244
static PointCloudPtr Load(const String &fileName, PointCloudFlags flags)
Loads a 3D point, polygon or mesh file.
Definition point_cloud_factory.hpp:58
static SparsePointCloudPtr CreateSparse(std::size_t numPoints, PointCloudFlags flags)
Creates a new sparse Cartesian 3D point cloud.
Definition point_cloud_factory.hpp:224
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:42
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:124
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:295
static DensePointCloudPtr CreateDense(Size2D< int > size, PointCloudFlags flags)
Creates a new dense Cartesian 3D point cloud.
Definition point_cloud_factory.hpp:273
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:171
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:198
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:101
Class to store camera sensor settings.
Definition sensor_settings.hpp:26
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
An unorganized sparse Cartesian 3D point cloud object.
Definition decl_sparse_point_cloud.hpp:34
T copy(T... args)
Root namespace for the Image Manager interface.
Definition version.hpp:11
PointCloudFlags
Flags for creating point clouds.
Definition core_3d.hpp:90
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
std::shared_ptr< PointCloud > PointCloudPtr
Convenience shared pointer for PointCloud.
Definition core_3d.hpp:40
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
T dynamic_pointer_cast(T... args)
Factor components to be applied in the 3D domain.
Definition core_3d.hpp:16