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-2015 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 
71 template <typename T>
73 public:
74 
76  virtual ~T2DInterpolator(){}
81  virtual T operator () (const C2DFVector& x) const = 0;
82 
87  virtual T2DVector<T> derivative_at(const C2DFVector& x) const = 0;
88 
89 };
90 
94 template <class U>
95 struct coeff_map<T2DVector<U> > {
96  typedef T2DVector<U> value_type;
97  typedef C2DDVector coeff_type;
98 };
99 
101 
112 template <class T>
114 public:
122 
132  const CSplineBoundaryCondition& xbc, const CSplineBoundaryCondition& ybc);
133 
135 
136 
143  T operator () (const C2DFVector& x) const;
144 
151  T2DVector<T> derivative_at(const C2DFVector& x) const;
152 
158 
162  const TCoeff2D& get_coefficients() const;
163 
164 protected:
166  typedef std::vector< typename TCoeff2D::value_type > coeff_vector;
167 private:
168 
169  void prefilter(const T2DDatafield<T>& image);
170 
171  typename TCoeff2D::value_type evaluate() const;
172 
173  TCoeff2D m_coeff;
174  C2DBounds m_size2;
175  PSplineKernel m_kernel;
176  PSplineBoundaryCondition m_x_boundary;
177  PSplineBoundaryCondition m_y_boundary;
178  T m_min;
179  T m_max;
180 
182  mutable CSplineKernel::VIndex m_x_index;
183  mutable CSplineKernel::VIndex m_y_index;
184  mutable CSplineKernel::VWeight m_x_weight;
185  mutable CSplineKernel::VWeight m_y_weight;
186  mutable CSplineKernel::SCache m_x_cache;
187  mutable CSplineKernel::SCache m_y_cache;
188 
189 
190 
191 };
192 
200 public:
206  C2DInterpolatorFactory(const std::string& kernel, const std::string& boundary_conditions);
207 
208 
214  C2DInterpolatorFactory(PSplineKernel kernel, const CSplineBoundaryCondition& boundary_conditions);
215 
221  C2DInterpolatorFactory(PSplineKernel kernel, const std::string& boundary_conditions);
222 
230 
233 
235  C2DInterpolatorFactory& operator = ( const C2DInterpolatorFactory& o);
236 
237  virtual ~C2DInterpolatorFactory();
238 
247  template <class T>
248  T2DInterpolator<T> *create(const T2DDatafield<T>& src) const
249  __attribute__ ((warn_unused_result));
250 
251 
255  const CSplineKernel* get_kernel() const;
256 
257 private:
258  PSplineKernel m_kernel;
261 };
262 
264 typedef std::shared_ptr<C2DInterpolatorFactory > P2DInterpolatorFactory;
265 
266 
271  __attribute__ ((warn_unused_result));
272 
273 // implementation
274 
275 template <class T>
277 {
278  return new T2DConvoluteInterpolator<T>(src, m_kernel, *m_xbc, *m_ybc);
279 }
280 
282 
283 #endif
T2DInterpolator< T > * create(const T2DDatafield< T > &src) const __attribute__((warn_unused_result))
std::shared_ptr< C2DInterpolatorFactory > P2DInterpolatorFactory
Pointer type for the 2D interpolationfactory.
The base class template for all kinds of interpolators.
a 2D vector
Definition: 2d/vector.hh:46
C2DInterpolatorFactory EXPORT_2D * create_2dinterpolation_factory(EInterpolation type, EBoundaryConditions bc) __attribute__((warn_unused_result))
virtual ~T2DInterpolator()
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:43
std::vector< double > VWeight
type for the weight vector
Definition: splinekernel.hh:60
std::vector< typename TCoeff2D::value_type > coeff_vector
helper class for the coefficient field
#define EXPORT_2D
Definition: defines2d.hh:37
std::shared_ptr< CSplineKernel > PSplineKernel
T2DDatafield< typename coeff_map< T >::coeff_type > TCoeff2D
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:63
Abstract base class for B-spline interpolation boundary conditions.
A class to hold data on a regular 2D grid.
Definition: 2d/datafield.hh:53
The factory to create an interpolator from some input data.
EBoundaryConditions
The base class for 2D interpolators that use some kind of spacial convolution.
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:45
EInterpolation
some constants for interpoation types
Definition: defines.hh:71
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46