一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

 1 #include <vtkAutoInit.h>
 2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
 3 VTK_MODULE_INIT(vtkRenderingFreeType);
 4 VTK_MODULE_INIT(vtkInteractionStyle);
 5 
 6 #include <vtkSmartPointer.h>
 7 #include <vtkSphereSource.h>
 8 #include <vtkConeSource.h>
 9 #include <vtkPolyDataConnectivityFilter.h>
10 #include <vtkPolyDataMapper.h>
11 #include <vtkActor.h>
12 #include <vtkProperty.h>
13 #include <vtkRenderer.h>
14 #include <vtkRenderWindow.h>
15 #include <vtkRenderWindowInteractor.h>
16 #include <vtkAppendPolyData.h>
17 
18 int main(int, char *[])
19 {
20     vtkSmartPointer<vtkSphereSource> sphereSource = 
21         vtkSmartPointer<vtkSphereSource>::New();
22     sphereSource->SetRadius(10);
23     sphereSource->SetThetaResolution(10);
24     sphereSource->SetPhiResolution(10);
25     sphereSource->Update();
26 
27     vtkSmartPointer<vtkConeSource> coneSource = 
28         vtkSmartPointer<vtkConeSource>::New();
29     coneSource->SetRadius(5);
30     coneSource->SetHeight(10);
31     coneSource->SetCenter(25,0,0);
32     coneSource->Update();
33 
34     vtkSmartPointer<vtkAppendPolyData> appendFilter = 
35         vtkSmartPointer<vtkAppendPolyData>::New();
36     appendFilter->AddInputData(sphereSource->GetOutput());
37     appendFilter->AddInputData(coneSource->GetOutput());
38     appendFilter->Update();
39 
40     vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter = 
41         vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
42     connectivityFilter->SetInputData(appendFilter->GetOutput());
43     connectivityFilter->SetExtractionModeToCellSeededRegions();
44     connectivityFilter->AddSeed(100);
45     connectivityFilter->Update();
46 
47     vtkSmartPointer<vtkPolyDataMapper> originalMapper = 
48         vtkSmartPointer<vtkPolyDataMapper>::New();
49     originalMapper->SetInputConnection(appendFilter->GetOutputPort());
50     originalMapper->Update();
51 
52     vtkSmartPointer<vtkActor> originalActor = 
53         vtkSmartPointer<vtkActor>::New();
54     originalActor->SetMapper(originalMapper);
55 
56     vtkSmartPointer<vtkPolyDataMapper> extractedMapper = 
57         vtkSmartPointer<vtkPolyDataMapper>::New();
58     extractedMapper->SetInputConnection(connectivityFilter->GetOutputPort());
59     extractedMapper->Update();
60 
61     vtkSmartPointer<vtkActor> extractedActor = 
62         vtkSmartPointer<vtkActor>::New();
63     extractedActor->SetMapper(extractedMapper);
64 
65     double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
66     double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
67 
68     vtkSmartPointer<vtkRenderer> leftRenderer =
69         vtkSmartPointer<vtkRenderer>::New();
70     leftRenderer->SetViewport(leftViewport);
71     leftRenderer->AddActor(originalActor);
72     leftRenderer->SetBackground(0.8, 0.8, 0.8);
73 
74     vtkSmartPointer<vtkRenderer> rightRenderer =
75         vtkSmartPointer<vtkRenderer>::New();
76     rightRenderer->SetViewport(rightViewport);
77     rightRenderer->AddActor(extractedActor);
78     rightRenderer->SetBackground(1.0, 1.0, 1.0);
79 
80     vtkSmartPointer<vtkRenderWindow> renderWindow = 
81         vtkSmartPointer<vtkRenderWindow>::New();
82     renderWindow->AddRenderer(leftRenderer);
83     renderWindow->AddRenderer(rightRenderer);
84     renderWindow->SetSize(640, 320);
85     renderWindow->Render();
86     renderWindow->SetWindowName("PolyDataConnectedCompExtract");
87 
88     leftRenderer->ResetCamera();
89     rightRenderer->SetActiveCamera(leftRenderer->GetActiveCamera());
90 
91     vtkSmartPointer<vtkRenderWindowInteractor> interactor = 
92         vtkSmartPointer<vtkRenderWindowInteractor>::New();
93     interactor->SetRenderWindow(renderWindow);
94     interactor->Initialize();
95     interactor->Start();
96 
97     return EXIT_SUCCESS;
98 }

SetExtractionModeToLargestRegion():用于提取具有最多点数的连通区域;
SetExtractionModeToAllRegions():该模式主要用于连通区域标记,配合函数ColorRegionsOn()使用,在连通区域像是的同时,生成一个名为RegionId的点属性数据。
SetExtractionModeToSpecifiedRegions():该模式用于提取一个或多个连通区域,在该模式下,需要通过AddSpecifiedRegion()来添加西药提取的区域号,区域号从零开始。
SetExtractionModeToClosestPointRegion():该模式需要使用SetClosestPoint()函数设置一个空间点坐标,执行结果为离该点最近的连通区域。
SetExtractionModeToPointSeededRegions():该模式下需要使用AddSeed()函数添加种子点,提取种子点所在的区域。
SetExtractionModeToCellSeededRegions():该模式下需要使用AddSeed()函数调价种子单元,提取种子单元所在的区域。

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