1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
* Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbStreamingManager_h
#define otbStreamingManager_h
#include "otbMacro.h"
#include "itkDataObject.h"
#include "itkImageRegionSplitterBase.h"
#include "otbPipelineMemoryPrintCalculator.h"
namespace otb
{
/** \class StreamingManager
* \brief This class handles the streaming process used in the writers implementation
*
* The streaming mode can be chosen with either SetStrippedRAMStreamingMode, SetStrippedNumberOfLinesStreamingMode,
* SetTiledRAMStreamingMode, or SetTiledTileDimensionStreamingMode.
*
* Then, PrepareStreaming must be called so that the stream type and dimensions are computed
* This involves passing the actual DataObject who will be written, since it will be used
* during memory estimation for some specific streaming modes.
*
* After PrepareStreaming has been called, the actual number of splits and streaming mode which will be used
* can be retrieved with GetStreamingMode and GetNumberOfSplits.
* The different splits can be retrieved with GetSplit
*
* \sa ImageFileWriter
* \sa StreamingImageVirtualFileWriter
*
* \ingroup OTBStreaming
*/
template<class TImage>
class ITK_EXPORT StreamingManager : public itk::Object
{
public:
/** Standard class typedefs. */
typedef StreamingManager Self;
typedef itk::LightObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef TImage ImageType;
typedef typename ImageType::Pointer ImagePointerType;
typedef typename ImageType::RegionType RegionType;
typedef typename RegionType::IndexType IndexType;
typedef typename RegionType::SizeType SizeType;
typedef typename ImageType::InternalPixelType PixelType;
typedef otb::PipelineMemoryPrintCalculator::MemoryPrintType MemoryPrintType;
typedef itk::ImageRegionSplitterBase AbstractSplitterType;
/** Type macro */
itkTypeMacro(StreamingManager, itk::LightObject);
/** Dimension of input image. */
itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
const AbstractSplitterType * GetSplitter() const;
/** Actually computes the stream divisions, according to the specified streaming mode,
* eventually using the input parameter to estimate memory consumption */
virtual void PrepareStreaming(itk::DataObject * input, const RegionType ®ion) = 0;
/** Returns the actual number of pieces that will be used to process the image.
* PrepareStreaming() must have been called before.
* This can be different than the requested number */
virtual unsigned int GetNumberOfSplits();
/** Get a region definition that represents the ith piece a specified region.
* The "numberOfPieces" must be equal to what
* GetNumberOfSplits() returns. */
virtual RegionType GetSplit(unsigned int i);
itkSetMacro(DefaultRAM, MemoryPrintType);
itkGetMacro(DefaultRAM, MemoryPrintType);
protected:
StreamingManager();
~StreamingManager() override;
virtual unsigned int EstimateOptimalNumberOfDivisions(itk::DataObject * input, const RegionType ®ion,
MemoryPrintType availableRAMInMB,
double bias = 1.0);
/** The number of splits generated by the splitter */
unsigned int m_ComputedNumberOfSplits;
/** The region to stream */
RegionType m_Region;
/** The splitter used to compute the different strips */
typedef typename AbstractSplitterType::Pointer AbstractSplitterPointerType;
AbstractSplitterPointerType m_Splitter;
private:
StreamingManager(const StreamingManager &); //purposely not implemented
void operator =(const StreamingManager&); //purposely not implemented
/** Compute the available RAM in Bytes from an input value in MByte.
* If the input value is 0, it uses the m_DefaultRAM value.
* If m_DefaultRAM is also 0, it uses the configuration settings */
MemoryPrintType GetActualAvailableRAMInBytes(MemoryPrintType availableRAMInMB);
/** Default available RAM in MB */
MemoryPrintType m_DefaultRAM;
};
} // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbStreamingManager.txx"
#endif
#endif
|