diff --git a/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx b/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx index 65252ff5c68cfc5e7a3d85fc0f8ff5a835ab55de..3aed87bd664e084610aee0decdc16415ae71076b 100644 --- a/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx +++ b/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx @@ -22,8 +22,7 @@ #include "otbOGRDataSourceToLabelImageFilter.h" #include "itkImageRegionConstIterator.h" -#include "otbStreamingTraits.h" - +#include "otbRAMDrivenAdaptativeStreamingManager.h" #include "otbConfusionMatrixMeasurements.h" @@ -49,10 +48,9 @@ public: typedef itk::ImageRegionConstIterator<Int32ImageType> ImageIteratorType; typedef otb::OGRDataSourceToLabelImageFilter<Int32ImageType> RasterizeFilterType; - - typedef otb::StreamingTraits<Int32ImageType> StreamingTraitsType; - - typedef itk::ImageRegionSplitter<2> SplitterType; + + typedef RAMDrivenAdaptativeStreamingManager + <Int32ImageType> RAMDrivenAdaptativeStreamingManagerType; typedef Int32ImageType::RegionType RegionType; @@ -242,14 +240,17 @@ private: } // Prepare local streaming - SplitterType::Pointer splitter = SplitterType::New(); - unsigned int numberOfStreamDivisions = StreamingTraitsType::CalculateNumberOfStreamDivisions( - input, - input->GetLargestPossibleRegion(), - splitter, - otb::SET_BUFFER_MEMORY_SIZE, - 0, 1048576*GetParameterInt("ram"), 0); - RegionType streamRegion; + + RAMDrivenAdaptativeStreamingManagerType::Pointer + streamingManager = RAMDrivenAdaptativeStreamingManagerType::New(); + int availableRAM = GetParameterInt("ram"); + streamingManager->SetAvailableRAMInMB(availableRAM); + float bias = 2.0; // empiric value; + streamingManager->SetBias(bias); + + streamingManager->PrepareStreaming(input, input->GetLargestPossibleRegion()); + + unsigned long numberOfStreamDivisions = streamingManager->GetNumberOfSplits(); otbAppLogINFO("Number of stream divisions : "<<numberOfStreamDivisions); @@ -262,7 +263,7 @@ private: for (unsigned int index = 0; index < numberOfStreamDivisions; index++) { - streamRegion = splitter->GetSplit(index, numberOfStreamDivisions, reference->GetLargestPossibleRegion()); + RegionType streamRegion = streamingManager->GetSplit(index); input->SetRequestedRegion(streamRegion); input->PropagateRequestedRegion(); diff --git a/Modules/Applications/AppClassification/app/otbSOMClassification.cxx b/Modules/Applications/AppClassification/app/otbSOMClassification.cxx index aed041c0a697a5f04616074132ff720ffbb945d7..87f9313cfc15566edb122b752f07c2286bef3fa7 100644 --- a/Modules/Applications/AppClassification/app/otbSOMClassification.cxx +++ b/Modules/Applications/AppClassification/app/otbSOMClassification.cxx @@ -21,7 +21,7 @@ #include "otbSOMMap.h" #include "otbSOM.h" #include "otbSOMImageClassificationFilter.h" -#include "otbStreamingTraits.h" +#include "otbRAMDrivenAdaptativeStreamingManager.h" #include "itkImageRegionConstIterator.h" #include "itkImageRandomNonRepeatingConstIteratorWithIndex.h" @@ -53,8 +53,9 @@ public: typedef itk::Statistics::ListSample<SampleType> ListSampleType; typedef otb::SOM<ListSampleType, SOMMapType> EstimatorType; - typedef otb::StreamingTraits<FloatVectorImageType> StreamingTraitsType; - typedef itk::ImageRegionSplitter<2> SplitterType; + typedef RAMDrivenAdaptativeStreamingManager + <FloatVectorImageType> RAMDrivenAdaptativeStreamingManagerType; + typedef FloatVectorImageType::RegionType RegionType; typedef itk::ImageRegionConstIterator<FloatVectorImageType> IteratorType; @@ -99,10 +100,6 @@ private: SetParameterDescription("ts", "Maximum training set size (in pixels)"); MandatoryOff("ts"); - AddParameter(ParameterType_Int, "sl", "StreamingLines"); - SetParameterDescription("sl", "Number of lines in each streaming block (used during data sampling)"); - MandatoryOff("sl"); - AddParameter(ParameterType_OutputImage, "som", "SOM Map"); SetParameterDescription("som","Output image containing the Self-Organizing Map"); MandatoryOff("som"); @@ -203,24 +200,18 @@ private: RegionType largestRegion = input->GetLargestPossibleRegion(); // Setting up local streaming capabilities - SplitterType::Pointer splitter = SplitterType::New(); - unsigned int numberOfStreamDivisions; - if (HasValue("sl")) - { - numberOfStreamDivisions = StreamingTraitsType::CalculateNumberOfStreamDivisions(input, - largestRegion, - splitter, - otb::SET_BUFFER_NUMBER_OF_LINES, - 0, 0, GetParameterInt("sl")); - } - else - { - numberOfStreamDivisions = StreamingTraitsType::CalculateNumberOfStreamDivisions(input, - largestRegion, - splitter, - otb::SET_BUFFER_MEMORY_SIZE, - 0, 1048576*GetParameterInt("ram"), 0); - } + + RAMDrivenAdaptativeStreamingManagerType::Pointer + streamingManager = RAMDrivenAdaptativeStreamingManagerType::New(); + int availableRAM = GetParameterInt("ram"); + streamingManager->SetAvailableRAMInMB(availableRAM); + float bias = 2.0; // empiric value; + streamingManager->SetBias(bias); + + streamingManager->PrepareStreaming(input, largestRegion); + + unsigned long numberOfStreamDivisions = streamingManager->GetNumberOfSplits(); + otbAppLogINFO("The images will be streamed into "<<numberOfStreamDivisions<<" parts."); @@ -258,7 +249,7 @@ private: unsigned int localNbSamples=0; piece = randPerm[index]; - streamingRegion = splitter->GetSplit(piece, numberOfStreamDivisions, largestRegion); + streamingRegion = streamingManager->GetSplit(piece); //otbAppLogINFO("Processing region: "<<streamingRegion); input->SetRequestedRegion(streamingRegion); diff --git a/Modules/Applications/AppClassification/otb-module.cmake b/Modules/Applications/AppClassification/otb-module.cmake index 453880987bae9e569e993189f8e955674f5de398..e40002ec7ba6d16d5cdf7d59c622e2228d02e82c 100644 --- a/Modules/Applications/AppClassification/otb-module.cmake +++ b/Modules/Applications/AppClassification/otb-module.cmake @@ -26,6 +26,7 @@ otb_module(OTBAppClassification OTBImageManipulation OTBObjectList OTBCommon + OTBStreaming TEST_DEPENDS OTBTestKernel OTBCommandLine diff --git a/Modules/Applications/AppImageUtils/otb-module.cmake b/Modules/Applications/AppImageUtils/otb-module.cmake index 95aadda68bbbde6a63ece2e1085962b7cd627afa..5aaa29518841f9c03a4e57833501ad81cd332579 100644 --- a/Modules/Applications/AppImageUtils/otb-module.cmake +++ b/Modules/Applications/AppImageUtils/otb-module.cmake @@ -18,6 +18,7 @@ otb_module(OTBAppImageUtils OTBKMZWriter OTBOSSIMAdapters OTBObjectList + OTBStreaming TEST_DEPENDS OTBTestKernel OTBCommandLine diff --git a/Modules/Core/PointSet/include/otbImageToPointSetFilter.h b/Modules/Core/PointSet/include/otbImageToPointSetFilter.h index bbea9402334e6c6c0aa97b0511ef7b80824a590f..c272fca339df3268b31bd1c7f6a3300112a2d06e 100644 --- a/Modules/Core/PointSet/include/otbImageToPointSetFilter.h +++ b/Modules/Core/PointSet/include/otbImageToPointSetFilter.h @@ -19,7 +19,9 @@ #define __otbImageToPointSetFilter_h #include "otbPointSetSource.h" -#include "otbStreamingTraits.h" +#include "otbRAMDrivenAdaptativeStreamingManager.h" + +// TODO: This class needs a refactoring to become a persistent filter namespace otb { @@ -113,10 +115,10 @@ protected: /** End Multi-threading implementation */ /** Setup for streaming */ - typedef StreamingTraits<InputImageType> StreamingTraitsType; - typedef itk::ImageRegionSplitter<itkGetStaticConstMacro(InputImageDimension)> SplitterType; - typedef typename SplitterType::Pointer RegionSplitterPointer; - RegionSplitterPointer m_RegionSplitter; + typedef RAMDrivenAdaptativeStreamingManager<InputImageType> StreamingManagerType; + typedef typename StreamingManagerType::Pointer StreamingManagerPointer; + + StreamingManagerPointer m_StreamingManager; private: ImageToPointSetFilter(const ImageToPointSetFilter &); //purposely not implemented diff --git a/Modules/Core/PointSet/include/otbImageToPointSetFilter.txx b/Modules/Core/PointSet/include/otbImageToPointSetFilter.txx index 370f093e0f48985c764e66827491964ff09b75a6..3bd2b134441fb8d38c57e57260fa6bae26544f2e 100644 --- a/Modules/Core/PointSet/include/otbImageToPointSetFilter.txx +++ b/Modules/Core/PointSet/include/otbImageToPointSetFilter.txx @@ -42,8 +42,7 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> m_PointDataContainerPerThread.clear(); // create default region splitter - m_RegionSplitter = itk::ImageRegionSplitter<itkGetStaticConstMacro(InputImageDimension)>::New(); - + m_StreamingManager = StreamingManagerType::New(); } /** @@ -138,21 +137,17 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> PointDataContainerType * outputPointDataContainer = this->GetOutput()->GetPointData(); outputPointDataContainer->Initialize(); - + typename TInputImage::RegionType inputRegion = this->GetInput()->GetLargestPossibleRegion(); - unsigned int numDivisions; - numDivisions = StreamingTraitsType - ::CalculateNumberOfStreamDivisions(this->GetInput(), - this->GetInput()->GetLargestPossibleRegion(), - m_RegionSplitter, - SET_AUTOMATIC_NUMBER_OF_STREAM_DIVISIONS, - 0, 0, 0); - // Input is an image, cast away the constness so we can set // the requested region. InputImagePointer input = const_cast<TInputImage *> (this->GetInput()); + m_StreamingManager->PrepareStreaming(input,inputRegion); + + unsigned long numDivisions = m_StreamingManager->GetNumberOfSplits(); + /** * Loop over the number of pieces, execute the upstream pipeline on each * piece, and copy the results into the output image. @@ -163,7 +158,7 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet> piece < numDivisions && !this->GetAbortGenerateData(); piece++) { - streamRegion = m_RegionSplitter->GetSplit(piece, numDivisions, inputRegion); + streamRegion = m_StreamingManager->GetSplit(piece); typedef itk::ImageToImageFilterDetail::ImageRegionCopier<itkGetStaticConstMacro(InputImageDimension), itkGetStaticConstMacro(InputImageDimension)> OutputToInputRegionCopierType; diff --git a/Modules/Core/PointSet/otb-module.cmake b/Modules/Core/PointSet/otb-module.cmake index 04c03982cbcea6028adb1a7be52475ed4463a8b6..2a7c22396ef892d3690fd6fcb9889da9165ec421 100644 --- a/Modules/Core/PointSet/otb-module.cmake +++ b/Modules/Core/PointSet/otb-module.cmake @@ -10,6 +10,7 @@ otb_module(OTBPointSet DEPENDS OTBCommon OTBInterpolation + OTBStreaming TEST_DEPENDS OTBTestKernel