Orfeo Toolbox  3.16
itkImageRegionMultidimensionalSplitter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageRegionMultidimensionalSplitter.txx,v $
5  Language: C++
6  Date: $Date: 2009-11-03 12:24:19 $
7  Version: $Revision: 1.11 $
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 __itkImageRegionMultidimensionalSplitter_txx
18 #define __itkImageRegionMultidimensionalSplitter_txx
20 #include <math.h>
21 
22 namespace itk
23 {
24 
28 template <unsigned int VImageDimension>
29 unsigned int
31 ::GetNumberOfSplits(const RegionType &region, unsigned int requestedNumber)
32 {
33  const SizeType &regionSize = region.GetSize();
34 
35  // requested number of splits per dimension
36  double splitsPerDimension =
37  vcl_ceil( vcl_pow((double) requestedNumber, 1.0/(double) VImageDimension));
38 
39  // if a given dimension has fewer pixels that splitsPerDimension, then
40  // only split number of pixels times
41  unsigned int i, numPieces;
42  numPieces = 1;
43  for (i=0; i < VImageDimension; ++i)
44  {
45  if (regionSize[i] < splitsPerDimension)
46  {
47  numPieces *= regionSize[i];
48  }
49  else
50  {
51  numPieces *= (unsigned int) splitsPerDimension;
52  }
53  }
54 
55  return numPieces;
56 }
57 
58 
62 template <unsigned int VImageDimension>
65 ::GetSplit(unsigned int i, unsigned int numberOfPieces,
66  const RegionType &region)
67 {
68  RegionType splitRegion;
69  IndexType splitIndex;
70  SizeType splitSize, regionSize;
71 
72  // Initialize the splitRegion to the requested region
73  splitRegion = region;
74  splitIndex = splitRegion.GetIndex();
75  splitSize = splitRegion.GetSize();
76 
77  regionSize = region.GetSize();
78 
79  // requested number of splits per dimension
80  double splitsPerDimension =
81  vcl_ceil( vcl_pow((double) numberOfPieces, 1.0/(double) VImageDimension));
82 
83  // if a given dimension has fewer pixels that splitsPerDimension, then
84  // only split number of pixels times
85  unsigned int splits[VImageDimension], pixelsPerSplit[VImageDimension];
86  unsigned int j, numPieces;
87  unsigned int ijk[VImageDimension];
88  unsigned int offsetTable[VImageDimension];
89  numPieces = 1;
90  for (j=0; j < VImageDimension; ++j)
91  {
92  offsetTable[j] = numPieces;
93  if (regionSize[j] < splitsPerDimension)
94  {
95  splits[j] = regionSize[j];
96  pixelsPerSplit[j] = 1;
97  numPieces *= regionSize[j];
98  }
99  else
100  {
101  splits[j] = (unsigned int) splitsPerDimension;
102  pixelsPerSplit[j] = Math::Ceil<unsigned int>( regionSize[j] / (double) splits[j] );
103  numPieces *= (unsigned int) splitsPerDimension;
104  }
105  }
106 
107  // determine which split we are in
108  unsigned int offset = i;
109  for (j=VImageDimension-1; j > 0; j--)
110  {
111  ijk[j] = offset / offsetTable[j];
112  offset -= (ijk[j] * offsetTable[j]);
113  }
114  ijk[0] = offset;
115 
116  // compute the split
117  for (j=0; j < VImageDimension; j++)
118  {
119  splitIndex[j] += ijk[j]*pixelsPerSplit[j];
120  if (ijk[j] < splits[j] - 1)
121  {
122  splitSize[j] = pixelsPerSplit[j];
123  }
124  else
125  {
126  // this dimension is falling off the edge of the image
127  splitSize[j] = splitSize[j] - ijk[j]*pixelsPerSplit[j];
128  }
129  }
130 
131  // set the split region ivars
132  splitRegion.SetIndex( splitIndex );
133  splitRegion.SetSize( splitSize );
134 
135  itkDebugMacro(" Split Piece: " << std::endl << splitRegion );
136 
137  return splitRegion;
138 }
139 
140 
141 
145 template <unsigned int VImageDimension>
146 void
148 ::PrintSelf(std::ostream& os, Indent indent) const
149 {
150  Superclass::PrintSelf(os,indent);
151 }
152 
153 
154 } // end namespace itk
155 
156 #endif

Generated at Sat Feb 2 2013 23:44:18 for Orfeo Toolbox with doxygen 1.8.1.1