Orfeo Toolbox  4.0
otbStreamingImageVirtualWriter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbStreamingImageVirtualWriter_txx
19 #define __otbStreamingImageVirtualWriter_txx
21 
22 #include "otbMacro.h"
23 #include "otbConfigure.h"
24 #include "itkCommand.h"
25 
33 
34 namespace otb
35 {
36 
37 template <class TInputImage>
40  : m_NumberOfDivisions(0),
41  m_CurrentDivision(0),
42  m_DivisionProgress(0.0),
43  m_IsObserving(true),
44  m_ObserverID(0)
45 {
46  // By default, we use tiled streaming, with automatic tile size
47  // We don't set any parameter, so the memory size is retrieved from the OTB configuration options
48  this->SetAutomaticAdaptativeStreaming();
49 }
50 
51 template <class TInputImage>
54 {
55 }
56 
57 template <class TInputImage>
58 void
60 ::PrintSelf(std::ostream& os, itk::Indent indent) const
61 {
62  Superclass::PrintSelf(os, indent);
63 }
64 
65 template <class TInputImage>
66 void
68 ::SetNumberOfDivisionsStrippedStreaming(unsigned int nbDivisions)
69 {
70  typedef NumberOfDivisionsStrippedStreamingManager<TInputImage> NumberOfDivisionsStrippedStreamingManagerType;
71  typename NumberOfDivisionsStrippedStreamingManagerType::Pointer streamingManager = NumberOfDivisionsStrippedStreamingManagerType::New();
72  streamingManager->SetNumberOfDivisions(nbDivisions);
73 
74  m_StreamingManager = streamingManager;
75 }
76 
77 template <class TInputImage>
78 void
80 ::SetNumberOfDivisionsTiledStreaming(unsigned int nbDivisions)
81 {
82  typedef NumberOfDivisionsTiledStreamingManager<TInputImage> NumberOfDivisionsTiledStreamingManagerType;
83  typename NumberOfDivisionsTiledStreamingManagerType::Pointer streamingManager = NumberOfDivisionsTiledStreamingManagerType::New();
84  streamingManager->SetNumberOfDivisions(nbDivisions);
85 
86  m_StreamingManager = streamingManager;
87 }
88 
89 template <class TInputImage>
90 void
92 ::SetNumberOfLinesStrippedStreaming(unsigned int nbLinesPerStrip)
93 {
94  typedef NumberOfLinesStrippedStreamingManager<TInputImage> NumberOfLinesStrippedStreamingManagerType;
95  typename NumberOfLinesStrippedStreamingManagerType::Pointer streamingManager = NumberOfLinesStrippedStreamingManagerType::New();
96  streamingManager->SetNumberOfLinesPerStrip(nbLinesPerStrip);
97 
98  m_StreamingManager = streamingManager;
99 }
100 
101 template <class TInputImage>
102 void
104 ::SetAutomaticStrippedStreaming(unsigned int availableRAM, double bias)
105 {
106  typedef RAMDrivenStrippedStreamingManager<TInputImage> RAMDrivenStrippedStreamingManagerType;
107  typename RAMDrivenStrippedStreamingManagerType::Pointer streamingManager = RAMDrivenStrippedStreamingManagerType::New();
108  streamingManager->SetAvailableRAMInMB(availableRAM);
109  streamingManager->SetBias(bias);
110  m_StreamingManager = streamingManager;
111 }
112 
113 template <class TInputImage>
114 void
116 ::SetTileDimensionTiledStreaming(unsigned int tileDimension)
117 {
118  typedef TileDimensionTiledStreamingManager<TInputImage> TileDimensionTiledStreamingManagerType;
119  typename TileDimensionTiledStreamingManagerType::Pointer streamingManager = TileDimensionTiledStreamingManagerType::New();
120  streamingManager->SetTileDimension(tileDimension);
121 
122  m_StreamingManager = streamingManager;
123 }
124 
125 template <class TInputImage>
126 void
128 ::SetAutomaticTiledStreaming(unsigned int availableRAM, double bias)
129 {
130  typedef RAMDrivenTiledStreamingManager<TInputImage> RAMDrivenTiledStreamingManagerType;
131  typename RAMDrivenTiledStreamingManagerType::Pointer streamingManager = RAMDrivenTiledStreamingManagerType::New();
132  streamingManager->SetAvailableRAMInMB(availableRAM);
133  streamingManager->SetBias(bias);
134  m_StreamingManager = streamingManager;
135 }
136 
137 template <class TInputImage>
138 void
140 ::SetAutomaticAdaptativeStreaming(unsigned int availableRAM, double bias)
141 {
142  typedef RAMDrivenAdaptativeStreamingManager<TInputImage> RAMDrivenAdaptativeStreamingManagerType;
143  typename RAMDrivenAdaptativeStreamingManagerType::Pointer streamingManager = RAMDrivenAdaptativeStreamingManagerType::New();
144  streamingManager->SetAvailableRAMInMB(availableRAM);
145  streamingManager->SetBias(bias);
146  m_StreamingManager = streamingManager;
147 }
148 
149 template <class TInputImage>
150 void
153 {
154  InputImagePointer inputPtr = const_cast<InputImageType *>(this->GetInput(0));
155  inputPtr->UpdateOutputInformation();
156 
157  this->GenerateData();
158 }
159 
160 template <class TInputImage>
161 void
164 {
165  InputImagePointer inputPtr = const_cast<InputImageType *>(this->GetInput(0));
166 
167  InputImageRegionType region;
168  typename InputImageRegionType::SizeType size;
169  typename InputImageRegionType::IndexType index;
170 
171  index.Fill(0);
172  size.Fill(0);
173  region.SetSize(size);
174  region.SetIndex(index);
175  inputPtr->SetRequestedRegion(region);
176 }
177 
178 template<class TInputImage>
179 void
182 {
186  this->PrepareOutputs();
187  this->SetAbortGenerateData(0);
188  this->SetProgress(0.0);
189  this->m_Updating = true;
193  this->InvokeEvent(itk::StartEvent());
194 
198  InputImagePointer inputPtr = const_cast<InputImageType *>(this->GetInput(0));
199  InputImageRegionType outputRegion = inputPtr->GetLargestPossibleRegion();
205  m_StreamingManager->PrepareStreaming(inputPtr, outputRegion);
206  m_NumberOfDivisions = m_StreamingManager->GetNumberOfSplits();
207 
211  // Get the source process object
212  itk::ProcessObject* source = inputPtr->GetSource();
213  m_IsObserving = false;
214  m_ObserverID = 0;
215 
216  // Check if source exists
217  if(source)
218  {
219  typedef itk::MemberCommand<Self> CommandType;
220  typedef typename CommandType::Pointer CommandPointerType;
221 
222  CommandPointerType command = CommandType::New();
223  command->SetCallbackFunction(this, &Self::ObserveSourceFilterProgress);
224 
225  m_ObserverID = source->AddObserver(itk::ProgressEvent(), command);
226  m_IsObserving = true;
227  }
228  else
229  {
230  itkWarningMacro(<< "Could not get the source process object. Progress report might be buggy");
231  }
232 
237  InputImageRegionType streamRegion;
238  for (m_CurrentDivision = 0;
239  m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
240  m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
241  {
242  streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
243  otbMsgDevMacro(<< "Processing region : " << streamRegion )
244  //inputPtr->ReleaseData();
245  //inputPtr->SetRequestedRegion(streamRegion);
246  //inputPtr->Update();
247  inputPtr->SetRequestedRegion(streamRegion);
248  inputPtr->PropagateRequestedRegion();
249  inputPtr->UpdateOutputData();
250  }
251 
256  if (!this->GetAbortGenerateData())
257  {
258  this->UpdateProgress(1.0);
259  }
260 
261  // Notify end event observers
262  this->InvokeEvent(itk::EndEvent());
263 
264  if (m_IsObserving)
265  {
266  m_IsObserving = false;
267  source->RemoveObserver(m_ObserverID);
268  }
269 
273  for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx)
274  {
275  if (this->GetOutput(idx))
276  {
277  this->GetOutput(idx)->DataHasBeenGenerated();
278  }
279  }
280 
284  this->ReleaseInputs();
285 }
286 
287 
288 } // end namespace otb
289 
290 #endif

Generated at Sat Mar 8 2014 16:19:55 for Orfeo Toolbox with doxygen 1.8.3.1