ITK  4.3.0
Insight Segmentation and Registration Toolkit
VNLSparseLUSolverTraits.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 #ifndef __VNLSparseLUSolverTraits_h
19 #define __VNLSparseLUSolverTraits_h
20 
21 #include "vnl/vnl_vector.h"
22 #include "vnl/vnl_sparse_matrix.h"
23 #include "vnl/algo/vnl_sparse_lu.h"
24 
41 template< typename T = double >
43 {
44 public:
45  typedef T ValueType;
46  typedef vnl_sparse_matrix< ValueType > MatrixType;
48  typedef vnl_sparse_lu SolverType;
49 
51  static bool IsDirectSolver()
52  {
53  return true;
54  }
55 
57  static MatrixType InitializeSparseMatrix(const unsigned int & iN)
58  {
59  return MatrixType(iN, iN);
60  }
61 
63  static MatrixType InitializeSparseMatrix(const unsigned int & iRow, const unsigned int& iCol)
64  {
65  return MatrixType(iRow, iCol);
66  }
67 
69  static VectorType InitializeVector(const unsigned int & iN)
70  {
71  return VectorType(iN);
72  }
73 
75  static void FillMatrix(MatrixType & iA, const unsigned int & iR, const unsigned int & iC, const ValueType & iV)
76  {
77  iA(iR, iC) = iV;
78  }
79 
81  static void AddToMatrix(MatrixType & iA, const unsigned int & iR, const unsigned int & iC, const ValueType & iV)
82  {
83  iA(iR, iC) += iV;
84  }
85 
87  static bool Solve(const MatrixType & iA, const VectorType & iB, VectorType & oX)
88  {
89  SolverType solver( iA );
90  oX = solver.solve( iB );
91 
92  return true;
93  }
94 
96  static bool Solve(const MatrixType & iA,
97  const VectorType & iBx, const VectorType & iBy, const VectorType & iBz,
98  VectorType & oX, VectorType & oY, VectorType & oZ )
99  {
100  SolverType solver( iA );
101  oX = solver.solve( iBx );
102  oY = solver.solve( iBy );
103  oZ = solver.solve( iBz );
104 
105  return true;
106  }
107 
109  static bool Solve(const MatrixType & iA,
110  const VectorType & iBx, const VectorType & iBy,
111  VectorType & oX, VectorType & oY)
112  {
113  SolverType solver( iA );
114  oX = solver.solve( iBx );
115  oY = solver.solve( iBy );
116 
117  return true;
118  }
119 
120 };
121 
122 #endif
123