22 #ifndef otbImageRegionNonUniformMultidimensionalSplitter_hxx
23 #define otbImageRegionNonUniformMultidimensionalSplitter_hxx
32 template <
unsigned int VImageDimension>
35 const SizeType& regionSize = region.GetSize();
38 double splitsPerDimension[VImageDimension];
41 unsigned int numberOfPiecesLeft = requestedNumber;
42 unsigned int j, numPieces;
45 for (j = VImageDimension; j > 0; --j)
47 if (regionSize[j - 1] < numberOfPiecesLeft)
49 splitsPerDimension[j - 1] = regionSize[j - 1];
53 splitsPerDimension[j - 1] = numberOfPiecesLeft;
55 numberOfPiecesLeft = (
unsigned int)::ceil(numberOfPiecesLeft / splitsPerDimension[j - 1]);
56 numPieces *= (
unsigned int)splitsPerDimension[j - 1];
81 template <
unsigned int VImageDimension>
91 splitIndex = splitRegion.GetIndex();
92 splitSize = splitRegion.GetSize();
94 regionSize = region.GetSize();
97 double splitsPerDimension[VImageDimension];
100 unsigned int numberOfPiecesLeft = numberOfPieces;
103 for (j = VImageDimension; j > 0; --j)
105 if (regionSize[j - 1] < numberOfPiecesLeft)
107 splitsPerDimension[j - 1] = regionSize[j - 1];
111 splitsPerDimension[j - 1] = numberOfPiecesLeft;
113 numberOfPiecesLeft = (
unsigned int)::ceil(numberOfPiecesLeft / splitsPerDimension[j - 1]);
118 unsigned int splits[VImageDimension], pixelsPerSplit[VImageDimension];
119 unsigned int numPieces;
120 unsigned int ijk[VImageDimension];
121 unsigned int offsetTable[VImageDimension];
123 for (j = 0; j < VImageDimension; ++j)
125 offsetTable[j] = numPieces;
126 if (regionSize[j] < splitsPerDimension[j])
128 splits[j] = regionSize[j];
129 pixelsPerSplit[j] = 1;
130 numPieces *= regionSize[j];
134 splits[j] = (
unsigned int)splitsPerDimension[j];
135 pixelsPerSplit[j] = (
unsigned int)::ceil(regionSize[j] / (
double)splits[j]);
136 numPieces *= (
unsigned int)splitsPerDimension[j];
141 unsigned int offset = i;
142 for (j = VImageDimension - 1; j > 0; j--)
144 ijk[j] = offset / offsetTable[j];
145 offset -= (ijk[j] * offsetTable[j]);
150 for (j = 0; j < VImageDimension; ++j)
152 splitIndex[j] += ijk[j] * pixelsPerSplit[j];
153 if (ijk[j] < splits[j] - 1)
155 splitSize[j] = pixelsPerSplit[j];
160 splitSize[j] = splitSize[j] - ijk[j] * pixelsPerSplit[j];
165 splitRegion.SetIndex(splitIndex);
166 splitRegion.SetSize(splitSize);
168 itkDebugMacro(
" Split Piece: " << std::endl << splitRegion);
176 template <
unsigned int VImageDimension>
179 Superclass::PrintSelf(os, indent);