# Miscellaneous functions¶

## Matrix I/O¶

pymesh.save_matrix(filename, matrix, in_ascii=False)

Save matrix into file in .dmat format.

Parameters: filename (str) – Output file name. matrix (numpy.ndarray) – The matrix to save. in_ascii (boolean) – Whether to save matrix in ASCII. Default is false, which saves in binary format to save space.
pymesh.load_matrix(filename)

Load matrix from file (assuming .dmat format).

## Mesh type conversion¶

pymesh.quad_to_tri(mesh, keep_symmetry=False)

Parameters: mesh (Mesh) – Input quad mesh. keep_symmetry (boolean) – (optional) Whether to split quad symmetrically into triangles. Default is False. The resulting triangle mesh.
pymesh.hex_to_tet(mesh, keep_symmetry=False, subdiv_order=0)

Convert hex mesh into tet mesh.

Parameters: mesh (Mesh) – Input hex mesh. keep_symmetry (boolean) – (optional) Whether to split hex symmetrically into tets. Default is False. subdiv_order (int) – (optional) Number of times to subdiv the hex before splitting. Default is 0. The resulting tet mesh.

## Attribute type conversion¶

pymesh.convert_to_vertex_attribute(mesh, attr)

Convert attribute attr from either per-face or per-voxel attribute into per-vertex attribute.

Parameters: mesh (Mesh) – Input mesh. attr (numpy.ndarray) – #vertices by k matrix of floats. Per-vertex attribute. The value at a vertex will be the average of the values at its neighboring faces or voxels.
pymesh.convert_to_vertex_attribute_from_name(mesh, name)

Same as convert_to_vertex_attribute() except looking up attribute values from the input mesh using name.

pymesh.convert_to_face_attribute(mesh, attr)

Convert attribute attr from either per-vertex or per-voxel attribute into per-face attribute.

Parameters: mesh (Mesh) – Input mesh. attr (numpy.ndarray) – #faces by k matrix of floats. Per-face attribute. The value at a face will be the average of the values at its neighboring vertices or its neighboring voxels.
pymesh.convert_to_face_attribute_from_name(mesh, name)

Same as convert_to_face_attribute() except looking up attribute values from the input mesh using name.

pymesh.convert_to_voxel_attribute(mesh, attr)

Convert attribute attr from either per-vertex or per-face attribute into per-voxel attribute.

Parameters: mesh (Mesh) – Input mesh. attr (numpy.ndarray) – #voxel by k matrix of floats. Per-voxel attribute. The value at a voxel will be the average of the values at its neighboring vertices or faces.
pymesh.convert_to_voxel_attribute_from_name(mesh, name)

Same as convert_to_voxel_attribute() except looking up attribute values from the input mesh using name.

## Attribute mapping¶

pymesh.map_vertex_attribute(mesh1, mesh2, attr_name, bvh=None)

Map vertex attribute from mesh1 to mesh2 based on closest points.

Parameters: mesh1 (Mesh) – Source mesh, where the attribute is defined. mesh2 (Mesh) – Target mesh, where the attribute is mapped to. attr_name (string) – Attribute name. bvh (BVH) – Pre-computed Bounded volume hierarchy if available.

A new attribute with name attr_name is added to mesh2.

pymesh.map_face_attribute(mesh1, mesh2, attr_name, bvh=None)

Map face attribute from mesh1 to mesh2 based on closest points.

Parameters: mesh1 (Mesh) – Source mesh, where the attribute is defined. mesh2 (Mesh) – Target mesh, where the attribute is mapped to. attr_name (string) – Attribute name. bvh (BVH) – Pre-computed Bounded volume hierarchy if available.

A new attribute with name attr_name is added to mesh2.

pymesh.map_corner_attribute(mesh1, mesh2, attr_name, bvh=None)

Map per-vertex per-face attribute from mesh1 to mesh2 based on closest points.

Parameters: mesh1 (Mesh) – Source mesh, where the attribute is defined. mesh2 (Mesh) – Target mesh, where the attribute is mapped to. attr_name (string) – Attribute name. bvh (BVH) – Pre-computed Bounded volume hierarchy if available.

A new attribute with name attr_name is added to mesh2.

## Quaternion¶

class pymesh.Quaternion(quat=[1, 0, 0, 0])

This class implements quaternion used for 3D rotations.

w

float – same as quaternion.

x

float – same as quaternion.

y

float – same as quaternion.

z

float – same as quaternion.

classmethod fromAxisAngle(axis, angle)

Crate quaternion from axis angle representation

Parameters: angle (float) – Angle in radian. axis (numpy.ndarray) – Rotational axis. Not necessarily normalized. The following values are returned. quat (Quaternion): The corresponding quaternion object.
classmethod fromData(v1, v2)

Create the rotation to rotate v1 to v2

Parameters: v1 (numpy.ndarray) – From vector. Normalization not necessary. v2 (numpy.ndarray) – To vector. Normalization not necessary. The following values are returned. quat (Quaternion): Corresponding quaternion that rotates v1 to v2.
norm()

Quaternion norm.

normalize()

Normalize quaterion to have length 1.

to_matrix()

Convert to rotational matrix.

Returns: The corresponding rotational matrix. numpy.ndarray
conjugate()

returns the conjugate of this quaternion, does nothing to self.

rotate(v)

Rotate 3D vector v by this quaternion

Parameters: v (numpy.ndarray) – Must be 1D vector. The rotated vector.

## Exact number types¶

pymesh.Gmpz

alias of mock.

pymesh.Gmpq

alias of mock.

## Exact predicates¶

pymesh.orient_2D(p1, p2, p3)

Determine the orientation 2D points p1, p2, p3

Parameters: p1,p2,p3 – 2D points. positive if (p1, p2, p3) is in counterclockwise order. negative if (p1, p2, p3) is in clockwise order. 0.0 if they are collinear.
pymesh.orient_3D(p1, p2, p3, p4)

Determine the orientation 3D points p1, p2, p3, p4.

Parameters: p1,p2,p3,p4 – 3D points. positive if p4 is below the plane formed by (p1, p2, p3). negative if p4 is above the plane formed by (p1, p2, p3). 0.0 if they are coplanar.
pymesh.in_circle(p1, p2, p3, p4)

Determine if p4 is in the circle formed by p1, p2, p3.

Parameters: p1,p2,p3,p4 – 2D points. orient_2D(p1, p2, p3) must be postive, otherwise the result will be flipped. positive p4 is inside of the circle. negative p4 is outside of the circle. 0.0 if they are cocircular.
pymesh.in_sphere(p1, p2, p3, p4, p5)

Determine if p5 is in the sphere formed by p1, p2, p3, p4.

Parameters: p1,p2,p3,p4,p5 – 3D points. orient_3D(p1, p2, p3, p4) must be positive, otherwise the result will be flipped. positive p5 is inside of the sphere. negative p5 is outside of the sphere. 0.0 if they are cospherical.

The following predicates are built on top of above fundamental predicates.

pymesh.is_colinear(v0, v1, v2)

Return true if v0, v1 and v2 are colinear. Colinear check is done using exact predicates.

Parameters: v0 (numpy.ndarray) – vector of size 2 or 3. v1 (numpy.ndarray) – vector of size 2 or 3. v2 (numpy.ndarray) – vector of size 2 or 3. A boolean indicating whether v0, v1 and v2 are colinear.
pymesh.get_degenerated_faces(mesh)

A thin wrapper for get_degenerated_faces_raw().

pymesh.get_degenerated_faces_raw(vertices, faces)

Return indices of degenerated faces. A face is degenerated if all its 3 corners are colinear.

Parameters: vertices (numpy.ndarray) – Vertex matrix. faces (numpy.ndarray) – Face matrix. A numpy.ndarray of indices of degenerated faces.
pymesh.get_tet_orientations(mesh)

A thin wrapper of get_tet_orientations_raw.

pymesh.get_tet_orientations_raw(vertices, tets)

Compute orientation of each tet.

Parameters: vertice (numpy.ndarray) – n by 3 matrix representing vertices. tets (numpy.ndarray) – m by 4 matrix of vertex indices representing tets. A list of m floats, where Positive number => tet is positively oriented. 0 => tet is degenerate. Negative number => tet is inverted.

## Mesh compression¶

pymesh.compress(mesh, engine_name='draco')

Compress mesh data.

Parameters: mesh (Mesh) – Input mesh. engine_name (string) – Valid engines are: draco: Google’s Draco engine  A binary string representing the compressed mesh data.

A simple usage example:

>>> mesh = pymesh.generate_icosphere(1.0, [0, 0, 0])
>>> data = pymesh.compress(mesh)
>>> with open("out.drc", 'wb') as fout:
...     fout.write(data)

  Draco uses lossy compression. Both accuarcy and vertices/face order will be lost due to compression. Draco only works with triangular mesh or point cloud.
pymesh.decompress(data, engine_name='draco')

Decompress mesh data.

Parameters: data (string) – Binary string representing compressed mesh. engine_name (string) – Decompression engine name. Valid engines are: draco: Google’s Draco engine A mesh object encoded by the data.

A simple usage example:

>>> mesh = pymesh.generate_icosphere(1.0, [0, 0, 0])
>>> data = pymesh.compress(mesh)
>>> mesh2 = pymesh.decompress(data);


## Mesh to graph¶

pymesh.mesh_to_graph(mesh)

Convert a mesh into a graph $$(V, E)$$, where $$V$$ represents the mesh vertices, and $$E$$ represent the edges.

Parameters: mesh (Mesh) – Input mesh. The graph $$(V, E)$$.
pymesh.mesh_to_dual_graph(mesh)

Convert a mesh into a dual graph $$(V, E)$$, where $$V$$ represents the mesh faces, and $$E$$ represent the dual edges.

Parameters: mesh (Mesh) – Input mesh. The graph $$(V, E)$$.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5781146,"math_prob":0.94104016,"size":8602,"snap":"2020-24-2020-29","text_gpt3_token_len":2449,"char_repetition_ratio":0.14759247,"word_repetition_ratio":0.20105422,"special_character_ratio":0.27051848,"punctuation_ratio":0.21153846,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9887938,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-02T09:49:17Z\",\"WARC-Record-ID\":\"<urn:uuid:cf9ac568-0cba-4b02-94e0-09a487a5328a>\",\"Content-Length\":\"53694\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:be1d9ec2-835f-49b3-aa3e-9b370d814e2a>\",\"WARC-Concurrent-To\":\"<urn:uuid:6b8d8888-3440-4007-953e-4798f64105c9>\",\"WARC-IP-Address\":\"104.17.32.82\",\"WARC-Target-URI\":\"https://pymesh.readthedocs.io/en/latest/api_misc.html\",\"WARC-Payload-Digest\":\"sha1:2OTE3MS65WZ2A4ZZUWSZ7ZJGAV2PE42A\",\"WARC-Block-Digest\":\"sha1:OILNYJNZVU7ALIEWVM6XCNYVT2K3DS3M\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655878639.9_warc_CC-MAIN-20200702080623-20200702110623-00085.warc.gz\"}"}