Orfeo Toolbox  3.16
itkNeighborhoodAlgorithm.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkNeighborhoodAlgorithm.txx,v $
5  Language: C++
6  Date: $Date: 2009-02-06 20:53:12 $
7  Version: $Revision: 1.35 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkNeighborhoodAlgorithm_txx
18 #define __itkNeighborhoodAlgorithm_txx
20 #include "itkImageRegionIterator.h"
21 #include "itkImageRegion.h"
22 #include "itkConstSliceIterator.h"
23 
24 namespace itk
25 {
26 
27 namespace NeighborhoodAlgorithm {
28 
29 template<class TImage>
30 typename ImageBoundaryFacesCalculator<TImage>::FaceListType
32 ::operator()(const TImage *img, RegionType regionToProcess, RadiusType radius)
33 {
34  unsigned int j, i;
35  // Analyze the regionToProcess to determine if any of its faces are
36  // along a buffer boundary (we have no data in the buffer for pixels
37  // that are outside the boundary, but within the neighborhood radius and will
38  // have to treat them differently). We also determine the size of the non-
39  // boundary region that will be processed.
40 
41  const IndexType bStart = img->GetBufferedRegion().GetIndex();
42  const SizeType bSize = img->GetBufferedRegion().GetSize();
43  const IndexType rStart = regionToProcess.GetIndex();
44  const SizeType rSize = regionToProcess.GetSize();
45 
46  long overlapLow, overlapHigh;
47  FaceListType faceList;
48  IndexType fStart; // Boundary, "face"
49  SizeType fSize; // region data.
50  RegionType fRegion;
51  SizeType nbSize = regionToProcess.GetSize(); // Non-boundary region
52  IndexType nbStart = regionToProcess.GetIndex(); // data.
53  RegionType nbRegion;
54 
55  for (i = 0; i < ImageDimension; ++i)
56  {
57  overlapLow = static_cast<long>((rStart[i] - radius[i]) - bStart[i]);
58  overlapHigh= static_cast<long>((bStart[i] + bSize[i]) - (rStart[i] + rSize[i] + radius[i]));
59 
60  if (overlapLow < 0) // out of bounds condition, define a region of
61  { // iteration along this face
62  for (j = 0; j < ImageDimension; ++j) // define the starting index
63  { // and size of the face region
64  fStart[j] = rStart[j];
65  if ( j == i )
66  {
67  fSize[j] = -overlapLow;
68  }
69  else // NOTE: this algorithm
70  { // results in duplicate
71  fSize[j] = rSize[j]; // pixels at corners between
72  } // adjacent faces.
73 
74  // Boundary region cannot be outside the region to process
75  if (fSize[j] > rSize[j])
76  {
77  fSize[j] = rSize[j];
78  }
79  }
80 
81  // avoid unsigned overflow if the non-boundary region is too small to process
82  if (fSize[i] > nbSize[i])
83  {
84  nbSize[i] = 0;
85  }
86  else
87  {
88  nbSize[i] -= fSize[i];
89  }
90  nbStart[i] += -overlapLow;
91  fRegion.SetIndex(fStart);
92  fRegion.SetSize(fSize);
93  faceList.push_back(fRegion);
94  }
95  if (overlapHigh < 0)
96  {
97  for (j = 0; j < ImageDimension; ++j)
98  {
99  if ( j == i )
100  {
101  fStart[j] = rStart[j] + static_cast<IndexValueType>(rSize[j]) + overlapHigh;
102  fSize[j] = -overlapHigh;
103 
104  // Start of the boundary condition region cannot be to the
105  // left of the region to process
106  if (fStart[j] < rStart[j])
107  {
108  fStart[j] = rStart[j];
109  fSize[j] = rSize[j]; // is this the right size?
110  }
111  }
112  else
113  {
114  fStart[j] = rStart[j];
115  fSize[j] = rSize[j];
116  }
117  }
118  // avoid unsigned overflow if the non-boundary region is too small to process
119  if (fSize[i] > nbSize[i])
120  {
121  nbSize[i] = 0;
122  }
123  else
124  {
125  nbSize[i] -= fSize[i];
126  }
127  fRegion.SetIndex(fStart);
128  fRegion.SetSize(fSize);
129  faceList.push_back(fRegion);
130  }
131  }
132  nbRegion.SetSize(nbSize);
133  nbRegion.SetIndex(nbStart);
134 
135  faceList.push_front(nbRegion);
136  return faceList;
137 }
138 
139 template<class TImage>
142 ::operator()(TImage *input, TImage *output) const
143 {
144  OffsetType ans;
145  const Size<TImage::ImageDimension> isz = input->GetBufferedRegion().GetSize();
146  const Size<TImage::ImageDimension> osz = output->GetBufferedRegion().GetSize();
147 
148  for (int i=0; i<TImage::ImageDimension; ++i)
149  {
150  ans[i] = osz[i] - isz[i];
151  }
152  return ans;
153 }
154 
155 } // end namespace NeighborhoodAlgorithm
156 } // end namespace itk
157 
158 #endif

Generated at Sat Feb 2 2013 23:55:54 for Orfeo Toolbox with doxygen 1.8.1.1