ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkFEMLinearSystemWrapperDenseVNL.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef __itkFEMLinearSystemWrapperDenseVNL_h
20 #define __itkFEMLinearSystemWrapperDenseVNL_h
22 #include "vnl/vnl_matrix.h"
23 #include "vnl/vnl_vector.h"
24 #include "vnl/algo/vnl_svd.h"
25 #include <vector>
26 
27 namespace itk
28 {
29 namespace fem
30 {
39 {
40 public:
41 
42  /* values stored in matrices & vectors */
44 
45  /* superclass */
47 
48  /* matrix typedef */
49  typedef vnl_matrix<Float> MatrixRepresentation;
50 
51  /* matrix holder typedef */
52  typedef std::vector<MatrixRepresentation *> MatrixHolder;
53 
54  /* constructor & destructor */
55  LinearSystemWrapperDenseVNL() : LinearSystemWrapper(), m_Matrices(ITK_NULLPTR), m_Vectors(ITK_NULLPTR), m_Solutions(ITK_NULLPTR)
56  {
57  }
59 
60  /* memory management routines */
61  virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
62 
63  virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE;
64 
65  virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
66 
67  virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE;
68 
69  virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE;
70 
71  virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE;
72 
73  virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE;
74 
75  virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE;
76 
77  virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE;
78 
79  virtual void SetMaximumNonZeroValuesInMatrix(unsigned int, unsigned int)
80  {
81  }
82 
83  /* assembly & solving routines */
84  virtual Float GetMatrixValue(unsigned int i, unsigned int j,
85  unsigned int matrixIndex) const ITK_OVERRIDE
86  {
87  return ( *( ( *m_Matrices )[matrixIndex] ) )(i, j);
88  }
89  virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value,
90  unsigned int matrixIndex) ITK_OVERRIDE
91  {
92  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) = value;
93  }
94  virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value,
95  unsigned int matrixIndex) ITK_OVERRIDE
96  {
97  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) += value;
98  }
99  virtual Float GetVectorValue(unsigned int i,
100  unsigned int vectorIndex) const ITK_OVERRIDE
101  {
102  return ( *( ( *m_Vectors )[vectorIndex] ) )[i];
103  }
104  virtual void SetVectorValue(unsigned int i, Float value,
105  unsigned int vectorIndex) ITK_OVERRIDE
106  {
107  ( *( ( *m_Vectors )[vectorIndex] ) )(i) = value;
108  }
109  virtual void AddVectorValue(unsigned int i, Float value,
110  unsigned int vectorIndex) ITK_OVERRIDE
111  {
112  ( *( ( *m_Vectors )[vectorIndex] ) )(i) += value;
113  }
114  virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE;
115 
116  virtual void SetSolutionValue(unsigned int i, Float value,
117  unsigned int solutionIndex) ITK_OVERRIDE
118  {
119  ( *( ( *m_Solutions )[solutionIndex] ) )(i) = value;
120  }
121  virtual void AddSolutionValue(unsigned int i, Float value,
122  unsigned int solutionIndex) ITK_OVERRIDE
123  {
124  ( *( ( *m_Solutions )[solutionIndex] ) )(i) += value;
125  }
126  virtual void Solve(void) ITK_OVERRIDE;
127 
128  /* matrix & vector manipulation routines */
129  virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE;
130 
131  virtual void ScaleVector(Float scale, unsigned int vectorIndex);
132 
133  virtual void ScaleSolution(Float scale, unsigned int solutionIndex);
134 
135  virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE;
136 
137  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE;
138 
139  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE;
140 
141  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE;
142 
143  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE;
144 
145  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
146  unsigned int rightMatrixIndex) ITK_OVERRIDE;
147 
148  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE;
149 
150 private:
151 
153  // std::vector< vnl_sparse_matrix<Float>* > *m_Matrices;
155 
157  std::vector<vnl_vector<Float> *> *m_Vectors;
158 
160  std::vector<vnl_vector<Float> *> *m_Solutions;
161 };
162 }
163 } // end namespace itk::fem
164 
165 #endif
virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE
virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE
virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE
virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE
LinearSystemWrapper class that uses VNL numeric library functions to define a sparse linear system of...
virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE
virtual void ScaleVector(Float scale, unsigned int vectorIndex)
virtual void SetMaximumNonZeroValuesInMatrix(unsigned int, unsigned int)
virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE
virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE
virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE
virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex) const ITK_OVERRIDE
virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE
virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE
virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE
virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE
virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE
std::vector< MatrixRepresentation * > MatrixHolder
virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex) const ITK_OVERRIDE
virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE
Defines all functions required by Solver class to allocate, assemble and solve a linear system of equ...
virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE
virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE
virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE
virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex, unsigned int rightMatrixIndex) ITK_OVERRIDE
virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE
std::vector< vnl_vector< Float > * > * m_Vectors
virtual void ScaleSolution(Float scale, unsigned int solutionIndex)
virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE
virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE
virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE
virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE
std::vector< vnl_vector< Float > * > * m_Solutions
virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE
virtual void Solve(void) ITK_OVERRIDE