Exemplo n.º 1
0
def test_regression_test1():
    """A regression test with manually init"""
    parameters = [136.0, 151.0, -91.0, 8.0]
    model = VTKSurfaceModel("data/CT_Level_1.vtp", [1., 0., 0.])
    x_values = model.get_points_as_numpy()[:, 0]
    y_values = model.get_points_as_numpy()[:, 1]
    z_values = model.get_points_as_numpy()[:, 2]
    result = sphere_fitting.fit_sphere_least_squares(x_values, y_values,
                                                     z_values, parameters)
    numpy.testing.assert_approx_equal(result.x[0], 136.571, significant=3)
    numpy.testing.assert_approx_equal(result.x[1], 151.973, significant=3)
    numpy.testing.assert_approx_equal(result.x[2], -95.518, significant=3)
    numpy.testing.assert_approx_equal(result.x[3], 8.119, significant=3)
def run_demo(model_file_name, output="", configfile=False):
    """ Run the application """
    model = VTKSurfaceModel(model_file_name, [1., 0., 0.])
    x_values = model.get_points_as_numpy()[:, 0]
    y_values = model.get_points_as_numpy()[:, 1]
    z_values = model.get_points_as_numpy()[:, 2]

    initial_parameters = [
        mean(x_values),
        mean(y_values),
        mean(z_values),
        std(x_values)
    ]
    bounds = ((-inf, -inf, -inf, -inf), (inf, inf, inf, inf))

    if configfile:
        configurer = ConfigurationManager(configfile)
        configuration = configurer.get_copy()
        if "initial values" in configuration:
            initial_parameters = configuration.get("initial values")
        if "bounds" in configuration:
            bounds = configuration.get("bounds")
        if "fixed radius" in configuration:
            radius = configuration.get("fixed radius")
            bounds = ((-inf, -inf, -inf, radius - 1e-6), (inf, inf, inf,
                                                          radius + 1e-6))

    result = sphere_fitting.fit_sphere_least_squares(x_values,
                                                     y_values,
                                                     z_values,
                                                     initial_parameters,
                                                     bounds=bounds)

    print("Result is {}".format(result))

    if output != "":

        sphere = vtk.vtkSphereSource()
        sphere.SetCenter(result.x[0], result.x[1], result.x[2])
        sphere.SetRadius(result.x[3])
        sphere.SetThetaResolution(60)
        sphere.SetPhiResolution(60)

        writer = vtk.vtkXMLPolyDataWriter()
        writer.SetFileName(output)
        writer.SetInputData(sphere.GetOutput())
        sphere.Update()
        writer.Write()
Exemplo n.º 3
0
def test_extract_points_and_normals_as_numpy_array():
    input_file = 'tests/data/models/Prostate.vtk'
    model = VTKSurfaceModel(input_file, colors.red)
    number_of_points = model.get_number_of_points()
    points = model.get_points_as_numpy()
    assert isinstance(points, np.ndarray)
    assert points.shape[0] == number_of_points
    assert points.shape[1] == 3
    normals = model.get_normals_as_numpy()
    assert isinstance(normals, np.ndarray)
    assert normals.shape[0] == number_of_points
    assert normals.shape[1] == 3
Exemplo n.º 4
0
def test_regression_test2():
    """A regression test with fixed radius"""
    model = VTKSurfaceModel("data/US_Sphere_2.vtp", [1., 0., 0.])
    x_values = model.get_points_as_numpy()[:, 0]
    y_values = model.get_points_as_numpy()[:, 1]
    z_values = model.get_points_as_numpy()[:, 2]
    parameters = [
        numpy.mean(x_values),
        numpy.mean(y_values),
        numpy.mean(z_values), 4.5
    ]
    radius = 4.5
    epsilon = 1e-6
    bounds = ((-numpy.inf, -numpy.inf, -numpy.inf, radius - epsilon),
              (numpy.inf, numpy.inf, numpy.inf, radius + epsilon))
    result = sphere_fitting.fit_sphere_least_squares(x_values,
                                                     y_values,
                                                     z_values,
                                                     parameters,
                                                     bounds=bounds)
    numpy.testing.assert_approx_equal(result.x[0], 86.474, significant=3)
    numpy.testing.assert_approx_equal(result.x[1], -97.243, significant=3)
    numpy.testing.assert_approx_equal(result.x[2], -208.528, significant=3)
    numpy.testing.assert_approx_equal(result.x[3], 4.500, significant=3)