ITK  4.13.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 <vector>
25 #include "ITKFEMExport.h"
26 
27 namespace itk
28 {
29 namespace fem
30 {
38 class ITKFEM_EXPORT LinearSystemWrapperVNL : public LinearSystemWrapper
39 {
40 public:
41 
42  /* values stored in matrices & vectors */
44 
45  /* superclass */
47 
48  /* matrix typedef */
49  typedef vnl_sparse_matrix<Float> MatrixRepresentation;
50 
51  /* matrix holder typedef */
52  typedef std::vector<MatrixRepresentation *> MatrixHolder;
53 
54  /* constructor & destructor */
55  LinearSystemWrapperVNL() : LinearSystemWrapper(), m_Matrices(ITK_NULLPTR), m_Vectors(ITK_NULLPTR), m_Solutions(ITK_NULLPTR)
56  {
57  }
58  virtual ~LinearSystemWrapperVNL() ITK_OVERRIDE;
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 SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE;
132 
133  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE;
134 
135  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE;
136 
137  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE;
138 
139  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE;
140 
141  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
142  unsigned int rightMatrixIndex) ITK_OVERRIDE;
143 
144  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE;
145 
146 private:
147 
149  // std::vector< vnl_sparse_matrix<Float>* > *m_Matrices;
150  MatrixHolder *m_Matrices;
151 
153  std::vector<vnl_vector<Float> *> *m_Vectors;
154 
156  std::vector<vnl_vector<Float> *> *m_Solutions;
157 };
158 }
159 } // end namespace itk::fem
160 
161 #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 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...