Open3D (C++ API)
BoundingBox.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 
30 #include <Open3D/Utility/Console.h>
31 
32 namespace open3d {
33 namespace visualization {
34 
37 class BoundingBox {
38 public:
39  BoundingBox();
40  BoundingBox(const geometry::Geometry3D &geometry);
41  ~BoundingBox();
42 
43 public:
44  void Reset();
45  void FitInGeometry(const geometry::Geometry3D &geometry);
46 
47 public:
48  Eigen::Vector3d GetCenter() const {
49  return (min_bound_ + max_bound_) * 0.5;
50  }
51 
52  double GetSize() const { return (max_bound_ - min_bound_).maxCoeff(); }
53 
54  double GetXPercentage(double x) const {
55  return (x - min_bound_(0)) / (max_bound_(0) - min_bound_(0));
56  }
57 
58  double GetYPercentage(double y) const {
59  return (y - min_bound_(1)) / (max_bound_(1) - min_bound_(1));
60  }
61 
62  double GetZPercentage(double z) const {
63  return (z - min_bound_(2)) / (max_bound_(2) - min_bound_(2));
64  }
65 
66  std::string GetPrintInfo() const {
67  char buffer[DEFAULT_IO_BUFFER_SIZE];
68  snprintf(buffer, DEFAULT_IO_BUFFER_SIZE,
69  "[(%.4f, %.4f, %.4f) - (%.4f, %.4f, %.4f)]", min_bound_(0),
71  max_bound_(2));
72  return std::string(buffer);
73  }
74 
75 public:
76  Eigen::Vector3d min_bound_ = Eigen::Vector3d::Zero();
77  Eigen::Vector3d max_bound_ = Eigen::Vector3d::Zero();
78 };
79 
80 } // namespace visualization
81 } // namespace open3d
void Reset()
Definition: BoundingBox.cpp:40
Eigen::Vector3d GetCenter() const
Definition: BoundingBox.h:48
#define DEFAULT_IO_BUFFER_SIZE
Definition: Console.h:33
double GetSize() const
Definition: BoundingBox.h:52
Definition: BoundingBox.h:37
BoundingBox()
Definition: BoundingBox.cpp:32
Definition: Geometry3D.h:35
std::string GetPrintInfo() const
Definition: BoundingBox.h:66
Definition: PinholeCameraIntrinsic.cpp:33
double GetYPercentage(double y) const
Definition: BoundingBox.h:58
Eigen::Vector3d min_bound_
Definition: BoundingBox.h:76
double GetXPercentage(double x) const
Definition: BoundingBox.h:54
double GetZPercentage(double z) const
Definition: BoundingBox.h:62
void FitInGeometry(const geometry::Geometry3D &geometry)
Definition: BoundingBox.cpp:45
Eigen::Vector3d max_bound_
Definition: BoundingBox.h:77
~BoundingBox()
Definition: BoundingBox.cpp:38