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-2013 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 
96 
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:
268  void fill_index(short i, VIndex& index) const;
269 
270 
271  size_t m_half_degree;
272 
273  double m_shift;
274 
275  std::vector<double> m_poles;
276 
277  size_t m_support_size;
278 
279  EInterpolation m_type;
280  std::vector<short> m_indices;
281 
282 };
283 
288 typedef std::shared_ptr<CSplineKernel> PSplineKernel;
289 
292 
298 
306 inline PSplineKernel produce_spline_kernel(const std::string& descr)
307 {
308  return CSplineKernelPluginHandler::instance().produce(descr);
309 }
310 
312 
313 
321 };
322 
328 template <>
329 struct __cache_policy<CSplineKernelPlugin> {
330  static bool apply() {
331  return true;
332  }
333 };
334 
335 template <typename T>
336 struct max_hold_type {
337  typedef double type;
338 };
339 
344 template <class T>
345 struct coeff_map {
346  typedef T value_type;
347  typedef double coeff_type;
348 };
353 template <>
354 struct coeff_map<float> {
355  typedef float value_type;
356  typedef float coeff_type;
357 };
358 
360 
361 inline size_t CSplineKernel::size()const
362 {
363  return m_support_size;
364 }
365 
366 
385 double EXPORT_CORE integrate2(const CSplineKernel& spline, double s1, double s2, int d1, int d2, double n, double x0, double L);
386 
387 
389 
390 #endif