Zivid C++ API 2.18.0+1b44dbef-1
PointCloud.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of the Zivid API
3 *
4 * Copyright 2015-2026 (C) Zivid AS
5 * All rights reserved.
6 *
7 * Zivid Software License, v1.0
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of Zivid AS nor the names of its contributors may be used
20 * to endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * 4. This software, with or without modification, must not be used with any
24 * other 3D camera than from Zivid AS.
25 *
26 * 5. Any software provided in binary form under this license must not be
27 * reverse engineered, decompiled, modified and/or disassembled.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
41 * Info: http://www.zivid.com
42 ******************************************************************************/
43
44#pragma once
45
46#include "Zivid/Array2D.h"
49#include "Zivid/DeviceArray.h"
50#include "Zivid/Image.h"
51#include "Zivid/Mask.h"
52#include "Zivid/Matrix.h"
53#include "Zivid/Normal.h"
54#include "Zivid/Point.h"
56#include "Zivid/Resolution.h"
57#include "Zivid/SNR.h"
58#include "Zivid/Settings.h"
60
61#include <iosfwd>
62#include <memory>
63#include <string>
64
65namespace Zivid
66{
67 class Frame;
68
87 {
88 public:
95 enum class Downsampling
96 {
100 };
101
104
106 ZIVID_CORE_EXPORT size_t width() const;
107
109 ZIVID_CORE_EXPORT size_t height() const;
110
113 ZIVID_CORE_EXPORT size_t size() const;
114
118
121
137
157
169
186
203
224
242
260
277
290
312
331
349
356
370
373
376
379
382
385
387 template<
388 typename ColorFormat,
389 typename = std::enable_if_t<Detail::SupportedImageDeviceArrayColorFormat<ColorFormat>::value>>
391
403 template<
404 typename ColorFormat,
405 typename = std::enable_if_t<Detail::SupportedImageDeviceArrayColorFormat<ColorFormat>::value>>
406 void imageDeviceArray(DeviceArrayView<ColorFormat> destinationBuffer, StreamOrQueue streamOrQueue) const;
407
421
436
450
464
476 template<typename DataFormat>
478 {
479 static_assert(
480 HasCopyDataImplReturnArray2DTag<DataFormat>::value,
481 "The provided DataFormat is unsupported. Please refer to the documentation for "
482 "this method for the supported DataFormats.");
483 return copyDataImpl(ReturnArray2DTag<DataFormat>{});
484 }
485
572 template<typename DataFormat>
573 void copyData(DataFormat *destination) const
574 {
575 static_assert(
576 HasCopyDataImpl<DataFormat *>::value,
577 "The provided DataFormat is unsupported. Please refer to the documentation for "
578 "this method for the supported data formats.");
579 return copyDataImpl(destination);
580 }
581
584 ZIVID_CORE_EXPORT std::string toString() const;
585
591
599
611
642
651
666
676
688
696
708
725
726#ifndef NO_DOC
727 ZIVID_CORE_EXPORT class PointCloudImpl &getImpl();
728 ZIVID_CORE_EXPORT const class PointCloudImpl &getImpl() const;
729 ZIVID_CORE_EXPORT explicit PointCloud(std::shared_ptr<class PointCloudImpl> other);
730#endif
731
732 private:
733 template<class T>
734 struct ReturnArray2DTag
735 {};
736
737 template<typename... Args>
738 class HasCopyDataImplReturnArray2DTag
739 {
740 template<
741 typename C,
742 typename = decltype(std::declval<C>().copyDataImpl(std::declval<ReturnArray2DTag<Args>>()...))>
743 static std::true_type test(int);
744 template<typename C>
745 static std::false_type test(...);
746
747 public:
748 static constexpr bool value = decltype(test<PointCloud>(0))::value;
749 };
750
751 template<typename... Args>
752 class HasCopyDataImpl
753 {
754 template<typename C, typename = decltype(std::declval<C>().copyDataImpl(std::declval<Args>()...))>
755 static std::true_type test(int);
756 template<typename C>
757 static std::false_type test(...);
758
759 public:
760 static constexpr bool value = decltype(test<PointCloud>(0))::value;
761 };
762
763 ZIVID_CORE_EXPORT Array2D<PointXYZ> copyDataImpl(ReturnArray2DTag<PointXYZ> /*tag*/) const;
764 ZIVID_CORE_EXPORT Array2D<PointXYZW> copyDataImpl(ReturnArray2DTag<PointXYZW> /*tag*/) const;
765 ZIVID_CORE_EXPORT Array2D<PointZ> copyDataImpl(ReturnArray2DTag<PointZ> /*tag*/) const;
766 ZIVID_CORE_EXPORT Array2D<ColorRGBA> copyDataImpl(ReturnArray2DTag<ColorRGBA> /*tag*/) const;
767 ZIVID_CORE_EXPORT Array2D<ColorBGRA> copyDataImpl(ReturnArray2DTag<ColorBGRA> /*tag*/) const;
768 ZIVID_CORE_EXPORT Array2D<ColorRGBA_SRGB> copyDataImpl(ReturnArray2DTag<ColorRGBA_SRGB> /*tag*/) const;
769 ZIVID_CORE_EXPORT Array2D<ColorBGRA_SRGB> copyDataImpl(ReturnArray2DTag<ColorBGRA_SRGB> /*tag*/) const;
770 ZIVID_CORE_EXPORT Array2D<PointXYZColorRGBA> copyDataImpl(ReturnArray2DTag<PointXYZColorRGBA> /*tag*/) const;
771 ZIVID_CORE_EXPORT Array2D<PointXYZColorRGBA_SRGB> copyDataImpl(
772 ReturnArray2DTag<PointXYZColorRGBA_SRGB> /*tag*/) const;
773 ZIVID_CORE_EXPORT Array2D<PointXYZColorBGRA> copyDataImpl(ReturnArray2DTag<PointXYZColorBGRA> /*tag*/) const;
774 ZIVID_CORE_EXPORT Array2D<PointXYZColorBGRA_SRGB> copyDataImpl(
775 ReturnArray2DTag<PointXYZColorBGRA_SRGB> /*tag*/) const;
776 ZIVID_CORE_EXPORT Array2D<SNR> copyDataImpl(ReturnArray2DTag<SNR> /*tag*/) const;
777 ZIVID_CORE_EXPORT Array2D<NormalXYZ> copyDataImpl(ReturnArray2DTag<NormalXYZ> /*tag*/) const;
778 ZIVID_CORE_EXPORT void copyDataImpl(PointXYZ *destination) const;
779 ZIVID_CORE_EXPORT void copyDataImpl(PointXYZW *destination) const;
780 ZIVID_CORE_EXPORT void copyDataImpl(PointZ *destination) const;
781 ZIVID_CORE_EXPORT void copyDataImpl(ColorRGBA *destination) const;
782 ZIVID_CORE_EXPORT void copyDataImpl(struct ColorRGBAf *destination) const;
783 ZIVID_CORE_EXPORT void copyDataImpl(ColorBGRA *destination) const;
784 ZIVID_CORE_EXPORT void copyDataImpl(ColorRGBA_SRGB *destination) const;
785 ZIVID_CORE_EXPORT void copyDataImpl(ColorBGRA_SRGB *destination) const;
786 ZIVID_CORE_EXPORT void copyDataImpl(PointXYZColorRGBA *destination) const;
787 ZIVID_CORE_EXPORT void copyDataImpl(PointXYZColorRGBA_SRGB *destination) const;
788 ZIVID_CORE_EXPORT void copyDataImpl(PointXYZColorBGRA *destination) const;
789 ZIVID_CORE_EXPORT void copyDataImpl(PointXYZColorBGRA_SRGB *destination) const;
790 ZIVID_CORE_EXPORT void copyDataImpl(SNR *destination) const;
791 ZIVID_CORE_EXPORT void copyDataImpl(NormalXYZ *destination) const;
792
793 std::shared_ptr<class PointCloudImpl> m_impl;
794 };
795
797 ZIVID_CORE_EXPORT std::ostream &operator<<(std::ostream &stream, const PointCloud &pointCloud);
798
799#ifndef NO_DOC
801 namespace Detail
802 {
803 ZIVID_CORE_EXPORT void waitUntilProcessingIsComplete(const PointCloud &pointCloud);
804 } // namespace Detail
805#endif
806
807#ifndef NO_DOC
808# define ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN(Format) \
809 extern template ZIVID_CORE_EXPORT DeviceArray<Format> PointCloud::imageDeviceArray<Format>(StreamOrQueue) \
810 const; \
811 extern template ZIVID_CORE_EXPORT void \
812 PointCloud::imageDeviceArray<Format>(DeviceArrayView<Format>, StreamOrQueue) const
813
814 ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN(ColorRGBA);
815 ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN(ColorRGBA_SRGB);
816 ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN(ColorBGRA);
817 ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN(ColorBGRA_SRGB);
818 ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN(ColorRGBAf);
819# undef ZIVID_POINT_CLOUD_IMAGE_DEVICE_ARRAY_EXTERN
820#endif
821} // namespace Zivid
#define ZIVID_CORE_EXPORT
Definition CoreExport.h:56
Two-dimensional container of data.
Definition Array2D.h:83
Non-owning view of a device buffer.
Definition DeviceArray.h:270
Reference-counted handle to data on a GPU device.
Definition DeviceArray.h:94
A frame captured by a Zivid camera.
Definition Frame.h:70
A 2-dimensional image.
Definition Image.h:141
A mask for filtering point cloud data.
Definition Mask.h:63
Point cloud with x, y, z, RGB color and SNR laid out on a 2D grid.
Definition PointCloud.h:87
ZIVID_CORE_EXPORT DeviceArray< PointXYZ > devicePointsXYZ(StreamOrQueue streamOrQueue) const
Get a device buffer containing XYZ point coordinates, synchronized to the user's stream/queue.
ZIVID_CORE_EXPORT Image< ColorBGRA_SRGB > copyImageBGRA_SRGB() const
Get point cloud colors as 8-bit BGRA image in the sRGB color space.
ZIVID_CORE_EXPORT DeviceArray< SNR > deviceSNRs(StreamOrQueue streamOrQueue) const
Get a device buffer containing SNR values, synchronized to the user's stream/queue.
ZIVID_CORE_EXPORT Array2D< PointXYZW > copyPointsXYZW() const
Array2D of point coordinates in 4D.
ZIVID_CORE_EXPORT Array2D< PointXYZColorRGBA_SRGB > copyPointsXYZColorsRGBA_SRGB() const
Array2D of PointXYZColorRGBA_SRGB.
ZIVID_CORE_EXPORT PointCloud clone() const
Returns a clone of the point cloud. The clone will include a copy of all of the point cloud data on t...
ZIVID_CORE_EXPORT PointCloud masked(const Zivid::Mask &mask) const
Get a masked point cloud.
ZIVID_CORE_EXPORT Resolution resolution() const
Get the resolution of the point cloud.
ZIVID_CORE_EXPORT DeviceArray< NormalXYZ > deviceNormalsXYZ(StreamOrQueue streamOrQueue) const
Get a device buffer containing normal vectors, synchronized to the user's stream/queue.
ZIVID_CORE_EXPORT PointCloud & downsample(Downsampling downsampling)
Downsample the point cloud in-place.
ZIVID_CORE_EXPORT PointCloud transformed(const Zivid::Matrix4x4 &matrix) const
Transform the point cloud by the given 4x4 transformation matrix.
ZIVID_CORE_EXPORT Image< ColorRGBA > copyImageRGBA() const
Get point cloud colors as 8-bit RGBA image.
void copyData(DataFormat *destination) const
Copy data in the specified DataFormat to a destination buffer.
Definition PointCloud.h:573
ZIVID_CORE_EXPORT DeviceArray< PointZ > devicePointsZ(StreamOrQueue streamOrQueue) const
Get a device buffer containing Z point coordinates, synchronized to the user's stream/queue.
ZIVID_CORE_EXPORT Array2D< SNR > copySNRs() const
Array2D of SNR values.
ZIVID_CORE_EXPORT PointCloud & transform(const Zivid::Matrix4x4 &matrix)
Transform the point cloud in-place by the given 4x4 transformation matrix.
Downsampling
Option for downsampling.
Definition PointCloud.h:96
@ by4x4
Definition PointCloud.h:99
@ by3x3
Definition PointCloud.h:98
@ by2x2
Definition PointCloud.h:97
ZIVID_CORE_EXPORT PointCloud maskedByRegionOfInterest(const Zivid::Settings::RegionOfInterest::Box &roiSettings) const
Apply region of interest filtering to a copy of the point cloud.
void imageDeviceArray(DeviceArrayView< ColorFormat > destinationBuffer, StreamOrQueue streamOrQueue) const
Fill a user-provided DeviceArrayView with the point cloud's color image in the specified format.
ZIVID_CORE_EXPORT DeviceArray< PointXYZW > devicePointsXYZW(StreamOrQueue streamOrQueue) const
Get a device buffer containing XYZW point coordinates, synchronized to the user's stream/queue.
ZIVID_CORE_EXPORT Array2D< ColorRGBA > copyColorsRGBA() const
Array2D of point colors in 8-bit RGBA format.
ZIVID_CORE_EXPORT size_t size() const
Get the size of the point cloud (total number of points)
ZIVID_CORE_EXPORT Array2D< ColorBGRA_SRGB > copyColorsBGRA_SRGB() const
Array2D of point colors in 8-bit BGRA format in the sRGB color space.
ZIVID_CORE_EXPORT Array2D< PointXYZColorRGBA > copyPointsXYZColorsRGBA() const
Array2D of PointXYZColorRGBA.
ZIVID_CORE_EXPORT Array2D< ColorRGBA_SRGB > copyColorsSRGB() const
Array2D of point colors in 8-bit RGBA format in the sRGB color space.
ZIVID_CORE_EXPORT Image< ColorRGBA_SRGB > copyImageRGBA_SRGB() const
Get point cloud colors as 8-bit RGBA image in the sRGB color space.
ZIVID_CORE_EXPORT std::string toString() const
Get string representation of the point cloud.
Array2D< DataFormat > copyData() const
Array2D with point cloud data using specified DataFormat.
Definition PointCloud.h:477
ZIVID_CORE_EXPORT PointCloud()
Create an empty point cloud.
ZIVID_CORE_EXPORT Array2D< NormalXYZ > copyNormalsXYZ() const
Array2D of NormalXYZ.
ZIVID_CORE_EXPORT Array2D< ColorRGBA_SRGB > copyColorsRGBA_SRGB() const
Array2D of point colors in 8-bit RGBA format in the sRGB color space.
ZIVID_CORE_EXPORT size_t width() const
Get the width of the point cloud (number of columns)
ZIVID_CORE_EXPORT Array2D< PointXYZ > copyPointsXYZ() const
Array2D of point coordinates.
ZIVID_CORE_EXPORT Array2D< PointXYZColorBGRA > copyPointsXYZColorsBGRA() const
Array2D of PointXYZColorBGRA.
ZIVID_CORE_EXPORT Image< ColorRGBA_SRGB > copyImageSRGB() const
Get point cloud colors as 8-bit RGBA image in the sRGB color space.
ZIVID_CORE_EXPORT Array2D< PointZ > copyPointsZ() const
Array2D of Z coordinates.
ZIVID_CORE_EXPORT UnorganizedPointCloud toUnorganizedPointCloud() const
Convert to an UnorganizedPointCloud.
ZIVID_CORE_EXPORT PointCloud downsampled(Downsampling downsampling) const
Get a downsampled point cloud.
ZIVID_CORE_EXPORT bool isEmpty() const
Check if the point cloud is empty (contains zero points)
ZIVID_CORE_EXPORT Array2D< PointXYZColorBGRA_SRGB > copyPointsXYZColorsBGRA_SRGB() const
Array2D of PointXYZColorBGRA_SRGB.
ZIVID_CORE_EXPORT PointCloud & mask(const Zivid::Mask &mask)
Apply a mask to the point cloud in-place.
DeviceArray< ColorFormat > imageDeviceArray(StreamOrQueue streamOrQueue) const
Get the point cloud color image as a device buffer in the specified format.
ZIVID_CORE_EXPORT Image< ColorBGRA > copyImageBGRA() const
Get point cloud colors as 8-bit BGRA image.
ZIVID_CORE_EXPORT Zivid::Matrix4x4 transformationMatrix() const
Return the current transformation matrix of this point cloud.
ZIVID_CORE_EXPORT size_t height() const
Get the height of the point cloud (number of rows)
ZIVID_CORE_EXPORT Array2D< ColorBGRA > copyColorsBGRA() const
Array2D of point colors in 8-bit BGRA format.
ZIVID_CORE_EXPORT PointCloud & maskByRegionOfInterest(const Zivid::Settings::RegionOfInterest::Box &roiSettings)
Apply region of interest filtering to the point cloud in-place.
Class describing a resolution with a width and a height.
Definition Resolution.h:56
Removes points outside the given three-dimensional box.
Definition Settings.h:12718
Point cloud with x, y, z, RGB color and SNR laid out as a linear list of only valid points.
Definition UnorganizedPointCloud.h:75
Definition EnvironmentInfo.h:74
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:85
ColorSRGB ColorRGBA_SRGB
Color with 8-bit red, green, blue and alpha channels in the sRGB color space.
Definition Color.h:93
Matrix< float, 4, 4 > Matrix4x4
Matrix of size 4x4 containing floats.
Definition Matrix.h:329
std::ostream & operator<<(std::ostream &stream, const Array1D< T > &array)
Serialize array information to a stream.
Definition Array1D.h:183
A user CUDA stream or OpenCL command queue, selected by which member is populated.
Definition ComputeWrappers.h:106