ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkImageRegionSplitter.h
Go to the documentation of this file.
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 __itkImageRegionSplitter_h
19 #define __itkImageRegionSplitter_h
20 
21 #include "itkImageRegion.h"
23 
24 namespace itk
25 {
68 template< unsigned int VImageDimension >
70 {
71 public:
77 
79  itkNewMacro(Self);
80 
82  itkTypeMacro(ImageRegionSplitter, Object);
83 
85  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
86 
88  static unsigned int GetImageDimension()
89  { return VImageDimension; }
90 
93 
97 
100 
107  virtual unsigned int GetNumberOfSplits(const RegionType & region,
108  unsigned int requestedNumber);
109 
110 
114  virtual RegionType GetSplit(unsigned int i, unsigned int numberOfPieces,
115  const RegionType & region);
116 
117 protected:
120 
121  virtual unsigned int GetNumberOfSplitsInternal(unsigned int,
122  const IndexValueType regionIndex[],
123  const SizeValueType regionSize[],
124  unsigned int requestedNumber) const
125  {
126  // this function adapts the legecy method, defined in this class
127  // be used by the ImageRegionSplitterBase.
128  IndexType idx;
129  idx.SetIndex( regionIndex );
130  SizeType sz;
131  sz.SetSize( regionSize );
132  RegionType region = RegionType(idx, sz);
133 
134  Self *nonconst_this = const_cast<Self*>(this);
135  return nonconst_this->GetNumberOfSplits(region, requestedNumber);
136 
137  }
138 
139  virtual unsigned int GetSplitInternal(unsigned int dim,
140  unsigned int i,
141  unsigned int numberOfPieces,
142  IndexValueType regionIndex[],
143  SizeValueType regionSize[]) const
144  {
145  // this function adapts the legecy method, defined in this class
146  // be used by the ImageRegionSplitterBase.
147  IndexType idx;
148  idx.SetIndex( regionIndex );
149  SizeType sz;
150  sz.SetSize( regionSize );
151  RegionType region = RegionType(idx, sz);
152 
153  Self *nonconst_this = const_cast<Self*>(this);
154  region = nonconst_this->GetSplit(i, numberOfPieces, region);
155 
156  for (unsigned int d = 0; d < dim; ++d)
157  {
158  regionIndex[d] = region.GetIndex(d);
159  regionSize[d] = region.GetSize(d);
160  }
161  return numberOfPieces;
162  }
163 
164  void PrintSelf(std::ostream & os, Indent indent) const;
165 
166 private:
167  ImageRegionSplitter(const ImageRegionSplitter &); //purposely not implemented
168  void operator=(const ImageRegionSplitter &); //purposely not implemented
169 };
170 } // end namespace itk
171 
172 #ifndef ITK_MANUAL_INSTANTIATION
173 #include "itkImageRegionSplitter.hxx"
174 #endif
175 
176 #endif
177