Back

GridMeshCreator

The `GridMeshCreator` is a SOFA component that procedurally generates a two-dimensional triangular grid mesh. It inherits from the `MeshLoader` class and creates vertices within a specified resolution range, translating coordinates from (0,0,0) to (1,1,0). The grid can be customized with different triangle patterns, including no triangles, alternate triangles, upward triangles, or downward triangles. This component interacts with other SOFA components through the `MeshLoader` interface and provides methods like `canLoad`, `doLoad`, and `doClearBuffers`. Users can configure the number of vertices in each direction using the `resolution` data field and choose a triangle pattern via the `trianglePattern` data field.

abstract
The `GridMeshCreator` procedurally generates a two-dimensional triangular grid within a specified resolution range, allowing customization through different triangle patterns.
sheet
# GridMeshCreator **Overview** The `GridMeshCreator` is a SOFA component that procedurally generates a two-dimensional triangular grid mesh. It inherits from the `MeshLoader` class and creates vertices within a normalized coordinate system spanning from (0,0,0) to (1,1,0). The grid can be customized with different triangle patterns: no triangles, alternate triangles, upward triangles, or downward triangles. **Parameters and Data** - **resolution**: `type::Vec2i` - Specifies the number of vertices in each direction. Default is not specified. - **trianglePattern**: `int` - Determines the type of triangle pattern to be used: 0 (no triangles), 1 (alternate triangles), 2 (upward triangles), or 3 (downward triangles). Default is not specified. **Dependencies and Connections** The `GridMeshCreator` inherits from the `MeshLoader` class, which provides methods like `canLoad`, `doLoad`, and `doClearBuffers`. It does not have specific dependencies but fits into the SOFA scene graph as a mesh generation component. The generated grid can be used in conjunction with other components for further simulation tasks. **Practical Notes** The resolution parameter should be carefully chosen to balance between detail and computational efficiency. Triangle patterns affect the connectivity of the mesh, which may influence subsequent simulations or visualizations.
description
The `GridMeshCreator` is a SOFA component that procedurally generates a two-dimensional triangular grid mesh. It inherits from the `MeshLoader` class and creates vertices within a specified resolution range, translating coordinates from (0,0,0) to (1,1,0). The grid can be customized with different triangle patterns, including no triangles, alternate triangles, upward triangles, or downward triangles. This component interacts with other SOFA components through the `MeshLoader` interface and provides methods like `canLoad`, `doLoad`, and `doClearBuffers`. Users can configure the number of vertices in each direction using the `resolution` data field and choose a triangle pattern via the `trianglePattern` data field.
maths
The `GridMeshCreator` is a procedural mesh generator that creates a two-dimensional triangular grid within a specified resolution range. The coordinates of the vertices are normalized to span from (0,0,0) to (1,1,0). This component allows for customization through different triangle patterns and vertex resolutions. ### Key Mathematical Components: #### Vertex Generation: - **Resolution**: The `d_resolution` parameter specifies the number of vertices in each direction. Let \( numX \) be the number of vertices along the x-axis, and \( numY \) be the number of vertices along the y-axis. - Vertices are generated using a nested loop over the indices \((x, y)\), where \(0 \\(\leq x < numX\) and \(0 \\(\leq y < numY\). - The coordinates of each vertex are given by: \[ (x_{coord}, y_{coord}, z_{coord}) = \left(\frac{x}{numX-1}, \frac{y}{numY-1}, 0\right) \] #### Triangle Patterns: - **No Triangles**: Only quadrilaterals are created. - Quadrilateral vertices are defined by the four points: \\( (x,y), (x+1,y), (x+1,y+1), (x,y+1) \). - These quads cover the entire grid, and each quad is inserted into the mesh as a set of edges and faces. - **Alternate Triangles**: The triangles alternate based on the sum of vertex indices modulo 2: - For even sums: \\( (x,y), (x+1,y), (x+1,y+1) \) and \\( (x,y), (x+1,y+1), (x,y+1) \). - For odd sums: \\( (x,y), (x+1,y), (x,y+1) \) and \\( (x+1,y), (x+1,y+1), (x,y+1) \). - **Upward Triangles**: The triangles are oriented upward: - Triangle vertices: \\( (x,y), (x+1,y), (x+1,y+1) \) and \\( (x,y), (x+1,y+1), (x,y+1) \). - **Downward Triangles**: The triangles are oriented downward: - Triangle vertices: \\( (x,y), (x+1,y), (x,y+1) \) and \\( (x+1,y), (x+1,y+1), (x,y+1) \). #### Edge Handling: - To avoid redundant edges, a set `uniqueEdges` is used to store unique edges. - An edge `(a,b)` is considered the same as `(b,a)`, and only one instance of each edge is stored in the set. - For each triangle or quad added, its edges are checked for redundancy and added if not present. ### Summary: The `GridMeshCreator` component allows users to generate a custom triangular grid within a normalized coordinate system. The resolution and triangle patterns can be specified to tailor the mesh generation process according to specific requirements. This procedural generation is useful in simulation frameworks where precise control over initial geometry is necessary.
{
  "name": "GridMeshCreator",
  "main": {
    "name": "GridMeshCreator",
    "namespace": "sofa::component::io::mesh",
    "module": "Sofa.Component.IO.Mesh",
    "include": "sofa/component/io/mesh/GridMeshCreator.h",
    "doc": "Procedural creation of a two-dimensional mesh.\n\nProcedurally creates a triangular grid.\n  The coordinates range from (0,0,0) to (1,1,0). They can be translated, rotated and scaled using the corresponding attributes of the parent class.\n  @author François Faure, 2012",
    "inherits": [
      "MeshLoader"
    ],
    "templates": [],
    "data_fields": [
      {
        "name": "d_resolution",
        "type": "type::Vec2i",
        "xmlname": "resolution",
        "help": "Number of vertices in each direction"
      },
      {
        "name": "d_trianglePattern",
        "type": "int",
        "xmlname": "trianglePattern",
        "help": "0: no triangles, 1: alternate triangles, 2: upward triangles, 3: downward triangles"
      }
    ],
    "links": [],
    "methods": [
      {
        "name": "type",
        "return_type": "int",
        "params": [],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "canLoad",
        "return_type": "bool",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "doLoad",
        "return_type": "bool",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "public"
      },
      {
        "name": "doClearBuffers",
        "return_type": "void",
        "params": [],
        "is_virtual": true,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      },
      {
        "name": "vert",
        "return_type": "unsigned int",
        "params": [
          {
            "name": "x",
            "type": "unsigned int"
          },
          {
            "name": "y",
            "type": "unsigned int"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      },
      {
        "name": "insertUniqueEdge",
        "return_type": "void",
        "params": [
          {
            "name": "a",
            "type": "unsigned int"
          },
          {
            "name": "b",
            "type": "unsigned int"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      },
      {
        "name": "insertTriangle",
        "return_type": "void",
        "params": [
          {
            "name": "a",
            "type": "unsigned int"
          },
          {
            "name": "b",
            "type": "unsigned int"
          },
          {
            "name": "c",
            "type": "unsigned int"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      },
      {
        "name": "insertQuad",
        "return_type": "void",
        "params": [
          {
            "name": "a",
            "type": "unsigned int"
          },
          {
            "name": "b",
            "type": "unsigned int"
          },
          {
            "name": "c",
            "type": "unsigned int"
          },
          {
            "name": "d",
            "type": "unsigned int"
          }
        ],
        "is_virtual": false,
        "is_pure_virtual": false,
        "is_static": false,
        "access": "protected"
      }
    ]
  },
  "desc": {
    "description": "The `GridMeshCreator` is a SOFA component that procedurally generates a two-dimensional triangular grid mesh. It inherits from the `MeshLoader` class and creates vertices within a specified resolution range, translating coordinates from (0,0,0) to (1,1,0). The grid can be customized with different triangle patterns, including no triangles, alternate triangles, upward triangles, or downward triangles. This component interacts with other SOFA components through the `MeshLoader` interface and provides methods like `canLoad`, `doLoad`, and `doClearBuffers`. Users can configure the number of vertices in each direction using the `resolution` data field and choose a triangle pattern via the `trianglePattern` data field."
  },
  "maths": {
    "maths": "The `GridMeshCreator` is a procedural mesh generator that creates a two-dimensional triangular grid within a specified resolution range. The coordinates of the vertices are normalized to span from (0,0,0) to (1,1,0). This component allows for customization through different triangle patterns and vertex resolutions.\n\n### Key Mathematical Components:\n\n#### Vertex Generation:\n- **Resolution**: The `d_resolution` parameter specifies the number of vertices in each direction. Let \\( numX \\) be the number of vertices along the x-axis, and \\( numY \\) be the number of vertices along the y-axis.\n  - Vertices are generated using a nested loop over the indices \\((x, y)\\), where \\(0 \\\\(\\leq x < numX\\) and \\(0 \\\\(\\leq y < numY\\).\n  - The coordinates of each vertex are given by:\n    \\[\n    (x_{coord}, y_{coord}, z_{coord}) = \\left(\\frac{x}{numX-1}, \\frac{y}{numY-1}, 0\\right)\n    \\]\n\n#### Triangle Patterns:\n- **No Triangles**: Only quadrilaterals are created.\n  - Quadrilateral vertices are defined by the four points: \\\\( (x,y), (x+1,y), (x+1,y+1), (x,y+1) \\).\n  - These quads cover the entire grid, and each quad is inserted into the mesh as a set of edges and faces.\n\n- **Alternate Triangles**: The triangles alternate based on the sum of vertex indices modulo 2:\n  - For even sums: \\\\( (x,y), (x+1,y), (x+1,y+1) \\) and \\\\( (x,y), (x+1,y+1), (x,y+1) \\).\n  - For odd sums: \\\\( (x,y), (x+1,y), (x,y+1) \\) and \\\\( (x+1,y), (x+1,y+1), (x,y+1) \\).\n\n- **Upward Triangles**: The triangles are oriented upward:\n  - Triangle vertices: \\\\( (x,y), (x+1,y), (x+1,y+1) \\) and \\\\( (x,y), (x+1,y+1), (x,y+1) \\).\n\n- **Downward Triangles**: The triangles are oriented downward:\n  - Triangle vertices: \\\\( (x,y), (x+1,y), (x,y+1) \\) and \\\\( (x+1,y), (x+1,y+1), (x,y+1) \\).\n\n#### Edge Handling:\n- To avoid redundant edges, a set `uniqueEdges` is used to store unique edges.\n  - An edge `(a,b)` is considered the same as `(b,a)`, and only one instance of each edge is stored in the set.\n  - For each triangle or quad added, its edges are checked for redundancy and added if not present.\n\n### Summary:\nThe `GridMeshCreator` component allows users to generate a custom triangular grid within a normalized coordinate system. The resolution and triangle patterns can be specified to tailor the mesh generation process according to specific requirements. This procedural generation is useful in simulation frameworks where precise control over initial geometry is necessary."
  },
  "summary": {
    "abstract": "The `GridMeshCreator` procedurally generates a two-dimensional triangular grid within a specified resolution range, allowing customization through different triangle patterns.",
    "sheet": "# GridMeshCreator\n\n**Overview**\n\nThe `GridMeshCreator` is a SOFA component that procedurally generates a two-dimensional triangular grid mesh. It inherits from the `MeshLoader` class and creates vertices within a normalized coordinate system spanning from (0,0,0) to (1,1,0). The grid can be customized with different triangle patterns: no triangles, alternate triangles, upward triangles, or downward triangles.\n\n**Parameters and Data**\n\n- **resolution**: `type::Vec2i` - Specifies the number of vertices in each direction. Default is not specified.\n- **trianglePattern**: `int` - Determines the type of triangle pattern to be used: 0 (no triangles), 1 (alternate triangles), 2 (upward triangles), or 3 (downward triangles). Default is not specified.\n\n**Dependencies and Connections**\n\nThe `GridMeshCreator` inherits from the `MeshLoader` class, which provides methods like `canLoad`, `doLoad`, and `doClearBuffers`. It does not have specific dependencies but fits into the SOFA scene graph as a mesh generation component. The generated grid can be used in conjunction with other components for further simulation tasks.\n\n**Practical Notes**\n\nThe resolution parameter should be carefully chosen to balance between detail and computational efficiency. Triangle patterns affect the connectivity of the mesh, which may influence subsequent simulations or visualizations."
  }
}