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>
31
33
34
36
46{
47public:
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
91
94
97
100
103
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
225
229 const std::vector<double>& get_poles() const;
230
234 size_t size() const;
235
236
238 double get_nonzero_radius() const;
239
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
259protected:
263 void add_pole(double x);
264
265private:
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
291typedef std::shared_ptr<CSplineKernel> PSplineKernel;
292
295
296
297template<> const char *const
304
312inline PSplineKernel produce_spline_kernel(const std::string& descr)
313{
314 return CSplineKernelPluginHandler::instance().produce(descr);
315}
316
318
324template <>
325struct __cache_policy<CSplineKernelPlugin> {
326 static bool apply()
327 {
328 return true;
329 }
330};
331
332template <typename T>
333struct max_hold_type {
334 typedef double type;
335};
336
341template <class T>
342struct coeff_map {
343 typedef T value_type;
344 typedef double coeff_type;
345};
350template <>
351struct coeff_map<float> {
352 typedef float value_type;
353 typedef float coeff_type;
354};
355
357
358inline size_t CSplineKernel::size()const
359{
360 return m_support_size;
361}
362
363
382double 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
The base class for all plug-in created object.
Abstract base class for B-spline interpolation boundary conditions.
Base class for all spline based interpolation kernels.
int get_active_halfrange() const
CSplineKernel plugin_data
helper typedef for plugin handling
virtual void get_derivative_weights(double x, VWeight &weight, int order) const =0
std::vector< double > VWeight
type for the weight vector
virtual void get_derivative_weights(double x, VWeight &weight) const =0
int get_start_idx_and_value_weights(double x, VWeight &weights) const
void add_pole(double x)
CSplineKernel plugin_type
helper typedef for plugin handling
virtual ~CSplineKernel()
CSplineKernel(int degree, double shift, EInterpolation type)
size_t size() const
static const char * data_descr
plugin handling data description
virtual void get_weights(double x, VWeight &weight) const =0
static const char * type_descr
plugin handling type description
virtual double get_weight_at(double x, int order) const
const std::vector< double > & get_poles() const
void derivative(double x, VWeight &weight, VIndex &index, int order) const
void get_cached(double x, SCache &cache) const
void derivative(double x, VWeight &weight, VIndex &index) const
double get_nonzero_radius() const
void get_uncached(double x, SCache &cache) const
EInterpolation get_type() const
int get_start_idx_and_derivative_weights(double x, VWeight &weights) const
std::vector< int > VIndex
type for the index vector
int get_indices(double x, VIndex &index) const
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition factory.hh:51
the singleton that a plug-in handler really is
Definition handler.hh:159
static const T & instance()
The basic template of all plugin handlers.
Definition handler.hh:57
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition defines.hh:101
EInterpolation
some constants for interpoation types
Definition defines.hh:62
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
THandlerSingleton< TFactoryPluginHandler< CSplineKernelPlugin > > CSplineKernelPluginHandler
PSplineKernel produce_spline_kernel(const std::string &descr)
std::shared_ptr< CSplineKernel > PSplineKernel
#define FACTORY_TRAIT(F)
double EXPORT_CORE integrate2(const CSplineKernel &spline, double s1, double s2, int d1, int d2, double n, double x0, double L)
TFactory< CSplineKernel > CSplineKernelPlugin
base plugin for spline kernels
bool never_flat
always use mirror
bool is_flat
store whether indices were mirrored
VIndex index
cached indices
int index_limit
last possible start index
VWeight weights
cached weights
const CSplineBoundaryCondition & boundary_condition
the boundary condition to be applied
int start_idx
last start index the B-spline was evaluated for
SCache(size_t s, const CSplineBoundaryCondition &bc, bool am)