DataCallback
The `DataCallback` component in SOFA is designed to associate callbacks with sets of data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses and interactions within simulations based on data modifications. **Role and Purpose**: The primary role of `DataCallback` is to enable reactive behavior in a simulation environment by tying specific actions (callbacks) to changes in certain data values. It serves as an intermediary, facilitating the execution of user-defined functions when relevant inputs are updated. **Interactions with Other Components**: `DataCallback` interacts closely with other SOFA components through its dependency on `DDGNode`. Specifically, it overrides the `notifyEndEdit()` and `update()` methods from this base class to manage callback executions. It also works with `BaseData` objects, which represent the data fields that can trigger these callbacks. **Practical Usage Guidance**: To use `DataCallback`, one must first create a set of input data (e.g., `Data<int>`) and register them using the `addInputs()` method. Callback functions are then added via `addCallback()`. When any registered input is modified, the associated callbacks are executed. **Data Fields**: The primary internal state includes a boolean flag `m_updating` to prevent circular dependencies and a vector of callback functions `m_callbacks`, which store the user-defined actions to be triggered.
- abstract
- `DataCallback` associates callbacks with sets of input data in SOFA simulations, triggering user-defined actions when these inputs change.
- sheet
- # DataCallback **Overview** The `DataCallback` component is designed to associate callbacks with sets of input data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses and interactions within simulations based on data modifications. **Parameters and Data** - **m_updating**: A boolean flag that prevents circular dependencies during updates. - **m_callbacks**: A vector of callback functions that store user-defined actions to be executed when associated inputs are modified. **Dependencies and Connections** `DataCallback` inherits from `DDGNode`, allowing it to integrate with SOFA's dependency graph and execution framework. It overrides the `notifyEndEdit()` and `update()` methods for managing callback executions. The component works closely with `BaseData` objects, which represent the data fields that can trigger these callbacks. **Practical Notes** To use `DataCallback`, one must first create a set of input data (e.g., `Data<int>`) and register them using the `addInputs()` method. Callback functions are then added via `addCallback()`. When any registered input is modified, the associated callbacks are executed.
- description
- The `DataCallback` component in SOFA is designed to associate callbacks with sets of data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses and interactions within simulations based on data modifications. **Role and Purpose**: The primary role of `DataCallback` is to enable reactive behavior in a simulation environment by tying specific actions (callbacks) to changes in certain data values. It serves as an intermediary, facilitating the execution of user-defined functions when relevant inputs are updated. **Interactions with Other Components**: `DataCallback` interacts closely with other SOFA components through its dependency on `DDGNode`. Specifically, it overrides the `notifyEndEdit()` and `update()` methods from this base class to manage callback executions. It also works with `BaseData` objects, which represent the data fields that can trigger these callbacks. **Practical Usage Guidance**: To use `DataCallback`, one must first create a set of input data (e.g., `Data<int>`) and register them using the `addInputs()` method. Callback functions are then added via `addCallback()`. When any registered input is modified, the associated callbacks are executed. **Data Fields**: The primary internal state includes a boolean flag `m_updating` to prevent circular dependencies and a vector of callback functions `m_callbacks`, which store the user-defined actions to be triggered.
- maths
- The `DataCallback` component in SOFA does not directly involve mathematical or physical concepts related to the simulation itself. Instead, it serves as a reactive mechanism within the framework to trigger user-defined actions (callbacks) when specific data fields are modified. **Mathematical and Physical Description:** - **Role**: The `DataCallback` component is designed to associate callbacks with sets of input data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses within simulations based on data modifications. - **Internal Mechanism**: - The component maintains a list of callback functions (`m_callbacks`) and a boolean flag `m_updating` to prevent circular dependencies. - When an associated input is modified, the `notifyEndEdit()` method is called, which in turn triggers all registered callbacks if no update is currently ongoing. - **Dependency on DDGNode**: - The `DataCallback` class inherits from `DDGNode`, allowing it to integrate with SOFA's dependency graph and execution framework. It overrides the `notifyEndEdit()` and `update()` methods for managing callback executions. - **Usage**: To use `DataCallback`, one must create a set of input data fields (e.g., `BaseData*`), register them using `addInputs()`, and add user-defined callback functions via `addCallback()`. When any registered input is modified, the associated callbacks are executed. In summary, while `DataCallback` does not directly involve mathematical or physical computations, it provides a crucial mechanism for dynamic behavior in simulations based on data changes.
{
"name": "DataCallback",
"main": {
"name": "DataCallback",
"namespace": "sofa::core::objectmodel::_datacallback_",
"module": "Sofa.framework.Core",
"include": "sofa/core/objectmodel/DataCallback.h",
"doc": "Associate to a set of data a set of callback\nThe callbacks are called when one of the input is changed.\nExample of use:\n Data<int> a;\n Data<int> b;\n DataCallback cb;\n In constructor:\n cb.addCallback([&a,&b](DataCallback*){\n std::cout << \"sum is:\" << a.getValue()+b.getValue() << std::endl;\n });\n cb.addInputs({&a,&b}); or cb.addInput(&a); cb.addInput(&b);\n a.setValue(5); /// should print: \"sum is 5\"\n b.setValue(6); /// should print: \"sum is 11\"",
"inherits": [
"DDGNode"
],
"templates": [],
"data_fields": [],
"links": [],
"methods": [
{
"name": "addInputs",
"return_type": "void",
"params": [
{
"name": "datas",
"type": "int"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addCallback",
"return_type": "void",
"params": [
{
"name": "",
"type": "int"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "notifyEndEdit",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "update",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
}
]
},
"desc": {
"description": "The `DataCallback` component in SOFA is designed to associate callbacks with sets of data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses and interactions within simulations based on data modifications.\n\n**Role and Purpose**: The primary role of `DataCallback` is to enable reactive behavior in a simulation environment by tying specific actions (callbacks) to changes in certain data values. It serves as an intermediary, facilitating the execution of user-defined functions when relevant inputs are updated.\n\n**Interactions with Other Components**: `DataCallback` interacts closely with other SOFA components through its dependency on `DDGNode`. Specifically, it overrides the `notifyEndEdit()` and `update()` methods from this base class to manage callback executions. It also works with `BaseData` objects, which represent the data fields that can trigger these callbacks.\n\n**Practical Usage Guidance**: To use `DataCallback`, one must first create a set of input data (e.g., `Data<int>`) and register them using the `addInputs()` method. Callback functions are then added via `addCallback()`. When any registered input is modified, the associated callbacks are executed.\n\n**Data Fields**: The primary internal state includes a boolean flag `m_updating` to prevent circular dependencies and a vector of callback functions `m_callbacks`, which store the user-defined actions to be triggered."
},
"maths": {
"maths": "The `DataCallback` component in SOFA does not directly involve mathematical or physical concepts related to the simulation itself. Instead, it serves as a reactive mechanism within the framework to trigger user-defined actions (callbacks) when specific data fields are modified.\n\n**Mathematical and Physical Description:**\n- **Role**: The `DataCallback` component is designed to associate callbacks with sets of input data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses within simulations based on data modifications.\n\n- **Internal Mechanism**:\n - The component maintains a list of callback functions (`m_callbacks`) and a boolean flag `m_updating` to prevent circular dependencies.\n - When an associated input is modified, the `notifyEndEdit()` method is called, which in turn triggers all registered callbacks if no update is currently ongoing.\n\n- **Dependency on DDGNode**:\n - The `DataCallback` class inherits from `DDGNode`, allowing it to integrate with SOFA's dependency graph and execution framework. It overrides the `notifyEndEdit()` and `update()` methods for managing callback executions.\n\n- **Usage**: To use `DataCallback`, one must create a set of input data fields (e.g., `BaseData*`), register them using `addInputs()`, and add user-defined callback functions via `addCallback()`. When any registered input is modified, the associated callbacks are executed.\n\nIn summary, while `DataCallback` does not directly involve mathematical or physical computations, it provides a crucial mechanism for dynamic behavior in simulations based on data changes."
},
"summary": {
"abstract": "`DataCallback` associates callbacks with sets of input data in SOFA simulations, triggering user-defined actions when these inputs change.",
"sheet": "# DataCallback\n\n**Overview**\n\nThe `DataCallback` component is designed to associate callbacks with sets of input data. When any associated input data changes, the registered callback functions are triggered. This mechanism allows for dynamic responses and interactions within simulations based on data modifications.\n\n**Parameters and Data**\n\n- **m_updating**: A boolean flag that prevents circular dependencies during updates.\n- **m_callbacks**: A vector of callback functions that store user-defined actions to be executed when associated inputs are modified.\n\n**Dependencies and Connections**\n\n`DataCallback` inherits from `DDGNode`, allowing it to integrate with SOFA's dependency graph and execution framework. It overrides the `notifyEndEdit()` and `update()` methods for managing callback executions. The component works closely with `BaseData` objects, which represent the data fields that can trigger these callbacks.\n\n**Practical Notes**\n\nTo use `DataCallback`, one must first create a set of input data (e.g., `Data<int>`) and register them using the `addInputs()` method. Callback functions are then added via `addCallback()`. When any registered input is modified, the associated callbacks are executed."
}
}