[vtkusers] volume rendering problem

#ZHAO ZHEEN# kurtzhao at pmail.ntu.edu.sg
Wed Jun 16 09:20:50 EDT 2004


Hi All,

I want to display the volume rendering of a 256X256X62 3D mri image. the code compiles well. but the rendering window is empty, no rendering.  Can someone please help me? I am using vtk4.2. the codes are attached.

Best Regards
Kurt

	vtkRenderer *ren1=vtkRenderer::New();
	

	vtkPiecewiseFunction *oTFun=vtkPiecewiseFunction::New();
		oTFun->AddSegment(80,1.0,255,1.0);
	vtkPiecewiseFunction *gTFun=vtkPiecewiseFunction::New();
		oTFun->AddSegment(0,1.0,255,1.0);

	vtkVolumeProperty *volProperty = vtkVolumeProperty::New();
		volProperty->SetColor(gTFun);
		volProperty->SetScalarOpacity(oTFun);
		volProperty->SetInterpolationTypeToLinear();
		volProperty->ShadeOn();

	vtkVolumeRayCastCompositeFunction *compositeFunction =
		vtkVolumeRayCastCompositeFunction::New();

	vtkImageCast *cast = vtkImageCast::New();
		cast->SetInput(image);
		cast->SetOutputScalarTypeToUnsignedChar();
		cast->Update();


	vtkVolumeRayCastMapper *volMapper = 
		vtkVolumeRayCastMapper::New();
//		volMapper->SetInput(image);
	    volMapper->SetInput(cast->GetOutput());
		volMapper->SetVolumeRayCastFunction(compositeFunction);
  //      volMapper->Print(std::cout);
	vtkVolume *vol=vtkVolume::New();
		vol->SetMapper(volMapper);
		vol->SetProperty(volProperty);
//		vol->Print(std::cout);

	ren1->AddVolume(vol);
	ren1->GetActiveCamera()->Azimuth(20);
	ren1->GetActiveCamera()->Dolly(1.65);
	vtkRenderWindow *renWin = vtkRenderWindow::New();
		renWin->AddRenderer(ren1);

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

	renWin->SetSize(WINDOW_WIDTH,WINDOW_HEIGHT);
	renWin->Render();
	iren->SetDesiredUpdateRate(3.0);
	iren->Start();
//	SAVEIMAGE( renWin );
	// Clean up
  ren1->Delete();
  renWin->Delete();
  iren->Delete();

  oTFun->Delete();
  gTFun->Delete();
  volProperty->Delete();
  compositeFunction->Delete();
  volMapper->Delete();
  vol->Delete();
  cast->Delete();



More information about the vtkusers mailing list