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 
255 template <class FNC>
256 class TEMPLATE_EXPORT ImageStateNonModAlgorithm: public FNC, public NonModAlgorithm, public ImageStateNonModVisitorBase {
257 public:
258 
260 
261  // base interface
262  virtual void Visit_(const RealSpatialImageState& is) {T_Visit_(is);}
263  virtual void Visit_(const ComplexSpatialImageState& is) {T_Visit_(is);}
264  virtual void Visit_(const RealFrequencyImageState& is) {T_Visit_(is);}
265  virtual void Visit_(const ComplexFrequencyImageState& is) {T_Visit_(is);}
266  virtual void Visit_(const ComplexHalfFrequencyImageState& is) {T_Visit_(is);}
267  virtual void Visit_(const WordSpatialImageState& is) {T_Visit_(is);}
268 
269  // const algorithm interface
270  virtual void Visit(const ConstImageHandle& h) {
271  h.StateApply(*this);
272  }
273 
274 private:
275  /*
276  must be defined at this point to ensure proper instantiation of
277  ImageStateNonModAlgorithm<X>
278  */
279  template <typename T, class D>
280  void T_Visit_(const ImageStateImpl<T,D>& isi) {
281  this->VisitState(isi);
282  }
283 
284 };
285 
286 
288 
306 template <class FNC>
307 class TEMPLATE_EXPORT ImageStateModIPAlgorithm: public FNC, public ModIPAlgorithm, public ImageStateModIPVisitorBase {
308 public:
310 
311  virtual void Visit_(RealSpatialImageState& is) {T_Visit_(is);}
312  virtual void Visit_(ComplexSpatialImageState& is) {T_Visit_(is);}
313  virtual void Visit_(RealFrequencyImageState& is) {T_Visit_(is);}
314  virtual void Visit_(ComplexFrequencyImageState& is) {T_Visit_(is);}
315  virtual void Visit_(ComplexHalfFrequencyImageState& is) {T_Visit_(is);}
316  virtual void Visit_(WordSpatialImageState& is) {T_Visit_(is);}
317 
318  // mod ip algorithm interface
319  virtual void Visit(ImageHandle& h) {
320  h.StateApplyIP(*this);
321  }
322 
323 private:
324  template <typename T, class D>
325  void T_Visit_(ImageStateImpl<T,D>& isi) {
326  this->VisitState(isi);
327  }
328 };
329 
331 
349 template <class FNC>
350 class TEMPLATE_EXPORT ImageStateConstModIPAlgorithm: public FNC,
351  public ConstModIPAlgorithm,
353 public:
355 
356  virtual void Visit_(RealSpatialImageState& is) const {T_Visit_(is);}
357  virtual void Visit_(ComplexSpatialImageState& is) const {T_Visit_(is);}
358  virtual void Visit_(RealFrequencyImageState& is) const {T_Visit_(is);}
359  virtual void Visit_(ComplexFrequencyImageState& is) const {T_Visit_(is);}
360  virtual void Visit_(ComplexHalfFrequencyImageState& is) const {T_Visit_(is);}
361  virtual void Visit_(WordSpatialImageState& is) const {T_Visit_(is);}
362 
363  // mod ip const algorithm interface
364  virtual void Visit(ImageHandle& h) const {
365  h.StateApplyIP(*this);
366  }
367 
368 private:
369  template <typename T, class D>
370  void T_Visit_(ImageStateImpl<T,D>& isi) const {
371  this->VisitState(isi);
372  }
373 };
374 
376 template <class FNC>
377 class TEMPLATE_EXPORT ImageStateModOPAlgorithm: public FNC, public ModOPAlgorithm, public ImageStateModOPVisitorBase {
378 public:
379 
381 
382  virtual ImageStateBasePtr Visit_(const RealSpatialImageState& is) {return T_Visit_(is);}
383  virtual ImageStateBasePtr Visit_(const ComplexSpatialImageState& is) {return T_Visit_(is);}
384  virtual ImageStateBasePtr Visit_(const RealFrequencyImageState& is) {return T_Visit_(is);}
385  virtual ImageStateBasePtr Visit_(const ComplexFrequencyImageState& is) {return T_Visit_(is);}
386  virtual ImageStateBasePtr Visit_(const ComplexHalfFrequencyImageState& is) {return T_Visit_(is);}
387  virtual ImageStateBasePtr Visit_(const WordSpatialImageState& is) {return T_Visit_(is);}
388 
389  // mod op algorithm interface
390  virtual ImageHandle Visit(const ConstImageHandle& h) {
391  return h.StateApply(*this);
392  }
393 
394 private:
395  template <typename T, class D>
396  ImageStateBasePtr T_Visit_(const ImageStateImpl<T,D>& isi) {
397  return this->VisitState(isi);
398  }
399 };
400 
402 template <class FNC>
403 class TEMPLATE_EXPORT ImageStateConstModOPAlgorithm: public FNC,
404  public ConstModOPAlgorithm,
406 public:
407 
409 
410  virtual ImageStateBasePtr Visit_(const RealSpatialImageState& is) const {return T_Visit_(is);}
411  virtual ImageStateBasePtr Visit_(const ComplexSpatialImageState& is) const {return T_Visit_(is);}
412  virtual ImageStateBasePtr Visit_(const RealFrequencyImageState& is) const {return T_Visit_(is);}
413  virtual ImageStateBasePtr Visit_(const ComplexFrequencyImageState& is) const {return T_Visit_(is);}
414  virtual ImageStateBasePtr Visit_(const ComplexHalfFrequencyImageState& is) const {return T_Visit_(is);}
415  virtual ImageStateBasePtr Visit_(const WordSpatialImageState& is) const {return T_Visit_(is);}
416 
417  // mod op algorithm interface
418  virtual ImageHandle Visit(const ConstImageHandle& h) const {
419  return h.StateApply(*this);
420  }
421 
422 private:
423  template <typename T, class D>
424  ImageStateBasePtr T_Visit_(const ImageStateImpl<T,D>& isi) const {
425  return this->VisitState(isi);
426  }
427 };
428 
429 
431 template <class FNC>
432 class TEMPLATE_EXPORT ImageStateMorphAlgorithm: public FNC, public ModIPAlgorithm, public ImageStateMorphVisitorBase {
433 public:
434 
436 
437  virtual ImageStateBasePtr Visit_(RealSpatialImageState& is) {return T_Visit_(is);}
438  virtual ImageStateBasePtr Visit_(ComplexSpatialImageState& is) {return T_Visit_(is);}
439  virtual ImageStateBasePtr Visit_(RealFrequencyImageState& is) {return T_Visit_(is);}
440  virtual ImageStateBasePtr Visit_(ComplexFrequencyImageState& is) {return T_Visit_(is);}
441  virtual ImageStateBasePtr Visit_(ComplexHalfFrequencyImageState& is) {return T_Visit_(is);}
442  virtual ImageStateBasePtr Visit_(WordSpatialImageState& is) {return T_Visit_(is);}
443 
444  // mod ip algorithm interface
445  virtual void Visit(ImageHandle& h) {
446  h.StateApply(*this);
447  }
448 
449 private:
450  template <typename T, class D>
451  ImageStateBasePtr T_Visit_(ImageStateImpl<T,D>& isi) {
452  return this->VisitState(isi);
453  }
454 };
455 
456 #undef IMAGE_STATE_VISITOR_CTOR_ADAPTERS
457 
458 }}} // ns
459 
460 #endif