SOFA API  3944ba52
Open source framework for multi-physics simuation
sofa::core::DataTrackerEngine Class Reference

#include <DataTracker.h>

Inheritance diagram for sofa::core::DataTrackerEngine:

Detailed Description

a DDGNode that automatically triggers its update function when asking for an output and any input changed. Similar behavior than a DataEngine, but this is NOT a component and can be used everywhere.

Note that it contains a DataTrackerDDGNode (m_dataTracker) to be able to check precisly which input changed if needed.

**** Implementation good rules: (similar to DataEngine)

//init addInput // indicate all inputs addOutput // indicate all outputs setDirtyValue(); // the engine must start dirty (of course, no output are up-to-date)

void UpdateCallback( DataTrackerEngine* dataTrackerEngine ) { // get the list of inputs for this DDGNode const core::DataTrackerEngine::DDGLinkContainer& inputs = dataTrackerEngine->getInputs(); // get the list of outputs for this DDGNode const core::DataTrackerEngine::DDGLinkContainer& outputs = dataTrackerEngine->getOutputs();

// we known who is who from the order Data were added to the DataTrackerEngine static_cast<Data< FirstInputType >*>( inputs[0] );

// all inputs must be updated // can be done by Data::getValue, ReadAccessor, Data::updateIfDirty, DataTrackerDDGNode::updateAllInputsIfDirty

// must be called AFTER updating all inputs, otherwise a modified input will set the engine to dirty again. // must be called BEFORE read access to an output, otherwise read-accessing the output will call update dataTrackerEngine->cleanDirty();

// FINALLY access and set outputs // Note that a write-only access has better performance and is enough in 99% engines Data::beginWriteOnly, WriteOnlyAccessor // A read access is possible, in that case, be careful the cleanDirty is called before the read-access }

Protected Attributes

std::vector< std::function< void(DataTrackerEngine *)> > m_callbacks
- Protected Attributes inherited from sofa::core::DataTrackerDDGNode
DataTracker m_dataTracker
- Protected Attributes inherited from sofa::core::objectmodel::DDGNode
DDGLinkContainer inputs
DDGLinkContainer outputs

Public Member Functions

void addCallback (std::function< void(DataTrackerEngine *)> f)
void update () override
 Calls the callback when one of the data has changed. More...
- Public Member Functions inherited from sofa::core::DataTrackerDDGNode
 DataTrackerDDGNode ()
void addInputs (std::initializer_list< sofa::core::objectmodel::BaseData * > datas)
 Create a DataCallback object associated with multiple Data. More...
void addOutputs (std::initializer_list< sofa::core::objectmodel::BaseData * > datas)
virtual void cleanDirty (const core::ExecParams *params=nullptr)
void updateAllInputsIfDirty ()
- Public Member Functions inherited from sofa::core::objectmodel::DDGNode
 DDGNode ()
 Constructor. More...
virtual ~DDGNode ()
 Destructor. Automatically remove remaining links. More...
void addInput (DDGNode *n)
 Add a new input to this node. More...
void delInput (DDGNode *n)
 Remove an input from this node. More...
void addOutput (DDGNode *n)
 Add a new output to this node. More...
void delOutput (DDGNode *n)
 Remove an output from this node. More...
const DDGLinkContainergetInputs ()
 Get the list of inputs for this DDGNode. More...
const DDGLinkContainergetOutputs ()
 Get the list of outputs for this DDGNode. More...
bool isDirty (const core::ExecParams *) const
 Returns true if the DDGNode needs to be updated. More...
bool isDirty () const
virtual void setDirtyValue (const core::ExecParams *) final
 Indicate the value needs to be updated. More...
virtual void setDirtyValue ()
virtual void setDirtyOutputs (const core::ExecParams *) final
 Indicate the outputs needs to be updated. This method must be called after changing the value of this node. More...
virtual void setDirtyOutputs ()
void cleanDirty (const core::ExecParams *)
 Set dirty flag to false. More...
void cleanDirty ()
virtual void notifyEndEdit (const core::ExecParams *) final
 Notify links that the DGNode has been modified. More...
virtual void notifyEndEdit ()
void updateIfDirty (const core::ExecParams *) const
 Utility method to call update if necessary. This method should be called before reading of writing the value of this node. More...
void updateIfDirty () const

Additional Inherited Members

- Protected Member Functions inherited from sofa::core::objectmodel::DDGNode
virtual void doAddInput (DDGNode *n)
virtual void doDelInput (DDGNode *n)
virtual void doAddOutput (DDGNode *n)
virtual void doDelOutput (DDGNode *n)
void cleanDirtyOutputsOfInputs (const core::ExecParams *)
 the dirtyOutputs flags of all the inputs will be set to false More...
void cleanDirtyOutputsOfInputs ()

Attribute details

std::vector<std::function<void(DataTrackerEngine*)> > sofa::core::DataTrackerEngine::m_callbacks

Function details

void sofa::core::DataTrackerEngine::addCallback ( std::function< void(DataTrackerEngine *)>  f)

set the update function to call when asking for an output and any input changed.

void sofa::core::DataTrackerEngine::update ( )

Calls the callback when one of the data has changed.

Implements sofa::core::objectmodel::DDGNode.