VTK入门范例1
VTK 3D地球
通过VTK的球形增加地球纹理图片,生成一个3D地球
VTK 管道后处理数据流图
source/reader → filter → mapper → actor → renderer → renderWindow → interactor
实现代码如下:
#include <vtkActor.h>
#include <vtkCellData.h>
#include <vtkColorTransferFunction.h>
#include <vtkDataArray.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkNew.h>
#include <vtkTextureMapToSphere.h>
#include <vtkJPEGReader.h>
#include <vtkTexture.h>
int main(int argc, char* argv[]) {
//Create SphereSource
vtkNew<vtkSphereSource> source;
source->SetRadius(0.5);
source->SetPhiResolution(80);
source->SetThetaResolution(80);
//Create TextureMapToSphere
vtkNew<vtkTextureMapToSphere> texturemap;
texturemap->SetInputConnection(source->GetOutputPort());
//Create Texture
vtkNew<vtkJPEGReader> jPEGReader;
jPEGReader->SetFileName("earth.jpg");
vtkNew<vtkTexture> texture;
texture->SetInputConnection(jPEGReader->GetOutputPort());
//Create Data Set Mapper
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(texturemap->GetOutputPort());
//Create Actor
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->SetTexture(texture);
//Create Renderer and RenderWindow and WindowInteractor
vtkNew<vtkRenderer> render;
render->AddActor(actor);
render->SetBackground(0.1, 0.2, 0.3);
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(render);
vtkNew<vtkRenderWindowInteractor> rwInteractor;
vtkNew<vtkInteractorStyleTrackballCamera> style;
rwInteractor->SetRenderWindow(renderWindow);
rwInteractor->SetInteractorStyle(style);
rwInteractor->Initialize();
rwInteractor->Start();
return 0;
}
结果
源码
参考文献
- VTKUsersGuide https://www.kitware.com/products/books/VTKUsersGuide.pdf
- VTKTextbook https://www.kitware.com/products/books/VTKTextbook.pdf
- API https://vtk.org/doc/nightly/html/index.html
- VTK 架构 https://www.aosabook.org/en/vtk.html
- VTK官方示例:https://lorensen.github.io/VTKExamples/site/
- VTK官方示例:https://kitware.github.io/vtk-examples/site/Cxx/
- VTK 演示 旋转叶轮泵 后处理示例 https://benjaminhopfer.com/2014/10/07/3d-data-visualization-with-vtk/
- VTK 演示 旋转叶轮泵 后处理示例 http://www.toptal.com/data-science/3d-data-visualization-with-open-source-tools-an-example-using-vtk
- VTK8.2.0 介绍 https://blog.kitware.com/vtk-8-2-0/
- VTK.js 介绍 https://blog.kitware.com/vis-on-the-web/
- VTK中的C ++ 11 for-range支持 https://blog.kitware.com/c11-for-range-support-in-vtk/
- DataSet Resampling Filters https://blog.kitware.com/dataset-resampling-filters/
- VR with VTK https://blog.kitware.com/using-virtual-reality-devices-with-vtk/
- VTK Demo https://github.com/daviddoria/Examples/tree/master/c%2B%2B/Demos
- 官方论坛 https://discourse.vtk.org/