### Test Installation Source: https://pymeshfix.pyvista.org/index.html Verify the installation using the built-in examples module. ```python from pymeshfix import examples # Test of pymeshfix without VTK module examples.native() # Performs same mesh repair while leveraging VTK's plotting/mesh loading examples.with_vtk() ``` -------------------------------- ### Install PyMeshFix Source: https://pymeshfix.pyvista.org/index.html Installation commands for PyMeshFix via pip or from source. ```bash pip install pymeshfix ``` ```bash git clone https://github.com/pyvista/pymeshfix cd pymeshfix pip install . ``` ```bash pip install pymeshfix[extras] ``` -------------------------------- ### Load and Visualize Torso Mesh Source: https://pymeshfix.pyvista.org/examples/torso.html Loads the example torso mesh and prints its properties. Use this to inspect the mesh before repair. ```python # sphinx_gallery_thumbnail_number = 2 import pyvista as pv from pyvista import examples import pymeshfix as mf mesh = examples.download_torso() print(mesh) ``` ```python PolyData (0x7f5d8912cee0) N Cells: 12448 N Points: 12015 N Strips: 0 X Bounds: -1.680e+02, 1.720e+02 Y Bounds: -1.624e+02, 1.320e+02 Z Bounds: -6.442e+02, 9.083e+01 N Arrays: 0 ``` ```python cpos = [(-1053.0, -1251.0, 83.0), (2.0, -15.0, -276.0), (0.12, 0.18, 1)] mesh.plot(color=True, show_edges=True, cpos=cpos) ``` -------------------------------- ### Load and Display Torso Mesh Source: https://pymeshfix.pyvista.org/_downloads/8c2304a7db3bb5ef65786189c6b6749c/torso.ipynb Loads the torso example mesh from PyVista and prints its information. This is the initial step before any mesh processing. ```python # sphinx_gallery_thumbnail_number = 2 import pyvista as pv from pyvista import examples import pymeshfix as mf mesh = examples.download_torso() print(mesh) ``` -------------------------------- ### Load and Visualize Bunny Mesh with Holes Source: https://pymeshfix.pyvista.org/_downloads/87ff65eb9bf4b89622fc5038dfb7623a/bunny.ipynb Load the bunny example mesh from PyVista and define a camera position to clearly show the holes. Visualize the mesh with eye-dome lighting and anti-aliasing. ```python bunny = examples.download_bunny() # Define a camera position that shows the holes in the mesh cpos = [(-0.2, -0.13, 0.12), (-0.015, 0.10, -0.0), (0.28, 0.26, 0.9)] # Show mesh bunny.plot(cpos=cpos, eye_dome_lighting=True, anti_aliasing=True, smooth_shading=True) ``` -------------------------------- ### Accessing Mesh Faces with MeshFix Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.faces.html Demonstrates initializing a MeshFix object from a PyVista example mesh and retrieving its face indices. ```python >>> from pyvista import examples >>> from pymeshfix import MeshFix >>> cow = examples.download_cow() >>> mfix = MeshFix(cow) >>> mfix.faces array([[ 210, 252, 251], [ 250, 251, 252], [ 201, 253, 210], ..., [1965, 2193, 2194], [2391, 2398, 970], [ 966, 961, 970]]) ``` -------------------------------- ### Load and Prepare Cow Mesh Source: https://pymeshfix.pyvista.org/_downloads/a765c73a2265f8a59b388228b14b1937/cow.ipynb Load the cow example mesh, add random cell data, and create a version with holes by thresholding and extracting geometry. The mesh is then triangulated. ```python cow = examples.download_cow() # Add holes and cast to triangulated PolyData cow["random"] = np.random.rand(cow.n_cells) cow_w_holes = cow.threshold(0.9, invert=True).extract_geometry().triangulate() print(cow_w_holes) ``` -------------------------------- ### Retrieve mesh points using MeshFix Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.points.html Demonstrates initializing a MeshFix object from a PyVista example mesh and accessing its points property. ```python >>> from pyvista import examples >>> from pymeshfix import MeshFix >>> cow = examples.download_cow() >>> mfix = MeshFix(cow) >>> mfix.points pyvista_ndarray([[3.71636 , 2.343387, 0. ], [4.126565, 0.642027, 0. ], [3.454971, 2.169877, 0. ], ..., [4.12616 , 2.12093 , 1.17252 ], [4.133175, 2.175231, 1.259323], [4.232341, 1.903079, 0.534362]], dtype=float32) ``` -------------------------------- ### Plot Mesh with Holes Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.plot.html Load an example mesh and plot it, showing mesh boundaries. Requires pyvista and pymeshfix libraries. ```python from pyvista import examples from pymeshfix import MeshFix mesh = examples.download_bunny() mfix = MeshFix(mesh) mfix.plot(show_holes=True) ``` -------------------------------- ### Import Libraries and Download Cow Mesh Source: https://pymeshfix.pyvista.org/_sources/examples/cow.rst.txt Imports necessary libraries and downloads the cow mesh example. This sets up the environment for mesh manipulation and repair. The cow mesh is then processed to add holes and triangulated. ```Python import numpy as np # sphinx_gallery_thumbnail_number = 1 import pyvista as pv from pyvista import examples import pymeshfix as mf ``` ```Python cow = examples.download_cow() # Add holes and cast to triangulated PolyData cow["random"] = np.random.rand(cow.n_cells) cow_w_holes = cow.threshold(0.9, invert=True).extract_geometry().triangulate() print(cow_w_holes) ``` -------------------------------- ### Accessing Mesh Points Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.points.html Demonstrates how to get the points (vertices) of a mesh using the `points` property of the `MeshFix` object. ```APIDOC ## GET MeshFix.points ### Description Retrieves the points (vertices) of the mesh as a NumPy ndarray. ### Method GET ### Endpoint MeshFix.points ### Parameters This is a property, not an endpoint with parameters. ### Request Example ```python from pyvista import examples from pymeshfix import MeshFix cow = examples.download_cow() mfix = MeshFix(cow) mesh_points = mfix.points print(mesh_points) ``` ### Response #### Success Response (200) - **points** (numpy.ndarray) - An array containing the coordinates of the mesh vertices. #### Response Example ```json { "points": [[3.71636, 2.343387, 0.0], [4.126565, 0.642027, 0.0], ...] } ``` ``` -------------------------------- ### Create MeshFix Object from PyVista Mesh Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.MeshFix.html Initialize a MeshFix object using a PyVista PolyData mesh. Ensure PyVista examples are available. ```python from pyvista import examples from pymeshfix import MeshFix cow = examples.download_cow() mfix = MeshFix(cow) ``` -------------------------------- ### GET PyTMesh.n_boundaries Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.n_boundaries.html Retrieves the count of boundary loops present in the mesh object. ```APIDOC ## GET PyTMesh.n_boundaries ### Description Returns the number of boundary loops in the mesh. ### Endpoint PyTMesh.n_boundaries ### Response #### Success Response (200) - **n_boundaries** (int) - The number of boundary loops in the mesh. ``` -------------------------------- ### GET PyTMesh.n_faces Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.n_faces.rst.txt Retrieves the total number of faces currently defined in the PyTMesh object. ```APIDOC ## GET PyTMesh.n_faces ### Description Returns the number of faces in the PyTMesh object. ### Method GET ### Endpoint PyTMesh.n_faces ### Response #### Success Response (200) - **n_faces** (int) - The total count of faces in the mesh. ``` -------------------------------- ### Clean Mesh from Arrays Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.clean_from_arrays.html Use this function to clean and repair a triangular surface mesh when you have vertex and face data as NumPy arrays. Ensure you have numpy and pymeshfix installed and the data loaded from files. ```python import pymeshfix import numpy as np points = np.load('points.npy') faces = np.load('faces.npy') clean_points, clean_faces = pymeshfix.clean_from_arrays(points, faces) ``` -------------------------------- ### Import Required Libraries Source: https://pymeshfix.pyvista.org/_downloads/0a2188cdc9ab9d0a467401debbe3ab17/repair_planar.ipynb Initializes the environment by importing NumPy, PyVista, and the PyMeshFix modules. ```python # sphinx_gallery_thumbnail_number = 1 import numpy as np import pyvista as pv from pymeshfix import PyTMesh from pymeshfix import MeshFix from pymeshfix import examples ``` -------------------------------- ### GET MeshFix.mesh Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.mesh.html Retrieves the surface mesh from a MeshFix object as a PolyData object. ```APIDOC ## GET MeshFix.mesh ### Description Returns the surface mesh associated with the MeshFix object. ### Response - **mesh** (pyvista.PolyData) - The surface mesh object. ``` -------------------------------- ### Repair a mesh using MeshFix Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.repair.html Demonstrates initializing a MeshFix object with a sample mesh and executing the default repair process with verbose output enabled. ```python >>> from pyvista import examples >>> from pymeshfix import MeshFix >>> mesh = examples.download_bunny() >>> mfix = MeshFix(mesh, verbose=True) >>> mfix.repair() >>> mfix.plot(show_holes=True) ``` -------------------------------- ### Load and Visualize Torso Mesh Source: https://pymeshfix.pyvista.org/_sources/examples/torso.rst.txt Initializes the PyVista environment and displays the raw torso mesh. ```Python # sphinx_gallery_thumbnail_number = 2 import pyvista as pv from pyvista import examples import pymeshfix as mf mesh = examples.download_torso() print(mesh) ``` ```Python cpos = [(-1053.0, -1251.0, 83.0), (2.0, -15.0, -276.0), (0.12, 0.18, 1)] mesh.plot(color=True, show_edges=True, cpos=cpos) ``` -------------------------------- ### Initialize MeshFix and access mesh Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.mesh.html Create a MeshFix object from a PyVista mesh and retrieve the underlying surface mesh. ```python >>> from pyvista import examples >>> from pymeshfix import MeshFix >>> cow = examples.download_cow() >>> mfix = MeshFix(cow) >>> mfix.mesh PolyData (0x7fa3c735f8e0) N Cells: 5804 N Points: 2903 N Strips: 0 X Bounds: -4.446e+00, 5.998e+00 Y Bounds: -3.637e+00, 2.760e+00 Z Bounds: -1.701e+00, 1.701e+00 N Arrays: 0 ``` -------------------------------- ### Plot Initial Torso Mesh Source: https://pymeshfix.pyvista.org/_downloads/8c2304a7db3bb5ef65786189c6b6749c/torso.ipynb Visualizes the loaded torso mesh with specified camera position and edge highlighting. This helps in understanding the initial state of the mesh. ```python cpos = [(-1053.0, -1251.0, 83.0), (2.0, -15.0, -276.0), (0.12, 0.18, 1)] mesh.plot(color=True, show_edges=True, cpos=cpos) ``` -------------------------------- ### PyTMesh.boundaries Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.boundaries.rst.txt Documentation for the PyTMesh.boundaries method. ```APIDOC ## PyTMesh.boundaries ### Description Retrieves the boundaries of the PyTMesh object. ### Method Method call ### Endpoint pymeshfix.PyTMesh.boundaries ``` -------------------------------- ### Initialize MeshFix and Extract Holes Source: https://pymeshfix.pyvista.org/_downloads/87ff65eb9bf4b89622fc5038dfb7623a/bunny.ipynb Create an instance of pymeshfix.MeshFix using the PyVista PolyData object. Extract the holes from the mesh for visualization. ```python mfix = MeshFix(bunny, verbose=True) holes = mfix.extract_holes() ``` -------------------------------- ### PyTMesh.clean Method Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.clean.rst.txt Documentation for the clean method of the PyTMesh class. ```APIDOC ## PyTMesh.clean ### Description Cleans the mesh using the PyTMesh class functionality. ### Method Method call ### Endpoint pymeshfix.PyTMesh.clean ``` -------------------------------- ### Constructor: pymeshfix.MeshFix Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.MeshFix.html Initializes a new MeshFix object for processing surface meshes. ```APIDOC ## Constructor: pymeshfix.MeshFix ### Description Initializes the MeshFix object with a surface mesh provided as a pyvista object, numpy arrays, or a file path. ### Parameters #### Request Body - **args** (pyvista.PolyData | (np.ndarray, np.ndarray) | pathlib.Path | str) - Required - Either a pyvista surface mesh, a tuple of vertex and face arrays, or a file path. - **verbose** (bool) - Optional - Set to True to enable additional output from MeshFix. Defaults to False. ``` -------------------------------- ### Convenience Methods Source: https://pymeshfix.pyvista.org/_sources/api.rst.txt Provides lower-level convenience methods for mesh fixing operations without direct use of `pyvista`. ```APIDOC ## pymeshfix.clean_from_file ### Description A convenience method to clean mesh data directly from a file. ### Method (Method type not specified, likely a function call) ### Endpoint (Not applicable for a function) ### Parameters (Specific parameters are not detailed in the provided text.) ### Request Example (No request examples are provided in the source text.) ### Response #### Success Response (No specific success responses are detailed in the provided text.) #### Response Example (No response examples are provided in the source text.) ``` ```APIDOC ## pymeshfix.clean_from_arrays ### Description A convenience method to clean mesh data provided as arrays. ### Method (Method type not specified, likely a function call) ### Endpoint (Not applicable for a function) ### Parameters (Specific parameters are not detailed in the provided text.) ### Request Example (No request examples are provided in the source text.) ### Response #### Success Response (No specific success responses are detailed in the provided text.) #### Response Example (No response examples are provided in the source text.) ``` -------------------------------- ### Fill Small Boundaries via PyTMesh Source: https://pymeshfix.pyvista.org/_downloads/0a2188cdc9ab9d0a467401debbe3ab17/repair_planar.ipynb Uses the low-level PyTMesh interface to fill holes based on boundary edge count constraints. ```python mfix = PyTMesh() mfix.set_quiet(True) mfix.load_file(examples.planar_mesh) # Fills all the holes having at at most 'nbe' boundary edges. If # 'refine' is true, adds inner vertices to reproduce the sampling # density of the surroundings. Returns number of holes patched. If # 'nbe' is 0 (default), all the holes are patched. mfix.fill_small_boundaries(nbe=100, refine=True) ``` -------------------------------- ### Import Libraries for Mesh Repair Source: https://pymeshfix.pyvista.org/_downloads/a765c73a2265f8a59b388228b14b1937/cow.ipynb Import necessary libraries including numpy, pyvista, and pymeshfix. This is a prerequisite for all subsequent operations. ```python import numpy as np # sphinx_gallery_thumbnail_number = 1 import pyvista as pv from pyvista import examples import pymeshfix as mf ``` -------------------------------- ### Repair and Verify Mesh Source: https://pymeshfix.pyvista.org/_sources/examples/torso.rst.txt Executes the repair process and displays the resulting watertight mesh. ```Python meshfix.repair() ``` ```Python meshfix.mesh.plot(cpos=cpos, show_edges=True) ``` -------------------------------- ### Import Libraries for Mesh Repair Source: https://pymeshfix.pyvista.org/_downloads/87ff65eb9bf4b89622fc5038dfb7623a/bunny.ipynb Import necessary libraries including PyVista for mesh handling and visualization, and MeshFix from pymeshfix for repair operations. ```python # sphinx_gallery_thumbnail_number = 2 import pyvista as pv from pyvista import examples from pymeshfix import MeshFix ``` -------------------------------- ### Advanced Mesh Cleaning with PyTMesh Source: https://pymeshfix.pyvista.org/index.html Use the PyTMesh object for granular control over the cleaning algorithm, including hole filling and component joining. ```python import pymeshfix # Create TMesh object tin = pymeshfix.PyTMesh() tin.LoadFile(infile) # tin.load_array(v, f) # or read arrays from memory # Attempt to join nearby components # tin.join_closest_components() # Fill holes tin.fill_small_boundaries() print(f'There are {tin.boundaries()} boundaries') # Clean (removes self intersections) tin.clean(max_iters=10, inner_loops=3) # Check mesh for holes again print(f'There are {tin.boundaries()} boundaries') # Clean again if necessary... # Output mesh tin.save_file(outfile) # or return numpy arrays vclean, fclean = tin.return_arrays() ``` -------------------------------- ### Visualize Mesh with Holes and Extract Holes Source: https://pymeshfix.pyvista.org/_downloads/a765c73a2265f8a59b388228b14b1937/cow.ipynb Initialize a PyVista plotter, add the mesh with holes, and highlight the extracted holes in red. Configure camera position and lighting for better visualization. This step helps in understanding the mesh's state before repair. ```python # A nice camera location to view the cow cpos = [(6.56, 8.73, 22.03), (0.77, -0.44, 0.0), (-0.13, 0.93, -0.35)] meshfix = mf.MeshFix(cow_w_holes, verbose=True) holes = meshfix.extract_holes() # Render the mesh and outline the holes p = pv.Plotter() p.add_mesh(cow_w_holes, color=True, smooth_shading=True, split_sharp_edges=True) p.add_mesh(holes, color="r", line_width=8) p.camera_position = cpos p.camera.zoom(1.5) p.enable_eye_dome_lighting() # helps depth perception p.enable_anti_aliasing("ssaa") p.show() ``` -------------------------------- ### Create MeshFix Object from NumPy Arrays Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.load_arrays.html Use this method to initialize a `MeshFix` object when your mesh data is already in NumPy arrays. Ensure your vertex array has shape (n, 3) and your face array has shape (m, 3). ```python from pymeshfix import MeshFix import numpy as np points = np.array( [ [3.71636, 2.343387, 0.0], [4.126565, 0.642027, 0.0], [3.454971, 2.169877, 0.0], ..., [4.12616, 2.12093, 1.17252], [4.133175, 2.175231, 1.259323], [4.232341, 1.903079, 0.534362], ], dtype=float32, ) faces = np.array( [ [210, 252, 251], [250, 251, 252], [201, 253, 210], ..., [1965, 2193, 2194], [2391, 2398, 970], [966, 961, 970], ] ) mfix = MeshFix(points, faces) ``` -------------------------------- ### PyTMesh.boundaries() Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.boundaries.html The boundaries() method of the PyTMesh class is used to identify and work with the boundaries of a mesh. It does not take any arguments and returns None. ```APIDOC ## PyTMesh.boundaries() ### Description Identifies and processes the boundaries of a mesh. This method does not return any value. ### Method `None` ### Endpoint `None` ### Parameters This method does not accept any parameters. ### Request Example ```python # Assuming 'mesh' is an instance of PyTMesh mesh.boundaries() ``` ### Response This method returns `None`. ``` -------------------------------- ### PyTMesh.remove_smallest_components Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.remove_smallest_components.rst.txt Documentation for the remove_smallest_components method within the PyTMesh class. ```APIDOC ## PyTMesh.remove_smallest_components ### Description Removes the smallest components from the mesh structure. ### Method Method call on PyTMesh object ### Endpoint pymeshfix.PyTMesh.remove_smallest_components ``` -------------------------------- ### Display Repaired Mesh Source: https://pymeshfix.pyvista.org/_downloads/a765c73a2265f8a59b388228b14b1937/cow.ipynb Access the repaired mesh from the `MeshFix` object and print its information. Then, visualize the repaired mesh using PyVista, applying similar camera settings as before for comparison. ```python repaired = meshfix.mesh print(repaired) ``` ```python repaired.plot(cpos=cpos, zoom=1.5, smooth_shading=True, split_sharp_edges=True) ``` -------------------------------- ### PyTMesh.load_file Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.load_file.html Method to load a surface mesh from a file into the PyTMesh object. ```APIDOC ## PyTMesh.load_file ### Description Load a surface mesh from a file. ### Parameters #### Path Parameters - **filename** (str) - Required - Path to the input mesh file. ### Response - **None** ``` -------------------------------- ### MeshFix.save Method Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.MeshFix.save.rst.txt Documentation for the save method used to write mesh data to a file. ```APIDOC ## MeshFix.save ### Description Saves the current mesh data to a specified file path. ### Method Method call ### Endpoint pymeshfix.MeshFix.save ``` -------------------------------- ### MeshFix.save() Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.save.html Writes the points and faces of a surface mesh to disk using PyVista. ```APIDOC ## MeshFix.save() ### Description Writes the points and faces as a surface mesh to disk using PyVista. This is a simple wrapper for :pyvista:`pyvista.PolyData.save`. ### Method POST ### Endpoint /websites/pymeshfix_pyvista ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **filename** (str) - Required - Filename of mesh to be written. Filetype is inferred from the extension of the filename unless overridden with ftype. Generally one of the following types: ".ply", ".stl", ".vtk" - **binary** (bool) - Optional - Default: True - Write the file using a binary writer. Binary files read and write much faster than ASCII. ### Request Example ```json { "filename": ".stl", "binary": true } ``` ### Response #### Success Response (200) - **message** (str) - Indicates successful saving of the mesh. #### Response Example ```json { "message": "Mesh successfully saved to file.stl" } ``` ``` -------------------------------- ### pymeshfix.clean_from_file Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.clean_from_file.html Clean and repair a triangular surface mesh from a file. ```APIDOC ## FUNCTION clean_from_file ### Description Clean and repair a triangular surface mesh from a file. ### Parameters - **infile** (str) - Required - Input mesh filename. - **outfile** (str) - Required - Output mesh filename. - **verbose** (bool) - Optional (default: False) - Enable verbose output. - **joincomp** (bool) - Optional (default: False) - Attempt to join nearby open components. ### Request Example ```python import pymeshfix pymeshfix.clean_from_file('inmesh.ply', 'outmesh.ply') ``` ### Response - **Returns** (None) - The function performs the operation on the specified files. ``` -------------------------------- ### PyTMesh Class Overview Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.PyTMesh.html The PyTMesh class is designed for mesh repair and cleaning, wrapping the MeshFix Basic_TMesh functionality. It allows users to load, manipulate, and save mesh data, as well as perform various repair operations. ```APIDOC ## PyTMesh Class ### Description Mesh repair and cleaning class. Wraps the MeshFix Basic_TMesh functionality and exposes it to Python. Provides methods to inspect, repair, and extract mesh data. ### Attributes - **n_boundaries** (int) - Number of boundary loops in the mesh. - **n_faces** (int) - Number of faces in the mesh. - **n_points** (int) - Number of points in the mesh. ### Methods - **boundaries()**: Returns None. Likely used for internal boundary processing. - **clean(max_iters=None, inner_loops=None)**: Perform iterative mesh cleaning and repair. - **fill_small_boundaries(nbe=None, ...)**: Fill small boundary loops (holes) in the mesh. - **fix_connectivity()**: Repair mesh connectivity issues. - **join_closest_components()**: Join the closest disconnected mesh components. - **load_array(points_arr, faces_arr, ...)**: Load a surface mesh from vertex and face arrays. - **load_file(filename)**: Load a surface mesh from a file. - **remove_smallest_components()**: Remove all but the largest connected mesh component. - **return_arrays()**: Return mesh data as vertex and face arrays. - **return_faces()**: Return the face array. - **return_points()**: Return the vertex array. - **save_file(filename, back_approx=False)**: Save the mesh to a file. - **select_intersecting_triangles(...)**: Select intersecting triangles in the mesh. - **set_quiet(arg)**: Enable or disable console output. - **strong_degeneracy_removal(arg)**: Iteratively removes degenerate triangles and closes holes. - **strong_intersection_removal(arg)**: Iteratively removes self-intersecting triangles. ``` -------------------------------- ### Repair Mesh with MeshFix Object Source: https://pymeshfix.pyvista.org/index.html Use the MeshFix class to repair meshes in memory, with optional PyVista visualization. ```python import pymeshfix # Create object from vertex and face arrays meshfix = pymeshfix.MeshFix(v, f) # Plot input meshfix.plot() # Repair input mesh meshfix.repair() # Access the repaired mesh with vtk mesh = meshfix.mesh # Or, access the resulting arrays directly from the object meshfix.points # numpy np.float64 array meshfix.faces # numpy np.int32 array # View the repaired mesh (requires pyvista) meshfix.plot() # Save the mesh meshfix.write('out.ply') ``` -------------------------------- ### Visualize the repaired result Source: https://pymeshfix.pyvista.org/examples/cow.html Renders the final repaired mesh using PyVista. ```python repaired.plot(cpos=cpos, zoom=1.5, smooth_shading=True, split_sharp_edges=True) ``` -------------------------------- ### PyTMesh.load_array Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.load_array.html Loads a surface mesh from vertex and face arrays. ```APIDOC ## PyTMesh.load_array ### Description Load a surface mesh from vertex and face arrays. ### Method This is a method of the PyTMesh class. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Assuming you have PyTMesh and numpy imported # and an instance of PyTMesh called 'mesh' points = np.array([[0,0,0], [1,0,0], [0,1,0]]) faces = np.array([[0,1,2]]) mesh.load_array(points_arr=points, faces_arr=faces) ``` ### Response #### Success Response (None) This method does not return any value. #### Response Example None ``` -------------------------------- ### Identify and Visualize Mesh Holes Source: https://pymeshfix.pyvista.org/_downloads/0a2188cdc9ab9d0a467401debbe3ab17/repair_planar.ipynb Reads a planar mesh and uses MeshFix to extract and visualize existing holes. ```python orig_mesh = pv.read(examples.planar_mesh) # orig_mesh.plot_boundaries() meshfix = MeshFix(orig_mesh, verbose=True) holes = meshfix.extract_holes() # Render the mesh and outline the holes pl = pv.Plotter() pl.add_mesh(orig_mesh, color=True, smooth_shading=True) pl.add_mesh(holes, color="r", line_width=8, render_lines_as_tubes=True, lighting=False) pl.enable_eye_dome_lighting() # helps depth perception _ = pl.show() ``` -------------------------------- ### Prepare Mesh for Repair Source: https://pymeshfix.pyvista.org/_downloads/8c2304a7db3bb5ef65786189c6b6749c/torso.ipynb Ensures the mesh consists only of triangles and extracts any holes present. This step is crucial for Pymeshfix to accurately identify and repair mesh defects. ```python meshfix = mf.MeshFix(mesh.triangulate(), verbose=True) holes = meshfix.extract_holes() ``` -------------------------------- ### PyTMesh.return_points Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.return_points.rst.txt Retrieves the points associated with the PyTMesh object. ```APIDOC ## PyTMesh.return_points ### Description Returns the points currently stored in the PyTMesh object. ### Method METHOD_NOT_SPECIFIED ### Endpoint PyTMesh.return_points ``` -------------------------------- ### MeshFix.plot Method Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.MeshFix.plot.rst.txt Documentation for the plot method used to visualize the mesh object. ```APIDOC ## MeshFix.plot ### Description Visualizes the current mesh object using the underlying plotting capabilities of the library. ### Method Method call on MeshFix object ### Endpoint pymeshfix.MeshFix.plot ``` -------------------------------- ### MeshFix.repair Method Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.MeshFix.repair.rst.txt The `repair` method is part of the `MeshFix` class and is used to repair issues within a mesh. This is an automethod, meaning it's automatically generated and documented. ```APIDOC ## MeshFix.repair ### Description Repairs issues within a mesh. ### Method This is an automethod, typically called on an instance of the MeshFix class. ### Endpoint N/A (This is a method within a Python class, not a REST API endpoint) ### Parameters This method does not explicitly define parameters in the provided documentation. Refer to the PyVista MeshFix documentation for specific parameter details. ### Request Example ```python # Assuming 'mesh' is a PyVista mesh object and 'mf' is an instance of MeshFix # mf = pymeshfix.MeshFix(mesh) # repaired_mesh = mf.repair() ``` ### Response #### Success Response Returns a repaired mesh object. #### Response Example ```json { "repaired_mesh": "" } ``` ``` -------------------------------- ### Render Mesh with Highlighted Holes Source: https://pymeshfix.pyvista.org/_downloads/87ff65eb9bf4b89622fc5038dfb7623a/bunny.ipynb Use a PyVista Plotter to display the original mesh and the extracted holes. The holes are rendered in red with thick lines to make them prominent. Enable advanced rendering features for better depth perception. ```python pl = pv.Plotter() pl.add_mesh(bunny, color=True, smooth_shading=True) pl.add_mesh(holes, color="r", line_width=12, render_lines_as_tubes=True, lighting=False) pl.camera_position = cpos pl.enable_eye_dome_lighting() # helps depth perception pl.enable_anti_aliasing("ssaa") pl.show() ``` -------------------------------- ### Clean Mesh from File with pymeshfix Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.clean_from_file.html Use this function to clean and repair a triangular surface mesh from a specified input file and save the result to an output file. It does not require pyvista or vtk. ```python import pymeshfix pymeshfix.clean_from_file('inmesh.ply', 'outmesh.ply') ``` -------------------------------- ### PyTMesh.save_file Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.save_file.rst.txt Saves the current PyTMesh object to a file. The file format is determined by the file extension. ```APIDOC ## PyTMesh.save_file ### Description Saves the current PyTMesh object to a file. The file format is determined by the file extension. ### Method This is a method of the PyTMesh class. ### Endpoint N/A (This is a method within a Python class, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Assuming 'mesh' is an instance of PyTMesh mesh.save_file('output.stl') mesh.save_file('output.ply') ``` ### Response #### Success Response (200) This method does not return a value upon successful execution. It performs a file operation. #### Response Example N/A ``` -------------------------------- ### Plot the underlying mesh Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.mesh.html Visualize the surface mesh using the plot method. ```python >>> mfix.mesh.plot() ``` -------------------------------- ### pymeshfix.MeshFix Class Source: https://pymeshfix.pyvista.org/api.html The `MeshFix` class provides a high-level interface for cleaning and tetrahedralizing surface meshes. It requires the `pyvista` library for some of its functionalities. ```APIDOC ## `pymeshfix.MeshFix` ### Description Clean and tetrahedralize surface meshes using MeshFix. ### Parameters - `*args`: Variable length argument list. - `verbose` (bool) - Optional - Controls the verbosity of the cleaning process. ``` -------------------------------- ### PyTMesh.return_points Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.return_points.html Retrieves the vertex array from the PyTMesh instance. ```APIDOC ## GET PyTMesh.return_points ### Description Returns the vertex array associated with the PyTMesh object. ### Method GET ### Endpoint PyTMesh.return_points() ### Response #### Success Response (200) - **vertex_array** (numpy.ndarray) - Vertex array of shape (N, 3) with dtype float64. ``` -------------------------------- ### PyTMesh.fill_small_boundaries Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.fill_small_boundaries.html Method to fill small boundary loops (holes) in a mesh. ```APIDOC ## PyTMesh.fill_small_boundaries ### Description Fill small boundary loops (holes) in the mesh. ### Parameters #### Parameters - **nbe** (int) - Optional (default: 0) - Maximum number of boundary edges to fill. If 0, fill all. - **refine** (bool) - Optional (default: True) - Refine filled regions. ### Response - **int** - Returns an integer representing the operation status or count. ``` -------------------------------- ### MeshFix.join_closest_components() Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.join_closest_components.html Attempts to join nearby open components of a mesh. This method modifies the mesh in place and does not return any value. ```APIDOC ## MeshFix.join_closest_components() ### Description Attempt to join nearby open components. ### Method None (This is a method of a class, not a standalone API endpoint) ### Endpoint N/A ### Parameters This method does not accept any parameters. ### Request Example ```python mesh_fix_instance.join_closest_components() ``` ### Response #### Success Response (None) This method returns `None` upon successful execution. #### Response Example ``` None ``` ``` -------------------------------- ### Show Repaired Mesh Source: https://pymeshfix.pyvista.org/_downloads/87ff65eb9bf4b89622fc5038dfb7623a/bunny.ipynb Visualize the mesh after the repair process has been completed. The holes should now be filled. ```python mfix.mesh.plot(cpos=cpos, eye_dome_lighting=True, anti_aliasing=True, smooth_shading=True) ``` -------------------------------- ### Visualize Repaired Mesh Source: https://pymeshfix.pyvista.org/_downloads/0a2188cdc9ab9d0a467401debbe3ab17/repair_planar.ipynb Displays the final repaired mesh alongside the original hole boundaries. ```python pl = pv.Plotter() pl.add_mesh(mesh, color=True, smooth_shading=True) pl.add_mesh(holes, color="r", line_width=8, render_lines_as_tubes=True, lighting=False) pl.enable_eye_dome_lighting() # helps depth perception _ = pl.show() ``` -------------------------------- ### Convert and Plot Repaired Mesh Source: https://pymeshfix.pyvista.org/_sources/examples/repair_planar.rst.txt Converts the repaired mesh from PyTMesh back to a pyvista mesh format and visualizes it with the original holes highlighted. Note that single-point boundary holes may not be filled. ```Python vert, faces = mfix.return_arrays() mesh = pv.make_tri_mesh(vert, faces) pl = pv.Plotter() pl.add_mesh(mesh, color=True, smooth_shading=True) pl.add_mesh(holes, color="r", line_width=8, render_lines_as_tubes=True, lighting=False) pl.enable_eye_dome_lighting() # helps depth perception _ = pl.show() ``` -------------------------------- ### Clean Mesh from Files or Arrays Source: https://pymeshfix.pyvista.org/index.html Perform basic mesh cleaning operations using file paths or existing vertex and face arrays. ```python import pymeshfix # Read mesh from infile and output cleaned mesh to outfile pymeshfix.clean_from_file(infile, outfile) ``` ```python import pymeshfix # Generate vertex and face arrays of cleaned mesh # where v and f are numpy arrays vclean, fclean = pymeshfix.clean_from_arrays(v, f) ``` -------------------------------- ### pymeshfix.clean_from_arrays Source: https://pymeshfix.pyvista.org/_sources/_autosummary/pymeshfix.clean_from_arrays.rst.txt Documentation for the clean_from_arrays function used to process and clean mesh data from arrays. ```APIDOC ## clean_from_arrays ### Description Cleans mesh data provided as arrays using the pymeshfix library. ### Endpoint pymeshfix.clean_from_arrays ``` -------------------------------- ### MeshFix.load_arrays Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.load_arrays.html Loads a triangular mesh into the MeshFix object from provided vertex and face numpy arrays. ```APIDOC ## MeshFix.load_arrays ### Description Load a triangular mesh from vertex and face numpy arrays. Both arrays should be 2D, with vertices containing XYZ data and faces containing three points. ### Parameters #### Path Parameters - **v** (np.ndarray[np.float64]) - Required - (n, 3) vertex array. - **f** (np.ndarray[np.int32]) - Required - (m, 3) face array. ### Request Example ```python from pymeshfix import MeshFix import numpy as np points = np.array([[3.71636, 2.343387, 0.0], ...], dtype=float32) faces = np.array([[210, 252, 251], ...]) mfix = MeshFix(points, faces) ``` ``` -------------------------------- ### MeshFix Methods Source: https://pymeshfix.pyvista.org/_autosummary/pymeshfix.MeshFix.html Common methods available on the MeshFix object for mesh repair and manipulation. ```APIDOC ## MeshFix Methods ### clean(max_iters, inner_loops) Remove degenerate triangles and self-intersections. ### degeneracy_removal(max_iter) Remove degenerate triangles. ### extract_holes() Extract the boundaries of the holes in this mesh to a new PyVista mesh of lines. ### fill_holes(n_edges, refine) Fill small boundary loops (holes) in the mesh. ### intersection_removal(max_iter) Remove self-intersecting triangles. ### join_closest_components() Attempt to join nearby open components. ### load_arrays(v, f) Load triangular mesh from vertex and face numpy arrays. ### plot(show_holes) Plot the mesh. ### remove_smallest_components() Remove all but the largest connected component. ### repair(joincomp, ...) Perform mesh repair using MeshFix's default repair process. ### save(filename, binary) Write the points and faces as a surface mesh to disk using PyVista. ``` -------------------------------- ### MeshFix.plot Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.plot.html Visualizes the mesh using the pyvista plotting backend. ```APIDOC ## MeshFix.plot ### Description Plot the mesh using the pyvista plotting backend. ### Parameters - **show_holes** (bool) - Optional (default: True) - If True, shows boundaries of the mesh. - **kwargs** (Any) - Optional - Additional keyword arguments passed to pyvista.plot(). ### Request Example ```python from pyvista import examples from pymeshfix import MeshFix mesh = examples.download_bunny() mfix = MeshFix(mesh) mfix.plot(show_holes=True) ``` ``` -------------------------------- ### PyTMesh.return_arrays Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.return_arrays.html Retrieves the vertex and face arrays from the PyTMesh instance. ```APIDOC ## GET PyTMesh.return_arrays ### Description Return mesh data as vertex and face arrays from the PyTMesh object. ### Method Method call on PyTMesh instance ### Response - **vertices** (numpy.ndarray) - Vertex array of shape (N, 3). - **faces** (numpy.ndarray) - Face array of shape (M, 3). ``` -------------------------------- ### Save the underlying mesh Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.mesh.html Export the surface mesh to a file using the save method. ```python >>> mfix.mesh.save("my_mesh.ply") ``` -------------------------------- ### MeshFix.repair() Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.MeshFix.repair.html Performs mesh repair using MeshFix's default repair process. This method can be called directly or individual repair functions can be invoked separately. ```APIDOC ## MeshFix.repair() ### Description Perform mesh repair using MeshFix’s default repair process. ### Method This is a method of the `MeshFix` class. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **joincomp** (_bool_, default: `False`) – Attempts to join nearby open components. - **remove_smallest_components** (_bool_, default: `True`) – Remove all but the largest isolated component from the mesh before beginning the repair process. ### Notes Vertex and face arrays can be accessed from: * `Meshfix.points` * `Meshfix.faces` You can alternatively call individual repair functions if you desire specific fixes. For example `MeshFix.fill_holes()`. ### Request Example ```python >>> from pyvista import examples >>> from pymeshfix import MeshFix >>> mesh = examples.download_bunny() >>> mfix = MeshFix(mesh, verbose=True) >>> mfix.repair() >>> mfix.plot(show_holes=True) ``` ### Response #### Success Response (200) This method does not return a value; it modifies the mesh in place. #### Response Example None ``` -------------------------------- ### pymeshfix.PyTMesh Class Source: https://pymeshfix.pyvista.org/api.html The `PyTMesh` class is a lower-level Cython extension for mesh repair and cleaning. It offers core mesh manipulation functionalities without requiring `pyvista`. ```APIDOC ## `pymeshfix.PyTMesh` ### Description Mesh repair and cleaning class. Lower level convenience methods that expose the lower level functionality of meshfix without using pyvista. ### Parameters - `*args`: Variable length argument list. - `**kwargs`: Arbitrary keyword arguments. ``` -------------------------------- ### Display repaired mesh information Source: https://pymeshfix.pyvista.org/examples/cow.html Retrieves the repaired mesh and prints its updated properties. ```python repaired = meshfix.mesh print(repaired) ``` -------------------------------- ### PyTMesh.save_file Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.save_file.html Saves the current mesh to a specified file. This method allows for optional backward approximation during the saving process. ```APIDOC ## PyTMesh.save_file ### Description Save the mesh to a file. ### Method `save_file` ### Parameters #### Path Parameters - **filename** (str) - Required - Output filename. - **back_approx** (bool) - Optional - Default: False - Use backward approximation when writing. ### Request Example ```python mesh.save_file("output.stl") mesh.save_file("output_approx.stl", back_approx=True) ``` ### Response #### Success Response (None) This method does not return any value. #### Response Example None ``` -------------------------------- ### PyTMesh.join_closest_components Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.join_closest_components.html Joins the closest disconnected mesh components of a PyTMesh object. ```APIDOC ## PyTMesh.join_closest_components() ### Description Joins the closest disconnected mesh components. ### Method None (This is a method of the PyTMesh class) ### Endpoint N/A (This is a method call on an object instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Assuming 'mesh' is an instance of PyTMesh mesh.join_closest_components() ``` ### Response #### Success Response (None) This method does not return any value. #### Response Example None ``` -------------------------------- ### MeshFix Class Overview Source: https://pymeshfix.pyvista.org/_sources/_autosummary/pymeshfix.MeshFix.rst.txt The MeshFix class provides a comprehensive set of tools for mesh repair and manipulation. It allows users to clean meshes, remove degeneracies, fill holes, and more. ```APIDOC ## MeshFix Class ### Description Provides tools for mesh repair and manipulation. ### Methods - **clean()**: Cleans the mesh. - **degeneracy_removal()**: Removes degenerate elements from the mesh. - **extract_holes()**: Extracts holes from the mesh. - **fill_holes()**: Fills holes in the mesh. - **intersection_removal()**: Removes intersecting elements. - **join_closest_components()**: Joins the closest components of the mesh. - **load_arrays()**: Loads mesh data from arrays. - **plot()**: Plots the mesh. - **remove_smallest_components()**: Removes the smallest components of the mesh. - **repair()**: Repairs the mesh. - **save()**: Saves the mesh. ### Attributes - **faces** (array): The faces of the mesh. - **mesh** (object): The underlying mesh object. - **n_boundaries** (int): The number of boundary components. - **points** (array): The points (vertices) of the mesh. ``` -------------------------------- ### Return hole count Source: https://pymeshfix.pyvista.org/examples/repair_planar.html The number of holes patched by the algorithm. ```text 16 ``` -------------------------------- ### MeshFix.load_arrays Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.MeshFix.load_arrays.rst.txt The load_arrays method is part of the MeshFix class in the pymeshfix library. It is used to load mesh data from arrays. ```APIDOC ## MeshFix.load_arrays ### Description Loads mesh data from arrays into a MeshFix object. ### Method This is a method of the `MeshFix` class. ### Endpoint N/A (This is a Python method, not a REST API endpoint) ### Parameters This method likely accepts arrays representing vertices, faces, and potentially other mesh attributes. Specific parameter names and types would be detailed in the full library documentation. ### Request Example ```python import pymeshfix # Assuming you have vertex and face arrays vertices = [...] # numpy array of shape (n_vertices, 3) faces = [...] # numpy array of shape (n_faces, 3) or similar meshfix_object = pymeshfix.MeshFix() meshfix_object.load_arrays(vertices, faces) ``` ### Response Upon successful execution, the `MeshFix` object will be populated with the mesh data from the provided arrays. Specific return values or side effects would be detailed in the full library documentation. ``` -------------------------------- ### PyTMesh.set_quiet Source: https://pymeshfix.pyvista.org/_autosummary/_autosummary/pymeshfix.PyTMesh.set_quiet.html This method allows you to control whether PyTMesh outputs messages to the console. Set `quiet` to `True` to suppress output, or `False` to enable it. ```APIDOC ## PyTMesh.set_quiet ### Description Enable or disable console output. ### Method `set_quiet` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **quiet** (bool) - Required - If True, suppress output. ### Request Example ```json { "quiet": true } ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### PyTMesh.return_arrays Source: https://pymeshfix.pyvista.org/_sources/_autosummary/_autosummary/pymeshfix.PyTMesh.return_arrays.rst.txt The return_arrays method of the PyTMesh class is used to retrieve arrays associated with the mesh. ```APIDOC ## PyTMesh.return_arrays ### Description Retrieves arrays associated with the mesh. ### Method This is a method of the PyTMesh class, typically called on an instance of PyTMesh. ### Endpoint N/A (This is a Python method, not a REST API endpoint) ### Parameters This method does not appear to take any explicit parameters. ### Request Example ```python # Assuming 'mesh' is an instance of PyTMesh arrays = mesh.return_arrays() ``` ### Response #### Success Response - **arrays** (list or dict) - A collection of arrays related to the mesh data (e.g., vertices, faces, normals). The exact structure depends on the internal implementation of PyTMesh. #### Response Example ```json { "example": "[numpy.ndarray, numpy.ndarray, ...]" } ``` ```