Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 class VoxelGrid;
49 
50 class PointCloud : public Geometry3D {
51 public:
53  PointCloud(const std::vector<Eigen::Vector3d> &points)
54  : Geometry3D(Geometry::GeometryType::PointCloud), points_(points) {}
55  ~PointCloud() override {}
56 
57 public:
58  PointCloud &Clear() override;
59  bool IsEmpty() const override;
60  Eigen::Vector3d GetMinBound() const override;
61  Eigen::Vector3d GetMaxBound() const override;
62  Eigen::Vector3d GetCenter() const override;
63  AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
64  OrientedBoundingBox GetOrientedBoundingBox() const override;
65  PointCloud &Transform(const Eigen::Matrix4d &transformation) override;
66  PointCloud &Translate(const Eigen::Vector3d &translation,
67  bool relative = true) override;
68  PointCloud &Scale(const double scale, bool center = true) override;
69  PointCloud &Rotate(const Eigen::Matrix3d &R, bool center = true) override;
70 
71  PointCloud &operator+=(const PointCloud &cloud);
72  PointCloud operator+(const PointCloud &cloud) const;
73 
74  bool HasPoints() const { return points_.size() > 0; }
75 
76  bool HasNormals() const {
77  return points_.size() > 0 && normals_.size() == points_.size();
78  }
79 
80  bool HasColors() const {
81  return points_.size() > 0 && colors_.size() == points_.size();
82  }
83 
85  for (size_t i = 0; i < normals_.size(); i++) {
86  normals_[i].normalize();
87  }
88  return *this;
89  }
90 
92  PointCloud &PaintUniformColor(const Eigen::Vector3d &color) {
93  ResizeAndPaintUniformColor(colors_, points_.size(), color);
94  return *this;
95  }
96 
100  PointCloud &RemoveNoneFinitePoints(bool remove_nan = true,
101  bool remove_infinite = true);
102 
106  std::shared_ptr<PointCloud> SelectDownSample(
107  const std::vector<size_t> &indices, bool invert = false) const;
108 
113  std::shared_ptr<PointCloud> VoxelDownSample(double voxel_size) const;
114 
117  std::tuple<std::shared_ptr<PointCloud>, Eigen::MatrixXi>
118  VoxelDownSampleAndTrace(double voxel_size,
119  const Eigen::Vector3d &min_bound,
120  const Eigen::Vector3d &max_bound,
121  bool approximate_class = false) const;
122 
125  std::shared_ptr<PointCloud> UniformDownSample(size_t every_k_points) const;
126 
130  std::shared_ptr<PointCloud> Crop(const AxisAlignedBoundingBox &bbox) const;
131 
135  std::shared_ptr<PointCloud> Crop(const OrientedBoundingBox &bbox) const;
136 
139  std::tuple<std::shared_ptr<PointCloud>, std::vector<size_t>>
140  RemoveRadiusOutliers(size_t nb_points, double search_radius) const;
141 
144  std::tuple<std::shared_ptr<PointCloud>, std::vector<size_t>>
145  RemoveStatisticalOutliers(size_t nb_neighbors, double std_ratio) const;
146 
152  bool EstimateNormals(
153  const KDTreeSearchParam &search_param = KDTreeSearchParamKNN(),
154  bool fast_normal_computation = true);
155 
159  bool OrientNormalsToAlignWithDirection(
160  const Eigen::Vector3d &orientation_reference =
161  Eigen::Vector3d(0.0, 0.0, 1.0));
162 
166  bool OrientNormalsTowardsCameraLocation(
167  const Eigen::Vector3d &camera_location = Eigen::Vector3d::Zero());
168 
174  std::vector<double> ComputePointCloudDistance(const PointCloud &target);
175 
178  std::tuple<Eigen::Vector3d, Eigen::Matrix3d> ComputeMeanAndCovariance()
179  const;
180 
184  std::vector<double> ComputeMahalanobisDistance() const;
185 
188  std::vector<double> ComputeNearestNeighborDistance() const;
189 
191  std::tuple<std::shared_ptr<TriangleMesh>, std::vector<size_t>>
192  ComputeConvexHull() const;
193 
201  std::tuple<std::shared_ptr<TriangleMesh>, std::vector<size_t>>
202  HiddenPointRemoval(const Eigen::Vector3d &camera_location,
203  const double radius) const;
204 
210  std::vector<int> ClusterDBSCAN(double eps,
211  size_t min_points,
212  bool print_progress = false) const;
213 
223  std::tuple<Eigen::Vector4d, std::vector<size_t>> SegmentPlane(
224  const double distance_threshold = 0.01,
225  const int ransac_n = 3,
226  const int num_iterations = 100) const;
227 
235  static std::shared_ptr<PointCloud> CreateFromDepthImage(
236  const Image &depth,
237  const camera::PinholeCameraIntrinsic &intrinsic,
238  const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity(),
239  double depth_scale = 1000.0,
240  double depth_trunc = 1000.0,
241  int stride = 1);
242 
246  static std::shared_ptr<PointCloud> CreateFromRGBDImage(
247  const RGBDImage &image,
248  const camera::PinholeCameraIntrinsic &intrinsic,
249  const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity());
250 
254  std::shared_ptr<PointCloud> CreateFromVoxelGrid(
255  const VoxelGrid &voxel_grid);
256 
257 public:
258  std::vector<Eigen::Vector3d> points_;
259  std::vector<Eigen::Vector3d> normals_;
260  std::vector<Eigen::Vector3d> colors_;
261 };
262 
263 } // namespace geometry
264 } // namespace open3d
The base geometry class.
Definition: Geometry.h:35
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:130
Contains the pinhole camera intrinsic parameters.
Definition: PinholeCameraIntrinsic.h:51
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
Definition: PointCloud.h:50
bool HasPoints() const
Definition: PointCloud.h:74
PointCloud & NormalizeNormals()
Definition: PointCloud.h:84
std::vector< Eigen::Vector3d > points_
Definition: PointCloud.h:258
PointCloud()
Definition: PointCloud.h:52
double voxel_size
Definition: FilePLY.cpp:285
PointCloud & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each point in the PointCloud the same color.
Definition: PointCloud.h:92
std::vector< Eigen::Vector3d > colors_
Definition: PointCloud.h:260
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
Definition: KDTreeSearchParam.h:32
Definition: RGBDImage.h:43
std::vector< Eigen::Vector3d > normals_
Definition: PointCloud.h:259
bool HasNormals() const
Definition: PointCloud.h:76
int points
Definition: FilePCD.cpp:70
Definition: PinholeCameraIntrinsic.cpp:34
~PointCloud() override
Definition: PointCloud.h:55
Definition: VoxelGrid.h:65
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:40
bool HasColors() const
Definition: PointCloud.h:80
Definition: KDTreeSearchParam.h:53
PointCloud(const std::vector< Eigen::Vector3d > &points)
Definition: PointCloud.h:53
The Image class stores image with customizable width, height, num of channels and bytes per channel...
Definition: Image.h:53