首页 > 其他分享 >VTK 实例57:网格细化(多分辨率处理)

VTK 实例57:网格细化(多分辨率处理)

时间:2023-08-16 09:02:47浏览次数:35  
标签:GetActiveCamera rw 57 网格 vtkSmartPointer origRender New include VTK

  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 <vtkPolyDataReader.h>
  8 #include <vtkPolyData.h>
  9 #include <vtkLinearSubdivisionFilter.h>
 10 #include <vtkLoopSubdivisionFilter.h>
 11 #include <vtkButterflySubdivisionFilter.h>
 12 #include <vtkPolyDataMapper.h>
 13 #include <vtkActor.h>
 14 #include <vtkRenderer.h>
 15 #include <vtkRenderWindow.h>
 16 #include <vtkCamera.h>
 17 #include <vtkRenderWindowInteractor.h>
 18 
 19 int main()
 20 {
 21     //读数据
 22     vtkSmartPointer<vtkPolyDataReader> reader =
 23         vtkSmartPointer<vtkPolyDataReader>::New();
 24     reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\fran_cut.vtk");
 25     reader->Update();
 26 
 27     vtkSmartPointer<vtkPolyData> orig = reader->GetOutput();
 28     std::cout << "original" << "-----------------------" << std::endl;
 29     std::cout << "模型点数为: " << orig->GetNumberOfPoints() << std::endl;
 30     std::cout << "模型面数为: " << orig->GetNumberOfPolys() << std::endl;
 31     //线性网格细分滤波器
 32     vtkSmartPointer<vtkLinearSubdivisionFilter> linear =
 33         vtkSmartPointer<vtkLinearSubdivisionFilter>::New();
 34     linear->SetInputData(orig);
 35     linear->SetNumberOfSubdivisions(4);
 36     linear->Update();
 37 
 38     vtkSmartPointer<vtkPolyData> linearInfo = linear->GetOutput();
 39     std::cout << "linear" << "-----------------------" << std::endl;
 40     std::cout << "模型点数为: " << linearInfo->GetNumberOfPoints() << std::endl;
 41     std::cout << "模型面数为: " << linearInfo->GetNumberOfPolys() << std::endl;
 42 
 43     //Loop网格细分滤波器
 44     vtkSmartPointer<vtkLoopSubdivisionFilter> loop =
 45         vtkSmartPointer<vtkLoopSubdivisionFilter>::New();
 46     loop->SetInputData(orig);
 47     loop->SetNumberOfSubdivisions(4);
 48     loop->Update();
 49 
 50     vtkSmartPointer<vtkPolyData> loopInfo = loop->GetOutput();
 51     std::cout << "loop" << "-----------------------" << std::endl;
 52     std::cout << "模型点数为: " << loopInfo->GetNumberOfPoints() << std::endl;
 53     std::cout << "模型面数为: " << loopInfo->GetNumberOfPolys() << std::endl;
 54 
 55     //butterfly网格细分滤波器
 56     vtkSmartPointer<vtkButterflySubdivisionFilter> butterfly =
 57         vtkSmartPointer<vtkButterflySubdivisionFilter>::New();
 58     butterfly->SetInputData(orig);
 59     butterfly->SetNumberOfSubdivisions(4);
 60     butterfly->Update();
 61 
 62     vtkSmartPointer<vtkPolyData> butterflyInfo = butterfly->GetOutput();
 63     std::cout << "butterfly" << "-----------------------" << std::endl;
 64     std::cout << "模型点数为: " << butterflyInfo->GetNumberOfPoints() << std::endl;
 65     std::cout << "模型面数为: " << butterflyInfo->GetNumberOfPolys() << std::endl;
 66     
 67     vtkSmartPointer<vtkPolyDataMapper> origMapper =
 68         vtkSmartPointer<vtkPolyDataMapper>::New();
 69     origMapper->SetInputData(orig);
 70     vtkSmartPointer<vtkActor> origActor =
 71         vtkSmartPointer<vtkActor>::New();
 72     origActor->SetMapper(origMapper);
 73 
 74     vtkSmartPointer<vtkPolyDataMapper> linearMapper =
 75         vtkSmartPointer<vtkPolyDataMapper>::New();
 76     linearMapper->SetInputData(linear->GetOutput());
 77     vtkSmartPointer<vtkActor> linearActor =
 78         vtkSmartPointer<vtkActor>::New();
 79     linearActor->SetMapper(linearMapper);
 80 
 81     vtkSmartPointer<vtkPolyDataMapper> loopMapper =
 82         vtkSmartPointer<vtkPolyDataMapper>::New();
 83     loopMapper->SetInputData(loop->GetOutput());
 84     vtkSmartPointer<vtkActor> loopActor =
 85         vtkSmartPointer<vtkActor>::New();
 86     loopActor->SetMapper(loopMapper);
 87 
 88     vtkSmartPointer<vtkPolyDataMapper> butterflyMapper =
 89         vtkSmartPointer<vtkPolyDataMapper>::New();
 90     butterflyMapper->SetInputData(butterfly->GetOutput());
 91     vtkSmartPointer<vtkActor> butterflyActor =
 92         vtkSmartPointer<vtkActor>::New();
 93     butterflyActor->SetMapper(butterflyMapper);
 94     //
 95     double ltView[4] = { 0, 0, 0.5, 0.5 };
 96     double rtView[4] = { 0.5, 0, 1, 0.5 };
 97     double lbView[4] = { 0, 0.5, 0.5, 1 };
 98     double rbView[4] = { 0.5, 0.5, 1, 1 };
 99 
100     vtkSmartPointer<vtkRenderer> origRender =
101         vtkSmartPointer<vtkRenderer>::New();
102     origRender->SetViewport(ltView);
103     origRender->AddActor(origActor);
104     origRender->SetBackground(1, 0, 0);
105 
106     vtkSmartPointer<vtkRenderer> linearRender =
107         vtkSmartPointer<vtkRenderer>::New();
108     linearRender->SetViewport(rtView);
109     linearRender->AddActor(linearActor);
110     linearRender->SetBackground(0, 1, 0);
111 
112     vtkSmartPointer<vtkRenderer> loopRender =
113         vtkSmartPointer<vtkRenderer>::New();
114     loopRender->SetViewport(lbView);
115     loopRender->AddActor(loopActor);
116     loopRender->SetBackground(0, 0, 1);
117 
118     vtkSmartPointer<vtkRenderer> butterflyRender =
119         vtkSmartPointer<vtkRenderer>::New();
120     butterflyRender->SetViewport(rbView);
121     butterflyRender->AddActor(butterflyActor);
122     butterflyRender->SetBackground(0, 0, 0);
123     //
124     vtkSmartPointer<vtkRenderWindow> rw =
125         vtkSmartPointer<vtkRenderWindow>::New();
126     rw->AddRenderer(origRender);
127     rw->AddRenderer(linearRender);
128     rw->AddRenderer(loopRender);
129     rw->AddRenderer(butterflyRender);
130     rw->SetSize(640, 640);
131     rw->SetWindowName("PolyData Subdivision");
132 
133     origRender->GetActiveCamera()->SetPosition(0, -1, 0);
134     origRender->GetActiveCamera()->SetFocalPoint(0, 0, 0);
135     origRender->GetActiveCamera()->SetViewUp(0, 0, 1);
136     origRender->GetActiveCamera()->Azimuth(30);
137     origRender->GetActiveCamera()->Elevation(30);
138     origRender->ResetCamera();//刷新照相机  
139     linearRender->SetActiveCamera(origRender->GetActiveCamera());
140     loopRender->SetActiveCamera(origRender->GetActiveCamera());
141     butterflyRender->SetActiveCamera(origRender->GetActiveCamera());
142     
143     vtkSmartPointer<vtkRenderWindowInteractor> rwi =
144         vtkSmartPointer<vtkRenderWindowInteractor>::New();
145     rwi->SetRenderWindow(rw);
146     rwi->Start();
147     rw->Render();
148 
149     return 0;
150 }

 放大细节

 红色视窗为原始三角网格模型,绿色视窗采用了线性细分算法;蓝色视窗采用Loop细分算法;黑色视窗采用了Butterfly细分算法。可见Loop细分、Butterfly细分能够得到较为光滑的效果;效果优于线性细分算法。

标签:GetActiveCamera,rw,57,网格,vtkSmartPointer,origRender,New,include,VTK
From: https://www.cnblogs.com/ybqjymy/p/17632970.html

相关文章

  • 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......
  • pchunter64v.157 授权过期
      16进制编辑器打开pchunter64.exe搜索字节序列:488B5C2450 33C9E8B5更改488B5C2450为BB7FE685F4  即:movrbx,[rsp+50]更改为movebx,F485E67F,保存更改。 ......
  • R语言进行支持向量机回归SVR和网格搜索超参数优化|附代码数据
    全文链接:http://tecdat.cn/?p=23305最近我们被客户要求撰写关于支持向量机回归的研究报告,包括一些图形和统计输出。在这篇文章中,我将展示如何使用R语言来进行支持向量回归SVR我们将首先做一个简单的线性回归,然后转向支持向量回归,这样你就可以看到两者在相同数据下的表现。一个......
  • 【LeetCode 571. 给定数字的频率查询中位数】WITH RECURSIVE实现Tally的逆操作
    目录题目地址代码题目地址https://leetcode.cn/problems/find-median-given-frequency-of-numbers/description/代码WITHRECURSIVERecCTEAS(SELECTnum,frequency-1asremaining_frequencyFROMNumbersWHEREfrequency>0UNIONALLSELECTn......
  • MySQL本地服务器与MySQL57网络服务器区别
    MySQL服务器与MySQL57服务器区别与不同处在哪里,他们各自的领域范围,能不能同时启动服务?安装了MySQL-5.7.18.0版本数据库,版本中包含了MySQLWorkbench可视化试图工具,在服务列表栏中会有MySQL的两个服务器;如果启动第一项MySQL服务器就只能操作数据库,外界不能连接到数据链接会报perfo......