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