Commit 43649209 authored by Stephen Thompson's avatar Stephen Thompson

Started implemeting a distance measure

parent 42164666
Pipeline #3721 failed with stages
in 6 minutes and 48 seconds
# coding=utf-8
""" Module for adding numbers. """
def add_two_numbers(input_x, input_y):
""" Add two numbers """
return input_x + input_y
# coding=utf-8
""" Algorithms for the surgery evaluation application """
from numpy import inf
def point_in_locator(point, point_locators, radius=1.0):
"""
Tests whether a point is within a set distance of any of a
list of point locators.
:param point: the point to test, in 3D (x,y,z)
:param point_locators: a list of vtkPointLocators
:param radius: optional search radius in mm (default=1.0)
:return locator: the index of the nearest point locator, (-1 if no locators within radius)
:return distance: distance to nearest point_locator
:raises: delegates to vtk
"""
minumum_distance = numpy.inf
locator_index = -1
for index, locator in enumerate(point_locators):
distance = vtk.mutable(0.0)
if locator.FindClosestPointWithinRadius(radius,point,distance) == -1:
continue
if distance > mimumum_distance:
continue
minumum_distance = distance
locator_index = index
return locator_index, minumum_distance
inside=pl.FindClosestPointWithinRadius(5.0,(0.0,0.0,0.0),distance)
reader = vtk.vtkSTLReader()
reader.SetFileName('phantom_patch_00.stl')
reader.Update()
source = reader.GetOutput()
pl = vtk.vtkPointLocator()
#this builds the point locator, which could be time consuming for a large set,
#we want to pass it
pl.SetDataSet(source)
#This isn't very useful, it returns the ID of the closest point
pl.FindClosestPoint(0,0,0)
#this gives us -1 if no points are within the radius
#otherwise gives the point id
return input_x + input_y
# coding=utf-8
"""Main loop for tracking visualisation"""
#from sksurgerytrackervisualisation.shapes import cone, cylinder
from math import isnan
from sksurgeryutils.common_overlay_apps import OverlayBaseApp
from sksurgerytrackervisualisation.algorithms.algorithms import (
np2vtk, configure_tracker, populate_models)
from sksurgerytrackervisualisation.algorithms.background_image import \
OverlayBackground
class OverlayApp(OverlayBaseApp):
"""Inherits from OverlayBaseApp, adding code to move vtk models
based on input from a scikitsurgery tracker"""
def __init__(self, config):
"""Overides overlay base app's init, to initialise the
external tracking system. Together with a video source"""
try:
super().__init__(None)
except RuntimeError:
self.update_rate = 30
self.img = None
self.timer = None
self.save_frame = None
if "image" in config:
self.bg_image = OverlayBackground(config.get("image"))
else:
default_config = {"logo" : True}
self.bg_image = OverlayBackground(default_config)
self._tracker = None
if "tracker config" in config:
self._tracker = configure_tracker(config.get("tracker config"))
self._model_handles, models = populate_models(config.get("models"))
self.vtk_overlay_window.add_vtk_models(models)
if "camera" in config:
camera_config = config.get("camera")
if "bounding box" in camera_config:
self.vtk_overlay_window.foreground_renderer.ResetCamera(
camera_config.get("bounding box"))
else:
self.vtk_overlay_window.foreground_renderer.ResetCamera(
-300, 300, -300, 300, -200, 0)
def update(self):
"""Update the background renderer with a new frame,
move the model and render"""
image = self.bg_image.next_image()
#add a method to move the rendered models
self._update_tracking()
self.vtk_overlay_window.set_video_image(image)
self.vtk_overlay_window.Render()
def _update_tracking(self):
"""Internal method to move the rendered models in
some interesting way
#Iterate through the rendered models
for actor in \
self.vtk_overlay_window.get_foreground_renderer().GetActors():
#get the current orientation
orientation = actor.GetOrientation()
#increase the rotation around the z-axis by 1.0 degrees
orientation = [orientation[0], orientation[1], orientation[2] + 1.0]
#add update the model's orientation
actor.SetOrientation(orientation)
"""
port_handles, _, _, tracking, quality = self._tracker.get_frame()
for ph_index, port_handle in enumerate(port_handles):
for actor_index, actor in enumerate(
self.vtk_overlay_window.get_foreground_renderer().
GetActors()):
if self._model_handles[actor_index] == port_handle:
if not isnan(quality[ph_index]):
actor.SetUserMatrix(np2vtk(tracking[ph_index]))
break
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment