ITK  4.4.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 */
56  {
57  }
59 
60  /* memory management routines */
61  virtual void InitializeMatrix(unsigned int matrixIndex);
62 
63  virtual bool IsMatrixInitialized(unsigned int matrixIndex);
64 
65  virtual void DestroyMatrix(unsigned int matrixIndex);
66 
67  virtual void InitializeVector(unsigned int vectorIndex);
68 
69  virtual bool IsVectorInitialized(unsigned int vectorIndex);
70 
71  virtual void DestroyVector(unsigned int vectorIndex);
72 
73  virtual void InitializeSolution(unsigned int solutionIndex);
74 
75  virtual bool IsSolutionInitialized(unsigned int solutionIndex);
76 
77  virtual void DestroySolution(unsigned int solutionIndex);
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
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)
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)
96  {
97  ( *( ( *m_Matrices )[matrixIndex] ) )(i, j) += value;
98  }
99  virtual Float GetVectorValue(unsigned int i,
100  unsigned int vectorIndex) const
101  {
102  return ( *( ( *m_Vectors )[vectorIndex] ) )[i];
103  }
104  virtual void SetVectorValue(unsigned int i, Float value,
105  unsigned int vectorIndex)
106  {
107  ( *( ( *m_Vectors )[vectorIndex] ) )(i) = value;
108  }
109  virtual void AddVectorValue(unsigned int i, Float value,
110  unsigned int vectorIndex)
111  {
112  ( *( ( *m_Vectors )[vectorIndex] ) )(i) += value;
113  }
114  virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const;
115 
116  virtual void SetSolutionValue(unsigned int i, Float value,
117  unsigned int solutionIndex)
118  {
119  ( *( ( *m_Solutions )[solutionIndex] ) )(i) = value;
120  }
121  virtual void AddSolutionValue(unsigned int i, Float value,
122  unsigned int solutionIndex)
123  {
124  ( *( ( *m_Solutions )[solutionIndex] ) )(i) += value;
125  }
126  virtual void Solve(void);
127 
128  /* matrix & vector manipulation routines */
129  virtual void ScaleMatrix(Float scale, unsigned int matrixIndex);
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);
136 
137  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2);
138 
139  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2);
140 
141  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex);
142 
143  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex);
144 
145  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
146  unsigned int rightMatrixIndex);
147 
148  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex);
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
166