Radium Engine  1.5.0
Obb.hpp
1 #pragma once
2 
3 #include <Core/RaCore.hpp>
4 #include <Eigen/Core>
5 #include <Eigen/Geometry>
6 
7 namespace Ra {
8 namespace Core {
9 namespace Geometry {
11 class Obb
12 {
13  public:
14  using Transform = Eigen::Transform<Scalar, 3, Eigen::Affine>;
15  using Aabb = Eigen::AlignedBox<Scalar, 3>;
16 
18 
20  inline Obb() : m_aabb(), m_transform( Transform::Identity() ) {}
21 
23  inline Obb( const Aabb& aabb, const Transform& tr ) : m_aabb( aabb ), m_transform( tr ) {}
24 
26  Obb( const Obb& other ) = default;
27  Obb& operator=( const Obb& other ) = default;
28 
29  virtual inline ~Obb() {}
30 
32  inline Aabb toAabb() const {
33  if ( m_aabb.isEmpty() ) { return m_aabb; }
34  Aabb tmp;
35  for ( int i = 0; i < 8; ++i ) {
36  tmp.extend( worldCorner( i ) );
37  }
38  return tmp;
39  }
40 
42  inline void addPoint( const Eigen::Matrix<Scalar, 3, 1>& p ) { m_aabb.extend( p ); }
43 
45  inline Eigen::Matrix<Scalar, 3, 1> corner( int i ) const {
46  return m_aabb.corner( static_cast<Aabb::CornerType>( i ) );
47  }
48 
50  inline Eigen::Matrix<Scalar, 3, 1> worldCorner( int i ) const {
51  return m_transform * m_aabb.corner( static_cast<Aabb::CornerType>( i ) );
52  }
53 
55  Transform& transform() { return m_transform; }
56 
58  const Transform& transform() const { return m_transform; }
59 
60  private:
62  Aabb m_aabb;
64  Transform m_transform;
65 };
66 } // namespace Geometry
67 } // namespace Core
68 } // namespace Ra
An oriented bounding box.
Definition: Obb.hpp:12
Obb(const Obb &other)=default
Default copy constructor and assignment operator.
Transform & transform()
Non-const access to the obb transformation.
Definition: Obb.hpp:55
Aabb toAabb() const
Return the AABB enclosing this.
Definition: Obb.hpp:32
void addPoint(const Eigen::Matrix< Scalar, 3, 1 > &p)
Extends the OBB with an new point.
Definition: Obb.hpp:42
const Transform & transform() const
Const access to the obb transformation.
Definition: Obb.hpp:58
Obb(const Aabb &aabb, const Transform &tr)
Initialize an OBB from an AABB and a transform.
Definition: Obb.hpp:23
Obb()
Constructors and destructor.
Definition: Obb.hpp:20
Eigen::Matrix< Scalar, 3, 1 > worldCorner(int i) const
Returns the position of the ith corner of the OBB ( world space )
Definition: Obb.hpp:50
Eigen::Matrix< Scalar, 3, 1 > corner(int i) const
Returns the position of the i^th corner of AABB (model space)
Definition: Obb.hpp:45
Definition: Cage.cpp:3