示例#1
0
def test_inflation_and_deflation_of_area(surface_paths, percentage):
    # Get default input
    common_input = read_command_line_area(surface_paths[0], surface_paths[1])

    # Change the default input
    common_input.update(dict(method="area",
                             region_of_interest="first_line",
                             percentage=percentage,
                             smooth=False))

    # Perform area manipulation
    manipulate_area(**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_point_data_array("CenterlineSectionArea", centerline_area)
    new_area = get_point_data_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
示例#2
0
def test_create_stenosis(surface_paths):
    # Get default input
    common_input = read_command_line_area(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"), 0)
    n = centerline.GetNumberOfPoints()
    region_point = list(centerline.GetPoint(int(n * 0.4)))

    # Change default input
    common_input.update(dict(region_of_interest="commandline",
                             region_points=region_point,
                             method="stenosis",
                             size=2.0,
                             percentage=50))

    # Create a stenosis
    manipulate_area(**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_point_data_array("CenterlineSectionArea", centerline_area)
    new_area = get_point_data_array("CenterlineSectionArea", new_centerline_area)

    # Check if there is a 50 % narrowing
    assert abs((np.sqrt(new_area / old_area)).min() - 0.5) < 0.05
def test_manipulate_branch_translation_and_polar_rotation(surface_paths):
    # Get default input
    common_input = read_command_line_branch(surface_paths[0], surface_paths[1])

    # Arbitrary branch in model C0001
    branch_number = 0

    # No rotation around new surface normal vector
    azimuth_angle0 = 0

    # New location of branch
    new_branch_location = (47.0, 27.8, 54.4)

    # Branch translation method
    translation_method = 'commandline'

    # Change default input
    common_input.update(
        dict(branch_to_manipulate_number=branch_number, branch_location=new_branch_location,
             translation_method=translation_method))

    # Run without rotation around surface normal
    common_input.update(dict(azimuth_angle=azimuth_angle0))

    # Run area variation
    manipulate_branch(**common_input)

    # Set file paths
    base_path = get_path_names(common_input['input_filepath'])
    old_centerlines_path = base_path + "_centerline.vtp"
    new_centerlines_path = base_path + "_centerline_moved.vtp"

    # Read centerlines
    old_centerlines = read_polydata(old_centerlines_path)
    old_centerlines = [extract_single_line(old_centerlines, i) for i in range(old_centerlines.GetNumberOfLines())]

    new_centerlines0 = read_polydata(new_centerlines_path)
    new_centerlines0 = [extract_single_line(new_centerlines0, i) for i in range(new_centerlines0.GetNumberOfLines())]

    # Perform same manipulation WITH rotation around new surface normal.
    azimuth_angle1 = np.pi
    common_input.update(dict(azimuth_angle=azimuth_angle1))

    # Run manipulate branch
    manipulate_branch(**common_input)

    # Read centerlines
    new_centerlines_path = base_path + "_centerline_moved_and_rotated.vtp"
    new_centerlines1 = read_polydata(new_centerlines_path)
    new_centerlines1 = [extract_single_line(new_centerlines1, i) for i in range(new_centerlines1.GetNumberOfLines())]

    # Compare end point of all centerlines
    unchanged_centerlines = compare_end_points(new_centerlines0, new_centerlines1)
    unchanged_centerlines0 = compare_end_points(new_centerlines0, old_centerlines)
    unchanged_centerlines1 = compare_end_points(new_centerlines1, old_centerlines)

    assert len(unchanged_centerlines) < len(old_centerlines)
    assert len(unchanged_centerlines0) < len(old_centerlines)
    assert len(unchanged_centerlines1) < len(old_centerlines)
def test_manipulate_branch_translation(surface_paths):
    # Get default input
    common_input = read_command_line_branch(surface_paths[0], surface_paths[1])

    # Opthalmic artery in model C0001
    branch_number = 2

    # No rotation around new surface normal vector
    azimuth_angle = 0

    # No rotation around new surface 'tangent' vector
    polar_angle = 0

    # New location of branch
    new_branch_location = (45.7, 37.6, 42.5)

    # Branch translation method
    translation_method = 'commandline'

    # Change default input
    common_input.update(
        dict(polar_angle=polar_angle, branch_to_manipulate_number=branch_number, branch_location=new_branch_location,
             translation_method=translation_method, azimuth_angle=azimuth_angle))

    # Run manipulate branch
    manipulate_branch(**common_input)

    # Set file paths
    base_path = get_path_names(common_input['input_filepath'])
    old_centerlines_path = base_path + "_centerline.vtp"
    new_centerlines_path = base_path + "_centerline_moved.vtp"

    # Read data, and get new area
    old_centerlines = read_polydata(old_centerlines_path)
    new_centerlines = read_polydata(new_centerlines_path)
    old_centerlines = [extract_single_line(old_centerlines, i) for i in range(old_centerlines.GetNumberOfLines())]
    new_centerlines = [extract_single_line(new_centerlines, i) for i in range(new_centerlines.GetNumberOfLines())]

    untouched_centerlines = compare_end_points(old_centerlines, new_centerlines)

    assert len(untouched_centerlines) < len(new_centerlines)
def test_manipulate_branch_azimuthal_rotation(surface_paths):
    # Get default input
    common_input = read_command_line_branch(surface_paths[0], surface_paths[1])

    # Arbitrary branch in model C0001
    branch_number = 2

    # No rotation around new surface normal vector
    azimuth_angle = np.pi

    # Branch translation method
    translation_method = 'no_translation'

    # Change default input
    common_input.update(
        dict(branch_to_manipulate_number=branch_number, translation_method=translation_method))

    # Run with only rotation around original surface normal
    common_input.update(dict(azimuth_angle=azimuth_angle))

    # Run manipulate branch
    manipulate_branch(**common_input)

    # Set file paths
    base_path = get_path_names(common_input['input_filepath'])
    old_centerlines_path = base_path + "_centerline.vtp"
    new_centerlines_path = base_path + "_centerline_rotated.vtp"

    # Read centerlines
    old_centerlines = read_polydata(old_centerlines_path)
    old_centerlines = [extract_single_line(old_centerlines, i) for i in range(old_centerlines.GetNumberOfLines())]

    new_centerlines = read_polydata(new_centerlines_path)
    new_centerlines = [extract_single_line(new_centerlines, i) for i in range(new_centerlines.GetNumberOfLines())]

    # Compare end point of all centerlines
    unchanged_centerlines = compare_end_points(new_centerlines, old_centerlines)

    assert len(unchanged_centerlines) < len(old_centerlines)
示例#6
0
def test_area_linear(surface_paths):
    # Get default input
    common_input = read_command_line_area(surface_paths[0], surface_paths[1])

    # Set 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_points = list(centerline.GetPoint(int(n * 0.3))) + list(centerline.GetPoint(int(n * 0.4)))

    # Change default input
    common_input.update(dict(region_of_interest="commandline",
                             region_points=region_points,
                             method="linear",
                             smooth=False,
                             size=1,
                             percentage=50))

    # Run area variation
    manipulate_area(**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)

    length = get_curvilinear_coordinate(centerline_spline)
    new_area = get_point_data_array("CenterlineSectionArea", new_centerline_area)
    linear_change = new_area[0] + (new_area[-1] - new_area[0]) * (length / length.max())

    # Check if the new area is within 2 % of the expected value
    assert (np.abs(new_area[:, 0] - linear_change) / linear_change).max() < 0.02
示例#7
0
def test_area_variation(ratio, surface_paths):
    # Get default input
    common_input = read_command_line_area(surface_paths[0], surface_paths[1])

    # Set 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_points = list(centerline.GetPoint(int(n * 0.05))) + list(centerline.GetPoint(int(n * 0.5)))

    # Change default input
    common_input.update(dict(method="variation",
                             smooth=False,
                             region_of_interest="commandline",
                             region_points=region_points,
                             ratio=ratio,
                             beta=None))

    # Run area variation
    manipulate_area(**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_point_data_array("CenterlineSectionArea", new_centerline_area)

    # Check if the new ratio holds
    assert abs(ratio - new_area.max() / new_area.min()) < 0.15