[vtkusers] volume rendering help needed

John Fourkiotis gfourk at zeus.csd.auth.gr
Mon Jul 12 10:09:03 EDT 2004



------- Forwarded message -------
From: "John Fourkiotis" <gfourk at zeus.csd.auth.gr>
To: "jfa at in.gr" <jfa at in.gr>
Subject: [vtkusers] volume rendering help needed
Date: Mon, 12 Jul 2004 17:06:48 +0300

Hi,
i have used the following code to load a set of tooth slices, with
dimensions 250x188x8bit [greyscale]. However, nothing good is shown in the
rendering window (basically, it's black box). I guess the mistake is with
the color and opacity functions. Is my guess correct ?

Thanx

CODE:

#include <vtk/vtkActor.h>
#include <vtk/vtkRenderer.h>
#include <vtk/vtkRenderWindow.h>
#include <vtk/vtkRenderWindowInteractor.h>
#include <vtk/vtkTIFFReader.h>
#include <vtk/vtkVolumeRayCastCompositeFunction.h>
#include <vtk/vtkVolumeRayCastMapper.h>
#include <vtk/vtkVolumeProperty.h>
#include <vtk/vtkVolumeRayCastIsosurfaceFunction.h>
#include <vtk/vtkColorTransferFunction.h>
#include <vtk/vtkPiecewiseFunction.h>

int main()
{
	// create actor, renderer, window & interactor
	vtkRenderer * renderer = vtkRenderer::New();
	vtkRenderWindow * rwin = vtkRenderWindow::New();
	vtkRenderWindowInteractor * interactor = vtkRenderWindowInteractor::New();

	// create TIFF reader:
	vtkTIFFReader * reader = vtkTIFFReader::New();
	reader->SetFileDimensionality(2);
	reader->SetDataSpacing(1,1,1);
	reader->SetDataExtent(0, 249, 0, 187, 100, 299);
	reader->SetNumberOfScalarComponents(1);
	reader->SetFilePrefix("C:\\Gtemp\\tooth\\KynodousA");
	reader->SetFilePattern("%s%i.tif");
	//reader->SetDataScalarTypeToUnsignedChar();
	//reader->SetDataByteOrderToBigEndian();
	reader->Update();

	// create a RayCast function:
	vtkVolumeRayCastCompositeFunction * rayCastFunction =
vtkVolumeRayCastCompositeFunction::New();
	//vtkVolumeRayCastIsosurfaceFunction * rayCastFunction =
vtkVolumeRayCastIsosurfaceFunction::New();

	// create a Volume RayCast Mapper:
	vtkVolumeRayCastMapper * volumeMapper = vtkVolumeRayCastMapper::New();
	volumeMapper->SetInput(reader->GetOutput());
	volumeMapper->SetVolumeRayCastFunction(rayCastFunction);

	// create a Volume Property + color functions:
	vtkColorTransferFunction * color = vtkColorTransferFunction::New();
	color->AddRGBPoint(25.0,0.05,0.05,0.05);
	color->AddRGBPoint(140.0,0.30,0.30,0.30);
	color->AddRGBPoint(208.0,0.56,0.56,0.56);
	color->AddRGBPoint(209.0,0.65,0.65,0.65);
	color->AddRGBPoint(219.0,0.85,0.85,0.85);
	color->AddRGBPoint(229.0,1.00,1.00,1.00);
	
	vtkPiecewiseFunction * opacity = vtkPiecewiseFunction::New();
	opacity->AddPoint(0.0,0.0);
	opacity->AddPoint(24.0,0.0);
	opacity->AddPoint(25.0,0.15);
	opacity->AddPoint(140.0,0.15);
	opacity->AddPoint(141.0,0.0);
	opacity->AddPoint(208.0,0.0);
	opacity->AddPoint(209.0,0.5);
	opacity->AddPoint(229.0,0.95);

	//vtkPiecewiseFunction * gradient = vtkPiecewiseFunction::New();
	//gradient->AddPoint(0.0, 255);
	//gradient->AddPoint(255, 0);


	vtkVolumeProperty * volumeProperty = vtkVolumeProperty::New();
	volumeProperty->SetColor(color);
	volumeProperty->SetScalarOpacity(opacity);
	//volumeProperty->SetGradientOpacity(gradient);
	volumeProperty->ShadeOn();
	volumeProperty->SetInterpolationTypeToLinear();
	//volumeMapper->SetSampleDistance(0.4);

	// create a Volume:
	vtkVolume * volume = vtkVolume::New();
	volume->SetProperty(volumeProperty);
	volume->SetMapper(volumeMapper);
	volume->Update();



	renderer->AddActor(volume);
	renderer->SetBackground(1, 1, 1);
	rwin->AddRenderer(renderer);
	rwin->SetSize(400, 400);
	interactor->SetRenderWindow(rwin);
	rwin->Render();
	interactor->Initialize();
	interactor->Start();

	// delete all object instances...
	reader->Delete();
	renderer->Delete();
	rwin->Delete();
	interactor->Delete();
	rayCastFunction->Delete();
	volumeMapper->Delete();
	return 0;
}



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: result.jpg
Type: image/jpeg
Size: 34838 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040712/077f394a/attachment.jpg>


More information about the vtkusers mailing list