Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::PoolProcessor Class Reference

#include <inviwo/core/processors/poolprocessor.h>

Inheritance diagram for inviwo::PoolProcessor:

Public Member Functions

bool delayDispatch () const
bool delayInvalidation () const
template<typename Job, typename Done>
void dispatchMany (std::vector< Job > jobs, Done &&done)
template<typename Job, typename Done>
void dispatchOne (Job &&job, Done &&done)
const std::optional< std::string > & error () const
pool::Options getOptions () const
virtual std::string handleError ()
bool hasJobs ()
virtual void invalidate (InvalidationLevel invalidationLevel, Property *source=nullptr) override
bool keepOldJobs () const
void newResults ()
void newResults (const std::vector< Outport * > &outports)
PoolProcessoroperator= (const PoolProcessor &)=delete
PoolProcessoroperator= (PoolProcessor &&)=delete
 PoolProcessor (const PoolProcessor &)=delete
 PoolProcessor (pool::Options options=pool::Options{flags::empty}, const std::string &identifier="", const std::string &displayName="")
 PoolProcessor (PoolProcessor &&)=delete
bool queuedDispatch () const
void stopJobs ()
Public Member Functions inherited from inviwo::Processor
virtual void accept (NetworkVisitor &visitor)
 Accept a NetworkVisitor, the visitor will visit this and then each Property of the Processor in an undefined order. The Visitor will then visit each Properties's properties and so on.
void addInteractionHandler (InteractionHandler *interactionHandler)
template<typename T, typename std::enable_if_t< std::is_base_of< Outport, T >::value, int > = 0>
T & addPort (std::unique_ptr< T > port, std::string_view portGroup="default")
template<typename T, typename std::enable_if_t< std::is_base_of< Inport, T >::value, int > = 0>
T & addPort (std::unique_ptr< T > port, std::string_view portGroup="default")
template<typename T>
T & addPort (T &port, std::string_view portGroup="default")
template<typename... Ts>
void addPorts (Ts &... ports)
bool allInportsAreReady () const
bool allInportsConnected () const
virtual void deserialize (Deserializer &d) override
virtual void doIfNotReady ()
const std::string & getCategory () const
const std::string & getClassIdentifier () const
CodeState getCodeState () const
const std::string & getDisplayName () const
virtual const std::string & getIdentifier () const override
InportgetInport (std::string_view identifier) const
const std::vector< Inport * > & getInports () const
const std::vector< InteractionHandler * > & getInteractionHandlers () const
virtual InviwoApplicationgetInviwoApplication () override
ProcessorNetworkgetNetwork () const
OutportgetOutport (std::string_view identifier) const
const std::vector< Outport * > & getOutports () const
virtual const PropertyOwner * getOwner () const override
virtual PropertyOwner * getOwner () override
PortgetPort (std::string_view identifier) const
const std::string & getPortGroup (Port *port) const
std::vector< std::string > getPortGroups () const
const std::vector< Port * > & getPortsInGroup (std::string_view portGroup) const
const std::vector< Port * > & getPortsInSameGroup (Port *port) const
virtual const ProcessorgetProcessor () const override
virtual ProcessorgetProcessor () override
virtual const ProcessorInfogetProcessorInfo () const =0
ProcessorWidgetgetProcessorWidget () const
const TagsgetTags () const
bool hasInteractionHandler () const
bool hasProcessorWidget () const
virtual void initializeResources ()
virtual void invokeEvent (Event *event) override
virtual bool isConnectionActive (Inport *inport, Outport *outport) const
bool isReady () const
bool isSink () const
bool isSource () const
NameDispatcherHandle onDisplayNameChange (std::function< void(std::string_view, std::string_view)> callback)
NameDispatcherHandle onIdentifierChange (std::function< void(std::string_view, std::string_view)> callback)
virtual void process ()
 Processor (std::string_view identifier="", std::string_view displayName="")
virtual void propagateEvent (Event *event, Outport *source) override
void removeInteractionHandler (InteractionHandler *interactionHandler)
InportremovePort (Inport *port)
OutportremovePort (Outport *port)
PortremovePort (std::string_view identifier)
virtual void serialize (Serializer &s) const override
void setDisplayName (std::string_view displayName)
void setIdentifier (std::string_view identifier)
virtual void setNetwork (ProcessorNetwork *network)
virtual void setProcessorWidget (std::unique_ptr< ProcessorWidget > processorWidget)
virtual void setValid () override
const ProcessorStatusstatus () const
Public Member Functions inherited from inviwo::PropertyOwner
template<typename... Ts>
void addProperties (Ts &... properties)
void addProperty (Property &property)
void addProperty (Property *property, bool owner=true)
PropertyaddProperty (std::unique_ptr< Property > property)
iterator begin ()
const_iterator begin () const
const_iterator cbegin () const
const_iterator cend () const
virtual void clear ()
 Remove all properties; Owned properties will be deleted.
bool empty () const
iterator end ()
const_iterator end () const
const_iterator find (Property *property) const
const std::vector< CompositeProperty * > & getCompositeProperties () const
InvalidationLevel getInvalidationLevel () const
const std::vector< Property * > & getProperties () const
template<class T>
std::vector< T * > getPropertiesByType (bool recursiveSearch=false) const
std::vector< Property * > getPropertiesRecursive () const
std::vector< Property * > & getPropertiesRecursive (std::vector< Property * > &destination) const
template<std::derived_from< Property > T = Property>
T * getProperty (std::string_view identifier)
PropertygetPropertyByIdentifier (std::string_view identifier, bool recursiveSearch=false) const
PropertygetPropertyByPath (std::string_view path) const
void insertProperty (size_t index, Property &property)
 insert property property at position index If index is not valid, the property is appended.
virtual void insertProperty (size_t index, Property *property, bool owner=true)
 insert property property at position index If index is not valid, the property is appended.
PropertyinsertProperty (size_t index, std::unique_ptr< Property > property)
 insert property property at position index If index is not valid, the property is appended.
virtual bool isValid () const
virtual bool move (Property *property, size_t newIndex)
PropertyOwner & operator= (const PropertyOwner &that)=delete
Propertyoperator[] (size_t)
const Propertyoperator[] (size_t) const
virtual PropertyremoveProperty (iterator it)
PropertyremoveProperty (Property &property)
PropertyremoveProperty (Property *property)
PropertyremoveProperty (size_t index)
 remove property referred to by index
PropertyremoveProperty (std::string_view identifier)
virtual void resetAllProperties ()
virtual void setAllPropertiesCurrentStateAsDefault ()
size_t size () const
virtual ~PropertyOwner ()
 Removes all properties and notifies its observers of the removal.
Public Member Functions inherited from inviwo::PropertyOwnerObservable
void notifyObserversDidAddProperty (Property *property, size_t index)
void notifyObserversDidRemoveProperty (PropertyOwner *owner, Property *property, size_t index)
void notifyObserversWillAddProperty (PropertyOwner *owner, Property *property, size_t index)
void notifyObserversWillRemoveProperty (Property *property, size_t index)
Public Member Functions inherited from inviwo::Observable< PropertyOwnerObserver >
void addObserver (PropertyOwnerObserver *observer)
bool isObservedBy (PropertyOwnerObserver *observer) const
Observable< PropertyOwnerObserver > & operator= (const Observable< PropertyOwnerObserver > &other)
void removeObserver (PropertyOwnerObserver *observer)
virtual void startBlockingNotifications () override final
virtual void stopBlockingNotifications () override final
Public Member Functions inherited from inviwo::MetaDataOwner
void copyMetaDataFrom (const MetaDataOwner &src)
void copyMetaDataTo (MetaDataOwner &dst)
template<typename T>
requires std::derived_from<T, MetaData>
T * createMetaData (std::string_view key)
void deserialize (Deserializer &d)
template<typename T>
requires std::derived_from<T, MetaData>
T * getMetaData (std::string_view key)
template<typename T>
requires std::derived_from<T, MetaData>
const T * getMetaData (std::string_view key) const
template<typename T, typename U>
requires std::derived_from<T, MetaData> && Gettable<T, U>
getMetaData (std::string_view key, U val) const
MetaDataMapgetMetaDataMap ()
const MetaDataMapgetMetaDataMap () const
template<typename T>
requires std::derived_from<T, MetaData>
bool hasMetaData (std::string_view key) const
bool hasMetaData (std::string_view key) const
 MetaDataOwner (const MetaDataOwner &rhs)=default
 MetaDataOwner (MetaDataOwner &rhs)=default
MetaDataOwner & operator= (const MetaDataOwner &rhs)=default
MetaDataOwner & operator= (MetaDataOwner &)=default
void serialize (Serializer &s) const
template<typename T, typename U>
requires std::derived_from<T, MetaData> && Settable<T, U>
void setMetaData (std::string_view key, U value)
template<typename T>
requires std::derived_from<T, MetaData>
bool unsetMetaData (std::string_view key)
 unset, i.e. remove the metadata entry matching the given key and type
Public Member Functions inherited from inviwo::Observable< ProcessorObserver >
void addObserver (ProcessorObserver *observer)
bool isObservedBy (ProcessorObserver *observer) const
Observable< ProcessorObserver > & operator= (const Observable< ProcessorObserver > &other)
void removeObserver (ProcessorObserver *observer)
virtual void startBlockingNotifications () override final
virtual void stopBlockingNotifications () override final

Additional Inherited Members

Public Types inherited from inviwo::Processor
using NameDispatcher = Dispatcher<void(std::string_view, std::string_view)>
using NameDispatcherHandle = typename NameDispatcher::Handle
Public Types inherited from inviwo::PropertyOwner
using const_iterator = std::vector<Property*>::const_iterator
using iterator = std::vector<Property*>::iterator
Protected Member Functions inherited from inviwo::Processor
void addPortToGroup (Port *port, std::string_view portGroup)
void removePortFromGroups (Port *port)
void setInportsChanged (bool changed)
Protected Member Functions inherited from inviwo::PropertyOwner
void forEachProperty (std::function< void(Property &)> callback, bool recursiveSearch=false) const
PropertyOwner & operator= (PropertyOwner &&that)
 PropertyOwner (const PropertyOwner &rhs)
 PropertyOwner (PropertyOwner &&rhs)
Protected Member Functions inherited from inviwo::Observable< PropertyOwnerObserver >
void forEachObserver (C callback)
Protected Member Functions inherited from inviwo::ObservableInterface
void addObservationHelper (Observer *observer)
virtual void addObserver (Observer *observer)=0
void removeObservationHelper (Observer *observer)
virtual void removeObserver (Observer *observer)=0
Protected Member Functions inherited from inviwo::ProcessorObservable
void notifyObserversAboutPropertyChange (Property *p)
void notifyObserversAboutToProcess (Processor *p)
void notifyObserversActiveConnectionsChange (Processor *p)
void notifyObserversFinishBackgroundWork (Processor *p, size_t jobs=1)
void notifyObserversFinishedProcess (Processor *p)
void notifyObserversInvalidationBegin (Processor *p)
void notifyObserversInvalidationEnd (Processor *p)
void notifyObserversProcessorPortAdded (Processor *p, Port *port)
void notifyObserversProcessorPortRemoved (Processor *p, Port *port)
void notifyObserversProgressChanged (Processor *p, std::optional< double > progress)
void notifyObserversReadyChange (Processor *p)
void notifyObserversSinkChange (Processor *p)
void notifyObserversSourceChange (Processor *p)
void notifyObserversStartBackgroundWork (Processor *p, size_t jobs=1)
Protected Member Functions inherited from inviwo::Observable< ProcessorObserver >
void forEachObserver (C callback)
Static Protected Member Functions inherited from inviwo::Processor
static std::function< ProcessorStatus()> getDefaultIsReadyUpdater (Processor *)
Protected Attributes inherited from inviwo::Processor
StateCoordinator< ProcessorStatusisReady_
StateCoordinator< bool > isSink_
StateCoordinator< bool > isSource_
std::unique_ptr< ProcessorWidgetprocessorWidget_
Protected Attributes inherited from inviwo::PropertyOwner
std::vector< CompositeProperty * > compositeProperties_
std::vector< EventProperty * > eventProperties_
std::vector< std::unique_ptr< Property > > ownedProperties_
std::vector< Property * > properties_
Protected Attributes inherited from inviwo::MetaDataOwner
MetaDataMap metaData_
Protected Attributes inherited from inviwo::ProcessorObservable
friend ProcessorNetworkEvaluator
friend Property

Detailed Description

PoolProcessor is a base class to help make processors that dispatch work to the thread pool.

Constructor & Destructor Documentation

◆ PoolProcessor()

inviwo::PoolProcessor::PoolProcessor ( pool::Options options = pool::Options{flags::empty},
const std::string & identifier = "",
const std::string & displayName = "" )

Construct the pool processor with given options.

See also
pool::Option

Member Function Documentation

◆ delayDispatch()

bool inviwo::PoolProcessor::delayDispatch ( ) const
inline

◆ delayInvalidation()

bool inviwo::PoolProcessor::delayInvalidation ( ) const
inline

◆ dispatchMany()

template<typename Job, typename Done>
void inviwo::PoolProcessor::dispatchMany ( std::vector< Job > jobs,
Done && done )

Dispatch a vector of background jobs. The jobs will be executed in a background thread in the thread pool. It is important that the jobs captures its state by value, since it might outlive the processor. The jobs can take two optional parameters

  • pool::Stop a stop token to periodically check if the job has been canceled.
  • pool::Progress a callback to report progress of the calculation. The progress is represented as a float in the interval [0.0, 1.0]. The progress is automatically normalized across all the jobs If the jobs takes a progress callback the processor will show a progress bar. The progress from all the jobs will automatically be merged and normalized

The second functor 'done' is called with the results when the background jobs are finished. It will be executed on the main thread, and only if the processor is still valid and the jobs have not been stopped. Hence it is safe to refer to the processor in this functor.

std::vector<std::function<std::shared_ptr<Mesh>(pool::Stop, pool::Progress progress)>> jobs;
for (...) {
jobs.push_back([some state](pool::Stop stop, pool::Progress progress) {
if (stop) return nullptr;
// construct some new Mesh
progress(0.5f);
return newMesh;
});
}
dispatchMany(jobs, [this](std::vector<std::shared_ptr<Mesh>> results) {
outport_.setData(std::make_shared<std::vector<std::shared_ptr<Mesh>>>(results));
});
void dispatchMany(std::vector< Job > jobs, Done &&done)
Definition poolprocessor.h:447
Definition poolprocessor.h:104
Definition poolprocessor.h:77

◆ dispatchOne()

template<typename Job, typename Done>
void inviwo::PoolProcessor::dispatchOne ( Job && job,
Done && done )

Dispatch a single background job. The job will be executed in a background thread in the thread pool. It is important that the job captures its state by value, since it might outlive the processor. The job can take two optional parameters

  • pool::Stop a stop token to periodically check if the job has been canceled.
  • pool::Progress a callback to report progress of the calculation. The progress is represented as a float in the interval [0.0, 1.0]. If the job takes a progress callback the processor will show a progress bar. The second functor done is called with the result when the background job is finished. It will be executed on the main thread, and only if the processor is still valid and the job has not been stopped. Hence it is safe to refer to the processor in this functor.
const auto calc = [image = inport_.getData()]
( pool::Stop stop, pool::Progress progress) -> std::shared_ptr<const Image> {
if (stop) return nullptr;
auto newImage = std::shared_ptr<Image>(image->clone());
progress(0.5f);
// Do some work with the image
return newImage;
};
dispatchOne(calc, [this](std::shared_ptr<const Image> result) {
outport_.setData(result);
newResults(); // Let the network know that the processor has new results on the
// outport.
});
void dispatchOne(Job &&job, Done &&done)
Definition poolprocessor.h:499

◆ error()

const std::optional< std::string > & inviwo::PoolProcessor::error ( ) const
Returns
the last error return by handleError if any. The error is clear at any invalidation.

◆ getOptions()

pool::Options inviwo::PoolProcessor::getOptions ( ) const
inline

Get the current Options

See also
pool::Option

◆ handleError()

virtual std::string inviwo::PoolProcessor::handleError ( )
virtual

handleError is called on the main thread whenever there has be an error in a background calculation this will by default just log the error message, and clear any outports. Deriving classes can overload this and rethrow the caught exception to enable custom error handling if needed.

◆ hasJobs()

bool inviwo::PoolProcessor::hasJobs ( )

Are there any ongoing background jobs

◆ invalidate()

virtual void inviwo::PoolProcessor::invalidate ( InvalidationLevel invalidationLevel,
Property * source = nullptr )
overridevirtual

Overrides Processor::invalidate to customize the invalidation behavior We generally only want to invalidate the dependent processor when we put data on our outports.

Reimplemented from inviwo::Processor.

◆ keepOldJobs()

bool inviwo::PoolProcessor::keepOldJobs ( ) const
inline

◆ newResults() [1/2]

void inviwo::PoolProcessor::newResults ( )

Call newResults to let the network know we have new data on our outports.

◆ newResults() [2/2]

void inviwo::PoolProcessor::newResults ( const std::vector< Outport * > & outports)

Call newResults to let the network know we have new data on our outports. Only invalidate the specified outports. Use this if you only set data to a subset of the outports.

◆ queuedDispatch()

bool inviwo::PoolProcessor::queuedDispatch ( ) const
inline

◆ stopJobs()

void inviwo::PoolProcessor::stopJobs ( )

Cancel all current jobs


The documentation for this class was generated from the following file:
  • include/inviwo/core/processors/poolprocessor.h