Ejemplo n.º 1
0
    def SetVolumeCamera(self, pubsub_evt):
        if self.camera_state:
            #TODO: exclude dependency on initial focus
            cam_focus = np.array(bases.flip_x(pubsub_evt.data))
            cam = self.ren.GetActiveCamera()

            if self.initial_focus is None:
                self.initial_focus = np.array(cam.GetFocalPoint())

            cam_pos0 = np.array(cam.GetPosition())
            cam_focus0 = np.array(cam.GetFocalPoint())

            v0 = cam_pos0 - cam_focus0
            v0n = np.sqrt(inner1d(v0, v0))

            v1 = (cam_focus - self.initial_focus)
            v1n = np.sqrt(inner1d(v1, v1))
            if not v1n:
                v1n = 1.0
            cam_pos = (v1 / v1n) * v0n + cam_focus

            cam.SetFocalPoint(cam_focus)
            cam.SetPosition(cam_pos)

        # It works without doing the reset. Check with trackers if there is any difference.
        # Need to be outside condition for sphere marker position update
        # self.ren.ResetCameraClippingRange()
        # self.ren.ResetCamera()
        self.interactor.Render()
Ejemplo n.º 2
0
    def AddMarker(self, pubsub_evt):
        """
        Markers create by navigation tools and
        rendered in volume viewer.
        """
        self.ball_id = pubsub_evt.data[0]
        ballsize = pubsub_evt.data[1]
        ballcolour = pubsub_evt.data[2]
        coord = pubsub_evt.data[3]
        x, y, z = bases.flip_x(coord)

        ball_ref = vtk.vtkSphereSource()
        ball_ref.SetRadius(ballsize)
        ball_ref.SetCenter(x, y, z)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(ball_ref.GetOutputPort())

        prop = vtk.vtkProperty()
        prop.SetColor(ballcolour)

        #adding a new actor for the present ball
        self.staticballs.append(vtk.vtkActor())

        self.staticballs[self.ball_id].SetMapper(mapper)
        self.staticballs[self.ball_id].SetProperty(prop)

        self.ren.AddActor(self.staticballs[self.ball_id])
        self.ball_id = self.ball_id + 1
        self.UpdateRender()
Ejemplo n.º 3
0
    def SetBallReferencePosition(self, pubsub_evt):
        if self._to_show_ball:
            if not self.ball_actor:
                self.ActivateBallReference()

            coord = pubsub_evt.data
            x, y, z = bases.flip_x(coord)
            self.ball_actor.SetPosition(x, y, z)

        else:
            self.RemoveBallReference()