aimstil  5.0.5
if_then_else.h
Go to the documentation of this file.
1 #ifndef TIL_IF_THEN_ELSE_H
2 #define TIL_IF_THEN_ELSE_H
3 
4 // Local includes
5 #include "til/til_common.h"
6 
7 
9 //
10 // if_then_else_old functions, to be used with Pixel Test and
11 // Pixel Action classes
12 //
14 
15 
16 // Namespace
17 
18 namespace til {
19 
20 
21 
22 
23 template < class TImage1, class TImage2, class PixelTest, class PixelAction1, class PixelAction2 >
24 void if_then_else_old(const TImage1 &in,
25  TImage2 &out,
26  const PixelTest &test,
27  PixelAction1 &actionIf,
28  PixelAction2 &actionElse)
29 {
30  typename Iterator<TImage1>::ConstVolumetric iIn(in);
31  typename Iterator<TImage2>::Volumetric iOut(out);
32  for (; !iIn.isAtEnd(); ++iIn, ++iOut, test.next(), actionIf.next(), actionElse.next())
33  {
34  if (test.compute(iIn))
35  {
36  actionIf.apply(iOut);
37  }
38  else
39  {
40  actionElse.apply(iOut);
41  }
42  }
43 }
44 
45 
46 template < class TImage, class PixelTest, class PixelAction1, class PixelAction2 >
47 void if_then_else_old(TImage &im,
48  const PixelTest &test,
49  PixelAction1 &actionIf,
50  PixelAction2 &actionElse)
51 {
52  typename Iterator<TImage>::Volumetric iIm(im);
53  for (; !iIm.isAtEnd(); ++iIm, test.next(), actionIf.next(), actionElse.next())
54  {
55  if (test.compute(iIm))
56  {
57  actionIf.apply(iIm);
58  }
59  else
60  {
61  actionElse.apply(iIm);
62  }
63  }
64 }
65 
66 
67 
68 template < class TImage1, class TImage2, class PixelTest, class PixelAction >
69 void if_then(const TImage1 &in,
70  TImage2 &out,
71  const PixelTest &test,
72  PixelAction &action)
73 {
74  typename Iterator<TImage1>::ConstVolumetric iIn(in);
75  typename Iterator<TImage2>::Volumetric iOut(out);
76  for (; !iIn.isAtEnd(); ++iIn, ++iOut, test.next(), action.next())
77  {
78  if (test.compute(iIn))
79  {
80  action.apply(iOut);
81  }
82  }
83 }
84 
85 
86 template < class TImage, class PixelTest, class PixelAction >
87 void if_then(TImage &im,
88  const PixelTest &test,
89  PixelAction &action)
90 {
91  typename Iterator<TImage>::Volumetric iIm(im);
92  for (; !iIm.isAtEnd(); ++iIm, test.next(), action.next())
93  {
94  if (test.compute(iIm))
95  {
96  action.apply(iIm);
97  }
98  }
99 }
100 
101 template < class TImage, class PixelTest, class PixelAction >
102 void if_then_inInterior(TImage &im,
103  const PixelTest &test,
104  PixelAction &action)
105 {
106  // If image has not interior: do nothing & quit!
107 
108  if ((im.dim()[0] < 3) ||
109  (im.dim()[1] < 3) ||
110  (im.dim()[2] < 3))
111  {
112  return;
113  }
114 
115 
116  // The range excluding image border
117 
118  Range<int,3> range(1,1,1,im.dim()[0]-2,im.dim()[1]-2,im.dim()[2]-2);
119 
120  typename Iterator<TImage>::Volumetric iIm(im, range);
121  for (; !iIm.isAtEnd(); ++iIm, test.next(), action.next())
122  {
123  if (test.compute(iIm))
124  {
125  action.apply(iIm);
126  }
127  }
128 }
129 
130 
131 } // namespace
132 
133 #endif
134 
A trait class to assign iterators to image types.
void if_then(const TImage1 &in, TImage2 &out, const PixelTest &test, PixelAction &action)
Definition: if_then_else.h:69
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
void if_then_inInterior(TImage &im, const PixelTest &test, PixelAction &action)
Definition: if_then_else.h:102
void if_then_else_old(const TImage1 &in, TImage2 &out, const PixelTest &test, PixelAction1 &actionIf, PixelAction2 &actionElse)
Definition: if_then_else.h:24
General macros, definitions and functions.