小结:
创建 数据对象
structuredGrid grid
使用contourfilter con
PolyDataMapper m
Actor a

使用
MaskPoint3D mask
glyph3D glyph
同上

生成数据

生成Actor

交给Renderer

放在Renderwindow中

显示

管线与数据加载#

pipline
分为两种一种

可视化管线 Visualization Pipeline
原始数据->图形数据

图形管线 Graphics Pipeline
图形数据->我们看到的图像

全流程

可视化管线tvtk对象

CubeSource PolyData对象
PolyDataMapper 对象 数据->图形数据

由 PolyData 的 output_port -> PolyDataMapper的input_connection

图形管线
可视化对象
Actor 包括一个场景实体,包括一个图形数据(mapper) ,具有实体的位置方向等信息

Renderer 渲染的场景 场景包含多个需要Actor

RenderWindow 渲染的窗口,包括多个Render

RenderWindowInteractor 提供一个用户交互功能

使用ivtk###

相机对象的属性

数据集###

分类

  • ImageData
    在数组中储存数据,在正交且等距的地方
    数据集构建的参数

  • RectilinearFrid
    表示间距不军训的网络,虽然正交但是不均匀

import numpy as np
x=np.array([0,3,9,15])
y=np.array([0,1,5])
z=np.array([0,2,3])

r=tvtk.RectilinearGrid()

r.x_coordinates=x
r.y_coordinates=y
r.z_coordinates=z

r.dimensions=len(x),len(y),len(z)

for n in range(6):
print(r.get_point(n))

可以看到依次底层

  • StructuredGrid
    需要指定点的坐标

+Polydata 数据集

有一系列的点,点之间的练习

TVTK库的数据加##

从外部读入

vtk object 是 vtk 中大多数对象的基类

读取STL####

s=tvtk.STLReader(file_name="文件名")

plot3D的读取
+网格文件 XYZ文件
+动气动力学结果文件(Q文件)
+通用结果

Plot3d=tvtk.MUltiBlockPLOT3DReader(
xyz_file_name="combxyz.bin",网格文件
q_file_name="combp.pin",动气动力学结果文件
scalar_function_number=100, # 设置标量数据数量
vector_function_number=200, #设置矢量数据数量
)
Plot3d.update() 计算其输出数据
grid=Plot3d.output.get_block(0)

tvtk.ContourFilter()

tvtk符号化技术####


tvtk.Glyph3d()

由于矢量数据过于密集

使用类maskpoint

外轮轮廓可视化技术####

使用tvtk.StructuredGridOutlineFilter()
计算POlyData对象的外边框

一下是代码
readstll&bin&show them.ipny


from tvtk.api import tvtk
from ivtk_func import*
from tvtk.api import tvtk
from ivtk_func import*
In [4]:

s=tvtk.STLReader(file_name="python.stl")# PolyData对象
In [5]:

m=tvtk.PolyDataMapper(input_connection=s.output_port)
In [6]:


from tvtk.api import tvtk
from ivtk_func import*
from tvtk.api import tvtk
from ivtk_func import*
a
from tvtk.api import tvtk
from ivtk_func import*
from tvtk.api import tvtk
from ivtk_func import*=tvtk.Actor(mapper=m)
In [7]:

win=ivtk_scene(a)
win.scene.isometric_view()
win=ivtk_scene(a)
win.scene.isometric_view()
In [9]:

event_loop()
In [2]:

Plot3d=tvtk.MultiBlockPLOT3DReader(
    xyz_file_name="combxyz.bin",  #网格文件
    q_file_name="combq.bin",   #动气动力学结果文件
    scalar_function_number=100,   # 设置标量数据数量
    vector_function_number=200,   #设置矢量数据数量
    )
Plot3d.update()
grid=Plot3d.output.get_block(0)
In [3]:

print(type(Plot3d.output))             #MultiBlockDataSet
print(type(Plot3d.output.get_block(0)))#StructuredGrid
print(type(Plot3d.output.get_block(1)))#Nonetype
print(type(Plot3d))     #MultiPlot3dread_read
print(grid.dimensions)  #网格文件的内容是List
​
print(type(grid.points))#Points 类型
print(grid.points.to_array())#Points array
​
print(type(grid))
print(grid.point_data.number_of_arrays) #网格中的点有四种数据
print(grid.point_data)
​
​
print(grid.point_data.scalars.name)
print(grid.point_data.vectors.name)
​
print("\n")
print(grid)
​
​
print("\n")
print(Plot3d)
​
print("\n")
print(grid.point_data)
<class 'tvtk.tvtk_classes.multi_block_data_set.MultiBlockDataSet'>
<class 'tvtk.tvtk_classes.structured_grid.StructuredGrid'>
<class 'NoneType'>
<class 'tvtk.tvtk_classes.multi_block_plot3d_reader.MultiBlockPLOT3DReader'>
[57 33 25]
<class 'tvtk.tvtk_classes.points.Points'>
[[  2.66700006  -3.77476001  23.83292007]
 [  2.94346499  -3.74825287  23.66555977]
 [  3.21985817  -3.72175312  23.49823952]
 ..., 
 [ 15.84669018   5.66214085  35.7493782 ]
 [ 16.17829895   5.66214085  35.7493782 ]
 [ 16.51000023   5.66214085  35.7493782 ]]
<class 'tvtk.tvtk_classes.structured_grid.StructuredGrid'>
4
vtkPointData (0000012712511380)
  Debug: Off
  Modified Time: 413
  Reference Count: 2
  Registered Events: 
    Registered Observers:
      vtkObserver (0000012714C3D3A0)
        Event: 33
        EventName: ModifiedEvent
        Command: 00000127149B2B40
        Priority: 0
        Tag: 3
      vtkObserver (0000012714C3CBC0)
        Event: 33
        EventName: ModifiedEvent
        Command: 0000012714D622D0
        Priority: 0
        Tag: 1
  Number Of Arrays: 4
  Array 0 name = Density
  Array 1 name = Momentum
  Array 2 name = StagnationEnergy
  Array 3 name = Velocity
  Number Of Components: 8
  Number Of Tuples: 47025
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
  Scalars: 
    Debug: Off
    Modified Time: 392
    Reference Count: 1
    Registered Events: (none)
    Name: Density
    Data type: float
    Size: 47025
    MaxId: 47024
    NumberOfComponents: 1
    Information: 0000000000000000
    Name: Density
    Number Of Components: 1
    Number Of Tuples: 47025
    Size: 47025
    MaxId: 47024
    LookupTable: (none)
  Vectors: 
    Debug: Off
    Modified Time: 409
    Reference Count: 1
    Registered Events: (none)
    Name: Velocity
    Data type: float
    Size: 141075
    MaxId: 141074
    NumberOfComponents: 3
    Information: 0000000000000000
    Name: Velocity
    Number Of Components: 3
    Number Of Tuples: 47025
    Size: 141075
    MaxId: 141074
    LookupTable: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
  EdgeFlag: (none)


Density
Velocity


vtkStructuredGrid (0000012711A0B400)
  Debug: Off
  Modified Time: 413
  Reference Count: 3
  Registered Events: 
    Registered Observers:
      vtkObserver (0000012714C3CD70)
        Event: 33
        EventName: ModifiedEvent
        Command: 00000127149B2B00
        Priority: 0
        Tag: 1
  Information: 0000012714D62280
  Data Released: False
  Global Release Data: Off
  UpdateTime: 0
  Field Data:
    Debug: Off
    Modified Time: 389
    Reference Count: 1
    Registered Events: (none)
    Number Of Arrays: 1
    Array 0 name = Properties
    Number Of Components: 1
    Number Of Tuples: 4
  Number Of Points: 47025
  Number Of Cells: 43008
  Cell Data:
    Debug: Off
    Modified Time: 187
    Reference Count: 1
    Registered Events: 
      Registered Observers:
        vtkObserver (0000012714C3CE60)
          Event: 33
          EventName: ModifiedEvent
          Command: 0000012714D622D0
          Priority: 0
          Tag: 1
    Number Of Arrays: 0
    Number Of Components: 0
    Number Of Tuples: 0
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
    Scalars: (none)
    Vectors: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
  Point Data:
    Debug: Off
    Modified Time: 413
    Reference Count: 1
    Registered Events: 
      Registered Observers:
        vtkObserver (0000012714C3CBC0)
          Event: 33
          EventName: ModifiedEvent
          Command: 0000012714D622D0
          Priority: 0
          Tag: 1
    Number Of Arrays: 4
    Array 0 name = Density
    Array 1 name = Momentum
    Array 2 name = StagnationEnergy
    Array 3 name = Velocity
    Number Of Components: 8
    Number Of Tuples: 47025
    Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
    Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
    Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
    Scalars: 
      Debug: Off
      Modified Time: 392
      Reference Count: 1
      Registered Events: 
        Registered Observers:
          (none)
      Name: Density
      Data type: float
      Size: 47025
      MaxId: 47024
      NumberOfComponents: 1
      Information: 0000000000000000
      Name: Density
      Number Of Components: 1
      Number Of Tuples: 47025
      Size: 47025
      MaxId: 47024
      LookupTable: (none)
    Vectors: 
      Debug: Off
      Modified Time: 409
      Reference Count: 1
      Registered Events: 
        Registered Observers:
          (none)
      Name: Velocity
      Data type: float
      Size: 141075
      MaxId: 141074
      NumberOfComponents: 3
      Information: 0000000000000000
      Name: Velocity
      Number Of Components: 3
      Number Of Tuples: 47025
      Size: 141075
      MaxId: 141074
      LookupTable: (none)
    Normals: (none)
    TCoords: (none)
    Tensors: (none)
    GlobalIds: (none)
    PedigreeIds: (none)
    EdgeFlag: (none)
  Bounds: 
    Xmin,Xmax: (0, 16.51)
    Ymin,Ymax: (-5.66214, 5.66214)
    Zmin,Zmax: (23.3312, 36.195)
  Compute Time: 431
  Number Of Points: 47025
  Point Coordinates: 0000012714711730
  Locator: 0000000000000000
  Dimensions: (57, 33, 25)
  Extent: 0, 56, 0, 32, 0, 24
)




vtkMultiBlockPLOT3DReader (00000127148ABF80)
  Debug: Off
  Modified Time: 101
  Reference Count: 2
  Registered Events: 
    Registered Observers:
      vtkObserver (0000012714C3C080)
        Event: 33
        EventName: ModifiedEvent
        Command: 00000127149B27C0
        Priority: 0
        Tag: 1
  Executive: 000001271488C710
  ErrorCode: No error
  Information: 0000012714D62500
  AbortExecute: Off
  Progress: 1
  Progress Text: (None)
  XYZ File Name: combxyz.bin
  Q File Name: combq.bin
  Function File Name: (none)
  BinaryFile: 1
  HasByteCount: 0
  Gamma: 1.4
  R: 1
  ScalarFunctionNumber: 100
  VectorFunctionNumber: 200
  MultiGrid: 0
  ForceRead: 0
  IBlanking: 0
  ByteOrder: 0
  TwoDimensionalGeometry: off
  Double Precision:0
  Auto Detect Format: 0




vtkPointData (0000012712511380)
  Debug: Off
  Modified Time: 413
  Reference Count: 2
  Registered Events: 
    Registered Observers:
      vtkObserver (0000012714C3CC20)
        Event: 33
        EventName: ModifiedEvent
        Command: 00000127149B29C0
        Priority: 0
        Tag: 6
      vtkObserver (0000012714C3CBC0)
        Event: 33
        EventName: ModifiedEvent
        Command: 0000012714D622D0
        Priority: 0
        Tag: 1
  Number Of Arrays: 4
  Array 0 name = Density
  Array 1 name = Momentum
  Array 2 name = StagnationEnergy
  Array 3 name = Velocity
  Number Of Components: 8
  Number Of Tuples: 47025
  Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
  Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
  Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
  Scalars: 
    Debug: Off
    Modified Time: 392
    Reference Count: 1
    Registered Events: 
      Registered Observers:
        (none)
    Name: Density
    Data type: float
    Size: 47025
    MaxId: 47024
    NumberOfComponents: 1
    Information: 0000000000000000
    Name: Density
    Number Of Components: 1
    Number Of Tuples: 47025
    Size: 47025
    MaxId: 47024
    LookupTable: (none)
  Vectors: 
    Debug: Off
    Modified Time: 409
    Reference Count: 1
    Registered Events: 
      Registered Observers:
        (none)
    Name: Velocity
    Data type: float
    Size: 141075
    MaxId: 141074
    NumberOfComponents: 3
    Information: 0000000000000000
    Name: Velocity
    Number Of Components: 3
    Number Of Tuples: 47025
    Size: 141075
    MaxId: 141074
    LookupTable: (none)
  Normals: (none)
  TCoords: (none)
  Tensors: (none)
  GlobalIds: (none)
  PedigreeIds: (none)
  EdgeFlag: (none)


In [7]:

from tvtk.tools import tvtk_doc
In [9]:

tvtk_doc.main()
In [16]:

#标量数据可视化
con=tvtk.ContourFilter()
con.set_input_data(grid)
con.generate_values(20,grid.point_data.scalars.range)
con.set_value(0,0.3)#将第0个等值面设为0.3
In [86]:

from ivtk_func import*
m=tvtk.PolyDataMapper(scalar_range=grid.point_data.scalars.range,input_connection=con.output_port)
a=tvtk.Actor(mapper=m)
#a.property.opacity=0.5
win=ivtk_scene(a)
#win.scene.isometric_view()
event_loop()
In [41]:

#矢量数据可视化
mask=tvtk.MaskPoints(random_mode=True,on_ratio=50)#表示每50个点选一个点
mask.set_input_data(grid)#采样后的数据集
​
glyph_source=tvtk.ConeSource()#表示箭头的PolyData 数据集
In [73]:

glyph=tvtk.Glyph3D(input_connection=mask.output_port,scale_factor=2)
#Glyph3D对象 scale_factor 符号的共同放缩系数
glyph.set_source_connection(glyph_source.output_port)
#设置那个箭头&或者圆锥的方法
m=tvtk.PolyDataMapper(input_connection=glyph.output_port,scalar_range=grid.point_data.scalars.range)
​
a=tvtk.Actor(mapper=m)
​
mout=m.output_port
In [43]:

print(type(glyph.output_port))
print(type(glyph_source))
<class 'tvtk.tvtk_classes.algorithm_output.AlgorithmOutput'>
<class 'tvtk.tvtk_classes.cone_source.ConeSource'>
In [46]:

win.scene.isometric_view()
from ivtk_func import*
win=ivtk_scene(a)
win.scene.isometric_view()
event_loop()
In [47]:

#计算轮廓图的方法如下
from tvtk.common import configure_input
#计算轮廓图的方法如下
from tvtk.common import configure_input
In [114]:

outline=tvtk.StructuredGridOutlineFilter()
configure_input(outline,grid)#计算外边框的PolyData对象
m=tvtk.PolyDataMapper(input_connection=con.output_port,scalar_range=grid.point_data.scalars.range)
m.add_input_connection(glyph.output_port)
#m2=tvtk.PolyDataMapper(input_connection=outline.output_port,scalar_range=grid.point_data.scalars.range)
#m2.set_input_connection(glyph.output_port)
m.update_information()
​
a=tvtk.Actor(mapper=m2)
#a.add_mapper()
 
ivtk_scene(a)
win.scene.isometric_view()
event_loop()
In [97]:

from tvtk.tools import tvtk_doc
tvtk_doc.main()
from tvtk.tools import tvtk_doc
tvtk_doc.main()