My Project
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
34typedef std::shared_ptr<C2DImageSparseSolver > P2DImageSparseSolver;
35
38
41
43typedef std::shared_ptr<C2DImageSolverAmultx> P2DImageSolverAmultx;
44
47
50
51
52
62template <typename T>
63struct 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
73template <typename T>
74void 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 long b = A.get_boundary_size();
79 long nx = X.get_size().x - 2 * b;
80 long ny = X.get_size().y - 2 * b;
81 copy(X.begin(), X.begin() + b * X.get_size().x + b, result.begin());
82 auto ir = result.begin() + b * X.get_size().x + b;
83 auto ix = X.begin() + b * X.get_size().x + b;
84
85 for (int y = 0; y < ny; ++y) {
86 int x = 0;
87
88 for (; x < nx; ++x, ++ix, ++ir)
89 *ir = static_cast<T>(A(ix));
90
91 for (; x < (int)X.get_size().x; ++x, ++ix, ++ir)
92 *ir = *ix;
93 }
94
95 copy(ix, X.end(), ir);
96}
97
102
103
105
106#endif
const C2DBounds & get_size() const
This is the template version of a 2D image that is used for holding real data.
Definition 2d/image.hh:140
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:269
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:275
T y
second element
Definition 2d/vector.hh:57
T x
first element
Definition 2d/vector.hh:54
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition factory.hh:51
the singleton that a plug-in handler really is
Definition handler.hh:159
A class that implements the multiplication of a cell of the matrix A with the field x.
solver for sparse systems of equations
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
#define FACTORY_TRAIT(F)
TSparseSolver< C2DFImage > C2DImageSparseSolver
base type for the sparse solvers for 2D images
THandlerSingleton< TFactoryPluginHandler< C2DImageSolverAmultxPlugin > > C2DImageSolverAmultxPluginHandler
plug-in handler for the Matrix-Vector multiplication
TFactory< C2DImageSolverAmultx > C2DImageSolverAmultxPlugin
plug-in base for the Matrix-Vector multiplication
THandlerSingleton< TFactoryPluginHandler< TFactory< C2DImageSparseSolver > > > C2DImageSparseSolverPluginHandler
Plugin handler for sparse image solver plug-ins.
std::shared_ptr< C2DImageSolverAmultx > P2DImageSolverAmultx
pointer type for the Matrix-Vector multiplication
C2DImageSparseSolver::A_mult_x C2DImageSolverAmultx
base class for the Matrix-Vector multiplication
std::shared_ptr< C2DImageSparseSolver > P2DImageSparseSolver
pointer type for the sparse solvers for 2D images
Class template to implement a matrix - field multiplication.
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)