Radium Engine  1.5.0
Quadric.hpp
1 #pragma once
2 
3 #include <Core/RaCore.hpp>
4 #include <Core/Types.hpp>
5 
6 #include <Eigen/Eigenvalues>
7 
8 namespace Ra {
9 namespace Core {
10 
24 
25 // template<int _DIM = 3>
26 template <int _DIM>
27 class Quadric
28 {
29  public:
30  static constexpr int DIM = _DIM;
31  using Matrix = Eigen::Matrix<Scalar, DIM, DIM>;
32  using Vector = Eigen::Matrix<Scalar, DIM, 1>;
33 
35  Quadric();
36 
38  Quadric( const Matrix& a, const Vector& b, double c ) : m_a( a ), m_b( b ), m_c( c ) {}
39 
41  Quadric( const Quadric<DIM>& q );
42 
46  Quadric( const Vector& n, Scalar ndotp );
47 
48  ~Quadric();
49 
51 
52  inline const Matrix& getA() const;
53  inline void setA( const Matrix& a );
54 
55  inline const Vector& getB() const;
56  inline void setB( const Vector& b );
57 
58  inline const double& getC() const;
59  inline void setC( const double& c );
60 
64  [[deprecated]] void compute( const Vector& n, double ndotp );
65 
67  inline typename Eigen::EigenSolver<Matrix3>::EigenvalueType computeEigenValuesA();
68  inline typename Eigen::EigenSolver<Matrix3>::EigenvectorsType computeEigenVectorsA();
69 
71 
72  inline Quadric operator+( const Quadric& q ) const;
73  inline Quadric operator*( const Scalar scal );
74 
75  inline Quadric& operator+=( const Quadric& q );
76  inline Quadric& operator*=( Scalar scal );
77 
78  private:
79  Matrix m_a;
80  Vector m_b;
81  double m_c;
82 };
83 
84 template <int DIM>
85 inline Quadric<DIM>::Quadric() : m_a( Matrix::Zero() ), m_b( Vector::Zero() ), m_c( 0 ) {}
86 
87 template <int DIM>
88 inline Quadric<DIM>::Quadric( const Quadric<DIM>& q ) : m_a( q.m_a ), m_b( q.m_b ), m_c( q.m_c ) {}
89 
90 template <int DIM>
91 inline Quadric<DIM>::Quadric( const Vector& n, Scalar ndotp ) :
92  m_a( n * n.transpose() ), m_b( ndotp * n ), m_c( ndotp * ndotp ) {}
93 
94 template <int DIM>
95 inline Quadric<DIM>::~Quadric() {}
96 
97 template <int DIM>
98 inline void Quadric<DIM>::compute( const Vector& n, double ndotp ) {
99  m_a = n * n.transpose();
100  m_b = ndotp * n;
101  m_c = ndotp * ndotp;
102 }
103 
104 template <int DIM>
105 inline const typename Quadric<DIM>::Matrix& Quadric<DIM>::getA() const {
106  return m_a;
107 }
108 
109 template <int DIM>
110 inline void Quadric<DIM>::setA( const Matrix& a ) {
111  m_a = a;
112 }
113 
114 template <int DIM>
115 inline const typename Quadric<DIM>::Vector& Quadric<DIM>::getB() const {
116  return m_b;
117 }
118 
119 template <int DIM>
120 inline void Quadric<DIM>::setB( const Vector& b ) {
121  m_b = b;
122 }
123 
124 template <int DIM>
125 inline const double& Quadric<DIM>::getC() const {
126  return m_c;
127 }
128 
129 template <int DIM>
130 inline void Quadric<DIM>::setC( const double& c ) {
131  m_c = c;
132 }
133 
134 template <int DIM>
135 inline typename Eigen::EigenSolver<Matrix3>::EigenvalueType Quadric<DIM>::computeEigenValuesA() {
136  typename Eigen::EigenSolver<Matrix3> es( m_a );
137  return es.eigenvalues();
138 }
139 
140 template <int DIM>
141 inline typename Eigen::EigenSolver<Matrix3>::EigenvectorsType Quadric<DIM>::computeEigenVectorsA() {
142  typename Eigen::EigenSolver<Matrix3> es( m_a );
143  return es.eigenvectors();
144 }
145 
146 template <int DIM>
147 inline Quadric<DIM> Quadric<DIM>::operator+( const Quadric& q ) const {
148  return Quadric<DIM>( m_a + q.getA(), m_b + q.getB(), m_c + q.getC() );
149 }
150 
151 template <int DIM>
152 inline Quadric<DIM> Quadric<DIM>::operator*( const Scalar scal ) {
153  return Quadric<DIM>( m_a * scal, m_b * scal, m_c * scal );
154 }
155 
156 template <int DIM>
157 inline Quadric<DIM>& Quadric<DIM>::operator+=( const Quadric& q ) {
158  m_a += q.getA();
159  m_b += q.getB();
160  m_c += q.getC();
161  return *this;
162 }
163 
164 template <int DIM>
165 inline Quadric<DIM>& Quadric<DIM>::operator*=( Scalar scal ) {
166  m_a *= scal;
167  m_b *= scal;
168  m_c *= scal;
169  return *this;
170 }
171 
172 } // namespace Core
173 } // namespace Ra
void compute(const Vector &n, double ndotp)
Definition: Quadric.hpp:98
Quadric()
Construct an initialized quadric.
Definition: Quadric.hpp:85
const Matrix & getA() const
Getters and setters.
Definition: Quadric.hpp:105
Quadric(const Matrix &a, const Vector &b, double c)
Construct and initialize a quadric.
Definition: Quadric.hpp:38
Eigen::EigenSolver< Matrix3 >::EigenvalueType computeEigenValuesA()
Computes eigen values and vectors of matrix A.
Definition: Quadric.hpp:135
Quadric operator+(const Quadric &q) const
Operators.
Definition: Quadric.hpp:147
Definition: Cage.cpp:3