boundary_conditions.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_boundary_conditions_hh
#define mia_core_boundary_conditions_hh
#include <mia/core/msgstream.hh>
#include <mia/core/type_traits.hh>
#include <mia/core/factory.hh>
#include <mia/core/product_base.hh>
#include <mia/core/splinekernel.hh>
#include <vector>
#include <memory>
NS_MIA_BEGIN
enum EBoundaryConditions {
bc_mirror_on_bounds,
bc_repeat,
bc_zero,
bc_unknown
};
class EXPORT_CORE CSplineBoundaryCondition : public CProductBase
{
public:
typedef CSplineBoundaryCondition plugin_data;
typedef CSplineBoundaryCondition plugin_type;
static const char *const type_descr;
static const char *const data_descr;
typedef std::unique_ptr<CSplineBoundaryCondition> Pointer;
CSplineBoundaryCondition();
CSplineBoundaryCondition(const CSplineBoundaryCondition& /*other*/) = delete;
CSplineBoundaryCondition& operator = (const CSplineBoundaryCondition& /*other*/) = delete;
CSplineBoundaryCondition(int width);
bool apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const;
void set_width(int width);
int get_width() const
{
return m_width;
}
template <typename T>
void filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
void filter_line(std::vector<double>& coeff, const std::vector<double>& poles) const;
template <typename T>
void template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
virtual
CSplineBoundaryCondition *clone() const __attribute__((warn_unused_result)) = 0 ;
private:
virtual void do_apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const = 0;
virtual void test_supported(int npoles) const = 0;
virtual void do_set_width(int width);
virtual double initial_coeff(const std::vector<double>& coeff, double pole) const = 0;
virtual double initial_anti_coeff(const std::vector<double>& coeff, double pole)const = 0;
int m_width;
};
typedef CSplineBoundaryCondition::Pointer PSplineBoundaryCondition;
extern template class EXPORT_CORE TFactory<CSplineBoundaryCondition>;
class EXPORT_CORE CSplineBoundaryConditionPlugin: public TFactory<CSplineBoundaryCondition>
{
public:
CSplineBoundaryConditionPlugin(const char *name);
private:
virtual CSplineBoundaryCondition *do_create() const;
virtual CSplineBoundaryCondition *do_create(int width) const = 0;
int m_width;
};
typedef THandlerSingleton<TFactoryPluginHandler<CSplineBoundaryConditionPlugin>> CSplineBoundaryConditionPluginHandler;
template<>
const char *const TPluginHandler<CSplineBoundaryConditionPlugin>::m_help;
extern template class EXPORT_CORE THandlerSingleton<TFactoryPluginHandler<CSplineBoundaryConditionPlugin>>;
FACTORY_TRAIT(CSplineBoundaryConditionPluginHandler);
inline
PSplineBoundaryCondition produce_spline_boundary_condition(const std::string& descr)
{
return CSplineBoundaryConditionPluginHandler::instance().produce_unique(descr);
}
EXPORT_CORE PSplineBoundaryCondition produce_spline_boundary_condition(const std::string& descr, int width)
__attribute__((deprecated));
template <typename T, int size>
struct __dispatch_filter_line {
static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles);
};
template <typename T, int size>
void __dispatch_filter_line<T, size>::apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff,
const std::vector<double>& poles)
{
std::vector<double> temp(coeff.size());
for (int i = 0; i < size; ++i) {
std::transform(coeff.begin(), coeff.end(), temp.begin(),
[i](const T & x) {
return x[i];
});
bc.filter_line(temp, poles);
for (size_t j = 0; j < coeff.size(); ++j)
coeff[j][i] = temp[j];
}
}
template <typename T>
struct __dispatch_filter_line<T, 1> {
static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles)
{
bc.template_filter_line(coeff, poles);
}
};
template <typename T>
void CSplineBoundaryCondition::filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
{
typedef atomic_data<T> atom;
__dispatch_filter_line<T, atom::size>::apply(*this, coeff, poles);
}
template <typename T>
void CSplineBoundaryCondition::template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
{
std::vector<double> temp(coeff.begin(), coeff.end());
filter_line(temp, poles);
std::transform(temp.begin(), temp.end(), coeff.begin(), [](double x) {
return static_cast<T>(x);
});
}
NS_MIA_END
#endif
produce_spline_boundary_condition
PSplineBoundaryCondition produce_spline_boundary_condition(const std::string &descr)
Definition boundary_conditions.hh:213
EBoundaryConditions
EBoundaryConditions
Definition boundary_conditions.hh:35
bc_repeat
@ bc_repeat
Definition boundary_conditions.hh:37
bc_mirror_on_bounds
@ bc_mirror_on_bounds
Definition boundary_conditions.hh:36
bc_zero
@ bc_zero
Definition boundary_conditions.hh:38
bc_unknown
@ bc_unknown
Definition boundary_conditions.hh:39
CProductBase
The base class for all plug-in created object.
Definition product_base.hh:41
CSplineBoundaryConditionPlugin::CSplineBoundaryConditionPlugin
CSplineBoundaryConditionPlugin(const char *name)
CSplineBoundaryCondition
Abstract base class for B-spline interpolation boundary conditions.
Definition boundary_conditions.hh:53
CSplineBoundaryCondition::apply
bool apply(CSplineKernel::VIndex &index, CSplineKernel::VWeight &weights) const
CSplineBoundaryCondition::CSplineBoundaryCondition
CSplineBoundaryCondition(int width)
CSplineBoundaryCondition::Pointer
std::unique_ptr< CSplineBoundaryCondition > Pointer
pointer type to this boundary condition
Definition boundary_conditions.hh:70
CSplineBoundaryCondition::set_width
void set_width(int width)
CSplineBoundaryCondition::CSplineBoundaryCondition
CSplineBoundaryCondition()
CSplineBoundaryCondition::plugin_type
CSplineBoundaryCondition plugin_type
helper typedef for plug-in handling
Definition boundary_conditions.hh:60
CSplineBoundaryCondition::CSplineBoundaryCondition
CSplineBoundaryCondition(const CSplineBoundaryCondition &)=delete
CSplineBoundaryCondition::get_width
int get_width() const
Definition boundary_conditions.hh:105
CSplineBoundaryCondition::plugin_data
CSplineBoundaryCondition plugin_data
helper typedef for plug-in handling
Definition boundary_conditions.hh:57
CSplineBoundaryCondition::filter_line
void filter_line(std::vector< double > &coeff, const std::vector< double > &poles) const
CSplineBoundaryCondition::template_filter_line
void template_filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
Definition boundary_conditions.hh:293
CSplineBoundaryCondition::clone
virtual CSplineBoundaryCondition * clone() const __attribute__((warn_unused_result))=0
CSplineBoundaryCondition::data_descr
static const char *const data_descr
data portion of the plugin search path
Definition boundary_conditions.hh:66
CSplineBoundaryCondition::type_descr
static const char *const type_descr
type portion of the plugin search path
Definition boundary_conditions.hh:63
CSplineBoundaryCondition::filter_line
void filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
*‍/
Definition boundary_conditions.hh:285
CSplineKernel
Base class for all spline based interpolation kernels.
Definition splinekernel.hh:46
CSplineKernel::VWeight
std::vector< double > VWeight
type for the weight vector
Definition splinekernel.hh:61
CSplineKernel::VIndex
std::vector< int > VIndex
type for the index vector
Definition splinekernel.hh:64
Pointer
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition factory.hh:51
TFactory< CSplineBoundaryCondition >::TFactory
TFactory(char const *const name)
Definition factory.hh:173
THandlerSingleton
the singleton that a plug-in handler really is
Definition handler.hh:159
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > >::instance
static const TFactoryPluginHandler< CSplineBoundaryConditionPlugin > & instance()
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
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
factory.hh
PSplineBoundaryCondition
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
Definition boundary_conditions.hh:167
CSplineBoundaryConditionPluginHandler
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > > CSplineBoundaryConditionPluginHandler
Definition boundary_conditions.hh:196
FACTORY_TRAIT
#define FACTORY_TRAIT(F)
Definition factory_trait.hh:69
msgstream.hh
std
Definition gsl_iterator.hh:324
product_base.hh
splinekernel.hh
type_traits.hh