VTK笔记——如何创建圆柱体
VTK是⼀个强⼤的可视化开发⼯具,它提供了很多程序源对象可供我们使⽤。下⾯我们介绍如何创建圆柱体。
VTK创建圆柱体有两种⽅式:
- ⽅式⼀:使⽤vtkCylinderSource来创建。
vtkSmartPointer<vtkCylinderSource> cylinderSource =
vtkSmartPointer<vtkCylinderSource>::New();
cylinderSource->SetHeight(10.0);
cylinderSource->SetCenter(0.0, 0.0, 0.0);
cylinderSource->SetRadius(2.0);
cylinderSource->SetResolution(50);
- ⽅式⼆:使⽤vtkLineSource和vtkTubeFilter来创建。
vtkSmartPointer<vtkLineSource> lineSource =
vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoint1(5.0, 0.0, 0.0);
lineSource->SetPoint2(-5.0, 0.0, 0.0);
vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkSmartPointer<vtkTubeFilter>::New();training是什么意思
tubeFilter->SetInputConnection(lineSource->GetOutputPort());
tubeFilter->SetRadius(2.0);
tubeFilter->SetNumberOfSides(50);
tubeFilter->CappingOn();
两种⽅式的区别只在于能否任意设置长轴的⽅向。
后悔的英文⽅式⼀只能创建沿着世界坐标系Y轴⽅向的圆柱体,不能任意设置圆柱体长轴的⽅向。
⽅式⼆可以创建具有⽅向性的圆柱体,通过设置圆柱体长轴的两个端点SetPoint1和SetPoint2。
main.cpp:好看的美剧
#include <vtkCylinderSource.h>
#include <vtkLineSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>电影功夫熊猫2
back to the future#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkTubeFilter.h>
int main(int, char *[])
{
// Create a Cylinder
vtkSmartPointer<vtkCylinderSource> cylinderSource =
vtkSmartPointer<vtkCylinderSource>::New();
cylinderSource->SetHeight(10.0);
cylinderSource->SetCenter(0.0, 0.0, 0.0);
cylinderSource->SetRadius(2.0);
cylinderSource->SetResolution(50);
vtkSmartPointer<vtkLineSource> lineSource =
vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoint1(5.0, 0.0, 0.0);
lineSource->SetPoint2(-5.0, 0.0, 0.0);
vtkSmartPointer<vtkTubeFilter> tubeFilter = vtkSmartPointer<vtkTubeFilter>::New(); tubeFilter->SetInputConnection(lineSource->GetOutputPort());
tubeFilter->SetRadius(2.0);
tubeFilter->SetNumberOfSides(50);
tubeFilter->CappingOn();
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper1 =
vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper1->SetInputConnection(cylinderSource->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper2 =
vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper2->SetInputConnection(tubeFilter->GetOutputPort());
vtkSmartPointer<vtkActor> cylinderActor1 =
vtkSmartPointer<vtkActor>::New();
cylinderActor1->SetMapper(cylinderMapper1);
vtkSmartPointer<vtkActor> cylinderActor2 =
vtkSmartPointer<vtkActor>::New();
cylinderActor2->SetMapper(cylinderMapper2);
vtkSmartPointer<vtkRenderer> renderer1 =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderer> renderer2 =
vtkSmartPointer<vtkRenderer>::New();
六级满分
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(600, 600);
renderWindow->AddRenderer(renderer1);
renderWindow->AddRenderer(renderer2);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
double leftViewport[] = { 0.0, 0.0, 0.5, 1.0 };
double rightViewport[] = { 0.5, 0.0, 1.0, 1.0 };
cylinderActor1->GetProperty()->SetColor(0.0, 1.0, 0.0);
cylinderActor2->GetProperty()->SetColor(0.0, 0.0, 1.0);
renderer1->AddActor(cylinderActor1);
renderer2->AddActor(cylinderActor2);
renderer1->SetBackground(.3, .3, .5); // Background color purple renderer2->SetBackground(.2, .4, .5);
renderer1->SetViewport(leftViewport);
renderer2->SetViewport(rightViewport);
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
usual
恶魔的英文
cmake_minimum_required(VERSION 2.8)
PROJECT(Cylinder)
现状英语
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(Cylinder MACOSX_BUNDLE Cylinder.cpp ) target_link_libraries(Cylinder ${VTK_LIBRARIES})
cde