My Project
2d/interpolator.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 /*
22  The filter routines for splines and omoms is based on code by
23  Philippe Thevenaz http://bigwww.epfl.ch/thevenaz/interpolation/
24  see also:
25 
26  [1] M. Unser,
27  "Splines: A Perfect Fit for Signal and Image Processing,"
28  IEEE Signal Processing Magazine, vol. 16, no. 6, pp. 22-38,
29  November 1999.
30  [2] M. Unser, A. Aldroubi and M. Eden,
31  "B-Spline Signal Processing: Part I--Theory,"
32  IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 821-832,
33  February 1993.
34  [3] M. Unser, A. Aldroubi and M. Eden,
35  "B-Spline Signal Processing: Part II--Efficient Design and Applications,"
36  IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 834-848,
37  February 1993.
38 */
39 
40 #ifndef mia_2d_interpolator_hh
41 #define mia_2d_interpolator_hh
42 
43 #include <vector>
44 #include <mia/core/splinekernel.hh>
46 #include <mia/2d/image.hh>
47 
48 
50 
54 template <typename T>
55 struct max_hold_type<T2DVector<T>> {
56  typedef T2DVector<double> type;
57 
58 
59 };
61 
65 template <class U>
66 struct coeff_map<T2DVector<U>> {
67  typedef T2DVector<U> value_type;
68  typedef C2DDVector coeff_type;
69 };
70 
72 
73 
77 struct C2DWeightCache {
80 
81  C2DWeightCache(int kernel_size,
82  const CSplineBoundaryCondition& xbc,
83  const CSplineBoundaryCondition& ybc);
84 };
86 
97 template <class T>
99 {
100 public:
108 
118  const CSplineBoundaryCondition& xbc, const CSplineBoundaryCondition& ybc);
119 
121 
127  C2DWeightCache create_cache() const;
128 
129 
136  T operator () (const C2DFVector& x) const;
137 
138 
139  T operator () (const C2DFVector& x, C2DWeightCache& cache) const;
140 
148 
154 
158  const TCoeff2D& get_coefficients() const;
159 
160 protected:
162  typedef std::vector< typename TCoeff2D::value_type > coeff_vector;
163 private:
164 
165  void prefilter(const T2DDatafield<T>& image);
166 
167  typename TCoeff2D::value_type evaluate() const;
168 
169  TCoeff2D m_coeff;
170  C2DBounds m_size2;
171  PSplineKernel m_kernel;
172  PSplineBoundaryCondition m_x_boundary;
173  PSplineBoundaryCondition m_y_boundary;
174  typename T2DDatafield<T>::value_type m_min;
175  typename T2DDatafield<T>::value_type m_max;
176 
177  mutable CMutex m_cache_lock;
178  mutable C2DWeightCache m_cache;
179 
180 
181 };
182 
190 {
191 public:
197  C2DInterpolatorFactory(const std::string& kernel, const std::string& boundary_conditions);
198 
199 
205  C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition& boundary_conditions);
206 
212  C2DInterpolatorFactory(PSplineKernel kernel, const std::string& boundary_conditions);
213 
221 
224 
227 
229 
238  template <class T>
239  T2DInterpolator<T> *create(const T2DDatafield<T>& src) const
240  __attribute__ ((warn_unused_result));
241 
242 
246  const CSplineKernel *get_kernel() const;
247 
248 private:
249  PSplineKernel m_kernel;
252 };
253 
255 typedef std::shared_ptr<C2DInterpolatorFactory > P2DInterpolatorFactory;
256 
257 
258 // implementation
259 
260 template <class T>
262 {
263  return new T2DInterpolator<T>(src, m_kernel, *m_xbc, *m_ybc);
264 }
265 
267 
268 #endif
CMutex
std::mutex CMutex
Definition: parallelcxx11.hh:34
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
T2DInterpolator::get_coefficients
const TCoeff2D & get_coefficients() const
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(const std::string &kernel, const std::string &boundary_conditions)
T2DInterpolator::~T2DInterpolator
~T2DInterpolator()
C2DInterpolatorFactory::~C2DInterpolatorFactory
virtual ~C2DInterpolatorFactory()
T2DInterpolator::coeff_vector
std::vector< typename TCoeff2D::value_type > coeff_vector
helper class for the coefficient field
Definition: 2d/interpolator.hh:162
C2DInterpolatorFactory
The factory to create an interpolator from some input data.
Definition: 2d/interpolator.hh:190
T2DInterpolator::derivative_at
T2DVector< T > derivative_at(const C2DFVector &x) const
CSplineBoundaryCondition
Abstract base class for B-spline interpolation boundary conditions.
Definition: boundary_conditions.hh:53
C2DInterpolatorFactory::create
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
Definition: 2d/interpolator.hh:261
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
T2DInterpolator
The base class for 2D interpolators that use some kind of spacial convolution.
Definition: 2d/interpolator.hh:99
T2DVector
a 2D vector
Definition: 2d/vector.hh:47
CSplineKernel::SCache
Definition: splinekernel.hh:69
T2DInterpolator::T2DInterpolator
T2DInterpolator(const T2DDatafield< T > &data, PSplineKernel kernel, const CSplineBoundaryCondition &xbc, const CSplineBoundaryCondition &ybc)
PSplineKernel
std::shared_ptr< CSplineKernel > PSplineKernel
Definition: splinekernel.hh:291
T2DInterpolator::T2DInterpolator
T2DInterpolator(const T2DDatafield< T > &data, PSplineKernel kernel)
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(const C2DInterpolatorFactory &o)
Copy constructor.
P2DInterpolatorFactory
std::shared_ptr< C2DInterpolatorFactory > P2DInterpolatorFactory
Pointer type for the 2D interpolationfactory.
Definition: 2d/interpolator.hh:255
CSplineKernel
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:46
boundary_conditions.hh
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition &xbc, const CSplineBoundaryCondition &ybc)
C2DInterpolatorFactory::get_kernel
const CSplineKernel * get_kernel() const
T2DDatafield
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:90
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(PSplineKernel kernel, const std::string &boundary_conditions)
T2DInterpolator::TCoeff2D
T2DDatafield< typename coeff_map< T >::coeff_type > TCoeff2D
Definition: 2d/interpolator.hh:153
image.hh
C2DInterpolatorFactory::C2DInterpolatorFactory
C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition &boundary_conditions)
T2DInterpolator::create_cache
C2DWeightCache create_cache() const
PSplineBoundaryCondition
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
Definition: boundary_conditions.hh:167
EXPORT_2D
#define EXPORT_2D
Definition: defines2d.hh:37
splinekernel.hh