Commit 1f9af73a authored by Julien Michel's avatar Julien Michel

ENH: Aligning streams on a power of 2 grid with respect to a decoding tile size

parent 345134b2
......@@ -124,7 +124,7 @@ public:
itkGetMacro(TileDimension, unsigned int);
protected:
ImageRegionSquareTileSplitter() : m_SplitsPerDimension(0U), m_TileDimension(0), m_TileSizeAlignment(16) {}
ImageRegionSquareTileSplitter() : m_SplitsPerDimension(0U), m_TileDimension(0), m_TileSizeAlignment(0), m_TileHint(2048) {}
virtual ~ImageRegionSquareTileSplitter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const;
......@@ -135,6 +135,7 @@ private:
itk::FixedArray<unsigned int, VImageDimension> m_SplitsPerDimension;
unsigned int m_TileDimension;
unsigned int m_TileSizeAlignment;
unsigned int m_TileHint;
};
} // end namespace otb
......
......@@ -33,8 +33,23 @@ ImageRegionSquareTileSplitter<VImageDimension>
unsigned int theoricalNbPixelPerTile = region.GetNumberOfPixels() / requestedNumber;
unsigned int theoricalTileDimension = static_cast<unsigned int> (vcl_sqrt(static_cast<double>(theoricalNbPixelPerTile)) );
// Take the next multiple of m_TileSizeAlignment (eventually generate more splits than requested)
m_TileDimension = (theoricalTileDimension + m_TileSizeAlignment - 1) / m_TileSizeAlignment * m_TileSizeAlignment;
m_TileDimension = m_TileHint;
// If we have less than one jpeg 2000 tile, split in sub-tiles
if(theoricalTileDimension < m_TileHint)
{
while(m_TileDimension > theoricalTileDimension)
{
m_TileDimension/=2;
}
}
else
{
while(2*m_TileDimension < theoricalTileDimension)
{
m_TileDimension*=2;
}
}
// Minimal tile size is m_TileSizeAlignment * m_TileSizeAlignment
if (m_TileDimension < m_TileSizeAlignment)
......@@ -78,26 +93,47 @@ ImageRegionSquareTileSplitter<VImageDimension>
itkExceptionMacro("Asked for split number " << i << " but region contains only " << numPieces << " splits");
}
// Compute the split index in the streaming grid
unsigned int remaining = i;
// First, find the megatile index
unsigned int tilesPerMegaTilesPerDim = m_TileHint / m_TileDimension;
if(tilesPerMegaTilesPerDim == 0)
{
tilesPerMegaTilesPerDim =1;
}
unsigned int tilesPerMegaTiles = tilesPerMegaTilesPerDim*tilesPerMegaTilesPerDim;
unsigned int remaining = i / tilesPerMegaTiles;
for (unsigned int j = VImageDimension - 1; j > 0; --j)
{
splitIndex[j] = remaining / m_SplitsPerDimension[VImageDimension - 1 - j];
remaining = remaining % m_SplitsPerDimension[VImageDimension - 1 - j];
splitIndex[j] = tilesPerMegaTilesPerDim * remaining / (m_SplitsPerDimension[VImageDimension - 1 - j] / tilesPerMegaTilesPerDim);
remaining = remaining % (m_SplitsPerDimension[VImageDimension - 1 - j] / tilesPerMegaTilesPerDim);
}
splitIndex[0] = remaining;
splitIndex[0] = tilesPerMegaTilesPerDim * remaining;
// Now splitIndex contains the megaTile index
remaining = i % tilesPerMegaTiles;
for (unsigned int j = VImageDimension - 1; j > 0; --j)
{
splitIndex[j] += remaining / tilesPerMegaTilesPerDim;
remaining = remaining % (tilesPerMegaTilesPerDim);
}
splitIndex[0]+= remaining;
// Now split index contains the tile index
// Transform the split index to the actual coordinates
for (unsigned int j = 0; j < VImageDimension; ++j)
{
splitRegion.SetIndex(j, region.GetIndex(j) + m_TileDimension * splitIndex[j]);
splitRegion.SetSize(j, m_TileDimension);
}
// Handle the borders
splitRegion.Crop(region);
return splitRegion;
// Handle the borders
splitRegion.Crop(region);
return splitRegion;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment