1 #include <vtkAutoInit.h>
2 VTK_MODULE_INIT(vtkRenderingOpenGL);
3 VTK_MODULE_INIT(vtkInteractionStyle);
4 VTK_MODULE_INIT(vtkRenderingFreeType);
5
6 #include <vtkSmartPointer.h>
7 #include <vtkPolyDataReader.h>
8 #include <vtkCurvatures.h>
9 #include <vtkLookupTable.h>
10 #include <vtkPolyDataMapper.h>
11 #include <vtkActor.h>
12 #include <vtkScalarBarActor.h>
13 #include <vtkPointData.h>
14 #include <vtkRenderer.h>
15 #include <vtkRenderWindow.h>
16 #include <vtkRenderWindowInteractor.h>
17
18 int main()
19 {
20 vtkSmartPointer<vtkPolyDataReader> reader =
21 vtkSmartPointer<vtkPolyDataReader>::New();
22 reader->SetFileName("fran_cut.vtk");
23 reader->Update();
24
25 vtkSmartPointer<vtkCurvatures> curvaturesFilter =
26 vtkSmartPointer<vtkCurvatures>::New();
27 curvaturesFilter->SetInputConnection(reader->GetOutputPort());
28 //curvaturesFilter->SetCurvatureTypeToMinimum(); //最小曲率
29 curvaturesFilter->SetCurvatureTypeToMaximum(); //最大曲率
30 //curvaturesFilter->SetCurvatureTypeToGaussian();//高斯曲率
31 //curvaturesFilter->SetCurvatureTypeToMean(); //平均曲率
32 curvaturesFilter->Update();
33
34 double scalarRange[2];
35 curvaturesFilter->GetOutput()->GetScalarRange(scalarRange);
36 //建立查找表 做颜色映射
37 vtkSmartPointer<vtkLookupTable> lut =
38 vtkSmartPointer<vtkLookupTable>::New();
39 lut->SetHueRange(0.0, 0.6);
40 lut->SetAlphaRange(1.0, 1.0);
41 lut->SetValueRange(1.0, 1.0);
42 lut->SetSaturationRange(1.0, 1.0);
43 lut->SetNumberOfTableValues(256);
44 lut->SetRange(scalarRange);
45 lut->Build();
46 ///
47 vtkSmartPointer<vtkPolyDataMapper> mapper =
48 vtkSmartPointer<vtkPolyDataMapper>::New();
49 mapper->SetInputData(curvaturesFilter->GetOutput());
50 mapper->SetLookupTable(lut);
51 mapper->SetScalarRange(scalarRange);
52
53 vtkSmartPointer<vtkActor> actor =
54 vtkSmartPointer<vtkActor>::New();
55 actor->SetMapper(mapper);
56
57 vtkSmartPointer<vtkScalarBarActor> scalarBar =
58 vtkSmartPointer<vtkScalarBarActor>::New();
59 scalarBar->SetLookupTable(mapper->GetLookupTable());
60 scalarBar->SetTitle(curvaturesFilter->GetOutput()->GetPointData()->GetScalars()->GetName());
61 scalarBar->SetNumberOfLabels(5); //设置5个标签
62
63 vtkSmartPointer<vtkRenderer> render =
64 vtkSmartPointer<vtkRenderer>::New();
65 render->AddActor(actor);
66 render->AddActor2D(scalarBar);
67 render->SetBackground(0, 0, 0);
68
69 vtkSmartPointer<vtkRenderWindow> rw =
70 vtkSmartPointer<vtkRenderWindow>::New();
71 rw->AddRenderer(render);
72 rw->SetSize(640, 480);
73 rw->SetWindowName("Calculating PolyData Curvature");
74
75 vtkSmartPointer<vtkRenderWindowInteractor> rwi =
76 vtkSmartPointer<vtkRenderWindowInteractor>::New();
77 rwi->SetRenderWindow(rw);
78 rwi->Initialize();
79 rwi->Start();
80 return 0;
81 }
1 vtkDoubleArray *gauss = static_cast<vtkDoubleArray*>(
2 curvaturesFilter->GetOutput()->GetpointData()->GetArray("Gauss_Curvature"));
为了能够在模型上显示曲率属性数据,采用颜色映射来显示。定义了一个256色的VTKLookupTable对象,并设置了曲率数据的范围。
然后将改颜色映射表添加到vtkPolyDataMapper中。
最后,我用到了一个新的VTKScalarBarActor类,该类支持一个颜色映射表转换为一个Actor对象,将颜色表以图形的形式显示,并支持设置图形相应的名字和翔实数据Label个数。最后显示即可。