一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
 1 #include "vtkAutoInit.h" 
 2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
 3 VTK_MODULE_INIT(vtkInteractionStyle);
 4 
 5 #include <vtkSphereSource.h>
 6 #include <vtkProperty.h>
 7 #include <vtkPolyData.h>
 8 #include <vtkSmartPointer.h>
 9 #include <vtkPolyDataMapper.h>
10 #include <vtkActor.h>
11 #include <vtkRenderWindow.h>
12 #include <vtkRenderer.h>
13 #include <vtkRenderWindowInteractor.h>
14 #include <vtkDijkstraGraphGeodesicPath.h>
15 
16 int main(int , char *[])
17 { 
18     vtkSmartPointer<vtkSphereSource> sphereSource = 
19         vtkSmartPointer<vtkSphereSource>::New();
20     sphereSource->Update();
21 
22     vtkSmartPointer<vtkDijkstraGraphGeodesicPath> dijkstra = 
23         vtkSmartPointer<vtkDijkstraGraphGeodesicPath>::New();
24     dijkstra->SetInputData(sphereSource->GetOutput());
25     dijkstra->SetStartVertex(0);
26     dijkstra->SetEndVertex(10);
27     dijkstra->Update();
28 
29     vtkSmartPointer<vtkPolyDataMapper> pathMapper = 
30         vtkSmartPointer<vtkPolyDataMapper>::New();
31     pathMapper->SetInputData(dijkstra->GetOutput());
32 
33     vtkSmartPointer<vtkActor> pathActor = 
34         vtkSmartPointer<vtkActor>::New();
35     pathActor->SetMapper(pathMapper);
36     pathActor->GetProperty()->SetColor(1,0,0); 
37     pathActor->GetProperty()->SetLineWidth(4);
38 
39     vtkSmartPointer<vtkPolyDataMapper> mapper = 
40         vtkSmartPointer<vtkPolyDataMapper>::New();
41     mapper->SetInputData(sphereSource->GetOutput());
42 
43     vtkSmartPointer<vtkActor> actor = 
44         vtkSmartPointer<vtkActor>::New();
45     actor->SetMapper(mapper);
46 
47     vtkSmartPointer<vtkRenderer> renderer = 
48         vtkSmartPointer<vtkRenderer>::New();
49     renderer->AddActor(actor);
50     renderer->AddActor(pathActor);
51     renderer->SetBackground(1.0, 1.0, 1.0); 
52 
53     vtkSmartPointer<vtkRenderWindow> renderWindow = 
54         vtkSmartPointer<vtkRenderWindow>::New();
55     renderWindow->AddRenderer(renderer);
56     renderWindow->SetSize( 640, 480 );
57     renderWindow->Render();
58     renderWindow->SetWindowName("PolyDataGeodesic");
59 
60     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
61         vtkSmartPointer<vtkRenderWindowInteractor>::New();
62     renderWindowInteractor->SetRenderWindow(renderWindow);
63 
64     renderWindow->Render();
65     renderWindowInteractor->Start();
66 
67     return EXIT_SUCCESS;
68 }

posted on 2023-08-16 08:28  一杯清酒邀明月  阅读(75)  评论(0编辑  收藏  举报