Managing Attributes
This section explains how to define, check, and remove attributes in RXMeshStatic. Attributes in RXMesh are strongly typed and always associated with a specific mesh element (vertex, edge, or face). You can create attributes from scratch, load them from data in memory, or copy the shape and layout from an existing attribute.
For manipulating attribute values, i.e., access, memory movement, or math, see the Working with Attributes section.
Adding Attributes
Attribute names must be unique across all vertex, edge, and face attributes in the same RXMeshStatic instance.
From Scratch
Used when you want to allocate a new attribute with no initial values. You specify the number of values per element, where they should be allocated (host/device), and the layout (SoA or AoS).
rx.add_vertex_attribute<float>("vColor", 3); // RGB color
rx.add_edge_attribute<int>("eFlags", 1); // One integer flag per edge
rx.add_face_attribute<double>("area", 1); // Scalar per face
add_vertex_attribute<T>(name, num_attributes, location, layout)
Allocates a new vertex attribute with num_attributes components per vertex. location selects host, device, or both; layout is SoA or AoS.
add_edge_attribute<T>(name, num_attributes, location, layout)
Same as the vertex variant, but storage is indexed by edges.
add_face_attribute<T>(name, num_attributes, location, layout)
Same as the vertex variant, but storage is indexed by faces.
add_attribute<T, HandleT>(...)
Generic overload: HandleT is VertexHandle, EdgeHandle, or FaceHandle, which selects the element type.
From Existing Data
Used when you already have attribute values stored in memory (e.g., parsed from a file or generated by preprocessing).
// Per-vertex 3D coordinates
std::vector<std::vector<float>> coords = ...;
rx.add_vertex_attribute(coords, "vertex_positions");
// Per-face scalar value
std::vector<int> face_labels = ...;
rx.add_face_attribute(face_labels, "fLabels");
add_vertex_attribute<T>(std::vector<std::vector<T>>, name, layout)
Load per-vertex data from a nested vector: one inner vector per vertex (e.g., 3D positions). layout controls SoA vs AoS.
add_face_attribute<T>(std::vector<std::vector<T>>, name, layout)
Load per-face data from a nested vector: one inner vector per face.
add_vertex_attribute<T>(std::vector<T>, name, layout)
Load a flat scalar per vertex (one value per vertex index).
add_face_attribute<T>(std::vector<T>, name, layout)
Load a flat scalar per face (one value per face index).
These methods copy the input data to both host and device and allocate storage accordingly.
From Existing Attribute (Same Shape)
Used when you want to allocate an attribute that has the same layout, memory location, and shape as an existing one.
add_vertex_attribute_like<T>(name, other)
Allocate a new vertex attribute with the same shape, layout, and locations as other.
add_edge_attribute_like<T>(name, other)
Same as the vertex variant, but for edge attributes.
add_face_attribute_like<T>(name, other)
Same as the vertex variant, but for face attributes.
add_attribute_like<T, HandleT>(name, other)
Generic version: HandleT determines the element type; other supplies the template for shape and layout.
Built-in Attributes
In addition to user-created attributes, RXMeshStatic also provides built-in mesh attributes.
get_input_vertex_coordinates()
Returns std::shared_ptr<VertexAttribute<rx_coord_t>> containing the input vertex coordinates.
When the input is provided as multiple meshes, RXMesh assigns a region index to each input mesh. Region label attributes store this index on faces, edges, and vertices, so you can track which original mesh component each element belongs to.
get_face_region_label()
Returns std::shared_ptr<FaceAttribute<int>> for per-face region labels.
get_edge_region_label()
Returns std::shared_ptr<EdgeAttribute<int>> for per-edge region labels.
get_vertex_region_label()
Returns std::shared_ptr<VertexAttribute<int>> for per-vertex region labels.
get_region_label<HandleT>()
Generic region-label accessor. HandleT can be VertexHandle, EdgeHandle, or FaceHandle.
get_num_regions() const
Returns the number of regions represented by the built-in label attributes.
Checking for Existence
To check if an attribute with a given name is already defined:
does_attribute_exist(name)
Returns true if an attribute with the given name is registered on the mesh.
Removing Attributes
To delete an attribute from RXMesh and release its memory:
remove_attribute(name)
Removes the attribute named name from RXMesh and releases its storage.