sparse_image_solver.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_2d_sparse_image_solver_hh
22 #define mia_2d_sparse_image_solver_hh
23 
24 #include <mia/core/factory.hh>
26 #include <mia/2d/image.hh>
27 
29 
32 
34 typedef std::shared_ptr<C2DImageSparseSolver > P2DImageSparseSolver;
35 
38 
41 
43 typedef std::shared_ptr<C2DImageSolverAmultx> P2DImageSolverAmultx;
44 
47 
50 
51 
52 
62 template <typename T>
63 struct multiply<T2DImage<T> > {
70  static void apply(T2DImage<T>& result, const typename TSparseSolver<T2DImage<T> >::A_mult_x& A, const T2DImage<T>& x);
71 };
72 
73 template <typename T>
74 void multiply<T2DImage<T> >::apply(T2DImage<T>& result, const typename TSparseSolver<T2DImage<T> >::A_mult_x& A, const T2DImage<T>& X)
75 {
76  assert(result.get_size() == X.get_size());
77  assert(result.get_size() == A.get_size());
78 
79  long b = A.get_boundary_size();
80  long nx = X.get_size().x - 2 * b;
81  long ny = X.get_size().y - 2 * b;
82  copy(X.begin(), X.begin() + b * X.get_size().x + b, result.begin());
83  auto ir = result.begin() + b * X.get_size().x + b;
84  auto ix = X.begin() + b * X.get_size().x + b;
85 
86  for (int y = 0; y < ny; ++y) {
87  int x = 0;
88  for (; x < nx; ++x, ++ix, ++ir)
89  *ir = static_cast<T>(A(ix));
90  for (; x < (int)X.get_size().x; ++x, ++ix, ++ir)
91  *ir = *ix;
92  }
93  copy(ix, X.end(), ir);
94 }
95 
100 
101 
103 
104 #endif
the singleton that a plug-in handler really is
Definition: handler.hh:157
A class that implements the multiplication of a cell of the matrix A with the field x...
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:266
std::shared_ptr< C2DImageSolverAmultx > P2DImageSolverAmultx
pointer type for the Matrix-Vector multiplication
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition: 2d/image.hh:261
T y
second element
Definition: 2d/vector.hh:56
Class template to implement a matrix - field multiplication.
This is the template version of a 2D image that is used for holding real data.
Definition: 2d/image.hh:138
solver for sparse systems of equations
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
TFactory< C2DImageSolverAmultx > C2DImageSolverAmultxPlugin
plug-in base for the Matrix-Vector multiplication
#define FACTORY_TRAIT(F)
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49
C2DImageSparseSolver::A_mult_x C2DImageSolverAmultx
base class for the Matrix-Vector multiplication
THandlerSingleton< TFactoryPluginHandler< C2DImageSolverAmultxPlugin > > C2DImageSolverAmultxPluginHandler
plug-in handler for the Matrix-Vector multiplication
std::shared_ptr< C2DImageSparseSolver > P2DImageSparseSolver
pointer type for the sparse solvers for 2D images
const C2DBounds & get_size() const
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)
TSparseSolver< C2DFImage > C2DImageSparseSolver
base type for the sparse solvers for 2D images
THandlerSingleton< TFactoryPluginHandler< TFactory< C2DImageSparseSolver > > > C2DImageSparseSolverPluginHandler
Plugin handler for sparse image solver plug-ins.
T x
first element
Definition: 2d/vector.hh:53
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36