Example #1
0
def mesh_isolines_numpy(mesh, attr_name, N=50):
    """Compute the isolines of a specified attribute of the vertices of a mesh.

    Parameters
    ----------
    mesh : Mesh
        A mesh object.
    attr_name : str
        The name of the vertex attribute.
    N : int, optional
        The density of the isolines.
        Default is ``50``.

    Returns
    -------
    tuple
        A tuple of a list of levels and a list of isolines.

        The list of levels contains the z-values at each of the isolines.
        Each isoline is a list of paths, and each path is a list polygons.

    """
    xy = [mesh.vertex_coordinates(key, 'xy') for key in mesh.vertices()]
    s = [mesh.vertex[key][attr_name] for key in mesh.vertices()]
    return scalarfield_contours_numpy(xy, s, N)
Example #2
0
def mesh_contours_numpy(mesh, N=50):
    """Compute the contours of the mesh.

    Notes
    -----
    The contours are defined as the isolines of the z-coordinates of the vertices
    of the mesh.

    Parameters
    ----------
    mesh : Mesh
        The mesh object.
    N : int, optional
        The density of the contours.
        Default is ``50``.

    Returns
    -------
    tuple
        A tuple of a list of levels and a list of contours.

        The list of levels contains the z-values at each of the contours.
        Each contour is a list of paths, and each path is a list polygons.

    Examples
    --------
    .. code-block:: python

        import compas
        from compas.datastructures import Mesh
        from compas.geometry import mesh_contours_numpy

        mesh = Mesh.from_obj(compas.get('hypar.obj'))
        print(mesh_contours_numpy(mesh))

    """
    xy = [mesh.vertex_coordinates(key, 'xy') for key in mesh.vertices()]
    z = [mesh.vertex_coordinates(key, 'z') for key in mesh.vertices()]
    return scalarfield_contours_numpy(xy, z, N)
Example #3
0
    import compas
    from compas.datastructures import Mesh
    from compas.geometry import centroid_points
    from compas.geometry import distance_point_point
    from compas.geometry import scalarfield_contours_numpy

    mesh = Mesh.from_obj(compas.get('faces.obj'))

    points = [mesh.vertex_coordinates(key) for key in mesh.vertices()]
    centroid = centroid_points(points)
    distances = [distance_point_point(point, centroid) for point in points]

    xy = [point[0:2] for point in points]

    levels, contours = scalarfield_contours_numpy(xy, distances)

    # xy = [mesh.vertex_coordinates(key, 'xy') for key in mesh.vertices()]
    # z = [mesh.get_vertex_attribute(key, 'z') for key in mesh.vertices()]
    # levels, contours = scalarfield_contours_numpy(xy, z)

    # levels, contours = mesh_contours_numpy(mesh)

    for i in range(len(contours)):
        level = levels[i]
        contour = contours[i]
        print(level)
        for path in contour:
            for polygon in path:
                print([point.tolist() for point in polygon])