[vtkusers] Surface color
Gheorghe Postelnicu
gheorghe.postelnicu at gmail.com
Wed Feb 7 15:26:32 EST 2007
Hi Amy,
Thanks for the useful tip! This indeed seemed to solve this particular
problem. However, now I am experiencing a different phenomenon, which
might be related to the first. Namely, in my original pipeline, I
compute the volume of the displayed shape and use it to display
another shape. However, when the input is the result of an implicit
computation (see example below), the resulting volume is negative.
This might suggest that the surface normals are in the wrong
direction.
Thanks again for the quick reply!
Below is the updated toy example and the cmd-line output:
[postelni at asterix vtk ]$ vtk noise2.tcl
volume = 0.4480181937
volume = -0.5030376912
package require vtk
package require vtkinteraction
package require vtktesting
vtkPolyDataMapper mapper
mapper ScalarVisibilityOff
vtkActor actor
actor SetMapper mapper
eval [actor GetProperty] SetColor .5 .5 .5
vtkRenderer ren1
ren1 AddActor actor
vtkRenderWindow renWin
renWin AddRenderer ren1
proc ComputeVolume data {
vtkTriangleFilter filter
filter SetInput $data
filter Update
vtkMassProperties mass
mass SetInput [filter GetOutput]
mass Update
set volume [ expr .3333 * ( [mass GetVolumeX] \
+ [mass GetVolumeY] \
+ [mass GetVolumeZ] ) ]
puts " volume = $volume "
filter Delete
mass Delete
}
proc Show_smooth {} {
vtkSphereSource vtks
vtks Update
mapper SetInput [vtks GetOutput]
ComputeVolume [vtks GetOutput]
vtks Delete
}
proc Show_bumpy {} {
vtkSphere vtks
vtkPerlinNoise pin
vtkImplicitSum sum
sum SetNormalizeByWeight 1
sum AddFunction vtks
sum AddFunction pin .2
vtkSampleFunction sample
sample SetImplicitFunction sum
sample SetSampleDimensions 20 20 20
sample SetModelBounds -2. 2. -2. 2. -2. 2.
sample ComputeNormalsOn
vtkContourFilter surface
surface SetInputConnection [sample GetOutputPort]
surface SetValue 0 0
mapper SetInput [surface GetOutput]
ComputeVolume [surface GetOutput]
eval [actor GetProperty] SetColor .5 .5 .5
renWin Render
surface Delete
sample Delete
sum Delete
pin Delete
vtks Delete
}
Show_smooth
set vtkw [vtkTkRenderWidget .ren \
-width 600 \
-height 600 \
-rw renWin ]
::vtk::bind_tk_render_widget $vtkw
frame .btns
renWin Render
set radioType "smooth"
foreach type {smooth bumpy} {
set gui_${type} [ radiobutton .btns.${type} \
-command "Show_${type}" \
-variable radioType \
-value "$type" \
-text "$type" ]
}
pack $gui_smooth $gui_bumpy \
-side left -fill both -ipady 5 -expand 1
pack .btns $vtkw -side left -fill both -expand yes
wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit
tkwait window .
update
On 2/7/07, Amy Squillacote <amy.squillacote at kitware.com> wrote:
> Hi Gheorghe,
>
> Try calling ScalarVisibilityOff on the mapper. What I think is happening
> is that when you're generating the sphere using the contour filter, the
> dataset you're rendering has scalar data in it, and the mapper is using
> this scalar data to determine the color of the dataset. Since the scalar
> value is the same for every point in the contour, the resulting surface
> is a solid color.
>
> - Amy
>
> Gheorghe Postelnicu wrote:
> > Hi,
> >
> > I am using the implicit modelling tools provided by VTK and I ran
> > across the following issue: consider the following toy example code
> > which builds a sphere using either the SphereSource method or an
> > implicit pipeline.
> >
> > The problem is that whenever I display an implicit sphere, its color
> > is red and I can't seem to figure out how to make it become gray, just
> > like the original surface.
> >
> > Any suggestions would be greatly appreciated.
> >
> > -------------------
> >
> > package require vtk
> > package require vtkinteraction
> > package require vtktesting
> >
> >
> > vtkPolyDataMapper mapper
> >
> > vtkActor actor
> > actor SetMapper mapper
> >
> > eval [actor GetProperty] SetColor .5 .5 .5
> >
> > vtkRenderer ren1
> > ren1 AddActor actor
> >
> > vtkRenderWindow renWin
> > renWin AddRenderer ren1
> >
> > proc Show_smooth {} {
> > vtkSphereSource vtks
> > vtks Update
> > mapper SetInput [vtks GetOutput]
> > vtks Delete
> > }
> >
> > proc Show_bumpy {} {
> > vtkSphere vtks
> > vtkPerlinNoise pin
> >
> > vtkImplicitSum sum
> > sum SetNormalizeByWeight 1
> > sum AddFunction vtks
> > sum AddFunction pin .2
> >
> > vtkSampleFunction sample
> > sample SetImplicitFunction sum
> > sample SetSampleDimensions 20 20 20
> > sample SetModelBounds -2. 2. -2. 2. -2. 2.
> > sample ComputeNormalsOn
> >
> > vtkContourFilter surface
> > surface SetInputConnection [sample GetOutputPort]
> > surface SetValue 0 0
> >
> > mapper SetInput [surface GetOutput]
> > eval [actor GetProperty] SetColor .5 .5 .5
> > renWin Render
> >
> > surface Delete
> > sample Delete
> > sum Delete
> > pin Delete
> > vtks Delete
> > }
> >
> > Show_smooth
> > set vtkw [vtkTkRenderWidget .ren \
> > -width 600 \
> > -height 600 \
> > -rw renWin ]
> >
> > ::vtk::bind_tk_render_widget $vtkw
> >
> > frame .btns
> >
> > renWin Render
> >
> > set radioType "smooth"
> > foreach type {smooth bumpy} {
> > set gui_${type} [ radiobutton .btns.${type} \
> > -command "Show_${type}" \
> > -variable radioType \
> > -value "$type" \
> > -text "$type" ]
> > }
> > pack $gui_smooth $gui_bumpy \
> > -side left -fill both -ipady 5 -expand 1
> >
> > pack .btns $vtkw -side left -fill both -expand yes
> >
> > wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit
> >
> > tkwait window .
> >
> > update
> >
> > -----------------------------
> >
>
--
Gheorghe Postelnicu, PhD
MGH, Harvard Medical School
More information about the vtkusers
mailing list