Skip to content

shapeworks::MeshUtils

Module: Mesh Classes

More...

#include <MeshUtils.h>

Public Functions

Name
const vtkSmartPointer< vtkMatrix4x4 > createICPTransform(const Mesh source, const Mesh target, Mesh::AlignmentType align, const unsigned iterations =20, bool meshTransform =false)
computes a rigid transformation from source to target using vtkIterativeClosestPointTransform
Mesh create_mesh_from_file(std::string filename, double iso_value =0.5)
Mesh from mesh or image file.
Mesh threadSafeReadMesh(std::string filename)
Thread safe reading of a mesh, uses a lock.
void threadSafeWriteMesh(std::string filename, Mesh mesh)
Thread safe writing of a mesh, uses a lock.
PhysicalRegion boundingBox(const std::vector< std::string > & filenames, bool center =false)
calculate bounding box incrementally for meshes
PhysicalRegion boundingBox(const std::vector< std::reference_wrapper< const Mesh > > & meshes, bool center =false)
calculate bounding box incrementally for meshes
PhysicalRegion boundingBox(const std::vector< Mesh > & meshes, bool center =false)
calculate bounding box incrementally for meshes
int findReferenceMesh(std::vector< Mesh > & meshes, int random_subset_size =-1)
determine the reference mesh
Mesh extract_boundary_loop(Mesh mesh)
boundary loop extractor for a given mesh
std::array< Mesh, 3 > shared_boundary_extractor(const Mesh & mesh_l, const Mesh & mesh_r, double tol)
shared boundary extractor for the left and right mesh
void generateNormals(const std::vector< std::reference_wrapper< Mesh > > & meshes, bool forceRegen =false)
generates and adds normals for points and faces for each mesh in given set of meshes
Field computeMeanNormals(const std::vector< std::string > & filenames, bool autoGenerateNormals =true)
computes average normals for each point in given set of meshes
Field computeMeanNormals(const std::vector< std::reference_wrapper< const Mesh > > & meshes)
computes average normals for each point in given set of meshes
int evaluate_triangle_position(const double x[3], double closestPoint[3], int & subId, double pcoords[3], double & dist2, double weights[], double pt3[3], double pt1[3], double pt2[3])
vtkSmartPointer< vtkPolyData > clean_mesh(vtkSmartPointer< vtkPolyData > mesh)
Clean mesh (merge points and remove degenerate cells)
vtkSmartPointer< vtkPolyData > remove_zero_area_triangles(vtkSmartPointer< vtkPolyData > mesh)
Remove zero area triangles from a mesh.
bool has_zero_area_triangles(vtkSmartPointer< vtkPolyData > mesh)
Return true if the mesh contains any (near) zero-area triangle.
vtkSmartPointer< vtkPolyData > recreate_mesh(vtkSmartPointer< vtkPolyData > mesh)
Recreate mesh, dropping deleted cells.
vtkSmartPointer< vtkPolyData > extract_largest_edge_connected_component(vtkSmartPointer< vtkPolyData > mesh)
vtkSmartPointer< vtkPolyData > repair_mesh(vtkSmartPointer< vtkPolyData > mesh, bool extract_largest =true)
bool is_contour(vtkSmartPointer< vtkPolyData > poly_data)
void transfer_point_data(vtkSmartPointer< vtkPolyData > source, vtkSmartPointer< vtkPolyData > target)
void visualizeVectorFieldForFFCs(std::shared_ptr< Mesh > mesh)
This function visualizes vector and scalar fields for FFCs.
vtkSmartPointer< vtkActor > getArrow(Eigen::Vector3d start, Eigen::Vector3d end)
Used as an auxiliary function for vector field visualizations.

Detailed Description

class shapeworks::MeshUtils;

This class provides helper functions for meshes

Public Functions Documentation

function createICPTransform

static const vtkSmartPointer< vtkMatrix4x4 > createICPTransform(
    const Mesh source,
    const Mesh target,
    Mesh::AlignmentType align,
    const unsigned iterations =20,
    bool meshTransform =false
)

computes a rigid transformation from source to target using vtkIterativeClosestPointTransform

function create_mesh_from_file

static Mesh create_mesh_from_file(
    std::string filename,
    double iso_value =0.5
)

Mesh from mesh or image file.

function threadSafeReadMesh

static Mesh threadSafeReadMesh(
    std::string filename
)

Thread safe reading of a mesh, uses a lock.

function threadSafeWriteMesh

static void threadSafeWriteMesh(
    std::string filename,
    Mesh mesh
)

Thread safe writing of a mesh, uses a lock.

function boundingBox

static PhysicalRegion boundingBox(
    const std::vector< std::string > & filenames,
    bool center =false
)

calculate bounding box incrementally for meshes

function boundingBox

static PhysicalRegion boundingBox(
    const std::vector< std::reference_wrapper< const Mesh > > & meshes,
    bool center =false
)

calculate bounding box incrementally for meshes

function boundingBox

static PhysicalRegion boundingBox(
    const std::vector< Mesh > & meshes,
    bool center =false
)

calculate bounding box incrementally for meshes

function findReferenceMesh

static int findReferenceMesh(
    std::vector< Mesh > & meshes,
    int random_subset_size =-1
)

determine the reference mesh

function extract_boundary_loop

static Mesh extract_boundary_loop(
    Mesh mesh
)

boundary loop extractor for a given mesh

function shared_boundary_extractor

static std::array< Mesh, 3 > shared_boundary_extractor(
    const Mesh & mesh_l,
    const Mesh & mesh_r,
    double tol
)

shared boundary extractor for the left and right mesh

function generateNormals

static void generateNormals(
    const std::vector< std::reference_wrapper< Mesh > > & meshes,
    bool forceRegen =false
)

generates and adds normals for points and faces for each mesh in given set of meshes

function computeMeanNormals

static Field computeMeanNormals(
    const std::vector< std::string > & filenames,
    bool autoGenerateNormals =true
)

computes average normals for each point in given set of meshes

function computeMeanNormals

static Field computeMeanNormals(
    const std::vector< std::reference_wrapper< const Mesh > > & meshes
)

computes average normals for each point in given set of meshes

function evaluate_triangle_position

static int evaluate_triangle_position(
    const double x[3],
    double closestPoint[3],
    int & subId,
    double pcoords[3],
    double & dist2,
    double weights[],
    double pt3[3],
    double pt1[3],
    double pt2[3]
)

function clean_mesh

static vtkSmartPointer< vtkPolyData > clean_mesh(
    vtkSmartPointer< vtkPolyData > mesh
)

Clean mesh (merge points and remove degenerate cells)

function remove_zero_area_triangles

static vtkSmartPointer< vtkPolyData > remove_zero_area_triangles(
    vtkSmartPointer< vtkPolyData > mesh
)

Remove zero area triangles from a mesh.

function has_zero_area_triangles

static bool has_zero_area_triangles(
    vtkSmartPointer< vtkPolyData > mesh
)

Return true if the mesh contains any (near) zero-area triangle.

function recreate_mesh

static vtkSmartPointer< vtkPolyData > recreate_mesh(
    vtkSmartPointer< vtkPolyData > mesh
)

Recreate mesh, dropping deleted cells.

function extract_largest_edge_connected_component

static vtkSmartPointer< vtkPolyData > extract_largest_edge_connected_component(
    vtkSmartPointer< vtkPolyData > mesh
)

Keep only the largest group of faces joined edge-to-edge, dropping any point left unused. vtkPolyDataConnectivityFilter joins faces that merely share a corner, so it cannot separate a scrap that hangs off the surface by a single vertex. Solvers that walk the mesh by its edges – igl::biharmonic_coordinates among them – see such a scrap as its own component and fail.

function repair_mesh

static vtkSmartPointer< vtkPolyData > repair_mesh(
    vtkSmartPointer< vtkPolyData > mesh,
    bool extract_largest =true
)

Repair mesh: triangulate, optionally extract largest component, clean, fix non-manifold, remove zero-area triangles

function is_contour

static bool is_contour(
    vtkSmartPointer< vtkPolyData > poly_data
)

Return true if the polydata is a contour (line cells) rather than a surface mesh (face cells). A surface mesh has polygon or triangle-strip cells; a contour has only line cells. This is more robust than inspecting the first cell, whose type/point-count can vary within a mesh.

function transfer_point_data

static void transfer_point_data(
    vtkSmartPointer< vtkPolyData > source,
    vtkSmartPointer< vtkPolyData > target
)

Carry the scalar fields of one mesh onto the points of another. Each target point takes the value interpolated across the closest triangle of the source, so the two meshes need not share a vertex count or a topology. Normals are not carried over: they describe the geometry, which is the part that changed.

function visualizeVectorFieldForFFCs

void visualizeVectorFieldForFFCs(
    std::shared_ptr< Mesh > mesh
)

This function visualizes vector and scalar fields for FFCs.

function getArrow

vtkSmartPointer< vtkActor > getArrow(
    Eigen::Vector3d start,
    Eigen::Vector3d end
)

Used as an auxiliary function for vector field visualizations.


Updated on 2026-10-11 at 04:33:09 +0000