21 #ifndef otbImageRegionSquareTileSplitter_hxx
22 #define otbImageRegionSquareTileSplitter_hxx
31 template <
unsigned int VImageDimension>
34 unsigned int theoreticalNbPixelPerTile = region.GetNumberOfPixels() / requestedNumber;
35 unsigned int theoreticalTileDimension =
static_cast<unsigned int>(std::sqrt(
static_cast<double>(theoreticalNbPixelPerTile)));
38 m_TileDimension = (theoreticalTileDimension + m_TileSizeAlignment - 1) / m_TileSizeAlignment * m_TileSizeAlignment;
41 if (m_TileDimension < m_TileSizeAlignment)
43 otbMsgDevMacro(<<
"Warning: clamping tile size to " << m_TileSizeAlignment <<
" * " << m_TileSizeAlignment);
44 m_TileDimension = m_TileSizeAlignment;
47 unsigned int numPieces = 1;
48 const SizeType& regionSize = region.GetSize();
49 for (
unsigned int j = 0; j < VImageDimension; ++j)
51 m_SplitsPerDimension[j] = (regionSize[j] + m_TileDimension - 1) / m_TileDimension;
52 numPieces *= m_SplitsPerDimension[j];
56 otbMsgDevMacro(<<
"Number of splits per dimension : " << m_SplitsPerDimension[0] <<
" " << m_SplitsPerDimension[1])
61 template <
unsigned int VImageDimension>
69 unsigned int numPieces = 1;
70 for (
unsigned int j = 0; j < VImageDimension; ++j)
72 numPieces *= m_SplitsPerDimension[j];
78 itkExceptionMacro(
"Asked for split number " << i <<
" but region contains only " << numPieces <<
" splits");
82 unsigned int remaining = i;
83 for (
unsigned int j = VImageDimension - 1; j > 0; --j)
85 splitIndex[j] = remaining / m_SplitsPerDimension[VImageDimension - 1 - j];
86 remaining = remaining % m_SplitsPerDimension[VImageDimension - 1 - j];
88 splitIndex[0] = remaining;
91 for (
unsigned int j = 0; j < VImageDimension; ++j)
93 splitRegion.SetIndex(j, region.GetIndex(j) + m_TileDimension * splitIndex[j]);
94 splitRegion.SetSize(j, m_TileDimension);
98 splitRegion.Crop(region);
106 template <
unsigned int VImageDimension>
109 Superclass::PrintSelf(os, indent);
110 os << indent <<
"SplitsPerDimension : " << m_SplitsPerDimension << std::endl;
111 os << indent <<
"TileDimension : " << m_TileDimension << std::endl;
112 os << indent <<
"TileSizeAlignment : " << m_TileSizeAlignment << std::endl;