Exemple #1
0
def mesh_thicken(mesh, thickness=1.0, cls=None):
    """Thicken a mesh.

    Parameters
    ----------
    mesh : Mesh
        A mesh to thicken.
    thickness : real
        The mesh thickness

    Returns
    -------
    thickened_mesh : Mesh
        The thickened mesh.
    """
    if cls is None:
        cls = type(mesh)

    # offset in both directions
    mesh_top, mesh_bottom = map(
        lambda eps: mesh_offset(mesh, eps * thickness / 2., cls), [+1, -1])

    # flip bottom part
    mesh_flip_cycles(mesh_bottom)

    # join parts
    thickened_mesh = meshes_join([mesh_top, mesh_bottom], cls)

    # close boundaries
    n = thickened_mesh.number_of_vertices() / 2
    for u, v in list(thickened_mesh.edges_on_boundary()):
        if u < n and v < n:
            thickened_mesh.add_face([u, v, v + n, u + n])

    return thickened_mesh
Exemple #2
0
def mesh_thicken(mesh, thickness=1.0, both=True):
    """Thicken a mesh.

    Parameters
    ----------
    mesh : :class:`compas.datastructures.Mesh`
        A mesh to thicken.
    thickness : float, optional
        The mesh thickness.
        This should be a positive value.
        Default is ``1.0``.
    both : bool, optional
        If true, the mesh is thickened on both sides of the original.
        Otherwise, the mesh is thickened on the side of the positive normal.

    Returns
    -------
    thickened_mesh : :class:`compas.datastructures.Mesh`
        The thickened mesh.

    Raises
    ------
    ValueError
        If ``thickness`` is not a positive number.

    Examples
    --------
    >>> from compas.datastructures import Mesh, mesh_thicken
    >>> from compas.geometry import distance_point_point as dist
    >>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]])
    >>> thick = mesh_thicken(mesh)
    >>> thick.is_closed()
    True

    """
    if thickness <= 0:
        raise ValueError("Thickness should be a positive number.")

    if both:
        mesh_top = mesh_offset(mesh, +0.5 * thickness)
        mesh_bottom = mesh_offset(mesh, -0.5 * thickness)
    else:
        mesh_top = mesh_offset(mesh, thickness)
        mesh_bottom = mesh.copy()

    # flip bottom part
    mesh_flip_cycles(mesh_bottom)

    # join parts
    thickened_mesh = meshes_join([mesh_top, mesh_bottom])

    # close boundaries
    n = thickened_mesh.number_of_vertices() / 2

    edges_on_boundary = [
        edge for boundary in list(thickened_mesh.edges_on_boundaries())
        for edge in boundary
    ]

    for u, v in edges_on_boundary:
        if u < n and v < n:
            thickened_mesh.add_face([u, v, v + n, u + n])

    return thickened_mesh