예제 #1
0
    def __init__(self, renderer, interactor):

        self.connect = ConnectFilter()
        self.deci = DecimateFilter()
        self.marchingCubes = vtk.vtkMarchingCubes()

        self.prog = ProgressBarDialog(
            title='Rendering surface %s' % self.label,
            parent=None,
            msg='Marching cubes ....',
            size=(300,40),
                                 )
        def start(o, event):
            self.prog.show()
            while gtk.events_pending(): gtk.main_iteration()


        def progress(o, event):
            val = o.GetProgress()
            self.prog.bar.set_fraction(val)            
            while gtk.events_pending(): gtk.main_iteration()
            
        def end(o, event):
            self.prog.hide()
            while gtk.events_pending(): gtk.main_iteration()

        self.marchingCubes.AddObserver('StartEvent', start)
        self.marchingCubes.AddObserver('ProgressEvent', progress)
        self.marchingCubes.AddObserver('EndEvent', end)
        self.renderer = renderer
        self.interactor = interactor
        self.isoActor = None
        
        self.update_pipeline()
예제 #2
0
    def __init__(self, renderer, interactor):

        self.connect = ConnectFilter()
        self.deci = DecimateFilter()
        self.marchingCubes = vtk.vtkMarchingCubes()

        self.prog = ProgressBarDialog(
            title='Rendering surface %s' % self.label,
            parent=None,
            msg='Marching cubes ....',
            size=(300,40),
                                 )
        def start(o, event):
            self.prog.show()
            while gtk.events_pending(): gtk.main_iteration()


        def progress(o, event):
            val = o.GetProgress()
            self.prog.bar.set_fraction(val)            
            while gtk.events_pending(): gtk.main_iteration()
            
        def end(o, event):
            self.prog.hide()
            while gtk.events_pending(): gtk.main_iteration()

        self.marchingCubes.AddObserver('StartEvent', start)
        self.marchingCubes.AddObserver('ProgressEvent', progress)
        self.marchingCubes.AddObserver('EndEvent', end)
        self.renderer = renderer
        self.interactor = interactor
        self.isoActor = None
        
        self.update_pipeline()
예제 #3
0
    def __init__(self, imageData, intensity, color=None):
        self._uuid = uuid.uuid1()
        if intensity!=None:
            self.intensity = intensity
        if color==None:
            color=self.color_
        self.set_color(color)

        self.connect = ConnectFilter()
        self.deci = DecimateFilter()
        self.marchingCubes = vtk.vtkMarchingCubes()
        self.marchingCubes.SetInput(imageData)

        self.output = vtk.vtkPassThrough()

        self.prog = ProgressBarDialog(
            title='Rendering surface %s' % self.label,
            parent=None,
            msg='Marching cubes ....',
            size=(300,40),
        )
        self.prog.set_modal(True)

        def start(o, event):
            self.prog.show()
            while gtk.events_pending(): gtk.main_iteration()


        def progress(o, event):
            val = o.GetProgress()
            self.prog.bar.set_fraction(val)            
            while gtk.events_pending(): gtk.main_iteration()
            
        def end(o, event):
            self.prog.hide()
            while gtk.events_pending(): gtk.main_iteration()

        self.marchingCubes.AddObserver('StartEvent', start)
        self.marchingCubes.AddObserver('ProgressEvent', progress)
        self.marchingCubes.AddObserver('EndEvent', end)
        
        self.update_pipeline()

        self.notify_add_surface(self.output)
예제 #4
0
class SurfParams(Viewer):
    """
    CLASS: SurfParams
    DESCR:

      Public attrs:
    
      color       # a normed rgb
      intensity   # intensity to segment on
      label       # name of segment
      useConnect  # boolean, whether to use ConnectFilter
      useDecimate # boolean, whether to use DecimateFilter
      connect     # a ConnectFilter or None
      deci        # a DecimateFilter or None
      imageData   # default None
    """

    label, color  = colorSeq[0]
    intensity     = 3000

    useConnect    = True
    useDecimate   = False

    def __init__(self, renderer, interactor):

        self.connect = ConnectFilter()
        self.deci = DecimateFilter()
        self.marchingCubes = vtk.vtkMarchingCubes()

        self.prog = ProgressBarDialog(
            title='Rendering surface %s' % self.label,
            parent=None,
            msg='Marching cubes ....',
            size=(300,40),
                                 )
        def start(o, event):
            self.prog.show()
            while gtk.events_pending(): gtk.main_iteration()


        def progress(o, event):
            val = o.GetProgress()
            self.prog.bar.set_fraction(val)            
            while gtk.events_pending(): gtk.main_iteration()
            
        def end(o, event):
            self.prog.hide()
            while gtk.events_pending(): gtk.main_iteration()

        self.marchingCubes.AddObserver('StartEvent', start)
        self.marchingCubes.AddObserver('ProgressEvent', progress)
        self.marchingCubes.AddObserver('EndEvent', end)
        self.renderer = renderer
        self.interactor = interactor
        self.isoActor = None
        
        self.update_pipeline()

    def update_pipeline(self):

        if self.isoActor is not None:
            self.renderer.RemoveActor(self.isoActor)

        
        
        pipe = self.marchingCubes


        if self.useConnect:
            self.connect.SetInput( pipe.GetOutput())
            pipe = self.connect

        if self.useDecimate:
            self.deci.SetInput( pipe.GetOutput())
            pipe = self.deci

        if 0:
            plane = vtk.vtkPlane()
            clipper = vtk.vtkClipPolyData()
            polyData = pipe.GetOutput()

            clipper.SetInput(polyData)
            clipper.SetClipFunction(plane)
            clipper.InsideOutOff()
            pipe = clipper

            def callback(pw, event):
                pw.GetPlane(plane)
                self.interactor.Render()
            self.planeWidget = vtk.vtkImplicitPlaneWidget()
            self.planeWidget.SetInteractor(self.interactor)
            self.planeWidget.On()
            self.planeWidget.SetPlaceFactor(1.0)
            self.planeWidget.SetInput(polyData)
            self.planeWidget.PlaceWidget()
            self.planeWidget.AddObserver("InteractionEvent", callback)
        
        
        self.isoMapper = vtk.vtkPolyDataMapper()
        self.isoMapper.SetInput(pipe.GetOutput())
        self.isoMapper.ScalarVisibilityOff()

        self.isoActor = vtk.vtkActor()
        self.isoActor.SetMapper(self.isoMapper)
        self.renderer.AddActor(self.isoActor)
        self.update_properties()

    def set_image_data(self, imageData):
        if debug:
            print "SurfParams.set_image_data(", imageData,")"
        self.marchingCubes.SetInput(imageData)
        x1,x2,y1,y2,z1,z2 = imageData.GetExtent()
        sx, sy, sz = imageData.GetSpacing()
        if 0:
            self.planeWidget.PlaceWidget((x1*sx, x2*sx, y1*sy, y2*sy, z1*sz, z2*sz))

    def update_properties(self):
        self.marchingCubes.SetValue(0, self.intensity)
        self.isoActor.GetProperty().SetColor(self.color)

        if self.useConnect:  self.connect.update()
        if self.useDecimate: self.deci.update()

    def update_viewer(self, event, *args):
        if event=='set image data':
            imageData = args[0]
            self.set_image_data(imageData)       


    def __del__(self):
        if self.isoActor is not None:
            self.renderer.RemoveActor(self.isoActor)
예제 #5
0
class SurfParams(object):
    label = "Surface"
    colorName, color_  = colorSeq[0]
    intensity     = 80.
    _opacity = 1.0

    useConnect    = True
    useDecimate   = False

    def __init__(self, imageData, intensity, color=None):
        self._uuid = uuid.uuid1()
        if intensity!=None:
            self.intensity = intensity
        if color==None:
            color=self.color_
        self.set_color(color)

        self.connect = ConnectFilter()
        self.deci = DecimateFilter()
        self.marchingCubes = vtk.vtkMarchingCubes()
        self.marchingCubes.SetInput(imageData)

        self.output = vtk.vtkPassThrough()

        self.prog = ProgressBarDialog(
            title='Rendering surface %s' % self.label,
            parent=None,
            msg='Marching cubes ....',
            size=(300,40),
        )
        self.prog.set_modal(True)

        def start(o, event):
            self.prog.show()
            while gtk.events_pending(): gtk.main_iteration()


        def progress(o, event):
            val = o.GetProgress()
            self.prog.bar.set_fraction(val)            
            while gtk.events_pending(): gtk.main_iteration()
            
        def end(o, event):
            self.prog.hide()
            while gtk.events_pending(): gtk.main_iteration()

        self.marchingCubes.AddObserver('StartEvent', start)
        self.marchingCubes.AddObserver('ProgressEvent', progress)
        self.marchingCubes.AddObserver('EndEvent', end)
        
        self.update_pipeline()

        self.notify_add_surface(self.output)


    def update_pipeline(self):
        pipe = self.marchingCubes

        if self.useConnect:
            self.connect.SetInputConnection( pipe.GetOutputPort())
            pipe = self.connect

        if self.useDecimate:
            self.deci.SetInputConnection( pipe.GetOutputPort())
            pipe = self.deci

        self.output.SetInputConnection( pipe.GetOutputPort() )
        self.update_properties()

    def notify_add_surface(self, pipe):
        EventHandler().notify("add surface", self._uuid, pipe, self._color)

    def notify_remove_surface(self):
        EventHandler().notify("remove surface", self._uuid)

    def notify_color_surface(self, color):
        EventHandler().notify("color surface", self._uuid, color)

    def notify_change_surface_opacity(self, opacity):
        EventHandler().notify("change surface opacity", self._uuid, opacity)

    def update_properties(self):
        self.marchingCubes.SetValue(0, self.intensity)
        self.notify_color_surface(self.color)

        if self.useConnect:  self.connect.update()
        if self.useDecimate: self.deci.update()

    def update_viewer(self, event, *args):
        if event=='set image data':
            imageData = args[0]
            self.set_image_data(imageData)       

    def __del__(self):
        self.notify_remove_surface()

    def set_color(self,color, color_name=""):
        #print color, type(color)
        self.colorName = color_name
        if type(color)==gtk.gdk.Color:
            self._color = gdkColor2tuple(color)
        else:
            self._color = color
        self.notify_color_surface(self._color)

    def get_color(self):
        return self._color

    def set_opacity(self,opacity):
        self._opacity = opacity
        self.notify_change_surface_opacity(self._opacity)

    def get_opacity(self):
        return self._opacity

    def get_uuid(self):
        return self._uuid

    color = property(get_color,set_color)
    opacity = property(get_opacity,set_opacity)
    uuid = property(get_uuid)

    def destroy(self):
        self.notify_remove_surface()
예제 #6
0
class SurfParams(Viewer):
    """
    CLASS: SurfParams
    DESCR:

      Public attrs:
    
      color       # a normed rgb
      intensity   # intensity to segment on
      label       # name of segment
      useConnect  # boolean, whether to use ConnectFilter
      useDecimate # boolean, whether to use DecimateFilter
      connect     # a ConnectFilter or None
      deci        # a DecimateFilter or None
      imageData   # default None
    """

    label, color = colorSeq[0]
    intensity = 3000

    useConnect = True
    useDecimate = False

    def __init__(self, renderer, interactor):

        self.connect = ConnectFilter()
        self.deci = DecimateFilter()
        self.marchingCubes = vtk.vtkMarchingCubes()

        self.prog = ProgressBarDialog(
            title='Rendering surface %s' % self.label,
            parent=None,
            msg='Marching cubes ....',
            size=(300, 40),
        )

        def start(o, event):
            self.prog.show()
            while gtk.events_pending():
                gtk.main_iteration()

        def progress(o, event):
            val = o.GetProgress()
            self.prog.bar.set_fraction(val)
            while gtk.events_pending():
                gtk.main_iteration()

        def end(o, event):
            self.prog.hide()
            while gtk.events_pending():
                gtk.main_iteration()

        self.marchingCubes.AddObserver('StartEvent', start)
        self.marchingCubes.AddObserver('ProgressEvent', progress)
        self.marchingCubes.AddObserver('EndEvent', end)
        self.renderer = renderer
        self.interactor = interactor
        self.isoActor = None

        self.update_pipeline()

    def update_pipeline(self):

        if self.isoActor is not None:
            self.renderer.RemoveActor(self.isoActor)

        pipe = self.marchingCubes

        if self.useConnect:
            self.connect.SetInput(pipe.GetOutput())
            pipe = self.connect

        if self.useDecimate:
            self.deci.SetInput(pipe.GetOutput())
            pipe = self.deci

        if 0:
            plane = vtk.vtkPlane()
            clipper = vtk.vtkClipPolyData()
            polyData = pipe.GetOutput()

            clipper.SetInput(polyData)
            clipper.SetClipFunction(plane)
            clipper.InsideOutOff()
            pipe = clipper

            def callback(pw, event):
                pw.GetPlane(plane)
                self.interactor.Render()

            self.planeWidget = vtk.vtkImplicitPlaneWidget()
            self.planeWidget.SetInteractor(self.interactor)
            self.planeWidget.On()
            self.planeWidget.SetPlaceFactor(1.0)
            self.planeWidget.SetInput(polyData)
            self.planeWidget.PlaceWidget()
            self.planeWidget.AddObserver("InteractionEvent", callback)

        self.isoMapper = vtk.vtkPolyDataMapper()
        self.isoMapper.SetInput(pipe.GetOutput())
        self.isoMapper.ScalarVisibilityOff()

        self.isoActor = vtk.vtkActor()
        self.isoActor.SetMapper(self.isoMapper)
        self.renderer.AddActor(self.isoActor)
        self.update_properties()

    def set_image_data(self, imageData):
        print "SurfParams.set_image_data(", imageData, ")"
        self.marchingCubes.SetInput(imageData)
        x1, x2, y1, y2, z1, z2 = imageData.GetExtent()
        sx, sy, sz = imageData.GetSpacing()
        if 0:
            self.planeWidget.PlaceWidget(
                (x1 * sx, x2 * sx, y1 * sy, y2 * sy, z1 * sz, z2 * sz))

    def update_properties(self):
        self.marchingCubes.SetValue(0, self.intensity)
        self.isoActor.GetProperty().SetColor(self.color)

        if self.useConnect: self.connect.update()
        if self.useDecimate: self.deci.update()

    def update_viewer(self, event, *args):
        if event == 'set image data':
            imageData = args[0]
            self.set_image_data(imageData)

    def __del__(self):
        if self.isoActor is not None:
            self.renderer.RemoveActor(self.isoActor)