当前位置:网站首页>Generation and rendering of VTK cylinder
Generation and rendering of VTK cylinder
2022-06-26 13:40:00 【Dianyun Xia】
Catalog
One 、 Simple VTK Program
1、 Code example
#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();// Define a with a smart pointer vtkRenderWindow object
renWin->Render();// Display and render VTK window
renWin->SetWindowName("TestVTKInstall");
renWin->SetSize(640, 480);
renWin->Render();
std::cin.get();
return EXIT_SUCCESS;
}
Two 、 Generate a cylinder
1、 Code implementation
#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>// Generate a cylinder centered at the origin of the rendered scene
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkPLYWriter.h>
int main()
{
//--------------- Generate a cylinder centered at the origin of the rendered scene ---------------
// Along the long axis of the cylinder Y Axis , The height of the column, the section radius, etc. can be arbitrarily specified
vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
cylinder->SetHeight(3.0);// Sets the height of the column
cylinder->SetRadius(1.0);// Set the radius of the cylinder
cylinder->SetResolution(10);// Sets the number of sides of the equilateral polygon of the column cross section
//--------------- Used to render polygon geometry data -------------------------
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort()); //VTK Input data interface of visual pipeline
vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(0.0, 0.0, 1.0);
//------------------- Write as PLY Format file --------------------------
vtkSmartPointer<vtkPLYWriter> plywriter = vtkSmartPointer<vtkPLYWriter>::New();
plywriter->SetFileName("cylinder.ply");
plywriter->SetInputConnection(cylinder->GetOutputPort());
plywriter->Write();
plywriter->Update();
//---------------------- Manage scene rendering passes ------------------
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(cylinderActor);
renderer->SetBackground(1.0, 1.0, 1.0);//RGB Value range 0~1
//---------------------- Set window parameters ----------------------
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
renWin->SetSize(640, 480);// Set window size , In pixels
renWin->Render();
renWin->SetWindowName("RenderCylinder");
//--------------------- Interaction mechanism --------------------------
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、 Result display

边栏推荐
- ES基於Snapshot(快照)的數據備份和還原
- Es common grammar I
- Use of wangeditor rich text editor
- Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
- Echart stack histogram: add white spacing effect setting between color blocks
- Hdu1724[Simpson formula for integral]ellipse
- ES6 module
- 2. Introduction to parallel interface, protocol and related chips (8080, 8060)
- MySQL数据库讲解(四)
- 【Proteus仿真】Arduino UNO按键启停 + PWM 调速控制直流电机转速
猜你喜欢

创建一个自己的跨域代理服务器

Common faults of MySQL database - forgetting database password

Calculate the distance between two points (2D, 3D)

Included angle of 3D vector

2021-10-09

【Spark】. Explanation of several icons of scala file in idea

MySQL讲解(二)

Select tag - uses the default text as a placeholder prompt but is not considered a valid value

【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示

Chapter 10 setting up structured logging (2)
随机推荐
HW蓝队溯源流程详细整理
imagecopymerge
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
GO语言-管道channel
Use of wangeditor rich text editor
Typescript
There are many contents in the widget, so it is a good scheme to support scrolling
Mongodb series window environment deployment configuration
Es6: iterator
【Proteus仿真】Arduino UNO按键启停 + PWM 调速控制直流电机转速
[how to connect the network] Chapter 2 (middle): sending a network packet
Basic methods for network diagnosis and hardware troubleshooting of Beifu EtherCAT module
POJ 3070 Fibonacci
Common faults of MySQL database - forgetting database password
7-2 picking peanuts
微信小程序注册指引
Oplg: new generation cloud native observable best practices
Calculate the distance between two points (2D, 3D)
A primary multithreaded server model
[how to connect the network] Chapter 1: the browser generates messages