Skip to content
Snippets Groups Projects
Commit e08d948b authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: support AbortGenerateData in virtual streamer

parent c0a506e7
No related branches found
No related tags found
1 merge request!34Stop button for graphic applications
......@@ -142,6 +142,11 @@ public:
* This filter does not produce an output */
void Update() ITK_OVERRIDE;
// the interface of the superclass getter function is not thread safe
bool GetAbortGenerateDataMutex() const;
void SetAbortGenerateData(bool val) override;
protected:
StreamingImageVirtualWriter();
......@@ -186,6 +191,9 @@ private:
bool m_IsObserving;
unsigned long m_ObserverID;
/** Lock to ensure thread-safety (added for the AbortGenerateData flag) */
itk::SimpleFastMutexLock m_Lock;
};
} // end namespace otb
......
......@@ -238,7 +238,7 @@ StreamingImageVirtualWriter<TInputImage>
*/
InputImageRegionType streamRegion;
for (m_CurrentDivision = 0;
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateData();
m_CurrentDivision < m_NumberOfDivisions && !this->GetAbortGenerateDataMutex();
m_CurrentDivision++, m_DivisionProgress = 0, this->UpdateFilterProgress())
{
streamRegion = m_StreamingManager->GetSplit(m_CurrentDivision);
......@@ -255,10 +255,17 @@ StreamingImageVirtualWriter<TInputImage>
* If we ended due to aborting, push the progress up to 1.0 (since
* it probably didn't end there)
*/
if (!this->GetAbortGenerateData())
if (!this->GetAbortGenerateDataMutex())
{
this->UpdateProgress(1.0);
}
else
{
itk::ProcessAborted e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Image streaming has been aborted");
throw e;
}
// Notify end event observers
this->InvokeEvent(itk::EndEvent());
......@@ -286,6 +293,26 @@ StreamingImageVirtualWriter<TInputImage>
this->ReleaseInputs();
}
template <class TInputImage>
bool
StreamingImageVirtualWriter<TInputImage>
::GetAbortGenerateDataMutex() const
{
m_Lock.Lock();
bool ret = Superclass::GetAbortGenerateData();
m_Lock.Unlock();
return ret;
}
template <class TInputImage>
void
StreamingImageVirtualWriter<TInputImage>
::SetAbortGenerateData(bool val)
{
m_Lock.Lock();
Superclass::SetAbortGenerateData(val);
m_Lock.Unlock();
}
} // end namespace otb
......
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