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-2015 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*/) = default;
78 
84  CSplineBoundaryCondition(int width);
85 
92  bool apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const;
93 
99  void set_width(int width);
100 
102  int get_width() const {
103  return m_width;
104  }
105 
116  template <typename T>
117  void filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
118 
126  void filter_line(std::vector<double>& coeff, const std::vector<double>& poles) const;
127 
135  template <typename T>
136  void template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const;
137 
141  virtual
142  CSplineBoundaryCondition *clone() const __attribute__((warn_unused_result)) = 0 ;
143 private:
144 
145  virtual void do_apply(CSplineKernel::VIndex& index, CSplineKernel::VWeight& weights) const = 0;
146  virtual void test_supported(int npoles) const = 0;
147 
148  virtual void do_set_width(int width);
149 
150 
151  virtual double initial_coeff(const std::vector<double>& coeff, double pole) const = 0;
152  virtual double initial_anti_coeff(const std::vector<double>& coeff, double pole)const = 0;
153 
154 
155  int m_width;
156 };
157 
158 
159 
164 
165 extern template class EXPORT_CORE TFactory<CSplineBoundaryCondition>;
166 
170 class EXPORT_CORE CSplineBoundaryConditionPlugin: public TFactory<CSplineBoundaryCondition> {
171 public:
176  CSplineBoundaryConditionPlugin(const char * name);
177 private:
178  virtual CSplineBoundaryCondition *do_create() const;
179 
180  virtual CSplineBoundaryCondition *do_create(int width) const = 0;
181 
182  int m_width;
183 };
184 
185 
186 
192 
194 
197 
198 
204 inline
206 {
207  return CSplineBoundaryConditionPluginHandler::instance().produce_unique(descr);
208 }
209 
210 
218  __attribute__((deprecated));
219 
220 
222 
238 template <typename T, int size>
239 struct __dispatch_filter_line {
240  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles);
241 };
242 
243 template <typename T, int size>
244 void __dispatch_filter_line<T, size>::apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff,
245  const std::vector<double>& poles)
246 {
247  std::vector<double> temp(coeff.size());
248  for (int i = 0; i < size; ++i) {
249  std::transform(coeff.begin(), coeff.end(), temp.begin(),
250  [i](const T& x) { return x[i]; });
251  bc.filter_line(temp, poles);
252  for (size_t j = 0; j < coeff.size(); ++j)
253  coeff[j][i] = temp[j];
254  }
255 }
256 
262 template <typename T>
263 struct __dispatch_filter_line<T,1> {
264  static void apply(const CSplineBoundaryCondition& bc, std::vector<T>& coeff, const std::vector<double>& poles) {
265  bc.template_filter_line(coeff, poles);
266  }
267 };
268 
270 
271 template <typename T>
272 void CSplineBoundaryCondition::filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
273 {
274  typedef atomic_data<T> atom;
275  __dispatch_filter_line<T, atom::size>::apply(*this, coeff, poles);
276 }
277 
278 
279 template <typename T>
280 void CSplineBoundaryCondition::template_filter_line(std::vector<T>& coeff, const std::vector<double>& poles) const
281 {
282  std::vector<double> temp(coeff.begin(), coeff.end());
283  filter_line(temp, poles);
284  std::transform(temp.begin(), temp.end(), coeff.begin(), [](double x) {return static_cast<T>(x);});
285 }
286 
288 #endif
PSplineBoundaryCondition produce_spline_boundary_condition(const std::string &descr)
the singleton that a plug-in handler really is
Definition: handler.hh:155
CSplineBoundaryCondition plugin_data
helper typedef for plug-in handling
static const char *const type_descr
type portion of the plugin search path
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:43
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
void template_filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
void filter_line(std::vector< T > &coeff, const std::vector< double > &poles) const
std::vector< int > VIndex
type for the index vector
Definition: splinekernel.hh:63
Abstract base class for B-spline interpolation boundary conditions.
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:110
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:46