首页 > 其他分享 >VTK 实例53:网格平滑

VTK 实例53:网格平滑

时间:2023-08-16 09:03:57浏览次数:35  
标签:VTK 网格 53 vtkSmartPointer rightRenderer renderWindow New include leftRenderer

 1 #include "vtkAutoInit.h" 
 2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
 3 VTK_MODULE_INIT(vtkInteractionStyle);
 4 
 5 #include <vtkSmartPointer.h>
 6 #include <vtkPolyDataReader.h>
 7 #include <vtkPolyData.h>
 8 #include <vtkSmoothPolyDataFilter.h>
 9 #include <vtkWindowedSincPolyDataFilter.h>
10 #include <vtkSphereSource.h>
11 #include <vtkPolyDataMapper.h>
12 #include <vtkActor.h>
13 #include <vtkRenderWindow.h>
14 #include <vtkRenderer.h>
15 #include <vtkRenderWindowInteractor.h>
16 
17 //测试文件:../data/fran_cut.vtk
18 int main(int argc, char *argv[])
19 {
20     vtkSmartPointer<vtkPolyDataReader> reader = 
21         vtkSmartPointer<vtkPolyDataReader>::New();
22     reader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\fran_cut.vtk");
23     reader->Update();
24 
25     vtkSmartPointer<vtkSmoothPolyDataFilter> smoothFilter =
26         vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
27     smoothFilter->SetInputConnection(reader->GetOutputPort());
28     smoothFilter->SetNumberOfIterations(200);
29     smoothFilter->Update();
30 
31     vtkSmartPointer<vtkPolyDataMapper> inputMapper =
32         vtkSmartPointer<vtkPolyDataMapper>::New();
33     inputMapper->SetInputConnection(reader->GetOutputPort());
34     vtkSmartPointer<vtkActor> inputActor =
35         vtkSmartPointer<vtkActor>::New();
36     inputActor->SetMapper(inputMapper);
37 
38     vtkSmartPointer<vtkPolyDataMapper> smoothedMapper =
39         vtkSmartPointer<vtkPolyDataMapper>::New();
40     smoothedMapper->SetInputConnection(smoothFilter->GetOutputPort());
41 
42     vtkSmartPointer<vtkActor> smoothedActor =
43         vtkSmartPointer<vtkActor>::New();
44     smoothedActor->SetMapper(smoothedMapper);
45 
46     double leftViewport[4] = {0.0, 0.0, 0.5, 1.0};
47     double rightViewport[4] = {0.5, 0.0, 1.0, 1.0};
48 
49     vtkSmartPointer<vtkRenderer> leftRenderer =
50         vtkSmartPointer<vtkRenderer>::New();
51 
52     leftRenderer->SetViewport(leftViewport);
53     leftRenderer->AddActor(inputActor);
54     leftRenderer->SetBackground(0.8, 0.8, 0.8);
55     leftRenderer->ResetCamera();
56 
57     vtkSmartPointer<vtkRenderer> rightRenderer =
58         vtkSmartPointer<vtkRenderer>::New();
59     rightRenderer->SetViewport(rightViewport);
60     rightRenderer->AddActor(smoothedActor);
61     rightRenderer->SetBackground(0.8, 0.8, 0.8);
62     rightRenderer->SetActiveCamera(leftRenderer->GetActiveCamera());
63     rightRenderer->ResetCamera();
64 
65     vtkSmartPointer<vtkRenderWindow> renderWindow =
66         vtkSmartPointer<vtkRenderWindow>::New();
67     renderWindow->AddRenderer(leftRenderer);
68     renderWindow->AddRenderer(rightRenderer);
69     renderWindow->SetSize(640, 320);
70     renderWindow->Render();
71     renderWindow->SetWindowName("PolyDataLapLasianSmooth");
72 
73     vtkSmartPointer<vtkRenderWindowInteractor> interactor =
74         vtkSmartPointer<vtkRenderWindowInteractor>::New();
75     interactor->SetRenderWindow(renderWindow);
76 
77     renderWindow->Render();
78     interactor->Start();
79 
80     return EXIT_SUCCESS;
81 }

标签:VTK,网格,53,vtkSmartPointer,rightRenderer,renderWindow,New,include,leftRenderer
From: https://www.cnblogs.com/ybqjymy/p/17632963.html

相关文章

  • VTK 实例54:封闭性检测
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkSelectionNode.h>7#include<vtkInformation.h>8#incl......
  • VTK 实例55:连通区域分析
    1#include<vtkAutoInit.h>2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkRenderingFreeType);4VTK_MODULE_INIT(vtkInteractionStyle);56#include<vtkSmartPointer.h>7#include<vtkSphereSource.h>8#include<v......
  • 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......