ITK  4.8.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 "ITKFEMExport.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_matrix<Float> MatrixRepresentation;
51 
52  /* matrix holder typedef */
53  typedef std::vector<MatrixRepresentation *> MatrixHolder;
54 
55  /* constructor & destructor */
56  LinearSystemWrapperDenseVNL() : LinearSystemWrapper(), m_Matrices(ITK_NULLPTR), m_Vectors(ITK_NULLPTR), m_Solutions(ITK_NULLPTR)
57  {
58  }
59  virtual ~LinearSystemWrapperDenseVNL();
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 ScaleVector(Float scale, unsigned int vectorIndex);
133 
134  virtual void ScaleSolution(Float scale, unsigned int solutionIndex);
135 
136  virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE;
137 
138  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE;
139 
140  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE;
141 
142  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE;
143 
144  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE;
145 
146  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
147  unsigned int rightMatrixIndex) ITK_OVERRIDE;
148 
149  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE;
150 
151 private:
152 
154  // std::vector< vnl_sparse_matrix<Float>* > *m_Matrices;
155  MatrixHolder *m_Matrices;
156 
158  std::vector<vnl_vector<Float> *> *m_Vectors;
159 
161  std::vector<vnl_vector<Float> *> *m_Solutions;
162 };
163 }
164 } // end namespace itk::fem
165 
166 #endif
virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex) override
LinearSystemWrapper class that uses VNL numeric library functions to define a sparse linear system of...
virtual void SetMaximumNonZeroValuesInMatrix(unsigned int, unsigned int)
virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) override
virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) override
std::vector< MatrixRepresentation * > MatrixHolder
virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex) const override
Defines all functions required by Solver class to allocate, assemble and solve a linear system of equ...
virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex) override
virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) override
virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex) const override
virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) override