Python TVTK scalar data visualization and vector data visualization

Source: Internet
Author: User
Tags scalar



Python data visualization is divided into



Scalar visualization, vector visualization, contour line visualization
Scalar is also called no vector, only the size has no direction, the operation follows the algebraic algorithm such as mass, density, temperature, volume, time
Vectors, also known as vectors, are determined by the size and direction of the volume, the operation of the following geometric algorithms, such as speed, acceleration, force, magnetic field strength, electric field strength, etc.



#实例1标量数据可视化
‘‘‘
Use equivalent to face scalar fields for visualization (volume rendering [three-dimensional spatial data field] common means)
Contour: A surface of equal value in a scalar field, similar to a contour in a map
TVTK. Contourfilter equivalent surface filter, used to obtain the contour,
It is a class inherited by Vtkobject<--vtkalogorithm<--vtkpolydataalgorithm.
Two methods
Generate_values () Sets the value of the n contour, which is typically used to redraw the contour line
Set_value () Sets the value of a contour line, which is typically used to override a contour line or to add a new contour line


from tvtk.api import tvtk
from tvtkfunc import ivtk_scene, event_loop
#Read in plot3D data
plot3d = tvtk.MultiBlockPLOT3DReader (
        xyz_file_name = "combxyz.bin", # Grid file
        q_file_name = "combq.bin", # Aerodynamic result file
        scalar_function_number = 100, # Set the number of scalar data
        vector_function_number = 200 # Set the number of vector data
        )
plot3d.update ()
grid = plot3d.output.get_block (0) #Get the read data set
con = tvtk.ContourFilter () # Create isosurface object
con.set_input_data (grid) #Binding the grid to it
#The range is determined by the array Scalars.range, and the color is also determined by scalars
con.generate_values (10, grid.point_data.scalars.range) #Create 10 isosurfaces
#Default mapping table: minimum value is red, maximum value is blue
#Constructing the mapper
m = tvtk.PolyDataMapper (scalar_range = grid.point_data.scalars.range, input_connection = con.output_port)
#Assign a scalar behavior property and set the value range of the newly added array
a = tvtk.Actor (mapper = m)
#Since the ten isosurfaces will be nested with each other, in order to observe the internal structure of the isosurfaces, modify the Actor object transparency to 0.5
a.property.opacity = 0.5
#Draw interactive window
win = ivtk_scene (a)
win.scene.isometric_view ()
event_loop () 


Generate_values is a function that creates a contour, and it can set the value of n contours at the same time.
The color changes after attempting to change the N value in Generate_values. You can use the Set_value method to set the value of each contour, whose first parameter specifies the number of contours, and the second parameter specifies the value of the contour.
The effect is beautiful, and different effects can occur by setting different transparency.






Vector Data Visualization
Use arrows to represent the data of a vector data field,
The size of the arrows can represent scalar information,
The direction of the arrows can represent the direction of the vector data
To place the arrowhead symbol at the grid of the vector data, use the Glyph3d method provided by the TVTK Library
Can produce indented, shaded, and directional symbols
Vtkobject<--vtkalgorithm<--vtkpolydataalgorithm<--vtkgly3d
Reduce the data density by using the dimensionality reduction method
You can use TVTK. Maskpoints () de-sampling the data
Vtkobject<--vtkalgorithm<--vtkpolydataalgorithm<--vtkmaskpoints


from tvtk.api import tvtk
from tvtkfunc import ivtk_scene, event_loop
#Read in plot3D data
plot3d = tvtk.MultiBlockPLOT3DReader (
        xyz_file_name = "combxyz.bin", # Grid file
        q_file_name = "combq.bin", # Aerodynamic result file
        scalar_function_number = 100, # Set the number of scalar data
        vector_function_number = 200 # Set the number of vector data
        )
plot3d.update ()
grid = plot3d.output.get_block (0) #Get the read data set (StructureGrid)
#Randomly select the data in the data set, choose a point every 50 points
mask = tvtk.MaskPoints (random_mode = True, on_ratio = 50) # downsampled the data
#Select a point every 50 points to downsample the data. In order to observe the effect, the effect of output downsampling can be performed in the shell
mask.set_input_data (grid) #Connect grid to musk
#Create PolyData dataset representing arrows
glyph_source = tvtk.ArrowSource () # ArrowSource can be changed to ConeSource () and the arrow becomes a cone, and scale_factor = 2 sets the shrinkage factor
#Place an arrow on each point of the PolyData dataset after Mask sampling
#The direction, length, and color of the arrow are determined by the vector and scalar data corresponding to the point
#In this example, the direction of the arrow indicates the direction of the speed, and the size and color indicate the density
The larger the #arrow, the larger the scalar value at that point. The color table of the arrows indicates the size of the scalar value
#The smaller the scalar value corresponding to red, the larger the scalar value corresponding to blue
glyph = tvtk.Glyph3D (input_connection = mask.output_port, scale_factor = 4) # 4 represents the common scaling factor of the symbol
# tvtk's visualization technology, where each point of the input data is copied with a symbol.
The # symbol itself is used to receive the type data of vtkPolyData through the second input function of Glyph3D's filter
#Then place an arrow on each point via ArrowSource
glyph.set_source_connection (glyph_source.output_port)
m = tvtk.PolyDataMapper (scalar_range = grid.point_data.scalars.range, input_connection = glyph.output_port)
a = tvtk.Actor (mapper = m)
#Interactive window drawing
win = ivtk_scene (a)
win.scene.isometric_view ()
event_loop () 


The operating effect is as follows, it can be said that the simulation version of the Northwest Wind, wow ka ka ka






What is the effect of replacing the cone with the annotated method?






hahaha small cone Meng Meng ~ If I get a little bit more leather for a cube?






Unexpectedly good-looking.



The drop sampling technique is very important, it is impossible to get out at all



You can use TVTK. Maskpoints () de-sampling the data. The shell can be used to see the number of data before the downsampling and the number of data after the drop-sample



It's a lot of difference.






Python TVTK scalar data visualization and vector data visualization


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.