Back

Data

The `Data` component in the SOFA framework is a fundamental template class used to encapsulate member variables for Sofa components, allowing dynamic and generic access at runtime. It serves as a container that holds variable values and provides mechanisms for setting, getting, and updating these values dynamically through their names. In the context of XML scene files, each `Data` declared in a component corresponds to an attribute of this component. This means users can assign or retrieve parameter values directly from these attributes. The `Data` class interacts with other components by providing methods for setting and getting its value (`setValue`, `getValue`), allowing it to integrate seamlessly into Sofa's data-driven simulation framework. It also supports operations like reading values from strings, printing values as strings, and determining the type information of the associated variable. Practically, users should declare a `Data` instance for each member variable they wish to dynamically access or modify within their components. Initialization is done through constructors using `Base::initData()` to provide default values and descriptions. Users can assign these Data values in XML scene files directly.

abstract
The `Data` component encapsulates member variables in Sofa components, enabling dynamic access at runtime via their names and facilitating easy configuration through XML scene files.
sheet
# Data ## Overview The `Data` component is a fundamental template class that encapsulates member variables within Sofa components. It allows for dynamic access to these variables at runtime, making it easier to manage and manipulate simulation parameters interactively or programmatically. Each `Data` instance corresponds to an attribute in XML scene files, enabling users to assign or retrieve parameter values directly. ## Parameters and Data The `Data` class provides methods for setting and getting its value (`setValue`, `getValue`). It also supports operations like reading values from strings (`read(const std::string& str)`), printing values as strings (`printValue()`), and determining the type information of the associated variable (`getTypeName()`). ## Practical Notes Users should declare a `Data` instance for each member variable they wish to dynamically access or modify within their components. Initialization is done through constructors using `Base::initData()` to provide default values and descriptions. Example usage in XML scene files: ```xml <Node> <Component enabled="true"/> </Node> ``` In code, the value can be accessed and modified as follows: ```cpp bool currentValue = d_enabled.getValue(); d_enabled.setValue(true); ```
description
The `Data` component in the SOFA framework is a fundamental template class used to encapsulate member variables for Sofa components, allowing dynamic and generic access at runtime. It serves as a container that holds variable values and provides mechanisms for setting, getting, and updating these values dynamically through their names. In the context of XML scene files, each `Data` declared in a component corresponds to an attribute of this component. This means users can assign or retrieve parameter values directly from these attributes. The `Data` class interacts with other components by providing methods for setting and getting its value (`setValue`, `getValue`), allowing it to integrate seamlessly into Sofa's data-driven simulation framework. It also supports operations like reading values from strings, printing values as strings, and determining the type information of the associated variable. Practically, users should declare a `Data` instance for each member variable they wish to dynamically access or modify within their components. Initialization is done through constructors using `Base::initData()` to provide default values and descriptions. Users can assign these Data values in XML scene files directly.
maths
# Mathematical and Physical Description of the `Data` Component in SOFA Framework ## Introduction The `Data` component in the SOFA (Simulation Open-Framework Architecture) framework serves as a fundamental template class that encapsulates member variables within Sofa components. This allows for dynamic access to these variables at runtime, making it easier to manage and manipulate simulation parameters interactively or programmatically. ## Purpose - **Dynamic Access**: The primary purpose of `Data` is to provide mechanisms for setting, getting, and updating variable values dynamically through their names. - **Interoperability with XML Scene Files**: Each `Data` instance can be represented as an attribute in XML scene files. This allows users to assign or retrieve parameter values directly from these attributes, facilitating easy configuration of simulations. ## Key Methods and Attributes ### Initialization Each `Data` instance is initialized using constructors that accept default values and descriptions. This initialization is typically performed through methods like `Base::initData()`, which ensures the component's variables can be accessed dynamically: ```cpp Data<T> d(..., "description"); ``` ### Setting and Getting Values - **`setValue()`**: Allows setting a new value for the encapsulated variable. - **`getValue()`**: Retrieves the current value of the encapsulated variable. ### Reading and Writing Values from Strings - **`read(const std::string& str)`**: Parses a string to set the internal value. This method supports various input formats, including boolean values ('T', 'F'), integers, etc. ```cpp Data<bool>::read("true"); // sets value to true ``` - **`printValue()`**: Converts the current value into a human-readable string format for output purposes. ### Type Information The `Data` class supports determining type information about its associated variable, which can be useful for debugging or logging purposes: ```cpp const char* typeName = Data<T>::getTypeName(); ``` ## Interaction with Other Components - **Integrating into Sofa's Simulation Framework**: The `Data` component interacts seamlessly with other parts of the Sofa framework. For example, engines (computational components) can use `Data` instances to exchange information dynamically during a simulation. - **Dynamic Updates**: When using `WriteAccessor`, the data is automatically updated before it becomes accessible, ensuring that the latest values are used in computations. However, for write-only access, `WriteOnlyAccessor` avoids unnecessary updates by not triggering engine updates. ## Practical Usage 1. **Declaration and Initialization**: ```cpp Data<bool> d_enabled(initData(&d_enabled, false, "enabled", "Enable this component")); ``` 2. **Assigning Values via XML Scene Files**: ```xml <Node> <Component enabled="true"/> </Node> ``` 3. **Access and Modify in Code**: ```cpp d_enabled.setValue(true); bool currentValue = d_enabled.getValue(); ``` ## Conclusion The `Data` component plays a crucial role in SOFA by providing dynamic access to member variables of components, facilitating easy configuration via XML scene files and seamless integration with the simulation framework. This makes it an essential tool for creating flexible and interactive simulations.
{
  "name": "Data",
  "main": {
    "name": "Data",
    "namespace": "sofa::core::objectmodel",
    "module": "Sofa.framework.Core",
    "include": "sofa/core/objectmodel/Data.h",
    "doc": "Container that holds a variable for a component.\nThis is a fundamental class template in Sofa.  Data are used to encapsulated\nmember variables of Sofa components (i.e. classes that somehow inherit from\nBase) in order to access them dynamically and generically: briefly, Data can\nbe retrieved at run-time by their name, and they can be assigned a value from\na string, or be printed as a string.\nMore concretely, from the perspective of XML scene files, each Data declared\nin a component corresponds to an attribute of this component.\n<h4> Example </h4>\nIf a component \\c Foo has a boolean parameter \\c bar, it does not simply declares it\nas <tt>bool m_bar</tt>, but rather like this:\n\\code{.cpp}\n Data<bool> d_bar;\n\\endcode\nThen, this %Data must be initialized to provide its name and default value.\nThis is typically done in the initialization list of \\b each constructor of\nthe component, using the helper function Base::initData():\n\\code{.cpp}\nFoo::Foo(): d_bar(initData(&d_bar, true, \"bar\", \"Here is a little description of this Data.\")) {\n    // ...\n}\n\\endcode\nAnd this %Data can be assigned a value in XML scene files like so:\n\\code{.xml}\n<Foo bar=\"false\"/>\n\\endcode",
    "inherits": [
      "BaseData"
    ],
    "templates": [
      "bool"
    ],
    "data_fields": [],
    "links": [],
    "methods": [
      {
        "name": "templateName",
        "return_type": "int",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": true,
        "access": "public"
      },
      {
        "name": "getNewInstance",
        "return_type": "BaseData *",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "beginEdit",
        "return_type": "T *",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "beginWriteOnly",
        "return_type": "T *",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "endEdit",
        "return_type": "void",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "setValue",
        "return_type": "void",
        "params": [
          {
            "name": "value",
            "type": "const T &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "getValue",
        "return_type": "const T &",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "getValueTypeInfo",
        "return_type": "const sofa::defaulttype::AbstractTypeInfo *",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "read",
        "return_type": "bool",
        "params": [
          {
            "name": "s",
            "type": "const int &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "printValue",
        "return_type": "void",
        "params": [
          {
            "name": "out",
            "type": "int &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "getValueString",
        "return_type": "int",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "getDefaultValueString",
        "return_type": "int",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "getValueTypeString",
        "return_type": "int",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "operator=",
        "return_type": "void",
        "params": [
          {
            "name": "value",
            "type": "const T &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "copyValueFrom",
        "return_type": "bool",
        "params": [
          {
            "name": "data",
            "type": "const Data<T> *"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "isCopyOnWrite",
        "return_type": "bool",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": true,
        "access": "public"
      },
      {
        "name": "operator=",
        "return_type": "Data<DataTypes> &",
        "params": [
          {
            "name": "",
            "type": "const Data<DataTypes> &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "readValue",
        "return_type": "int &",
        "params": [
          {
            "name": "in",
            "type": "int &"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      }
    ]
  },
  "desc": {
    "description": "The `Data` component in the SOFA framework is a fundamental template class used to encapsulate member variables for Sofa components, allowing dynamic and generic access at runtime. It serves as a container that holds variable values and provides mechanisms for setting, getting, and updating these values dynamically through their names.\n\nIn the context of XML scene files, each `Data` declared in a component corresponds to an attribute of this component. This means users can assign or retrieve parameter values directly from these attributes.\n\nThe `Data` class interacts with other components by providing methods for setting and getting its value (`setValue`, `getValue`), allowing it to integrate seamlessly into Sofa's data-driven simulation framework. It also supports operations like reading values from strings, printing values as strings, and determining the type information of the associated variable.\n\nPractically, users should declare a `Data` instance for each member variable they wish to dynamically access or modify within their components. Initialization is done through constructors using `Base::initData()` to provide default values and descriptions. Users can assign these Data values in XML scene files directly."
  },
  "maths": {
    "maths": "# Mathematical and Physical Description of the `Data` Component in SOFA Framework\n\n## Introduction\nThe `Data` component in the SOFA (Simulation Open-Framework Architecture) framework serves as a fundamental template class that encapsulates member variables within Sofa components. This allows for dynamic access to these variables at runtime, making it easier to manage and manipulate simulation parameters interactively or programmatically.\n\n## Purpose\n- **Dynamic Access**: The primary purpose of `Data` is to provide mechanisms for setting, getting, and updating variable values dynamically through their names.\n- **Interoperability with XML Scene Files**: Each `Data` instance can be represented as an attribute in XML scene files. This allows users to assign or retrieve parameter values directly from these attributes, facilitating easy configuration of simulations.\n\n## Key Methods and Attributes\n### Initialization\nEach `Data` instance is initialized using constructors that accept default values and descriptions. This initialization is typically performed through methods like `Base::initData()`, which ensures the component's variables can be accessed dynamically:\n```cpp\nData<T> d(..., \"description\");\n```\n\n### Setting and Getting Values\n- **`setValue()`**: Allows setting a new value for the encapsulated variable.\n- **`getValue()`**: Retrieves the current value of the encapsulated variable.\n\n### Reading and Writing Values from Strings\n- **`read(const std::string& str)`**: Parses a string to set the internal value. This method supports various input formats, including boolean values ('T', 'F'), integers, etc.\n    ```cpp\n    Data<bool>::read(\"true\"); // sets value to true\n    ```\n- **`printValue()`**: Converts the current value into a human-readable string format for output purposes.\n\n### Type Information\nThe `Data` class supports determining type information about its associated variable, which can be useful for debugging or logging purposes:\n```cpp\nconst char* typeName = Data<T>::getTypeName();\n```\n\n## Interaction with Other Components\n- **Integrating into Sofa's Simulation Framework**: The `Data` component interacts seamlessly with other parts of the Sofa framework. For example, engines (computational components) can use `Data` instances to exchange information dynamically during a simulation.\n- **Dynamic Updates**: When using `WriteAccessor`, the data is automatically updated before it becomes accessible, ensuring that the latest values are used in computations. However, for write-only access, `WriteOnlyAccessor` avoids unnecessary updates by not triggering engine updates.\n\n## Practical Usage\n1. **Declaration and Initialization**:\n    ```cpp\n    Data<bool> d_enabled(initData(&d_enabled, false, \"enabled\", \"Enable this component\"));\n    ```\n2. **Assigning Values via XML Scene Files**:\n    ```xml\n    <Node>\n        <Component enabled=\"true\"/>\n    </Node>\n    ```\n3. **Access and Modify in Code**:\n    ```cpp\n    d_enabled.setValue(true);\n    bool currentValue = d_enabled.getValue();\n    ```\n\n## Conclusion\nThe `Data` component plays a crucial role in SOFA by providing dynamic access to member variables of components, facilitating easy configuration via XML scene files and seamless integration with the simulation framework. This makes it an essential tool for creating flexible and interactive simulations."
  },
  "summary": {
    "abstract": "The `Data` component encapsulates member variables in Sofa components, enabling dynamic access at runtime via their names and facilitating easy configuration through XML scene files.",
    "sheet": "# Data\n\n## Overview\nThe `Data` component is a fundamental template class that encapsulates member variables within Sofa components. It allows for dynamic access to these variables at runtime, making it easier to manage and manipulate simulation parameters interactively or programmatically. Each `Data` instance corresponds to an attribute in XML scene files, enabling users to assign or retrieve parameter values directly.\n\n## Parameters and Data\nThe `Data` class provides methods for setting and getting its value (`setValue`, `getValue`). It also supports operations like reading values from strings (`read(const std::string& str)`), printing values as strings (`printValue()`), and determining the type information of the associated variable (`getTypeName()`).\n\n## Practical Notes\nUsers should declare a `Data` instance for each member variable they wish to dynamically access or modify within their components. Initialization is done through constructors using `Base::initData()` to provide default values and descriptions.\n\nExample usage in XML scene files:\n```xml\n<Node>\n    <Component enabled=\"true\"/>\n</Node>\n```\nIn code, the value can be accessed and modified as follows:\n```cpp\nbool currentValue = d_enabled.getValue();\nd_enabled.setValue(true);\n```"
  }
}