首页 > 其他分享 >VTK 实例56:网格抽取(多分辨率处理)

VTK 实例56:网格抽取(多分辨率处理)

时间:2023-08-16 09:03:00浏览次数:36  
标签:1.0 VTK 56 网格 vtkSmartPointer 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 <vtkPolyData.h>
 7 #include <vtkSphereSource.h>
 8 #include <vtkDecimatePro.h>
 9 #include <vtkQuadricDecimation.h>
10 #include <vtkQuadricClustering.h>
11 #include <vtkSmartPointer.h>
12 #include <vtkPolyDataMapper.h>
13 #include <vtkProperty.h>
14 #include <vtkRenderWindow.h>
15 #include <vtkRenderWindowInteractor.h>
16 #include <vtkRenderer.h>
17 #include <vtkPolydataReader.h>
18 #include <vtkCamera.h>
19 
20 //测试文件:../data/fran_cut.vtk
21 int main(int argc, char * argv[])
22 {
23     vtkSmartPointer<vtkPolyDataReader> reader = 
24         vtkSmartPointer<vtkPolyDataReader>::New();
25     reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\fran_cut.vtk");
26     reader->Update();
27     vtkSmartPointer<vtkPolyData> original  =  reader->GetOutput();
28 
29     std::cout << "抽取前:" << std::endl << "------------" << std::endl;
30     std::cout << "模型点数为: " << original->GetNumberOfPoints() << std::endl;
31     std::cout << "模型面数为: " << original->GetNumberOfPolys() << std::endl;
32 
33     vtkSmartPointer<vtkDecimatePro> decimate =
34         vtkSmartPointer<vtkDecimatePro>::New();
35     decimate->SetInputData(original);
36     decimate->SetTargetReduction(.80); //80%的三角面片被移除
37     decimate->Update();
38 
39     vtkSmartPointer<vtkPolyData> decimated = decimate->GetOutput();
40     std::cout << "抽取后" << std::endl << "------------" << std::endl;
41     std::cout << "模型点数为:" << decimated->GetNumberOfPoints()<< std::endl;
42     std::cout << "模型面数为:" << decimated->GetNumberOfPolys()<< std::endl;
43 
44     vtkSmartPointer<vtkPolyDataMapper> origianlMapper =
45         vtkSmartPointer<vtkPolyDataMapper>::New();
46     origianlMapper->SetInputData(original);
47 
48     vtkSmartPointer<vtkActor> origianlActor =
49         vtkSmartPointer<vtkActor>::New();
50     origianlActor->SetMapper(origianlMapper);
51 
52     vtkSmartPointer<vtkPolyDataMapper> decimatedMapper =
53         vtkSmartPointer<vtkPolyDataMapper>::New();
54     decimatedMapper->SetInputData(decimated);
55 
56     vtkSmartPointer<vtkActor> decimatedActor =
57         vtkSmartPointer<vtkActor>::New();
58     decimatedActor->SetMapper(decimatedMapper);
59 
60     double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
61     double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
62 
63     vtkSmartPointer<vtkRenderer> leftRenderer =
64         vtkSmartPointer<vtkRenderer>::New();
65     leftRenderer->SetViewport(leftViewport);
66     leftRenderer->AddActor(origianlActor);
67     leftRenderer->SetBackground(1.0, 1.0, 1.0);
68 
69     vtkSmartPointer<vtkRenderer> rightRenderer =
70         vtkSmartPointer<vtkRenderer>::New();
71     rightRenderer->SetViewport(rightViewport);
72     rightRenderer->AddActor(decimatedActor);
73     rightRenderer->SetBackground(1.0, 1.0, 1.0);
74 
75     leftRenderer->GetActiveCamera()->SetPosition(0, -1, 0);
76     leftRenderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
77     leftRenderer->GetActiveCamera()->SetViewUp(0, 0, 1);
78     leftRenderer->GetActiveCamera()->Azimuth(30);
79     leftRenderer->GetActiveCamera()->Elevation(30);
80     leftRenderer->ResetCamera();
81     rightRenderer->SetActiveCamera(leftRenderer->GetActiveCamera());
82 
83     vtkSmartPointer<vtkRenderWindow> renderWindow =
84         vtkSmartPointer<vtkRenderWindow>::New();
85     renderWindow->AddRenderer(leftRenderer);
86     renderWindow->AddRenderer(rightRenderer);
87     renderWindow->SetSize(640, 320);
88     renderWindow->Render();
89     renderWindow->SetWindowName("PolyDataDecimation");
90 
91     vtkSmartPointer<vtkRenderWindowInteractor> interactor =
92         vtkSmartPointer<vtkRenderWindowInteractor>::New();
93     interactor->SetRenderWindow(renderWindow);
94 
95     renderWindow->Render();
96     interactor->Start();
97 
98     return EXIT_SUCCESS;
99 }

标签:1.0,VTK,56,网格,vtkSmartPointer,renderWindow,New,include,leftRenderer
From: https://www.cnblogs.com/ybqjymy/p/17632969.html

相关文章

  • 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......
  • R语言进行支持向量机回归SVR和网格搜索超参数优化|附代码数据
    全文链接:http://tecdat.cn/?p=23305最近我们被客户要求撰写关于支持向量机回归的研究报告,包括一些图形和统计输出。在这篇文章中,我将展示如何使用R语言来进行支持向量回归SVR我们将首先做一个简单的线性回归,然后转向支持向量回归,这样你就可以看到两者在相同数据下的表现。一个......
  • chatGPT用C++写的HMAC-SHA256函数
    以下内容全为chatGPT生成:#include<openssl/hmac.h>#include<openssl/sha.h>#include<iostream>#include<iomanip>std::stringhmac_sha256(conststd::string&key,conststd::string&data){unsignedcharhash[SHA256_DIGEST_L......
  • 8-15| _ctypes.COMError: (-2147352567, '发生意外。', ('无法获取 Document 对象', '
    此错误是一个COM错误,它与试图从Python通过`pyautocad`与AutoCAD通信时出现的问题有关。错误信息"无法获取Document对象"指示了问题的本质,即Python无法访问AutoCAD的当前文档。这里有一些建议来解决这个问题:1.**确保AutoCAD已经运行**:在尝试从Python访问Aut......