Lagrange
Attributes utilities

Various attribute processing utilities. More...

Classes

struct  WeldOptions
 Options for welding indexed attributes. More...
 

Functions

template<typename Scalar , typename Index >
void weld_indexed_attribute (SurfaceMesh< Scalar, Index > &mesh, AttributeId attr_id, const WeldOptions &options={})
 Weld an indexed attribute by combining all corners around a vertex with the same attribute value. More...
 

Attribute remapping

Mapping attributes between different element types.

  • When mapping indexed to value attributes, values are duplicated for each corner, since otherwise the mapping corner -> value would be lost.
  • When mapping value to indexed attributes, the size of the value buffer must be equal to the number of corners. The values are not deduplicated in the new indexed attribute.
template<typename Scalar , typename Index >
AttributeId map_attribute (SurfaceMesh< Scalar, Index > &mesh, AttributeId id, std::string_view new_name, AttributeElement new_element)
 Map attribute values to a new attribute with a different element type. More...
 
template<typename Scalar , typename Index >
AttributeId map_attribute (SurfaceMesh< Scalar, Index > &mesh, std::string_view old_name, std::string_view new_name, AttributeElement new_element)
 Map attribute values to a new attribute with a different element type. More...
 
template<typename Scalar , typename Index >
AttributeId map_attribute_in_place (SurfaceMesh< Scalar, Index > &mesh, AttributeId id, AttributeElement new_element)
 Map attribute values to a different element type. More...
 
template<typename Scalar , typename Index >
AttributeId map_attribute_in_place (SurfaceMesh< Scalar, Index > &mesh, std::string_view name, AttributeElement new_element)
 Map attribute values to a different element type. More...
 

Index buffer unification

template<typename Scalar , typename Index >
SurfaceMesh< Scalar, Index > unify_index_buffer (const SurfaceMesh< Scalar, Index > &mesh, const std::vector< AttributeId > &attribute_ids={})
 Unify index buffers of the input mesh for all attributes specified in attribute_ids. More...
 
template<typename Scalar , typename Index >
SurfaceMesh< Scalar, Index > unify_named_index_buffer (const SurfaceMesh< Scalar, Index > &mesh, const std::vector< std::string_view > &attribute_names)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 

Detailed Description

Various attribute processing utilities.

Function Documentation

◆ map_attribute() [1/2]

AttributeId map_attribute ( SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  id,
std::string_view  new_name,
AttributeElement  new_element 
)

#include <lagrange/map_attribute.h>

Map attribute values to a new attribute with a different element type.

If the input attribute is a value attribute, its number of rows must match the number of target mesh element (or number of corners if the target is an indexed attribute).

Parameters
[in,out]meshInput mesh. Modified to add a new attribute.
[in]idId of the input attribute to map.
[in]new_nameName of the new mesh attribute to create.
[in]new_elementNew attribute element type.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
Id of the newly created attribute.

◆ map_attribute() [2/2]

AttributeId map_attribute ( SurfaceMesh< Scalar, Index > &  mesh,
std::string_view  old_name,
std::string_view  new_name,
AttributeElement  new_element 
)

#include <lagrange/map_attribute.h>

Map attribute values to a new attribute with a different element type.

If the input attribute is a value attribute, its number of rows must match the number of target mesh element (or number of corners if the target is an indexed attribute).

Parameters
[in,out]meshInput mesh. Modified to add a new attribute.
[in]old_nameName of the input attribute to map.
[in]new_nameName of the new mesh attribute to create.
[in]new_elementNew attribute element type.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
Id of the newly created attribute.

◆ map_attribute_in_place() [1/2]

AttributeId map_attribute_in_place ( SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  id,
AttributeElement  new_element 
)

#include <lagrange/map_attribute.h>

Map attribute values to a different element type.

A new attribute with the new element type is created with the same name as the old one, and the old one is removed. If the input attribute is a value attribute, its number of rows must match the number of target mesh element (or number of corners if the target is an indexed attribute).

Todo:
To be truly in-place ideally the new AttributeId should be the same as the old one.
Parameters
[in,out]meshInput mesh. Modified to add a new attribute.
[in]idId of the input attribute to map.
[in]new_elementNew attribute element type.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
Id of the modified attribute.

◆ map_attribute_in_place() [2/2]

AttributeId map_attribute_in_place ( SurfaceMesh< Scalar, Index > &  mesh,
std::string_view  name,
AttributeElement  new_element 
)

#include <lagrange/map_attribute.h>

Map attribute values to a different element type.

A new attribute with the new element type is created with the same name as the old one, and the old one is removed. If the input attribute is a value attribute, its number of rows must match the number of target mesh element (or number of corners if the target is an indexed attribute).

Todo:
To be truly in-place ideally the new AttributeId should be the same as the old one.
Parameters
[in,out]meshInput mesh. Modified to add a new attribute.
[in]nameName of the attribute to map.
[in]new_elementNew attribute element type.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
Id of the modified attribute.

◆ unify_index_buffer()

SurfaceMesh< Scalar, Index > unify_index_buffer ( const SurfaceMesh< Scalar, Index > &  mesh,
const std::vector< AttributeId > &  attribute_ids = {} 
)

#include <lagrange/unify_index_buffer.h>

Unify index buffers of the input mesh for all attributes specified in attribute_ids.

Postcondition
The attributes specified by attribute_id will become vertex attributes in the output mesh under the same names.
Parameters
[in]meshThe input polygonal mesh.
[in]attribute_idsThe input indexed attribute ids to be unified. If empty, all indexed attributes are unified.
Returns
A polygonal mesh with unified indices for position and attributes specified in attribute_ids.

◆ unify_named_index_buffer()

SurfaceMesh< Scalar, Index > unify_named_index_buffer ( const SurfaceMesh< Scalar, Index > &  mesh,
const std::vector< std::string_view > &  attribute_names 
)

#include <lagrange/unify_index_buffer.h>

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]meshThe input polygonal mesh.
[in]attribute_namesThe input indexed attribute names to be unified. If empty, all indexed attributes are unified.
Returns
A polygonal mesh with unified indices for position and attributes specified in attribute_names.
See also
unify_index_buffer(const SurfaceMesh<Scalar, Index>&, const std::vector<AttributeId>&) for more info.

◆ weld_indexed_attribute()

void weld_indexed_attribute ( SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  attr_id,
const WeldOptions options = {} 
)

#include <lagrange/weld_indexed_attribute.h>

Weld an indexed attribute by combining all corners around a vertex with the same attribute value.

Template Parameters
ScalarThe mesh scalar type.
IndexThe mesh index type.
Parameters
meshThe source mesh.
attr_idThe indexed attribute id.