OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
image_state_algorithm.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  Author: Ansgar Philippsen
23 */
24 
25 #ifndef IMG_IMAGE_STATE_ALGORITHM_HH
26 #define IMG_IMAGE_STATE_ALGORITHM_HH
27 
28 #include <ost/img/image.hh>
30 
31 #include "image_state_visitor.hh"
32 
33 namespace ost { namespace img { namespace image_state {
34 
35 /*
36  one-time definition of the constructor adapters, allowing
37  zero to 12 ctor parameters to be automagically used. There
38  is probably a recursive way to do this more elegantly...
39 
40  this version includes a call to a base class to allow a name
41  to be set
42 */
43 
44 #define IMAGE_STATE_VISITOR_CTOR_ADAPTERS(CLASS, BASE ) \
45  /* no param */ \
46  CLASS (): FNC(), BASE (FNC::GetAlgorithmName()) {} \
47  /* 1 param */ \
48  template <class P0> \
49  CLASS (const P0& p0): \
50  FNC(p0), BASE (FNC::GetAlgorithmName()) {} \
51  /* 2 params */ \
52  template <class P0, \
53  class P1> \
54  CLASS (const P0& p0, \
55  const P1& p1): \
56  FNC(p0,p1), BASE (FNC::GetAlgorithmName()) {} \
57  /* 3 params */ \
58  template <class P0, \
59  class P1, \
60  class P2> \
61  CLASS (const P0& p0, \
62  const P1& p1, \
63  const P2& p2): \
64  FNC(p0,p1,p2), BASE (FNC::GetAlgorithmName()) {} \
65  /* 4 params */ \
66  template <class P0, \
67  class P1, \
68  class P2, \
69  class P3> \
70  CLASS (const P0& p0, \
71  const P1& p1, \
72  const P2& p2, \
73  const P3& p3): \
74  FNC(p0,p1,p2,p3), BASE (FNC::GetAlgorithmName()) {} \
75  /* 5 params */ \
76  template <class P0, \
77  class P1, \
78  class P2, \
79  class P3, \
80  class P4> \
81  CLASS (const P0& p0, \
82  const P1& p1, \
83  const P2& p2, \
84  const P3& p3, \
85  const P4& p4): \
86  FNC(p0,p1,p2,p3,p4), BASE (FNC::GetAlgorithmName()) {} \
87  /* 6 params */ \
88  template <class P0, \
89  class P1, \
90  class P2, \
91  class P3, \
92  class P4, \
93  class P5> \
94  CLASS (const P0& p0, \
95  const P1& p1, \
96  const P2& p2, \
97  const P3& p3, \
98  const P4& p4, \
99  const P5& p5): \
100  FNC(p0,p1,p2,p3,p4,p5), BASE (FNC::GetAlgorithmName()) {} \
101  /* 7 params */ \
102  template <class P0, \
103  class P1, \
104  class P2, \
105  class P3, \
106  class P4, \
107  class P5, \
108  class P6> \
109  CLASS (const P0& p0, \
110  const P1& p1, \
111  const P2& p2, \
112  const P3& p3, \
113  const P4& p4, \
114  const P5& p5, \
115  const P6& p6): \
116  FNC(p0,p1,p2,p3,p4,p5,p6), BASE (FNC::GetAlgorithmName()) {} \
117  /* 8 params */ \
118  template <class P0, \
119  class P1, \
120  class P2, \
121  class P3, \
122  class P4, \
123  class P5, \
124  class P6, \
125  class P7> \
126  CLASS (const P0& p0, \
127  const P1& p1, \
128  const P2& p2, \
129  const P3& p3, \
130  const P4& p4, \
131  const P5& p5, \
132  const P6& p6, \
133  const P7& p7): \
134  FNC(p0,p1,p2,p3,p4,p5,p6,p7), BASE (FNC::GetAlgorithmName()) {} \
135  /* 9 params */ \
136  template <class P0, \
137  class P1, \
138  class P2, \
139  class P3, \
140  class P4, \
141  class P5, \
142  class P6, \
143  class P7, \
144  class P8> \
145  CLASS (const P0& p0, \
146  const P1& p1, \
147  const P2& p2, \
148  const P3& p3, \
149  const P4& p4, \
150  const P5& p5, \
151  const P6& p6, \
152  const P7& p7, \
153  const P8& p8): \
154  FNC(p0,p1,p2,p3,p4,p5,p6,p7,p8), BASE (FNC::GetAlgorithmName()) {} \
155  /* 10 params */ \
156  template <class P0, \
157  class P1, \
158  class P2, \
159  class P3, \
160  class P4, \
161  class P5, \
162  class P6, \
163  class P7, \
164  class P8, \
165  class P9> \
166  CLASS (const P0& p0, \
167  const P1& p1, \
168  const P2& p2, \
169  const P3& p3, \
170  const P4& p4, \
171  const P5& p5, \
172  const P6& p6, \
173  const P7& p7, \
174  const P8& p8, \
175  const P9& p9): \
176  FNC(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9), BASE (FNC::GetAlgorithmName()) {} \
177  /* 11 params */ \
178  template <class P0, \
179  class P1, \
180  class P2, \
181  class P3, \
182  class P4, \
183  class P5, \
184  class P6, \
185  class P7, \
186  class P8, \
187  class P9, \
188  class PA> \
189  CLASS (const P0& p0, \
190  const P1& p1, \
191  const P2& p2, \
192  const P3& p3, \
193  const P4& p4, \
194  const P5& p5, \
195  const P6& p6, \
196  const P7& p7, \
197  const P8& p8, \
198  const P9& p9, \
199  const PA& pa): \
200  FNC(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pa), BASE (FNC::GetAlgorithmName()) {} \
201  /* 12 params */ \
202  template <class P0, \
203  class P1, \
204  class P2, \
205  class P3, \
206  class P4, \
207  class P5, \
208  class P6, \
209  class P7, \
210  class P8, \
211  class P9, \
212  class PA, \
213  class PB> \
214  CLASS (const P0& p0, \
215  const P1& p1, \
216  const P2& p2, \
217  const P3& p3, \
218  const P4& p4, \
219  const P5& p5, \
220  const P6& p6, \
221  const P7& p7, \
222  const P8& p8, \
223  const P9& p9, \
224  const PA& pa, \
225  const PB& pb): \
226  FNC(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pa,pb), BASE (FNC::GetAlgorithmName()) {}
227 
228 
230 
260 template <class FNC>
261 class TEMPLATE_EXPORT ImageStateNonModAlgorithm: public FNC, public NonModAlgorithm, public ImageStateNonModVisitorBase {
262 public:
263 
265 
266  // base interface
267  virtual void Visit_(const RealSpatialImageState& is) {T_Visit_(is);}
268  virtual void Visit_(const ComplexSpatialImageState& is) {T_Visit_(is);}
269  virtual void Visit_(const RealFrequencyImageState& is) {T_Visit_(is);}
270  virtual void Visit_(const ComplexFrequencyImageState& is) {T_Visit_(is);}
271  virtual void Visit_(const ComplexHalfFrequencyImageState& is) {T_Visit_(is);}
272  virtual void Visit_(const WordSpatialImageState& is) {T_Visit_(is);}
273 
274  // const algorithm interface
275  virtual void Visit(const ConstImageHandle& h) {
276  h.StateApply(*this);
277  }
278  virtual void Visit(const Function& f) {
279  this->VisitFunction(f);
280  }
281 
282 private:
283  /*
284  must be defined at this point to ensure proper instantiation of
285  ImageStateNonModAlgorithm<X>
286  */
287  template <typename T, class D>
288  void T_Visit_(const ImageStateImpl<T,D>& isi) {
289  this->VisitState(isi);
290  }
291 
292 };
293 
294 
296 
314 template <class FNC>
315 class TEMPLATE_EXPORT ImageStateModIPAlgorithm: public FNC, public ModIPAlgorithm, public ImageStateModIPVisitorBase {
316 public:
318 
319  virtual void Visit_(RealSpatialImageState& is) {T_Visit_(is);}
320  virtual void Visit_(ComplexSpatialImageState& is) {T_Visit_(is);}
321  virtual void Visit_(RealFrequencyImageState& is) {T_Visit_(is);}
322  virtual void Visit_(ComplexFrequencyImageState& is) {T_Visit_(is);}
323  virtual void Visit_(ComplexHalfFrequencyImageState& is) {T_Visit_(is);}
324  virtual void Visit_(WordSpatialImageState& is) {T_Visit_(is);}
325 
326  // mod ip algorithm interface
327  virtual void Visit(ImageHandle& h) {
328  h.StateApplyIP(*this);
329  }
330 
331 private:
332  template <typename T, class D>
333  void T_Visit_(ImageStateImpl<T,D>& isi) {
334  this->VisitState(isi);
335  }
336 };
337 
339 
357 template <class FNC>
358 class TEMPLATE_EXPORT ImageStateConstModIPAlgorithm: public FNC,
359  public ConstModIPAlgorithm,
361 public:
363 
364  virtual void Visit_(RealSpatialImageState& is) const {T_Visit_(is);}
365  virtual void Visit_(ComplexSpatialImageState& is) const {T_Visit_(is);}
366  virtual void Visit_(RealFrequencyImageState& is) const {T_Visit_(is);}
367  virtual void Visit_(ComplexFrequencyImageState& is) const {T_Visit_(is);}
368  virtual void Visit_(ComplexHalfFrequencyImageState& is) const {T_Visit_(is);}
369  virtual void Visit_(WordSpatialImageState& is) const {T_Visit_(is);}
370 
371  // mod ip const algorithm interface
372  virtual void Visit(ImageHandle& h) const {
373  h.StateApplyIP(*this);
374  }
375 
376 private:
377  template <typename T, class D>
378  void T_Visit_(ImageStateImpl<T,D>& isi) const {
379  this->VisitState(isi);
380  }
381 };
382 
384 template <class FNC>
385 class TEMPLATE_EXPORT ImageStateModOPAlgorithm: public FNC, public ModOPAlgorithm, public ImageStateModOPVisitorBase {
386 public:
387 
389 
390  virtual ImageStateBasePtr Visit_(const RealSpatialImageState& is) {return T_Visit_(is);}
391  virtual ImageStateBasePtr Visit_(const ComplexSpatialImageState& is) {return T_Visit_(is);}
392  virtual ImageStateBasePtr Visit_(const RealFrequencyImageState& is) {return T_Visit_(is);}
393  virtual ImageStateBasePtr Visit_(const ComplexFrequencyImageState& is) {return T_Visit_(is);}
394  virtual ImageStateBasePtr Visit_(const ComplexHalfFrequencyImageState& is) {return T_Visit_(is);}
395  virtual ImageStateBasePtr Visit_(const WordSpatialImageState& is) {return T_Visit_(is);}
396 
397  // mod op algorithm interface
398  virtual ImageHandle Visit(const ConstImageHandle& h) {
399  return h.StateApply(*this);
400  }
401 
402 private:
403  template <typename T, class D>
404  ImageStateBasePtr T_Visit_(const ImageStateImpl<T,D>& isi) {
405  return this->VisitState(isi);
406  }
407 };
408 
410 template <class FNC>
411 class TEMPLATE_EXPORT ImageStateConstModOPAlgorithm: public FNC,
412  public ConstModOPAlgorithm,
414 public:
415 
417 
418  virtual ImageStateBasePtr Visit_(const RealSpatialImageState& is) const {return T_Visit_(is);}
419  virtual ImageStateBasePtr Visit_(const ComplexSpatialImageState& is) const {return T_Visit_(is);}
420  virtual ImageStateBasePtr Visit_(const RealFrequencyImageState& is) const {return T_Visit_(is);}
421  virtual ImageStateBasePtr Visit_(const ComplexFrequencyImageState& is) const {return T_Visit_(is);}
422  virtual ImageStateBasePtr Visit_(const ComplexHalfFrequencyImageState& is) const {return T_Visit_(is);}
423  virtual ImageStateBasePtr Visit_(const WordSpatialImageState& is) const {return T_Visit_(is);}
424 
425  // mod op algorithm interface
426  virtual ImageHandle Visit(const ConstImageHandle& h) const {
427  return h.StateApply(*this);
428  }
429 
430 private:
431  template <typename T, class D>
432  ImageStateBasePtr T_Visit_(const ImageStateImpl<T,D>& isi) const {
433  return this->VisitState(isi);
434  }
435 };
436 
437 
439 template <class FNC>
440 class TEMPLATE_EXPORT ImageStateMorphAlgorithm: public FNC, public ModIPAlgorithm, public ImageStateMorphVisitorBase {
441 public:
442 
444 
445  virtual ImageStateBasePtr Visit_(RealSpatialImageState& is) {return T_Visit_(is);}
446  virtual ImageStateBasePtr Visit_(ComplexSpatialImageState& is) {return T_Visit_(is);}
447  virtual ImageStateBasePtr Visit_(RealFrequencyImageState& is) {return T_Visit_(is);}
448  virtual ImageStateBasePtr Visit_(ComplexFrequencyImageState& is) {return T_Visit_(is);}
449  virtual ImageStateBasePtr Visit_(ComplexHalfFrequencyImageState& is) {return T_Visit_(is);}
450  virtual ImageStateBasePtr Visit_(WordSpatialImageState& is) {return T_Visit_(is);}
451 
452  // mod ip algorithm interface
453  virtual void Visit(ImageHandle& h) {
454  h.StateApply(*this);
455  }
456 
457 private:
458  template <typename T, class D>
459  ImageStateBasePtr T_Visit_(ImageStateImpl<T,D>& isi) {
460  return this->VisitState(isi);
461  }
462 };
463 
464 #undef IMAGE_STATE_VISITOR_CTOR_ADAPTERS
465 
466 }}} // ns
467 
468 #endif