def test_noise_surface(surface_paths):
    # Get default inputs
    common_input = read_command_line_surface(surface_paths[0], surface_paths[1])
    common_input.update(dict(noise=True,
                             smooth=False,
                             frequency=5,
                             frequency_deviation=0.01,
                             add_noise_lower_limit=0.8,
                             add_noise_upper_limit=0.95,
                             radius_min=1.1,
                             radius_max=1.35,
                             poly_ball_size=[250, 250, 250]))

    # Manipulate surface
    manipulate_surface(**common_input)

    old_surface = read_polydata(surface_paths[0])
    new_surface = read_polydata(surface_paths[1])

    # Compare curvature
    old_surface = vmtk_surface_curvature(old_surface, curvature_type="gaussian",
                                         absolute=True, median_filtering=True,
                                         bounded_reciporcal=True)
    new_surface = vmtk_surface_curvature(new_surface, curvature_type="gaussian",
                                         absolute=True, median_filtering=True,
                                         bounded_reciporcal=True)

    old_curvature = get_point_data_array("Curvature", old_surface, k=1)
    new_curvature = get_point_data_array("Curvature", new_surface, k=1)

    assert np.mean(new_curvature) > np.mean(old_curvature)
def test_smooth_surface(surface_paths):
    # Get default inputs
    common_input = read_command_line_surface(surface_paths[0], surface_paths[1])
    common_input["poly_ball_size"] = [250, 250, 250]

    # Manipulate surface
    manipulate_surface(**common_input)

    old_voronoi = read_polydata(surface_paths[0].replace(".vtp", "_voronoi.vtp"))
    old_surface = create_new_surface(old_voronoi, poly_ball_size=common_input["poly_ball_size"])
    new_surface = read_polydata(surface_paths[1])

    # Compare curvature
    old_surface = vmtk_surface_curvature(old_surface, curvature_type="gaussian",
                                         absolute=True, median_filtering=True,
                                         bounded_reciporcal=True)
    new_surface = vmtk_surface_curvature(new_surface, curvature_type="gaussian",
                                         absolute=True, median_filtering=True,
                                         bounded_reciporcal=True)
    write_polydata(new_surface, "tmp_new.vtp")
    write_polydata(old_surface, "tmp_old.vtp")
    old_curvature = get_point_data_array("Curvature", old_surface, k=1)
    new_curvature = get_point_data_array("Curvature", new_surface, k=1)

    assert np.mean(new_curvature) < np.mean(old_curvature)
def test_decrease_curvature(surface_paths, smooth_line):
    # Get default inputs
    common_input = read_command_line_curvature(surface_paths[0], surface_paths[1])

    # Get region points
    base_path = get_path_names(common_input["input_filepath"])
    centerline = extract_single_line(read_polydata(base_path + "_centerline.vtp"), 1)
    n = centerline.GetNumberOfPoints()
    region_points = list(centerline.GetPoint(int(n * 0.1))) + list(centerline.GetPoint(int(n * 0.4)))

    # Set problem specific parameters
    common_input.update(dict(smooth_factor_line=1.5,
                             iterations=200,
                             region_of_interest="commandline",
                             region_points=region_points,
                             smooth_line=smooth_line))

    # Manipulate surface
    manipulate_curvature(**common_input)

    # Select and compare altered region
    p1 = np.asarray(region_points[:3])
    p2 = np.asarray(region_points[3:])

    old_centerlines_path = base_path + "_centerline.vtp"
    old_centerlines = read_polydata(old_centerlines_path)
    old_locator = get_vtk_point_locator(extract_single_line(old_centerlines, 0))
    old_id1 = old_locator.FindClosestPoint(p1)
    old_id2 = old_locator.FindClosestPoint(p2)
    old_centerline = extract_single_line(old_centerlines, 0, start_id=old_id1,
                                         end_id=old_id2)

    direction = "smoothed" if smooth_line else "extended"
    new_centerlines_path = base_path + "_centerline_new_%s.vtp" % direction
    new_centerlines = read_polydata(new_centerlines_path)
    new_locator = get_vtk_point_locator(extract_single_line(new_centerlines, 0))
    new_id1 = new_locator.FindClosestPoint(p1)
    new_id2 = new_locator.FindClosestPoint(p2)
    new_centerline = extract_single_line(new_centerlines, 0, start_id=new_id1,
                                         end_id=new_id2)

    # Comute curvature and assert
    _, old_curvature = compute_discrete_derivatives(old_centerline, neigh=20)
    _, new_curvature = compute_discrete_derivatives(new_centerline, neigh=20)
    old_mean_curv = np.mean(old_curvature)
    new_mean_curv = np.mean(new_curvature)
    if smooth_line:
        assert old_mean_curv > new_mean_curv
    else:
        assert old_mean_curv < new_mean_curv
def test_siphon(surface_paths, alpha, beta):
    # Set problem specific parameters
    common_input = read_command_line_bend(surface_paths[0], surface_paths[1])
    common_input.update(
        dict(alpha=alpha,
             beta=beta,
             region_of_interest="commandline",
             region_points=[
                 44.17085266113281, 38.514854431152344, 41.20818328857422,
                 43.242130279541016, 42.68572235107422, 38.65191650390625
             ]))

    # Perform manipulation
    manipulate_bend(**common_input)

    # Compute angle
    base_path = get_path_names(common_input['input_filepath'])
    new_centerlines_path = base_path + "_centerlines_alpha_%s_beta_%s.vtp" % (
        alpha, beta)
    new_centerlines = read_polydata(new_centerlines_path)
    angle_new, angle_original = compute_angle(
        common_input["input_filepath"],
        alpha,
        beta,
        "plane",
        new_centerlines,
        region_of_interest=common_input["region_of_interest"],
        region_points=common_input["region_points"])

    if alpha < 0 and beta == 0 or beta > 0 and alpha == 0:
        assert angle_original < angle_new
    elif alpha > 0 and beta == 0 or beta < 0 and alpha == 0:
        assert angle_original > angle_new
    else:
        assert angle_original > angle_new
示例#5
0
def vmtk_compute_voronoi_diagram(surface,
                                 filename,
                                 simplify_voronoi=False,
                                 cap_displacement=None,
                                 flip_normals=False,
                                 check_non_manifold=False,
                                 delaunay_tolerance=0.001,
                                 subresolution_factor=1.0):
    """
    Wrapper for vmtkDelanayVoronoi. Creates a surface model's
    coresponding voronoi diagram.

    Args:
        subresolution_factor (float): Factor for removal of subresolution tetrahedra
        flip_normals (bool): Flip normals after outward normal computation.
        cap_displacement (float): Displacement of the center points of caps at open profiles along their normals
        simplify_voronoi (bool): Use alternative algorith for compute Voronoi diagram, reducing quality, improving speed
        check_non_manifold (bool): Check the surface for non-manifold edges
        delaunay_tolerance (float): Tolerance for evaluating coincident points during Delaunay tessellation
        surface (vtkPolyData): Surface model
        filename (str): Path where voronoi diagram is stored

    Returns:
        new_voronoi (vtkPolyData): Voronoi diagram
    """
    if path.isfile(filename):
        return read_polydata(filename)

    voronoi = vmtkscripts.vmtkDelaunayVoronoi()
    voronoi.Surface = surface
    voronoi.RemoveSubresolutionTetrahedra = 1
    voronoi.DelaunayTolerance = delaunay_tolerance
    voronoi.SubresolutionFactor = subresolution_factor
    if simplify_voronoi:
        voronoi.SimplifyVoronoi = 1
    if cap_displacement is not None:
        voronoi.CapDisplacement = cap_displacement
    if flip_normals:
        voronoi.FlipNormals = 1
    if check_non_manifold:
        voronoi.CheckNonManifold = 1

    voronoi.Execute()
    new_voronoi = voronoi.VoronoiDiagram

    write_polydata(new_voronoi, filename)

    return new_voronoi
示例#6
0
def test_bifurcation_angle(surface_paths, angle):
    common_input = read_command_line_bifurcation(surface_paths[0],
                                                 surface_paths[1])
    common_input.update(
        dict(angle=angle,
             region_of_interest="commandline",
             region_points=[35.8, 59.8, 39.7, 76.8, 54.7, 53.2]))

    manipulate_bifurcation(**common_input)

    # Read in files to compute angle
    base_path = get_path_names(common_input["input_filepath"])
    old_centerlines = read_polydata(base_path + "_centerline_par.vtp")
    new_centerlines = read_polydata(base_path +
                                    "_centerline_interpolated_ang.vtp")
    end_points = read_polydata(base_path + "_clippingpoints.vtp")

    # Start points
    start_point1 = end_points.GetPoint(1)
    start_point2 = end_points.GetPoint(2)

    # Get relevant centerlines
    cl_old_1 = -1
    cl_old_2 = -1
    cl_new_1 = -1
    cl_new_2 = -1
    tol = get_centerline_tolerance(old_centerlines)

    for i in range(old_centerlines.GetNumberOfLines()):
        line_old = extract_single_line(old_centerlines, i)
        line_new = extract_single_line(new_centerlines, i)

        loc_old = get_vtk_point_locator(line_old)
        loc_new = get_vtk_point_locator(line_new)

        id1_old = loc_old.FindClosestPoint(start_point1)
        id2_old = loc_old.FindClosestPoint(start_point2)

        id1_new = loc_new.FindClosestPoint(start_point1)
        id2_new = loc_new.FindClosestPoint(start_point2)

        if get_distance(start_point1, line_old.GetPoint(id1_old)) < tol:
            cl_old_1 = i
            cl_old_id1 = id1_old
        if get_distance(start_point2, line_old.GetPoint(id2_old)) < tol:
            cl_old_2 = i
            cl_old_id2 = id2_old
        if get_distance(start_point1, line_new.GetPoint(id1_new)) < tol:
            cl_new_1 = i
            cl_new_id1 = id1_new
        if get_distance(start_point2, line_new.GetPoint(id2_new)) < tol:
            cl_new_2 = i
            cl_new_id2 = id2_new

        if -1 not in [cl_old_1, cl_old_2, cl_new_1, cl_new_2]:
            break

    # Get end points
    end_point1_old = np.array(
        extract_single_line(old_centerlines,
                            cl_old_1).GetPoint(cl_old_id1 + 20))
    end_point2_old = np.array(
        extract_single_line(old_centerlines,
                            cl_old_2).GetPoint(cl_old_id2 + 20))
    end_point1_new = np.array(
        extract_single_line(new_centerlines,
                            cl_new_1).GetPoint(cl_new_id1 + 20))
    end_point2_new = np.array(
        extract_single_line(new_centerlines,
                            cl_new_2).GetPoint(cl_new_id2 + 20))

    # Vectors
    v1_old = end_point1_old - np.array(start_point1)
    v2_old = end_point2_old - np.array(start_point2)
    v1_new = end_point1_new - np.array(start_point1)
    v2_new = end_point2_new - np.array(start_point2)

    # Normalize
    v1_old = v1_old / np.sqrt(np.sum(v1_old**2))
    v2_old = v2_old / np.sqrt(np.sum(v2_old**2))
    v1_new = v1_new / np.sqrt(np.sum(v1_new**2))
    v2_new = v2_new / np.sqrt(np.sum(v2_new**2))

    # Angle
    first_daughter_branch_angle_change = np.arccos(np.dot(v1_old, v1_new))
    second_daughter_branch_angle_change = np.arccos(np.dot(v2_old, v2_new))

    assert abs(first_daughter_branch_angle_change +
               second_daughter_branch_angle_change -
               2 * abs(common_input["angle"])) < 0.04