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 #ifndef itkNeighborhoodIteratorTestCommon_hxx
19 #define itkNeighborhoodIteratorTestCommon_hxx
20
21 #include "itkImage.h"
22 #include "itkIndex.h"
23 #include "itkImageRegionIterator.h"
24 #include <iostream>
25
26 using TestImageType = itk::Image<itk::Index<4>, 4>;
27 using OffsetType = itk::Offset<4>;
28
29 extern void println(const char *s);
30 extern TestImageType::Pointer GetTestImage(int , int , int , int );
31
32
33 template<typename TIteratorType>
printnb(const TIteratorType & nb,bool full)34 void printnb( const TIteratorType &nb, bool full)
35 {
36 unsigned long count = 1;
37 const unsigned long sz = nb.GetRadius()[0] *2 +1;
38 typename TIteratorType::ConstIterator it;
39 if (full)
40 {
41 it = nb.Begin();
42
43 while (it != nb.End() )
44 {
45 std::cout << **it << " ";
46 if ( (count % sz) == 0 ) std::cout << std::endl;
47 ++it;
48 count ++;
49 }
50 }
51 else
52 {
53 std::cout << nb.GetCenterPixel() << std::endl;
54 }
55 }
56
57 template<unsigned int N>
FillImage(itk::Image<itk::Index<N>,N> * img)58 void FillImage(itk::Image<itk::Index<N>,N> *img)
59 {
60 using IndexType = itk::Index<N>;
61 using ImageType = itk::Image<IndexType, N>;
62 const itk::Size<N> size = img->GetRequestedRegion().GetSize();
63
64 unsigned int i;
65 IndexType loop;
66 loop.Fill(0);
67 itk::ImageRegionIterator<ImageType> it(img, img->GetRequestedRegion());
68
69 while (! it.IsAtEnd() )
70 {
71 it.Value() = loop;
72 for (i = 0; i <N; ++i)
73 {
74 loop[i]++;
75 if ( (unsigned int)(loop[i]) == size[i] )
76 {
77 loop[i]= 0;
78 }
79 else break;
80 }
81 ++it;
82 }
83 }
84
85
86 #endif
87