vnl_scatter_3x3.hxx
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_scatter_3x3.hxx
2 #ifndef vnl_scatter_3x3_hxx_
3 #define vnl_scatter_3x3_hxx_
4 //:
5 // \file
6 // \author Andrew W. Fitzgibbon, Oxford RRG
7 // Created: 02 Oct 96
8 //-----------------------------------------------------------------------------
9 
10 #include <iostream>
11 #include "vnl_scatter_3x3.h"
12 #ifdef _MSC_VER
13 # include <vcl_msvc_warnings.h>
14 #endif
16 
17 template <class T>
19  : base(T(0))
20  , symmetricp(true)
21  , eigenvectors_currentp(false)
22 {
23 }
24 
25 template <class T>
27 {
28  vnl_scatter_3x3<T> & S = *this;
29  for (int i = 0; i < 3; ++i) {
30  S(i,i) += v[i]*v[i];
31  for (int j = i+1; j < 3; ++j) {
32  T value = v[i]*v[j];
33  S(i,j) += value;
34  S(j,i) = S(i,j);
35  }
36  }
37 }
38 
39 template <class T>
41  const vnl_vector_fixed<T,3> & v)
42 {
43  vnl_scatter_3x3<T> & S = *this;
44  for (int i = 0; i < 3; ++i)
45  for (int j = 0; j < 3; ++j)
46  S(i,j) += v[i]*u[j];
47  symmetricp = false; // conservative assumption -- use add_outer_product(v) to maintain symmetry
48 }
49 
50 template <class T>
52 {
53  vnl_scatter_3x3<T> & S = *this;
54  for (int i = 0; i < 3; ++i) {
55  S(i,i) -= v[i]*v[i];
56  for (int j = i+1; j < 3; ++j) {
57  T value = v[i]*v[j];
58  S(i,j) -= value;
59  S(j,i) = S(i,j);
60  }
61  }
62 }
63 
64 template <class T>
66  const vnl_vector_fixed<T,3> & v)
67 {
68  vnl_scatter_3x3<T> & S = *this;
69  for (int i = 0; i < 3; ++i)
70  for (int j = 0; j < 3; ++j)
71  S(i,j) -= v[i]*u[j];
72  symmetricp = false; // conservative assumption -- use sub_outer_product(v) to maintain symmetry
73 }
74 
75 template <class T>
77 {
78  if (symmetricp)
79  return;
80  vnl_scatter_3x3<T> & S = *this;
81  for (int i = 0; i < 3; ++i)
82  for (int j = i+1; j < 3; ++j) {
83  T vbar = (S(i,j) + S(j,i)) / 2;
84  S(i,j) = S(j,i) = vbar;
85  }
86  symmetricp = true;
87 }
88 
89 template <class T>
91 {
92  vnl_scatter_3x3<T> &S = *this;
93  vnl_matrix<T> M = S.as_matrix();
94  if (symmetricp) {
95  vnl_symmetric_eigensystem_compute(M, V_.as_ref().non_const(), D.as_ref().non_const());
96  }
97  else {
98  std::cerr << "Asymmetric scatter not handled now\n";
99  }
100 
101  eigenvectors_currentp = true;
102 }
103 
104 //--------------------------------------------------------------------------------
106 #define VNL_SCATTER_3X3_INSTANTIATE(T) \
107 template class VNL_ALGO_EXPORT vnl_scatter_3x3<T >
108 
109 #endif // vnl_scatter_3x3_hxx_
void sub_outer_product(const vnl_vector_fixed< T, 3 > &v)
Subtract v*v' from scatter.
const vnl_matrix< T > as_matrix() const
Convert to a vnl_matrix.
void compute_eigensystem()
Compute the eigensystem of S.
#define v
Definition: vnl_vector.h:42
vnl_matrix< T > const & as_ref() const
Return a reference to this.
Definition: vnl_matrix.h:635
An ordinary mathematical matrix.
Definition: vnl_adjugate.h:22
3x3 scatter matrix
void add_outer_product(const vnl_vector_fixed< T, 3 > &v)
Add v*v' to scatter.
void force_symmetric()
Replace S with $(S+S^\top)/2$.
Find eigenvalues of a symmetric matrix.
vnl_scatter_3x3()
Constructor. Fills with zeros.
bool vnl_symmetric_eigensystem_compute(vnl_matrix< T > const &A, vnl_matrix< T > &V, vnl_vector< T > &D)
Find eigenvalues of a symmetric matrix.