首页 > 其他分享 >VTK 实例63:纹理映射

VTK 实例63:纹理映射

时间:2023-08-16 09:00:53浏览次数:43  
标签:映射 VTK actor vtkSmartPointer 63 renderWindow New include

 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 <vtkRenderWindowInteractor.h>
 8 #include <vtkRenderWindow.h>
 9 #include <vtkRenderer.h>
10 #include <vtkActor.h>
11 #include <vtkPolyDataMapper.h>
12 #include <vtkTransformTextureCoords.h>
13 #include <vtkTexture.h>
14 #include <vtkTextureMapToSphere.h>
15 #include <vtkTextureMapToCylinder.h>
16 #include <vtkBMPReader.h>
17 #include <vtkTexturedSphereSource.h>
18 #include <vtkXMLPolyDataReader.h>
19 
20 //测试:../data/masonry.bmp ../data/cow.vtp
21 int main (int argc, char *argv[])
22 {
23     double translate[3];
24     translate[0] = 10.0;
25     translate[1] = 0.0;
26     translate[2] = 0.0;
27     std::cout << translate[0] << ", "
28         << translate[1] << ", "
29         << translate[2] << "\n";
30 
31     vtkSmartPointer<vtkBMPReader> texReader =
32         vtkSmartPointer<vtkBMPReader>::New();
33     texReader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\masonry.bmp");//读取纹理图像
34 
35     vtkSmartPointer<vtkTexture> texture =
36         vtkSmartPointer<vtkTexture>::New();
37     texture->SetInputConnection(texReader->GetOutputPort());
38 
39     vtkSmartPointer<vtkXMLPolyDataReader> modelReader =
40         vtkSmartPointer<vtkXMLPolyDataReader>::New();
41     modelReader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\cow.vtp");//读取模型
42 
43     vtkSmartPointer<vtkTextureMapToCylinder> texturemap = 
44         vtkSmartPointer<vtkTextureMapToCylinder>::New();
45     texturemap->SetInputConnection(modelReader->GetOutputPort());
46 
47     vtkSmartPointer<vtkPolyDataMapper> mapper =
48         vtkSmartPointer<vtkPolyDataMapper>::New();
49     mapper->SetInputConnection(texturemap->GetOutputPort());
50 
51     vtkSmartPointer<vtkActor> actor =
52         vtkSmartPointer<vtkActor>::New();
53     actor->SetMapper( mapper );
54     actor->SetTexture( texture );
55 
56     vtkSmartPointer<vtkRenderer> renderer =
57         vtkSmartPointer<vtkRenderer>::New();
58     renderer->AddActor(actor);
59     renderer->SetBackground(1.0, 1.0, 1.0);
60 
61     vtkSmartPointer<vtkRenderWindow> renderWindow =
62         vtkSmartPointer<vtkRenderWindow>::New();
63     renderWindow->AddRenderer( renderer );
64 
65     vtkSmartPointer<vtkRenderWindowInteractor> renWinInteractor =
66         vtkSmartPointer<vtkRenderWindowInteractor>::New();
67     renWinInteractor->SetRenderWindow( renderWindow );
68 
69     renderWindow->SetSize(640, 480);
70     renderWindow->Render();
71     renderWindow->SetWindowName("TextureMap");
72     renderWindow->Render();
73     renderWindow->Render();
74     renWinInteractor->Start();
75 
76     return EXIT_SUCCESS;
77 }

标签:映射,VTK,actor,vtkSmartPointer,63,renderWindow,New,include
From: https://www.cnblogs.com/ybqjymy/p/17632980.html

相关文章