当前位置:网站首页>VTK 圆柱体的生成与渲染
VTK 圆柱体的生成与渲染
2022-06-26 12:46:00 【点云侠】
一、简单VTK程序
1、代码示例
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
int main()
{
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();//用智能指针定义一个vtkRenderWindow对象
renWin->Render();//显示并渲染VTK窗口
renWin->SetWindowName("TestVTKInstall");
renWin->SetSize(640, 480);
renWin->Render();
std::cin.get();
return EXIT_SUCCESS;
}
二、生成圆柱
1、代码实现
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkCylinderSource.h>//生成一个中心在渲染场景原点的柱体
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkPLYWriter.h>
int main()
{
//---------------生成一个中心在渲染场景原点的柱体---------------
//柱体的长轴沿Y轴,柱体的高度截面半径等都可以任意指定
vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
cylinder->SetHeight(3.0);//设置柱体的高
cylinder->SetRadius(1.0);//设置柱体的半径
cylinder->SetResolution(10);//设置柱体横截面的等边多边形的边数
//---------------用于渲染多边形几何数据-------------------------
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort()); //VTK可视化管线的输入数据接口
vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(0.0, 0.0, 1.0);
//-------------------写出为PLY格式文件--------------------------
vtkSmartPointer<vtkPLYWriter> plywriter = vtkSmartPointer<vtkPLYWriter>::New();
plywriter->SetFileName("cylinder.ply");
plywriter->SetInputConnection(cylinder->GetOutputPort());
plywriter->Write();
plywriter->Update();
//----------------------管理场景渲染过程------------------
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(cylinderActor);
renderer->SetBackground(1.0, 1.0, 1.0);//RGB取值范围0~1
//----------------------设置窗口参数----------------------
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
renWin->SetSize(640, 480);//设置窗口大小,以像素为单元
renWin->Render();
renWin->SetWindowName("RenderCylinder");
//---------------------交互机制--------------------------
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();
return EXIT_SUCCESS;
}
2、结果展示
边栏推荐
- KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
- J - Wooden Sticks poj 1065
- Es sauvegarde et restauration des données par instantané
- MySQL数据库讲解(五)
- Hdu1724[Simpson formula for integral]ellipse
- tauri vs electron
- 7-2 a Fu the thief
- H5 video automatic playback and circular playback
- mysql讲解(一)
- 33、使用RGBD相机进行目标检测和深度信息输出
猜你喜欢
三维向量的夹角
Learn how to develop owl components by hand (7): practical use of owl projects
Ring queue PHP
原型模式(prototype)
Design of simple digital circuit traffic light
Chapter 10 setting up structured logging (2)
MediaPipe手势(Hands)
古瑞瓦特冲刺港交所上市:创下“多个第一”,获IDG资本9亿元投资
Beifu cx5130 card replacement and transfer of existing authorization files
8. [STM32] timer (TIM) -- interrupt, PWM, input capture experiment (proficient in timer)
随机推荐
Es6: iterator
Network remote access using raspberry pie
MySQL explanation (II)
ES基于Snapshot(快照)的数据备份和还原
IDC report: the AI cloud market share of Baidu AI Cloud ranks first for six consecutive times
What features are added to Photoshop 2022 23.4.1? Do you know anything
Create your own cross domain proxy server
HDU 3555 Bomb
Basic methods for network diagnosis and hardware troubleshooting of Beifu EtherCAT module
【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
Electron official docs series: Testing And Debugging
创建一个自己的跨域代理服务器
A few lines of code can realize complex excel import and export. This tool class is really powerful!
Typescript
CloudCompare——泊松重建
C language: Exercise 2
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
适配器模式(Adapter)
mysql讲解(一)
Nexys A7开发板资源使用技巧