[vtkusers] Having problems with light and shading

Prename Surname bsd.diverse at gmail.com
Wed Oct 18 02:03:57 EDT 2006


Hello everybody
I have started using VTK not to long ago to visualize my MR-images of the
brain.
I seems to be a great toolkit, but i do have some difficulties getting a
really nice visualization. So i am not sure whether it is just me that has
misunderstood something, or if it in fact is not possible to get a better
rendering.
My visualization of labelimage of graymatter in a brain (voxels only have
value 0 or 255) is seen here
http://coachkontakt.dk/brain.PNG
As can be seen the surface looks very homogeneus. The reason for the black
spots is because i put the opacity to 0.1 making the voxels almost
transparant, so that it is possible to see that the graymatter is not
massive(of course), since the brain also consists of other things.

But my problem is the surface look. There is absolutely no variation in the
surface and it looks very 2D like. Its not very pretty, and does not look
like a brain.
I have tried to set different lighting settings, both ambient, specular and
diffuse. I have tried to enable shading, but i cannot really seem to get any
different results. So i was hoping that someone had some suggestions as of
how i can get this binary labeled volume of the brain to look more nice.

The code that produces the image i have so far is listed below:

#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolume.h"

// Raytracer
#include "vtkVolumeRayCastCompositeFunction.h"
#include "vtkVolumeRayCastMapper.h"

#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"

int main(int argc, char *argv[]){
//reading the image and preparing etc.
.
.
.
 //Create transfer mapping scalar value to color
 vtkPiecewiseFunction *opacityTransferfunction=vtkPiecewiseFunction::New();
 vtkColorTransferFunction
*colorTransferFunction=vtkColorTransferFunction::New();
 //////////////////////////////////////////////////////////////////////////////////
 //Set transferfunctions for gm-mask-image
 opacityTransferfunction->SetClamping(0);//Implicit setting of transparent
background = 255
 opacityTransferfunction->AddPoint(0,.1);
 colorTransferFunction->AddRGBPoint(0,1.,0.,0.);

 //////////////////////////////////////////////////////////////////////////////////
 vtkVolumeProperty *volumeProperty=vtkVolumeProperty::New();
 volumeProperty->SetColor(colorTransferFunction);
 volumeProperty->SetScalarOpacity(opacityTransferfunction);
 volumeProperty->SetAmbient(.4);
 volumeProperty->SetSpecular(.5);
 volumeProperty->SetDiffuse(0.6);
 volumeProperty->SetInterpolationTypeToLinear();

 //Raytracing
 vtkVolumeRayCastCompositeFunction *compositeFunction =
vtkVolumeRayCastCompositeFunction::New();
 vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
 volumeMapper->SetVolumeRayCastFunction(compositeFunction);
 volumeMapper->SetInput(connector->GetOutput());


 vtkVolume *volume=vtkVolume::New();
 volume->SetMapper(volumeMapper);
 volume->SetProperty(volumeProperty);

 // A renderer and render window
 vtkRenderer *ren1 = vtkRenderer::New();
 vtkRenderWindow *renWin = vtkRenderWindow::New();
 ren1->AutomaticLightCreationOn();

 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
 iren->LightFollowCameraOn();
 iren->SetRenderWindow(renWin);

 ren1->AddViewProp(volume);

 renWin->AddRenderer(ren1);

 //Render an image(lights and camera are created automatically)
 renWin->Render();

 //Begin mouse interaction
 iren->Start();

}



I hope to hear from you soon. Another issue is that the volume renders quite
slow even though my computer and graphic card is of a fairly good quality.

Am i doing something wrong, or missing something that has an impact on
performance?



Thank you very much in advance. Hope to hear from you soon.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061018/219cf1fe/attachment.htm>


More information about the vtkusers mailing list