Radium Engine  1.5.20
Loading...
Searching...
No Matches
Quadric.hpp
1#pragma once
2
3#include <Core/RaCore.hpp>
4#include <Core/Types.hpp>
5
6#include <Eigen/Eigenvalues>
7
8namespace Ra {
9namespace Core {
10
24
25// template<int _DIM = 3>
26template <int _DIM>
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
84template <int DIM>
85inline Quadric<DIM>::Quadric() : m_a( Matrix::Zero() ), m_b( Vector::Zero() ), m_c( 0 ) {}
86
87template <int DIM>
88inline Quadric<DIM>::Quadric( const Quadric<DIM>& q ) : m_a( q.m_a ), m_b( q.m_b ), m_c( q.m_c ) {}
89
90template <int DIM>
91inline Quadric<DIM>::Quadric( const Vector& n, Scalar ndotp ) :
92 m_a( n * n.transpose() ), m_b( ndotp * n ), m_c( ndotp * ndotp ) {}
93
94template <int DIM>
95inline Quadric<DIM>::~Quadric() {}
96
97template <int DIM>
98inline 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
104template <int DIM>
105inline const typename Quadric<DIM>::Matrix& Quadric<DIM>::getA() const {
106 return m_a;
107}
108
109template <int DIM>
110inline void Quadric<DIM>::setA( const Matrix& a ) {
111 m_a = a;
112}
113
114template <int DIM>
115inline const typename Quadric<DIM>::Vector& Quadric<DIM>::getB() const {
116 return m_b;
117}
118
119template <int DIM>
120inline void Quadric<DIM>::setB( const Vector& b ) {
121 m_b = b;
122}
123
124template <int DIM>
125inline const double& Quadric<DIM>::getC() const {
126 return m_c;
127}
128
129template <int DIM>
130inline void Quadric<DIM>::setC( const double& c ) {
131 m_c = c;
132}
133
134template <int DIM>
135inline typename Eigen::EigenSolver<Matrix3>::EigenvalueType Quadric<DIM>::computeEigenValuesA() {
136 typename Eigen::EigenSolver<Matrix3> es( m_a );
137 return es.eigenvalues();
138}
139
140template <int DIM>
141inline typename Eigen::EigenSolver<Matrix3>::EigenvectorsType Quadric<DIM>::computeEigenVectorsA() {
142 typename Eigen::EigenSolver<Matrix3> es( m_a );
143 return es.eigenvectors();
144}
145
146template <int DIM>
148 return Quadric<DIM>( m_a + q.getA(), m_b + q.getB(), m_c + q.getC() );
149}
150
151template <int DIM>
152inline Quadric<DIM> Quadric<DIM>::operator*( const Scalar scal ) {
153 return Quadric<DIM>( m_a * scal, m_b * scal, m_c * scal );
154}
155
156template <int DIM>
158 m_a += q.getA();
159 m_b += q.getB();
160 m_c += q.getC();
161 return *this;
162}
163
164template <int DIM>
165inline 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
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3