21 #ifndef otbImageRegionTileMapSplitter_hxx
22 #define otbImageRegionTileMapSplitter_hxx
34 template <
unsigned int VImageDimension>
37 const SizeType& regionSize = region.GetSize();
38 const IndexType& regionIndex = region.GetIndex();
42 unsigned int numPieces = 1;
45 for (
unsigned int j = VImageDimension; j > 0; --j)
48 unsigned long int remainingToDo =
static_cast<unsigned long int>(std::ceil(
static_cast<double>(requestedNumber) / numPieces));
49 unsigned int maxPieces = (regionIndex[j - 1] + regionSize[j - 1] - 1) / m_AlignStep - regionIndex[j - 1] / m_AlignStep + 1;
50 unsigned int stepPerPiece = 1;
51 if (remainingToDo < maxPieces)
53 stepPerPiece =
static_cast<unsigned int>(std::floor(
static_cast<double>(maxPieces) / remainingToDo));
54 if ((remainingToDo - 1) * (stepPerPiece + 1) < maxPieces)
59 unsigned int maxPieceUsed =
static_cast<unsigned int>(std::ceil(
static_cast<double>(maxPieces) / stepPerPiece));
60 m_SplitsPerDimension[j - 1] = maxPieceUsed;
63 numPieces *= maxPieceUsed;
72 template <
unsigned int VImageDimension>
81 splitIndex = splitRegion.GetIndex();
82 splitSize = splitRegion.GetSize();
84 regionSize = region.GetSize();
85 regionIndex = region.GetIndex();
87 unsigned int numPieces = GetNumberOfSplits(region, numberOfPieces);
90 itkDebugMacro(
" Cannot Split");
94 unsigned int stackSize = 1;
95 for (
unsigned int j = 0; j < VImageDimension; ++j)
97 unsigned int slicePos = (i % (stackSize * m_SplitsPerDimension[j])) / stackSize;
98 stackSize *= m_SplitsPerDimension[j];
100 unsigned int generalSplitSize =
101 static_cast<unsigned int>(std::ceil(
static_cast<double>(regionSize[j]) / (m_SplitsPerDimension[j] * m_AlignStep))) * m_AlignStep;
104 splitIndex[j] = regionIndex[j];
108 splitIndex[j] = (regionIndex[j] / generalSplitSize + slicePos) * generalSplitSize;
112 splitSize[j] = generalSplitSize - (regionIndex[j] % generalSplitSize);
114 else if (slicePos == m_SplitsPerDimension[j] - 1)
116 splitSize[j] = regionSize[j] - (generalSplitSize - (regionIndex[j] % generalSplitSize)) - (m_SplitsPerDimension[j] - 2) * generalSplitSize;
120 splitSize[j] = generalSplitSize;
125 splitRegion.SetIndex(splitIndex);
126 splitRegion.SetSize(splitSize);
134 template <
unsigned int VImageDimension>
137 Superclass::PrintSelf(os, indent);