Commit ad3d1df8 authored by Thomas Dowrick's avatar Thomas Dowrick

Merge branch...

Merge branch '12-fix-sksurgeryrendermodelslikecamera_demo-py-to-exit-when-you-provide-a-file-name-to-save-to' into 'master'

Resolve "Fix sksurgeryrendermodelslikecamera_demo.py to exit when you provide a file name to save to."

Closes #12

See merge request WEISS/SoftwareRepositories/SNAPPY/scikit-surgeryutils!5
parents 85436ea2 cc0c8dc9
Pipeline #1696 failed with stages
in 5 minutes and 45 seconds
......@@ -12,57 +12,49 @@ from sksurgeryvtk.widgets import vtk_overlay_window
from sksurgeryvtk.models import vtk_surface_model_directory_loader
from sksurgeryvtk.models import vtk_point_model
class RenderModelDemoGui(QtWidgets.QWidget):
""" Demo app, to render an image using a calibrated camera. """
def __init__(self, image_file, model_dir, extrinsics_file,
intrinsics_file, points_file, output_file):
super().__init__()
vtk_widget = vtk_overlay_window.VTKOverlayWindow()
# Set the video image on the widget.
img = cv2.imread(image_file)
vtk_widget.set_video_image(img)
layout = QtWidgets.QVBoxLayout()
layout.setSpacing(0)
layout.setMargin(0)
layout.addWidget(vtk_widget)
def run_demo(image_file, model_dir, extrinsics_file,
intrinsics_file, points_file, output_file):
""" Demo app, to render an image using a calibrated camera. """
app = QtWidgets.QApplication([])
self.resize(img.shape[1], img.shape[0])
self.setLayout(layout)
vtk_widget = vtk_overlay_window.VTKOverlayWindow()
if points_file:
points = np.loadtxt(points_file)
vtk_points = vtk_point_model.VTKPointModel(points.astype(np.float),
points.astype(np.byte))
vtk_widget.add_vtk_actor(vtk_points.actor)
# Set the video image on the widget.
img = cv2.imread(image_file)
vtk_widget.set_video_image(img)
if model_dir:
model_loader = vtk_surface_model_directory_loader. \
VTKSurfaceModelDirectoryLoader(model_dir)
vtk_widget.add_vtk_models(model_loader.models)
layout = QtWidgets.QVBoxLayout()
layout.setSpacing(0)
layout.setMargin(0)
layout.addWidget(vtk_widget)
if extrinsics_file and intrinsics_file:
window = QtWidgets.QWidget()
window.resize(img.shape[1], img.shape[0])
window.setLayout(layout)
window.show()
intrinsics = np.loadtxt(intrinsics_file, dtype=np.float)
extrinsics = np.loadtxt(extrinsics_file)
if points_file:
points = np.loadtxt(points_file)
vtk_points = vtk_point_model.VTKPointModel(points.astype(np.float),
points.astype(np.byte))
vtk_widget.add_vtk_actor(vtk_points.actor)
vtk_widget.set_camera_matrix(intrinsics)
vtk_widget.set_camera_pose(extrinsics)
if model_dir:
model_loader = vtk_surface_model_directory_loader. \
VTKSurfaceModelDirectoryLoader(model_dir)
vtk_widget.add_vtk_models(model_loader.models)
if output_file:
vtk_widget.save_scene_to_file(output_file)
sys.exit()
if extrinsics_file and intrinsics_file:
intrinsics = np.loadtxt(intrinsics_file, dtype=np.float)
extrinsics = np.loadtxt(extrinsics_file)
def run_demo(image_file, model_dir, extrinsics_file,
intrinsics_file, points_file, output_file):
""" Demo app, to render an image using a calibrated camera. """
app = QtWidgets.QApplication([])
vtk_widget.set_camera_matrix(intrinsics)
vtk_widget.set_camera_pose(extrinsics)
widget = RenderModelDemoGui(image_file, model_dir, extrinsics_file,
intrinsics_file, points_file, output_file)
if output_file:
vtk_widget.save_scene_to_file(output_file)
return 0
widget.show()
return sys.exit(app.exec_())
......@@ -2,9 +2,9 @@
"""sksurgeryrendermodelslikecamera tests"""
from sksurgeryutils.ui.sksurgeryrendermodelslikecamera_demo import RenderModelDemoGui
import pytest
@pytest.mark.skip(reason="Need to reimplement")
def test_rendermodelslikecamera(qtbot):
""" Basic test to run the widget and make sure everything loads OK."""
......
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