My Project
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-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_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 {
47 public:
48 
53 
55  static const char *type_descr;
56 
58  static const char *data_descr;
59 
61  typedef std::vector<double> VWeight;
62 
64  typedef std::vector<int> VIndex;
65 
69  struct SCache {
77  SCache(size_t s, const CSplineBoundaryCondition& bc, bool am);
78 
82  void reset();
83 
87  double x;
88 
90  int start_idx;
91 
94 
97 
100 
103 
105  bool is_flat;
106 
109  };
110 
117  CSplineKernel(int degree, double shift, EInterpolation type);
118 
122  virtual ~CSplineKernel();
123 
130  void operator () (double x, VWeight& weight, VIndex& index)const;
131 
140  void operator () (double x, SCache& cache)const;
141 
152  void get_cached(double x, SCache& cache)const;
153 
163  void get_uncached(double x, SCache& cache)const;
164 
172  void derivative(double x, VWeight& weight, VIndex& index)const;
173 
182  void derivative(double x, VWeight& weight, VIndex& index, int order)const;
183 
190  int get_indices(double x, VIndex& index) const;
191 
197  virtual void get_weights(double x, VWeight& weight) const = 0;
198 
204  virtual void get_derivative_weights(double x, VWeight& weight) const = 0;
205 
212  virtual void get_derivative_weights(double x, VWeight& weight, int order) const = 0;
213 
214 
221  virtual double get_weight_at(double x, int order) const;
222 
224  EInterpolation get_type() const;
225 
229  const std::vector<double>& get_poles() const;
230 
234  size_t size() const;
235 
236 
238  double get_nonzero_radius() const;
239 
241  int get_active_halfrange()const;
242 
249  int get_start_idx_and_value_weights(double x, VWeight& weights) const;
250 
257  int get_start_idx_and_derivative_weights(double x, VWeight& weights) const;
258 
259 protected:
263  void add_pole(double x);
264 
265 private:
266  int get_start_idx(double x) const;
267 
271  void fill_index(short i, VIndex& index) const;
272 
273 
274  size_t m_half_degree;
275 
276  double m_shift;
277 
278  std::vector<double> m_poles;
279 
280  size_t m_support_size;
281 
282  EInterpolation m_type;
283  std::vector<short> m_indices;
284 
285 };
286 
291 typedef std::shared_ptr<CSplineKernel> PSplineKernel;
292 
295 
296 
297 template<> const char *const
304 
312 inline PSplineKernel produce_spline_kernel(const std::string& descr)
313 {
314  return CSplineKernelPluginHandler::instance().produce(descr);
315 }
316 
318 
324 template <>
325 struct __cache_policy<CSplineKernelPlugin> {
326  static bool apply()
327  {
328  return true;
329  }
330 };
331 
332 template <typename T>
333 struct max_hold_type {
334  typedef double type;
335 };
336 
341 template <class T>
342 struct coeff_map {
343  typedef T value_type;
344  typedef double coeff_type;
345 };
350 template <>
351 struct coeff_map<float> {
352  typedef float value_type;
353  typedef float coeff_type;
354 };
355 
357 
358 inline size_t CSplineKernel::size()const
359 {
360  return m_support_size;
361 }
362 
363 
382 double EXPORT_CORE integrate2(const CSplineKernel& spline, double s1, double s2, int d1, int d2, double n, double x0, double L);
383 
384 
386 
387 #endif
CSplineKernelPlugin
TFactory< CSplineKernel > CSplineKernelPlugin
base plugin for spline kernels
Definition: splinekernel.hh:294
THandlerSingleton::instance
static const T & instance()
factory.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
CSplineKernel::size
size_t size() const
Definition: splinekernel.hh:358
CSplineKernel::data_descr
static const char * data_descr
plugin handling data description
Definition: splinekernel.hh:58
CSplineKernel::plugin_data
CSplineKernel plugin_data
helper typedef for plugin handling
Definition: splinekernel.hh:50
CSplineKernel::VIndex
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:64
dictmap.hh
CSplineBoundaryCondition
Abstract base class for B-spline interpolation boundary conditions.
Definition: boundary_conditions.hh:52
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CSplineKernel::SCache::x
double x
Definition: splinekernel.hh:87
CSplineKernel::SCache::weights
VWeight weights
cached weights
Definition: splinekernel.hh:96
THandlerSingleton
the singleton that a plug-in handler really is
Definition: handler.hh:158
CSplineKernel::SCache
Definition: splinekernel.hh:69
CSplineKernel::VWeight
std::vector< double > VWeight
type for the weight vector
Definition: splinekernel.hh:61
CSplineKernel::SCache::is_flat
bool is_flat
store whether indices were mirrored
Definition: splinekernel.hh:105
CSplineKernel::SCache::start_idx
int start_idx
last start index the B-spline was evaluated for
Definition: splinekernel.hh:90
TPluginHandler
The basic template of all plugin handlers.
Definition: handler.hh:56
produce_spline_kernel
PSplineKernel produce_spline_kernel(const std::string &descr)
Definition: splinekernel.hh:312
PSplineKernel
std::shared_ptr< CSplineKernel > PSplineKernel
Definition: splinekernel.hh:291
CSplineKernelPluginHandler
THandlerSingleton< TFactoryPluginHandler< CSplineKernelPlugin > > CSplineKernelPluginHandler
Definition: splinekernel.hh:303
CSplineKernel::SCache::index
VIndex index
cached indices
Definition: splinekernel.hh:99
CProductBase
The base class for all plug-in created object.
Definition: product_base.hh:40
CSplineKernel::type_descr
static const char * type_descr
plugin handling type description
Definition: splinekernel.hh:55
CSplineKernel
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:45
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
EInterpolation
EInterpolation
some constants for interpoation types
Definition: defines.hh:62
product_base.hh
CSplineKernel::plugin_type
CSplineKernel plugin_type
helper typedef for plugin handling
Definition: splinekernel.hh:52
CSplineKernel::SCache::never_flat
bool never_flat
always use mirror
Definition: splinekernel.hh:108
FACTORY_TRAIT
FACTORY_TRAIT(CSplineKernelPluginHandler)
integrate2
double EXPORT_CORE integrate2(const CSplineKernel &spline, double s1, double s2, int d1, int d2, double n, double x0, double L)
CSplineKernel::SCache::index_limit
int index_limit
last possible start index
Definition: splinekernel.hh:93
defines.hh
CSplineKernel::SCache::boundary_condition
const CSplineBoundaryCondition & boundary_condition
the boundary condition to be applied
Definition: splinekernel.hh:102
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49