It looks to me like you are setting all values from 0 to 255 to be opaque. This means that you will see a solid cube that is however big your dataset is. You need to make at least the 0's surrounding your spheres transparent so you can see the spheres inside. I believe that would be something like:<br><br>AddSegment 0 0.0 255 1.0<br><br>If you used this for your color it would also give you something besides solid black.<br><br><b><i>Jian Wu <eewujian@gmail.com></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> Hi, everyone,<br>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! <br><br>Jian Wu<br><br>######################################################################<br>package require vtk<br>package require vtkinteraction<br><br># Create the standard renderer, render window<br># and interactor <br>vtkRenderer ren1<br>vtkRenderWindow renWin<br> renWin AddRenderer ren1<br>vtkRenderWindowInteractor iren<br> iren SetRenderWindow renWin<br><br># Create a geometric sphere<br>vtkSphereSource sphere<br> sphere SetRadius 20 <br> sphere SetCenter 70 25 25<br> sphere SetThetaResolution 50<br> sphere SetPhiResolution 50<br><br>vtkPolyDataMapper mapper<br> mapper SetInput [sphere GetOutput]<br><br>vtkActor actor<br> actor SetMapper mapper <br> [actor GetProperty] SetColor 1 1
1<br> [actor GetProperty] SetAmbient 0.01<br> [actor GetProperty] SetDiffuse 0.7<br> [actor GetProperty] SetSpecular 0.5<br> [actor GetProperty] SetSpecularPower 70.0<br> <br># Read in a volumetric sphere<br>vtkSLCReader reader<br> reader SetFileName "$VTK_DATA_ROOT/Data/sphere.slc"<br><br># Use this tfun for both opacity and color<br>vtkPiecewiseFunction tfun<br> tfun AddSegment 0 1.0 255 1.0<br><br># Make the volume property match the geometric one<br>vtkVolumeProperty volumeProperty<br> volumeProperty SetColor tfun<br> volumeProperty SetScalarOpacity tfun<br> volumeProperty ShadeOn<br> volumeProperty SetInterpolationTypeToLinear <br> volumeProperty SetDiffuse 0.7<br> volumeProperty SetAmbient 0.01<br> volumeProperty SetSpecular
0.5<br> volumeProperty SetSpecularPower 70.0<br><br>vtkVolumeRayCastCompositeFunction compositeFunction<br> vtkVolumeRayCastMapper volumeMapper<br> volumeMapper SetInputConnection [reader GetOutputPort]<br> volumeMapper SetVolumeRayCastFunction compositeFunction<br><br>vtkVolume volume<br> volume SetMapper volumeMapper <br> volume SetProperty volumeProperty<br><br># Add both the geometric and volumetric spheres to the renderer<br>ren1 AddViewProp volume<br>ren1 AddViewProp actor<br><br># Create a red, green, and blue light<br>vtkLight redlight <br> redlight SetColor 1 0 0<br> redlight SetPosition 1000 25 25<br> redlight SetFocalPoint 25 25 25<br> redlight SetIntensity 0.5<br><br>vtkLight greenlight<br> greenlight SetColor 0 1 0<br> greenlight SetPosition 25 1000 25
<br> greenlight SetFocalPoint 25 25 25<br> greenlight SetIntensity 0.5<br><br>vtkLight bluelight<br> bluelight SetColor 0 0 1<br> bluelight SetPosition 25 25 1000<br> bluelight SetFocalPoint 25 25 25<br> bluelight SetIntensity 0.5<br><br># Add the light to the renderer<br>ren1 AddLight redlight<br>ren1 AddLight greenlight<br>ren1 AddLight bluelight<br>ren1 SetBackground 0.1 0.1 0.2<br><br># Render it!<br>renWin Render<br><br>proc TkCheckAbort {} { <br> set foo [renWin GetEventPending]<br> if {$foo != 0} {renWin SetAbortRender 1}<br>}<br>renWin AddObserver AbortCheckEvent {TkCheckAbort}<br><br>iren AddObserver UserEvent {wm deiconify .vtkInteract}<br>iren Initialize <br><br>wm withdraw .<br><br>######################################################################<br> _______________________________________________<br>This is the private VTK discussion
list. <br>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br>Follow this link to subscribe/unsubscribe:<br>http://www.vtk.org/mailman/listinfo/vtkusers<br></blockquote><br>