My Project
boundary_conditions.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_boundary_conditions_hh
22#define mia_core_boundary_conditions_hh
23
24#include <mia/core/msgstream.hh>
26#include <mia/core/factory.hh>
29
30#include <vector>
31#include <memory>
32
34
40};
41
53{
54public:
55
58
61
63 static const char *const type_descr;
64
66 static const char *const data_descr;
67
68
70 typedef std::unique_ptr<CSplineBoundaryCondition> Pointer;
71
73
74
79
80 CSplineBoundaryCondition& operator = (const CSplineBoundaryCondition& /*other*/) = delete;
81
88
96
102 void set_width(int width);
103
105 int get_width() const
106 {
107 return m_width;
108 }
109
120 template <typename T>
121 void filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
122
130 void filter_line(std::vector<double>& coeff, const std::vector<double>& poles) const;
131
139 template <typename T>
140 void template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
141
145 virtual
146 CSplineBoundaryCondition *clone() const __attribute__((warn_unused_result)) = 0 ;
147private:
148
149 virtual void do_apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const = 0;
150 virtual void test_supported(int npoles) const = 0;
151
152 virtual void do_set_width(int width);
153
154
155 virtual double initial_coeff(const std::vector<double>& coeff, double pole) const = 0;
156 virtual double initial_anti_coeff(const std::vector<double>& coeff, double pole)const = 0;
157
158
159 int m_width;
160};
161
162
163
168
169extern template class EXPORT_CORE TFactory<CSplineBoundaryCondition>;
170
175{
176public:
182private:
183 virtual CSplineBoundaryCondition *do_create() const;
184
185 virtual CSplineBoundaryCondition *do_create(int width) const = 0;
186
187 int m_width;
188};
189
190
191
197
198template<>
200
202
205
206
212inline
214{
215 return CSplineBoundaryConditionPluginHandler::instance().produce_unique(descr);
216}
217
218
226__attribute__((deprecated));
227
228
230
246template <typename T, int size>
247struct __dispatch_filter_line {
248 static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles);
249};
250
251template <typename T, int size>
252void __dispatch_filter_line<T, size>::apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff,
253 const std::vector<double>& poles)
254{
255 std::vector<double> temp(coeff.size());
256
257 for (int i = 0; i < size; ++i) {
258 std::transform(coeff.begin(), coeff.end(), temp.begin(),
259 [i](const T & x) {
260 return x[i];
261 });
262 bc.filter_line(temp, poles);
263
264 for (size_t j = 0; j < coeff.size(); ++j)
265 coeff[j][i] = temp[j];
266 }
267}
268
274template <typename T>
275struct __dispatch_filter_line<T, 1> {
276 static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles)
277 {
278 bc.template_filter_line(coeff, poles);
279 }
280};
281
283
284template <typename T>
285void CSplineBoundaryCondition::filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
286{
287 typedef atomic_data<T> atom;
288 __dispatch_filter_line<T, atom::size>::apply(*this, coeff, poles);
289}
290
291
292template <typename T>
293void CSplineBoundaryCondition::template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
294{
295 std::vector<double> temp(coeff.begin(), coeff.end());
296 filter_line(temp, poles);
297 std::transform(temp.begin(), temp.end(), coeff.begin(), [](double x) {
298 return static_cast<T>(x);
299 });
300}
301
303#endif
PSplineBoundaryCondition produce_spline_boundary_condition(const std::string &descr)
EBoundaryConditions
@ bc_repeat
@ bc_mirror_on_bounds
@ bc_unknown
FACTORY_TRAIT(CSplineBoundaryConditionPluginHandler)
make spline boundary conditions parsable by the command line
The base class for all plug-in created object.
Definition: product_base.hh:41
Base plugin for spline boundary conditions.
CSplineBoundaryConditionPlugin(const char *name)
Abstract base class for B-spline interpolation boundary conditions.
bool apply(CSplineKernel::VIndex &index, CSplineKernel::VWeight &weights) const
CSplineBoundaryCondition(int width)
std::unique_ptr< CSplineBoundaryCondition > Pointer
pointer type to this boundary condition
void set_width(int width)
CSplineBoundaryCondition plugin_type
helper typedef for plug-in handling
CSplineBoundaryCondition(const CSplineBoundaryCondition &)=delete
CSplineBoundaryCondition plugin_data
helper typedef for plug-in handling
void filter_line(std::vector< double > &coeff, const std::vector< double > &poles) const
void template_filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
virtual CSplineBoundaryCondition * clone() const __attribute__((warn_unused_result))=0
static const char *const data_descr
data portion of the plugin search path
static const char *const type_descr
type portion of the plugin search path
void filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:46
std::vector< double > VWeight
type for the weight vector
Definition: splinekernel.hh:61
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:64
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
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > > CSplineBoundaryConditionPluginHandler