Skip to content
Snippets Groups Projects
Commit 425d1af9 authored by Manuel Grizonnet's avatar Manuel Grizonnet
Browse files

BUG: backout rev 3db61e102740

parent edef3e4f
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
=========================================================================*/ =========================================================================*/
#include "otbStreamingShrinkImageFilter.h" #include "otbStreamingShrinkImageFilter.h"
//encapsulate adaptative splitter
#include "otbImageRegionAdaptativeSplitter.h"
namespace otb namespace otb
{ {
...@@ -26,96 +24,73 @@ unsigned int ...@@ -26,96 +24,73 @@ unsigned int
StreamingShrinkImageRegionSplitter StreamingShrinkImageRegionSplitter
::GetNumberOfSplits(const RegionType& region, unsigned int requestedNumber) ::GetNumberOfSplits(const RegionType& region, unsigned int requestedNumber)
{ {
//New method unsigned int theoricalNbPixelPerTile = region.GetNumberOfPixels() / requestedNumber;
// Set parameters unsigned int theoricalTileDimension = static_cast<unsigned int> (vcl_sqrt(static_cast<double>(theoricalNbPixelPerTile)) );
this->SetImageRegion(region);
this->SetRequestedNumberOfSplits(requestedNumber); // Take the previous multiple of m_TileSizeAlignment (eventually generate more splits than requested)
m_TileDimension = theoricalTileDimension / m_TileSizeAlignment * m_TileSizeAlignment;
// Check if we need to compute split map again
m_Lock.Lock(); // Minimal tile size is m_TileSizeAlignment * m_TileSizeAlignment
if(!m_IsUpToDate) if (m_TileDimension < m_TileSizeAlignment)
{ {
// Do so if we need to otbMsgDevMacro(<< "Using the minimal tile size : " << m_TileSizeAlignment << " * " << m_TileSizeAlignment);
this->EstimateSplitMap(requestedNumber); m_TileDimension = m_TileSizeAlignment;
} }
m_Lock.Unlock();
otbMsgDevMacro(<<"Stream vector size " << m_StreamVector.size() << std::endl);
// Return the size of the split map
return m_StreamVector.size();
}
// Use the computed tile size, and generate (m_TileDimension * 1) tiles
const SizeType& regionSize = region.GetSize();
m_SplitsPerDimension[0] = (regionSize[0] + m_TileDimension - 1) / m_TileDimension;
m_SplitsPerDimension[1] = regionSize[1] / m_TileSizeAlignment;
StreamingShrinkImageRegionSplitter::RegionType if (m_SplitsPerDimension[1] == 0)
StreamingShrinkImageRegionSplitter m_SplitsPerDimension[1] = 1;
::GetSplit(unsigned int i, unsigned int numberOfPieces, const RegionType& region)
{
// Set parameters
this->SetImageRegion(region);
// Check if we need to compute split map agagin unsigned int numPieces = 1;
m_Lock.Lock(); for (unsigned int j = 0; j < ImageDimension; ++j)
if(!m_IsUpToDate)
{ {
// Do so if we need to numPieces *= m_SplitsPerDimension[j];
this->EstimateSplitMap(numberOfPieces);
} }
m_Lock.Unlock();
// Return the requested split otbMsgDevMacro(<< "Tile dimension : " << m_TileDimension)
return m_StreamVector.at(i); otbMsgDevMacro(<< "Number of splits per dimension : " << m_SplitsPerDimension[0] << " " << m_SplitsPerDimension[1])
return numPieces;
} }
void StreamingShrinkImageRegionSplitter::RegionType
StreamingShrinkImageRegionSplitter StreamingShrinkImageRegionSplitter
::EstimateSplitMap(unsigned int numberOfPieces) ::GetSplit(unsigned int i, unsigned int numberOfPieces, const RegionType& region)
{ {
// Clear previous split map RegionType splitRegion;
m_StreamVector.clear(); IndexType splitIndex;
//Encapsulate adpatative splitter to get a list of streams
//adapted to the tiling scheme
typedef ImageRegionAdaptativeSplitter<2> AdaptativeSplitterType;
AdaptativeSplitterType::Pointer internalSplitter = AdaptativeSplitterType::New();
internalSplitter->SetTileHint(m_TileHint);
unsigned int nbSplits = internalSplitter->GetNumberOfSplits(m_ImageRegion,numberOfPieces);
//Iterate over streams computed by the adaptative splitter // Compute the actual number of splits
for (unsigned int i = 0; i < nbSplits; ++i) unsigned int numPieces = 1;
for (unsigned int j = 0; j < ImageDimension; ++j)
{ {
RegionType region; numPieces *= m_SplitsPerDimension[j];
IndexType index; }
region = internalSplitter->GetSplit(i,numberOfPieces,m_ImageRegion);
index = region.GetIndex();
const unsigned int sizeY = region.GetSize()[1] - 1;
for (unsigned int j = 0; j < sizeY; ++j) if (i >= numPieces)
{ {
//Add region aligned with the shrink factor itkExceptionMacro("Requested split number " << i << " but region contains only " << numPieces << " splits");
if (((index[1]+j) % m_TileSizeAlignment) == 0) }
{
RegionType splitRegion;
splitRegion.SetIndex(0, index[0]); // Compute the split index in the streaming grid
splitRegion.SetIndex(1, index[1]+j); splitIndex[1] = i / m_SplitsPerDimension[0];
splitIndex[0] = i % m_SplitsPerDimension[0];
splitRegion.SetSize(0, region.GetSize()[0]); // Transform the split index to the actual coordinates
splitRegion.SetSize(1, 1); splitRegion.SetIndex(0, region.GetIndex(0) + m_TileDimension * splitIndex[0]);
splitRegion.SetIndex(1, region.GetIndex(1) + m_TileSizeAlignment * splitIndex[1]);
// Handle the borders splitRegion.SetSize(0, m_TileDimension);
splitRegion.Crop(region); splitRegion.SetSize(1, 1);
//Add this split to the vector (we keep the order given by // Handle the borders
//the adaptative splitter) splitRegion.Crop(region);
m_StreamVector.push_back(splitRegion);
}
} return splitRegion;
}
m_IsUpToDate = true;
return;
} }
void void
......
...@@ -65,8 +65,6 @@ public: ...@@ -65,8 +65,6 @@ public:
/** Region typedef support. */ /** Region typedef support. */
typedef itk::ImageRegion<ImageDimension> RegionType; typedef itk::ImageRegion<ImageDimension> RegionType;
typedef std::vector<RegionType> StreamVectorType;
/** How many pieces can the specified region be split? A given region /** How many pieces can the specified region be split? A given region
* cannot always be divided into the requested number of pieces. For * cannot always be divided into the requested number of pieces. For
* instance, if the numberOfPieces exceeds the number of pixels along * instance, if the numberOfPieces exceeds the number of pixels along
...@@ -89,42 +87,12 @@ public: ...@@ -89,42 +87,12 @@ public:
itkSetMacro(ShrinkFactor, unsigned int); itkSetMacro(ShrinkFactor, unsigned int);
itkGetMacro(ShrinkFactor, unsigned int); itkGetMacro(ShrinkFactor, unsigned int);
/** Set the TileHint parameter */
itkSetMacro(TileHint, SizeType);
/** Get the TileHint parameter */
itkGetConstReferenceMacro(TileHint, SizeType);
/** Set the ImageRegion parameter */
itkSetMacro(ImageRegion, RegionType);
/** Get the ImageRegion parameter */
itkGetConstReferenceMacro(ImageRegion, RegionType);
/** Set the requested number of splits parameter */
itkSetMacro(RequestedNumberOfSplits, unsigned int);
/** Get the requested number of splits parameter */
itkGetConstReferenceMacro(RequestedNumberOfSplits, unsigned int);
protected: protected:
StreamingShrinkImageRegionSplitter() : m_SplitsPerDimension(0U), StreamingShrinkImageRegionSplitter() : m_SplitsPerDimension(0U), m_ShrinkFactor(10) {}
m_ShrinkFactor(10),
m_TileHint(),
m_ImageRegion(),
m_RequestedNumberOfSplits(0),
m_StreamVector(),
m_IsUpToDate(false)
{}
virtual ~StreamingShrinkImageRegionSplitter() {} virtual ~StreamingShrinkImageRegionSplitter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const; void PrintSelf(std::ostream& os, itk::Indent indent) const;
private: private:
/** This methods actually estimate the split map using the
ImageRegionAdaptativeSplitter and stores it in a
vector */
void EstimateSplitMap(unsigned int numberOfPieces);
StreamingShrinkImageRegionSplitter(const StreamingShrinkImageRegionSplitter &); //purposely not implemented StreamingShrinkImageRegionSplitter(const StreamingShrinkImageRegionSplitter &); //purposely not implemented
void operator =(const StreamingShrinkImageRegionSplitter&); //purposely not implemented void operator =(const StreamingShrinkImageRegionSplitter&); //purposely not implemented
...@@ -132,24 +100,6 @@ private: ...@@ -132,24 +100,6 @@ private:
unsigned int m_TileDimension; unsigned int m_TileDimension;
unsigned int m_TileSizeAlignment; unsigned int m_TileSizeAlignment;
unsigned int m_ShrinkFactor; unsigned int m_ShrinkFactor;
// This reflects the input image tiling
SizeType m_TileHint;
// This contains the ImageRegion that is currently beeing split
RegionType m_ImageRegion;
// This contains the requested number of splits
unsigned int m_RequestedNumberOfSplits;
// This is a vector of all regions which will be split
StreamVectorType m_StreamVector;
// Is the splitter up-to-date ?
mutable bool m_IsUpToDate;
// Lock to ensure thread-safety
itk::SimpleFastMutexLock m_Lock;
}; };
......
...@@ -40,32 +40,9 @@ template <class TImage> ...@@ -40,32 +40,9 @@ template <class TImage>
void void
StreamingShrinkStreamingManager<TImage>::PrepareStreaming( itk::DataObject * input, const RegionType &region ) StreamingShrinkStreamingManager<TImage>::PrepareStreaming( itk::DataObject * input, const RegionType &region )
{ {
typedef otb::StreamingShrinkImageRegionSplitter TileSplitterType; typedef otb::StreamingShrinkImageRegionSplitter TileSplitterType;
TileSplitterType::Pointer splitter = TileSplitterType::New(); TileSplitterType::Pointer splitter = TileSplitterType::New();
splitter->SetTileSizeAlignment(m_ShrinkFactor); splitter->SetTileSizeAlignment(m_ShrinkFactor);
//Uses the TileHint from the MetaDataDictionnary to find out
//the tiling sheme of the input file if available.
typename otb::StreamingShrinkStreamingManager<TImage>::SizeType tileHint;
unsigned int tileHintX(0), tileHintY(0);
itk::ExposeMetaData<unsigned int>(input->GetMetaDataDictionary(),
MetaDataKey::TileHintX,
tileHintX);
itk::ExposeMetaData<unsigned int>(input->GetMetaDataDictionary(),
MetaDataKey::TileHintY,
tileHintY);
tileHint[0] = tileHintX;
tileHint[1] = tileHintY;
splitter->SetTileHint(tileHint);
this->m_Splitter = splitter; this->m_Splitter = splitter;
unsigned long nbDivisions = this->EstimateOptimalNumberOfDivisions(input, region, 0); unsigned long nbDivisions = this->EstimateOptimalNumberOfDivisions(input, region, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment