示例#1
0
def tow_mesh(tow):
    """Creates mesh from tow coordinates to use for z offset projection
    Iterates through points and forms segments from outer points
    
    Parameters
    ----------
    tow : Tow object
        Tow object to be converted to mesh
    
    Returns
    -------
    Trimesh
        mesh representation of all points in tow
    """
    outer_mesh = Trimesh()
    # inner_mesh = Trimesh()
    [L1, L2, L3, L4, L5] = tow.new_pts
    for i in range(len(tow.new_pts[0]) - 1):
        v1 = L5[i]  # vertices has to be anticlockwise
        v2 = L5[i + 1]
        v3 = L4[i + 1]
        v4 = L4[i]
        v5 = L3[i + 1]
        v6 = L3[i]
        v7 = L2[i + 1]
        v8 = L2[i]
        v9 = L1[i + 1]
        v10 = L1[i]
        outer_mesh_segment = Trimesh(
            vertices=[v1, v2, v3, v4, v5, v6, v7, v8, v9, v10],
            faces=[[0, 1, 2], [2, 3, 0], [3, 2, 4], [3, 4, 5], [5, 4, 6],
                   [6, 7, 5], [7, 6, 8], [8, 9, 7]])
        # inner_mesh_segment = Trimesh(vertices=[v5, v6, v7, v8], faces=[[0, 1, 2, 3]])
        if i == 0:
            outer_mesh = outer_mesh_segment
        else:
            outer_mesh = outer_mesh.__add__(outer_mesh_segment)
    outer_mesh.merge_vertices()

    return outer_mesh
示例#2
0
def gen_intersecting_mesh(base_mesh, bodies):
    """Generates mesh of tows that are intersecting with ray offset

    
    Parameters
    ----------
    base_mesh : Trimesh
        Mesh of exisiting tows already laid down
    bodies: set(int)
        Indexes of bodies intersecting with the new tow
    
    Returns
    -------
    Trimesh
        Subset of base_mesh, containing only the tows from bodies
        
    """

    # Create copy of mesh so to not change any face data
    mesh_copy = base_mesh
    # Body count should be equivalent to the number of tows - make sure not to merge vertices
    body_count = mesh_copy.body_count
    # Split mesh modies into individual tow meshes
    mesh_bodies = mesh_copy.split(only_watertight=False)
    if (len(bodies) is 0):
        return Trimesh()

    # Based on interesting bodies, create new mesh with only those bodies
    intersecting = Trimesh()
    for i in bodies:
        if intersecting.is_empty:
            intersecting = mesh_bodies[i - 1]
        else:
            intersecting = intersecting.__add__(mesh_bodies[i - 1])

    return intersecting