当前位置:网站首页>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、结果展示

边栏推荐
- 7-1 n queen problem
- DataGrip配置的连接迁移
- May product upgrade observation station
- Uva10341 solve it
- imagecopymerge
- Reflect the technical depth (unable to speed up)
- 创建一个自己的跨域代理服务器
- Zoomeeper sets ACL permission control (only specific IP access is allowed to enhance security)
- MySQL数据库讲解(六)
- Mysql database explanation (III)
猜你喜欢

Here document interaction free and expect automatic interaction

ES中索引别名(alias)的到底有什么用

Beifu cx5130 card replacement and transfer of existing authorization files

Beifu PLC model selection -- how to see whether the motor is a multi turn absolute value encoder or a single turn absolute value encoder

Decorator

Arcpy -- use of insertlayer() function: adding layers to map documents

Beifu PLC based on NT_ Shutdown to realize automatic shutdown and restart of controller

Basic methods for network diagnosis and hardware troubleshooting of Beifu EtherCAT module

Detailed sorting of HW blue team traceability process

Network remote access using raspberry pie
随机推荐
H - Sumsets POJ 2229
ES中索引别名(alias)的到底有什么用
MongoDB系列之Window环境部署配置
计算两点之间的距离(二维、三维)
KITTI Detection dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
MySQL explanation (I)
SQL assigns the field value of data table B to a column in data table a
偶言佳句,孤芳自赏
Electron official docs series: Examples
Uva10341 solve it
A collection of common tools for making we media videos
First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
Firewall introduction
Network remote access using raspberry pie
三维向量的夹角
F - Charm Bracelet
MediaPipe手势(Hands)
ES6:Map
Log in to the server using SSH key pair
HDU 5860