mf
Media Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bounding_box.h
Go to the documentation of this file.
1 #ifndef MF_BOUNDING_BOX_H_
2 #define MF_BOUNDING_BOX_H_
3 
4 #include <iosfwd>
5 #include <array>
6 #include <cmath>
7 #include <utility>
8 #include <string>
9 #include "../eigen.h"
10 
11 namespace mf {
12 
14 
16 struct bounding_box {
17  using edge = std::pair<Eigen::Vector3f, Eigen::Vector3f>;
18  using face = std::array<Eigen::Vector3f, 4>;
19 
20  using corners_array = std::array<Eigen::Vector3f, 8>;
21  using edges_array = std::array<edge, 12>;
22  using faces_array = std::array<face, 6>;
23 
24  Eigen::Vector3f origin;
25  Eigen::Vector3f extremity;
26 
27  bounding_box() = default;
28  bounding_box(const bounding_box&) = default;
29  bounding_box(const Eigen::Vector3f& o, const Eigen::Vector3f& e);
30 
31  Eigen::Vector3f center() const;
32  Eigen::Vector3f side_lengths() const;
33  float side_length(std::ptrdiff_t i = 0) const;
34  float volume() const;
35 
36  void expand_extremity(float ep = 0.1);
37 
38  bool contains(const Eigen::Vector3f&) const;
39  bool contains(const bounding_box&) const;
40 
41  corners_array corners() const;
42  edges_array edges() const;
43  faces_array faces() const;
44 
45  std::string to_string() const;
46  static bounding_box from_string(const std::string&);
47 
48  friend std::ostream& operator<<(std::ostream&, const bounding_box&);
49 };
50 
51 
52 
53 float minimal_distance_sq(const bounding_box& a, const bounding_box& b);
54 float maximal_distance_sq(const bounding_box& a, const bounding_box& b);
55 
56 float minimal_distance_sq(const Eigen::Vector3f& p, const bounding_box& b);
57 float maximal_distance_sq(const Eigen::Vector3f& p, const bounding_box& b);
58 
59 inline float maximal_distance(const bounding_box& a, const bounding_box& b) {
60  return std::sqrt( maximal_distance_sq(a, b) );
61 }
62 
63 inline float minimal_distance(const bounding_box& a, const bounding_box& b) {
64  return std::sqrt( minimal_distance_sq(a, b) );
65 }
66 
67 
68 inline float minimal_distance(const Eigen::Vector3f& p, const bounding_box& b) {
69  return std::sqrt( minimal_distance_sq(p, b) );
70 }
71 
72 inline float maximal_distance(const Eigen::Vector3f& p, const bounding_box& b) {
73  return std::sqrt( maximal_distance_sq(p, b) );
74 }
75 
76 
77 }
78 
79 #endif
Eigen::Vector3f center() const
Definition: bounding_box.cc:16
bounding_box()=default
corners_array corners() const
Definition: bounding_box.cc:53
Eigen::Vector3f origin
Definition: bounding_box.h:24
float minimal_distance_sq(const bounding_box &a, const bounding_box &b)
Definition: bounding_box.cc:107
faces_array faces() const
Definition: bounding_box.cc:94
std::array< edge, 12 > edges_array
Definition: bounding_box.h:21
std::pair< Eigen::Vector3f, Eigen::Vector3f > edge
Definition: bounding_box.h:17
Eigen::Vector3f side_lengths() const
Definition: bounding_box.cc:20
std::array< Eigen::Vector3f, 4 > face
Definition: bounding_box.h:18
float volume() const
Definition: bounding_box.cc:29
float minimal_distance(const bounding_box &a, const bounding_box &b)
Definition: bounding_box.h:63
float maximal_distance_sq(const bounding_box &a, const bounding_box &b)
Definition: bounding_box.cc:122
void expand_extremity(float ep=0.1)
Definition: bounding_box.cc:34
bool contains(const Eigen::Vector3f &) const
Definition: bounding_box.cc:38
Axis-aligned 3D cuboid bounding box.
Definition: bounding_box.h:16
float side_length(std::ptrdiff_t i=0) const
Definition: bounding_box.cc:24
std::array< face, 6 > faces_array
Definition: bounding_box.h:22
friend std::ostream & operator<<(std::ostream &, const bounding_box &)
Definition: bounding_box.cc:187
static bounding_box from_string(const std::string &)
Definition: bounding_box.cc:176
std::string to_string() const
Definition: bounding_box.cc:164
float maximal_distance(const bounding_box &a, const bounding_box &b)
Definition: bounding_box.h:59
edges_array edges() const
Definition: bounding_box.cc:70
std::array< Eigen::Vector3f, 8 > corners_array
Definition: bounding_box.h:20
Eigen::Vector3f extremity
Definition: bounding_box.h:25