[vtkusers] isosurface of labeled blobs: all contours just red

lynx.abraxas at freenet.de lynx.abraxas at freenet.de
Sat Aug 8 04:57:48 EDT 2009


Hello!


I'm new to VTK. I want to generate a surface of labeld blobs (3D-TIF from ITK)
that I'd like to import into blender but I'm stuck in VTK:
I used http://www.evl.uic.edu/aspale/cs526/final/3-5-2-0.htm as  a  start  and
modified                   it                   according                   to
http://public.kitware.com/pipermail/vtkusers/2004-November/077288.html.    But
Tracy's problem is now also my problem: How do I get the surfaces of my labels
colored differently?
>From the docs I'd understand that GenerateValues(10,1,11) should  generate  10
sufaces of my first 10 labels but I always see all 955 labels in red.
When only dots are shown during rotation I can see some different colors.
If I use GenerateValues(10 ,1,955) I can see multiple colored layers in the blobs that
are cut through by the border.

So how do I get my blobs colored differently with just one layer?
What is GenerateValues() doing exactly?

Many thanks for any hints or help
Lynx


import Tkinter

import vtk

from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor

 

# Prepare to read the file

readerVolume = vtk.vtkImageReader()
#readerVolume = vtk.vtkTIFFReader()
readerVolume.SetDataScalarType( vtk.VTK_UNSIGNED_SHORT )
readerVolume.SetFileDimensionality( 3 )
readerVolume.SetDataExtent ( 0,517, 0,228, 0,392)
readerVolume.SetDataSpacing( 1,1,1 )
readerVolume.SetNumberOfScalarComponents( 1 )
readerVolume.SetDataByteOrderToBigEndian()
#readerVolume.SetFileName( "./Female.raw" )
readerVolume.SetFileName( "../stack_ws01.raw" )

 

# Extract the region of interest

voiHead = vtk.vtkExtractVOI()

voiHead.SetInput( readerVolume.GetOutput() )

#voiHead.SetVOI( 0,255, 60,255, 0,100 )
voiHead.SetVOI(0,517, 0,228, 0,392)
#voiHead.SetSampleRate(1,1,1)
voiHead.SetSampleRate(3,3,3)
voiHead.Update()#necessary for GetScalarRange()
srange= voiHead.GetOutput().GetScalarRange()#needs Update() before!
print "Range", srange

# Generate an isosurface

# UNCOMMENT THE FOLLOWING LINE FOR CONTOUR FILTER

#contourBoneHead = vtk.vtkContourFilter()
contourBoneHead = vtk.vtkMarchingCubes()

contourBoneHead.SetInput( voiHead.GetOutput() )

contourBoneHead.ComputeNormalsOn()
#contourBoneHead.GenerateValues(10,1,11)
#contourBoneHead.GenerateValues(955,1,955)
contourBoneHead.GenerateValues(10 ,1,955)
#contourBoneHead.SetValue( 0, 100. )  #second value has no effect!?!
print "# Values:", contourBoneHead.GetNumberOfContours()
contourBoneHead.Update() #needed for GetNumberOfPolys() !!!
print "Creating ", contourBoneHead.GetOutput().GetNumberOfPolys(), " polygons."

# define lookuptable 
lut = vtk.vtkLookupTable()
lut.SetHueRange (0.0,0.667)
lut.SetNumberOfColors (256)
lut.Build()
for i in range(0, 53):
    lut.SetTableValue(i, (i+1)/255.0, (i+2)/255.0, (i+3)/255.0, 1.0) 

# Take the isosurface data and create geometry

geoBoneMapper = vtk.vtkPolyDataMapper()

geoBoneMapper.SetInput( contourBoneHead.GetOutput() )

#geoBoneMapper.ScalarVisibilityOff()#show no colour 
geoBoneMapper.ScalarVisibilityOn()#show colour 
geoBoneMapper.SetScalarRange(srange)
#geoBoneMapper.SetLookupTable(lut)
 

# Take the isosurface data and create geometry

actorBone = vtk.vtkLODActor()

actorBone.SetNumberOfCloudPoints( 100000 )
actorBone.SetMapper( geoBoneMapper )
#actorBone.GetProperty().SetColor( 1, 1, 1 ) #for ScalarVisibilityOff()

 

# Create renderer

ren = vtk.vtkRenderer()
ren.SetBackground( 0.329412, 0.34902, 0.427451 ) #Paraview blue
ren.AddActor(actorBone)

 

# Create a window for the renderer of size 250x250

renWin = vtk.vtkRenderWindow()

renWin.AddRenderer(ren)
renWin.SetSize(250, 250)

 

# Set an user interface interactor for the render window

iren = vtk.vtkRenderWindowInteractor()

iren.SetRenderWindow(renWin)

 

# Start the initialization and rendering

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

#   vtkPolyDataWriter *volwriter1 = vtkPolyDataWriter::New();
#    volwriter1->SetInput( iso->GetOutput() );
#   volwriter1->SetFileName("braintstem6740.vtk");
#   volwriter1->Write();
 






More information about the vtkusers mailing list