def __init__(self, imageData=None):
        MarkerWindowInteractor.__init__(self) #does this really just control the markers or is it for the other frames too?

        print "PlaneWidgetsXYZ.__init__()"

        self.vtksurface = None

        self.interactButtons = (1,2,3)
        self.sharedPicker = vtk.vtkCellPicker()
        #self.sharedPicker.SetTolerance(0.005)
        self.SetPicker(self.sharedPicker)
        #initialize all three axes slice objects on the bottom of the window
        self.pwX = vtk.vtkImagePlaneWidget()
        self.pwY = vtk.vtkImagePlaneWidget()
        self.pwZ = vtk.vtkImagePlaneWidget()

        
        self.textActors = {}
        self.boxes = {}

        self.set_image_data(imageData)
        self.Render()

        self.vtk_translation = zeros(3, 'd')
        self.vtk_rotation = zeros(3, 'd')
Exemplo n.º 2
0
    def __init__(self, imageData=None):
        MarkerWindowInteractor.__init__(
            self
        )  #does this really just control the markers or is it for the other frames too?

        print "PlaneWidgetsXYZ.__init__()"

        self.vtksurface = None

        self.interactButtons = (1, 2, 3)
        self.sharedPicker = vtk.vtkCellPicker()
        #self.sharedPicker.SetTolerance(0.005)
        self.SetPicker(self.sharedPicker)
        #initialize all three axes slice objects on the bottom of the window
        self.pwX = vtk.vtkImagePlaneWidget()
        self.pwY = vtk.vtkImagePlaneWidget()
        self.pwZ = vtk.vtkImagePlaneWidget()

        self.textActors = {}
        self.boxes = {}

        self.set_image_data(imageData)
        self.Render()

        self.vtk_translation = zeros(3, 'd')
        self.vtk_rotation = zeros(3, 'd')
Exemplo n.º 3
0
    def __init__(self, imageData=None):
        MarkerWindowInteractor.__init__(self)

        print "PlaneWidgetsXYZ.__init__()"

        self.vtksurface = None

        self.interactButtons = (1,2,3)
        self.sharedPicker = vtk.vtkCellPicker()
        #self.sharedPicker.SetTolerance(0.005)
        self.SetPicker(self.sharedPicker)
        
        self.pwX = vtk.vtkImagePlaneWidget()
        self.pwY = vtk.vtkImagePlaneWidget()
        self.pwZ = vtk.vtkImagePlaneWidget()

        
        self.textActors = {}
        self.boxes = {}

        self.set_image_data(imageData)
        self.Render()

        self.vtk_translation = zeros(3, 'd')
        self.vtk_rotation = zeros(3, 'd')
Exemplo n.º 4
0
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event=='color marker':
            marker, color = args
            marker.set_color(color)
        elif event=='label marker':
            marker, label = args
            marker.set_label(label)
            
            if shared.debug: print "Create VTK-Text", marker.get_label()
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)

        elif event=='move marker':
            marker, center = args
            marker.set_center(center)
            #update the select boxes and text actor
            textActor = self.textActors[marker]
            size = marker.get_size()
            textActor.SetScale(size, size, size)
            x,y,z = marker.get_center()
            textActor.SetPosition(x+size, y+size, z+size)

            if self.boxes.has_key(marker):
                selectActor = self.boxes[marker]
                boxSource = vtk.vtkCubeSource()
                boxSource.SetBounds(marker.GetBounds())
                mapper = vtk.vtkPolyDataMapper()
                mapper.SetInput(boxSource.GetOutput())
                selectActor.SetMapper(mapper)
                
        elif event=='labels on':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOn()
        elif event=='labels off':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOff()
        #elif event=='select marker':
        #    marker = args[0]
        #    actor = create_box_actor_around_marker(marker)
        #    if shared.debug: print "PlaneWidgetsXYZ.update_viewer(): self.renderer.AddActor(actor)"
        #    self.renderer.AddActor(actor)
        #    self.boxes[marker] = actor
        #elif event=='unselect marker':
        #    marker = args[0]
        #    actor = self.boxes[marker]
        #    print "pwxyz: u m", repr(marker), repr(actor)
        #    self.renderer.RemoveActor(actor)
        #    del self.boxes[marker]
        elif event=="set axes directions":
            self.add_axes_labels()
            EventHandler().notify('observers update plane')
        
        self.Render()
Exemplo n.º 5
0
    def __init__(self, imageData=None):
        MarkerWindowInteractor.__init__(self)

        if debug:
            print "PlaneWidgetsXYZ.__init__()"

        self.vtksurface = None

        self.interactButtons = (1,2,3)
        self.sharedPicker = vtk.vtkCellPicker()
        #self.sharedPicker.SetTolerance(0.005)
        self.SetPicker(self.sharedPicker)
        
        self.pwX = vtk.vtkImagePlaneWidget()
        self.pwY = vtk.vtkImagePlaneWidget()
        self.pwZ = vtk.vtkImagePlaneWidget()

        
        self.textActors = {}
        self.boxes = {}

        self.set_image_data(imageData)
        self.Render()

        self.vtk_translation = zeros(3, 'd')
        self.vtk_rotation = zeros(3, 'd')
Exemplo n.º 6
0
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event=='add marker':
            marker = args[0]
            self.add_ring_actor(marker)
        elif event=='remove marker':
            marker = args[0]
            self.remove_ring_actor(marker)
        elif event=='move marker':
            # ring actor will update automatically because it shares
            # the sphere source
            marker, pos = args
            textActor = self.textActors[marker]
            textActor.SetPosition(pos)

        elif event=='color marker':
            marker, color = args
            actor = self.get_actor_for_marker(marker)
            actor.update()
        elif event=='label marker':
            marker, label = args
            marker.set_label(label)
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)
        elif event=='observers update plane':
            self.update_plane()
            
        self.update_rings()
        self.Render()
Exemplo n.º 7
0
    def __init__(self, imageData=None):
        MarkerWindowInteractor.__init__(self)
        ThreeDimRenderWindow.__init__(self)

        if shared.debug: print "PlaneWidgetsXYZ.__init__()"

        self.vtksurface = None

        self.interactButtons = (1,2,3)
        self.sharedPicker = vtk.vtkCellPicker()
        #self.sharedPicker.SetTolerance(0.005)
        self.SetPicker(self.sharedPicker)
        
        self.pwX = vtk.vtkImagePlaneWidget()
        self.pwY = vtk.vtkImagePlaneWidget()
        self.pwZ = vtk.vtkImagePlaneWidget()

        
        self.axes_labels = []

        self.set_image_data(imageData)
        self.Render()

        self.vtk_translation = np.zeros(3, 'd')
        self.vtk_rotation = np.zeros(3, 'd')
Exemplo n.º 8
0
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event == 'add marker':
            marker = args[0]
            self.add_ring_actor(marker)
        elif event == 'remove marker':
            marker = args[0]
            self.remove_ring_actor(marker)
        elif event == 'move marker':
            # ring actor will update automatically because it shares
            # the sphere source
            marker, pos = args
            textActor = self.textActors[marker]
            textActor.SetPosition(pos)

        elif event == 'color marker':
            marker, color = args
            actor = self.get_actor_for_marker(marker)
            actor.update()
        elif event == 'label marker':
            marker, label = args
            marker.set_label(label)
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)
        elif event == 'observers update plane':
            self.update_plane()

        self.update_rings()
        self.Render()
Exemplo n.º 9
0
    def OnButtonDown(self, wid, event):
        if not self.hasData: return
        self.lastPnts = self.get_plane_points()

        if event.button == 1:
            self.observer.InteractionOn()

        ret = MarkerWindowInteractor.OnButtonDown(self, wid, event)
        return ret
Exemplo n.º 10
0
    def __init__(self, planeWidget, owner, orientation, imageData=None):
        print "PlaneWidgetObserver.__init__(): orientation=", orientation
        MarkerWindowInteractor.__init__(self)
        self.interactButtons = (1, 2, 3)
        self.pw = planeWidget
        self.owner = owner
        self.orientation = orientation
        self.observer = vtk.vtkImagePlaneWidget()

        self.camera = self.renderer.GetActiveCamera()

        self.ringActors = vtk.vtkActorCollection()
        self.defaultRingLine = 1
        self.textActors = {}
        self.hasData = 0

        self.set_image_data(imageData)
        self.lastTime = 0
        self.set_mouse1_to_move()
Exemplo n.º 11
0
    def __init__(self, planeWidget, owner, orientation, imageData=None):
        print "PlaneWidgetObserver.__init__(): orientation=",orientation
        MarkerWindowInteractor.__init__(self)
        self.interactButtons = (1,2,3)
        self.pw = planeWidget
        self.owner = owner
        self.orientation = orientation
        self.observer = vtk.vtkImagePlaneWidget()

        self.camera = self.renderer.GetActiveCamera()

        self.ringActors = vtk.vtkActorCollection()
        self.defaultRingLine = 1
        self.textActors = {}
        self.hasData = 0

        self.set_image_data(imageData)
        self.lastTime = 0
        self.set_mouse1_to_move()
Exemplo n.º 12
0
 def update_viewer(self, event, *args):
     MarkerWindowInteractor.update_viewer(self, event, *args)
     if event=='add marker':
         marker = args[0]
         self.add_ring_actor(marker)
     elif event=='remove marker':
         marker = args[0]
         self.remove_ring_actor(marker)
     elif event=='move marker':
         # ring actor will update automatically because it shares
         # the sphere source
         marker, pos = args
         textActor = self.textActors[marker.uuid]
         textActor.SetPosition(pos)
     elif event=='color marker':
         marker, color = args
         actor = self.get_actor_for_marker(marker)
         actor.update()
     elif event=='label marker':
         marker, label = args
         self.label_ring_actor(marker, label)
     elif event=='color marker':
         marker, color = args
         actor = self.get_actor_for_marker(marker)
         actor.update()
     elif event=='select marker':
         marker = args[0]
         actor = self.get_actor_for_marker(marker)
         actor.set_selected(True)
     elif event=='unselect marker':
         marker = args[0]
         actor = self.get_actor_for_marker(marker)
         if actor!=None:
             actor.set_selected(False)
     elif event=='observers update plane':
         self.update_plane()
     elif event=="set axes directions":
         self.add_axes_labels()
     self.update_rings()
     self.update_rois()
     self.Render()
Exemplo n.º 13
0
    def OnButtonDown(self, wid, event):
        """Mouse button pressed."""

        print "PlaneWidgetsXYZ.OnButtonDown(): event=", event

        self.lastPntsXYZ = (self.get_plane_points(self.pwX),
                            self.get_plane_points(self.pwY),
                            self.get_plane_points(self.pwZ))
        print "PlaneWidgetsXYZ.OnButtonDown(): self.lastPntsXYZ=", self.lastPntsXYZ

        MarkerWindowInteractor.OnButtonDown(self, wid, event)
        return True
Exemplo n.º 14
0
    def OnButtonUp(self, wid, event):
        if not hasattr(self, 'lastPnts'): return
        #calling this before base class freezes the cursor at last pos
        if not self.hasData: return
        if event.button == 1:
            self.observer.InteractionOff()
        MarkerWindowInteractor.OnButtonUp(self, wid, event)

        pnts = self.get_plane_points()

        if pnts != self.lastPnts:
            UndoRegistry().push_command(self.set_plane_points, self.lastPnts)
        return True
Exemplo n.º 15
0
    def OnButtonUp(self, wid, event):
        """Mouse button released."""

        #print "PlaneWidgetsXYZ.OnButtonUp(): event=", event

        if not hasattr(self, 'lastPntsXYZ'): return
        MarkerWindowInteractor.OnButtonUp(self, wid, event)
        pntsXYZ = (self.get_plane_points(self.pwX),
                   self.get_plane_points(self.pwY),
                   self.get_plane_points(self.pwZ))

        if pntsXYZ != self.lastPntsXYZ:
            UndoRegistry().push_command(self.set_plane_points_xyz,
                                        self.lastPntsXYZ)

        return True
Exemplo n.º 16
0
    def OnKeyPress(self, wid, event=None):

        if (event.keyval == gdk.keyval_from_name("i")
                or event.keyval == gdk.keyval_from_name("I")):

            xyz = self.get_cursor_position_world()
            if xyz is None: return

            marker = Marker(xyz=xyz, rgb=EventHandler().get_default_color())

            EventHandler().add_marker(marker)
            return True

        elif (event.keyval == gdk.keyval_from_name("r")
              or event.keyval == gdk.keyval_from_name("R")):
            self.set_camera(self.resetCamera)
            return True

        return MarkerWindowInteractor.OnKeyPress(self, wid, event)
Exemplo n.º 17
0
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event=='add marker':
            marker = args[0]
            self.add_marker(marker)
        elif event=='remove marker':
            marker = args[0]
            self.remove_marker(marker)
        elif event=='color marker':
            marker, color = args
            marker.set_color(color)
        elif event=='label marker':
            marker, label = args
            marker.set_label(label)
            
            print "Create VTK-Text", marker.get_label()
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)

        elif event=='move marker':
            marker, center = args
            marker.set_center(center)
            #update the select boxes and text actor
            textActor = self.textActors[marker]
            size = marker.get_size()
            textActor.SetScale(size, size, size)
            x,y,z = marker.get_center()
            textActor.SetPosition(x+size, y+size, z+size)

            if self.boxes.has_key(marker):
                selectActor = self.boxes[marker]
                boxSource = vtk.vtkCubeSource()
                boxSource.SetBounds(marker.GetBounds())
                mapper = vtk.vtkPolyDataMapper()
                mapper.SetInput(boxSource.GetOutput())
                selectActor.SetMapper(mapper)
                
                
        elif event=='labels on':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOn()
        elif event=='labels off':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOff()
        elif event=='select marker':
            marker = args[0]
            boxSource = vtk.vtkCubeSource()
            boxSource.SetBounds(marker.GetBounds())
            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInput(boxSource.GetOutput())
            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.GetProperty().SetColor( marker.get_color() )
            actor.GetProperty().SetRepresentationToWireframe()
            actor.GetProperty().SetLineWidth(2.0)
            print "PlaneWidgetsXYZ.update_viewer(): self.renderer.AddActor(actor)"
            self.renderer.AddActor(actor)
            self.boxes[marker] = actor
        elif event=='unselect marker':
            marker = args[0]
            actor = self.boxes[marker]
            self.renderer.RemoveActor(actor)

        
        self.Render()
Exemplo n.º 18
0
    def update_viewer(self, event, *args):
        MarkerWindowInteractor.update_viewer(self, event, *args)
        if event=='add marker':
            marker = args[0]
            self.add_marker(marker)
        elif event=='remove marker':
            marker = args[0]
            self.remove_marker(marker)
        elif event=='color marker':
            marker, color = args
            marker.set_color(color)
        elif event=='label marker':
            marker, label = args
            marker.set_label(label)
            
            if debug:
                print "Create VTK-Text", marker.get_label()
            text = vtk.vtkVectorText()
            text.SetText(marker.get_label())
            textMapper = vtk.vtkPolyDataMapper()
            textMapper.SetInput(text.GetOutput())
            textActor = self.textActors[marker]
            textActor.SetMapper(textMapper)

        elif event=='move marker':
            marker, center = args
            marker.set_center(center)
            #update the select boxes and text actor
            textActor = self.textActors[marker]
            size = marker.get_size()
            textActor.SetScale(size, size, size)
            x,y,z = marker.get_center()
            textActor.SetPosition(x+size, y+size, z+size)

            if self.boxes.has_key(marker):
                selectActor = self.boxes[marker]
                boxSource = vtk.vtkCubeSource()
                boxSource.SetBounds(marker.GetBounds())
                mapper = vtk.vtkPolyDataMapper()
                mapper.SetInput(boxSource.GetOutput())
                selectActor.SetMapper(mapper)
                
                
        elif event=='labels on':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOn()
        elif event=='labels off':
            actors = self.textActors.values()
            for actor in actors:
                actor.VisibilityOff()
        elif event=='select marker':
            marker = args[0]
            boxSource = vtk.vtkCubeSource()
            boxSource.SetBounds(marker.GetBounds())
            mapper = vtk.vtkPolyDataMapper()
            mapper.SetInput(boxSource.GetOutput())
            actor = vtk.vtkActor()
            actor.SetMapper(mapper)
            actor.GetProperty().SetColor( marker.get_color() )
            actor.GetProperty().SetRepresentationToWireframe()
            actor.GetProperty().SetLineWidth(2.0)
            if debug:
                print "PlaneWidgetsXYZ.update_viewer(): self.renderer.AddActor(actor)"
            self.renderer.AddActor(actor)
            self.boxes[marker] = actor
        elif event=='unselect marker':
            marker = args[0]
            actor = self.boxes[marker]
            self.renderer.RemoveActor(actor)

        
        self.Render()