Zivid C++ API  2.3.1+1a22cbf1-1
Defining the Future of 3D Machine Vision
PointCloud.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * This file is part of the Zivid 3D Camera API
4  *
5  * Copyright 2015-2022 (C) Zivid AS
6  * All rights reserved.
7  *
8  * Zivid Software License, v1.0
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of Zivid AS nor the names of its contributors may be used
21  * to endorse or promote products derived from this software without specific
22  * prior written permission.
23  *
24  * 4. This software, with or without modification, must not be used with any
25  * other 3D camera than from Zivid AS.
26  *
27  * 5. Any software provided in binary form under this license must not be
28  * reverse engineered, decompiled, modified and/or disassembled.
29  *
30  * THIS SOFTWARE IS PROVIDED BY ZIVID AS "AS IS" AND ANY EXPRESS OR IMPLIED
31  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
33  * DISCLAIMED. IN NO EVENT SHALL ZIVID AS OR CONTRIBUTORS BE LIABLE FOR ANY
34  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
39  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Contact: Zivid Customer Success Team <customersuccess@zivid.com>
42  * Info: http://www.zivid.com
43  ******************************************************************************/
44 
45 #pragma once
46 
47 #include <Zivid/Matrix.h>
48 #include "Zivid/Array2D.h"
50 #include "Zivid/Image.h"
51 #include "Zivid/Point.h"
53 #include "Zivid/SNR.h"
54 
55 #include <iosfwd>
56 #include <memory>
57 #include <string>
58 
59 namespace Zivid
60 {
69  class PointCloud
70  {
71  public:
78  enum class Downsampling
79  {
80  by2x2,
81  by3x3,
82  by4x4,
83  };
84 
87 
89  ZIVID_CORE_EXPORT size_t width() const;
90 
92  ZIVID_CORE_EXPORT size_t height() const;
93 
96  ZIVID_CORE_EXPORT size_t size() const;
97 
99  ZIVID_CORE_EXPORT bool isEmpty() const;
100 
116 
136 
148 
161 
174 
181 
195 
209 
221  template<typename DataFormat>
223  {
224  static_assert(HasCopyDataImplReturnArray2DTag<DataFormat>::value,
225  "The provided DataFormat is unsupported. Please refer to the documentation for "
226  "this method for the supported DataFormats.");
227  return copyDataImpl(ReturnArray2DTag<DataFormat>{});
228  }
229 
285  template<typename DataFormat>
286  void copyData(DataFormat *destination) const
287  {
288  static_assert(HasCopyDataImpl<DataFormat *>::value,
289  "The provided DataFormat is unsupported. Please refer to the documentation for "
290  "this method for the supported data formats.");
291  return copyDataImpl(destination);
292  }
293 
296  ZIVID_CORE_EXPORT std::string toString() const;
297 
303 
331 
340 
341 #ifndef NO_DOC
342  ZIVID_CORE_EXPORT class PointCloudImpl &getImpl();
343  ZIVID_CORE_EXPORT const class PointCloudImpl &getImpl() const;
344  ZIVID_CORE_EXPORT explicit PointCloud(std::shared_ptr<class PointCloudImpl> other);
345 #endif
346 
347  private:
348  template<class T>
349  struct ReturnArray2DTag
350  {};
351 
352  template<typename... Args>
353  class HasCopyDataImplReturnArray2DTag
354  {
355  template<typename C,
356  typename = decltype(std::declval<C>().copyDataImpl(std::declval<ReturnArray2DTag<Args>>()...))>
357  static std::true_type test(int);
358  template<typename C>
359  static std::false_type test(...);
360 
361  public:
362  static constexpr bool value = decltype(test<PointCloud>(0))::value;
363  };
364 
365  template<typename... Args>
366  class HasCopyDataImpl
367  {
368  template<typename C, typename = decltype(std::declval<C>().copyDataImpl(std::declval<Args>()...))>
369  static std::true_type test(int);
370  template<typename C>
371  static std::false_type test(...);
372 
373  public:
374  static constexpr bool value = decltype(test<PointCloud>(0))::value;
375  };
376 
377  ZIVID_CORE_EXPORT Array2D<PointXYZ> copyDataImpl(ReturnArray2DTag<PointXYZ> /*tag*/) const;
378  ZIVID_CORE_EXPORT Array2D<PointXYZW> copyDataImpl(ReturnArray2DTag<PointXYZW> /*tag*/) const;
379  ZIVID_CORE_EXPORT Array2D<PointZ> copyDataImpl(ReturnArray2DTag<PointZ> /*tag*/) const;
380  ZIVID_CORE_EXPORT Array2D<ColorRGBA> copyDataImpl(ReturnArray2DTag<ColorRGBA> /*tag*/) const;
381  ZIVID_CORE_EXPORT Array2D<PointXYZColorRGBA> copyDataImpl(ReturnArray2DTag<PointXYZColorRGBA> /*tag*/) const;
382  ZIVID_CORE_EXPORT Array2D<PointXYZColorBGRA> copyDataImpl(ReturnArray2DTag<PointXYZColorBGRA> /*tag*/) const;
383  ZIVID_CORE_EXPORT Array2D<SNR> copyDataImpl(ReturnArray2DTag<SNR> /*tag*/) const;
384  ZIVID_CORE_EXPORT void copyDataImpl(PointXYZ *destination) const;
385  ZIVID_CORE_EXPORT void copyDataImpl(PointXYZW *destination) const;
386  ZIVID_CORE_EXPORT void copyDataImpl(PointZ *destination) const;
387  ZIVID_CORE_EXPORT void copyDataImpl(ColorRGBA *destination) const;
388  ZIVID_CORE_EXPORT void copyDataImpl(PointXYZColorRGBA *destination) const;
389  ZIVID_CORE_EXPORT void copyDataImpl(PointXYZColorBGRA *destination) const;
390  ZIVID_CORE_EXPORT void copyDataImpl(SNR *destination) const;
391 
392  std::shared_ptr<class PointCloudImpl> m_impl;
393  };
394 
396  ZIVID_CORE_EXPORT std::ostream &operator<<(std::ostream &stream, const PointCloud &pointCloud);
397 
398 #ifndef NO_DOC
400  namespace Detail
401  {
402  ZIVID_CORE_EXPORT void waitUntilProcessingIsComplete(const PointCloud &pointCloud);
403  } // namespace Detail
404 #endif
405 
406 } // namespace Zivid
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:57
Two-dimensional container of data
Definition: Array2D.h:75
A 2-dimensional image
Definition: Image.h:71
Point cloud with x, y, z, RGB color and SNR laid out on a 2D grid
Definition: PointCloud.h:70
ZIVID_CORE_EXPORT PointCloud & downsample(Downsampling downsampling)
Downsample the point cloud in-place
ZIVID_CORE_EXPORT Array2D< PointXYZW > copyPointsXYZW() const
Array2D of point coordinates in 4D
void copyData(DataFormat *destination) const
Copy data in the specified DataFormat to a destination buffer
Definition: PointCloud.h:286
ZIVID_CORE_EXPORT Array2D< PointZ > copyPointsZ() const
Array2D of Z coordinates
ZIVID_CORE_EXPORT Image< ColorRGBA > copyImageRGBA() const
Get point cloud colors as 8-bit RGBA image
Downsampling
Option for downsampling
Definition: PointCloud.h:79
ZIVID_CORE_EXPORT Array2D< PointXYZColorRGBA > copyPointsXYZColorsRGBA() const
Array2D of PointXYZColorRGBA
Array2D< DataFormat > copyData() const
Array2D with point cloud data using specified DataFormat
Definition: PointCloud.h:222
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 std::string toString() const
Get string representation of the point cloud
ZIVID_CORE_EXPORT Array2D< PointXYZColorBGRA > copyPointsXYZColorsBGRA() const
Array2D of PointXYZColorBGRA
ZIVID_CORE_EXPORT Array2D< SNR > copySNRs() const
Array2D of SNR values
ZIVID_CORE_EXPORT PointCloud()
Create an empty point cloud
ZIVID_CORE_EXPORT Array2D< PointXYZ > copyPointsXYZ() const
Array2D of point coordinates
ZIVID_CORE_EXPORT size_t width() const
Get the width of the point cloud (number of columns)
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 size_t height() const
Get the height of the point cloud (number of rows)
ZIVID_CORE_EXPORT PointCloud & transform(const Zivid::Matrix4x4 &matrix)
Transform the point cloud in-place by the given 4x4 transformation matrix
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:55
std::ostream & operator<<(std::ostream &stream, const Array2D< T > &array)
Serialize array information to a stream
Definition: Array2D.h:170