Open3D (C++ API)  0.13.0
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BoundingVolume.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 
32 
33 namespace open3d {
34 namespace geometry {
35 
36 class AxisAlignedBoundingBox;
37 
45 public:
51  center_(0, 0, 0),
52  R_(Eigen::Matrix3d::Identity()),
53  extent_(0, 0, 0),
54  color_(0, 0, 0) {}
61  OrientedBoundingBox(const Eigen::Vector3d& center,
62  const Eigen::Matrix3d& R,
63  const Eigen::Vector3d& extent)
65  center_(center),
66  R_(R),
67  extent_(extent) {}
68  ~OrientedBoundingBox() override {}
69 
70 public:
71  OrientedBoundingBox& Clear() override;
72  bool IsEmpty() const override;
73  virtual Eigen::Vector3d GetMinBound() const override;
74  virtual Eigen::Vector3d GetMaxBound() const override;
75  virtual Eigen::Vector3d GetCenter() const override;
76  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
77  virtual OrientedBoundingBox GetOrientedBoundingBox() const override;
79  const Eigen::Matrix4d& transformation) override;
80  virtual OrientedBoundingBox& Translate(const Eigen::Vector3d& translation,
81  bool relative = true) override;
82  virtual OrientedBoundingBox& Scale(const double scale,
83  const Eigen::Vector3d& center) override;
84  virtual OrientedBoundingBox& Rotate(const Eigen::Matrix3d& R,
85  const Eigen::Vector3d& center) override;
86 
88  double Volume() const;
89 
110  std::vector<Eigen::Vector3d> GetBoxPoints() const;
111 
113  std::vector<size_t> GetPointIndicesWithinBoundingBox(
114  const std::vector<Eigen::Vector3d>& points) const;
115 
121  const AxisAlignedBoundingBox& aabox);
122 
129  const std::vector<Eigen::Vector3d>& points);
130 
131 public:
133  Eigen::Vector3d center_;
136  Eigen::Matrix3d R_;
138  Eigen::Vector3d extent_;
140  Eigen::Vector3d color_;
141 };
142 
151 public:
157  min_bound_(0, 0, 0),
158  max_bound_(0, 0, 0),
159  color_(0, 0, 0) {}
164  AxisAlignedBoundingBox(const Eigen::Vector3d& min_bound,
165  const Eigen::Vector3d& max_bound)
167  min_bound_(min_bound),
168  max_bound_(max_bound),
169  color_(0, 0, 0) {}
171 
172 public:
173  AxisAlignedBoundingBox& Clear() override;
174  bool IsEmpty() const override;
175  virtual Eigen::Vector3d GetMinBound() const override;
176  virtual Eigen::Vector3d GetMaxBound() const override;
177  virtual Eigen::Vector3d GetCenter() const override;
178  virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override;
179  virtual OrientedBoundingBox GetOrientedBoundingBox() const override;
181  const Eigen::Matrix4d& transformation) override;
183  const Eigen::Vector3d& translation, bool relative = true) override;
184 
194  virtual AxisAlignedBoundingBox& Scale(
195  const double scale, const Eigen::Vector3d& center) override;
196 
200  const Eigen::Matrix3d& R, const Eigen::Vector3d& center) override;
201 
202  AxisAlignedBoundingBox& operator+=(const AxisAlignedBoundingBox& other);
203 
205  Eigen::Vector3d GetExtent() const { return (max_bound_ - min_bound_); }
206 
208  Eigen::Vector3d GetHalfExtent() const { return GetExtent() * 0.5; }
209 
212  double GetMaxExtent() const { return (max_bound_ - min_bound_).maxCoeff(); }
213 
214  double GetXPercentage(double x) const {
215  return (x - min_bound_(0)) / (max_bound_(0) - min_bound_(0));
216  }
217 
218  double GetYPercentage(double y) const {
219  return (y - min_bound_(1)) / (max_bound_(1) - min_bound_(1));
220  }
221 
222  double GetZPercentage(double z) const {
223  return (z - min_bound_(2)) / (max_bound_(2) - min_bound_(2));
224  }
225 
227  double Volume() const;
229  std::vector<Eigen::Vector3d> GetBoxPoints() const;
230 
234  std::vector<size_t> GetPointIndicesWithinBoundingBox(
235  const std::vector<Eigen::Vector3d>& points) const;
236 
238  std::string GetPrintInfo() const;
239 
244  const std::vector<Eigen::Vector3d>& points);
245 
246 public:
248  Eigen::Vector3d min_bound_;
250  Eigen::Vector3d max_bound_;
252  Eigen::Vector3d color_;
253 };
254 
255 } // namespace geometry
256 } // namespace open3d
OrientedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:40
The base geometry class.
Definition: Geometry.h:37
Eigen::Matrix3d R_
Definition: BoundingVolume.h:136
Eigen::Vector3d max_bound_
The upper x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:250
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:150
~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:170
double GetXPercentage(double x) const
Definition: BoundingVolume.h:214
Eigen::Vector3d extent_
The extent of the bounding box in its frame of reference.
Definition: BoundingVolume.h:138
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.cpp:102
static OrientedBoundingBox CreateFromPoints(const std::vector< Eigen::Vector3d > &points)
Definition: BoundingVolume.cpp:148
A bounding box oriented along an arbitrary frame of reference.
Definition: BoundingVolume.h:44
Eigen::Vector3d min_bound_
The lower x, y, z bounds of the bounding box.
Definition: BoundingVolume.h:248
Definition: NonRigidOptimizer.cpp:40
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.cpp:48
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
Definition: BoundingVolume.cpp:60
double GetMaxExtent() const
Definition: BoundingVolume.h:212
virtual OrientedBoundingBox & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
Definition: BoundingVolume.cpp:70
double GetZPercentage(double z) const
Definition: BoundingVolume.h:222
virtual OrientedBoundingBox & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
Definition: BoundingVolume.cpp:78
std::vector< Eigen::Vector3d > GetBoxPoints() const
Definition: BoundingVolume.cpp:106
The base geometry class for 3D geometries.
Definition: Geometry3D.h:46
virtual AxisAlignedBoundingBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
Definition: BoundingVolume.cpp:62
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
Definition: BoundingVolume.cpp:50
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:88
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:252
OrientedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:49
~OrientedBoundingBox() override
Definition: BoundingVolume.h:68
double GetYPercentage(double y) const
Definition: BoundingVolume.h:218
virtual OrientedBoundingBox GetOrientedBoundingBox() const override
Returns an oriented bounding box of the geometry.
Definition: BoundingVolume.cpp:66
AxisAlignedBoundingBox(const Eigen::Vector3d &min_bound, const Eigen::Vector3d &max_bound)
Parameterized constructor.
Definition: BoundingVolume.h:164
int points
Definition: FilePCD.cpp:73
OrientedBoundingBox(const Eigen::Vector3d &center, const Eigen::Matrix3d &R, const Eigen::Vector3d &extent)
Parameterized constructor.
Definition: BoundingVolume.h:61
Definition: PinholeCameraIntrinsic.cpp:35
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:122
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:95
Eigen::Vector3d color_
The color of the bounding box in RGB.
Definition: BoundingVolume.h:140
GeometryType
Specifies possible geometry types.
Definition: Geometry.h:42
Eigen::Vector3d GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: BoundingVolume.h:205
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
Definition: BoundingVolume.cpp:55
AxisAlignedBoundingBox()
Default constructor.
Definition: BoundingVolume.h:155
static OrientedBoundingBox CreateFromAxisAlignedBoundingBox(const AxisAlignedBoundingBox &aabox)
Definition: BoundingVolume.cpp:139
Eigen::Vector3d GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: BoundingVolume.h:208
Eigen::Vector3d center_
The center point of the bounding box.
Definition: BoundingVolume.h:133