splinekernel.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_core_splinekernel_hh
#define mia_core_splinekernel_hh
#include <vector>
#include <memory>
#include <cmath>
#include <mia/core/defines.hh>
#include <mia/core/dictmap.hh>
#include <mia/core/factory.hh>
#include <mia/core/product_base.hh>
NS_MIA_BEGIN
class CSplineBoundaryCondition;
class EXPORT_CORE CSplineKernel : public CProductBase
{
public:
typedef CSplineKernel plugin_data;
typedef CSplineKernel plugin_type;
static const char *type_descr;
static const char *data_descr;
typedef std::vector<double> VWeight;
typedef std::vector<int> VIndex;
struct SCache {
SCache(size_t s, const CSplineBoundaryCondition& bc, bool am);
void reset();
double x;
int start_idx;
int index_limit;
VWeight weights;
VIndex index;
const CSplineBoundaryCondition& boundary_condition;
bool is_flat;
bool never_flat;
};
CSplineKernel(int degree, double shift, EInterpolation type);
virtual ~CSplineKernel();
void operator () (double x, VWeight& weight, VIndex& index)const;
void operator () (double x, SCache& cache)const;
void get_cached(double x, SCache& cache)const;
void get_uncached(double x, SCache& cache)const;
void derivative(double x, VWeight& weight, VIndex& index)const;
void derivative(double x, VWeight& weight, VIndex& index, int order)const;
int get_indices(double x, VIndex& index) const;
virtual void get_weights(double x, VWeight& weight) const = 0;
virtual void get_derivative_weights(double x, VWeight& weight) const = 0;
virtual void get_derivative_weights(double x, VWeight& weight, int order) const = 0;
virtual double get_weight_at(double x, int order) const;
EInterpolation get_type() const;
const std::vector<double>& get_poles() const;
size_t size() const;
double get_nonzero_radius() const;
int get_active_halfrange()const;
int get_start_idx_and_value_weights(double x, VWeight& weights) const;
int get_start_idx_and_derivative_weights(double x, VWeight& weights) const;
protected:
void add_pole(double x);
private:
int get_start_idx(double x) const;
void fill_index(short i, VIndex& index) const;
size_t m_half_degree;
double m_shift;
std::vector<double> m_poles;
size_t m_support_size;
EInterpolation m_type;
std::vector<short> m_indices;
};
typedef std::shared_ptr<CSplineKernel> PSplineKernel;
typedef TFactory<CSplineKernel> CSplineKernelPlugin;
template<> const char *const
TPluginHandler<TFactory<CSplineKernel>>::m_help;
typedef THandlerSingleton<TFactoryPluginHandler<CSplineKernelPlugin>> CSplineKernelPluginHandler;
inline PSplineKernel produce_spline_kernel(const std::string& descr)
{
return CSplineKernelPluginHandler::instance().produce(descr);
}
FACTORY_TRAIT(CSplineKernelPluginHandler);
template <>
struct __cache_policy<CSplineKernelPlugin> {
static bool apply()
{
return true;
}
};
template <typename T>
struct max_hold_type {
typedef double type;
};
template <class T>
struct coeff_map {
typedef T value_type;
typedef double coeff_type;
};
template <>
struct coeff_map<float> {
typedef float value_type;
typedef float coeff_type;
};
inline size_t CSplineKernel::size()const
{
return m_support_size;
}
double EXPORT_CORE integrate2(const CSplineKernel& spline, double s1, double s2, int d1, int d2, double n, double x0, double L);
NS_MIA_END
#endif
m_help
const char *const TPluginHandler< CSplineBoundaryConditionPlugin >::m_help
Definition boundary_conditions.hh:199
CProductBase
The base class for all plug-in created object.
Definition product_base.hh:41
CSplineBoundaryCondition
Abstract base class for B-spline interpolation boundary conditions.
Definition boundary_conditions.hh:53
CSplineKernel
Base class for all spline based interpolation kernels.
Definition splinekernel.hh:46
CSplineKernel::get_active_halfrange
int get_active_halfrange() const
CSplineKernel::plugin_data
CSplineKernel plugin_data
helper typedef for plugin handling
Definition splinekernel.hh:50
CSplineKernel::get_derivative_weights
virtual void get_derivative_weights(double x, VWeight &weight, int order) const =0
CSplineKernel::VWeight
std::vector< double > VWeight
type for the weight vector
Definition splinekernel.hh:61
CSplineKernel::get_derivative_weights
virtual void get_derivative_weights(double x, VWeight &weight) const =0
CSplineKernel::get_start_idx_and_value_weights
int get_start_idx_and_value_weights(double x, VWeight &weights) const
CSplineKernel::add_pole
void add_pole(double x)
CSplineKernel::plugin_type
CSplineKernel plugin_type
helper typedef for plugin handling
Definition splinekernel.hh:52
CSplineKernel::~CSplineKernel
virtual ~CSplineKernel()
CSplineKernel::CSplineKernel
CSplineKernel(int degree, double shift, EInterpolation type)
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::get_weights
virtual void get_weights(double x, VWeight &weight) const =0
CSplineKernel::type_descr
static const char * type_descr
plugin handling type description
Definition splinekernel.hh:55
CSplineKernel::get_weight_at
virtual double get_weight_at(double x, int order) const
CSplineKernel::get_poles
const std::vector< double > & get_poles() const
CSplineKernel::derivative
void derivative(double x, VWeight &weight, VIndex &index, int order) const
CSplineKernel::get_cached
void get_cached(double x, SCache &cache) const
CSplineKernel::derivative
void derivative(double x, VWeight &weight, VIndex &index) const
CSplineKernel::get_nonzero_radius
double get_nonzero_radius() const
CSplineKernel::get_uncached
void get_uncached(double x, SCache &cache) const
CSplineKernel::get_type
EInterpolation get_type() const
CSplineKernel::get_start_idx_and_derivative_weights
int get_start_idx_and_derivative_weights(double x, VWeight &weights) const
CSplineKernel::VIndex
std::vector< int > VIndex
type for the index vector
Definition splinekernel.hh:64
CSplineKernel::get_indices
int get_indices(double x, VIndex &index) const
type
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition factory.hh:51
THandlerSingleton
the singleton that a plug-in handler really is
Definition handler.hh:159
THandlerSingleton< TFactoryPluginHandler< CSplineKernelPlugin > >::instance
static const TFactoryPluginHandler< CSplineKernelPlugin > & instance()
TPluginHandler
The basic template of all plugin handlers.
Definition handler.hh:57
defines.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
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
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
dictmap.hh
factory.hh
CSplineKernelPluginHandler
THandlerSingleton< TFactoryPluginHandler< CSplineKernelPlugin > > CSplineKernelPluginHandler
Definition splinekernel.hh:303
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
FACTORY_TRAIT
#define FACTORY_TRAIT(F)
Definition factory_trait.hh:69
product_base.hh
integrate2
double EXPORT_CORE integrate2(const CSplineKernel &spline, double s1, double s2, int d1, int d2, double n, double x0, double L)
CSplineKernelPlugin
TFactory< CSplineKernel > CSplineKernelPlugin
base plugin for spline kernels
Definition splinekernel.hh:294
CSplineKernel::SCache
Definition splinekernel.hh:69
CSplineKernel::SCache::never_flat
bool never_flat
always use mirror
Definition splinekernel.hh:108
CSplineKernel::SCache::x
double x
Definition splinekernel.hh:87
CSplineKernel::SCache::is_flat
bool is_flat
store whether indices were mirrored
Definition splinekernel.hh:105
CSplineKernel::SCache::index
VIndex index
cached indices
Definition splinekernel.hh:99
CSplineKernel::SCache::index_limit
int index_limit
last possible start index
Definition splinekernel.hh:93
CSplineKernel::SCache::weights
VWeight weights
cached weights
Definition splinekernel.hh:96
CSplineKernel::SCache::boundary_condition
const CSplineBoundaryCondition & boundary_condition
the boundary condition to be applied
Definition splinekernel.hh:102
CSplineKernel::SCache::start_idx
int start_idx
last start index the B-spline was evaluated for
Definition splinekernel.hh:90
CSplineKernel::SCache::reset
void reset()
CSplineKernel::SCache::SCache
SCache(size_t s, const CSplineBoundaryCondition &bc, bool am)