Lagrange
Eigen views

View mesh attributes as Eigen matrices. More...

Typedefs

template<typename Scalar >
using RowMatrix = Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >
 Type alias for row-major Eigen matrices.
 
template<typename Scalar >
using RowMatrixView = Eigen::Map< RowMatrix< Scalar >, Eigen::Unaligned >
 Type alias for row-major matrix views.
 
template<typename Scalar >
using ConstRowMatrixView = const Eigen::Map< const RowMatrix< Scalar >, Eigen::Unaligned >
 Type alias for row-major const matrix view.
 
template<typename Scalar >
using Vector = Eigen::Matrix< Scalar, Eigen::Dynamic, 1 >
 Type alias for one-dimensional column Eigen vectors.
 
template<typename Scalar >
using VectorView = Eigen::Map< Vector< Scalar >, Eigen::Unaligned >
 Type alias for row-major vector view.
 
template<typename Scalar >
using ConstVectorView = const Eigen::Map< const Vector< Scalar >, Eigen::Unaligned >
 Type alias for row-major const vector view.
 

Generic attribute views

template<typename ValueType >
RowMatrixView< ValueType > matrix_ref (Attribute< ValueType > &attribute)
 Returns a writable view of a given attribute in the form of an Eigen matrix. More...
 
template<typename ValueType >
ConstRowMatrixView< ValueType > matrix_view (const Attribute< ValueType > &attribute)
 Returns a read-only view of a given attribute in the form of an Eigen matrix. More...
 
template<typename ValueType >
VectorView< ValueType > vector_ref (Attribute< ValueType > &attribute)
 Returns a writable view of a scalar attribute in the form of an Eigen vector. More...
 
template<typename ValueType >
ConstVectorView< ValueType > vector_view (const Attribute< ValueType > &attribute)
 Returns a read-only view of a scalar attribute in the form of an Eigen vector. More...
 
template<typename ValueType >
RowMatrixView< ValueType > reshaped_ref (Attribute< ValueType > &attribute, size_t num_cols)
 Returns a writable view of a given single-channel attribute in the form of an Eigen matrix with a prescribed number of columns. More...
 
template<typename ValueType >
ConstRowMatrixView< ValueType > reshaped_view (const Attribute< ValueType > &attribute, size_t num_cols)
 Returns a read-only view of a given single-channel attribute in the form of an Eigen matrix with a prescribed number of columns. More...
 

Generic attribute views (mesh)

template<typename ValueType , typename Scalar , typename Index >
RowMatrixView< ValueType > attribute_matrix_ref (SurfaceMesh< Scalar, Index > &mesh, std::string_view name)
 Returns a writable view of a mesh attribute in the form of an Eigen matrix. More...
 
template<typename ValueType , typename Scalar , typename Index >
RowMatrixView< ValueType > attribute_matrix_ref (SurfaceMesh< Scalar, Index > &mesh, AttributeId id)
 Returns a writable view of a mesh attribute in the form of an Eigen matrix. More...
 
template<typename ValueType , typename Scalar , typename Index >
ConstRowMatrixView< ValueType > attribute_matrix_view (const SurfaceMesh< Scalar, Index > &mesh, std::string_view name)
 Returns a read-only view of a mesh attribute in the form of an Eigen matrix. More...
 
template<typename ValueType , typename Scalar , typename Index >
ConstRowMatrixView< ValueType > attribute_matrix_view (const SurfaceMesh< Scalar, Index > &mesh, AttributeId id)
 Returns a read-only view of a mesh attribute in the form of an Eigen matrix. More...
 
template<typename ValueType , typename Scalar , typename Index >
VectorView< ValueType > attribute_vector_ref (SurfaceMesh< Scalar, Index > &mesh, std::string_view name)
 Returns a writable view of a mesh attribute in the form of an Eigen vector. More...
 
template<typename ValueType , typename Scalar , typename Index >
VectorView< ValueType > attribute_vector_ref (SurfaceMesh< Scalar, Index > &mesh, AttributeId id)
 Returns a writable view of a mesh attribute in the form of an Eigen vector. More...
 
template<typename ValueType , typename Scalar , typename Index >
ConstVectorView< ValueType > attribute_vector_view (const SurfaceMesh< Scalar, Index > &mesh, std::string_view name)
 Returns a read-only view of a mesh attribute in the form of an Eigen vector. More...
 
template<typename ValueType , typename Scalar , typename Index >
ConstVectorView< ValueType > attribute_vector_view (const SurfaceMesh< Scalar, Index > &mesh, AttributeId id)
 Returns a read-only view of a mesh attribute in the form of an Eigen vector. More...
 

Specific attribute views

template<typename Scalar , typename Index >
RowMatrixView< Scalar > vertex_ref (SurfaceMesh< Scalar, Index > &mesh)
 Returns a writable view of the mesh vertices in the form of an Eigen matrix. More...
 
template<typename Scalar , typename Index >
ConstRowMatrixView< Scalar > vertex_view (const SurfaceMesh< Scalar, Index > &mesh)
 Returns a read-only view of the mesh vertices in the form of an Eigen matrix. More...
 
template<typename Scalar , typename Index >
RowMatrixView< Index > facet_ref (SurfaceMesh< Scalar, Index > &mesh)
 Returns a writable view of a mesh facets in the form of an Eigen matrix. More...
 
template<typename Scalar , typename Index >
ConstRowMatrixView< Index > facet_view (const SurfaceMesh< Scalar, Index > &mesh)
 Returns a read-only view of a mesh facets in the form of an Eigen matrix. More...
 

Detailed Description

View mesh attributes as Eigen matrices.

Mesh attributes such as positions and facet indices can be views as Eigen matrices. Specifically, we provide read-only views as Eigen::Map<const ...>:

#include <lagrange/SurfaceMesh.h>
#include <lagrange/views.h>
#include <igl/massmatrix.h>
// Fill up mesh data...
// With ADL, no need to prefix by lagrange::
auto V_view = vertex_view(mesh);
auto F_view = facet_view(mesh);
// Call your favorite libigl function
Eigen::SparseMatrix<Scalar> M;
igl::massmatrix(V_view, F_view, igl::MASSMATRIX_TYPE_VORONOI, M);
ConstRowMatrixView< Scalar > vertex_view(const SurfaceMesh< Scalar, Index > &mesh)
Returns a read-only view of the mesh vertices in the form of an Eigen matrix.
Definition: views.cpp:156
ConstRowMatrixView< Index > facet_view(const SurfaceMesh< Scalar, Index > &mesh)
Returns a read-only view of a mesh facets in the form of an Eigen matrix.
Definition: views.cpp:170

Writable reference are also available:

// Writable reference, creates a copy if buffer is not uniquely owned
auto V_ref = vertex_ref(mesh);
auto F_ref = facet_ref(mesh);
// Center mesh around vertex barycenter
V_ref.rowwise() -= V_ref.colwise().mean();
RowMatrixView< Scalar > vertex_ref(SurfaceMesh< Scalar, Index > &mesh)
Returns a writable view of the mesh vertices in the form of an Eigen matrix.
Definition: views.cpp:150
RowMatrixView< Index > facet_ref(SurfaceMesh< Scalar, Index > &mesh)
Returns a writable view of a mesh facets in the form of an Eigen matrix.
Definition: views.cpp:162

Function Documentation

◆ matrix_ref()

RowMatrixView< ValueType > matrix_ref ( Attribute< ValueType > &  attribute)

#include <lagrange/views.h>

Returns a writable view of a given attribute in the form of an Eigen matrix.

Parameters
[in]attributeAttribute to view.
Template Parameters
ValueTypeAttribute scalar type.
Returns
An Eigen::Map wrapping the attribute data.

◆ matrix_view()

ConstRowMatrixView< ValueType > matrix_view ( const Attribute< ValueType > &  attribute)

#include <lagrange/views.h>

Returns a read-only view of a given attribute in the form of an Eigen matrix.

Parameters
[in]attributeAttribute to view.
Template Parameters
ValueTypeAttribute scalar type.
Returns
An Eigen::Map wrapping the attribute data.

◆ vector_ref()

VectorView< ValueType > vector_ref ( Attribute< ValueType > &  attribute)

#include <lagrange/views.h>

Returns a writable view of a scalar attribute in the form of an Eigen vector.

The attribute must have exactly one channel.

Parameters
[in]attributeAttribute to view.
Template Parameters
ValueTypeAttribute scalar type.
Returns
An Eigen::Map wrapping the attribute data.

◆ vector_view()

ConstVectorView< ValueType > vector_view ( const Attribute< ValueType > &  attribute)

#include <lagrange/views.h>

Returns a read-only view of a scalar attribute in the form of an Eigen vector.

The attribute must have exactly one channel.

Parameters
[in]attributeAttribute to view.
Template Parameters
ValueTypeAttribute scalar type.
Returns
An Eigen::Map wrapping the attribute data.

◆ reshaped_ref()

RowMatrixView< ValueType > reshaped_ref ( Attribute< ValueType > &  attribute,
size_t  num_cols 
)

#include <lagrange/views.h>

Returns a writable view of a given single-channel attribute in the form of an Eigen matrix with a prescribed number of columns.

This is useful to view arbitrary corner attributes as 2D matrices for regular meshes.

Parameters
[in]attributeAttribute to view.
[in]num_colsNumber of columns to use. It must divide the number of elements of the prescribed attribute.
Template Parameters
ValueTypeAttribute scalar type.
Returns
An Eigen::Map wrapping the attribute data.

◆ reshaped_view()

ConstRowMatrixView< ValueType > reshaped_view ( const Attribute< ValueType > &  attribute,
size_t  num_cols 
)

#include <lagrange/views.h>

Returns a read-only view of a given single-channel attribute in the form of an Eigen matrix with a prescribed number of columns.

This is useful to view arbitrary corner attributes as 2D matrices for regular meshes.

Parameters
[in]attributeAttribute to view.
[in]num_colsNumber of columns to use. It must divide the number of elements of the prescribed attribute.
Template Parameters
ValueTypeAttribute scalar type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_matrix_ref() [1/2]

RowMatrixView< ValueType > attribute_matrix_ref ( SurfaceMesh< Scalar, Index > &  mesh,
std::string_view  name 
)

#include <lagrange/views.h>

Returns a writable view of a mesh attribute in the form of an Eigen matrix.

Parameters
[in]meshMesh whose attribute to view.
[in]nameName of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_matrix_ref() [2/2]

RowMatrixView< ValueType > attribute_matrix_ref ( SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  id 
)

#include <lagrange/views.h>

Returns a writable view of a mesh attribute in the form of an Eigen matrix.

Parameters
[in]meshMesh whose attribute to view.
[in]idId of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_matrix_view() [1/2]

ConstRowMatrixView< ValueType > attribute_matrix_view ( const SurfaceMesh< Scalar, Index > &  mesh,
std::string_view  name 
)

#include <lagrange/views.h>

Returns a read-only view of a mesh attribute in the form of an Eigen matrix.

Parameters
[in]meshMesh whose attribute to view.
[in]nameName of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_matrix_view() [2/2]

ConstRowMatrixView< ValueType > attribute_matrix_view ( const SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  id 
)

#include <lagrange/views.h>

Returns a read-only view of a mesh attribute in the form of an Eigen matrix.

Parameters
[in]meshMesh whose attribute to view.
[in]idId of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_vector_ref() [1/2]

VectorView< ValueType > attribute_vector_ref ( SurfaceMesh< Scalar, Index > &  mesh,
std::string_view  name 
)

#include <lagrange/views.h>

Returns a writable view of a mesh attribute in the form of an Eigen vector.

The attribute must have exactly one channel.

Parameters
[in]meshMesh whose attribute to view.
[in]nameName of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_vector_ref() [2/2]

VectorView< ValueType > attribute_vector_ref ( SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  id 
)

#include <lagrange/views.h>

Returns a writable view of a mesh attribute in the form of an Eigen vector.

The attribute must have exactly one channel.

Parameters
[in]meshMesh whose attribute to view.
[in]idId of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_vector_view() [1/2]

ConstVectorView< ValueType > attribute_vector_view ( const SurfaceMesh< Scalar, Index > &  mesh,
std::string_view  name 
)

#include <lagrange/views.h>

Returns a read-only view of a mesh attribute in the form of an Eigen vector.

The attribute must have exactly one channel.

Parameters
[in]meshMesh whose attribute to view.
[in]nameName of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ attribute_vector_view() [2/2]

ConstVectorView< ValueType > attribute_vector_view ( const SurfaceMesh< Scalar, Index > &  mesh,
AttributeId  id 
)

#include <lagrange/views.h>

Returns a read-only view of a mesh attribute in the form of an Eigen vector.

The attribute must have exactly one channel.

Parameters
[in]meshMesh whose attribute to view.
[in]idId of the mesh attribute to view.
Template Parameters
ValueTypeAttribute scalar type.
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ vertex_ref()

RowMatrixView< Scalar > vertex_ref ( SurfaceMesh< Scalar, Index > &  mesh)

#include <lagrange/views.h>

Returns a writable view of the mesh vertices in the form of an Eigen matrix.

Parameters
[in]meshMesh whose vertices to view.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ vertex_view()

ConstRowMatrixView< Scalar > vertex_view ( const SurfaceMesh< Scalar, Index > &  mesh)

#include <lagrange/views.h>

Returns a read-only view of the mesh vertices in the form of an Eigen matrix.

Parameters
[in]meshMesh whose vertices to view.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ facet_ref()

RowMatrixView< Index > facet_ref ( SurfaceMesh< Scalar, Index > &  mesh)

#include <lagrange/views.h>

Returns a writable view of a mesh facets in the form of an Eigen matrix.

This function only works for regular meshes. If the mesh does not have a fixed facet size, an exception is thrown.

Parameters
[in]meshMesh whose facets to view.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.

◆ facet_view()

ConstRowMatrixView< Index > facet_view ( const SurfaceMesh< Scalar, Index > &  mesh)

#include <lagrange/views.h>

Returns a read-only view of a mesh facets in the form of an Eigen matrix.

This function only works for regular meshes. If the mesh does not have a fixed facet size, an exception is thrown.

Parameters
[in]meshMesh whose facets to view.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
An Eigen::Map wrapping the attribute data.