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 
26 public:
32  center_(0, 0, 0),
33  R_(Eigen::Matrix3d::Identity()),
34  extent_(0, 0, 0),
35  color_(1, 1, 1) {}
42  OrientedBoundingBox(const Eigen::Vector3d& center,
43  const Eigen::Matrix3d& R,
44  const Eigen::Vector3d& extent)
46  center_(center),
47  R_(R),
48  extent_(extent) {}
49  ~OrientedBoundingBox() override {}
50 
51 public:
52  OrientedBoundingBox& Clear() override;
53  bool IsEmpty() const override;
54  virtual Eigen::Vector3d GetMinBound() const override;
55  virtual Eigen::Vector3d GetMaxBound() const override;
56  virtual Eigen::Vector3d GetCenter() const override;
57 
60  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
61 
64  bool robust) const override;
65 
68  bool robust) const override;
69 
71  const Eigen::Matrix4d& transformation) override;
72  virtual OrientedBoundingBox& Translate(const Eigen::Vector3d& translation,
73  bool relative = true) override;
74  virtual OrientedBoundingBox& Scale(const double scale,
75  const Eigen::Vector3d& center) override;
76  virtual OrientedBoundingBox& Rotate(const Eigen::Matrix3d& R,
77  const Eigen::Vector3d& center) override;
78 
80  double Volume() const;
81 
102  std::vector<Eigen::Vector3d> GetBoxPoints() const;
103 
105  std::vector<size_t> GetPointIndicesWithinBoundingBox(
106  const std::vector<Eigen::Vector3d>& points) const;
107 
113  const AxisAlignedBoundingBox& aabox);
114 
131  const std::vector<Eigen::Vector3d>& points, bool robust = false);
132 
150  const std::vector<Eigen::Vector3d>& points, bool robust = false);
151 
152 public:
154  Eigen::Vector3d center_;
157  Eigen::Matrix3d R_;
159  Eigen::Vector3d extent_;
161  Eigen::Vector3d color_;
162 };
163 
173 public:
179  min_bound_(0, 0, 0),
180  max_bound_(0, 0, 0),
181  color_(1, 1, 1) {}
186  AxisAlignedBoundingBox(const Eigen::Vector3d& min_bound,
187  const Eigen::Vector3d& max_bound);
189 
190 public:
191  AxisAlignedBoundingBox& Clear() override;
192  bool IsEmpty() const override;
193  virtual Eigen::Vector3d GetMinBound() const override;
194  virtual Eigen::Vector3d GetMaxBound() const override;
195  virtual Eigen::Vector3d GetCenter() const override;
196 
198  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
199 
203  bool robust = false) const override;
204 
208  bool robust = false) const override;
210  const Eigen::Matrix4d& transformation) override;
212  const Eigen::Vector3d& translation, bool relative = true) override;
213 
223  virtual AxisAlignedBoundingBox& Scale(
224  const double scale, const Eigen::Vector3d& center) override;
225 
229  const Eigen::Matrix3d& R, const Eigen::Vector3d& center) override;
230 
232 
234  Eigen::Vector3d GetExtent() const { return (max_bound_ - min_bound_); }
235 
237  Eigen::Vector3d GetHalfExtent() const { return GetExtent() * 0.5; }
238 
241  double GetMaxExtent() const { return (max_bound_ - min_bound_).maxCoeff(); }
242 
245  double GetXPercentage(double x) const {
246  return (x - min_bound_(0)) / (max_bound_(0) - min_bound_(0));
247  }
248 
251  double GetYPercentage(double y) const {
252  return (y - min_bound_(1)) / (max_bound_(1) - min_bound_(1));
253  }
254 
257  double GetZPercentage(double z) const {
258  return (z - min_bound_(2)) / (max_bound_(2) - min_bound_(2));
259  }
260 
262  double Volume() const;
264  std::vector<Eigen::Vector3d> GetBoxPoints() const;
265 
269  std::vector<size_t> GetPointIndicesWithinBoundingBox(
270  const std::vector<Eigen::Vector3d>& points) const;
271 
273  std::string GetPrintInfo() const;
274 
279  const std::vector<Eigen::Vector3d>& points);
280 
281 public:
283  Eigen::Vector3d min_bound_;
285  Eigen::Vector3d max_bound_;
287  Eigen::Vector3d color_;
288 };
289 
290 } // namespace geometry
291 } // namespace open3d
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:172
Eigen::Vector3d GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: BoundingVolume.h:237
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:335
AxisAlignedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:177
~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:188
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:283
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:217
double GetXPercentage(double x) const
Definition: BoundingVolume.h:245
virtual OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust=false) const override
Definition: BoundingVolume.cpp:231
virtual AxisAlignedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:254
Eigen::Vector3d min_bound_
The lower x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:283
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:209
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:207
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns the object itself.
Definition: BoundingVolume.cpp:221
virtual AxisAlignedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:263
AxisAlignedBoundingBox & operator+=(const AxisAlignedBoundingBox &other)
Definition: BoundingVolume.cpp:298
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust=false) const override
Definition: BoundingVolume.cpp:226
Eigen::Vector3d GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: BoundingVolume.h:234
std::string GetPrintInfo() const
Returns the 3D dimensions of the bounding box in string format.
Definition: BoundingVolume.cpp:292
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:201
double GetZPercentage(double z) const
Definition: BoundingVolume.h:257
static AxisAlignedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
Definition: BoundingVolume.cpp:310
double GetMaxExtent() const
Definition: BoundingVolume.h:241
double GetYPercentage(double y) const
Definition: BoundingVolume.h:251
std::vector< Eigen::Vector3d > GetBoxPoints() const
Returns the eight points that define the bounding box.
Definition: BoundingVolume.cpp:337
std::vector< size_t > GetPointIndicesWithinBoundingBox(const std::vector< Eigen::Vector3d > &points) const
Definition: BoundingVolume.cpp:351
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:276
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:287
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:213
Eigen::Vector3d max_bound_
The upper x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:285
The base geometry class for 3D geometries.
Definition: Geometry3D.h:28
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:25
static OrientedBoundingBox CreateFromPointsMinimal(const std::vector< Eigen::Vector3d > &points, bool robust=false)
Definition: BoundingVolume.cpp:192
Eigen::Vector3d extent_
The extent of the bounding box in its frame of reference.
Definition: BoundingVolume.h:159
OrientedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:30
OrientedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:23
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:161
Eigen::Matrix3d R_
Definition: BoundingVolume.h:157
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:38
~OrientedBoundingBox() override
Definition: BoundingVolume.h:49
virtual OrientedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:58
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:43
OrientedBoundingBox(const Eigen::Vector3d &center, const Eigen::Matrix3d &R, const Eigen::Vector3d &extent)
Parameterized constructor.
Definition: BoundingVolume.h:42
static OrientedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points, bool robust=false)
Definition: BoundingVolume.cpp:136
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:83
std::vector< Eigen::Vector3d > GetBoxPoints() const
Definition: BoundingVolume.cpp:94
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabox)
Definition: BoundingVolume.cpp:127
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:76
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:90
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:110
virtual OrientedBoundingBox GetOrientedBoundingBox(bool robust) const override
Returns the object itself.
Definition: BoundingVolume.cpp:49
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:33
virtual OrientedBoundingBox GetMinimalOrientedBoundingBox(bool robust) const override
Returns the object itself.
Definition: BoundingVolume.cpp:53
virtual OrientedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:66
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Definition: BoundingVolume.cpp:45
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:31
Eigen::Vector3d center_
The center point of the bounding box.
Definition: BoundingVolume.h:154
int points
Definition: FilePCD.cpp:54
Definition: NonRigidOptimizer.cpp:22
Definition: PinholeCameraIntrinsic.cpp:16