Open3D (C++ API)
PointCloud.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <tuple>
30 #include <vector>
31 #include <memory>
32 #include <Eigen/Core>
35 
36 namespace open3d {
37 
38 namespace camera {
39 class PinholeCameraIntrinsic;
40 }
41 
42 namespace geometry {
43 
44 class Image;
45 class RGBDImage;
46 
47 class PointCloud : public Geometry3D {
48 public:
50  ~PointCloud() override{};
51 
52 public:
53  void Clear() override;
54  bool IsEmpty() const override;
55  Eigen::Vector3d GetMinBound() const override;
56  Eigen::Vector3d GetMaxBound() const override;
57  void Transform(const Eigen::Matrix4d &transformation) override;
58 
59 public:
60  PointCloud &operator+=(const PointCloud &cloud);
61  PointCloud operator+(const PointCloud &cloud) const;
62 
63 public:
64  bool HasPoints() const { return points_.size() > 0; }
65 
66  bool HasNormals() const {
67  return points_.size() > 0 && normals_.size() == points_.size();
68  }
69 
70  bool HasColors() const {
71  return points_.size() > 0 && colors_.size() == points_.size();
72  }
73 
75  for (size_t i = 0; i < normals_.size(); i++) {
76  normals_[i].normalize();
77  }
78  }
79 
80  void PaintUniformColor(const Eigen::Vector3d &color) {
81  colors_.resize(points_.size());
82  for (size_t i = 0; i < points_.size(); i++) {
83  colors_[i] = color;
84  }
85  }
86 
87 public:
88  std::vector<Eigen::Vector3d> points_;
89  std::vector<Eigen::Vector3d> normals_;
90  std::vector<Eigen::Vector3d> colors_;
91 };
92 
100 std::shared_ptr<PointCloud> CreatePointCloudFromDepthImage(
101  const Image &depth,
102  const camera::PinholeCameraIntrinsic &intrinsic,
103  const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity(),
104  double depth_scale = 1000.0,
105  double depth_trunc = 1000.0,
106  int stride = 1);
107 
111 std::shared_ptr<PointCloud> CreatePointCloudFromRGBDImage(
112  const RGBDImage &image,
113  const camera::PinholeCameraIntrinsic &intrinsic,
114  const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity());
115 
119 std::shared_ptr<PointCloud> SelectDownSample(const PointCloud &input,
120  const std::vector<size_t> &indices,
121  bool invert = false);
122 
127 std::shared_ptr<PointCloud> VoxelDownSample(const PointCloud &input,
128  double voxel_size);
129 
132 std::tuple<std::shared_ptr<PointCloud>, Eigen::MatrixXi>
134  double voxel_size,
135  const Eigen::Vector3d &min_bound,
136  const Eigen::Vector3d &max_bound,
137  bool approximate_class = false);
138 
141 std::shared_ptr<PointCloud> UniformDownSample(const PointCloud &input,
142  size_t every_k_points);
143 
147 std::shared_ptr<PointCloud> CropPointCloud(const PointCloud &input,
148  const Eigen::Vector3d &min_bound,
149  const Eigen::Vector3d &max_bound);
150 
153 std::tuple<std::shared_ptr<PointCloud>, std::vector<size_t>>
154 RemoveRadiusOutliers(const PointCloud &input,
155  size_t nb_points,
156  double search_radius);
157 
160 std::tuple<std::shared_ptr<PointCloud>, std::vector<size_t>>
162  size_t nb_neighbors,
163  double std_ratio);
164 
170 bool EstimateNormals(
171  PointCloud &cloud,
172  const KDTreeSearchParam &search_param = KDTreeSearchParamKNN());
173 
178  PointCloud &cloud,
179  const Eigen::Vector3d &orientation_reference = Eigen::Vector3d(0.0,
180  0.0,
181  1.0));
182 
187  PointCloud &cloud,
188  const Eigen::Vector3d &camera_location = Eigen::Vector3d::Zero());
189 
195 std::vector<double> ComputePointCloudToPointCloudDistance(
196  const PointCloud &source, const PointCloud &target);
197 
200 std::tuple<Eigen::Vector3d, Eigen::Matrix3d> ComputePointCloudMeanAndCovariance(
201  const PointCloud &input);
202 
206 std::vector<double> ComputePointCloudMahalanobisDistance(
207  const PointCloud &input);
208 
211 std::vector<double> ComputePointCloudNearestNeighborDistance(
212  const PointCloud &input);
213 
214 } // namespace geometry
215 } // namespace open3d
Definition: Geometry.h:32
void NormalizeNormals()
Definition: PointCloud.h:74
std::tuple< std::shared_ptr< PointCloud >, std::vector< size_t > > RemoveRadiusOutliers(const PointCloud &input, size_t nb_points, double search_radius)
Definition: DownSample.cpp:395
std::shared_ptr< PointCloud > CreatePointCloudFromDepthImage(const Image &depth, const camera::PinholeCameraIntrinsic &intrinsic, const Eigen::Matrix4d &extrinsic=Eigen::Matrix4d::Identity(), double depth_scale=1000.0, double depth_trunc=1000.0, int stride=1)
Definition: PointCloudFactory.cpp:120
std::tuple< std::shared_ptr< PointCloud >, Eigen::MatrixXi > VoxelDownSampleAndTrace(const PointCloud &input, double voxel_size, const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound, bool approximate_class)
Definition: DownSample.cpp:291
Definition: PinholeCameraIntrinsic.h:41
Definition: PointCloud.h:47
bool HasPoints() const
Definition: PointCloud.h:64
std::vector< Eigen::Vector3d > points_
Definition: PointCloud.h:88
PointCloud()
Definition: PointCloud.h:49
std::shared_ptr< PointCloud > SelectDownSample(const PointCloud &input, const std::vector< size_t > &indices, bool invert)
Definition: DownSample.cpp:145
std::vector< Eigen::Vector3d > colors_
Definition: PointCloud.h:90
std::shared_ptr< PointCloud > CreatePointCloudFromRGBDImage(const RGBDImage &image, const camera::PinholeCameraIntrinsic &intrinsic, const Eigen::Matrix4d &extrinsic=Eigen::Matrix4d::Identity())
Definition: PointCloudFactory.cpp:143
bool OrientNormalsTowardsCameraLocation(PointCloud &cloud, const Eigen::Vector3d &camera_location)
Definition: EstimateNormals.cpp:181
std::tuple< Eigen::Vector3d, Eigen::Matrix3d > ComputePointCloudMeanAndCovariance(const PointCloud &input)
Definition: PointCloud.cpp:157
Definition: Geometry3D.h:35
Definition: KDTreeSearchParam.h:32
Definition: RGBDImage.h:38
std::vector< double > ComputePointCloudMahalanobisDistance(const PointCloud &input)
Definition: PointCloud.cpp:194
std::vector< Eigen::Vector3d > normals_
Definition: PointCloud.h:89
bool HasNormals() const
Definition: PointCloud.h:66
bool OrientNormalsToAlignWithDirection(PointCloud &cloud, const Eigen::Vector3d &orientation_reference)
Definition: EstimateNormals.cpp:159
Definition: PinholeCameraIntrinsic.cpp:33
~PointCloud() override
Definition: PointCloud.h:50
std::shared_ptr< PointCloud > UniformDownSample(const PointCloud &input, size_t every_k_points)
Definition: DownSample.cpp:360
GeometryType
Definition: Geometry.h:34
bool HasColors() const
Definition: PointCloud.h:70
std::shared_ptr< PointCloud > CropPointCloud(const PointCloud &input, const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound)
Definition: DownSample.cpp:373
void PaintUniformColor(const Eigen::Vector3d &color)
Definition: PointCloud.h:80
Definition: KDTreeSearchParam.h:53
std::vector< double > ComputePointCloudNearestNeighborDistance(const PointCloud &input)
Definition: PointCloud.cpp:211
bool EstimateNormals(PointCloud &cloud, const KDTreeSearchParam &search_param)
Definition: EstimateNormals.cpp:121
std::vector< double > ComputePointCloudToPointCloudDistance(const PointCloud &source, const PointCloud &target)
Definition: PointCloud.cpp:134
Definition: Image.h:44
std::shared_ptr< PointCloud > VoxelDownSample(const PointCloud &input, double voxel_size)
Definition: DownSample.cpp:245
std::tuple< std::shared_ptr< PointCloud >, std::vector< size_t > > RemoveStatisticalOutliers(const PointCloud &input, size_t nb_neighbors, double std_ratio)
Definition: DownSample.cpp:428