21 #ifndef otbStreamingImageVirtualWriter_hxx
22 #define otbStreamingImageVirtualWriter_hxx
26 #include "itkCommand.h"
40 template <
class TInputImage>
42 : m_NumberOfDivisions(0), m_CurrentDivision(0), m_DivisionProgress(0.0), m_IsObserving(true), m_ObserverID(0)
49 template <
class TInputImage>
54 template <
class TInputImage>
57 Superclass::PrintSelf(os, indent);
60 template <
class TInputImage>
64 typename NumberOfDivisionsStrippedStreamingManagerType::Pointer streamingManager = NumberOfDivisionsStrippedStreamingManagerType::New();
65 streamingManager->SetNumberOfDivisions(nbDivisions);
67 m_StreamingManager = streamingManager;
70 template <
class TInputImage>
74 typename NumberOfDivisionsTiledStreamingManagerType::Pointer streamingManager = NumberOfDivisionsTiledStreamingManagerType::New();
75 streamingManager->SetNumberOfDivisions(nbDivisions);
77 m_StreamingManager = streamingManager;
80 template <
class TInputImage>
84 typename NumberOfLinesStrippedStreamingManagerType::Pointer streamingManager = NumberOfLinesStrippedStreamingManagerType::New();
85 streamingManager->SetNumberOfLinesPerStrip(nbLinesPerStrip);
87 m_StreamingManager = streamingManager;
90 template <
class TInputImage>
94 typename RAMDrivenStrippedStreamingManagerType::Pointer streamingManager = RAMDrivenStrippedStreamingManagerType::New();
95 streamingManager->SetAvailableRAMInMB(availableRAM);
96 streamingManager->SetBias(bias);
97 m_StreamingManager = streamingManager;
100 template <
class TInputImage>
104 typename TileDimensionTiledStreamingManagerType::Pointer streamingManager = TileDimensionTiledStreamingManagerType::New();
105 streamingManager->SetTileDimension(tileDimension);
107 m_StreamingManager = streamingManager;
110 template <
class TInputImage>
114 typename RAMDrivenTiledStreamingManagerType::Pointer streamingManager = RAMDrivenTiledStreamingManagerType::New();
115 streamingManager->SetAvailableRAMInMB(availableRAM);
116 streamingManager->SetBias(bias);
117 m_StreamingManager = streamingManager;
120 template <
class TInputImage>
124 typename RAMDrivenAdaptativeStreamingManagerType::Pointer streamingManager = RAMDrivenAdaptativeStreamingManagerType::New();
125 streamingManager->SetAvailableRAMInMB(availableRAM);
126 streamingManager->SetBias(bias);
127 m_StreamingManager = streamingManager;
130 template <
class TInputImage>
134 inputPtr->UpdateOutputInformation();
136 this->GenerateData();
139 template <
class TInputImage>
145 typename InputImageRegionType::SizeType size;
146 typename InputImageRegionType::IndexType index;
150 region.SetSize(size);
151 region.SetIndex(index);
152 inputPtr->SetRequestedRegion(region);
155 template <
class TInputImage>
163 this->PrepareOutputs();
164 this->SetAbortGenerateData(0);
165 this->SetProgress(0.0);
166 this->m_Updating =
true;
171 this->InvokeEvent(itk::StartEvent());
184 m_StreamingManager->PrepareStreaming(inputPtr, outputRegion);
185 m_NumberOfDivisions = m_StreamingManager->GetNumberOfSplits();
192 itk::ProcessObject* source = inputPtr->GetSource();
193 m_IsObserving =
false;
199 typedef itk::MemberCommand<Self> CommandType;
200 typedef typename CommandType::Pointer CommandPointerType;
202 CommandPointerType command = CommandType::New();
203 command->SetCallbackFunction(
this, &Self::ObserveSourceFilterProgress);
205 m_ObserverID = source->AddObserver(itk::ProgressEvent(), command);
206 m_IsObserving =
true;
209 const auto firstSplitSize = m_StreamingManager->GetSplit(0).GetSize();
210 otbLogMacro(Info, <<
"Estimation will be performed in " << m_NumberOfDivisions <<
" blocks of " << firstSplitSize[0] <<
"x" << firstSplitSize[1]
219 for (m_CurrentDivision = 0; m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
220 m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
222 streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
226 inputPtr->SetRequestedRegion(streamRegion);
227 inputPtr->PropagateRequestedRegion();
228 inputPtr->UpdateOutputData();
236 if (!this->GetAbortGenerateData())
238 this->UpdateProgress(1.0);
242 itk::ProcessAborted e(__FILE__, __LINE__);
243 e.SetLocation(ITK_LOCATION);
244 e.SetDescription(
"Image streaming has been aborted");
250 this->InvokeEvent(itk::EndEvent());
254 m_IsObserving =
false;
255 source->RemoveObserver(m_ObserverID);
261 for (
unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx)
263 if (this->GetOutput(idx))
265 this->GetOutput(idx)->DataHasBeenGenerated();
273 this->ReleaseInputs();
276 template <
class TInputImage>
280 bool ret = Superclass::GetAbortGenerateData();
287 template <
class TInputImage>
291 Superclass::SetAbortGenerateData(val);