当前位置:网站首页>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
边栏推荐
- Included angle of 3D vector
- Electron official docs series: Testing And Debugging
- NVM installation tutorial
- A few lines of code can realize complex excel import and export. This tool class is really powerful!
- Mysql database explanation (III)
- Mongodb series window environment deployment configuration
- Aesthetic experience (episode 238) Luo Guozheng
- DataGrip配置的连接迁移
- GO语言-管道channel
- Connection migration for DataGrid configuration
猜你喜欢
Mediapipe gestures (hands)
Adapter mode
防火墙介绍
Beifu PLC obtains system time, local time, current time zone and system time zone conversion through program
古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
[how to connect the network] Chapter 2 (middle): sending a network packet
Reprint - easy to use wechat applet UI component library
基于PyTorch的生成对抗网络实战(7)——利用Pytorch搭建SGAN(Semi-Supervised GAN)生成手写数字并分类
Design of simple digital circuit traffic light
Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
随机推荐
[how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
Mysql database explanation (6)
SQL assigns the field value of data table B to a column in data table a
Detailed sorting of HW blue team traceability process
ES中索引别名(alias)的到底有什么用
Design of simple digital circuit traffic light
Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value
Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
Wechat applet -picker component is repackaged and the disabled attribute is added -- below
What is the use of index aliases in ES
Uva5009 error curves three points
NVM installation tutorial
7-16 monetary system I
Reprint - easy to use wechat applet UI component library
MongoDB系列之适用场景和不适用场景
Beifu PLC model selection -- how to see whether the motor is a multi turn absolute value encoder or a single turn absolute value encoder
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
微信小程序注册指引
[how to connect the network] Chapter 2 (middle): sending a network packet