Beispiel #1
0
    def __init__(self, parent, visualizer, **kws):
        """
		Method: __init__(parent)
		Initialization
		"""
        self.x, self.y, self.z = -1, -1, -1
        VisualizationModule.__init__(self, parent, visualizer, **kws)
        self.on = 0
        self.renew = 1
        self.mapper = vtk.vtkPolyDataMapper()
        self.eventDesc = "Rendering Camera Path"

        self.spline = spline = vtk.vtkSplineWidget()
        self.spline.GetLineProperty().SetColor(1, 0, 0)
        self.spline.GetHandleProperty().SetColor(0, 1, 0)
        self.spline.SetResolution(1000)

        #TODO: endInteraction is in GUI.Urmas.SplineEditor
        self.spline.AddObserver("EndInteractionEvent", self.endInteraction)
        self.spline.AddObserver("InteractionEvent", self.endInteraction)

        #TODO: iren is in GUI.Urmas.SplineEditor
        self.spline.SetInteractor(self.iren)
        #self.spline.On()

        #self.spline.SetEnabled(1)
        self.renderer = self.parent.getRenderer()
 def initNewSpline( self, **args ):
     handle_points = args.get( 'handles', None )
     self.spline = vtk.vtkSplineWidget() 
     self.spline.SetProjectionNormalToZAxes() 
     self.spline.SetProjectToPlane(2) 
     if self.iren: self.activateSpline( self.iren ) 
     if handle_points: self.modifyTrajectory( handle_points, takeSnapshot=True )  
    def _addSelector(self, selectorType, numPoints):
        if selectorType == "Spline":
            sw = vtk.vtkSplineWidget()
        else:
            sw = vtkdevide.vtkPolyLineWidget()

        sw.SetCurrentRenderer(self._renderer)
        sw.SetDefaultRenderer(self._renderer)
        sw.SetInput(self._histogram.GetOutput())
        sw.SetInteractor(self._viewFrame.rwi)
        sw.PlaceWidget()
        sw.ProjectToPlaneOn()
        sw.SetProjectionNormalToZAxes()
        sw.SetProjectionPosition(0.00)
        sw.SetPriority(0.6)
        sw.SetNumberOfHandles(numPoints)
        sw.SetClosed(1)
        sw.On()

        swPolyData = vtk.vtkPolyData()
        self._selectors.append({"type": selectorType, "widget": sw, "polyData": swPolyData})
        # add it to the appendPd
        self._appendPD.AddInput(swPolyData)
        nrGridRows = self._grid.GetNumberRows()
        self._grid.AppendRows()
        self._grid.SetCellValue(nrGridRows, self._gridTypeCol, selectorType)
        self._grid.SetCellValue(nrGridRows, self._gridNOHCol, str(sw.GetNumberOfHandles()))

        self._postSelectorChange()

        sw.AddObserver("EndInteractionEvent", self._observerSelectorEndInteraction)

        # make sure this is on
        self._activateOverlayIPW()
	def __init__(self, parent, visualizer, **kws):
		"""
		Method: __init__(parent)
		Initialization
		"""     
		self.x, self.y, self.z = -1, -1, -1
		VisualizationModule.__init__(self, parent, visualizer, **kws)   
		self.on = 0
		self.renew = 1
		self.mapper = vtk.vtkPolyDataMapper()
		self.eventDesc = "Rendering Camera Path"
		

		self.spline = spline = vtk.vtkSplineWidget()
		self.spline.GetLineProperty().SetColor(1, 0, 0)
		self.spline.GetHandleProperty().SetColor(0, 1, 0)
		self.spline.SetResolution(1000)

		#TODO: endInteraction is in GUI.Urmas.SplineEditor
		self.spline.AddObserver("EndInteractionEvent", self.endInteraction)
		self.spline.AddObserver("InteractionEvent", self.endInteraction)

		#TODO: iren is in GUI.Urmas.SplineEditor
		self.spline.SetInteractor(self.iren)
		#self.spline.On()
		
		#self.spline.SetEnabled(1)        
		self.renderer = self.parent.getRenderer()
Beispiel #5
0
 def initNewSpline(self, **args):
     handle_points = args.get('handles', None)
     self.spline = vtk.vtkSplineWidget()
     self.spline.SetProjectionNormalToZAxes()
     self.spline.SetProjectToPlane(2)
     if self.iren: self.activateSpline(self.iren)
     if handle_points:
         self.modifyTrajectory(handle_points, takeSnapshot=True)
Beispiel #6
0
    def _addSelector(self, selectorType, numPoints):
        if selectorType == 'Spline':
            sw = vtk.vtkSplineWidget()
        else:
            sw = vtkdevide.vtkPolyLineWidget()
            
        sw.SetCurrentRenderer(self._renderer)
        sw.SetDefaultRenderer(self._renderer)
        sw.SetInput(self._histogram.GetOutput())
        sw.SetInteractor(self._viewFrame.rwi)
        sw.PlaceWidget()
        sw.ProjectToPlaneOn()
        sw.SetProjectionNormalToZAxes()
        sw.SetProjectionPosition(0.00)
        sw.SetPriority(0.6)
        sw.SetNumberOfHandles(numPoints)
        sw.SetClosed(1)
        sw.On()

        swPolyData = vtk.vtkPolyData()
        self._selectors.append({'type' : selectorType,
                                'widget' : sw,
                                'polyData' : swPolyData})
        # add it to the appendPd
        self._appendPD.AddInput(swPolyData)
        nrGridRows = self._grid.GetNumberRows()
        self._grid.AppendRows()
        self._grid.SetCellValue(nrGridRows, self._gridTypeCol, selectorType)
        self._grid.SetCellValue(nrGridRows, self._gridNOHCol,
                                str(sw.GetNumberOfHandles()))

        self._postSelectorChange()

        sw.AddObserver('EndInteractionEvent',
                       self._observerSelectorEndInteraction)

        # make sure this is on
        self._activateOverlayIPW()
Beispiel #7
0
    def add_spline_widget(self,
                          callback,
                          bounds=None,
                          factor=1.25,
                          n_hanldes=5,
                          resolution=25,
                          color="yellow",
                          show_ribbon=False,
                          ribbon_color="pink",
                          ribbon_opacity=0.5,
                          pass_widget=False):
        """Create and add a spline widget to the scene.

        Use the bounds argument to place this widget. Several "handles" are
        used to control a parametric function for building this spline. Click
        directly on the line to translate the widget.

        Note
        ----
        This widget has trouble displaying certain colors. Use only simple
        colors (white, black, yellow).

        Parameters
        ----------
        callback : callable
            The method called every time the spline is updated. This passes a
            :class:`pyvista.PolyData` object to the callback function of the
            generated spline.

        bounds : tuple(float)
            Length 6 tuple of the bounding box where the widget is placed.

        factor : float, optional
            An inflation factor to expand on the bounds when placing

        n_handles : int
            The number of interactive spheres to control the spline's
            parametric function.

        resolution : int
            The number of points in the spline created between all the handles

        color : string or 3 item list, optional, defaults to white
            Either a string, rgb list, or hex color string.

        show_ribbon : bool
            If ``True``, the poly plane used for slicing will also be shown.

        pass_widget : bool
            If true, the widget will be passed as the last argument of the
            callback

        """
        if hasattr(self, 'notebook') and self.notebook:
            raise AssertionError(
                'Spline widget not available in notebook plotting')
        if not hasattr(self, 'iren'):
            raise AttributeError(
                'Widgets must be used with an intereactive renderer. No off screen plotting.'
            )

        if not hasattr(self, "spline_widgets"):
            self.spline_widgets = []

        if color is None:
            color = rcParams['color']

        if bounds is None:
            bounds = self.bounds

        ribbon = pyvista.PolyData()

        def _the_callback(widget, event_id):
            polyline = pyvista.PolyData()
            widget.GetPolyData(polyline)
            ribbon.shallow_copy(polyline.ribbon(normal=(0, 0, 1), angle=90.0))
            if hasattr(callback, '__call__'):
                if pass_widget:
                    try_callback(callback, polyline, widget)
                else:
                    try_callback(callback, polyline)
            return

        spline_widget = vtk.vtkSplineWidget()
        spline_widget.GetLineProperty().SetColor(parse_color(color))
        spline_widget.SetNumberOfHandles(n_hanldes)
        spline_widget.SetInteractor(self.iren)
        spline_widget.SetCurrentRenderer(self.renderer)
        spline_widget.SetPlaceFactor(factor)
        spline_widget.PlaceWidget(bounds)
        spline_widget.SetResolution(resolution)
        spline_widget.Modified()
        spline_widget.On()
        spline_widget.AddObserver(vtk.vtkCommand.EndInteractionEvent,
                                  _the_callback)
        _the_callback(spline_widget, None)

        if show_ribbon:
            self.add_mesh(ribbon, color=ribbon_color, opacity=ribbon_opacity)

        self.spline_widgets.append(spline_widget)
        return spline_widget
# forced to snap to either nearest pixel points, or pixel centers.  Here
# it is turned off.
#
itw.SnapToImageOff()

#
# Automatically form closed paths.
#
#itw AutoCloseOn
itw.AutoCloseOn()
#

# Set up a vtkSplineWidget in the second renderer and have
# its handles set by the tracer widget.
#
isw = vtk.vtkSplineWidget()
isw.SetCurrentRenderer(ren2)
isw.SetDefaultRenderer(ren2)
isw.SetInputConnection(extract.GetOutputPort())
isw.SetInteractor(iren)
bnds = imageActor2.GetBounds()
isw.PlaceWidget(bnds[0], bnds[1], bnds[2], bnds[3], bnds[4], bnds[5])
isw.ProjectToPlaneOn()
isw.SetProjectionNormalToXAxes()
isw.SetProjectionPosition(pos)
#

# Have the widgets control each others handle positions.
#
itw.AddObserver('EndInteractionEvent',AdjustSpline)
isw.AddObserver('EndInteractionEvent',AdjustTracer)
Beispiel #9
0
# forced to snap to either nearest pixel points, or pixel centers.  Here
# it is turned off.
#
itw.SnapToImageOff()

#
# Automatically form closed paths.
#
#itw AutoCloseOn
itw.AutoCloseOn()
#

# Set up a vtkSplineWidget in the second renderer and have
# its handles set by the tracer widget.
#
isw = vtk.vtkSplineWidget()
isw.SetCurrentRenderer(ren2)
isw.SetDefaultRenderer(ren2)
isw.SetInput(extract.GetOutput())
isw.SetInteractor(iren)
bnds = imageActor2.GetBounds()
isw.PlaceWidget(bnds[0], bnds[1], bnds[2], bnds[3], bnds[4], bnds[5])
isw.ProjectToPlaneOn()
isw.SetProjectionNormalToXAxes()
isw.SetProjectionPosition(pos)
#

# Have the widgets control each others handle positions.
#
itw.AddObserver('EndInteractionEvent',AdjustSpline)
isw.AddObserver('EndInteractionEvent',AdjustTracer)
Beispiel #10
0
    def initializeVTK(self):
        """
		Code to initialize VTK portions of this widget
		"""

        self.renWin = self.wxrenwin.GetRenderWindow()

        ren = self.renderer = self.wxrenwin.getRenderer()

        ren.SetBackground(0, 0, 0)
        self.wxrenwin.Render()

        self.iren = iren = self.renWin.GetInteractor()
        self.iren.SetSize(self.renWin.GetSize())

        self.dataExtensionX = 50
        self.dataExtensionY = 50
        self.dataExtensionZ = 50

        self.data = None
        self.interactionCallback = None

        self.spline = spline = vtk.vtkSplineWidget()
        self.spline.GetLineProperty().SetColor(1, 0, 0)
        self.spline.GetHandleProperty().SetColor(0, 1, 0)
        self.spline.SetResolution(10000)

        self.spline.SetInteractor(self.iren)
        self.style = self.iren.GetInteractorStyle()

        self.spline.AddObserver("EndInteractionEvent", self.endInteraction)
        self.spline.AddObserver("InteractionEvent", self.endInteraction)
        self.style.AddObserver("EndInteractionEvent", self.endInteraction)
        self.style.AddObserver("InteractionEvent", self.endInteraction)
        self.iren.AddObserver("EndInteractionEvent", self.endInteraction)
        self.iren.AddObserver("InteractionEvent", self.endInteraction)

        self.spline.On()

        self.spline.SetEnabled(1)
        self.style.SetEnabled(1)

        self.outline = vtk.vtkOutlineFilter()
        self.outlinemapper = vtk.vtkPolyDataMapper()
        self.outlineactor = vtk.vtkActor()
        self.axes = vtk.vtkCubeAxesActor2D()
        self.initCamera()

        self.arrow = vtk.vtkArrowSource()

        self.arrowTransform = vtk.vtkTransform()
        self.arrowTransform.RotateX(90.0)
        self.arrowTransform.Scale(80.0, 200.0, 200.0)

        self.transformFilter = vtk.vtkTransformFilter()

        self.transformFilter.SetTransform(self.arrowTransform)
        self.transformFilter.SetInput(self.arrow.GetOutput())
        self.arrowMapper = vtk.vtkPolyDataMapper()
        self.arrowMapper.SetInput(self.transformFilter.GetOutput())
        self.arrowActor = vtk.vtkActor()
        self.arrowActor.GetProperty().SetColor((0, 0, 1))
        self.arrowActor.SetMapper(self.arrowMapper)

        self.renderer.AddActor(self.arrowActor)

        self.arrowActor.SetVisibility(0)

        self.wxrenwin.Render()
	def initializeVTK(self):
		"""
		Code to initialize VTK portions of this widget
		"""           
		
		self.renWin = self.wxrenwin.GetRenderWindow()
		
		ren = self.renderer = self.wxrenwin.getRenderer()
		
		ren.SetBackground(0, 0, 0)
		self.wxrenwin.Render()

		self.iren = iren = self.renWin.GetInteractor()
		self.iren.SetSize(self.renWin.GetSize())

		self.dataExtensionX = 50
		self.dataExtensionY = 50
		self.dataExtensionZ = 50

		self.data = None
		self.interactionCallback = None
		
		self.spline = spline = vtk.vtkSplineWidget()
		self.spline.GetLineProperty().SetColor(1, 0, 0)
		self.spline.GetHandleProperty().SetColor(0, 1, 0)
		self.spline.SetResolution(10000)
		
		self.spline.SetInteractor(self.iren)
		self.style = self.iren.GetInteractorStyle()
		
		self.spline.AddObserver("EndInteractionEvent", self.endInteraction)
		self.spline.AddObserver("InteractionEvent", self.endInteraction)
		self.style.AddObserver("EndInteractionEvent", self.endInteraction)
		self.style.AddObserver("InteractionEvent", self.endInteraction)        
		self.iren.AddObserver("EndInteractionEvent", self.endInteraction)
		self.iren.AddObserver("InteractionEvent", self.endInteraction)                

		self.spline.On()
		
		self.spline.SetEnabled(1)        
		self.style.SetEnabled(1)
		
		self.outline = vtk.vtkOutlineFilter ()
		self.outlinemapper = vtk.vtkPolyDataMapper ()
		self.outlineactor = vtk.vtkActor ()
		self.axes = vtk.vtkCubeAxesActor2D ()
		self.initCamera()
				
		self.arrow = vtk.vtkArrowSource()

		self.arrowTransform = vtk.vtkTransform()
		self.arrowTransform.RotateX(90.0)
		self.arrowTransform.Scale(80.0, 200.0, 200.0)

		self.transformFilter = vtk.vtkTransformFilter()
			
		self.transformFilter.SetTransform(self.arrowTransform)
		self.transformFilter.SetInput(self.arrow.GetOutput())
		self.arrowMapper = vtk.vtkPolyDataMapper()
		self.arrowMapper.SetInput(self.transformFilter.GetOutput())
		self.arrowActor = vtk.vtkActor()
		self.arrowActor.GetProperty().SetColor((0, 0, 1))
		self.arrowActor.SetMapper(self.arrowMapper)

		self.renderer.AddActor(self.arrowActor)    
		
		self.arrowActor.SetVisibility(0)
		
		self.wxrenwin.Render()