Open3D (C++ API)  0.16.0
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-2021 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 "open3d/core/Tensor.h"
34 #include "open3d/utility/Logging.h"
35 
36 namespace open3d {
37 namespace t {
38 namespace geometry {
39 
64 public:
66  AxisAlignedBoundingBox(const core::Device &device = core::Device("CPU:0"));
67 
77  AxisAlignedBoundingBox(const core::Tensor &min_bound,
78  const core::Tensor &max_bound);
79 
80  virtual ~AxisAlignedBoundingBox() override {}
81 
83  core::Device GetDevice() const override { return device_; }
84 
86  core::Dtype GetDtype() const { return dtype_; }
87 
94  bool copy = false) const;
95 
98  return To(GetDevice(), /*copy=*/true);
99  }
100 
101  AxisAlignedBoundingBox &Clear() override;
102 
103  bool IsEmpty() const override { return Volume() == 0; }
104 
110  void SetMinBound(const core::Tensor &min_bound);
111 
117  void SetMaxBound(const core::Tensor &max_bound);
118 
123  void SetColor(const core::Tensor &color);
124 
125 public:
126  core::Tensor GetMinBound() const { return min_bound_; }
127 
128  core::Tensor GetMaxBound() const { return max_bound_; }
129 
130  core::Tensor GetColor() const { return color_; }
131 
132  core::Tensor GetCenter() const { return (min_bound_ + max_bound_) * 0.5; }
133 
143  AxisAlignedBoundingBox &Translate(const core::Tensor &translation,
144  bool relative = true);
145 
156  AxisAlignedBoundingBox &Scale(double scale, const core::Tensor &center);
157 
162 
165 
167  core::Tensor GetHalfExtent() const { return GetExtent() / 2; }
168 
171  double GetMaxExtent() const {
172  return GetExtent().Max({0}).To(core::Float64).Item<double>();
173  }
174 
175  double GetXPercentage(double x) const;
176 
177  double GetYPercentage(double y) const;
178 
179  double GetZPercentage(double z) const;
180 
182  double Volume() const {
183  return GetExtent().Prod({0}).To(core::Float64).Item<double>();
184  }
185 
188  core::Tensor GetBoxPoints() const;
189 
194  const core::Tensor &points) const;
195 
197  std::string ToString() const;
198 
201 
210  const core::Dtype &dtype = core::Float32,
211  const core::Device &device = core::Device("CPU:0"));
212 
217 
218 protected:
224 };
225 
226 } // namespace geometry
227 } // namespace t
228 } // namespace open3d
math::float4 color
Definition: LineSetBuffers.cpp:64
bool copy
Definition: VtkUtils.cpp:89
Definition: Device.h:37
Definition: Dtype.h:39
Definition: Tensor.h:51
Tensor Prod(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1210
Tensor Max(const SizeVector &dims, bool keepdim=false) const
Definition: Tensor.cpp:1224
A bounding box that is aligned along the coordinate axes.
Definition: BoundingVolume.h:155
A bounding box that is aligned along the coordinate axes and defined by the min_bound and max_bound.
Definition: BoundingVolume.h:63
double GetZPercentage(double z) const
Definition: BoundingVolume.cpp:198
double Volume() const
Returns the volume of the bounding box.
Definition: BoundingVolume.h:182
core::Tensor GetMinBound() const
Definition: BoundingVolume.h:126
core::Dtype GetDtype() const
Returns the data type attribute of this AxisAlignedBoundingBox.
Definition: BoundingVolume.h:86
static AxisAlignedBoundingBox FromLegacy(const open3d::geometry::AxisAlignedBoundingBox &box, const core::Dtype &dtype=core::Float32, const core::Device &device=core::Device("CPU:0"))
Definition: BoundingVolume.cpp:267
void SetMinBound(const core::Tensor &min_bound)
Set the min bound of the box. If the data type of the given tensor differs from the data type of the ...
Definition: BoundingVolume.cpp:88
core::Tensor GetBoxPoints() const
Definition: BoundingVolume.cpp:204
void SetColor(const core::Tensor &color)
Set the color of the box.
Definition: BoundingVolume.cpp:122
double GetYPercentage(double y) const
Definition: BoundingVolume.cpp:192
double GetMaxExtent() const
Definition: BoundingVolume.h:171
core::Dtype dtype_
Definition: BoundingVolume.h:220
virtual ~AxisAlignedBoundingBox() override
Definition: BoundingVolume.h:80
open3d::geometry::AxisAlignedBoundingBox ToLegacy() const
Convert to a legacy Open3D axis-aligned box.
Definition: BoundingVolume.cpp:247
AxisAlignedBoundingBox Clone() const
Returns copy of the AxisAlignedBoundingBox on the same device.
Definition: BoundingVolume.h:97
std::string ToString() const
Text description.
Definition: BoundingVolume.cpp:228
core::Tensor GetExtent() const
Get the extent/length of the bounding box in x, y, and z dimension.
Definition: BoundingVolume.h:164
AxisAlignedBoundingBox & operator+=(const AxisAlignedBoundingBox &other)
Add operation for axis-aligned bounding box. The device of ohter box must be the same as the device o...
Definition: BoundingVolume.cpp:167
core::Tensor max_bound_
Definition: BoundingVolume.h:222
AxisAlignedBoundingBox & Clear() override
Clear all elements in the geometry.
Definition: BoundingVolume.cpp:81
core::Tensor GetColor() const
Definition: BoundingVolume.h:130
void SetMaxBound(const core::Tensor &max_bound)
Set the max boundof the box. If the data type of the given tensor differs from the data type of the o...
Definition: BoundingVolume.cpp:104
core::Tensor GetCenter() const
Definition: BoundingVolume.h:132
AxisAlignedBoundingBox(const core::Device &device=core::Device("CPU:0"))
Construct an empty AxisAlignedBoundingBox on the provided device.
Definition: BoundingVolume.cpp:37
core::Device device_
Definition: BoundingVolume.h:219
core::Tensor GetMaxBound() const
Definition: BoundingVolume.h:128
AxisAlignedBoundingBox & Translate(const core::Tensor &translation, bool relative=true)
Translate the axis-aligned box by the given translation.
Definition: BoundingVolume.cpp:138
core::Tensor min_bound_
Definition: BoundingVolume.h:221
core::Tensor color_
Definition: BoundingVolume.h:223
core::Tensor GetHalfExtent() const
Returns the half extent of the bounding box.
Definition: BoundingVolume.h:167
core::Device GetDevice() const override
Returns the device attribute of this AxisAlignedBoundingBox.
Definition: BoundingVolume.h:83
double GetXPercentage(double x) const
Definition: BoundingVolume.cpp:186
AxisAlignedBoundingBox & Scale(double scale, const core::Tensor &center)
Scale the axis-aligned box. If is the min_bound and is the max_bound of the axis aligned bounding b...
Definition: BoundingVolume.cpp:155
AxisAlignedBoundingBox To(const core::Device &device, bool copy=false) const
Definition: BoundingVolume.cpp:69
core::Tensor GetPointIndicesWithinBoundingBox(const core::Tensor &points) const
Indices to points that are within the bounding box.
Definition: BoundingVolume.cpp:215
bool IsEmpty() const override
Returns true iff the geometry is empty.
Definition: BoundingVolume.h:103
static AxisAlignedBoundingBox CreateFromPoints(const core::Tensor &points)
Definition: BoundingVolume.cpp:233
Mix-in class for geometry types that can be visualized.
Definition: DrawableGeometry.h:38
The base geometry class.
Definition: Geometry.h:42
int points
Definition: FilePCD.cpp:73
const Dtype Float64
Definition: Dtype.cpp:62
const Dtype Float32
Definition: Dtype.cpp:61
Definition: PinholeCameraIntrinsic.cpp:35