#include <mitkNonBlockingAlgorithm.h>
Classes | |
class | ThreadParameters |
Public Types | |
typedef NonBlockingAlgorithm | Self |
typedef itk::Object | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
void | SetDataStorage (DataStorage &storage) |
DataStorage * | GetDataStorage () |
template<typename T > | |
void | SetParameter (const char *parameter, const T &value) |
For any kind of normal types. | |
template<typename T > | |
void | SetPointerParameter (const char *parameter, const itk::SmartPointer< T > &value) |
For any kind of smart pointers. | |
void | SetPointerParameter (const char *parameter, BaseData *value) |
For any kind of BaseData, like Image, Surface, etc. Will be stored inside some SmartPointerProperty. | |
template<typename TPixel , unsigned int VImageDimension> | |
void | SetItkImageAsMITKImagePointerParameter (const char *parameter, itk::Image< TPixel, VImageDimension > *itkImage) |
For any kind of ITK images (C pointers) | |
template<typename TPixel , unsigned int VImageDimension> | |
void | SetItkImageAsMITKImagePointerParameter (const char *parameter, const itk::SmartPointer< itk::Image< TPixel, VImageDimension > > &itkImage) |
For any kind of ITK images (smartpointers) | |
template<typename T > | |
void | GetParameter (const char *parameter, T &value) const |
template<typename T > | |
void | GetPointerParameter (const char *parameter, itk::SmartPointer< T > &value) const |
virtual void | Reset () |
void | StartAlgorithm () |
void | StartBlockingAlgorithm () |
void | StopAlgorithm () |
void | TriggerParameterModified (const itk::EventObject &) |
void | ThreadedUpdateSuccessful (const itk::EventObject &) |
void | ThreadedUpdateFailed (const itk::EventObject &) |
Protected Member Functions | |
NonBlockingAlgorithm () | |
virtual | ~NonBlockingAlgorithm () |
void | DefineTriggerParameter (const char *) |
void | UnDefineTriggerParameter (const char *) |
virtual void | Initialize (const NonBlockingAlgorithm *other=NULL) |
virtual bool | ReadyToRun () |
virtual bool | ThreadedUpdateFunction () |
virtual void | ThreadedUpdateSuccessful () |
virtual void | ThreadedUpdateFailed () |
Protected Attributes | |
PropertyList::Pointer | m_Parameters |
WeakPointer< DataStorage > | m_DataStorage |
Invokes ResultsAvailable with each new result
done centralize use of itk::MultiThreader in this class
Definition at line 73 of file mitkNonBlockingAlgorithm.h.
typedef itk::SmartPointer<const Self> mitk::NonBlockingAlgorithm::ConstPointer |
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 85 of file mitkNonBlockingAlgorithm.h.
typedef itk::SmartPointer<Self> mitk::NonBlockingAlgorithm::Pointer |
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 85 of file mitkNonBlockingAlgorithm.h.
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 85 of file mitkNonBlockingAlgorithm.h.
typedef itk::Object mitk::NonBlockingAlgorithm::Superclass |
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 85 of file mitkNonBlockingAlgorithm.h.
mitk::NonBlockingAlgorithm::NonBlockingAlgorithm | ( | ) | [protected] |
Definition at line 25 of file mitkNonBlockingAlgorithm.cpp.
References m_Parameters, and mitk::PropertyList::New().
: m_ThreadID(-1), m_UpdateRequests(0), m_KillRequest(false) { m_ParameterListMutex = itk::FastMutexLock::New(); m_Parameters = PropertyList::New(); m_MultiThreader = itk::MultiThreader::New(); }
mitk::NonBlockingAlgorithm::~NonBlockingAlgorithm | ( | ) | [protected, virtual] |
Definition at line 35 of file mitkNonBlockingAlgorithm.cpp.
{ }
void mitk::NonBlockingAlgorithm::DefineTriggerParameter | ( | const char * | parameter ) | [protected] |
Definition at line 70 of file mitkNonBlockingAlgorithm.cpp.
References m_Parameters, and TriggerParameterModified().
{ BaseProperty* value = m_Parameters->GetProperty( parameter ); if ( value && m_TriggerPropertyConnections.find(parameter) == m_TriggerPropertyConnections.end() ) { itk::ReceptorMemberCommand<NonBlockingAlgorithm>::Pointer command = itk::ReceptorMemberCommand<NonBlockingAlgorithm>::New(); command->SetCallbackFunction( this, &NonBlockingAlgorithm::TriggerParameterModified); m_TriggerPropertyConnections[ parameter ] = value->AddObserver( itk::ModifiedEvent(), command ); } }
virtual const char* mitk::NonBlockingAlgorithm::GetClassName | ( | ) | const [virtual] |
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
DataStorage * mitk::NonBlockingAlgorithm::GetDataStorage | ( | ) |
Definition at line 44 of file mitkNonBlockingAlgorithm.cpp.
{ return m_DataStorage; }
void mitk::NonBlockingAlgorithm::GetParameter | ( | const char * | parameter, |
T & | value | ||
) | const [inline] |
Definition at line 143 of file mitkNonBlockingAlgorithm.h.
References mitk::GenericProperty< T >::GetValue().
Referenced by mitk::SegmentationSink::Initialize().
{ //MITK_INFO << "GetParameter normal(" << parameter << ") " << typeid(T).name() << std::endl; //m_ParameterListMutex->Lock(); BaseProperty* p = m_Parameters->GetProperty(parameter); GenericProperty<T>* gp = dynamic_cast< GenericProperty<T>* >( p ); if ( gp ) { value = gp->GetValue(); //m_ParameterListMutex->Unlock(); return; } //m_ParameterListMutex->Unlock(); std::string error("There is no parameter \""); error += parameter; error += '"'; throw std::invalid_argument( error ); }
void mitk::NonBlockingAlgorithm::GetPointerParameter | ( | const char * | parameter, |
itk::SmartPointer< T > & | value | ||
) | const [inline] |
Definition at line 164 of file mitkNonBlockingAlgorithm.h.
References mitk::SmartPointerProperty::GetSmartPointer(), and QuadProgPP::t().
Referenced by mitk::SegmentationSink::GetGroupNode(), mitk::SegmentationSink::Initialize(), mitk::SegmentationSink::LookForPointerTargetBelowGroupNode(), and mitk::SegmentationSink::ReadyToRun().
{ //MITK_INFO << this << "->GetParameter smartpointer(" << parameter << ") " << typeid(itk::SmartPointer<T>).name() << std::endl; //m_ParameterListMutex->Lock(); BaseProperty* p = m_Parameters->GetProperty(parameter); if (p) { SmartPointerProperty* spp = dynamic_cast< SmartPointerProperty* >( p ); if ( spp ) { T* t = dynamic_cast<T*>( spp->GetSmartPointer().GetPointer() ); value = t; //m_ParameterListMutex->Unlock(); return; } } //m_ParameterListMutex->Unlock(); std::string error("There is no parameter \""); error += parameter; error += '"'; throw std::invalid_argument( error ); }
void mitk::NonBlockingAlgorithm::Initialize | ( | const NonBlockingAlgorithm * | other = NULL ) |
[protected, virtual] |
Reimplemented in mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 50 of file mitkNonBlockingAlgorithm.cpp.
References SetPointerParameter().
Referenced by mitk::SegmentationSink::Initialize(), and Reset().
{ // define one input, one output basedata object // some basedata input - image, surface, whatever BaseData::Pointer input; SetPointerParameter("Input", input ); // some basedata output BaseData::Pointer output; SetPointerParameter("Output", output ); }
bool mitk::NonBlockingAlgorithm::ReadyToRun | ( | ) | [protected, virtual] |
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 189 of file mitkNonBlockingAlgorithm.cpp.
Referenced by StartAlgorithm().
{ return true; // default is always ready }
void mitk::NonBlockingAlgorithm::Reset | ( | ) | [virtual] |
Definition at line 99 of file mitkNonBlockingAlgorithm.cpp.
References Initialize().
{ Initialize(); }
void mitk::NonBlockingAlgorithm::SetDataStorage | ( | DataStorage & | storage ) |
Definition at line 39 of file mitkNonBlockingAlgorithm.cpp.
{ m_DataStorage = &storage; }
void mitk::NonBlockingAlgorithm::SetItkImageAsMITKImagePointerParameter | ( | const char * | parameter, |
const itk::SmartPointer< itk::Image< TPixel, VImageDimension > > & | itkImage | ||
) | [inline] |
For any kind of ITK images (smartpointers)
Definition at line 131 of file mitkNonBlockingAlgorithm.h.
References mitk::ImportItkImage(), and mitk::Image::New().
{ //MITK_INFO << "SetParameter ITK image(" << parameter << ") " << typeid(itk::SmartPointer<itk::Image<TPixel, VImageDimension> >).name() << std::endl; // create an MITK image for that mitk::Image::Pointer mitkImage = mitk::Image::New(); mitkImage = ImportItkImage( itkImage ); SetPointerParameter( parameter, mitkImage ); }
void mitk::NonBlockingAlgorithm::SetItkImageAsMITKImagePointerParameter | ( | const char * | parameter, |
itk::Image< TPixel, VImageDimension > * | itkImage | ||
) | [inline] |
For any kind of ITK images (C pointers)
Definition at line 120 of file mitkNonBlockingAlgorithm.h.
References mitk::ImportItkImage(), and mitk::Image::New().
{ //MITK_INFO << "SetParameter ITK image(" << parameter << ") " << typeid(itk::Image<TPixel, VImageDimension>).name() << std::endl; // create an MITK image for that mitk::Image::Pointer mitkImage = mitk::Image::New(); mitkImage = ImportItkImage( itkImage ); SetPointerParameter( parameter, mitkImage ); }
void mitk::NonBlockingAlgorithm::SetParameter | ( | const char * | parameter, |
const T & | value | ||
) | [inline] |
For any kind of normal types.
Definition at line 94 of file mitkNonBlockingAlgorithm.h.
Referenced by mitk::SegmentationSink::Initialize().
{ //MITK_INFO << "SetParameter(" << parameter << ") " << typeid(T).name() << std::endl; //m_ParameterListMutex->Lock(); m_Parameters->SetProperty(parameter, GenericProperty<T>::New(value) ); //m_ParameterListMutex->Unlock(); }
void mitk::NonBlockingAlgorithm::SetPointerParameter | ( | const char * | parameter, |
const itk::SmartPointer< T > & | value | ||
) | [inline] |
For any kind of smart pointers.
Definition at line 104 of file mitkNonBlockingAlgorithm.h.
References mitk::SmartPointerProperty::New().
Referenced by mitk::SegmentationSink::Initialize(), and Initialize().
{ //MITK_INFO << this << "->SetParameter smartpointer(" << parameter << ") " << typeid(itk::SmartPointer<T>).name() << std::endl; m_ParameterListMutex->Lock(); m_Parameters->SetProperty(parameter, SmartPointerProperty::New(value.GetPointer()) ); m_ParameterListMutex->Unlock(); }
void mitk::NonBlockingAlgorithm::SetPointerParameter | ( | const char * | parameter, |
BaseData * | value | ||
) |
For any kind of BaseData, like Image, Surface, etc. Will be stored inside some SmartPointerProperty.
Definition at line 63 of file mitkNonBlockingAlgorithm.cpp.
References m_Parameters, and mitk::SmartPointerProperty::New().
{ m_ParameterListMutex->Lock(); m_Parameters->SetProperty(parameter, SmartPointerProperty::New(value) ); m_ParameterListMutex->Unlock(); }
void mitk::NonBlockingAlgorithm::StartAlgorithm | ( | ) |
Definition at line 111 of file mitkNonBlockingAlgorithm.cpp.
References mitk::NonBlockingAlgorithm::ThreadParameters::m_Algorithm, and ReadyToRun().
Referenced by StartBlockingAlgorithm(), and TriggerParameterModified().
{ if ( !ReadyToRun() ) return; // let algorithm check if all input/parameters are ok if (m_KillRequest) return; // someone wants us to die m_ParameterListMutex->Lock(); m_ThreadParameters.m_Algorithm = this; ++m_UpdateRequests; m_ParameterListMutex->Unlock(); if (m_ThreadID != -1) // thread already running. But something obviously wants us to recalculate the output { return; // thread already running } // spawn a thread that calls ThreadedUpdateFunction(), and ThreadedUpdateFinished() on us itk::ThreadFunctionType fpointer = &StaticNonBlockingAlgorithmThread; m_ThreadID = m_MultiThreader->SpawnThread( fpointer, &m_ThreadParameters); }
void mitk::NonBlockingAlgorithm::StartBlockingAlgorithm | ( | ) |
Definition at line 105 of file mitkNonBlockingAlgorithm.cpp.
References StartAlgorithm(), and StopAlgorithm().
{ StartAlgorithm(); StopAlgorithm(); }
void mitk::NonBlockingAlgorithm::StopAlgorithm | ( | ) |
Definition at line 130 of file mitkNonBlockingAlgorithm.cpp.
Referenced by StartBlockingAlgorithm().
{ if (m_ThreadID == -1) return; // thread not running m_MultiThreader->TerminateThread( m_ThreadID ); // waits for the thread to terminate on its own }
void mitk::NonBlockingAlgorithm::ThreadedUpdateFailed | ( | const itk::EventObject & | ) |
Definition at line 217 of file mitkNonBlockingAlgorithm.cpp.
References mitk::NonBlockingAlgorithm::ThreadParameters::m_Algorithm, and ThreadedUpdateFailed().
{ ThreadedUpdateFailed(); m_ParameterListMutex->Lock(); m_ThreadID = -1; // tested before starting m_ParameterListMutex->Unlock(); m_ThreadParameters.m_Algorithm = NULL; //delete }
void mitk::NonBlockingAlgorithm::ThreadedUpdateFailed | ( | ) | [protected, virtual] |
Definition at line 227 of file mitkNonBlockingAlgorithm.cpp.
Referenced by ThreadedUpdateFailed().
{ // notify observers that something went wrong InvokeEvent( ProcessingError(this) ); }
bool mitk::NonBlockingAlgorithm::ThreadedUpdateFunction | ( | ) | [protected, virtual] |
Reimplemented in mitk::CalculateSegmentationVolume, mitk::SegmentationSink, and mitk::ShowSegmentationAsSurface.
Definition at line 194 of file mitkNonBlockingAlgorithm.cpp.
{ return true; }
void mitk::NonBlockingAlgorithm::ThreadedUpdateSuccessful | ( | const itk::EventObject & | ) |
Definition at line 200 of file mitkNonBlockingAlgorithm.cpp.
References mitk::NonBlockingAlgorithm::ThreadParameters::m_Algorithm, and ThreadedUpdateSuccessful().
{ ThreadedUpdateSuccessful(); m_ParameterListMutex->Lock(); m_ThreadID = -1; // tested before starting m_ParameterListMutex->Unlock(); m_ThreadParameters.m_Algorithm = NULL; }
void mitk::NonBlockingAlgorithm::ThreadedUpdateSuccessful | ( | ) | [protected, virtual] |
Reimplemented in mitk::ShowSegmentationAsSurface.
Definition at line 210 of file mitkNonBlockingAlgorithm.cpp.
Referenced by ThreadedUpdateSuccessful().
{ // notify observers that a result is ready InvokeEvent( ResultAvailable(this) ); }
void mitk::NonBlockingAlgorithm::TriggerParameterModified | ( | const itk::EventObject & | ) |
Definition at line 184 of file mitkNonBlockingAlgorithm.cpp.
References StartAlgorithm().
Referenced by DefineTriggerParameter().
{ StartAlgorithm(); }
void mitk::NonBlockingAlgorithm::UnDefineTriggerParameter | ( | const char * | parameter ) | [protected] |
Definition at line 83 of file mitkNonBlockingAlgorithm.cpp.
References m_Parameters, and MITK_ERROR.
Referenced by mitk::SegmentationSink::Initialize().
{ MapTypeStringUInt::iterator iter = m_TriggerPropertyConnections.find( parameter ); if ( iter != m_TriggerPropertyConnections.end() ) { BaseProperty* value = m_Parameters->GetProperty( parameter ); MITK_ERROR(!value) << "NonBlockingAlgorithm::UnDefineTriggerProperty() in bad state." << std::endl; ; value->RemoveObserver( m_TriggerPropertyConnections[parameter] ); m_TriggerPropertyConnections.erase(iter); } }
Definition at line 219 of file mitkNonBlockingAlgorithm.h.
Referenced by mitk::SegmentationSink::InsertBelowGroupNode(), and mitk::SegmentationSink::LookForPointerTargetBelowGroupNode().
Definition at line 217 of file mitkNonBlockingAlgorithm.h.
Referenced by DefineTriggerParameter(), NonBlockingAlgorithm(), SetPointerParameter(), and UnDefineTriggerParameter().