Back

Element

sofa::topology::Element
BaseElement
Abstract (AI generated)

`Element` represents geometric elements in SOFA simulations by storing node indices and providing methods to access them.

Metadata
module
Sofa.framework.Topology
namespace
sofa::topology
include
sofa/topology/Element.h
inherits
  • BaseElement
description

Mathematical and Physical Description

The `Element` class in the SOFA framework is a fundamental data structure used to represent geometric elements, such as vertices, edges, faces, or higher-order elements. It plays a crucial role in defining the topological structure of the simulation mesh.

Topological Representation

The `Element` class is parameterized by a geometry type (`GeometryElement`), which defines the number of nodes that make up an element (e.g., 2 for edges, 3 for triangular faces). The static method size() returns this predefined number.

Data Structure

The `Element` class stores its node indices in a fixed-size array (`ArrayType`), which is defined as:

using ArrayType = sofa::type::fixed_array;

This allows for efficient and consistent storage of the node indices.

Accessing Node Indices

The class provides several methods to access these node indices:

  • operator[](size_type i): Accesses an index in the element array. This method is both non-const and const.
    constexpr reference operator[](size_type i)
    {
        return elems[i];
    }
    
    constexpr const_reference operator[](size_type i) const
    {
        return elems[i];
    }
  • at(size_type i): Provides bounds-checked access to an index. This method is both non-const and const.
    constexpr reference at(size_type i)
    {
        return elems.at(i);
    }
    
    constexpr const_reference at(size_type i) const
    {
        return elems.at(i);
    }
  • get<I>(): Retrieves a specific index by constant template parameter. This method supports both lvalue and rvalue references.
    template< std::size_t I >
    [[nodiscard]] constexpr reference get() & noexcept requires( I < static_size )
    {
        return elems[I];
    }
    
    // Other overloads for const&, &&, and const&&
  • array(): Returns the underlying fixed array of indices.
    const ArrayType& array() const
    {
        return elems;
    }

Iterator Support

The `Element` class supports standard iterator methods for iterating over its contents:

  • begin(), cbegin(): Return the beginning of the element array.
  • end(), cend(): Return the end of the element array.
    constexpr iterator begin() noexcept
    {
        return elems.begin();
    }
    
    // Other overloads for const and cbegin/cend

Comparison

The class supports comparison via the operator <, which compares two elements based on their node indices.

bool operator<(const Element& other) const
{
    return elems < other.elems;
}

Role in the SOFA Ecosystem

The `Element` class is a fundamental building block used to represent geometric elements within the SOFA simulation framework. It serves as a container for indices representing nodes that make up an element of the topology, ensuring consistency and efficiency in mesh representation.

Methods
int size ()
void Element<GeometryElement> (ArgsT &&... args)
int operator[] (int i)
int at (int i)
int get ()
int begin ()
int cbegin ()
int end ()
int cend ()
bool operator< (const Element<GeometryElement> & other)
const int & array ()
{
  "name": "Element",
  "namespace": "sofa::topology",
  "module": "Sofa.framework.Topology",
  "include": "sofa/topology/Element.h",
  "doc": "",
  "inherits": [
    "BaseElement"
  ],
  "templates": [],
  "data_fields": [],
  "links": [],
  "methods": [
    {
      "name": "size",
      "return_type": "int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": true,
      "access": "public"
    },
    {
      "name": "Element<GeometryElement>",
      "return_type": "void",
      "params": [
        {
          "name": "args",
          "type": "ArgsT &&..."
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "operator[]",
      "return_type": "int",
      "params": [
        {
          "name": "i",
          "type": "int"
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "at",
      "return_type": "int",
      "params": [
        {
          "name": "i",
          "type": "int"
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "get",
      "return_type": "int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "begin",
      "return_type": "int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "cbegin",
      "return_type": "int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "end",
      "return_type": "int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "cend",
      "return_type": "int",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "operator<",
      "return_type": "bool",
      "params": [
        {
          "name": "other",
          "type": "const Element<GeometryElement> &"
        }
      ],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    },
    {
      "name": "array",
      "return_type": "const int &",
      "params": [],
      "is_virtual": false,
      "is_pure_virtual": false,
      "is_static": false,
      "access": "public"
    }
  ],
  "description": "<h3>Role and Purpose in the SOFA Ecosystem</h3>\n\nThe `Element` class, defined within the `sofa::topology` namespace, is a fundamental building block used to represent geometric elements (e.g., vertices, edges, faces) within the SOFA simulation framework. It serves as a container for indices representing nodes that make up an element of the topology.\n\n<h3>Interactions with Other Components</h3>\n\nThe `Element` class interacts with other components in the SOFA ecosystem primarily through its role in defining and accessing the topological structure of elements within the scene graph. It inherits from `BaseElement`, indicating that it follows a common interface for element operations.\n\n<h3>Practical Usage Guidance</h3>\n\nThe `Element` class is typically used to define geometric elements in simulations, allowing users to manipulate and access node indices through various methods such as `operator[]`, `at`, and `get`. It supports standard iterator functions (`begin`, `cbegin`, `end`, `cend`) for iterating over its contents.\n\nThe class provides a static size method that returns the number of nodes in the element, ensuring consistency with the specified geometry type. The operator `<` enables comparison between elements based on their node indices.\n\n<h3>Data Fields and Methods</h3>\n\n- **Static Methods:**\n  - `size()`: Returns the number of nodes (statically defined).\n- **Public Member Functions:**\n  - `Element(ArgsT&&...)`: Constructor that initializes the element with node indices.\n  - `operator[](int i)`: Accesses an index in the element array.\n  - `at(int i)`: Provides bounds-checked access to an index.\n  - `get()`: Retrieves a specific index by constant template parameter.\n  - `begin()`, `cbegin()`, `end()`, `cend()`: Iterator methods for accessing elements.\n  - `array()`: Returns the underlying fixed array of indices.\n\nThe class is designed to work with any geometry type that defines its number of nodes, providing a flexible and consistent way to represent topological elements in simulations.",
  "maths": "<h3>Mathematical and Physical Description</h3>\n\n<p>The `Element` class in the SOFA framework is a fundamental data structure used to represent geometric elements, such as vertices, edges, faces, or higher-order elements. It plays a crucial role in defining the topological structure of the simulation mesh.</p>\n\n<h4>Topological Representation</h4>\n\n<p>The `Element` class is parameterized by a geometry type (`GeometryElement`), which defines the number of nodes that make up an element (e.g., 2 for edges, 3 for triangular faces). The static method <code>size()</code> returns this predefined number.</p>\n\n<h4>Data Structure</h4>\n\n<p>The `Element` class stores its node indices in a fixed-size array (`ArrayType`), which is defined as:</p>\n\n<pre><code>using ArrayType = sofa::type::fixed_array<sofa::Index, GeometryElement::NumberOfNodes>;\n</code></pre>\n\n<p>This allows for efficient and consistent storage of the node indices.</p>\n\n<h4>Accessing Node Indices</h4>\n\n<p>The class provides several methods to access these node indices:</p>\n\n<ul>\n<li><code>operator[](size_type i)</code>: Accesses an index in the element array. This method is both non-const and const.\n\n<pre><code>constexpr reference operator[](size_type i)\n{\n    return elems[i];\n}\n\nconstexpr const_reference operator[](size_type i) const\n{\n    return elems[i];\n}</code></pre>\n</li>\n<li><code>at(size_type i)</code>: Provides bounds-checked access to an index. This method is both non-const and const.\n\n<pre><code>constexpr reference at(size_type i)\n{\n    return elems.at(i);\n}\n\nconstexpr const_reference at(size_type i) const\n{\n    return elems.at(i);\n}</code></pre>\n</li>\n<li><code>get&lt;I&gt;()</code>: Retrieves a specific index by constant template parameter. This method supports both lvalue and rvalue references.\n\n<pre><code>template< std::size_t I >\n[[nodiscard]] constexpr reference get() & noexcept requires( I < static_size )\n{\n    return elems[I];\n}\n\n// Other overloads for const&, &&, and const&&</code></pre>\n</li>\n<li><code>array()</code>: Returns the underlying fixed array of indices.\n\n<pre><code>const ArrayType& array() const\n{\n    return elems;\n}</code></pre>\n</li>\n</ul>\n\n<h4>Iterator Support</h4>\n\n<p>The `Element` class supports standard iterator methods for iterating over its contents:</p>\n\n<ul>\n<li><code>begin()</code>, <code>cbegin()</code>: Return the beginning of the element array.</li>\n<li><code>end()</code>, <code>cend()</code>: Return the end of the element array.\n\n<pre><code>constexpr iterator begin() noexcept\n{\n    return elems.begin();\n}\n\n// Other overloads for const and cbegin/cend</code></pre>\n</li>\n</ul>\n\n<h4>Comparison</h4>\n\n<p>The class supports comparison via the operator <code>&lt;</code>, which compares two elements based on their node indices.\n\n<pre><code>bool operator&lt;(const Element& other) const\n{\n    return elems &lt; other.elems;\n}</code></pre>\n</p>\n\n<h4>Role in the SOFA Ecosystem</h4>\n\n<p>The `Element` class is a fundamental building block used to represent geometric elements within the SOFA simulation framework. It serves as a container for indices representing nodes that make up an element of the topology, ensuring consistency and efficiency in mesh representation.</p>\n",
  "abstract": "`Element` represents geometric elements in SOFA simulations by storing node indices and providing methods to access them.",
  "sheet": "# Element\n\n**Overview**\n\nThe `Element` class is a fundamental component within the SOFA framework, representing geometric elements such as vertices, edges, faces, or higher-order elements. It stores node indices and provides various methods for accessing these indices efficiently.\n\n**Parameters and Data**\n\n- **Static Methods:*\n  - `size()`: Returns the number of nodes in the element (statically defined).\n- **Public Member Functions:**\n  - `Element(ArgsT&&...)`: Constructor that initializes the element with node indices.\n  - `operator[](int i)`: Accesses an index in the element array.\n  - `at(int i)`: Provides bounds-checked access to an index.\n  - `get()`: Retrieves a specific index by constant template parameter.\n  - `begin()`, `cbegin()`, `end()`, `cend()`: Iterator methods for accessing elements.\n  - `array()`: Returns the underlying fixed array of indices.\n\n**Dependencies and Connections**\n\nThe `Element` class interacts with other components in the SOFA ecosystem primarily through its role in defining and accessing the topological structure of elements within the scene graph. It inherits from `BaseElement`, indicating that it follows a common interface for element operations."
}