Open3D (C++ API)  0.19.0
BoundingVolume.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 
13 
14 namespace open3d {
15 namespace geometry {
16 
17 class AxisAlignedBoundingBox;
18 class OrientedBoundingBox;
19 
21 public:
27  center_(0, 0, 0),
28  R_(Eigen::Matrix3d::Identity()),
29  radii_(0, 0, 0),
30  color_(1, 1, 1) {}
31 
38  OrientedBoundingEllipsoid(const Eigen::Vector3d& center,
39  const Eigen::Matrix3d& R,
40  const Eigen::Vector3d& radii)
42  center_(center),
43  R_(R),
44  radii_(radii),
45  color_(1, 1, 1) {}
47 
48 public:
49  OrientedBoundingEllipsoid& Clear() override;
50  bool IsEmpty() const override;
51  virtual Eigen::Vector3d GetMinBound() const override;
52  virtual Eigen::Vector3d GetMaxBound() const override;
53  virtual Eigen::Vector3d GetCenter() const override;
54 
56  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
57 
60  bool robust) const override;
61 
64  bool robust) const override;
65 
67  const Eigen::Matrix4d& transformation) override;
69  const Eigen::Vector3d& translation, bool relative = true) override;
71  const double scale, const Eigen::Vector3d& center) override;
73  const Eigen::Matrix3d& R, const Eigen::Vector3d& center) override;
74 
76  double Volume() const;
77 
102  std::vector<Eigen::Vector3d> GetEllipsoidPoints() const;
103 
106  const std::vector<Eigen::Vector3d>& points) const;
107 
118  const std::vector<Eigen::Vector3d>& points, bool robust = false);
119 
120 public:
122  Eigen::Vector3d center_;
125  Eigen::Matrix3d R_;
127  Eigen::Vector3d radii_;
129  Eigen::Vector3d color_;
130 };
131 
139 public:
145  center_(0, 0, 0),
146  R_(Eigen::Matrix3d::Identity()),
147  extent_(0, 0, 0),
148  color_(1, 1, 1) {}
155  OrientedBoundingBox(const Eigen::Vector3d& center,
156  const Eigen::Matrix3d& R,
157  const Eigen::Vector3d& extent)
159  center_(center),
160  R_(R),
161  extent_(extent) {}
162  ~OrientedBoundingBox() override {}
163 
164 public:
165  OrientedBoundingBox& Clear() override;
166  bool IsEmpty() const override;
167  virtual Eigen::Vector3d GetMinBound() const override;
168  virtual Eigen::Vector3d GetMaxBound() const override;
169  virtual Eigen::Vector3d GetCenter() const override;
170 
173  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
174 
177  bool robust) const override;
178 
181  bool robust) const override;
182 
184  const Eigen::Matrix4d& transformation) override;
185  virtual OrientedBoundingBox& Translate(const Eigen::Vector3d& translation,
186  bool relative = true) override;
187  virtual OrientedBoundingBox& Scale(const double scale,
188  const Eigen::Vector3d& center) override;
189  virtual OrientedBoundingBox& Rotate(const Eigen::Matrix3d& R,
190  const Eigen::Vector3d& center) override;
191 
193  double Volume() const;
194 
215  std::vector<Eigen::Vector3d> GetBoxPoints() const;
216 
218  std::vector<size_t> GetPointIndicesWithinBoundingBox(
219  const std::vector<Eigen::Vector3d>& points) const;
220 
226  const AxisAlignedBoundingBox& aabox);
227 
244  const std::vector<Eigen::Vector3d>& points, bool robust = false);
245 
263  const std::vector<Eigen::Vector3d>& points, bool robust = false);
264 
265 public:
267  Eigen::Vector3d center_;
270  Eigen::Matrix3d R_;
272  Eigen::Vector3d extent_;
274  Eigen::Vector3d color_;
275 };
276 
286 public:
292  min_bound_(0, 0, 0),
293  max_bound_(0, 0, 0),
294  color_(1, 1, 1) {}
299  AxisAlignedBoundingBox(const Eigen::Vector3d& min_bound,
300  const Eigen::Vector3d& max_bound);
302 
303 public:
304  AxisAlignedBoundingBox& Clear() override;
305  bool IsEmpty() const override;
306  virtual Eigen::Vector3d GetMinBound() const override;
307  virtual Eigen::Vector3d GetMaxBound() const override;
308  virtual Eigen::Vector3d GetCenter() const override;
309 
311  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
312 
316  bool robust = false) const override;
317 
321  bool robust = false) const override;
322 
324  const Eigen::Matrix4d& transformation) override;
326  const Eigen::Vector3d& translation, bool relative = true) override;
327 
337  virtual AxisAlignedBoundingBox& Scale(
338  const double scale, const Eigen::Vector3d& center) override;
339 
343  const Eigen::Matrix3d& R, const Eigen::Vector3d& center) override;
344 
346 
348  Eigen::Vector3d GetExtent() const { return (max_bound_ - min_bound_); }
349 
351  Eigen::Vector3d GetHalfExtent() const { return GetExtent() * 0.5; }
352 
355  double GetMaxExtent() const { return (max_bound_ - min_bound_).maxCoeff(); }
356 
359  double GetXPercentage(double x) const {
360  return (x - min_bound_(0)) / (max_bound_(0) - min_bound_(0));
361  }
362 
365  double GetYPercentage(double y) const {
366  return (y - min_bound_(1)) / (max_bound_(1) - min_bound_(1));
367  }
368 
371  double GetZPercentage(double z) const {
372  return (z - min_bound_(2)) / (max_bound_(2) - min_bound_(2));
373  }
374 
376  double Volume() const;
378  std::vector<Eigen::Vector3d> GetBoxPoints() const;
379 
383  std::vector<size_t> GetPointIndicesWithinBoundingBox(
384  const std::vector<Eigen::Vector3d>& points) const;
385 
387  std::string GetPrintInfo() const;
388 
393  const std::vector<Eigen::Vector3d>& points);
394 
395 public:
397  Eigen::Vector3d min_bound_;
399  Eigen::Vector3d max_bound_;
401  Eigen::Vector3d color_;
402 };
403 
404 } // namespace geometry
405 } // namespace open3d
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:285
Eigen::Vector3d GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: BoundingVolume.h:351
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:431
AxisAlignedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:290
~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:301
virtual AxisAlignedBoundingBox & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
an AxisAlignedBoundingBox can not be rotated. This method will throw an error.
Definition: BoundingVolume.cpp:379
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:313
double GetXPercentage(double x) const
Definition: BoundingVolume.h:359
virtual OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust=false) const override
Definition: BoundingVolume.cpp:327
virtual AxisAlignedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:350
Eigen::Vector3d min_bound_
The lower x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:397
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:305
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:303
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns the object itself.
Definition: BoundingVolume.cpp:317
virtual AxisAlignedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:359
AxisAlignedBoundingBox & operator+=(const AxisAlignedBoundingBox &other)
Definition: BoundingVolume.cpp:394
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: BoundingVolume.cpp:322
Eigen::Vector3d GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: BoundingVolume.h:348
std::string GetPrintInfo() const
Returns the 3D dimensions of the bounding box in string format.
Definition: BoundingVolume.cpp:388
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:297
double GetZPercentage(double z) const
Definition: BoundingVolume.h:371
static AxisAlignedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
Definition: BoundingVolume.cpp:406
double GetMaxExtent() const
Definition: BoundingVolume.h:355
double GetYPercentage(double y) const
Definition: BoundingVolume.h:365
std::vector< Eigen::Vector3d > GetBoxPoints() const
Returns the eight points that define the bounding box.
Definition: BoundingVolume.cpp:433
std::vector< size_t > GetPointIndicesWithinBoundingBox(const std::vector< Eigen::Vector3d > &points) const
Definition: BoundingVolume.cpp:447
virtual AxisAlignedBoundingBox & Scale(const double scale, const Eigen::Vector3d &center) override
Scales the axis-aligned bounding boxes. If is the min_bound and is the max_bound of the axis aligne...
Definition: BoundingVolume.cpp:372
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:401
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:309
Eigen::Vector3d max_bound_
The upper x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:399
The base geometry class for 3D geometries.
Definition: Geometry3D.h:29
The base geometry class.
Definition: Geometry.h:18
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:23
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:138
static OrientedBoundingBox CreateFromPointsMinimal(const std::vector< Eigen::Vector3d > &points, bool robust=false)
Definition: BoundingVolume.cpp:288
Eigen::Vector3d extent_
The extent of the bounding box in its frame of reference.
Definition: BoundingVolume.h:272
OrientedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:143
OrientedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:119
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:274
Eigen::Matrix3d R_
Definition: BoundingVolume.h:270
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:134
~OrientedBoundingBox() override
Definition: BoundingVolume.h:162
virtual OrientedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:154
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:139
OrientedBoundingBox(const Eigen::Vector3d &center, const Eigen::Matrix3d &R, const Eigen::Vector3d &extent)
Parameterized constructor.
Definition: BoundingVolume.h:155
static OrientedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points, bool robust=false)
Definition: BoundingVolume.cpp:232
virtual OrientedBoundingBox & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
Definition: BoundingVolume.cpp:179
std::vector< Eigen::Vector3d > GetBoxPoints() const
Definition: BoundingVolume.cpp:190
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabox)
Definition: BoundingVolume.cpp:223
virtual OrientedBoundingBox & Scale(const double scale, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
Definition: BoundingVolume.cpp:172
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:186
std::vector< size_t > GetPointIndicesWithinBoundingBox(const std::vector< Eigen::Vector3d > &points) const
Return indices to points that are within the bounding box.
Definition: BoundingVolume.cpp:206
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust) const override
Returns the object itself.
Definition: BoundingVolume.cpp:145
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:129
virtual OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust) const override
Returns the object itself.
Definition: BoundingVolume.cpp:149
virtual OrientedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:162
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Definition: BoundingVolume.cpp:141
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:127
Eigen::Vector3d center_
The center point of the bounding box.
Definition: BoundingVolume.h:267
Definition: BoundingVolume.h:20
static OrientedBoundingEllipsoid CreateFromPoints(const std::vector< Eigen::Vector3d > &points, bool robust=false)
Definition: BoundingVolume.cpp:113
virtual OrientedBoundingEllipsoid & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:61
~OrientedBoundingEllipsoid() override
Definition: BoundingVolume.h:46
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Creates an axis-aligned bounding box around the object.
Definition: BoundingVolume.cpp:46
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:32
virtual OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust) const override
Returns an oriented bounding box around the ellipsoid.
Definition: BoundingVolume.cpp:56
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:94
std::vector< size_t > GetPointIndicesWithinBoundingEllipsoid(const std::vector< Eigen::Vector3d > &points) const
Return indices to points that are within the bounding ellipsoid.
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:34
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:39
Eigen::Vector3d center_
The center point of the bounding ellipsoid.
Definition: BoundingVolume.h:122
virtual OrientedBoundingEllipsoid & Scale(const double scale, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
Definition: BoundingVolume.cpp:80
virtual OrientedBoundingEllipsoid & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
Definition: BoundingVolume.cpp:87
OrientedBoundingEllipsoid()
Default constructor.
Definition: BoundingVolume.h:25
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:44
std::vector< Eigen::Vector3d > GetEllipsoidPoints() const
Definition: BoundingVolume.cpp:98
virtual OrientedBoundingEllipsoid & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:70
OrientedBoundingEllipsoid & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:24
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust) const override
Returns an oriented bounding box around the ellipsoid.
Definition: BoundingVolume.cpp:51
Eigen::Vector3d radii_
The radii of the bounding ellipsoid in its frame of reference.
Definition: BoundingVolume.h:127
Eigen::Matrix3d R_
Definition: BoundingVolume.h:125
Eigen::Vector3d color_
The color of the bounding ellipsoid in RGB.
Definition: BoundingVolume.h:129
OrientedBoundingEllipsoid(const Eigen::Vector3d &center, const Eigen::Matrix3d &R, const Eigen::Vector3d &radii)
Parameterized constructor.
Definition: BoundingVolume.h:38
int points
Definition: FilePCD.cpp:54
Definition: NonRigidOptimizer.cpp:22
Definition: PinholeCameraIntrinsic.cpp:16