sparse_image_solver.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_2d_sparse_image_solver_hh
#define mia_2d_sparse_image_solver_hh
#include <mia/core/factory.hh>
#include <mia/core/sparse_solver.hh>
#include <mia/2d/image.hh>
NS_MIA_BEGIN
typedef TSparseSolver<C2DFImage> C2DImageSparseSolver;
typedef std::shared_ptr<C2DImageSparseSolver > P2DImageSparseSolver;
typedef THandlerSingleton<TFactoryPluginHandler<TFactory<C2DImageSparseSolver>>> C2DImageSparseSolverPluginHandler;
typedef C2DImageSparseSolver::A_mult_x C2DImageSolverAmultx;
typedef std::shared_ptr<C2DImageSolverAmultx> P2DImageSolverAmultx;
typedef TFactory<C2DImageSolverAmultx> C2DImageSolverAmultxPlugin;
typedef THandlerSingleton<TFactoryPluginHandler<C2DImageSolverAmultxPlugin>> C2DImageSolverAmultxPluginHandler;
template <typename T>
struct multiply<T2DImage<T>> {
static void apply(T2DImage<T>& result, const typename TSparseSolver<T2DImage<T>>::A_mult_x& A, const T2DImage<T>& x);
};
template <typename T>
void multiply<T2DImage<T>>::apply(T2DImage<T>& result, const typename TSparseSolver<T2DImage<T>>::A_mult_x& A, const T2DImage<T>& X)
{
assert(result.get_size() == X.get_size());
assert(result.get_size() == A.get_size());
long b = A.get_boundary_size();
long nx = X.get_size().x - 2 * b;
long ny = X.get_size().y - 2 * b;
copy(X.begin(), X.begin() + b * X.get_size().x + b, result.begin());
auto ir = result.begin() + b * X.get_size().x + b;
auto ix = X.begin() + b * X.get_size().x + b;
for (int y = 0; y < ny; ++y) {
int x = 0;
for (; x < nx; ++x, ++ix, ++ir)
*ir = static_cast<T>(A(ix));
for (; x < (int)X.get_size().x; ++x, ++ix, ++ir)
*ir = *ix;
}
copy(ix, X.end(), ir);
}
FACTORY_TRAIT(C2DImageSparseSolverPluginHandler);
FACTORY_TRAIT(C2DImageSolverAmultxPluginHandler);
NS_MIA_END
#endif
image.hh
C2DImage::get_size
const C2DBounds & get_size() const
T2DImage
This is the template version of a 2D image that is used for holding real data.
Definition 2d/image.hh:140
T2DImage::begin
const_iterator begin() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:269
T2DImage::end
const_iterator end() const
forwarding function to access the underlying T2DDatafield
Definition 2d/image.hh:275
T2DVector::y
T y
second element
Definition 2d/vector.hh:57
T2DVector::x
T x
first element
Definition 2d/vector.hh:54
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition factory.hh:51
THandlerSingleton
the singleton that a plug-in handler really is
Definition handler.hh:159
TSparseSolver
solver for sparse systems of equations
Definition sparse_solver.hh:44
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
factory.hh
FACTORY_TRAIT
#define FACTORY_TRAIT(F)
Definition factory_trait.hh:69
C2DImageSparseSolver
TSparseSolver< C2DFImage > C2DImageSparseSolver
base type for the sparse solvers for 2D images
Definition sparse_image_solver.hh:31
C2DImageSolverAmultxPluginHandler
THandlerSingleton< TFactoryPluginHandler< C2DImageSolverAmultxPlugin > > C2DImageSolverAmultxPluginHandler
plug-in handler for the Matrix-Vector multiplication
Definition sparse_image_solver.hh:49
C2DImageSolverAmultxPlugin
TFactory< C2DImageSolverAmultx > C2DImageSolverAmultxPlugin
plug-in base for the Matrix-Vector multiplication
Definition sparse_image_solver.hh:46
C2DImageSparseSolverPluginHandler
THandlerSingleton< TFactoryPluginHandler< TFactory< C2DImageSparseSolver > > > C2DImageSparseSolverPluginHandler
Plugin handler for sparse image solver plug-ins.
Definition sparse_image_solver.hh:37
P2DImageSolverAmultx
std::shared_ptr< C2DImageSolverAmultx > P2DImageSolverAmultx
pointer type for the Matrix-Vector multiplication
Definition sparse_image_solver.hh:43
C2DImageSolverAmultx
C2DImageSparseSolver::A_mult_x C2DImageSolverAmultx
base class for the Matrix-Vector multiplication
Definition sparse_image_solver.hh:40
P2DImageSparseSolver
std::shared_ptr< C2DImageSparseSolver > P2DImageSparseSolver
pointer type for the sparse solvers for 2D images
Definition sparse_image_solver.hh:34
sparse_solver.hh
multiply< T2DImage< T > >::apply
static void apply(T2DImage< T > &result, const typename TSparseSolver< T2DImage< T > >::A_mult_x &A, const T2DImage< T > &x)
Definition sparse_image_solver.hh:74
multiply
Class template to implement a matrix - field multiplication.
Definition sparse_solver.hh:158
multiply::apply
static void apply(F &result, const typename TSparseSolver< F >::A_mult_x &A, const F &x)
Definition sparse_solver.hh:165