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 <Eigen/Core>
30 #include <memory>
31 #include <tuple>
32 #include <vector>
33 
36 
37 namespace open3d {
38 
39 namespace camera {
40 class PinholeCameraIntrinsic;
41 }
42 
43 namespace geometry {
44 
45 class Image;
46 class RGBDImage;
47 class TriangleMesh;
48 
49 class PointCloud : public Geometry3D {
50 public:
52  ~PointCloud() override {}
53 
54 public:
55  void Clear() override;
56  bool IsEmpty() const override;
57  Eigen::Vector3d GetMinBound() const override;
58  Eigen::Vector3d GetMaxBound() const override;
59  PointCloud &Transform(const Eigen::Matrix4d &transformation) override;
60  PointCloud &Translate(const Eigen::Vector3d &translation) override;
61  PointCloud &Scale(const double scale, bool center = true) override;
62  PointCloud &Rotate(const Eigen::Vector3d &rotation,
63  bool center = true,
64  RotationType type = RotationType::XYZ) override;
65 
66 public:
67  PointCloud &operator+=(const PointCloud &cloud);
68  PointCloud operator+(const PointCloud &cloud) const;
69 
70 public:
71  bool HasPoints() const { return points_.size() > 0; }
72 
73  bool HasNormals() const {
74  return points_.size() > 0 && normals_.size() == points_.size();
75  }
76 
77  bool HasColors() const {
78  return points_.size() > 0 && colors_.size() == points_.size();
79  }
80 
82  for (size_t i = 0; i < normals_.size(); i++) {
83  normals_[i].normalize();
84  }
85  }
86 
88  void PaintUniformColor(const Eigen::Vector3d &color) {
89  colors_.resize(points_.size());
90  for (size_t i = 0; i < points_.size(); i++) {
91  colors_[i] = color;
92  }
93  }
94 
95 public:
96  std::vector<Eigen::Vector3d> points_;
97  std::vector<Eigen::Vector3d> normals_;
98  std::vector<Eigen::Vector3d> colors_;
99 };
100 
108 std::shared_ptr<PointCloud> CreatePointCloudFromDepthImage(
109  const Image &depth,
110  const camera::PinholeCameraIntrinsic &intrinsic,
111  const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity(),
112  double depth_scale = 1000.0,
113  double depth_trunc = 1000.0,
114  int stride = 1);
115 
119 std::shared_ptr<PointCloud> CreatePointCloudFromRGBDImage(
120  const RGBDImage &image,
121  const camera::PinholeCameraIntrinsic &intrinsic,
122  const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity());
123 
127 std::shared_ptr<PointCloud> SelectDownSample(const PointCloud &input,
128  const std::vector<size_t> &indices,
129  bool invert = false);
130 
135 std::shared_ptr<PointCloud> VoxelDownSample(const PointCloud &input,
136  double voxel_size);
137 
140 std::tuple<std::shared_ptr<PointCloud>, Eigen::MatrixXi>
142  double voxel_size,
143  const Eigen::Vector3d &min_bound,
144  const Eigen::Vector3d &max_bound,
145  bool approximate_class = false);
146 
149 std::shared_ptr<PointCloud> UniformDownSample(const PointCloud &input,
150  size_t every_k_points);
151 
155 std::shared_ptr<PointCloud> CropPointCloud(const PointCloud &input,
156  const Eigen::Vector3d &min_bound,
157  const Eigen::Vector3d &max_bound);
158 
161 std::tuple<std::shared_ptr<PointCloud>, std::vector<size_t>>
162 RemoveRadiusOutliers(const PointCloud &input,
163  size_t nb_points,
164  double search_radius);
165 
168 std::tuple<std::shared_ptr<PointCloud>, std::vector<size_t>>
170  size_t nb_neighbors,
171  double std_ratio);
172 
178 bool EstimateNormals(
179  PointCloud &cloud,
180  const KDTreeSearchParam &search_param = KDTreeSearchParamKNN());
181 
186  PointCloud &cloud,
187  const Eigen::Vector3d &orientation_reference = Eigen::Vector3d(0.0,
188  0.0,
189  1.0));
190 
195  PointCloud &cloud,
196  const Eigen::Vector3d &camera_location = Eigen::Vector3d::Zero());
197 
203 std::vector<double> ComputePointCloudToPointCloudDistance(
204  const PointCloud &source, const PointCloud &target);
205 
208 std::tuple<Eigen::Vector3d, Eigen::Matrix3d> ComputePointCloudMeanAndCovariance(
209  const PointCloud &input);
210 
214 std::vector<double> ComputePointCloudMahalanobisDistance(
215  const PointCloud &input);
216 
219 std::vector<double> ComputePointCloudNearestNeighborDistance(
220  const PointCloud &input);
221 
223 std::shared_ptr<TriangleMesh> ComputePointCloudConvexHull(
224  const PointCloud &input);
225 
226 } // namespace geometry
227 } // namespace open3d
Definition: Geometry.h:32
std::shared_ptr< TriangleMesh > ComputePointCloudConvexHull(const PointCloud &input)
Function that computes the convex hull of the point cloud using qhull.
Definition: PointCloud.cpp:276
void NormalizeNormals()
Definition: PointCloud.h:81
std::tuple< std::shared_ptr< PointCloud >, std::vector< size_t > > RemoveRadiusOutliers(const PointCloud &input, size_t nb_points, double search_radius)
Definition: DownSample.cpp:397
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:293
Definition: PinholeCameraIntrinsic.h:42
Definition: PointCloud.h:49
bool HasPoints() const
Definition: PointCloud.h:71
RotationType
Definition: Geometry3D.h:40
std::vector< Eigen::Vector3d > points_
Definition: PointCloud.h:96
PointCloud()
Definition: PointCloud.h:51
std::shared_ptr< PointCloud > SelectDownSample(const PointCloud &input, const std::vector< size_t > &indices, bool invert)
Definition: DownSample.cpp:144
std::vector< Eigen::Vector3d > colors_
Definition: PointCloud.h:98
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:200
Definition: Geometry3D.h:38
Definition: KDTreeSearchParam.h:32
Definition: RGBDImage.h:38
std::vector< double > ComputePointCloudMahalanobisDistance(const PointCloud &input)
Definition: PointCloud.cpp:237
char type
Definition: FilePCD.cpp:56
std::vector< Eigen::Vector3d > normals_
Definition: PointCloud.h:97
bool HasNormals() const
Definition: PointCloud.h:73
bool OrientNormalsToAlignWithDirection(PointCloud &cloud, const Eigen::Vector3d &orientation_reference)
Definition: EstimateNormals.cpp:159
Definition: PinholeCameraIntrinsic.cpp:34
~PointCloud() override
Definition: PointCloud.h:52
std::shared_ptr< PointCloud > UniformDownSample(const PointCloud &input, size_t every_k_points)
Definition: DownSample.cpp:362
GeometryType
Definition: Geometry.h:34
bool HasColors() const
Definition: PointCloud.h:77
std::shared_ptr< PointCloud > CropPointCloud(const PointCloud &input, const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound)
Definition: DownSample.cpp:375
void PaintUniformColor(const Eigen::Vector3d &color)
Assigns each point in the PointCloud the same color.
Definition: PointCloud.h:88
Definition: KDTreeSearchParam.h:53
std::vector< double > ComputePointCloudNearestNeighborDistance(const PointCloud &input)
Definition: PointCloud.cpp:254
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:177
Definition: Image.h:44
std::shared_ptr< PointCloud > VoxelDownSample(const PointCloud &input, double voxel_size)
Definition: DownSample.cpp:247
std::tuple< std::shared_ptr< PointCloud >, std::vector< size_t > > RemoveStatisticalOutliers(const PointCloud &input, size_t nb_neighbors, double std_ratio)
Definition: DownSample.cpp:430