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-2016 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 
196 
199 
200 
206 inline
208 {
209  return CSplineBoundaryConditionPluginHandler::instance().produce_unique(descr);
210 }
211 
212 
220  __attribute__((deprecated));
221 
222 
224 
240 template <typename T, int size>
241 struct __dispatch_filter_line {
242  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles);
243 };
244 
245 template <typename T, int size>
246 void __dispatch_filter_line<T, size>::apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff,
247  const std::vector<double>& poles)
248 {
249  std::vector<double> temp(coeff.size());
250  for (int i = 0; i < size; ++i) {
251  std::transform(coeff.begin(), coeff.end(), temp.begin(),
252  [i](const T& x) { return x[i]; });
253  bc.filter_line(temp, poles);
254  for (size_t j = 0; j < coeff.size(); ++j)
255  coeff[j][i] = temp[j];
256  }
257 }
258 
264 template <typename T>
265 struct __dispatch_filter_line<T,1> {
266  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles) {
267  bc.template_filter_line(coeff, poles);
268  }
269 };
270 
272 
273 template <typename T>
274 void CSplineBoundaryCondition::filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
275 {
276  typedef atomic_data<T> atom;
277  __dispatch_filter_line<T, atom::size>::apply(*this, coeff, poles);
278 }
279 
280 
281 template <typename T>
282 void CSplineBoundaryCondition::template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
283 {
284  std::vector<double> temp(coeff.begin(), coeff.end());
285  filter_line(temp, poles);
286  std::transform(temp.begin(), temp.end(), coeff.begin(), [](double x) {return static_cast<T>(x);});
287 }
288 
290 #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()
CSplineBoundaryCondition::Pointer PSplineBoundaryCondition
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36