[vtkusers] Picking question
Dominik Szczerba
domi at vision.ee.ethz.ch
Mon Feb 26 10:52:07 EST 2007
You can get the picked cell's ID, so what is the problem querying the data
value?
--ds
On Monday 26 February 2007 15:57, WolfgangZillig wrote:
> Hello,
>
> I'm importing some CT data into vtk and display it as an image. But I
> don't manage to create a picker that gives me the cell values.
>
> So, how do I have to adjust the picker that I get the cell values
> (ideally the original values and not the color value that is displayed)?
>
> Am I using the correct data representation or should I create it as
> regular mesh and import the data there?
>
> How can I querry single values from my imported data (without a picker)
> just when I know the element location (cell 100, 124)?
>
> Thanks for any help!
>
> The imported file can be found here:
> http://perswww.kuleuven.be/~u0049353/vtk/14.RAD
>
> My python script:
>
> import vtk,array
> from struct import unpack
> from vtk.util.colors import *
>
> # file to read
> filein="./14.rad"
> file=open(filein,'rb')
> file.seek(13312) # removing header of file
> valMatrix=file.read(1024*1024*2) # matrix
> valInt=unpack('1048576h',valMatrix)
> valArr=array.array('I',valInt)
> # print min(valArr), max(valArr)
>
> w=1024; h=1024
> extent = (0, w - 1, 0, h - 1, 0, 0)
>
> # importing the rad-file values to a vtk object
> importer = vtk.vtkImageImport()
> importer.SetDataScalarTypeToInt()
> importer.SetWholeExtent(extent)
> importer.SetDataExtent(extent)
> importer.SetImportVoidPointer(valArr)
> importer.SetDataSpacing(1,1,0)
> importer.Update()
>
> # flipping the image
> flipX = vtk.vtkImageFlip()
> flipX.SetInput(importer.GetOutput())
> flipX.SetFilteredAxes(1)
>
> # Start by creatin a black/white lookup table.
> cLut = vtk.vtkLookupTable()
> cLut.SetTableRange(min(valArr), max(valArr))
> cLut.SetSaturationRange(0, 1)
> cLut.SetHueRange(0, 1)
> cLut.SetValueRange(0, 1)
> # cLut.SetRampToLinear()
> # cLut.SetRampToSCurve()
> # cLut.SetRampToSQRT()
> # cLut.SetScaleToLog10()
> # dont forget to build the table
> cLut.Build()
>
> # transfering the image values to colors
> iSS = vtk.vtkImageMapToColors()
> iSS.SetInputConnection(flipX.GetOutputPort())
> iSS.SetLookupTable(cLut)
>
> # Create a cell picker.
> picker = vtk.vtkCellPicker()
>
> # the text rendering
> textMapper = vtk.vtkTextMapper()
> tprop = textMapper.GetTextProperty()
> tprop.SetFontFamilyToArial()
> tprop.SetFontSize(10)
> tprop.BoldOn()
> tprop.ShadowOn()
> tprop.SetColor(1, 1, 0)
> textActor = vtk.vtkActor2D()
> textActor.VisibilityOff()
> textActor.SetMapper(textMapper)
>
> # Create a Python function to create the text for the text mapper used
> to display the results of picking.
> def annLM(object,event):
> pos=iren.GetEventPosition() # x,y in windowcoords
> realpos=picker.Pick((pos[0],pos[1],0),ren)
> selPt = picker.GetSelectionPoint()
> picPos=picker.GetPickPosition()
> textMapper.SetInput("(%.2f, %.2f)"%(picPos[0],picPos[1]))
> textActor.SetPosition(selPt[:2])
> textActor.VisibilityOn()
> renWin.Render()
>
>
> # image actor
> iActor=vtk.vtkImageActor()
> iActor.SetInput(iSS.GetOutput())
>
> # renderer
> ren = vtk.vtkRenderer()
> ren.AddActor2D(textActor)
> ren.AddActor(iActor)
> ren.ResetCamera()
> ren.GetActiveCamera().Zoom(1.45)
>
> # render Window
> renWin = vtk.vtkRenderWindow()
> renWin.AddRenderer(ren)
> renWin.SetSize(800,800)
>
> # defining an interactorstyle
> interactor = vtk.vtkInteractorStyleImage() # works this only with
> vtkImageActor()???
> interactor.AddObserver('LeftButtonPressEvent',annLM)
>
> # the window interactor
> iren = vtk.vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
> iren.SetInteractorStyle(interactor)
> iren.SetPicker(picker)
> iren.Initialize()
> iren.Start()
>
>
>
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
--
Dominik Szczerba, Ph.D.
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi
More information about the vtkusers
mailing list