1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 #include "itkImageFileReader.h"
19 #include "itkContourExtractor2DImageFilter.h"
20 #include "itkTestingMacros.h"
21 
22 namespace itkContourExtractor2DImageFilterTestNamespace
23 {
24 constexpr unsigned int Dimension = 2;
25 using PixelType = unsigned char;
26 using ImageType = itk::Image<PixelType, Dimension>;
27 using ReaderType = itk::ImageFileReader<ImageType>;
28 using ExtractorType = itk::ContourExtractor2DImageFilter<ImageType>;
29 using VertexType = ExtractorType::VertexType;
30 using MyVertexType = std::pair<double, double>;
31 using MyVertexListType = std::vector<MyVertexType>;
32 using MyVertexListList = std::vector<MyVertexListType>;
33 constexpr float FLOAT_EPSILON = 0.0001;
34 }
35 
36 /* ----------------------------------------------------------------------- */
37 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _bottom_right[] =
38    {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 8),
39     itkContourExtractor2DImageFilterTestNamespace::MyVertexType(12, 7.5)};
40 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
41                                 bottom_right(_bottom_right, _bottom_right + 2);
42 
43 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
44     _rev_bottom_right[] =
45    {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(12, 7.5),
46     itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 8)};
47 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
48                     rev_bottom_right(_rev_bottom_right, _rev_bottom_right + 2);
49 
50 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _bottom_left[] =
51   {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 7.5),
52   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 8)};
53 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
54                     bottom_left(_bottom_left, _bottom_left + 2);
55 
56 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
57    _rev_bottom_left[] =
58  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 8),
59   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 7.5)};
60 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
61                    rev_bottom_left(_rev_bottom_left, _rev_bottom_left + 2);
62 
63 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row2_col4[] =
64  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 6.5),
65   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 6.5),
66   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 6),
67   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 5.5),
68   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 5),
69   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 4.5),
70   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 5),
71   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 6),
72   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 6.5)};
73 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
74                             row2_col4(_row2_col4, _row2_col4 + 9);
75 
76 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row2_col4[] =
77  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 6.5),
78   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 6),
79   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 5),
80   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 4.5),
81   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 5),
82   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 5.5),
83   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 6),
84   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 6.5),
85  itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 6.5)};
86 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
87                    rev_row2_col4(_rev_row2_col4, _rev_row2_col4 + 9);
88 
89 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row2_col3[] =
90  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8, 6.5),
91   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 6.5),
92   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 6),
93   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 5),
94   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 4.5),
95   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7.5, 5),
96   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8, 5.5),
97   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 6),
98  itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8, 6.5)};
99 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
100                             row2_col3(_row2_col3, _row2_col3 + 9);
101 
102 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row2_col3[] =
103  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8, 6.5),
104   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 6),
105   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8, 5.5),
106   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7.5, 5),
107   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 4.5),
108   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 5),
109   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 6),
110   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 6.5),
111   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8, 6.5),};
112 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
113                rev_row2_col3(_rev_row2_col3, _rev_row2_col3 + 9);
114 
115 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row2_col2[] =
116  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 6.5),
117   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4.5, 6),
118   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 5.5),
119   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(3.5, 5),
120   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 4.5),
121   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 4.5),
122   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5.5, 5),
123   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5.5, 6),
124   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 6.5)};
125 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
126               row2_col2(_row2_col2, _row2_col2 + 9);
127 
128 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row2_col2[] =
129  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 6.5),
130   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5.5, 6),
131   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5.5, 5),
132   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 4.5),
133   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 4.5),
134   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(3.5, 5),
135   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 5.5),
136   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4.5, 6),
137   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 6.5)};
138 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
139               rev_row2_col2(_rev_row2_col2, _rev_row2_col2 + 9);
140 
141 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row2_col1[] =
142  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 6.5),
143   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 6),
144   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 5),
145   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 4.5),
146   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 4.5),
147   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2.5, 5),
148   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 5.5),
149   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 6),
150  itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 6.5)};
151 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
152              row2_col1(_row2_col1, _row2_col1 + 9);
153 
154 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row2_col1[] =
155  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 6.5),
156   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 6),
157   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 5.5),
158   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2.5, 5),
159   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 4.5),
160   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 4.5),
161   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 5),
162   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 6),
163   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 6.5)};
164 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
165              rev_row2_col1(_rev_row2_col1, _rev_row2_col1 + 9);
166 
167 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
168      _row1_col4_middle[] =
169  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5),
170   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 3),
171   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 2.5),
172   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 3),
173   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5)};
174 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
175                    row1_col4_middle(_row1_col4_middle, _row1_col4_middle + 5);
176 
177 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
178    _rev_row1_col4_middle[] =
179  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5),
180   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 3),
181   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 2.5),
182   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 3),
183   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5)};
184 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
185     rev_row1_col4_middle(_rev_row1_col4_middle, _rev_row1_col4_middle + 5);
186 
187 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row1_col2[] =
188  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 3.5),
189   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 3.5),
190   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(3.5, 3),
191   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 2.5),
192   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 2.5),
193   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5.5, 3),
194   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 3.5)};
195 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
196               row1_col2(_row1_col2, _row1_col2 + 7);
197 
198 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row1_col2[] =
199  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 3.5),
200   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5.5, 3),
201   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 2.5),
202   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 2.5),
203   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(3.5, 3),
204   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(4, 3.5),
205   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(5, 3.5)};
206 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
207              rev_row1_col2(_rev_row1_col2, _rev_row1_col2 + 7);
208 
209 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row1_col1[] =
210  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 3.5),
211   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 3),
212   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 2.5),
213   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2.5, 3),
214   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 3.5)};
215 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
216                      row1_col1(_row1_col1, _row1_col1 + 5);
217 
218 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row1_col1[] =
219  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 3.5),
220   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2.5, 3),
221   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 2.5),
222   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 3),
223   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(2, 3.5)};
224 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
225             rev_row1_col1(_rev_row1_col1, _rev_row1_col1 + 5);
226 
227 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
228   _row1_col4_right[] =
229  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5),
230   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 2),
231   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 1.5),
232   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 2),
233   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5)};
234 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
235                row1_col4_right(_row1_col4_right, _row1_col4_right + 5);
236 
237 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
238    _rev_row1_col4_right[] =
239  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5),
240   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 2),
241   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 1.5),
242   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 2),
243   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5)};
244 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
245       rev_row1_col4_right(_rev_row1_col4_right, _rev_row1_col4_right + 5);
246 
247 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
248    _row1_col4_left[] =
249  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5),
250   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 2),
251   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 1.5),
252   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 2),
253   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5)};
254 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
255      row1_col4_left(_row1_col4_left, _row1_col4_left + 5);
256 
257 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
258    _rev_row1_col4_left[] =
259  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5),
260   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 2),
261   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 1.5),
262   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 2),
263   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5)};
264 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
265       rev_row1_col4_left(_rev_row1_col4_left, _rev_row1_col4_left + 5);
266 
267 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row1_col3[] =
268  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 3.5),
269   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 3),
270   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 2),
271   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 1.5),
272   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7.5, 2),
273   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7.5, 3),
274   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 3.5)};
275 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
276        row1_col3(_row1_col3, _row1_col3 + 7);
277 
278 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_row1_col3[] =
279  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 3.5),
280   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7.5, 3),
281   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7.5, 2),
282   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 1.5),
283   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 2),
284   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(6.5, 3),
285   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(7, 3.5)};
286 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
287     rev_row1_col3(_rev_row1_col3, _rev_row1_col3 + 7);
288 
289 
290 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _top_right[] =
291  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(12, 0.5),
292   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 0)};
293 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
294     top_right(_top_right, _top_right + 2);
295 
296 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_top_right[] =
297  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 0),
298   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(12, 0.5)};
299 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
300     rev_top_right(_rev_top_right, _rev_top_right + 2);
301 
302 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _top_left[] =
303  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 0),
304   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 0.5),
305   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1),
306   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5)};
307 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
308    top_left(_top_left, _top_left + 4);
309 
310 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _rev_top_left[] =
311  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5),
312   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1),
313   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1, 0.5),
314   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(1.5, 0)};
315 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
316    rev_top_left(_rev_top_left, _rev_top_left + 4);
317 
318 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
319   _top_left_cropped[] =
320  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1),
321   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5)};
322 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
323    top_left_cropped(_top_left_cropped, _top_left_cropped + 2);
324 
325 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
326    _rev_top_left_cropped[] =
327  {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0, 1.5),
328   itkContourExtractor2DImageFilterTestNamespace::MyVertexType(0.5, 1)};
329 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
330    rev_top_left_cropped(_rev_top_left_cropped, _rev_top_left_cropped + 2);
331 
332 itkContourExtractor2DImageFilterTestNamespace::MyVertexType _row1_col4_all[] =
333   {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5),
334    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 3),
335    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5),
336    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 2),
337    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 1.5),
338    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 2),
339    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 2.5),
340    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 2),
341    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 1.5),
342    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 2),
343    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5),
344    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 3),
345    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5)};
346 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
347    row1_col4_all(_row1_col4_all, _row1_col4_all + 13);
348 
349 itkContourExtractor2DImageFilterTestNamespace::MyVertexType
350   _rev_row1_col4_all[] =
351   {itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5),
352    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 3),
353    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 2.5),
354    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11.5, 2),
355    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(11, 1.5),
356    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10.5, 2),
357    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 2.5),
358    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 2),
359    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 1.5),
360    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(8.5, 2),
361    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9, 2.5),
362    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(9.5, 3),
363    itkContourExtractor2DImageFilterTestNamespace::MyVertexType(10, 3.5)};
364 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType
365    rev_row1_col4_all(_rev_row1_col4_all, _rev_row1_col4_all + 13);
366 
367 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _edco[] =
368   {top_left, top_right, row1_col3, row1_col4_left,
369    row1_col4_right, row1_col1, row1_col2, row1_col4_middle, row2_col1,
370    row2_col2, row2_col3, row2_col4, bottom_left, bottom_right};
371 itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
372    expected_disconnected_clockwise_outputs(_edco, _edco + 14);
373 
374 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _edcco[] =
375   {rev_top_left, rev_top_right, rev_row1_col3,
376    rev_row1_col4_left, rev_row1_col4_right, rev_row1_col1, rev_row1_col2,
377    rev_row1_col4_middle, rev_row2_col1, rev_row2_col2, rev_row2_col3,
378    rev_row2_col4, rev_bottom_left, rev_bottom_right};
379 itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
380    expected_disconnected_counterclockwise_outputs(_edcco, _edcco + 14);
381 
382 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _ecco[] =
383   {top_left, top_right, row1_col3, row1_col4_all,
384    row1_col1, row1_col2, row2_col1, row2_col2, row2_col3, row2_col4,
385    bottom_left, bottom_right};
386 itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
387   expected_connected_clockwise_outputs(_ecco, _ecco + 12);
388 
389 itkContourExtractor2DImageFilterTestNamespace::MyVertexListType _edcro[] =
390   {top_left_cropped, row1_col3, row1_col4_left,
391    row1_col4_right, row1_col1, row1_col2, row1_col4_middle, row2_col1,
392    row2_col2, row2_col3, row2_col4};
393 itkContourExtractor2DImageFilterTestNamespace::MyVertexListList
394    expected_disconnected_clockwise_cropped_outputs(_edcro, _edcro + 11);
395 
396 /*--------------------------------------------------------------------------*/
397 
HasCorrectOutput(itkContourExtractor2DImageFilterTestNamespace::ExtractorType::Pointer extractor,itkContourExtractor2DImageFilterTestNamespace::MyVertexListList & correct)398 bool HasCorrectOutput(
399 itkContourExtractor2DImageFilterTestNamespace::ExtractorType::Pointer
400    extractor,
401 itkContourExtractor2DImageFilterTestNamespace::MyVertexListList& correct)
402 {
403   if (extractor->GetNumberOfIndexedOutputs() != correct.size())
404     {
405     return false;
406     }
407 
408   for(unsigned int i = 0; i < correct.size(); i++)
409     {
410     itkContourExtractor2DImageFilterTestNamespace::ExtractorType::
411                     VertexListConstPointer
412         vertices = extractor->GetOutput(i)->GetVertexList();
413 
414     itkContourExtractor2DImageFilterTestNamespace::MyVertexListType&
415                 correctVertices = correct[i];
416 
417     if (vertices->Size() != correctVertices.size())
418       {
419       return false;
420       }
421     for(unsigned int j = 0; j < correctVertices.size(); j++)
422       {
423       const itkContourExtractor2DImageFilterTestNamespace::MyVertexType&
424           correctVertex = correctVertices[j];
425 
426       const itkContourExtractor2DImageFilterTestNamespace::VertexType&
427           vertex = vertices->ElementAt(j);
428       if (itk::Math::abs(correctVertex.first - vertex[0]) >
429             itkContourExtractor2DImageFilterTestNamespace::FLOAT_EPSILON ||
430           itk::Math::abs(correctVertex.second - vertex[1]) >
431             itkContourExtractor2DImageFilterTestNamespace::FLOAT_EPSILON)
432         {
433         return false;
434         }
435       }
436     }
437   return true;
438 }
439 
itkContourExtractor2DImageFilterTest(int argc,char * argv[])440 int itkContourExtractor2DImageFilterTest(int argc, char *argv[])
441 {
442   if( argc < 2 )
443     {
444     std::cerr << "Missing Parameters " << std::endl;
445     std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv);
446     std::cerr << " Input Test Image  " << std::endl;
447     return 1;
448     }
449 
450   itkContourExtractor2DImageFilterTestNamespace::ReaderType::Pointer
451     reader = itkContourExtractor2DImageFilterTestNamespace::ReaderType::New();
452 
453   reader->SetFileName(argv[1]);
454   itkContourExtractor2DImageFilterTestNamespace::ExtractorType::Pointer
455    extractor =
456       itkContourExtractor2DImageFilterTestNamespace::ExtractorType::New();
457 
458   extractor->SetInput(reader->GetOutput());
459 
460   // exercise Set/Get ContourValue methods
461   extractor->SetContourValue( 255.0 );
462   if( extractor->GetContourValue() != 255.0 )
463     {
464     std::cerr << " Contour Value Set/Get problem" << std::endl;
465     return EXIT_FAILURE;
466     }
467 
468   extractor->SetContourValue(127.5);
469 
470   // exercise Set/Get methods of VertexConnectHighPixels
471   extractor->VertexConnectHighPixelsOn();
472   if( extractor->GetVertexConnectHighPixels() != true )
473     {
474     std::cerr << "VertexConnectHighPixels Set/Get Problem" << std::endl;
475     return EXIT_FAILURE;
476     }
477 
478   // exercise Set/Get methods of ReverseContourOrientation
479   extractor->ReverseContourOrientationOn();
480   if( extractor->GetReverseContourOrientation() != true )
481     {
482     std::cerr << "ReverseContourOrientation Set/Get Problem" << std::endl;
483     return EXIT_FAILURE;
484     }
485 
486   bool testsPassed = true;
487   try
488     {
489     extractor->VertexConnectHighPixelsOff();
490     extractor->ReverseContourOrientationOff();
491     extractor->Update();
492     std::cout << "Test 1... ";
493     if (!HasCorrectOutput(extractor, expected_disconnected_clockwise_outputs))
494       {
495       testsPassed = false;
496       std::cout << "failed." << std::endl;
497       }
498     else std::cout << "passed." << std::endl;
499 
500     extractor->VertexConnectHighPixelsOff();
501     extractor->ReverseContourOrientationOn();
502     extractor->Update();
503     std::cout << "Test 2... ";
504     if (!HasCorrectOutput(extractor,
505             expected_disconnected_counterclockwise_outputs))
506       {
507       testsPassed = false;
508       std::cout << "failed." << std::endl;
509       }
510     else
511       {
512       std::cout << "passed." << std::endl;
513       }
514 
515     extractor->VertexConnectHighPixelsOn();
516     extractor->ReverseContourOrientationOff();
517     extractor->Update();
518     std::cout << "Test 3... ";
519     if (!HasCorrectOutput(extractor, expected_connected_clockwise_outputs))
520       {
521       testsPassed = false;
522       std::cout << "failed." << std::endl;
523       }
524     else
525       {
526        std::cout << "passed." << std::endl;
527       }
528 
529     extractor->VertexConnectHighPixelsOff();
530     extractor->ReverseContourOrientationOff();
531     // Move the region to evaluate in by one on the top and bottom
532     itkContourExtractor2DImageFilterTestNamespace::ImageType::RegionType
533               region = reader->GetOutput()->GetLargestPossibleRegion();
534 
535     itkContourExtractor2DImageFilterTestNamespace::ImageType::IndexType
536               index = region.GetIndex();
537 
538     itkContourExtractor2DImageFilterTestNamespace::ImageType::SizeType
539               size = region.GetSize();
540 
541     index[1] += 1;
542     size[1] -= 2;
543 
544     extractor->SetRequestedRegion(
545        itkContourExtractor2DImageFilterTestNamespace::ImageType::RegionType(
546                    index, size));
547 
548     // exercise Set/Get RequestRegion
549     if ( extractor->GetRequestedRegion() !=
550      itkContourExtractor2DImageFilterTestNamespace::ImageType::RegionType(
551                    index, size) )
552       {
553       std::cerr << "RequestedRegion Set/Get Problem" << std::endl;
554       return EXIT_FAILURE;
555       }
556 
557     extractor->Update();
558     std::cout << "Test 4... ";
559     if (!HasCorrectOutput(extractor,
560           expected_disconnected_clockwise_cropped_outputs))
561       {
562       testsPassed = false;
563       std::cerr << "failed." << std::endl;
564       }
565     else
566       {
567       std::cout << "passed." << std::endl;
568       }
569     }
570   catch( itk::ExceptionObject & err )
571     {
572     std::cerr << "ExceptionObject caught !" << std::endl;
573     std::cerr << err << std::endl;
574     return EXIT_FAILURE;
575     }
576 
577   if (testsPassed)
578     {
579     std::cout << "All tests passed." << std::endl;
580     return EXIT_SUCCESS;
581     }
582 
583   return EXIT_FAILURE;
584 }
585