首页 > 其他分享 >VTK 实例55:连通区域分析

VTK 实例55:连通区域分析

时间:2023-08-16 09:03:35浏览次数:38  
标签:55 VTK 区域分析 vtkSmartPointer rightRenderer renderWindow New include leftRenderer

 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()函数调价种子单元,提取种子单元所在的区域。

标签:55,VTK,区域分析,vtkSmartPointer,rightRenderer,renderWindow,New,include,leftRenderer
From: https://www.cnblogs.com/ybqjymy/p/17632967.html

相关文章

  • VTK 实例56:网格抽取(多分辨率处理)
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkPolyData.h>7#include<vtkSphereSource.h>8#include<vtkDe......
  • VTK 实例57:网格细化(多分辨率处理)
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkPolyDataReader.h>8#inc......
  • VTK 实例58:三角剖分(表面重建)
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkProperty.h>8#include<vtkPo......
  • VTK 实例59:加入边界限制的三角剖分(表面重建)
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkProperty.h>8#include&......
  • VTK 实例60:等值面提取(表面重建)
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkMarchingCubes.h>8#include<......
  • VTK 实例61:点云重建(表面重建)
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkPolyDataReader.h>8#inc......
  • VTK 实例62:点云配准
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkPoints.h>7#include<vtkSmartPointer.h>8#include<......
  • VTK 实例63:纹理映射
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkRenderWindowInteractor.h>8#inc......
  • HDU 5500
    ReordertheBooksTimeLimit:4000/2000MS(Java/Others)    MemoryLimit:131072/131072K(Java/Others)TotalSubmission(s):449    AcceptedSubmission(s):294ProblemDescriptionn(n≤19) booksinthisseries.Everybookhasanumberfrom ......
  • P1355 神秘大三角
    Smiling&Weeping----相同的夜让相同的树林泛白。彼时,我们也不再相似如初。题目链接:P1355神秘大三角-洛谷|计算机科学教育新生态(luogu.com.cn)题目:#神秘大三角##题目描述判断一个点与已知三角形的位置关系。##输入格式前三行,......