[vtkusers] Problem coloring the Iron Protein sample dataset
William R Sherman
wsherman at ncsa.uiuc.edu
Thu Nov 6 01:10:36 EST 2003
Hello VTKers,
I'm fairly new to VTK, but I've been putting myself through a crash course
to learn as much about it as one can in two months. I've run across a
few things that seem a bit quirky, but for the most part I've found ways
to solve all my problems, except one that I've been working on for a week
or so, and just can't figure out.
The problem is that I can't seem to affect the colormap used for
rendering cutting planes or the isosurface of the Iron Protein
example dataset -- even when the exact same code works fine for
two other example datasets (RectGrid2.vtk & office.binary.vtk).
Below is the TCL script that distills what I'm trying to do.
You can change the name of the argument to the "SetFileName"
method to compare the datasets. One hypothesis is that the
problem is a result of the fact that ironProt.vtk is a
StructuredPoints dataset, but there must be a way to color
such data.
I expect it's something pretty simple, but hopefully a few more
pair of eyes looking over my code will spot the problem quickly.
Thanks,
Bill
--
Bill Sherman
VR Impresario & co-author of "Understanding Virtual Reality"
NCSA Virtual Environments Group
wsherman at ncsa.uiuc.edu
-----------------8<------ cut here ------>8-----------------
#! /afs/ncsa/packages/vtk/vtk4.0/vtk4.2/vtk-src-unix/bin/vtk
#
# VTK TCL script to demonstrate problem with coloring Iron Protein data
#
# Three datasets are tested. The RectGrid2 and office.binary datasets are
# both colored correctly, however the ironProt data is colored with a
# simple black and white fully opaque map. This behavior is exhibitted
# with both a cutting plane and an iso-surface generated by vtkContourFilter.
# When the vtkMarchingCubes module is used instead, then the isosurface
# is colored correctly. I'm guessing the problem may be related to the
# fact that ironProt is a structured-points dataset, whereas the other
# two are RectilinearGrid and StructuredGrid.
#
# The cutting plane is centered in the Z-axis, and the isosurface value
# is set to be at the midpoint of the scalar values.
#
package require vtk
package require vtkinteraction
##### Setup standard rendering
vtkRenderer ren1
ren1 SetBackground 0.8 0.8 0.8
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin SetSize 400 300
##### Create and initialize the interactor
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
iren Initialize; # start the interaction
#############################################################
##### Create a simple colormap
vtkLookupTable clut
clut SetHueRange 0.0 0.67
clut SetAlphaRange 0.2 0.9
clut Build
##### Choose a data file to read. ironProt isn't colored correctly, others are
vtkDataSetReader reader
reader SetFileName "../VTKData/Data/ironProt.vtk"
#reader SetFileName "../VTKData/Data/RectGrid2.vtk"
#reader SetFileName "../VTKData/Data/office.binary.vtk"
reader Update
set range [[reader GetOutput] GetScalarRange]
#####
# outline
vtkOutlineFilter outline
outline SetInput [reader GetOutput]
vtkPolyDataMapper outlineMapper
outlineMapper SetInput [outline GetOutput]
vtkActor outlineActor
outlineActor SetMapper outlineMapper
set outlineProp [outlineActor GetProperty]
eval $outlineProp SetColor 0 0 0
ren1 AddActor outlineActor
##### Create an iso-surface (NOTE: Marching cubes colors ironProt correctly)
vtkContourFilter iso
#vtkMarchingCubes iso
iso SetInput [reader GetOutput]
iso SetValue 0 [expr ([lindex $range 1] - [lindex $range 0]) * 0.9 + [lindex $range 0]]
iso ComputeGradientsOn
vtkDataSetMapper isoMapper
isoMapper SetInput [iso GetOutput]
isoMapper ScalarVisibilityOn
eval isoMapper SetScalarRange $range
isoMapper ImmediateModeRenderingOn
isoMapper SetLookupTable clut
vtkActor isoActor
isoActor SetMapper isoMapper
ren1 AddActor isoActor
##### Create a colored slice plane
vtkPlane plane
set bounds [[reader GetOutput] GetBounds]
set zval [expr ([lindex $bounds 5] - [lindex $bounds 4]) * (50.0 / 100.0) + [lindex $bounds 4]]
plane SetOrigin 0 0 $zval
plane SetNormal 0 0 1
vtkCutter slicer
slicer SetInput [reader GetOutput]
slicer SetCutFunction plane
vtkPolyDataMapper sliceMapper
sliceMapper SetInput [slicer GetOutput]
sliceMapper SetLookupTable clut
eval sliceMapper SetScalarRange $range
vtkActor sliceActor
sliceActor SetMapper sliceMapper
ren1 AddActor sliceActor
#############################################################
More information about the vtkusers
mailing list