1 #include <vtkAutoInit.h>
2 VTK_MODULE_INIT(vtkRenderingOpenGL);
3 VTK_MODULE_INIT(vtkRenderingVolumeOpenGL);
4 VTK_MODULE_INIT(vtkRenderingFreeType);
5 VTK_MODULE_INIT(vtkInteractionStyle);
6
7 #include <vtkSmartPointer.h>
8 #include <vtkStructuredPoints.h>
9 #include <vtkStructuredPointsReader.h>
10 //#include <vtkVolumeTextureMapper2D.h>
11 #include <vtkVolumeTextureMapper3D.h>
12 #include <vtkColorTransferFunction.h>
13 #include <vtkPiecewiseFunction.h>
14 #include <vtkRenderer.h>
15 #include <vtkRenderWindow.h>
16 #include <vtkRenderWindowInteractor.h>
17 #include <vtkVolumeProperty.h>
18 #include <vtkVolumeRayCastIsosurfaceFunction.h>
19
20 int main(int argc, char *argv[])
21 {
22 vtkSmartPointer<vtkStructuredPointsReader> reader =
23 vtkSmartPointer<vtkStructuredPointsReader>::New();
24 reader->SetFileName("mummy.128.vtk");
25 reader->Update();
26
27
28 /*vtkSmartPointer<vtkVolumeTextureMapper2D> volumeMapper =
29 vtkSmartPointer<vtkVolumeTextureMapper2D>::New();
30 volumeMapper->SetInputData(reader->GetOutput());;*/
31
32 vtkSmartPointer<vtkVolumeTextureMapper3D> volumeMapper =
33 vtkSmartPointer<vtkVolumeTextureMapper3D>::New();
34 volumeMapper->SetInputData(reader->GetOutput());;
35 /*************************************************************************/
36 vtkSmartPointer<vtkVolumeProperty> volumeProperty =
37 vtkSmartPointer<vtkVolumeProperty>::New();
38 volumeProperty->SetInterpolationTypeToLinear();
39 volumeProperty->ShadeOn(); //打开或者关闭阴影测试
40 volumeProperty->SetAmbient(0.4);
41 volumeProperty->SetDiffuse(0.6); //漫反射
42 volumeProperty->SetSpecular(0.2); //镜面反射
43 //设置不透明度
44 vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity =
45 vtkSmartPointer<vtkPiecewiseFunction>::New();
46 compositeOpacity->AddPoint(70, 0.00);
47 compositeOpacity->AddPoint(90, 0.40);
48 compositeOpacity->AddPoint(180, 0.60);
49 volumeProperty->SetScalarOpacity(compositeOpacity); //设置不透明度传输函数
50
51 //设置颜色属性
52 vtkSmartPointer<vtkColorTransferFunction> color =
53 vtkSmartPointer<vtkColorTransferFunction>::New();
54 color->AddRGBPoint(0.000, 0.00, 0.00, 0.00);
55 color->AddRGBPoint(64.00, 1.00, 0.52, 0.30);
56 color->AddRGBPoint(190.0, 1.00, 1.00, 1.00);
57 color->AddRGBPoint(220.0, 0.20, 0.20, 0.20);
58 volumeProperty->SetColor(color);
59 /********************************************************************************/
60 vtkSmartPointer<vtkVolume> volume =
61 vtkSmartPointer<vtkVolume>::New();
62 volume->SetMapper(volumeMapper);
63 volume->SetProperty(volumeProperty);
64
65 vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
66 ren->SetBackground(0, 1, 0);
67 ren->AddVolume(volume);
68
69 vtkSmartPointer<vtkRenderWindow> rw = vtkSmartPointer<vtkRenderWindow>::New();
70 rw->AddRenderer(ren);
71 rw->SetSize(480, 480);
72 rw->Render();
73 rw->SetWindowName("VolumeRendering by Texture2D");
74
75 vtkSmartPointer<vtkRenderWindowInteractor> rwi =
76 vtkSmartPointer<vtkRenderWindowInteractor>::New();
77 rwi->SetRenderWindow(rw);
78
79 ren->ResetCamera();
80 rw->Render();
81 rwi->Start();
82
83 return 0;
84 }