vtk介绍

news/2025/3/15 11:20:02/

VTK(visualization toolkit)是一个开源的免费软件系统,主要用于三维计算机图形学、图像处理和科学计算可视化。VTK是在三维函数库OpenGL 的基础上采用面向对象的设计方法发展起来的,它将我们在可视化开发过程中会经常遇到的细节屏蔽起来,并将一些常用的算法封装起来。它包含一个C++类库,和解释封装层,包括Tcl/Tk、Java、Python等。 采用这种架构的优势是我们能使用C++语言建立高效的算法,用其他的脚本语言(如TCL、Python)可以进行快速的开发。

VTK中可以导入/导出或读/写多种三维格式的文件,可以参考What 3D file formats can VTK import and export? The following table identifies the file formats that VTK can read and write. Importer and Exporter classes move full scene information into or out of VTK. Reader and Writer classes move just geometry.
在这里插入图片描述

STL格式是一种3D模型文件格式,它采用三角形离散地近似表示三维模型,目前已被工业界认为是快速成形领域的标准描述文件格式。这种文件不包括模型的材质等信息。下面的代码将读入一个STL文件将其显示在窗口中,并可以用鼠标和键盘进行一些简单的交互。

#!/usr/bin/env pythonimport vtkfilename = "myfile.stl"reader = vtk.vtkSTLReader()
reader.SetFileName(filename)mapper = vtk.vtkPolyDataMapper()mapper.SetInputConnection(reader.GetOutputPort())actor = vtk.vtkActor()
actor.SetMapper(mapper)# Create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)# Create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)# Assign actor to the renderer
ren.AddActor(actor)# Enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()

3ds文件是是Autodesk 3dsMax使用的一种二进制存储格式,VTK中可以使用vtk3DSImporter类导入3ds文件。

vtkImporter is an abstract class that specifies the protocol for importing actors, cameras, lights and properties into a vtkRenderWindow. The following takes place: 1) Create a RenderWindow and Renderer if none is provided. 2) Call ImportBegin, if ImportBegin returns False, return 3) Call ReadData, which calls: a) Import the Actors b) Import the cameras c) Import the lights d) Import the Properties 7) Call ImportEnd

Subclasses optionally implement the ImportActors, ImportCameras, ImportLights and ImportProperties or ReadData methods. An ImportBegin and ImportEnd can optionally be provided to perform Importer-specific initialization and termination. The Read method initiates the import process. If a RenderWindow is provided, its Renderer will contained the imported objects. If the RenderWindow has no Renderer, one is created. If no RenderWindow is provided, both a RenderWindow and Renderer will be created. Both the RenderWindow and Renderer can be accessed using Get methods.

# This example demonstrates the use of vtk3DSImporter.
# vtk3DSImporter is used to load 3D Studio files.  Unlike writers,
# importers can load scenes (data as well as lights, cameras, actors
# etc.). Importers will either generate an instance of vtkRenderWindow
# and/or vtkRenderer or will use the ones you specify.import vtk# Create the importer and read a file
importer = vtk.vtk3DSImporter()
importer.ComputeNormalsOn()
importer.SetFileName("myfile.3ds")
importer.Read()# Here we let the importer create a renderer and a render window for
# us. We could have also create and assigned those ourselves like so:
# renWin = vtk.vtkRenderWindow()
# importer.SetRenderWindow(renWin)# Assign an interactor.
# We have to ask the importer for it's render window.
renWin = importer.GetRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)# Set the render window's size
renWin.SetSize(500, 500)# Set some properties on the renderer.
# We have to ask the importer for it's renderer.
ren = importer.GetRenderer()
ren.SetBackground(0.1, 0.2, 0.4)iren.Initialize()
renWin.Render()
iren.Start()

http://www.ppmy.cn/news/372544.html

相关文章

关于VTK

什么是VTK? Vtk(visualization toolkit)是一个开源的免费软件系统,主要用于三维计算机图形学、图像处理和可视化。Vtk是在面向对象原理的基础上设计和实现的,它的内核是用C构建的,包含有大约250,000行代码…

vtkPropPicker拾取功能

拾取一个对象,拾取的是这个对象所在的actor,所以如果想让不同的对象分开被拾取,一个对象就要创建一个actor。 vtkPropPicker 硬件拾取,只能返回位置信息 vtkAreaPicker 实现框选功能,拾取函数需要XMIN XMAX YMIN YMAX vtkPicker 通过物体的bounding box 拾取:相机和点之间…

VTK配置

提示:对编译过程迷糊的小白——VTK安装记录 文章目录 前言一、准备工作 1.下载最新版VTK(尽可能用最新版,我试过其他的,在cmake过程中选择64位,出现了一些问题)2.下载与本机匹配的cmake(我是Windows 64)二、…

ICP in VTK

提要 今天要研究的是关于图像配准的问题,图像配准是图像处理研究领域中的一个典型问题和技术难点,其目的在于比较或融合针对同一对象在不同条件下获取的图像,例如图像会来自不同的采集设备,取自不同的时间,不同的拍摄视…

VTK -SurfaceReconstruction

链接: 1.https://blog.csdn.net/hw140701/article/details/52796290 2.https://blog.csdn.net/HopefulLight/article/details/79157144?utm_sourceblogxgwz6 经典的Signed Distance Function重建算法主要流程如下: 1、对每个数据点,搜索其邻…

VTK-vtkPointInterpolator/vtkInterpolatorKernel

欢迎大家加入社区,雪易VTK社区-CSDN社区云 前言:目前在做模型的ReMesh,在研究这个接口,希望能有所帮助。 vtkPointInterpolator 描述: 变量: Strategy:MASK_POINTS, NULL_VALUE, CLOSEST_POI…

VTK(The Visualization Toolkit)编译

VTK系列文章目录 文章目录 VTK系列文章目录前言一、准备工作二、VTK编译1.使用CMake生成vs工程2.编译vtk.sln 总结 前言 可视化工具包(VTK)是用于操作和显示科学数据的开源软件。它配有最先进的三维渲染工具、一套用于三维交互的小部件和广泛的二维绘图…

安装VTK

需要的环境及文件 平台:win10已安装好的Visual Studio,建议2017及2019。vs主要是用来编译VTK,最后生成我们想要的库文件,头文件之类的。已安装好的Qt,建议版本5.9或5.12cmake-gui,如未安装可参照下面的教程…