[vtkusers] I have some trouble in display a volume data

zhq 15891495523 at 126.com
Sun Dec 29 07:27:50 EST 2013


      I has display the data by Surface rendering , the result is :
<http://vtk.1045678.n5.nabble.com/file/n5725159/QQ%E6%88%AA%E5%9B%BE20131229202204.png> 
      the code is :

      vtkDICOMImageReader * reader = vtkDICOMImageReader::New();
	reader->SetDirectoryName("G:\\Graduation
Design\\Data\\FAN_YURONG_1627676\\DUAL_VOLUME_SUB_HU_NORMAL_[INSPACE3D]_0034");
	reader->Update();

	vtkSmartPointer<vtkMarchingCubes> marchingCubes =
vtkSmartPointer<vtkMarchingCubes>::New();
	marchingCubes->SetInputConnection( reader->GetOutputPort() );
	marchingCubes->SetValue(0,50);

	vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection( marchingCubes->GetOutputPort() );

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);

	vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
	vtkSmartPointer<vtkRenderer> renderer   =
vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
	vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
	renWin->AddRenderer( renderer );
	renderer->SetBackground(1,1,1);
	interactor->SetRenderWindow( renWin );
	renderer->AddActor( actor );
	renderer->Render();
	interactor->SetInteractorStyle( style );
	interactor->Initialize();
	interactor->Start();


       But Why I can't display the data through volume rendering ?
       My volume rendering code is :
       vtkRenderer * aRenderer = vtkRenderer::New();
	vtkRenderWindow * renWin = vtkRenderWindow::New();
	renWin->AddRenderer(aRenderer);
	vtkRenderWindowInteractor * iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);
       
       vtkDICOMImageReader * reader = vtkDICOMImageReader::New();
	reader->SetDirectoryName("G:\\Graduation
Design\\Data\\FAN_YURONG_1627676\\DUAL_VOLUME_SUB_HU_NORMAL_[INSPACE3D]_0034");
	reader->Update();
       
        vtkImageShiftScale * shiftScale = vtkImageShiftScale::New();
	shiftScale->SetInputConnection( reader->GetOutputPort() );
	shiftScale->SetOutputScalarTypeToUnsignedChar();

	vtkPiecewiseFunction * opcityTransferFunction =
vtkPiecewiseFunction::New();
	opcityTransferFunction->AddPoint(30,0.0);
	opcityTransferFunction->AddPoint(60,1);

	vtkColorTransferFunction * colorTransferFunction =
vtkColorTransferFunction::New();
	colorTransferFunction->AddRGBPoint(0.0,0.0,0.0,0.0);
	colorTransferFunction->AddRGBPoint(64,1,0,0);
	colorTransferFunction->AddRGBPoint(128,0,0,1);
	colorTransferFunction->AddRGBPoint(192,0,1,0);
	colorTransferFunction->AddRGBPoint(255,0,0.2,0);

	vtkVolumeProperty * volumeProperty = vtkVolumeProperty::New();
	volumeProperty->SetColor( colorTransferFunction );
	volumeProperty->SetScalarOpacity( opcityTransferFunction );
	volumeProperty->ShadeOn();
	volumeProperty->SetInterpolationTypeToLinear();

        vtkVolumeRayCastCompositeFunction * compositeFunction =
vtkVolumeRayCastCompositeFunction::New();
//	vtkVolumeRayCastMIPFunction * compositeFunction =
vtkVolumeRayCastMIPFunction::New();
	vtkVolumeRayCastMapper * volumeMapper = vtkVolumeRayCastMapper::New();
	volumeMapper->SetVolumeRayCastFunction(compositeFunction);
	volumeMapper->SetInputConnection( shiftScale->GetOutputPort() );

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

	aRenderer->AddVolume( volume );
	aRenderer->SetBackground(1,1,1);
	renWin->SetSize(600,600);
	renWin->Render();
	iren->Initialize();
	iren->Start();



--
View this message in context: http://vtk.1045678.n5.nabble.com/I-have-some-trouble-in-display-a-volume-data-tp5725158p5725159.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list