Back

VisualModel

sofa::core::visual::VisualModel
BaseObject
Doc (from source)

An interface which all VisualModel inherit. This Interface is used for the VisualModel, which all visible objects must implement. VisualModels are drawn by calling their draw method. The method update is used to recompute some internal data (such as normals) after the simulation has computed a new timestep. Most VisualModel are bound by a Mapping to a BehaviorModel or MechanicalState.

Abstract (AI generated)

The `VisualModel` interface handles rendering and updating graphical representations in SOFA simulations by implementing methods for drawing, initializing, updating internal data, and managing visual resources.

Metadata
module
Sofa.framework.Core
namespace
sofa::core::visual
include
sofa/core/visual/VisualModel.h
inherits
  • BaseObject
description

The VisualModel in the SOFA framework is an interface that all visual models must implement to be visible within simulations. Its primary role is to handle the rendering and updating of graphical representations, rather than contributing to the physical or mechanical aspects of the simulation. Therefore, it does not directly involve governing equations such as the mass matrix $ M $, stiffness matrix $ K $, internal force $ f_{int} $, residual $ R $, or constitutive laws related to material behavior. Instead, its methods are focused on visual aspects and transformations.

Governing Equations and Operators

The VisualModel does not contribute to the governing equations of FEM. It is concerned with rendering and updating graphical representations rather than solving the mechanical system.

Constitutive or Kinematic Laws Involved

There are no constitutive laws involved in this component, as it deals purely with visual representation rather than material properties or kinematics. The transformations such as translation, rotation, and scaling (via applyTranslation, applyRotation, and applyScale) do not affect the mechanical state but instead change the graphical position, orientation, and size of the object.

Role in the Global FEM Pipeline

In the global FEM pipeline, the
- Rendering the visual representation (klzzwxh:0010).
- Updating internal data like normals after each simulation timestep (klzzwxh:0011).
- Initializing graphical resources (klzzwxh:0012).
- Clearing graphical resources when necessary (klzzwxh:0013).drawTransparent plays a role outside of the core mechanics. Its primary responsibilities are:), and pre/post rendering operations (

Numerical Methods or Discretization Choices

The VisualModel does not involve numerical methods related to discretization. Its methods are concerned with rendering and transformation, which do not require numerical integration or matrix assembly.

Fitting into the Broader Variational / Lagrangian Mechanics Framework

Since this component is focused on visualization rather than mechanics, it does not fit directly into the variational or Lagrangian framework of FEM. Its methods ensure that the visual representation of objects remains consistent with the mechanical state derived from the simulation.

Key Methods and Their Roles:

  • drawVisual: Renders the object based on the current state and visualization parameters (vparams).

  • updateVisual: Updates internal data (such as normals) after each timestep to ensure that the visual representation remains consistent with the mechanical state.

  • initVisual: Initializes graphical resources, such as textures and other graphical assets. Called once before the first frame is drawn or when the graphical context is recreated.

  • clearVisual: Cleans up any allocated graphical resources, typically called before deletion.

The component provides methods for managing various aspects of rendering, including shadows (drawShadow), transparency (drawTransparent plays a role outside of the core mechanics. Its primary responsibilities are:), and pre/post rendering operations (fwdDraw, bwdDraw). These ensure that the visual representation adheres to the intended display settings and context.

Data Fields
NameTypeDefaultHelp
d_enable bool Display the object or not
Methods
const VisualModel * toVisualModel () virtual
void drawVisual (const VisualParams * ) virtual
void initVisual (const VisualParams * )
void initVisual () virtual
void updateVisual (const VisualParams * )
void updateVisual () virtual
void clearVisual () virtual
void fwdDraw (VisualParams * ) virtual
void bwdDraw (VisualParams * ) virtual
void drawTransparent (const VisualParams * ) virtual
void drawShadow (const VisualParams * vparams) virtual
void parallelUpdateVisual () virtual
bool addBBox (SReal * , SReal * ) virtual
void applyTranslation (const SReal , const SReal , const SReal ) virtual
void applyRotation (const SReal , const SReal , const SReal ) virtual
void applyRotation (const type::Quat<SReal> ) virtual
void applyScale (const SReal , const SReal , const SReal ) virtual
void exportOBJ (int , int * , int * , int & , int & , int & , int & ) virtual
bool insertInNode (objectmodel::BaseNode * node) virtual
bool removeInNode (objectmodel::BaseNode * node) virtual
{
  "name": "VisualModel",
  "namespace": "sofa::core::visual",
  "module": "Sofa.framework.Core",
  "include": "sofa/core/visual/VisualModel.h",
  "doc": "An interface which all VisualModel inherit.\n This Interface is used for the VisualModel, which all visible objects must\n implement.\n VisualModels are drawn by calling their draw method. The method update is\n used to recompute some internal data (such as normals) after the simulation\n has computed a new timestep.\n Most VisualModel are bound by a Mapping to a BehaviorModel or\n MechanicalState.",
  "inherits": [
    "BaseObject"
  ],
  "templates": [],
  "data_fields": [
    {
      "name": "d_enable",
      "type": "bool",
      "xmlname": "enable",
      "help": "Display the object or not"
    }
  ],
  "links": [],
  "methods": [
    {
      "name": "toVisualModel",
      "return_type": "const VisualModel *",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "drawVisual",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const VisualParams *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "initVisual",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const VisualParams *"
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "initVisual",
      "return_type": "void",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "updateVisual",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const VisualParams *"
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "updateVisual",
      "return_type": "void",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "clearVisual",
      "return_type": "void",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "fwdDraw",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "VisualParams *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "bwdDraw",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "VisualParams *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "drawTransparent",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const VisualParams *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "drawShadow",
      "return_type": "void",
      "params": [
        {
          "name": "vparams",
          "type": "const VisualParams *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "parallelUpdateVisual",
      "return_type": "void",
      "params": [],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "addBBox",
      "return_type": "bool",
      "params": [
        {
          "name": "",
          "type": "SReal *"
        },
        {
          "name": "",
          "type": "SReal *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "applyTranslation",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const SReal"
        },
        {
          "name": "",
          "type": "const SReal"
        },
        {
          "name": "",
          "type": "const SReal"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "applyRotation",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const SReal"
        },
        {
          "name": "",
          "type": "const SReal"
        },
        {
          "name": "",
          "type": "const SReal"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "applyRotation",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const type::Quat<SReal>"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "applyScale",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "const SReal"
        },
        {
          "name": "",
          "type": "const SReal"
        },
        {
          "name": "",
          "type": "const SReal"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "exportOBJ",
      "return_type": "void",
      "params": [
        {
          "name": "",
          "type": "int"
        },
        {
          "name": "",
          "type": "int *"
        },
        {
          "name": "",
          "type": "int *"
        },
        {
          "name": "",
          "type": "int &"
        },
        {
          "name": "",
          "type": "int &"
        },
        {
          "name": "",
          "type": "int &"
        },
        {
          "name": "",
          "type": "int &"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "insertInNode",
      "return_type": "bool",
      "params": [
        {
          "name": "node",
          "type": "objectmodel::BaseNode *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "removeInNode",
      "return_type": "bool",
      "params": [
        {
          "name": "node",
          "type": "objectmodel::BaseNode *"
        }
      ],
      "is_virtual": true,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    }
  ],
  "description": "The `VisualModel` is an interface in the SOFA framework that all visual models must implement to be visible within simulations. Its primary role is to handle the rendering and updating of graphical representations. The `drawVisual` method is called to render the object, while the `updateVisual` method re-computes internal data such as normals after a new simulation timestep. Additionally, the `initVisual`, `clearVisual`, and various transformation methods (`applyTranslation`, `applyRotation`, `applyScale`) are provided for initializing, cleaning up, and transforming visual objects.\n\nThe component interacts with other SOFA components through the `BaseNode` API to be added or removed from the scene graph. The `d_enable` field controls whether the object is displayed. It also provides methods like `drawShadow`, `drawTransparent`, `fwdDraw`, and `bwdDraw` for managing different aspects of rendering, such as shadows and transparency.\n\nPractical usage includes implementing these virtual methods in derived classes to customize visual behavior according to specific needs. The `VisualParams` parameter in several methods provides context about the current state of the visualization pipeline.",
  "maths": "The `VisualModel` in the SOFA framework is an interface that all visual models must implement to be visible within simulations. Its primary role is to handle the rendering and updating of graphical representations, rather than contributing to the physical or mechanical aspects of the simulation. Therefore, it does not directly involve governing equations such as the mass matrix \\( M \\), stiffness matrix \\( K \\), internal force \\( f_{int} \\), residual \\( R \\), or constitutive laws related to material behavior. Instead, its methods are focused on visual aspects and transformations.\n\n### Governing Equations and Operators\nThe `VisualModel` does not contribute to the governing equations of FEM. It is concerned with rendering and updating graphical representations rather than solving the mechanical system.\n\n### Constitutive or Kinematic Laws Involved\nThere are no constitutive laws involved in this component, as it deals purely with visual representation rather than material properties or kinematics. The transformations such as translation, rotation, and scaling (via `applyTranslation`, `applyRotation`, and `applyScale`) do not affect the mechanical state but instead change the graphical position, orientation, and size of the object.\n\n### Role in the Global FEM Pipeline\nIn the global FEM pipeline, the `VisualModel` plays a role outside of the core mechanics. Its primary responsibilities are:\n- Rendering the visual representation (`drawVisual`).\n- Updating internal data like normals after each simulation timestep (`updateVisual`).\n- Initializing graphical resources (`initVisual`).\n- Clearing graphical resources when necessary (`clearVisual`).\n\n### Numerical Methods or Discretization Choices\nThe `VisualModel` does not involve numerical methods related to discretization. Its methods are concerned with rendering and transformation, which do not require numerical integration or matrix assembly.\n\n### Fitting into the Broader Variational / Lagrangian Mechanics Framework\nSince this component is focused on visualization rather than mechanics, it does not fit directly into the variational or Lagrangian framework of FEM. Its methods ensure that the visual representation of objects remains consistent with the mechanical state derived from the simulation.\n\n### Key Methods and Their Roles:\n- `drawVisual`: Renders the object based on the current state and visualization parameters (`vparams`).\n- `updateVisual`: Updates internal data (such as normals) after each timestep to ensure that the visual representation remains consistent with the mechanical state.\n- `initVisual`: Initializes graphical resources, such as textures and other graphical assets. Called once before the first frame is drawn or when the graphical context is recreated.\n- `clearVisual`: Cleans up any allocated graphical resources, typically called before deletion.\n\nThe component provides methods for managing various aspects of rendering, including shadows (`drawShadow`), transparency (`drawTransparent`), and pre/post rendering operations (`fwdDraw`, `bwdDraw`). These ensure that the visual representation adheres to the intended display settings and context.",
  "abstract": "The `VisualModel` interface handles rendering and updating graphical representations in SOFA simulations by implementing methods for drawing, initializing, updating internal data, and managing visual resources.",
  "sheet": "<h1>VisualModel</h1>\n\n<h2>Overview</h2>\n<p>The <code>VisualModel</code> is an interface that all visible objects must implement to handle rendering and updating graphical representations in SOFA simulations. It provides methods for drawing, initializing, updating internal data (such as normals), and managing visual resources.</p>\n\n<h2>Parameters and Data</h2>\n<p>The <code>d_enable</code> field controls whether the object is displayed:</p>\n<ul>\n<li><strong>d_enable</strong>: <em>bool</em>, default: true. Controls whether the object is visible in the simulation.</li>\n</ul>\n\n<h2>Dependencies and Connections</h2>\n<p>The <code>VisualModel</code> typically requires a mapping to a <code>BehaviorModel</code> or <code>MechanicalState</code>. It interacts with other SOFA components through methods like <code>insertInNode</code> and <code>removeInNode</code>, which manage its presence in the scene graph.</p>\n\n<h2>Practical Notes</h2>\n<p>The <code>VisualModel</code> must be implemented by derived classes to customize visual behavior. Proper initialization and cleanup are crucial for managing graphical resources efficiently.</p>"
}