VTK编程

VTK草稿5

2015-09-29  本文已影响0人  yzld2002

4.7 Using Texture

材质贴图的本质是一个2D的图像可以渲染过程中被贴在物体的表面,来创造出更丰富的渲染效果。材质贴图需要两个信息:

下面是示例代码和实现效果:

# Load in the texture map. A texture is any unsigned char image. If it
# is not of this type, you will have to map it through a lookup table
# or by using vtkImageShiftScale.
bmpReader = vtk.vtkBMPReader()
bmpReader.SetFileName("/Volumes/Data/VTK/VTK-6.2.0/.ExternalData/MD5/8aa8fa634bb80a41256b2fd0e01819af")
atext = vtk.vtkTexture()
atext.SetInputConnection(bmpReader.GetOutputPort())
atext.InterpolateOn()

# Create a plane source and actor. The vtkPlanesSource generates
# texture coordinates.
plane = vtk.vtkPlaneSource()
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInputConnection(plane.GetOutputPort())
planeActor = vtk.vtkActor()
planeActor.SetMapper(planeMapper)
planeActor.SetTexture(atext)
Texture map on plane

注:这里贴图的坐标就是plane的坐标,vtkPlaneSource会自动生成这个坐标。

4.8 Picking

pick是一个可视化中很常见的任务,选定一个点作为pick的起始位置,执行vtkAbstractPickerPick()方法,根据pick的类型,返回选取点的信息,最简单的信息是三维的坐标(x-y-z global coordinate),或者包括cell id, point id等。pick的语法如下:

Pick(selectionX, selectionY, selectionZ, Renderer)
pick点的三维坐标.png

4.9 vtkCoordinate and Coordinate Systems

VTK支持多种坐标系,vtkCoordinate这个类负责坐标系之间的转换。支持的坐标系如下:

4.10 Controlling vtkActor2D

vtkActor2D类似于vtkActor,不同之处在于它是绘制在一个平面上的,没有一个4*4的转换矩阵。它也有mapper:vtkMapper2D和property:vtkProperty2D,最难处理的部分在于它的位置处理。要做到这一点,必须要使用上文提到的vtkCoordinate

4.11 Annotation

VTK提供了两种方式来标注图像:

2D annotation

2D annotation.png

3D annotation and vtkFollower

3D的标注一般使用vtkVectorText来创建字符串的多边形表示,然后把它放在合适的位置上。一个用于放置3D标注的类是vtkFollower,这是个actor,能确保被渲染的actor始终正对着camera,所以不管图像怎么旋转位移,字符始终能够看清。

3D annotation.png

这张图是一个坐标系的图示,不管坐标系怎么旋转移动,指示原点的"Origin"标识始终正对着镜头

4.12 Special Plotting Classes

VTK提供了几种复杂的绘图操作:

Scalar Bat
上一篇 下一篇

猜你喜欢

热点阅读