### Run PyMesh Docker Container Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Starts an interactive Docker container with PyMesh pre-installed. This is the simplest way to use PyMesh without local installation. ```bash docker run -it pymesh/pymesh ``` -------------------------------- ### Install PyMesh Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Installs PyMesh onto the system. This command may require root privileges depending on the installation location. An alternative `--user` flag installs PyMesh locally. ```bash ./setup.py install ``` ```bash ./setup.py install --user ``` -------------------------------- ### Build PyMesh with Setuptools Source: https://pymesh.readthedocs.io/en/latest/installation Builds the main PyMesh module and its third-party dependencies using the setuptools build script. ```shell ./setup.py build ``` -------------------------------- ### Install PyMesh Locally for User Source: https://pymesh.readthedocs.io/en/latest/installation Installs the PyMesh library locally for the current user, avoiding the need for root privileges. ```shell ./setup.py install --user ``` -------------------------------- ### Run PyMesh Unit Tests Source: https://pymesh.readthedocs.io/en/latest/installation Executes PyMesh's built-in unit tests to verify correct installation. This command imports the PyMesh library and calls its test function. ```python python -c "import pymesh; pymesh.test()" ``` -------------------------------- ### Clone PyMesh Source and Initialize Submodules Source: https://pymesh.readthedocs.io/en/latest/installation Checks out the PyMesh source code from GitHub and initializes its submodules, setting up the PYMESH_PATH environment variable. ```shell git clone https://github.com/PyMesh/PyMesh.git cd PyMesh git submodule update --init export PYMESH_PATH=`pwd` ``` -------------------------------- ### Install MacOS System Dependencies Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Installs essential system-level libraries for PyMesh on macOS using MacPorts. ```bash port install python36 \ eigen3 \ gmp \ mpfr \ tbb \ boost ``` -------------------------------- ### Install PyMesh System Dependencies on Linux Source: https://pymesh.readthedocs.io/en/latest/installation Installs essential system dependencies for PyMesh on Debian-based Linux distributions using apt-get. ```shell apt-get install \ libeigen3-dev \ libgmp-dev \ libgmpxx4ldbl \ libmpfr-dev \ libboost-dev \ libboost-thread-dev \ libtbb-dev \ python3-dev ``` -------------------------------- ### Post-installation Check with Pytest Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Verifies that PyMesh has been installed correctly by running its unit tests. This involves importing the PyMesh library and executing its test suite. ```python import pymesh pymesh.test() ``` -------------------------------- ### Build PyMesh with Setuptools Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Builds the main PyMesh module and its third-party dependencies using the Setuptools build script. This is a straightforward method for building the project. ```bash ./setup.py build ``` -------------------------------- ### Clone PyMesh Source Code Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Downloads the PyMesh source code from GitHub and initializes necessary submodules. Sets the PYMESH_PATH environment variable. ```bash git clone https://github.com/PyMesh/PyMesh.git cd PyMesh git submodule update --init export PYMESH_PATH=`pwd` ``` -------------------------------- ### Install PyMesh System-Wide Source: https://pymesh.readthedocs.io/en/latest/installation Installs the PyMesh library into the system's Python environment, potentially requiring root privileges. ```shell ./setup.py install # May require root privilege ``` -------------------------------- ### Run PyMesh Docker Container Source: https://pymesh.readthedocs.io/en/latest/installation Executes a pre-built PyMesh Docker image, providing an interactive Python environment with PyMesh pre-installed. ```shell $ docker run -it pymesh/pymesh Python 3.6.4 (default, Dec 21 2017, 01:35:12) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pymesh >>> ``` -------------------------------- ### Install Linux System Dependencies Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Installs essential system-level libraries required for PyMesh on Debian-based Linux distributions using apt-get. ```bash apt-get install \ libeigen3-dev \ libgmp-dev \ libgmpxx4ldbl \ libmpfr-dev \ libboost-dev \ libboost-thread-dev \ libtbb-dev \ python3-dev ``` -------------------------------- ### Install PyMesh System Dependencies on macOS Source: https://pymesh.readthedocs.io/en/latest/installation Installs required system dependencies for PyMesh on macOS using MacPorts. ```shell port install python36 \ eigen3 \ gmp \ mpfr \ tbb \ boost ``` -------------------------------- ### Build PyMesh Third-Party Dependencies with CMake Source: https://pymesh.readthedocs.io/en/latest/installation Compiles and installs all third-party dependencies for PyMesh using CMake in an out-of-source build directory. ```shell cd $PYMESH_PATH/third_party mkdir build cd build cmake .. make make install ``` -------------------------------- ### Install PyMesh Python Dependencies Source: https://pymesh.readthedocs.io/en/latest/installation Installs Python-specific dependencies for PyMesh, such as NumPy and SciPy, using pip from a requirements file. ```shell pip install -r $PYMESH_PATH/python/requirements.txt ``` -------------------------------- ### Compile PyMesh Modules and Tests with CMake Source: https://pymesh.readthedocs.io/en/latest/installation Compiles all PyMesh modules and their corresponding unit tests after the build environment has been configured with CMake. ```shell make make tests ``` -------------------------------- ### Configure PyMesh Build Environment with CMake Source: https://pymesh.readthedocs.io/en/latest/installation Sets up the build environment for PyMesh using CMake for an out-of-source build, preparing for module compilation. ```shell cd $PYMESH_PATH mkdir build cd build cmake .. ``` -------------------------------- ### Install PyMesh Python Dependencies Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Installs Python packages required by PyMesh, such as NumPy and SciPy, using pip from a requirements file. ```bash pip install -r $PYMESH_PATH/python/requirements.txt ``` -------------------------------- ### PyMesh Triangle Triangulation Example Source: https://pymesh.readthedocs.io/en/latest/api_mesh_generation Demonstrates basic usage of the pymesh.triangle wrapper to triangulate a set of points. This example sets up the input points, specifies the maximum triangle area, and controls the verbosity of the triangle execution. The resulting mesh is then accessed. ```python >>> import numpy as np >>> import pymesh >>> vertices = np.array([ ... [0.0, 0.0], ... [1.0, 0.0], ... [1.0, 1.0], ... [0.0, 1.0], ... ]); >>> tri = pymesh.triangle(); >>> tri.points = vertices; >>> tri.max_area = 0.05; >>> tri.split_boundary = False; >>> tri.verbosity = 0; >>> tri.run(); # Execute triangle. >>> mesh = tri.mesh; # output triangulation. ``` -------------------------------- ### Build PyMesh with CMake Source: https://pymesh.readthedocs.io/en/latest/_sources/installation Builds PyMesh using CMake, suitable for C++ developers. This process involves building third-party dependencies separately before building the main PyMesh modules. Assumes `$PYMESH_PATH` is set. ```bash cd $PYMESH_PATH/third_party mkdir build cd build cmake .. make make install ``` ```bash cd $PYMESH_PATH mkdir build cd build cmake .. make make tests ``` -------------------------------- ### Mesh-Guided Tiling with Hexahedron Mesh Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Tiles a wire network according to a guide hexahedron mesh. The `tile_with_guide_mesh` method loads a mesh file (e.g., 'L_hex.msh') and uses it to guide the tiling process. The resulting tiled wire network is stored in `tiler.wire_network`. ```python >>> guide_mesh = pymesh.load_Mesh("L_hex.msh") >>> tiler = Tiler(wire_network) >>> tiler.tile_with_guide_mesh(guide_mesh) >>> tiled_wires = tiler.wire_network ``` -------------------------------- ### Solving Sparse Linear Systems with PyMesh (Direct Solvers) Source: https://pymesh.readthedocs.io/en/latest/api_sparse_solver Demonstrates how to use PyMesh's SparseSolver for direct linear system solving. It requires SciPy and NumPy. The example shows creating a solver, computing the matrix factorization, and solving for the unknown vector. ```python import scipy.sparse import numpy import pymesh M = scipy.sparse.eye(100) # Build matrix. rhs = numpy.ones(100) # build right hand side. solver = pymesh.SparseSolver.create("LDLT") solver.compute(M) x = solver.solve(rhs) ``` -------------------------------- ### Perform Mesh-Guided Tiling with PyMesh Tiler Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Tiles a wire network based on the geometry of a guide hexahedron mesh. This allows for non-uniform and complex tiling patterns by conforming the wire network to the shape of the guide mesh. Requires the Tiler class and pymesh.load_Mesh. ```python guide_mesh = pymesh.load_Mesh("L_hex.msh") tiler = Tiler(wire_network) tiler.tile_with_guide_mesh(guide_mesh) tiled_wires = tiler.wire_network ``` -------------------------------- ### Example: Forming a Mesh Object with PyMesh Source: https://pymesh.readthedocs.io/en/latest/api_meshio Shows how to create a PyMesh Mesh object from numpy arrays representing vertices and faces, specifically for a 2D square. ```python >>> vertices = np.array([ ... [0.0, 0.0], ... [1.0, 0.0], ... [1.0, 1.0], ... [0.0, 1.0], ... ]); >>> faces = np.array([ ... [0, 1, 2], ... [0, 2, 3], ... ]); >>> mesh = pymesh.form_mesh(vertices, faces); ``` -------------------------------- ### Solving Sparse Linear Systems with PyMesh (Iterative Solvers) Source: https://pymesh.readthedocs.io/en/latest/api_sparse_solver Illustrates the usage of PyMesh's SparseSolver for iterative linear system solving, including setting tolerance and maximum iterations. This example requires SciPy and NumPy. ```python import scipy.sparse import numpy import pymesh M = scipy.sparse.eye(100) # Build matrix. rhs = numpy.ones(100) # build right hand side. solver = pymesh.SparseSolver.create("CG") solver.tolerance = 1e-10 solver.max_iterations = 50 solver.compute(M) x = solver.solve(rhs) ``` -------------------------------- ### Example: Saving a Mesh to STL with PyMesh Source: https://pymesh.readthedocs.io/en/latest/api_meshio Demonstrates saving a generated box mesh to an STL file in ASCII format using PyMesh's save_mesh function. ```python >>> box = pymesh.generate_box_mesh(); >>> pymesh.save_mesh("tmp.stl", box, ascii=True); ``` -------------------------------- ### Create empty WireNetwork Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Initializes an empty WireNetwork object with no vertices or edges. This is useful for starting with a clean slate before loading data. ```python import pymesh empty_wires = pymesh.wires.WireNetwork.create_empty() ``` -------------------------------- ### Wire Network Utility Functions (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Provides examples of utility functions for wire networks, including trimming dangling edges and offsetting vertices with random vectors. It also shows how to center the network at the origin. ```python >>> wire_network.trim() >>> offset_vectors = np.random.rand( ... wire_network.num_vertices, wire_network.dim) >>> wire_network.offset(offset_vectors) >>> wire_network.center_at_origin() ``` -------------------------------- ### Attribute Management Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Functions for managing attributes associated with the wire network, including getting, checking, adding, and setting attributes. ```APIDOC ## GET /get_attribute_names ### Description Retrieves the names of all defined attributes. ### Method GET ### Endpoint `/get_attribute_names` ### Response #### Success Response (200) - **attribute_names** (list of strings) - A list of all attribute names. ## GET /has_attribute ### Description Checks if a specified attribute exists. ### Method GET ### Endpoint `/has_attribute` ### Parameters #### Query Parameters - **name** (str) - The name of the attribute to check. ### Response #### Success Response (200) - **exists** (boolean) - True if the attribute exists, False otherwise. ## POST /add_attribute ### Description Adds a new attribute to the wire network. ### Method POST ### Endpoint `/add_attribute` ### Parameters #### Request Body - **name** (str) - The name for the new attribute. - **value** (numpy.ndarray, optional) - The initial values for the attribute. Defaults to None. - **vertex_wise** (bool, optional) - Whether the attribute is per-vertex. Defaults to True. ### Request Example ```json { "name": "vertex_color", "value": [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], "vertex_wise": true } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ## GET /get_attribute ### Description Retrieves the value of a specified attribute. ### Method GET ### Endpoint `/get_attribute` ### Parameters #### Query Parameters - **name** (str) - The name of the attribute to retrieve. ### Response #### Success Response (200) - **value** (numpy.ndarray) - The value of the requested attribute. ## GET /is_vertex_attribute ### Description Checks if a specified attribute is per-vertex. ### Method GET ### Endpoint `/is_vertex_attribute` ### Parameters #### Query Parameters - **name** (str) - The name of the attribute to check. ### Response #### Success Response (200) - **is_vertex_wise** (boolean) - True if the attribute is per-vertex, False otherwise. ## POST /set_attribute ### Description Sets the value of an existing attribute. ### Method POST ### Endpoint `/set_attribute` ### Parameters #### Request Body - **name** (str) - The name of the attribute to set. - **value** (numpy.ndarray) - The new value for the attribute. ### Request Example ```json { "name": "vertex_color", "value": [[0.0, 0.0, 1.0]] } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ``` -------------------------------- ### Create WireNetwork from Data (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Constructs a WireNetwork object by providing vertex positions and edge connectivity as NumPy arrays. The vertex indices in the edges array should start from 0. ```python import pymesh import numpy as np vertices = np.array([ [0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0] ]) edges = np.array([ [0, 1], [1, 3], [2, 3], [2, 0] ]) wire_network = pymesh.wires.WireNetwork.create_from_data( vertices, edges) ``` -------------------------------- ### Example: Saving Raw Mesh Data with PyMesh Source: https://pymesh.readthedocs.io/en/latest/api_meshio Illustrates saving raw mesh data, including vertices, faces, and voxels, to a .msh file using PyMesh's save_mesh_raw function. ```python >>> mesh = pymesh.generate_regular_tetrahedron(); >>> pymesh.save_mesh_raw("out.msh", ... mesh.vertices, mesh.faces, mesh.voxels); ``` -------------------------------- ### Variable Wire Inflation with PyMesh (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Illustrates how to perform wire inflation with variable thickness using PyMesh's Inflator class. Examples show assigning thickness per-vertex and per-edge using NumPy arrays to define the varying thickness values. ```python >>> thickness = np.arange(wire_network.num_vertices) / \ ... wire_network.num_vertices * 0.5 + 0.1 >>> inflator.inflate(thickness, per_vertex_thickness=True) >>> mesh = inflator.mesh >>> thickness = np.arange(wire_network.num_edges) / \ ... wire_network.num_edges * 0.5 + 0.1 >>> inflator.inflate(thickness, per_vertex_thickness=False) >>> mesh = inflator.mesh ``` -------------------------------- ### Accessing Wire Network Attributes (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Demonstrates how to retrieve per-vertex and per-edge symmetry orbit attributes from a wire network using the get_attribute method. It shows an example of accessing 'vertex_symmetry_orbit' and its output. ```python >>> wire_network.get_attribute("vertex_symmetry_orbit") array([ 0., 0., 0., 0., 1., 1., 1., 1.]) ``` -------------------------------- ### PyMesh SparseSolver Class Source: https://pymesh.readthedocs.io/en/latest/api_sparse_solver Documentation for the `pymesh.SparseSolver` class, a wrapper for Eigen's sparse solvers. ```APIDOC ## Class pymesh.SparseSolver ### Description Linear solver for solving sparse linear systems. This class is a thin wrapper around sparse solvers supported by Eigen. ### Supported Direct Solvers - `LLT`: Wrapper of Eigen::SimplicialLLT, SPD only. - `LDLT`: Wrapper of Eigen::SimplicialLDLT, SPD only. - `SparseLU`: Wrapper of Eigen::SparseLU. - `SparseQR`: Wrapper of Eigen::SparseQR. - `UmfPackLU`: Wrapper of Eigen::UmfPackLU. (Requires SuiteSparse) - `Cholmod`: Wrapper of Eigen::CholmodSupernodalLLT. (Requires SuiteSparse) - `PardisoLLT`: Wrapper of Eigen::PardisoLLT. SPD only. (Requires Intel MKL) - `PardisoLDLT`: Wrapper of Eigen::PardisoLDLT. SPD only. (Requires Intel MKL) - `PardisoLU`: Wrapper of Eigen::PardisoLU. (Requires Intel MKL) ### Supported Iterative Solvers - `CG`: Wrapper of Eigen::ConjugateGradient. SPD only. - `LSCG`: Wrapper of Eigen::LeastSquaresConjugateGradient. - `BiCG`: Wrapper of Eigen::BiCGSTAB. ### Attributes - `supported_solvers` (list of str): The list of supported solvers. - `tolerance` (float): The residual error threshold for stopping iterative solvers. Default is `Eigen::NumTraits::epsilon()`. - `max_iterations` (int): The max iterations allowed for iterative solvers. Default is twice the number of columns of the matrix. ### Example Usage **Direct Solvers:** ```python import scipy.sparse import numpy import pymesh M = scipy.sparse.eye(100) # Build matrix. rhs = numpy.ones(100) # build right hand side. solver = pymesh.SparseSolver.create("LDLT") solver.compute(M) x = solver.solve(rhs) ``` **Iterative Solvers:** ```python import scipy.sparse import numpy import pymesh M = scipy.sparse.eye(100) # Build matrix. rhs = numpy.ones(100) # build right hand side. solver = pymesh.SparseSolver.create("CG") solver.tolerance = 1e-10 solver.max_iterations = 50 solver.compute(M) x = solver.solve(rhs) ``` ``` -------------------------------- ### Regular Tiling with Bounding Box and Repetitions Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Performs regular tiling of a wire network within a specified bounding box. The `tile_with_guide_bbox` method takes the minimum and maximum coordinates of the bounding box and the number of repetitions in each dimension. The tiled wire network is accessible via `tiler.wire_network`. ```python >>> tiler = Tiler(wire_network) >>> box_min = np.zeros(3) >>> box_max = np.ones(3) * 15.0 >>> reps = [3, 3, 3] >>> tiler.tile_with_guide_bbox(box_min, box_max, reps) >>> tiled_wires = tiler.wire_network ``` -------------------------------- ### Get All Defined Attribute Names in PyMesh Source: https://pymesh.readthedocs.io/en/latest/_sources/basic Retrieves a tuple containing the names of all attributes currently defined for a given mesh. ```python >>> mesh.get_attribute_names() ("attribute_name", "vertex_area", "vertex_normal") ``` -------------------------------- ### WireNetwork Add and Get Attributes Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Allows adding custom attributes (scalar or vector fields) to vertices or edges and retrieving them. ```APIDOC ## WireNetwork Add and Get Attributes ### Description Enables the association of arbitrary data, such as colors or other properties, with vertices or edges of the `WireNetwork`. Attributes can be added and then retrieved by their name. ### Method - `wire_network.add_attribute(attribute_name, attribute_data)` - `wire_network.get_attribute(attribute_name)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **attribute_name** (str) - Required - The name to assign to the attribute (e.g., "vertex_color"). - **attribute_data** (numpy.ndarray) - Required - The data for the attribute, matching the number of vertices or edges. ### Request Example ```python vertex_colors = np.zeros((wire_network.num_vertices, 3)) wire_network.add_attribute("vertex_color", vertex_colors) retrieved_colors = wire_network.get_attribute("vertex_color") print(retrieved_colors) ``` ### Response #### Success Response (200) - **add_attribute**: None (modifies object in-place). - **get_attribute**: (numpy.ndarray) - The data associated with the specified attribute name. #### Response Example ```python # Output from get_attribute("vertex_color"): # [[ 0. 0. 0.] # [ 0. 0. 0.] # [ 0. 0. 0.] # [ 0. 0. 0.]] ``` ``` -------------------------------- ### Load Mesh from File in Python Source: https://pymesh.readthedocs.io/en/latest/_sources/index Demonstrates how to load a mesh file (e.g., cube.obj) using the PyMesh library. This is the initial step for processing any mesh data. ```python import pymesh mesh = pymesh.load_mesh("cube.obj"); ``` -------------------------------- ### Add and Get Vertex Area Attribute in PyMesh Source: https://pymesh.readthedocs.io/en/latest/_sources/basic Demonstrates how to add a 'vertex_area' attribute to a mesh and then retrieve its values. Attribute values are stored as a 1D array. ```python >>> mesh.add_attribute("vertex_area") >>> mesh.get_attribute("vertex_area") array([ 0.56089278, 0.5608997 , 0.57080866, ..., 5.62381961, 2.12105028, 0.37581711]) ``` -------------------------------- ### Get vertex neighbors Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Retrieves the indices of vertices directly connected to a specified vertex in the WireNetwork. This is useful for analyzing connectivity and calculating vertex valence. ```python import pymesh # Assuming vertex_index is defined # wire_network.get_vertex_neighbors(vertex_index) # Example usage (assuming vertex_index = 0): # print(wire_network.get_vertex_neighbors(0)) ``` -------------------------------- ### WireNetwork Construction from File Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Creates a WireNetwork object from a file, typically in a format similar to .obj. ```APIDOC ## POST /api/wire_network/create_from_file ### Description Creates a WireNetwork object from a file, typically in a format similar to .obj. ### Method POST ### Endpoint /api/wire_network/create_from_file ### Parameters #### Request Body - **filename** (str) - Required - The path to the wire network file. ### Request Example ```json { "filename": "test.wire" } ``` ### Response #### Success Response (200) - **wire_network** (WireNetwork) - The created WireNetwork object. #### Response Example ```json { "wire_network": "" } ``` ``` -------------------------------- ### WireNetwork Construction from File Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Creates a WireNetwork object by loading data from a specified file, typically in a custom '.wire' format or compatible OBJ format. ```APIDOC ## WireNetwork Construction from File ### Description Loads a `WireNetwork` object from a file. The file format specifies vertex coordinates (lines starting with 'v') and edges (lines starting with 'l'). Note that file indices are 1-based. ### Method `WireNetwork.create_from_file(filepath)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **filepath** (str) - Required - The path to the file containing the wire network data. ### Request Example ```python # Assuming 'test.wire' contains: # v 0.0 0.0 0.0 # v 1.0 0.0 0.0 # v 0.0 1.0 0.0 # v 1.0 1.0 0.0 # l 1 2 # l 2 4 # l 3 4 # l 3 1 wire_network = pymesh.wires.WireNetwork.create_from_file("test.wire") ``` ### Response #### Success Response (200) - **WireNetwork object**: A `WireNetwork` object loaded from the specified file. #### Response Example ```python # Successful creation of wire_network object from file ``` ``` -------------------------------- ### Create Empty WireNetwork and Load Data (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Initializes an empty WireNetwork object and subsequently loads vertex and edge data into it. This is useful for creating a network and populating it later. ```python import pymesh import numpy as np empty_wires = pymesh.wires.WireNetwork.create_empty() vertices = np.array([ [0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0] ]) edges = np.array([ [0, 1], [1, 3], [2, 3], [2, 0] ]) wire_network.load(vertices, edges) ``` -------------------------------- ### Get attribute values from a mesh Source: https://pymesh.readthedocs.io/en/latest/basic This code snippet illustrates how to retrieve the values of a previously set mesh attribute. The returned value is a flattened 1D NumPy array. ```python >>> attr_val = mesh.get_attribute("attribute_name") >>> attr_val array([ 1.0, 1.0, 1.0, ..., 1.0, 1.0, 1.0]) ``` -------------------------------- ### Get Per-Vertex Normal Attribute as 2D Matrix in PyMesh Source: https://pymesh.readthedocs.io/en/latest/_sources/basic Retrieves the 'vertex_normal' attribute, specifically formatted as a 2D matrix where each row represents a vertex's normal vector. ```python >>> mesh.get_vertex_attribute("vertex_normal") array([[ 0.35735435, -0.49611438, -0.79130802], [ 0.41926554, -0.90767626, -0.01844495], [-0.64142577, 0.76638469, -0.03503568], ..., [-0.64897662, -0.64536558, -0.40290522], [-0.92207726, -0.10573231, -0.37228242], [-0.79797784, 0.55299134, -0.23964964]]) ``` -------------------------------- ### Wire Network Data Loading and Saving Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Functions for loading raw wire data and writing the wire network to a file. ```APIDOC ## POST /load_from_raw ### Description Loads vertex and edges from a raw C++ wire data structure. ### Method POST ### Endpoint `/load_from_raw` ### Parameters #### Request Body - **_raw_wires_** (object) - The raw C++ wire data structure. ### Request Example ```json { "_raw_wires_": "" } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ## POST /write_to_file ### Description Saves the current wire network into a file. ### Method POST ### Endpoint `/write_to_file` ### Parameters #### Request Body - **filename** (str) - The name of the file to save the wire network to. ### Request Example ```json { "filename": "output.wire" } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ``` -------------------------------- ### Get Vertex Neighbors (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Retrieves the indices of vertices that are directly connected to a specified vertex in the wire network. This is useful for analyzing connectivity and calculating vertex valence. ```python import pymesh wire_network.get_vertex_neighbors(vertex_index) ``` -------------------------------- ### Assemble Laplacian-Beltrami Matrix using PyMesh Assembler Source: https://pymesh.readthedocs.io/en/latest/api_matrix_assembly Demonstrates assembling the Laplacian-Beltrami matrix from a mesh using PyMesh's `Assembler`. Requires PyMesh and SciPy. Takes a PyMesh object as input and returns a SciPy sparse CSC matrix. ```python import pymesh import numpy as np mesh = pymesh.generate_icosphere(1.0, np.zeros(3), 3) assembler = pymesh.Assembler(mesh) L = assembler.assemble("laplacian") print(type(L)) ``` -------------------------------- ### Add and Get Flattened Vertex Normal Attribute in PyMesh Source: https://pymesh.readthedocs.io/en/latest/_sources/basic Shows how to add a 'vertex_normal' attribute and retrieve its flattened values. For vector fields, values are stored as a flattened 1D array. ```python >>> mesh.add_attribute("vertex_normal") >>> mesh.get_attribute("vertex_normal") array([ 0.35735435, -0.49611438, -0.79130802, ..., -0.79797784, 0.55299134, -0.23964964]) ``` -------------------------------- ### Wire Network Transformation Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Functions for transforming the wire network, including scaling, offsetting, centering, and trimming. ```APIDOC ## POST /scale ### Description Scales the wire network by specified factors. ### Method POST ### Endpoint `/scale` ### Parameters #### Request Body - **factors** (scalar or array) - Scaling factors. If a scalar, scales uniformly. If an array, scales each dimension separately. ### Request Example ```json { "factors": 2.0 } ``` ```json { "factors": [1.0, 2.0, 0.5] } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ## POST /offset ### Description Offsets vertices by a per-vertex offset vector. ### Method POST ### Endpoint `/offset` ### Parameters #### Request Body - **offset_vector** (numpy.ndarray) - A matrix representing per-vertex offset vectors. ### Request Example ```json { "offset_vector": [[0.1, 0.1, 0.1], [0.2, 0.2, 0.2]] } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ## POST /center_at_origin ### Description Translates the wire network to have its center at the origin. ### Method POST ### Endpoint `/center_at_origin` ### Request Example ```json {} ``` ### Response #### Success Response (200) - **message** (str) - Success message. ## POST /trim ### Description Removes all hanging edges (edges with at least one vertex of valence <= 1). ### Method POST ### Endpoint `/trim` ### Request Example ```json {} ``` ### Response #### Success Response (200) - **message** (str) - Success message. ``` -------------------------------- ### PyMesh API Reference Source: https://pymesh.readthedocs.io/en/latest/api_mesh_generation This section outlines the PyMesh API, detailing various functionalities for mesh manipulation and processing. It includes sections on Mesh Data Structure, Reading and Writing Meshes, Local Mesh Cleanup, Procedural Mesh Generation, Mesh Generation (Triangulation, Tetrahedralization), Geometry Processing Functions, Finite Element Matrix Assembly, Sparse Linear System Solver, and Miscellaneous functions. ```APIDOC ## PyMesh API Reference ### Description This documentation provides a comprehensive reference for the PyMesh API, covering various aspects of mesh data structures, operations, and functionalities. ### Sections * Mesh Data Structure * Reading and Writing Meshes * Local Mesh Cleanup * Procedural Mesh Generation * Mesh Generation * Triangulation * Tetrahedralization * Geometry Processing Functions * Finite Element Matrix Assembly * Sparse Linear System Solver * Miscellaneous functions ### Related Topics * Previous: Procedural Mesh Generation * Next: Geometry Processing Functions ``` -------------------------------- ### Get vertex attribute as a structured array Source: https://pymesh.readthedocs.io/en/latest/basic This code shows how to retrieve a per-vertex attribute, 'vertex_normal', in a structured 2D NumPy array format. Each row corresponds to a vertex, and columns represent the components of the vector. ```python >>> mesh.get_vertex_attribute("vertex_normal") array([[ 0.35735435, -0.49611438, -0.79130802], [ 0.41926554, -0.90767626, -0.01844495], [-0.64142577, 0.76638469, -0.03503568], ..., [-0.64897662, -0.64536558, -0.40290522], [-0.92207726, -0.10573231, -0.37228242], [-0.79797784, 0.55299134, -0.23964964]]) ``` -------------------------------- ### WireNetwork Construction from Data Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Creates a WireNetwork object from provided vertex positions and edge connectivity. ```APIDOC ## POST /api/wire_network/create_from_data ### Description Creates a WireNetwork object from provided vertex positions and edge connectivity. ### Method POST ### Endpoint /api/wire_network/create_from_data ### Parameters #### Request Body - **vertices** (numpy.ndarray) - Required - An array of vertex coordinates. - **edges** (numpy.ndarray) - Required - An array of vertex index pairs representing edges. ### Request Example ```json { "vertices": [ [0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0] ], "edges": [ [0, 1], [1, 3], [2, 3], [2, 0] ] } ``` ### Response #### Success Response (200) - **wire_network** (WireNetwork) - The created WireNetwork object. #### Response Example ```json { "wire_network": "" } ``` ``` -------------------------------- ### Load Mesh from File (PyMesh) Source: https://pymesh.readthedocs.io/en/latest/_sources/basic Loads a mesh from a specified file path using PyMesh. Supports various formats like .obj, .ply, .stl, etc. ```python import pymesh mesh = pymesh.load_mesh("model.obj") ``` -------------------------------- ### Compute and Get Vertex Gaussian Curvature with PyMesh Source: https://pymesh.readthedocs.io/en/latest/index Illustrates how to compute and retrieve the Gaussian curvature for each vertex of a mesh using PyMesh. This involves adding the 'vertex_gaussian_curvature' attribute and then accessing it. ```python >>> mesh.add_attribute("vertex_gaussian_curvature"); >>> mesh.get_attribute("vertex_gaussian_curvature"); array([ 1.57079633, 1.57079633, 1.57079633, 1.57079633, 1.57079633, 1.57079633, 1.57079633, 1.57079633]) ``` -------------------------------- ### Create Mesh from Raw Data (PyMesh) Source: https://pymesh.readthedocs.io/en/latest/_sources/basic Forms a mesh from raw vertex, face, and optional voxel data using PyMesh. Requires numpy arrays for input. ```python import pymesh import numpy as np # for surface mesh: mesh = pymesh.form_mesh(vertices, faces) # for volume mesh: mesh = pymesh.form_mesh(vertices, faces, voxels) # where vertices, faces, and voxels are numpy.ndarray. ``` -------------------------------- ### Add and Get Vertex Attributes (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Shows how to add custom attributes (like 'vertex_color') to a WireNetwork object and subsequently retrieve them. Attributes can represent scalar or vector fields associated with vertices or edges. ```python import pymesh import numpy as np vertex_colors = np.zeros((wire_network.num_vertices, 3)) wire_network.add_attribute("vertex_color", vertex_colors) print(wire_network.get_attribute("vertex_color")) ``` -------------------------------- ### Load Mesh from File using PyMesh Source: https://pymesh.readthedocs.io/en/latest/index Demonstrates how to load a mesh from a file using the PyMesh library. It requires the 'pymesh' library and a mesh file (e.g., 'cube.obj'). The output is a PyMesh object representing the loaded mesh. ```python >>> import pymesh >>> mesh = pymesh.load_mesh("cube.obj"); ``` -------------------------------- ### Generate Cylinder Mesh using PyMesh Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Generates a cylinder or conical frustum. It takes the start and end points of the central axis, along with their respective radii, and the number of segments to define the circular cross-section. ```python pymesh.generate_cylinder(p0, p1, r0, r1, num_segments=16) ``` -------------------------------- ### WireNetwork Construction from Data Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Creates a WireNetwork object from provided vertex positions and edge connectivity data. ```APIDOC ## WireNetwork Construction from Data ### Description Creates a `WireNetwork` object by providing vertex positions and a list of edges (vertex index pairs). ### Method `WireNetwork.create_from_data(vertices, edges)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **vertices** (numpy.ndarray) - Required - An array of shape (N, 3) representing N vertex coordinates. - **edges** (numpy.ndarray) - Required - An array of shape (M, 2) representing M edges, where each row contains the indices of the two connected vertices. ### Request Example ```python import numpy as np vertices = np.array([ [0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0] ]) edges = np.array([ [0, 1], [1, 3], [2, 3], [2, 0] ]) wire_network = pymesh.wires.WireNetwork.create_from_data(vertices, edges) ``` ### Response #### Success Response (200) - **WireNetwork object**: A `WireNetwork` object representing the frame structure. #### Response Example ```python # Successful creation of wire_network object ``` ``` -------------------------------- ### Attribute Management Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Functions for managing attributes associated with the wire network. This includes retrieving attribute names, checking for attribute existence, adding new attributes (vertex-wise or edge-wise), getting attribute values, and setting attribute values. ```python get_attribute_names() Get the names of all defined attributes. has_attribute(_name_) Check if an attribute exists. add_attribute(_name_ , _value=None_ , _vertex_wise=True_) Add a new attirbute. Parameters:| * **name** (`str`) – Attribute name. * **value** (`numpy.ndarray`) – N by d matrix of attribute values (one row per vertex or per edge). Default is None to represent uninitialized attribute value. * **vertex_wise** (`bool`) – Whether this attribute is assigned to vertices or edges. ---|--- get_attribute(_name_) Get the value of an attribute. is_vertex_attribute(_name_) Returns true if `name` is a per-vertex attribute. set_attribute(_name_ , _value_) Set the value of the attribute `name` to be `value`. ``` -------------------------------- ### Create WireNetwork from File (Python) Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Creates a WireNetwork object from a file, typically in a format similar to .obj but with a '.wire' extension. The file specifies vertex coordinates and edge connections. ```python import pymesh wire_network = pymesh.wires.WireNetwork.create_from_file( "test.wire") ``` -------------------------------- ### Generate Tube Mesh using PyMesh Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Generates a generalized tube, essentially a cylinder with an axial hole. Parameters include the start and end points of the axis, inner and outer radii for both ends, and the number of segments for the circular definition. ```python pymesh.generate_tube(p0, p1, r0_out, r1_out, r0_in, r1_in, num_segments=16, with_quad=False) ``` -------------------------------- ### Wire Network Profile and Refinement Source: https://pymesh.readthedocs.io/en/latest/api_procedural_mesh_generation Functions for setting the cross-section profile and refining the mesh. ```APIDOC ## POST /set_profile ### Description Sets the cross-section shape of each wire to an N-gon. ### Method POST ### Endpoint `/set_profile` ### Parameters #### Request Body - **N** (int) - The number of sides for the N-gon cross-section. ### Request Example ```json { "N": 6 } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ## POST /set_refinement ### Description Refines the output mesh using subdivision. ### Method POST ### Endpoint `/set_refinement` ### Parameters #### Request Body - **order** (int, optional) - The number of subdivision levels. Defaults to 1. - **method** (str, optional) - The subdivision scheme to use (`loop` or `simple`). Defaults to 'loop'. ### Request Example ```json { "order": 2, "method": "loop" } ``` ### Response #### Success Response (200) - **message** (str) - Success message. ``` -------------------------------- ### Perform Regular Grid Tiling with PyMesh Tiler Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Tiles a wire network according to a regular grid. This function distributes copies of the base wire network within a specified bounding box, creating a tiled structure. It takes the wire network, bounding box limits, and repetition counts as input. Requires the Tiler class and NumPy. ```python tiler = Tiler(wire_network) box_min = np.zeros(3) box_max = np.ones(3) * 15.0 reps = [3, 3, 3] tiler.tile_with_guide_bbox(box_min, box_max, reps) tiled_wires = tiler.wire_network ``` -------------------------------- ### Incremental CSGTree Construction in Python Source: https://pymesh.readthedocs.io/en/latest/_sources/mesh_boolean Demonstrates how to build a CSGTree incrementally using PyMesh. It shows the creation of left and right subtrees with specific operations and then combines them into a final CSGTree. The resulting mesh can be accessed via the .mesh attribute. ```python >>> left_tree = pymesh.CSGTree({ "intersection": [{"mesh": box}, {"mesh": ball}] }) >>> right_tree = pymesh.CSGTree({ "union": [{"mesh": x}, {"mesh": y}, {"mesh": z}] }) >>> csg = pymesh.CSGTree({ "difference": [left_tree, right_tree] }) >>> left_mesh = left_tree.mesh >>> right_mesh = right_tree.mesh >>> output = csg.mesh ``` -------------------------------- ### Initialize Wire Inflator Source: https://pymesh.readthedocs.io/en/latest/wire_mesh Creates an instance of the Inflator class, which is used to convert a WireNetwork into a triangular mesh. The WireNetwork object is passed during initialization. ```python >>> inflator = pymesh.wires.Inflator(wire_network) ``` -------------------------------- ### WireNetwork Load from File Source: https://pymesh.readthedocs.io/en/latest/_sources/wire_mesh Updates an existing WireNetwork object by loading data from a file. ```APIDOC ## WireNetwork Load from File ### Description Loads and assigns new vertex and edge data from a file to an existing `WireNetwork` object. ### Method `wire_network.load_from_file(filepath)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **filepath** (str) - Required - The path to the file containing the wire network data. ### Request Example ```python wire_network.load_from_file("another_test.wire") ``` ### Response #### Success Response (200) - **None**: This method modifies the object in-place. #### Response Example ```python # WireNetwork object updated successfully from file ``` ``` -------------------------------- ### Load Mesh from File Source: https://pymesh.readthedocs.io/en/latest/basic Loads a mesh from a specified file path using the PyMesh library. Supports various formats like .obj, .ply, .off, .stl, .mesh, .node, .poly, and .msh. ```python >>> mesh = pymesh.load_mesh("model.obj") ```