def test_inflation_and_deflation_of_area(common_input, percentage):
    common_input.update(
        dict(
            method="area",
            region_points=None,  # Inactive
            region_of_interest="first_line",
            stenosis_length=0,  # Inactive
            percentage=percentage,
            ratio=None,  # Inactive
            beta=None))  # Inactive

    # Perform area manipulation
    area_variations(**common_input)

    # Import old area and splined centerline for region of interest
    base_path = get_path_names(common_input['input_filepath'])
    centerline_spline_path = base_path + "_centerline_spline.vtp"
    centerline_area_spline_path = base_path + "_centerline_area_spline.vtp"
    surface = read_polydata(common_input["output_filepath"])
    centerline_area = read_polydata(centerline_area_spline_path)
    centerline_spline = read_polydata(centerline_spline_path)
    new_centerline_area, _ = vmtk_compute_centerline_sections(
        surface, centerline_spline)
    old_area = get_array("CenterlineSectionArea", centerline_area)
    new_area = get_array("CenterlineSectionArea", new_centerline_area)

    # Exclude first 5 %
    old_area = old_area[int(0.1 * old_area.shape[0]):]
    new_area = new_area[int(0.1 * new_area.shape[0]):]

    # Change in radius
    ratio = np.sqrt(new_area / old_area)

    # Check if the altered area is equal has change according to percentage
    assert np.mean(np.abs(ratio - (1 + percentage * 0.01))) < 0.05
def test_area_variation(ratio, common_input):
    common_input.update(
        dict(
            method="variation",
            region_points=None,  # Inactive
            region_of_interest="first_line",
            stenosis_length=0,  # Inactive
            percentage=0,  # Inactive
            ratio=ratio,
            beta=None))

    # Run area variation
    area_variations(**common_input)

    # Set file paths
    base_path = get_path_names(common_input['input_filepath'])
    centerline_spline_path = base_path + "_centerline_spline.vtp"
    new_surface_path = common_input["output_filepath"]

    # Read data, and get new area
    surface = read_polydata(new_surface_path)
    centerline_spline = read_polydata(centerline_spline_path)
    new_centerline_area, _ = vmtk_compute_centerline_sections(
        surface, centerline_spline)

    new_area = get_array("CenterlineSectionArea", new_centerline_area)

    # Check if the new ratio holds
    print("Target ratio", ratio, "New ratio", new_area.max() / new_area.min())
    assert ratio - new_area.max() / new_area.min() < 0.01
Beispiel #3
0
def test_decrease_curvature(common_input, smooth_line):
    # 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(resampling_step=0.1,
             smooth_factor_line=1.5,
             iterations=200,
             region_of_interest="commandline",
             region_points=region_points,
             smooth_line=smooth_line))

    # Manipulate surface
    curvature_variations(**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_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,
                                         startID=old_id1,
                                         endID=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_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,
                                         startID=new_id1,
                                         endID=new_id2)

    # Comute curvature and assert
    _, old_curvature = discrete_geometry(old_centerline, neigh=20)
    _, new_curvature = discrete_geometry(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_create_stenosis(common_input):
    # Get region points
    base_path = get_path_names(common_input['input_filepath'])
    centerline = extract_single_line(
        read_polydata(base_path + "_centerline.vtp"), 0)
    n = centerline.GetNumberOfPoints()
    region_point = list(centerline.GetPoint(int(n * 0.4)))
    common_input['region_of_interest'] = "commandline"
    common_input['region_points'] = region_point

    # Set problem specific parameters
    common_input.update(
        dict(
            method="stenosis",
            stenosis_length=1.0,
            percentage=50,
            ratio=None,  # Inactive
            beta=None))  # Inactive

    # Create a stenosis
    print(common_input)
    area_variations(**common_input)

    # Import old area and splined centerline for region of interest
    base_path = get_path_names(common_input['input_filepath'])
    centerline_spline_path = base_path + "_centerline_spline.vtp"
    centerline_area_spline_path = base_path + "_centerline_area_spline.vtp"
    new_surface_path = common_input["output_filepath"]
    surface = read_polydata(new_surface_path)
    centerline_area = read_polydata(centerline_area_spline_path)
    centerline_spline = read_polydata(centerline_spline_path)
    new_centerline_area, _ = vmtk_compute_centerline_sections(
        surface, centerline_spline)
    old_area = get_array("CenterlineSectionArea", centerline_area)
    new_area = get_array("CenterlineSectionArea", new_centerline_area)

    # Check if there is a 50 % narrowing
    assert (np.sqrt(new_area / old_area)).min() - 0.5 < 0.05
def test_siphon(common_input, alpha, beta):
    # Set problem specific parameters
    common_input.update(
        dict(
            alpha=alpha,
            beta=beta,
            region_of_interest="commandline",
            # TODO: Set points
            region_points=[
                44.17085266113281, 38.514854431152344, 41.20818328857422,
                43.242130279541016, 42.68572235107422, 38.65191650390625
            ],
            resampling_step=0.1))

    # Perform manipulation
    print(common_input.items())
    move_vessel(**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
Beispiel #6
0
def test_bifurcation_angle(common_input, angle):
    common_input.update(dict(keep_fixed_1 = False,
                             keep_fixed_2 = False,
                             bif = False,
                             lower = False,
                             cylinder_factor = 7,
                             angle = angle,
                             region_of_interest = "commandline",
                             region_points = [35.8, 59.8, 39.7, 76.8, 54.7, 53.2]))

    rotate_branches(**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_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_locator(line_old)
        loc_new = get_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 distance(start_point1, line_old.GetPoint(id1_old)) < tol:
            cl_old_1 = i
            cl_old_id1 = id1_old
        if distance(start_point2, line_old.GetPoint(id2_old)) < tol:
            cl_old_2 = i
            cl_old_id2 = id2_old
        if distance(start_point1, line_new.GetPoint(id1_new)) < tol:
            cl_new_1 = i
            cl_new_id1 = id1_new
        if 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.01