[vtkusers] how to set QVTKRenderWindowInteractor as vtkSplineWidget interactor

igorznt igorznt at gmail.com
Wed Dec 9 20:08:52 EST 2009


Maybe a code(this code is in vtk python examples n is called
ImageTracerWidget.py, i have just changed the interactor):

import vtk
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vtk.util.misc import vtkGetDataRoot
from PyQt4 import QtGui
import sys

def AdjustSpline(evt, obj):
    itw.GetPath(poly)
    npts = itw.GetNumberOfHandles()

    if npts < 2:
        imageActor2.SetInput(extract.GetOutput())
        return

    closed = itw.IsClosed()

    if closed:
        isw.ClosedOn()
    else:
        isw.ClosedOff()
        imageActor2.SetInput(extract.GetOutput())

    isw.SetNumberOfHandles(npts)

    for i in range(0, npts):
        pt = poly.GetPoints().GetPoint(i)
        isw.SetHandlePosition(i, pt[0], pt[1], pt[2])

    if closed:
        isw.GetPolyData(spoly)
        imageActor2.SetInputConnection(stencil.GetOutputPort())
        stencil.Update()

def AdjustTracer(evt, obj):
    npts = isw.GetNumberOfHandles()
    points.SetNumberOfPoints(npts)

    for i in range(0, npts):
        pt = isw.GetHandlePosition(i)
        points.SetPoint(i, pt[0], pt[1], pt[2])

    closed = isw.GetClosed()

    if closed:
        isw.GetPolyData(spoly)
        imageActor2.SetInputConnection(stencil.GetOutputPort())
        stencil.Update()

    itw.InitializeHandles(points)

v16 = vtk.vtkVolume16Reader()
v16.SetDataDimensions(64, 64)
v16.SetDataByteOrderToLittleEndian()
v16.SetImageRange(1, 93)
v16.SetDataSpacing(3.2, 3.2, 1.5)
v16.SetFilePrefix("/home/igorznt/Desenvolvimento/Neppo/preview3D/vtk/VTKData/Data/headsq/quarter")
v16.Update()

srange = v16.GetOutput().GetScalarRange()
min = srange[0]
max = srange[1]

diff = max-min
slope = 255.0/diff
inter = -slope*min
shift = inter/slope

shifter = vtk.vtkImageShiftScale()
shifter.SetShift(shift)
shifter.SetScale(slope)
shifter.SetOutputScalarTypeToUnsignedChar()
shifter.SetInputConnection(v16.GetOutputPort())
shifter.ReleaseDataFlagOff()
shifter.Update()

imageActor = vtk.vtkImageActor()
imageActor.SetInput(shifter.GetOutput())
imageActor.VisibilityOn()
imageActor.SetDisplayExtent(31, 31, 0, 63, 0, 92)
imageActor.InterpolateOff()
#

spc = shifter.GetOutput().GetSpacing()
orig = shifter.GetOutput().GetOrigin()
x0 = orig[0]
xspc = spc[0]
pos = x0+xspc*31.0

ren = vtk.vtkRenderer()
ren.SetBackground(0.4, 0.4, 0.5)
ren2 = vtk.vtkRenderer()
ren2.SetBackground(0.5, 0.4, 0.4)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.AddRenderer(ren2)
renWin.SetSize(600, 300)

ren.SetViewport(0, 0, 0.5, 1)
ren2.SetViewport(0.5, 0, 1, 1)
#

interactor = vtk.vtkInteractorStyleImage()
#
app = QtGui.QApplication(sys.argv)
iren = QVTKRenderWindowInteractor()
iren.SetInteractorStyle(interactor)
iren.SetRenderWindow(renWin)
#

extract = vtk.vtkExtractVOI()
extract.SetVOI(31, 31, 0, 63, 0, 92)
extract.SetSampleRate(1, 1, 1)
extract.SetInputConnection(shifter.GetOutputPort())
extract.ReleaseDataFlagOff()

imageActor2 = vtk.vtkImageActor()
imageActor2.SetInput(extract.GetOutput())
imageActor2.VisibilityOn()
imageActor2.SetDisplayExtent(31, 31, 0, 63, 0, 92)
imageActor2.InterpolateOff()

itw = vtk.vtkImageTracerWidget()
itw.SetCaptureRadius(1.5)
itw.GetGlyphSource().SetColor(1, 0, 0)
itw.GetGlyphSource().SetScale(3.0)
itw.GetGlyphSource().SetRotationAngle(45.0)
itw.GetGlyphSource().Modified()
itw.ProjectToPlaneOn()
itw.SetProjectionNormalToXAxes()
itw.SetProjectionPosition(pos)
itw.SetViewProp(imageActor)
itw.SetInput(shifter.GetOutput())
itw.SetInteractor(iren)
itw.PlaceWidget()
itw.SnapToImageOff()
itw.AutoCloseOn()

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)

itw.AddObserver('EndInteractionEvent',AdjustSpline)
isw.AddObserver('EndInteractionEvent',AdjustTracer)

itw.On()
isw.On()

poly = vtk.vtkPolyData()
points = vtk.vtkPoints()
spoly = vtk.vtkPolyData()

extrude = vtk.vtkLinearExtrusionFilter()
extrude.SetInput(spoly)
extrude.SetScaleFactor(1)
extrude.SetExtrusionTypeToNormalExtrusion()
extrude.SetVector(1, 0, 0)

dataToStencil = vtk.vtkPolyDataToImageStencil()
dataToStencil.SetInputConnection(extrude.GetOutputPort())

stencil = vtk.vtkImageStencil()
stencil.SetInputConnection(extract.GetOutputPort())
stencil.SetStencil(dataToStencil.GetOutput())
stencil.ReverseStencilOff()
stencil.SetBackgroundValue(128)

ren.AddViewProp(imageActor)
ren2.AddViewProp(imageActor2)
renWin.Render()

ren.GetActiveCamera().SetViewUp(0, 1, 0)
ren.GetActiveCamera().Azimuth(270)
ren.GetActiveCamera().Roll(270)
ren.GetActiveCamera().Dolly(1.7)
ren.ResetCameraClippingRange()

ren2.GetActiveCamera().SetViewUp(0, 1, 0)
ren2.GetActiveCamera().Azimuth(270)
ren2.GetActiveCamera().Roll(270)
ren2.GetActiveCamera().Dolly(1.7)
ren2.ResetCameraClippingRange()

vtk.vtkMapper.SetResolveCoincidentTopologyToPolygonOffset()
vtk.vtkMapper.SetResolveCoincidentTopologyPolygonOffsetParameters(10,10)

renWin.Render()

iren.Initialize()
renWin.Render()
iren.Start()

please. anyone knows why that happens?



igorznt wrote:
> 
> When i set the interactor as a QVTKRenderWindowInteractor, the system
> crashes and show no message. Does anybody know why and how to fix it?
> 

-- 
View this message in context: http://old.nabble.com/how-to-set-QVTKRenderWindowInteractor-as-vtkSplineWidget-interactor-tp26697933p26720612.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list