Lagrange
Loading...
Searching...
No Matches
Attributes utilities

Various attribute processing utilities. More...

Classes

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

Functions

template<typename ValueType, typename Index, typename Predicate>
void set_predicated_indexed_values (IndexedAttribute< ValueType, Index > &attr, Predicate &&predicate)
 For each index matching the given predicate, appends a new value set to invalid<ValueType>() and reassigns the index to point to it.
 
template<typename ValueType, typename Index>
void set_invalid_indexed_values (IndexedAttribute< ValueType, Index > &attr)
 For each element in the index buffer set to invalid<Index>(), appends a new value set to invalid<ValueType>() and updates the index to point to it.
 
template<typename ValueType, typename Index>
void set_out_of_range_indexed_values (IndexedAttribute< ValueType, Index > &attr)
 For each element in the index buffer pointing outside the value buffer, appends a new value set to invalid<ValueType>() and updates the index to point to it.
 
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.
 

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.
 
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.
 
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.
 
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.
 

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.
 
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.
 

Detailed Description

Various attribute processing utilities.

Function Documentation

◆ set_predicated_indexed_values()

template<typename ValueType, typename Index, typename Predicate>
void set_predicated_indexed_values ( IndexedAttribute< ValueType, Index > & attr,
Predicate && predicate )

#include <lagrange/internal/set_indexed_values.h>

For each index matching the given predicate, appends a new value set to invalid<ValueType>() and reassigns the index to point to it.

Parameters
[in,out]attrThe indexed attribute to fix up.
[in]predicateReturns true for each index that must be remapped.
Template Parameters
ValueTypeAttribute value type.
IndexAttribute index type.
PredicateCallable of signature bool(Index).

◆ set_invalid_indexed_values()

template<typename ValueType, typename Index>
void set_invalid_indexed_values ( IndexedAttribute< ValueType, Index > & attr)

#include <lagrange/internal/set_indexed_values.h>

For each element in the index buffer set to invalid<Index>(), appends a new value set to invalid<ValueType>() and updates the index to point to it.

Parameters
[in,out]attrThe indexed attribute to fix up.
Template Parameters
ValueTypeAttribute value type.
IndexAttribute index type.

◆ set_out_of_range_indexed_values()

template<typename ValueType, typename Index>
void set_out_of_range_indexed_values ( IndexedAttribute< ValueType, Index > & attr)

#include <lagrange/internal/set_indexed_values.h>

For each element in the index buffer pointing outside the value buffer, appends a new value set to invalid<ValueType>() and updates the index to point to it.

Parameters
[in,out]attrThe indexed attribute to fix up.
Template Parameters
ValueTypeAttribute value type.
IndexAttribute index type.

◆ map_attribute() [1/2]

template<typename Scalar, typename Index>
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]

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 )

#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]

template<typename Scalar, typename Index>
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]

template<typename Scalar, typename Index>
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()

template<typename Scalar, typename Index>
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.
See also
unify_named_index_buffer

◆ unify_named_index_buffer()

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 )

#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

◆ weld_indexed_attribute()

template<typename Scalar, typename Index>
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.
optionsWelding options (e.g. vertices to exclude).