21 #ifndef otbImageRegionAdaptativeSplitter_hxx
22 #define otbImageRegionAdaptativeSplitter_hxx
34 template <
unsigned int VImageDimension>
38 this->SetImageRegion(region);
39 this->SetRequestedNumberOfSplits(requestedNumber);
46 this->EstimateSplitMap();
51 return m_StreamVector.size();
54 template <
unsigned int VImageDimension>
59 this->SetImageRegion(region);
66 this->EstimateSplitMap();
71 return m_StreamVector.at(i);
74 template <
unsigned int VImageDimension>
78 m_StreamVector.clear();
81 if (m_RequestedNumberOfSplits == 1 || m_RequestedNumberOfSplits == 0)
83 m_StreamVector.push_back(m_ImageRegion);
88 if (m_TileHint[0] == 0 || m_TileHint[1] == 0 || VImageDimension != 2)
94 unsigned int nbSplits = splitter->
GetNumberOfSplits(m_ImageRegion, m_RequestedNumberOfSplits);
96 for (
unsigned int i = 0; i < nbSplits; ++i)
98 m_StreamVector.push_back(splitter->
GetSplit(i, m_RequestedNumberOfSplits, m_ImageRegion));
110 firstTileCovered[0] = m_ImageRegion.GetIndex()[0] / m_TileHint[0];
111 firstTileCovered[1] = m_ImageRegion.GetIndex()[1] / m_TileHint[1];
112 tilesPerDim[0] = (m_ImageRegion.GetIndex()[0] + m_ImageRegion.GetSize()[0] + m_TileHint[0] - 1) / m_TileHint[0] - firstTileCovered[0];
113 tilesPerDim[1] = (m_ImageRegion.GetIndex()[1] + m_ImageRegion.GetSize()[1] + m_TileHint[1] - 1) / m_TileHint[1] - firstTileCovered[1];
115 unsigned int totalTiles = tilesPerDim[0] * tilesPerDim[1];
118 if (totalTiles >= m_RequestedNumberOfSplits)
128 while (totalTiles / (groupTiles[0] * groupTiles[1]) > m_RequestedNumberOfSplits)
130 if (groupTiles[i] < tilesPerDim[i])
139 splitsPerDim[0] = tilesPerDim[0] / groupTiles[0];
140 splitsPerDim[1] = tilesPerDim[1] / groupTiles[1];
143 if (tilesPerDim[0] % groupTiles[0] > 0)
146 if (tilesPerDim[1] % groupTiles[1] > 0)
150 for (
unsigned int splity = 0; splity < splitsPerDim[1]; ++splity)
152 for (
unsigned int splitx = 0; splitx < splitsPerDim[0]; ++splitx)
159 newSplitSize[0] = groupTiles[0] * m_TileHint[0];
160 newSplitSize[1] = groupTiles[1] * m_TileHint[1];
162 newSplitIndex[0] = firstTileCovered[0] * m_TileHint[0] + splitx * newSplitSize[0];
163 newSplitIndex[1] = firstTileCovered[1] * m_TileHint[1] + splity * newSplitSize[1];
165 newSplit.SetIndex(newSplitIndex);
166 newSplit.SetSize(newSplitSize);
168 bool cropped = newSplit.Crop(m_ImageRegion);
173 m_StreamVector.push_back(newSplit);
187 while (totalTiles * (divideTiles[0] * divideTiles[1]) < m_RequestedNumberOfSplits && (divideTiles[0] < m_TileHint[0] || divideTiles[1] < m_TileHint[1]))
189 if (divideTiles[i] < m_TileHint[i])
198 splitSize[0] = (m_TileHint[0] + divideTiles[0] - 1) / divideTiles[0];
199 splitSize[1] = (m_TileHint[1] + divideTiles[1] - 1) / divideTiles[1];
202 tileHintRegion.SetSize(m_TileHint);
204 for (
unsigned int tiley = 0; tiley < tilesPerDim[1]; ++tiley)
206 for (
unsigned int tilex = 0; tilex < tilesPerDim[0]; ++tilex)
208 for (
unsigned int divy = 0; divy < divideTiles[1]; ++divy)
210 for (
unsigned int divx = 0; divx < divideTiles[0]; ++divx)
216 newSplitIndex[0] = (tilex + firstTileCovered[0]) * m_TileHint[0] + divx * splitSize[0];
217 newSplitIndex[1] = (tiley + firstTileCovered[1]) * m_TileHint[1] + divy * splitSize[1];
219 newSplit.SetIndex(newSplitIndex);
220 newSplit.SetSize(splitSize);
222 tileHintRegion.SetIndex(0, tilex * m_TileHint[0]);
223 tileHintRegion.SetIndex(1, tiley * m_TileHint[1]);
225 bool cropped = newSplit.Crop(m_ImageRegion);
232 cropped = newSplit.Crop(tileHintRegion);
235 m_StreamVector.push_back(newSplit);
251 template <
unsigned int VImageDimension>
254 Superclass::PrintSelf(os, indent);
255 os << indent <<
"IsUpToDate: " << (m_IsUpToDate ?
"true" :
"false") << std::endl;
256 os << indent <<
"ImageRegion: " << m_ImageRegion << std::endl;
257 os << indent <<
"Tile hint: " << m_TileHint << std::endl;
258 os << indent <<
"Requested number of splits: " << m_RequestedNumberOfSplits << std::endl;
259 os << indent <<
"Actual number of splits: " << m_StreamVector.size() << std::endl;