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 public:
54 
57 
60 
62  static const char * const type_descr;
63 
65  static const char * const data_descr;
66 
67 
69  typedef std::unique_ptr<CSplineBoundaryCondition> Pointer;
70 
72 
73 
77  CSplineBoundaryCondition(const CSplineBoundaryCondition& /*other*/) = delete;
78 
79  CSplineBoundaryCondition& operator = (const CSplineBoundaryCondition& /*other*/) = delete;
80 
86  CSplineBoundaryCondition(int width);
87 
94  bool apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const;
95 
101  void set_width(int width);
102 
104  int get_width() const {
105  return m_width;
106  }
107 
118  template <typename T>
119  void filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
120 
128  void filter_line(std::vector<double>& coeff, const std::vector<double>& poles) const;
129 
137  template <typename T>
138  void template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
139 
143  virtual
144  CSplineBoundaryCondition *clone() const __attribute__((warn_unused_result)) = 0 ;
145 private:
146 
147  virtual void do_apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const = 0;
148  virtual void test_supported(int npoles) const = 0;
149 
150  virtual void do_set_width(int width);
151 
152 
153  virtual double initial_coeff(const std::vector<double>& coeff, double pole) const = 0;
154  virtual double initial_anti_coeff(const std::vector<double>& coeff, double pole)const = 0;
155 
156 
157  int m_width;
158 };
159 
160 
161 
166 
167 extern template class EXPORT_CORE TFactory<CSplineBoundaryCondition>;
168 
172 class EXPORT_CORE CSplineBoundaryConditionPlugin: public TFactory<CSplineBoundaryCondition> {
173 public:
178  CSplineBoundaryConditionPlugin(const char * name);
179 private:
180  virtual CSplineBoundaryCondition *do_create() const;
181 
182  virtual CSplineBoundaryCondition *do_create(int width) const = 0;
183 
184  int m_width;
185 };
186 
187 
188 
194 
195 template<>
197 
199 
202 
203 
209 inline
211 {
212  return CSplineBoundaryConditionPluginHandler::instance().produce_unique(descr);
213 }
214 
215 
223  __attribute__((deprecated));
224 
225 
227 
243 template <typename T, int size>
244 struct __dispatch_filter_line {
245  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles);
246 };
247 
248 template <typename T, int size>
249 void __dispatch_filter_line<T, size>::apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff,
250  const std::vector<double>& poles)
251 {
252  std::vector<double> temp(coeff.size());
253  for (int i = 0; i < size; ++i) {
254  std::transform(coeff.begin(), coeff.end(), temp.begin(),
255  [i](const T& x) { return x[i]; });
256  bc.filter_line(temp, poles);
257  for (size_t j = 0; j < coeff.size(); ++j)
258  coeff[j][i] = temp[j];
259  }
260 }
261 
267 template <typename T>
268 struct __dispatch_filter_line<T,1> {
269  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles) {
270  bc.template_filter_line(coeff, poles);
271  }
272 };
273 
275 
276 template <typename T>
277 void CSplineBoundaryCondition::filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
278 {
279  typedef atomic_data<T> atom;
280  __dispatch_filter_line<T, atom::size>::apply(*this, coeff, poles);
281 }
282 
283 
284 template <typename T>
285 void CSplineBoundaryCondition::template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
286 {
287  std::vector<double> temp(coeff.begin(), coeff.end());
288  filter_line(temp, poles);
289  std::transform(temp.begin(), temp.end(), coeff.begin(), [](double x) {return static_cast<T>(x);});
290 }
291 
293 #endif
PSplineBoundaryCondition produce_spline_boundary_condition(const std::string &descr)
the singleton that a plug-in handler really is
Definition: handler.hh:157
CSplineBoundaryCondition plugin_data
helper typedef for plug-in handling
static const char *const type_descr
type portion of the plugin search path
void template_filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
std::vector< double > VWeight
type for the weight vector
Definition: splinekernel.hh:60
Base plugin for spline boundary conditions.
static const char *const data_descr
data portion of the plugin search path
FACTORY_TRAIT(CSplineBoundaryConditionPluginHandler)
make spline boundary conditions parsable by the command line
std::unique_ptr< CSplineBoundaryCondition > Pointer
pointer type to this boundary condition
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:63
Abstract base class for B-spline interpolation boundary conditions.
void filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
EBoundaryConditions
CSplineBoundaryCondition plugin_type
helper typedef for plug-in handling
THandlerSingleton< TFactoryPluginHandler< CSplineBoundaryConditionPlugin > > CSplineBoundaryConditionPluginHandler
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
The base class for all plug-in created object.
Definition: product_base.hh:40
static const T & instance()
The basic template of all plugin handlers.
Definition: handler.hh:56
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36