Beispiel #1
0
    def _add_marker(self, world_pos, colour, size=0.01):
        """
        @param size: fraction of visible prop bounds diagonal.
        """

        #self._add_sphere(world_pos, MAJOR_MARKER_SIZE, (1,1,0))
        pw = vtk.vtkPointWidget()
        # we're giving it a small bounding box
        pw.TranslationModeOn()
        b = self._viewer.GetRenderer().ComputeVisiblePropBounds()
        # calculate diagonal
        dx,dy = b[1] - b[0], b[3] - b[2]
        diag = math.hypot(dx,dy)
        d = size * diag
        w = world_pos
        pwb = w[0] - d, w[0] + d, \
                w[1] - d, w[1] + d, \
                b[4], b[5]

        pw.PlaceWidget(pwb)
        pw.SetPosition(world_pos)
        pw.SetInteractor(self._view_frame.rwi)
        pw.AllOff()

        pw.GetProperty().SetColor(colour)

        pw.On()

        return pw
Beispiel #2
0
 def Point(self):
         print 'Point'
         self.cut_point = vtk.vtkPointWidget()
         self.cut_point.SetInput(surface.GetOutput())
         self.cut_point.AllOff()
         self.cut_point.PlaceWidget()
         # nastavení interaktoru
         self.cut_point.SetInteractor(self.iren)
         self.cut_point.On()
         point = vtk.vtkPolyData()
         self.cut_point.GetPolyData(point);
Beispiel #3
0
 def Point(self):
     print('Point')
     self.cut_point = vtk.vtkPointWidget()
     self.cut_point.SetInput(surface.GetOutput())
     self.cut_point.AllOff()
     self.cut_point.PlaceWidget()
     # nastavení interaktoru
     self.cut_point.SetInteractor(self.iren)
     self.cut_point.On()
     point = vtk.vtkPolyData()
     self.cut_point.GetPolyData(point)
# per the probed value and orient it as per the vector.

import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Start by loading some data.
pl3d = vtk.vtkPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()

# The plane widget is used probe the dataset.
pointWidget = vtk.vtkPointWidget()
pointWidget.SetInput(pl3d.GetOutput())
pointWidget.AllOff()
pointWidget.PlaceWidget()
point = vtk.vtkPolyData()
pointWidget.GetPolyData(point)

probe = vtk.vtkProbeFilter()
probe.SetInput(point)
probe.SetSource(pl3d.GetOutput())

# create glyph
cone = vtk.vtkConeSource()
cone.SetResolution(16)
glyph = vtk.vtkGlyph3D()
glyph.SetInputConnection(probe.GetOutputPort())
Beispiel #5
0
import vtk
from vtk.util.misc import vtkGetDataRoot

VTK_DATA_ROOT = vtkGetDataRoot()

# Start by loading some data.
pl3d = vtk.vtkPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()

# The plane widget is used probe the dataset.
pointWidget = vtk.vtkPointWidget()
pointWidget.SetInput(pl3d.GetOutput())
pointWidget.AllOff()
pointWidget.PlaceWidget()
point = vtk.vtkPolyData()
pointWidget.GetPolyData(point)

probe = vtk.vtkProbeFilter()
probe.SetInput(point)
probe.SetSource(pl3d.GetOutput())

# create glyph
cone = vtk.vtkConeSource()
cone.SetResolution(16)
glyph = vtk.vtkGlyph3D()
glyph.SetInputConnection(probe.GetOutputPort())
Beispiel #6
0
    cutMapper.SetInput(cutTube.GetOutput())
    cutActor.SetMapper(cutMapper)

    cutActor.GetProperty().SetDiffuseColor(lamp_black)
    cutActor.GetProperty().SetSpecular(0.4)
    cutActor.GetProperty().SetSpecularPower(10)

    aRenderer.AddActor(cutActor)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(aRenderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()

pw = vtk.vtkPointWidget()
pw.PlaceWidget(-planeSize * 2, planeSize * 2, -planeSize * 2, planeSize * 2,
               -planeSize * 2, planeSize * 2)
pw.SetPosition(planeSize, planeSize, 0)
pw.SetInteractor(iren)
pw.AllOff()
pw.On()


def observerPW(widget, eventName):
    sphereActor.SetPosition(widget.GetPosition())
    for planeSource, cutter in zip(planeSources, cutters):
        planeSource.SetCenter(widget.GetPosition())
        cutter.GetCutFunction().SetNormal(planeSource.GetNormal())
        cutter.GetCutFunction().SetOrigin(planeSource.GetOrigin())
Beispiel #7
0
    def _storePoint(self, discrete, world, value, pointName,
                    lockToSurface=False, boundsForPoints=None):

        tdren = self.slice3dVWR._threedRenderer
        tdrwi = self.slice3dVWR.threedFrame.threedRWI

        if not boundsForPoints:
            bounds = tdren.ComputeVisiblePropBounds()
        else:
            bounds = boundsForPoints

        if bounds[1] - bounds[0] <= 0 or \
           bounds[3] - bounds[2] <= 0 or \
           bounds[5] - bounds[4] <= 0:
            bounds = (-1,1,-1,1,-1,1)
        

        # we use a pointwidget
        pw = vtk.vtkPointWidget()
        #pw.SetInput(inputData)
        pw.PlaceWidget(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4],
                       bounds[5])
        pw.SetPosition(world)
        # make priority higher than the default of vtk3DWidget so
        # that imageplanes behind us don't get selected the whole time
        pw.SetPriority(0.6)
        pw.SetInteractor(tdrwi)
        pw.AllOff()
        pw.On()

        #ss.SetRadius((bounds[1] - bounds[0]) / 100.0)
        
        ca = vtk.vtkCaptionActor2D()
        ca.GetProperty().SetColor(1,1,0)
        tp = ca.GetCaptionTextProperty()
        tp.SetColor(1,1,0)
        tp.ShadowOff()
        ca.SetPickable(0)
        ca.SetAttachmentPoint(world)
        ca.SetPosition(25,10)
        ca.BorderOff()
        ca.SetWidth(0.3)
        ca.SetHeight(0.04)
        # I used to have the problem on my ATI X1600 that interaction
        # was extremely slow of 3D was on... problem seems to have
        # gone away by itself, or it rather has to do with the slow-
        # glcontext-things
        ca.ThreeDimensionalLeaderOn()
        ca.SetMaximumLeaderGlyphSize(10)
        ca.SetLeaderGlyphSize(0.025)

        coneSource = vtk.vtkConeSource()
        coneSource.SetResolution(6)
        # we want the cone's very tip to by at 0,0,0
        coneSource.SetCenter(- coneSource.GetHeight() / 2.0, 0, 0)

        ca.SetLeaderGlyph(coneSource.GetOutput())

        if len(pointName) > 0:
            ca.SetCaption(pointName)
        else:
            ca.SetCaption(".")
            # since VTK 20070628, caption actor doesn't like an empty label

        tdren.AddActor(ca)


        def pw_ei_cb(pw, evt_name):
            # make sure our output is good
            self._syncOutputSelectedPoints()

        pw.AddObserver('StartInteractionEvent', lambda pw, evt_name,
                       s=self:
                       s._observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('InteractionEvent', lambda pw, evt_name,
                       s=self:
                       s._observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('EndInteractionEvent', pw_ei_cb)

        # we start with it disabled
        pw.Off()

        # store the cursor (discrete coords) the coords and the actor
        self._pointsList.append({'discrete' : tuple(discrete),
                                 'world' : tuple(world),
                                 'value' : value,
                                 'name' : pointName,
                                 'pointWidget' : pw,
                                 'lockToSurface' : lockToSurface,
                                 'sphereActor' : ca})

        self._grid.AppendRows()
        #self._grid.AdjustScrollBars()
        row = self._grid.GetNumberRows() - 1
        self._syncGridRowToSelPoints(row)
        
        # make sure self._outputSelectedPoints is up to date
        self._syncOutputSelectedPoints()

        self.slice3dVWR.render3D()
Beispiel #8
0
    def _storePoint(self,
                    discrete,
                    world,
                    value,
                    pointName,
                    lockToSurface=False,
                    boundsForPoints=None):

        tdren = self.slice3dVWR._threedRenderer
        tdrwi = self.slice3dVWR.threedFrame.threedRWI

        if not boundsForPoints:
            bounds = tdren.ComputeVisiblePropBounds()
        else:
            bounds = boundsForPoints

        if bounds[1] - bounds[0] <= 0 or \
           bounds[3] - bounds[2] <= 0 or \
           bounds[5] - bounds[4] <= 0:
            bounds = (-1, 1, -1, 1, -1, 1)

        # we use a pointwidget
        pw = vtk.vtkPointWidget()
        #pw.SetInput(inputData)
        pw.PlaceWidget(bounds[0], bounds[1], bounds[2], bounds[3], bounds[4],
                       bounds[5])
        pw.SetPosition(world)
        # make priority higher than the default of vtk3DWidget so
        # that imageplanes behind us don't get selected the whole time
        pw.SetPriority(0.6)
        pw.SetInteractor(tdrwi)
        pw.AllOff()
        pw.On()

        #ss.SetRadius((bounds[1] - bounds[0]) / 100.0)

        ca = vtk.vtkCaptionActor2D()
        ca.GetProperty().SetColor(1, 1, 0)
        tp = ca.GetCaptionTextProperty()
        tp.SetColor(1, 1, 0)
        tp.ShadowOff()
        ca.SetPickable(0)
        ca.SetAttachmentPoint(world)
        ca.SetPosition(25, 10)
        ca.BorderOff()
        ca.SetWidth(0.3)
        ca.SetHeight(0.04)
        # I used to have the problem on my ATI X1600 that interaction
        # was extremely slow of 3D was on... problem seems to have
        # gone away by itself, or it rather has to do with the slow-
        # glcontext-things
        ca.ThreeDimensionalLeaderOn()
        ca.SetMaximumLeaderGlyphSize(10)
        ca.SetLeaderGlyphSize(0.025)

        coneSource = vtk.vtkConeSource()
        coneSource.SetResolution(6)
        # we want the cone's very tip to by at 0,0,0
        coneSource.SetCenter(-coneSource.GetHeight() / 2.0, 0, 0)

        ca.SetLeaderGlyph(coneSource.GetOutput())

        if len(pointName) > 0:
            ca.SetCaption(pointName)
        else:
            ca.SetCaption(".")
            # since VTK 20070628, caption actor doesn't like an empty label

        tdren.AddActor(ca)

        def pw_ei_cb(pw, evt_name):
            # make sure our output is good
            self._syncOutputSelectedPoints()

        pw.AddObserver('StartInteractionEvent',
                       lambda pw, evt_name, s=self: s.
                       _observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('InteractionEvent',
                       lambda pw, evt_name, s=self: s.
                       _observerPointWidgetInteraction(pw, evt_name))
        pw.AddObserver('EndInteractionEvent', pw_ei_cb)

        # we start with it disabled
        pw.Off()

        # store the cursor (discrete coords) the coords and the actor
        self._pointsList.append({
            'discrete': tuple(discrete),
            'world': tuple(world),
            'value': value,
            'name': pointName,
            'pointWidget': pw,
            'lockToSurface': lockToSurface,
            'sphereActor': ca
        })

        self._grid.AppendRows()
        #self._grid.AdjustScrollBars()
        row = self._grid.GetNumberRows() - 1
        self._syncGridRowToSelPoints(row)

        # make sure self._outputSelectedPoints is up to date
        self._syncOutputSelectedPoints()

        self.slice3dVWR.render3D()