ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkFEMLinearSystemWrapperVNL.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 __itkFEMLinearSystemWrapperVNL_h
20 #define __itkFEMLinearSystemWrapperVNL_h
22 #include "vnl/vnl_sparse_matrix.h"
23 #include "vnl/vnl_vector.h"
24 #include <vnl/vnl_sparse_matrix_linear_system.h>
25 #include <vnl/algo/vnl_lsqr.h>
26 #include <vector>
27 
28 namespace itk
29 {
30 namespace fem
31 {
40 {
41 public:
42 
43  /* values stored in matrices & vectors */
45 
46  /* superclass */
48 
49  /* matrix typedef */
50  typedef vnl_sparse_matrix<Float> MatrixRepresentation;
51 
52  /* matrix holder typedef */
53  typedef std::vector<MatrixRepresentation *> MatrixHolder;
54 
55  /* constructor & destructor */
56  LinearSystemWrapperVNL() : LinearSystemWrapper(), m_Matrices(ITK_NULLPTR), m_Vectors(ITK_NULLPTR), m_Solutions(ITK_NULLPTR)
57  {
58  }
59  virtual ~LinearSystemWrapperVNL();
60 
61  /* memory management routines */
62  virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
63 
64  virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE;
65 
66  virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
67 
68  virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE;
69 
70  virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE;
71 
72  virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE;
73 
74  virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE;
75 
76  virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE;
77 
78  virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE;
79 
80  virtual void SetMaximumNonZeroValuesInMatrix(unsigned int, unsigned int)
81  {
82  }
83 
84  /* assembly & solving routines */
85  virtual Float GetMatrixValue(unsigned int i, unsigned int j,
86  unsigned int matrixIndex) const ITK_OVERRIDE
87  {
88  return ( *( ( *m_Matrices )[matrixIndex] ) )(i, j);
89  }
90  virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value,
91  unsigned int matrixIndex) ITK_OVERRIDE
92  {
93  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) = value;
94  }
95  virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value,
96  unsigned int matrixIndex) ITK_OVERRIDE
97  {
98  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) += value;
99  }
100  virtual Float GetVectorValue(unsigned int i,
101  unsigned int vectorIndex) const ITK_OVERRIDE
102  {
103  return ( *( ( *m_Vectors )[vectorIndex] ) )[i];
104  }
105  virtual void SetVectorValue(unsigned int i, Float value,
106  unsigned int vectorIndex) ITK_OVERRIDE
107  {
108  ( *( ( *m_Vectors )[vectorIndex] ) )(i) = value;
109  }
110  virtual void AddVectorValue(unsigned int i, Float value,
111  unsigned int vectorIndex) ITK_OVERRIDE
112  {
113  ( *( ( *m_Vectors )[vectorIndex] ) )(i) += value;
114  }
115  virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE;
116 
117  virtual void SetSolutionValue(unsigned int i, Float value,
118  unsigned int solutionIndex) ITK_OVERRIDE
119  {
120  ( *( ( *m_Solutions )[solutionIndex] ) )(i) = value;
121  }
122  virtual void AddSolutionValue(unsigned int i, Float value,
123  unsigned int solutionIndex) ITK_OVERRIDE
124  {
125  ( *( ( *m_Solutions )[solutionIndex] ) )(i) += value;
126  }
127  virtual void Solve(void) ITK_OVERRIDE;
128 
129  /* matrix & vector manipulation routines */
130  virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE;
131 
132  virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE;
133 
134  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE;
135 
136  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE;
137 
138  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE;
139 
140  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE;
141 
142  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
143  unsigned int rightMatrixIndex) ITK_OVERRIDE;
144 
145  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE;
146 
147 private:
148 
150  // std::vector< vnl_sparse_matrix<Float>* > *m_Matrices;
152 
154  std::vector<vnl_vector<Float> *> *m_Vectors;
155 
157  std::vector<vnl_vector<Float> *> *m_Solutions;
158 };
159 }
160 } // end namespace itk::fem
161 
162 #endif
virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE
virtual void Solve(void) ITK_OVERRIDE
virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE
virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE
virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE
virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE
virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex, unsigned int rightMatrixIndex) ITK_OVERRIDE
virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE
virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE
virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE
std::vector< vnl_vector< Float > * > * m_Solutions
vnl_sparse_matrix< Float > MatrixRepresentation
Defines all functions required by Solver class to allocate, assemble and solve a linear system of equ...
virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE
virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE
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
virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE
virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE
virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE
virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE
virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE
virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE
std::vector< vnl_vector< Float > * > * m_Vectors
virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE
virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE
virtual void SetMaximumNonZeroValuesInMatrix(unsigned int, unsigned int)
std::vector< MatrixRepresentation * > MatrixHolder
virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE
virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE
virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE
virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex) const ITK_OVERRIDE
LinearSystemWrapper class that uses VNL numeric library functions to define a sparse linear system of...
virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE