splinekernel.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-2014 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_core_splinekernel_hh
22 #define mia_core_splinekernel_hh
23 
24 #include <vector>
25 #include <memory>
26 #include <cmath>
27 #include <mia/core/defines.hh>
28 #include <mia/core/dictmap.hh>
29 #include <mia/core/factory.hh>
30 #include <mia/core/product_base.hh>
31 
33 
34 
36 
46 public:
47 
52 
54  static const char *type_descr;
55 
57  static const char *data_descr;
58 
60  typedef std::vector<double> VWeight;
61 
63  typedef std::vector<int> VIndex;
64 
68  struct SCache {
76  SCache(size_t s, const CSplineBoundaryCondition& bc, bool am);
77 
81  void reset();
82 
86  double x;
87 
89  int start_idx;
90 
93 
95  VWeight weights;
96 
98  VIndex index;
99 
102 
104  bool is_flat;
105 
107  bool never_flat;
108  };
109 
116  CSplineKernel(int degree, double shift, EInterpolation type);
117 
121  virtual ~CSplineKernel();
122 
129  void operator () (double x, VWeight& weight, VIndex& index)const;
130 
139  void operator () (double x, SCache& cache)const;
140 
151  void get_cached(double x, SCache& cache)const;
152 
162  void get_uncached(double x, SCache& cache)const;
163 
171  void derivative(double x, VWeight& weight, VIndex& index)const;
172 
181  void derivative(double x, VWeight& weight, VIndex& index, int order)const;
182 
189  int get_indices(double x, VIndex& index) const;
190 
196  virtual void get_weights(double x, VWeight& weight) const = 0;
197 
203  virtual void get_derivative_weights(double x, VWeight& weight) const = 0;
204 
211  virtual void get_derivative_weights(double x, VWeight& weight, int order) const = 0;
212 
213 
220  virtual double get_weight_at(double x, int order) const;
221 
223  EInterpolation get_type() const;
224 
228  const std::vector<double>& get_poles() const;
229 
233  size_t size() const;
234 
235 
237  double get_nonzero_radius() const;
238 
240  int get_active_halfrange()const;
241 
248  int get_start_idx_and_value_weights(double x, VWeight& weights) const;
249 
256  int get_start_idx_and_derivative_weights(double x, VWeight& weights) const;
257 
258 protected:
262  void add_pole(double x);
263 
264 private:
265  int get_start_idx(double x) const;
266 
270  void fill_index(short i, VIndex& index) const;
271 
272 
273  size_t m_half_degree;
274 
275  double m_shift;
276 
277  std::vector<double> m_poles;
278 
279  size_t m_support_size;
280 
281  EInterpolation m_type;
282  std::vector<short> m_indices;
283 
284 };
285 
290 typedef std::shared_ptr<CSplineKernel> PSplineKernel;
291 
294 
300 
308 inline PSplineKernel produce_spline_kernel(const std::string& descr)
309 {
310  return CSplineKernelPluginHandler::instance().produce(descr);
311 }
312 
314 
320 template <>
321 struct __cache_policy<CSplineKernelPlugin> {
322  static bool apply() {
323  return true;
324  }
325 };
326 
327 template <typename T>
328 struct max_hold_type {
329  typedef double type;
330 };
331 
336 template <class T>
337 struct coeff_map {
338  typedef T value_type;
339  typedef double coeff_type;
340 };
345 template <>
346 struct coeff_map<float> {
347  typedef float value_type;
348  typedef float coeff_type;
349 };
350 
352 
353 inline size_t CSplineKernel::size()const
354 {
355  return m_support_size;
356 }
357 
358 
377 double EXPORT_CORE integrate2(const CSplineKernel& spline, double s1, double s2, int d1, int d2, double n, double x0, double L);
378 
379 
381 
382 #endif
the singleton that a plug-in handler really is
Definition: handler.hh:143
VIndex index
cached indices
Definition: splinekernel.hh:98
TFactory< CSplineKernel > CSplineKernelPlugin
base plugin for spline kernels
static const char * type_descr
plugin handling type description
Definition: splinekernel.hh:54
int index_limit
last possible start index
Definition: splinekernel.hh:92
size_t size() const
#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
CSplineKernel plugin_type
helper typedef for plugin handling
Definition: splinekernel.hh:51
static const char * data_descr
plugin handling data description
Definition: splinekernel.hh:57
CSplineKernel plugin_data
helper typedef for plugin handling
Definition: splinekernel.hh:49
bool never_flat
always use mirror
FACTORY_TRAIT(CSplineKernelPluginHandler)
std::shared_ptr< CSplineKernel > PSplineKernel
THandlerSingleton< TFactoryPluginHandler< CSplineKernelPlugin > > CSplineKernelPluginHandler
PSplineKernel produce_spline_kernel(const std::string &descr)
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49
const CSplineBoundaryCondition & boundary_condition
the boundary condition to be applied
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:63
Abstract base class for B-spline interpolation boundary conditions.
double EXPORT_CORE integrate2(const CSplineKernel &spline, double s1, double s2, int d1, int d2, double n, double x0, double L)
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:45
EInterpolation
some constants for interpoation types
Definition: defines.hh:71
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:110
The base class for all plug-in created object.
Definition: product_base.hh:40
static const T & instance()
int start_idx
last start index the B-spline was evaluated for
Definition: splinekernel.hh:89
VWeight weights
cached weights
Definition: splinekernel.hh:95
bool is_flat
store whether indices were mirrored
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:46