Commit d148723e authored by Matt Clarkson's avatar Matt Clarkson

Issue #96: Add VTKOverlayWindow constructor arg to switch between either...

Issue #96: Add VTKOverlayWindow constructor arg to switch between either OpenCV or OpenGL conventions.
parent d54de331
......@@ -143,12 +143,22 @@ def compute_viewport(window_width,
return x_min, y_min, x_max, y_max
def set_camera_pose(vtk_camera, vtk_matrix):
def set_camera_pose(vtk_camera, vtk_matrix, opencv_style=True):
Sets the camera position and orientation from a camera to world matrix.
If opencv_style is False, the camera defaults to the origin,
facing along the -z axis, with +y being up.
If opencv_style is True (default for legacy compatibility), the camera
defaults to the origin, facing along the +z axis, with +y being down.
This is more in-line with Opencv. So, if you are calibrating with OpenCV,
and want to use those extrinsic matrices to set the pose,
then you want this option.
:param vtk_camera: a vtkCamera
:param vtk_matrix: a vtkMatrix4x4 representing the camera to world.
:param opencv_style: If True uses OpenCV (+z), otherwise OpenGL (-z)
if not isinstance(vtk_camera, vtk.vtkCamera):
raise TypeError('Invalid camera object passed')
......@@ -156,12 +166,17 @@ def set_camera_pose(vtk_camera, vtk_matrix):
if not isinstance(vtk_matrix, vtk.vtkMatrix4x4):
raise TypeError('Invalid matrix object passed')
# This implies a right handed coordinate system.
# By default, assume camera position is at origin,
# looking down the world +ve z-axis.
# All OpenCV/OpenGL/VTK use a right handed coordinate system.
# Start by placing at origin.
origin = [0, 0, 0, 1]
focal_point = [0, 0, 1000, 1]
view_up = [0, -1000, 0, 1]
# Then work out which way its facing.
if opencv_style:
focal_point = [0, 0, 1000, 1]
view_up = [0, -1000, 0, 1]
focal_point = [0, 0, -1000, 1]
view_up = [0, 1000, 0, 1]
vtk_matrix.MultiplyPoint(origin, origin)
vtk_matrix.MultiplyPoint(focal_point, focal_point)
......@@ -50,7 +50,8 @@ class VTKOverlayWindow(QVTKRenderWindowInteractor):
:param clipping_range: Near/Far clipping range.
:param aspect_ratio: Relative physical size of pixels, as x/y.
:param zbuffer: if True, will only render zbuffer of main renderer.
:param reset_camera: If True, will reset camera when a new model is added.
:param reset_camera: If True, resets camera when a new model is added.
:param opencv_style: If True, adopts OpenCV convention, otherwise OpenGL.
def __init__(self,
......@@ -58,7 +59,8 @@ class VTKOverlayWindow(QVTKRenderWindowInteractor):
clipping_range=(1, 1000),
Constructs a new VTKOverlayWindow.
......@@ -76,6 +78,7 @@ class VTKOverlayWindow(QVTKRenderWindowInteractor):
self.aspect_ratio = aspect_ratio
self.zbuffer = zbuffer
self.reset_camera = reset_camera
self.opencv_style = opencv_style
self.input = np.ones((400, 400, 3), dtype=np.uint8)
self.rgb_frame = None
......@@ -160,6 +163,12 @@ class VTKOverlayWindow(QVTKRenderWindowInteractor):
QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
default_pose = np.eye(4)
# Startup the widget fully
......@@ -307,7 +316,7 @@ class VTKOverlayWindow(QVTKRenderWindowInteractor):
self.camera_to_world = camera_to_world
vtk_cam = self.get_foreground_camera()
vtk_mat = mu.create_vtk_matrix_from_numpy(camera_to_world)
cm.set_camera_pose(vtk_cam, vtk_mat)
cm.set_camera_pose(vtk_cam, vtk_mat, self.opencv_style)
def add_vtk_models(self, models, layer=1):
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