BaseObject
The BaseObject is the fundamental class from which most Sofa components inherit. It serves as the base for all physical objects, engines, and other system elements in Sofa. This class provides essential functionalities such as event handling, data tracking, initialization, and cleanup operations.
- abstract
- BaseObject serves as the foundational class for all simulation components in SOFA, providing essential functionalities such as event handling, data tracking, initialization, and cleanup operations.
- sheet
- # BaseObject ## Overview BaseObject is a fundamental class from which most Sofa components inherit. It provides essential functionalities such as event handling, data tracking, initialization, and cleanup operations. ## Parameters and Data - **f_listening**: `bool` (default: false) - Determines whether the object handles events or ignores them. ## Dependencies and Connections BaseObject typically requires a context (`BaseContext`) to resolve dependencies and validate links between objects. It can also have slave objects, which are managed through methods like `addSlave`, `removeSlave`, and `getSlaves`.
- name
- BaseObject
- description
- The BaseObject is the fundamental class from which most Sofa components inherit. It serves as the base for all physical objects, engines, and other system elements in Sofa. This class provides essential functionalities such as event handling, data tracking, initialization, and cleanup operations.
- attributes
-
- {'name': 'context', 'type': 'BaseContext*', 'description': 'The Graph Node containing this object or BaseContext::getDefault() if no graph is used.'}
- {'name': 'slaves', 'type': 'BaseObject**', 'description': 'Sub-objects used internally by this object. These slaves can be added and removed dynamically using the addSlave and removeSlave methods.'}
- {'name': 'master', 'type': 'BaseObject*', 'description': 'The master object for which this object is a sub-object. Regular objects have no master, but some specialized objects may set their master to another BaseObject.'}
- methods
-
- {'name': 'init', 'return_type': 'void', 'parameters': [], 'description': 'Initializes the object by checking if all required data is set. If not, it either falls back to default values or logs an error.'}
- {'name': 'bwdInit', 'return_type': 'void', 'parameters': [], 'description': 'Backward initialization method that can be overridden in derived classes for additional setup steps.'}
- {'name': 'reinit', 'return_type': 'void', 'parameters': [], 'description': "Reinitialization method called to reset the object's state, typically after a significant change in its environment or data."}
- {'name': 'updateInternal', 'return_type': 'void', 'parameters': [], 'description': 'Updates internal state based on changes in tracked data. It first checks if any of the tracked data has changed and then performs an update if necessary.'}
- {'name': 'trackInternalData', 'return_type': 'void', 'parameters': ['BaseData&', 'data'], 'description': 'Registers a piece of internal data to be tracked for changes. This method is used internally by Sofa components that need to react to specific data modifications.'}
- {'name': 'hasDataChanged', 'return_type': 'bool', 'parameters': ['BaseData&', 'data'], 'description': 'Checks if the specified internal data has changed since the last update. This method is useful for determining whether an object needs to recompute its state.'}
- {'name': 'handleEvent', 'return_type': 'void', 'parameters': ['Event*', 'e'], 'description': 'Processes events dispatched by the Sofa simulation framework. By default, this method does nothing but can be overridden in derived classes to implement specific event handling logic.'}
- {'name': 'handleTopologyChange', 'return_type': 'void', 'parameters': ['core::topology::Topology*', 't'], 'description': 'Responds to changes in the topology of the simulation. This method is called when a specified Topology object (usually associated with the context) undergoes modifications.'}
- {'name': 'getTime', 'return_type': 'SReal', 'parameters': [], 'description': 'Retrieves the current simulation time from the context.'}
- notes
-
- The BaseObject class is abstract and cannot be instantiated directly. It must be subclassed to create concrete Sofa components.
- All Sofa components should inherit from BaseObject or one of its derivatives to integrate seamlessly with the framework's data management, event handling, and simulation lifecycle.
- maths
- The BaseObject class in the Sofa framework is designed to encapsulate common behaviors and properties shared by various physical objects, engines, and other system components. It serves as a foundational structure that ensures consistency across different types of simulation elements. Here’s a detailed mathematical and physical description of this component: ### 1. Event Handling Mechanism - **Mathematical Description**: The `handleEvent` method in the BaseObject class is an abstract mechanism designed to process event-driven interactions within the simulation environment. Events are typically modeled as objects that carry information about changes or actions occurring within the simulation (e.g., collision detection, force application). - **Physical Interpretation**: In a physical system, events can be considered analogous to external forces or impulses acting on bodies. The event handling mechanism ensures that these forces/impulses are appropriately processed and applied. ### 2. Data Tracking and Initialization - **Mathematical Description**: The BaseObject class includes methods for tracking changes in data (`trackInternalData`, `hasDataChanged`) and initializing objects (`init`, `bwdInit`). These mechanisms rely on maintaining a set of tracked data points that are validated against predefined conditions (e.g., required data must be initialized). - **Physical Interpretation**: In the context of physical simulations, these methods ensure that all necessary initial parameters (such as mass, velocity, or position) are correctly defined before simulation begins. Data tracking can also be seen as a way to monitor state changes in the system over time. ### 3. Internal State Management - **Mathematical Description**: The `reinit` method allows for reinitialization of internal states, while `updateInternal` ensures that any tracked data is updated when changes are detected (`doUpdateInternal`). These methods maintain a consistent state across the simulation by leveraging flags and conditions to indicate whether updates are needed. - **Physical Interpretation**: In physical simulations, maintaining an accurate internal state is crucial for ensuring realistic behavior. The reinitialization and update processes help in synchronizing the simulation with any external or internal changes (e.g., material properties, boundary conditions). ### 4. Simulation Cleanup and Reset Operations - **Mathematical Description**: The `cleanup` method ensures that all resources associated with an object are properly released at the end of a simulation run, while `storeResetState` and `reset` methods allow for saving and restoring the initial state of objects. - **Physical Interpretation**: These operations ensure that simulations can be restarted or resumed from known states without losing consistency. The cleanup process helps in freeing up computational resources efficiently. ### 5. Contextual Dependencies - **Mathematical Description**: BaseObject interacts with its context (`BaseContext`) to resolve dependencies and validate links between objects (e.g., `findLinkDestClass`, `setSrc`). This ensures that all components are correctly linked and can communicate within the simulation environment. - **Physical Interpretation**: In physical systems, contextual dependencies reflect how different elements of a system interact. Ensuring these interactions are properly defined is crucial for simulating complex behaviors (e.g., collision detection, constraint enforcement). ### Summary The BaseObject class in Sofa provides essential mathematical and physical mechanisms that ensure consistency, correctness, and efficiency in simulation components. By leveraging event handling, data tracking, state management, and contextual dependencies, it forms a robust foundation for constructing more complex simulation systems.
{
"name": "BaseObject",
"main": {
"name": "BaseObject",
"namespace": "sofa::core::objectmodel",
"module": "Sofa.framework.Core",
"include": "sofa/core/objectmodel/BaseObject.h",
"doc": "Base class for simulation components.\n An object defines a part of the functionality in the simulation\n (stores state data, specify topology, compute forces, etc).\n Each simulation object is related to a context, which gives access to all available external data.\n It is able to process events, if listening enabled (default is false).",
"inherits": [
"Base"
],
"templates": [],
"data_fields": [
{
"name": "f_listening",
"type": "bool",
"xmlname": "listening",
"help": "if true, handle the events, otherwise ignore the events"
}
],
"links": [
{
"name": "l_context",
"target": "BaseContext",
"kind": "single",
"xmlname": "context",
"help": "Graph Node containing this object (or BaseContext::getDefault() if no graph is used)"
},
{
"name": "l_master",
"target": "BaseObject",
"kind": "single",
"xmlname": "master",
"help": "nullptr for regular objects, or master object for which this object is one sub-objects"
}
],
"methods": [
{
"name": "toBaseObject",
"return_type": "const BaseObject *",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "canCreate",
"return_type": "bool",
"params": [
{
"name": "",
"type": "T *"
},
{
"name": "",
"type": "BaseContext *"
},
{
"name": "",
"type": "BaseObjectDescription *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": true,
"access": "public"
},
{
"name": "parse",
"return_type": "void",
"params": [
{
"name": "arg",
"type": "BaseObjectDescription *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "init",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "bwdInit",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "reinit",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "updateInternal",
"return_type": "void",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "storeResetState",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "reset",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "cleanup",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "draw",
"return_type": "void",
"params": [
{
"name": "",
"type": "const core::visual::VisualParams *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getContext",
"return_type": "const BaseContext *",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getMaster",
"return_type": "const BaseObject *",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getSlaves",
"return_type": "const VecSlaves &",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getSlave",
"return_type": "BaseObject *",
"params": [
{
"name": "name",
"type": "const int &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "addSlave",
"return_type": "void",
"params": [
{
"name": "s",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "removeSlave",
"return_type": "void",
"params": [
{
"name": "s",
"type": "int"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getTime",
"return_type": "SReal",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "handleEvent",
"return_type": "void",
"params": [
{
"name": "",
"type": "Event *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "handleTopologyChange",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "handleTopologyChange",
"return_type": "void",
"params": [
{
"name": "t",
"type": "core::topology::Topology *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "computeBBox",
"return_type": "void",
"params": [
{
"name": "",
"type": "const core::ExecParams *"
},
{
"name": "",
"type": "bool"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "setSrc",
"return_type": "void",
"params": [
{
"name": "v",
"type": "const int &"
},
{
"name": "attributeList",
"type": "int *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "setSrc",
"return_type": "void",
"params": [
{
"name": "v",
"type": "const int &"
},
{
"name": "loader",
"type": "const BaseObject *"
},
{
"name": "attributeList",
"type": "int *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "findLinkDestClass",
"return_type": "Base *",
"params": [
{
"name": "destType",
"type": "const BaseClass *"
},
{
"name": "path",
"type": "const int &"
},
{
"name": "link",
"type": "const BaseLink *"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "getPathName",
"return_type": "int",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "trackInternalData",
"return_type": "void",
"params": [
{
"name": "data",
"type": "const BaseData &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "cleanTracker",
"return_type": "void",
"params": [],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "hasDataChanged",
"return_type": "bool",
"params": [
{
"name": "data",
"type": "const BaseData &"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "doUpdateInternal",
"return_type": "void",
"params": [],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "changeContextLink",
"return_type": "void",
"params": [
{
"name": "before",
"type": "BaseContext *"
},
{
"name": "after",
"type": "BaseContext *&"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "changeSlavesLink",
"return_type": "void",
"params": [
{
"name": "ptr",
"type": "int"
},
{
"name": "",
"type": "int"
},
{
"name": "add",
"type": "bool"
}
],
"is_virtual": false,
"is_pure_virtual": false,
"is_static": false,
"access": "protected"
},
{
"name": "insertInNode",
"return_type": "bool",
"params": [
{
"name": "",
"type": "BaseNode *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
},
{
"name": "removeInNode",
"return_type": "bool",
"params": [
{
"name": "",
"type": "BaseNode *"
}
],
"is_virtual": true,
"is_pure_virtual": false,
"is_static": false,
"access": "public"
}
]
},
"desc": {
"name": "BaseObject",
"description": "The BaseObject is the fundamental class from which most Sofa components inherit. It serves as the base for all physical objects, engines, and other system elements in Sofa. This class provides essential functionalities such as event handling, data tracking, initialization, and cleanup operations.",
"attributes": [
{
"name": "context",
"type": "BaseContext*",
"description": "The Graph Node containing this object or BaseContext::getDefault() if no graph is used."
},
{
"name": "slaves",
"type": "BaseObject**",
"description": "Sub-objects used internally by this object. These slaves can be added and removed dynamically using the addSlave and removeSlave methods."
},
{
"name": "master",
"type": "BaseObject*",
"description": "The master object for which this object is a sub-object. Regular objects have no master, but some specialized objects may set their master to another BaseObject."
}
],
"methods": [
{
"name": "init",
"return_type": "void",
"parameters": [],
"description": "Initializes the object by checking if all required data is set. If not, it either falls back to default values or logs an error."
},
{
"name": "bwdInit",
"return_type": "void",
"parameters": [],
"description": "Backward initialization method that can be overridden in derived classes for additional setup steps."
},
{
"name": "reinit",
"return_type": "void",
"parameters": [],
"description": "Reinitialization method called to reset the object's state, typically after a significant change in its environment or data."
},
{
"name": "updateInternal",
"return_type": "void",
"parameters": [],
"description": "Updates internal state based on changes in tracked data. It first checks if any of the tracked data has changed and then performs an update if necessary."
},
{
"name": "trackInternalData",
"return_type": "void",
"parameters": [
"BaseData&",
"data"
],
"description": "Registers a piece of internal data to be tracked for changes. This method is used internally by Sofa components that need to react to specific data modifications."
},
{
"name": "hasDataChanged",
"return_type": "bool",
"parameters": [
"BaseData&",
"data"
],
"description": "Checks if the specified internal data has changed since the last update. This method is useful for determining whether an object needs to recompute its state."
},
{
"name": "handleEvent",
"return_type": "void",
"parameters": [
"Event*",
"e"
],
"description": "Processes events dispatched by the Sofa simulation framework. By default, this method does nothing but can be overridden in derived classes to implement specific event handling logic."
},
{
"name": "handleTopologyChange",
"return_type": "void",
"parameters": [
"core::topology::Topology*",
"t"
],
"description": "Responds to changes in the topology of the simulation. This method is called when a specified Topology object (usually associated with the context) undergoes modifications."
},
{
"name": "getTime",
"return_type": "SReal",
"parameters": [],
"description": "Retrieves the current simulation time from the context."
}
],
"notes": [
"The BaseObject class is abstract and cannot be instantiated directly. It must be subclassed to create concrete Sofa components.",
"All Sofa components should inherit from BaseObject or one of its derivatives to integrate seamlessly with the framework's data management, event handling, and simulation lifecycle."
]
},
"maths": {
"maths": "The BaseObject class in the Sofa framework is designed to encapsulate common behaviors and properties shared by various physical objects, engines, and other system components. It serves as a foundational structure that ensures consistency across different types of simulation elements. Here’s a detailed mathematical and physical description of this component:\n\n### 1. Event Handling Mechanism\n- **Mathematical Description**: The `handleEvent` method in the BaseObject class is an abstract mechanism designed to process event-driven interactions within the simulation environment. Events are typically modeled as objects that carry information about changes or actions occurring within the simulation (e.g., collision detection, force application).\n - **Physical Interpretation**: In a physical system, events can be considered analogous to external forces or impulses acting on bodies. The event handling mechanism ensures that these forces/impulses are appropriately processed and applied.\n\n### 2. Data Tracking and Initialization\n- **Mathematical Description**: The BaseObject class includes methods for tracking changes in data (`trackInternalData`, `hasDataChanged`) and initializing objects (`init`, `bwdInit`). These mechanisms rely on maintaining a set of tracked data points that are validated against predefined conditions (e.g., required data must be initialized).\n - **Physical Interpretation**: In the context of physical simulations, these methods ensure that all necessary initial parameters (such as mass, velocity, or position) are correctly defined before simulation begins. Data tracking can also be seen as a way to monitor state changes in the system over time.\n\n### 3. Internal State Management\n- **Mathematical Description**: The `reinit` method allows for reinitialization of internal states, while `updateInternal` ensures that any tracked data is updated when changes are detected (`doUpdateInternal`). These methods maintain a consistent state across the simulation by leveraging flags and conditions to indicate whether updates are needed.\n - **Physical Interpretation**: In physical simulations, maintaining an accurate internal state is crucial for ensuring realistic behavior. The reinitialization and update processes help in synchronizing the simulation with any external or internal changes (e.g., material properties, boundary conditions).\n\n### 4. Simulation Cleanup and Reset Operations\n- **Mathematical Description**: The `cleanup` method ensures that all resources associated with an object are properly released at the end of a simulation run, while `storeResetState` and `reset` methods allow for saving and restoring the initial state of objects.\n - **Physical Interpretation**: These operations ensure that simulations can be restarted or resumed from known states without losing consistency. The cleanup process helps in freeing up computational resources efficiently.\n\n### 5. Contextual Dependencies\n- **Mathematical Description**: BaseObject interacts with its context (`BaseContext`) to resolve dependencies and validate links between objects (e.g., `findLinkDestClass`, `setSrc`). This ensures that all components are correctly linked and can communicate within the simulation environment.\n - **Physical Interpretation**: In physical systems, contextual dependencies reflect how different elements of a system interact. Ensuring these interactions are properly defined is crucial for simulating complex behaviors (e.g., collision detection, constraint enforcement).\n\n### Summary\nThe BaseObject class in Sofa provides essential mathematical and physical mechanisms that ensure consistency, correctness, and efficiency in simulation components. By leveraging event handling, data tracking, state management, and contextual dependencies, it forms a robust foundation for constructing more complex simulation systems."
},
"summary": {
"abstract": "BaseObject serves as the foundational class for all simulation components in SOFA, providing essential functionalities such as event handling, data tracking, initialization, and cleanup operations.",
"sheet": "# BaseObject\n\n## Overview\nBaseObject is a fundamental class from which most Sofa components inherit. It provides essential functionalities such as event handling, data tracking, initialization, and cleanup operations.\n\n## Parameters and Data\n- **f_listening**: `bool` (default: false) - Determines whether the object handles events or ignores them.\n\n## Dependencies and Connections\nBaseObject typically requires a context (`BaseContext`) to resolve dependencies and validate links between objects. It can also have slave objects, which are managed through methods like `addSlave`, `removeSlave`, and `getSlaves`."
}
}