[vtkusers] seeking for help on volume rendering

Jian Wu eewujian at gmail.com
Wed Aug 23 16:42:04 EDT 2006


Thanks, Alark.

I tried your methods and found a better one as below.

    tfun AddSegment 0 0.0 0.01 0.0
    tfun AddSegment 0.2 1.0 255 1.0

This time, I got a gray sphere. I don't know why there are no colors as
shown on the other one. Anyone knows why?

Jian Wu

On 8/23/06, Alark Joshi <alark_j at hotmail.com> wrote:
>
> The transfer function in your case is set to 1 for all values of density
> in the volume. That is most probably causing the 'dark cube'.
>
> Try something like
>
>     tfun AddSegment 0 0.0 55 0.2
>     tfun AddSegment 55 0.2 255 1.0
>
> or even
>     tfun AddSegment 0 0.0 255 1.0
>
> Hope that helps.
>
> Alark
>
>
>
>
>
> ------------------------------
> Date: Wed, 23 Aug 2006 13:43:19 -0400
> From: eewujian at gmail.com
> To: vtkusers at vtk.org
> Subject: [vtkusers] seeking for help on volume rendering
>
> Hi, everyone,
> I'm a new VTK user. I was failed to produced the similar results for a
> sample code I came upon with in the book "The VTK User's Guide (VTK4.4)".
> Page 122. Here is the code that I used. I made a few modification 'cause it
> is incomplete and has a few obvious errors for the original one. It is
> supposed to display two similar spheres. But I found the one given by
> ray-casting was incorrect. It displayed as a dark cube. Is there anyone know
> the reason? Thanks!
>
> Jian Wu
>
> ######################################################################
> package require vtk
> package require vtkinteraction
>
> # Create the standard renderer, render window
> # and interactor
> vtkRenderer ren1
> vtkRenderWindow renWin
>     renWin AddRenderer ren1
> vtkRenderWindowInteractor iren
>     iren SetRenderWindow renWin
>
> # Create a geometric sphere
> vtkSphereSource sphere
>     sphere SetRadius 20
>     sphere SetCenter 70 25 25
>     sphere SetThetaResolution 50
>     sphere SetPhiResolution 50
>
> vtkPolyDataMapper mapper
>     mapper SetInput [sphere GetOutput]
>
> vtkActor actor
>     actor SetMapper mapper
>     [actor GetProperty] SetColor 1 1 1
>     [actor GetProperty] SetAmbient 0.01
>     [actor GetProperty] SetDiffuse 0.7
>     [actor GetProperty] SetSpecular 0.5
>     [actor GetProperty] SetSpecularPower 70.0
>
> # Read in a volumetric sphere
> vtkSLCReader reader
>     reader SetFileName "$VTK_DATA_ROOT/Data/sphere.slc"
>
> # Use this tfun for both opacity and color
> vtkPiecewiseFunction tfun
>     tfun AddSegment 0 1.0 255 1.0
>
> # Make the volume property match the geometric one
> vtkVolumeProperty volumeProperty
>     volumeProperty SetColor tfun
>     volumeProperty SetScalarOpacity tfun
>     volumeProperty ShadeOn
>     volumeProperty SetInterpolationTypeToLinear
>     volumeProperty SetDiffuse 0.7
>     volumeProperty SetAmbient 0.01
>     volumeProperty SetSpecular 0.5
>     volumeProperty SetSpecularPower 70.0
>
> vtkVolumeRayCastCompositeFunction  compositeFunction
> vtkVolumeRayCastMapper volumeMapper
>     volumeMapper SetInputConnection [reader GetOutputPort]
>     volumeMapper SetVolumeRayCastFunction compositeFunction
>
> vtkVolume volume
>     volume SetMapper volumeMapper
>     volume SetProperty volumeProperty
>
> # Add both the geometric and volumetric spheres to the renderer
> ren1 AddViewProp volume
> ren1 AddViewProp actor
>
> # Create a red, green, and blue light
> vtkLight redlight
>     redlight SetColor 1 0 0
>     redlight SetPosition 1000 25 25
>     redlight SetFocalPoint 25 25 25
>     redlight SetIntensity 0.5
>
> vtkLight greenlight
>     greenlight SetColor 0 1 0
>     greenlight SetPosition 25 1000 25
>     greenlight SetFocalPoint 25 25 25
>     greenlight SetIntensity 0.5
>
> vtkLight bluelight
>     bluelight SetColor 0 0 1
>     bluelight SetPosition 25 25 1000
>     bluelight SetFocalPoint 25 25 25
>     bluelight SetIntensity 0.5
>
> # Add the light to the renderer
> ren1 AddLight redlight
> ren1 AddLight greenlight
> ren1 AddLight bluelight
> ren1 SetBackground 0.1 0.1 0.2
>
> # Render it!
> renWin Render
>
> proc TkCheckAbort {} {
>   set foo [renWin GetEventPending]
>   if {$foo != 0} {renWin SetAbortRender 1}
> }
> renWin AddObserver AbortCheckEvent {TkCheckAbort}
>
> iren AddObserver UserEvent {wm deiconify .vtkInteract}
> iren Initialize
>
> wm withdraw .
>
> ######################################################################
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060823/03b528e3/attachment.htm>


More information about the vtkusers mailing list