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>
25 #include <mia/core/type_traits.hh>
26 #include <mia/core/factory.hh>
27 #include <mia/core/product_base.hh>
28 #include <mia/core/splinekernel.hh>
29 
30 #include <vector>
31 #include <memory>
32 
34 
40 };
41 
53 {
54 public:
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 
78  CSplineBoundaryCondition(const CSplineBoundaryCondition& /*other*/) = delete;
79 
80  CSplineBoundaryCondition& operator = (const CSplineBoundaryCondition& /*other*/) = delete;
81 
87  CSplineBoundaryCondition(int width);
88 
95  bool apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const;
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 ;
147 private:
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 
169 extern template class EXPORT_CORE TFactory<CSplineBoundaryCondition>;
170 
175 {
176 public:
181  CSplineBoundaryConditionPlugin(const char *name);
182 private:
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 
198 template<>
200 
202 
205 
206 
212 inline
214 {
215  return CSplineBoundaryConditionPluginHandler::instance().produce_unique(descr);
216 }
217 
218 
226 __attribute__((deprecated));
227 
228 
230 
246 template <typename T, int size>
247 struct __dispatch_filter_line {
248  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles);
249 };
250 
251 template <typename T, int size>
252 void __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 
274 template <typename T>
275 struct __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 
284 template <typename T>
285 void 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 
292 template <typename T>
293 void 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
THandlerSingleton::instance
static const T & instance()
bc_mirror_on_bounds
Definition: boundary_conditions.hh:36
factory.hh
CSplineBoundaryCondition::type_descr
static const char *const type_descr
type portion of the plugin search path
Definition: boundary_conditions.hh:63
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
CSplineBoundaryConditionPlugin
Base plugin for spline boundary conditions.
Definition: boundary_conditions.hh:174
CSplineKernel::VIndex
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:64
private
class EXPORT_CORE CMeans private
CSplineBoundaryCondition::plugin_type
CSplineBoundaryCondition plugin_type
helper typedef for plug-in handling
Definition: boundary_conditions.hh:60
bc_repeat
Definition: boundary_conditions.hh:37
CSplineBoundaryCondition
Abstract base class for B-spline interpolation boundary conditions.
Definition: boundary_conditions.hh:52
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CSplineBoundaryCondition::Pointer
std::unique_ptr< CSplineBoundaryCondition > Pointer
pointer type to this boundary condition
Definition: boundary_conditions.hh:70
THandlerSingleton
the singleton that a plug-in handler really is
Definition: handler.hh:158
CSplineBoundaryCondition::filter_line
void filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
Definition: boundary_conditions.hh:285
CSplineKernel::VWeight
std::vector< double > VWeight
type for the weight vector
Definition: splinekernel.hh:61
CSplineBoundaryCondition::template_filter_line
void template_filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
Definition: boundary_conditions.hh:293
msgstream.hh
CSplineBoundaryCondition::plugin_data
CSplineBoundaryCondition plugin_data
helper typedef for plug-in handling
Definition: boundary_conditions.hh:57
TPluginHandler
The basic template of all plugin handlers.
Definition: handler.hh:56
EBoundaryConditions
EBoundaryConditions
Definition: boundary_conditions.hh:35
CProductBase
The base class for all plug-in created object.
Definition: product_base.hh:40
CSplineBoundaryCondition::get_width
int get_width() const
Definition: boundary_conditions.hh:105
CSplineKernel
Base class for all spline based interpolation kernels.
Definition: splinekernel.hh:45
produce_spline_boundary_condition
PSplineBoundaryCondition produce_spline_boundary_condition(const std::string &descr)
Definition: boundary_conditions.hh:213
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
FACTORY_TRAIT
FACTORY_TRAIT(CSplineBoundaryConditionPluginHandler)
make spline boundary conditions parsable by the command line
std
Definition: gsl_iterator.hh:323
product_base.hh
CSplineBoundaryConditionPluginHandler
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > > CSplineBoundaryConditionPluginHandler
Definition: boundary_conditions.hh:196
CSplineBoundaryCondition::data_descr
static const char *const data_descr
data portion of the plugin search path
Definition: boundary_conditions.hh:66
type_traits.hh
PSplineBoundaryCondition
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
Definition: boundary_conditions.hh:167
bc_unknown
Definition: boundary_conditions.hh:39
bc_zero
Definition: boundary_conditions.hh:38
splinekernel.hh
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49