diff --git a/glenoidplanefitting/algorithms/models.py b/glenoidplanefitting/algorithms/models.py index b49b394..fff16d5 100644 --- a/glenoidplanefitting/algorithms/models.py +++ b/glenoidplanefitting/algorithms/models.py @@ -57,9 +57,9 @@ def make_vault_model(point1,point2): line.SetPoint2(point2) return line -def make_sphere_model(point): +def make_sphere_model(point, radius = 5.0): """ - Make a sphere source which we can use to represent a landmark + Make a sphere source which we can use to represent a landmark point :param point: the point @@ -70,5 +70,5 @@ def make_sphere_model(point): sphere_source.SetCenter(point) sphere_source.SetThetaResolution(12) sphere_source.SetPhiResolution(12) - sphere_source.SetRadius(5.0) + sphere_source.SetRadius(radius) return sphere_source diff --git a/glenoidplanefitting/ui/glenoidplanefitting_demo.py b/glenoidplanefitting/ui/glenoidplanefitting_demo.py index 82e3f55..aa00e69 100644 --- a/glenoidplanefitting/ui/glenoidplanefitting_demo.py +++ b/glenoidplanefitting/ui/glenoidplanefitting_demo.py @@ -14,7 +14,7 @@ from glenoidplanefitting.algorithms.models import make_plane_model, \ make_friedman_model, make_vault_model - +#pylint: disable=too-many-locals def run_demo(model_file_name, planes="", fried_points="", vault_points="", corr_fried="", output="", visualise = False, config_file = None): """ @@ -55,15 +55,14 @@ def run_demo(model_file_name, planes="", fried_points="", vault_points="", slice for picking the new landmark points for the 3D corrected Friedman method. - :param config_file: We can pass a configuration file, currently + :param config_file: We can pass a configuration file, currently focusing on visualisation parameters """ configuration = {} if config_file is not None: configurer = ConfigurationManager(config_file) configuration = configurer.get_copy() - background_colour = configuration.get('background colour', [0.8, 0.8, 0.8]) - model_colour = configuration.get('model colour', + model_colour = configuration.get('model colour', [0.89, 0.86, 0.79]) #bone from https://www.colorhexa.com/e3dac9 plane_resolution = configuration.get('plane resolution', 1) plane_size = configuration.get('plane size' , 200.0) @@ -96,7 +95,7 @@ def run_demo(model_file_name, planes="", fried_points="", vault_points="", if visualise: vis_planes(model, [result, result2, result3], points1, points2, - plane_resolution, plane_size, vary_plane_colour, + plane_resolution, plane_size, vary_plane_colour, point_size) @@ -125,7 +124,7 @@ def run_demo(model_file_name, planes="", fried_points="", vault_points="", result = vault.create_vault_line(anterior_glenoid,posterior_glenoid) if visualise: vis_vault(model, anterior_glenoid, posterior_glenoid, - glenoid_centre, result) + glenoid_centre, result, line_width = line_width) if corr_fried !="": diff --git a/glenoidplanefitting/widgets/visualisation.py b/glenoidplanefitting/widgets/visualisation.py index a8d975b..821da02 100644 --- a/glenoidplanefitting/widgets/visualisation.py +++ b/glenoidplanefitting/widgets/visualisation.py @@ -6,10 +6,12 @@ make_friedman_model, make_vault_model, make_sphere_model from glenoidplanefitting.algorithms.colour_palette import bang_list -def renderer_common(bone, background_colour = [0.9, 0.9, 0.9]): +def renderer_common(bone, background_colour = None): """ Initialises a vtk renderer and adds the bone model """ + if background_colour is None: + background_colour = [0.9, 0.9, 0.9] renderer = vtk.vtkRenderer() #pylint:disable=no-member renderer.SetBackground(background_colour) @@ -40,14 +42,16 @@ def render_window_common(renderer, window_name): render_window.Finalize() del render_window_interactor, render_window -def add_vtk_source(renderer, source, linewidth = 1.0, opacity = 1.0, wireframe = False, - colour = [1.0, 1.0, 1.0]): +def add_vtk_source(renderer, source, linewidth = 1.0, opacity = 1.0, + wireframe = False, colour = None): """ simplifies adding a vtk geometry source to a renderer :param renderer: a vtk renderer to add to :param source: a vtk geometry source """ + if colour is None: + colour = [1.0, 1.0, 1.0] mapper = vtk.vtkPolyDataMapper() #pylint:disable=no-member mapper.SetInputConnection(source.GetOutputPort()) actor = vtk.vtkActor() #pylint:disable=no-member @@ -61,16 +65,16 @@ def add_vtk_source(renderer, source, linewidth = 1.0, opacity = 1.0, wireframe = actor.GetProperty().SetSpecularColor(colour) else: actor.GetProperty().SetRepresentationToSurface() - + actor.GetProperty().SetColor(colour) actor.GetProperty().SetEdgeColor(colour) renderer.AddActor(actor) -def vis_planes(bone, planes, points1 = [], points2 = [], - resolution = 1, plane_size = 200.0, +def vis_planes(bone, planes, points1 = False, points2 = False, + resolution = 1, plane_size = 200.0, vary_plane_colour = False, - point_size = 1.0): + point_size = 5.0): """ Visualisation for plane fitting methods @@ -85,25 +89,27 @@ def vis_planes(bone, planes, points1 = [], points2 = [], if vary_plane_colour: colour = bang_list()[item] - plane_source = make_plane_model(plane[1], plane[2], resolution, plane_size) + plane_source = make_plane_model(plane[1], plane[2], resolution, + plane_size) add_vtk_source(renderer, plane_source, opacity = 0.15, colour = colour) - add_vtk_source(renderer, plane_source, linewidth = 2, opacity = 1.0, wireframe = True, - colour = colour) + add_vtk_source(renderer, plane_source, linewidth = 2, opacity = 1.0, + wireframe = True, colour = colour) - for point in points1: - colour = bang_list()[0] - sphere_source = make_sphere_model(point) - add_vtk_source(renderer, sphere_source, colour = colour) + if points1: + for point in points1: + colour = bang_list()[0] + sphere_source = make_sphere_model(point, point_size) + add_vtk_source(renderer, sphere_source, colour = colour) - for point in points2: - colour = bang_list()[1] - sphere_source = make_sphere_model(point) - add_vtk_source(renderer, sphere_source, colour = colour) + if points2: + for point in points2: + colour = bang_list()[1] + sphere_source = make_sphere_model(point, point_size) + add_vtk_source(renderer, sphere_source, colour = colour) render_window_common(renderer, "Fitted Planes") -def vis_fried(bone, cross1, cross2, glenoid1, result, resolution = 1, plane_size = 200.0, - line_width = 5): +def vis_fried(bone, cross1, cross2, glenoid1, result, line_width = 5): """ Visualise the lines resulting from the friedman method. @@ -116,7 +122,8 @@ def vis_fried(bone, cross1, cross2, glenoid1, result, resolution = 1, plane_size glenoid_line = make_friedman_model(cross1,cross2) colour = bang_list()[0] - add_vtk_source(renderer, glenoid_line, linewidth = line_width, colour = colour ) + add_vtk_source(renderer, glenoid_line, linewidth = line_width, + colour = colour ) sphere_source = make_sphere_model(cross1) add_vtk_source(renderer, sphere_source, colour = colour) @@ -128,12 +135,13 @@ def vis_fried(bone, cross1, cross2, glenoid1, result, resolution = 1, plane_size add_vtk_source(renderer, sphere_source, colour = colour) friedman_line = make_friedman_model(glenoid1,result) - add_vtk_source(renderer, friedman_line, linewidth = line_width, colour = colour) + add_vtk_source(renderer, friedman_line, linewidth = line_width, + colour = colour) render_window_common(renderer, "Friedman Lines") -def vis_vault(bone, cross1, cross2, glenoid1, result, resolution = 1, plane_size = 200.0): +def vis_vault(bone, cross1, cross2, glenoid1, result, line_width = 5): """ Visualise the lines resulting from the vault method. @@ -145,9 +153,21 @@ def vis_vault(bone, cross1, cross2, glenoid1, result, resolution = 1, plane_size renderer = renderer_common(bone) glenoid_line = make_vault_model(cross1,cross2) - add_vtk_source(renderer, glenoid_line) + colour = bang_list()[0] + add_vtk_source(renderer, glenoid_line, linewidth = line_width, + colour = colour) + + sphere_source = make_sphere_model(cross1) + add_vtk_source(renderer, sphere_source, colour = colour) + sphere_source = make_sphere_model(cross2) + add_vtk_source(renderer, sphere_source, colour = colour) + + colour = bang_list()[1] + sphere_source = make_sphere_model(glenoid1) + add_vtk_source(renderer, sphere_source, colour = colour) vault_line = make_vault_model(glenoid1, result) - add_vtk_source(renderer, vault_line) + add_vtk_source(renderer, vault_line, linewidth = line_width, + colour = colour) render_window_common(renderer, "Vault Lines")