Generating VTK files with Python
Paraview
is an industrial-strength, open-source 3D visualization program designed to visualize large data sets created by computational fluid dynamics (CFD) simulations. Although its native data file format (.vtu) is designed for reading in point- and cell-based data from CFD simulations, I have successfully used it to read in and visualized discrete particle data from a Brownian Dynamics (BD) simulation. Below, you can download a Python class that is useful for visualizing particles in motion. It should be easily adaptable to any type of discrete data set that involves discrete objects, vectors, and/or scalars. In addition, this class should be useful with any application based on the
VTK toolkit
because they also read .vtu files.
The Python .vtu Generator
This is the first release of a Python class that writes serial, unstructured VTK files (.vtu) in XML format. Even if your application is very different, I think this class will be useful as an example of how to write valid VTK files in the new XML format.
Download the class definition at GitHub
.
The class is used as follows. Brownian Dynamics is a method of simulating the motion of colloidal particles in a liquid. I need to visualize the particles–where they are, where they’ve been, and what forces are acting upon them. First, I create an object (let’s call it vtk_writer). Every time I need to see what’s going on in the simulation (perhaps every 5 time steps), I call the method vtk_writer.snapshot(filename, x, y, z, …) to write out a .vtu file. The object keeps track of every .vtu file that has been written. At the end of my simulation, I call vtk_writer.writePVD(filename) which writes out a .pvd file that contains all the filenames of the .vtu files. Using Paraview, open the .pvd file, and all the .vtu files will automatically be loaded.
Reference:
VTK file format documentation
Reading XML Data into Paraview
Even if you have completed all the steps correctly so far, you will see
nothing
in Paraview! In order to visualize something, you use a “filter.” Select your .pvd file in the Pipeline Browser, and choose Glyph from the Filter menu, or the toolbar. In the Object Inspector, choose
Sphere
for the Glyph Type. Set Radius to 1, Scale Mode to Scalar, and set the Scale Factor to 1. Assuming you put radii into the .vtu files, you should now have scale spheres. However, you may not be able to see them, so click on the Display tab and click the “Zoom to Data” button. Now you should see your spheres! If you have saved forces in the .vtu file, add an Arrow glyph and choose “Forces” from the “Vectors” drop-down. Now you will see the force being exerted on each sphere. Finally, create a box from the “Sources” menu and set the appropriate dimensions for your simulation area.
Creating Movies from Paraview
From the File menu, choose “Save Animation”, choose a directory, and enter a filename. Paraview will generate a .jpg image for every frame of your animation. You then need to use a third-party tool to turn the images into a movie. You can do it with ImageMagick, but I don’t recommend it if you have more than a few hundred frames. Imagemagick loads every image into RAM before creating the movie. A better way is to install
mplayer
(use the “encode” USE flag on the Gentoo ebuild). Then you can use the command line tool “
mencoder
” to create the movie much more efficiently. I had some trouble getting Windows Media Player 11 to play the movies created with mencoder. I used the following command line to create Windows-compatible mpeg movies:
mencoder "mf://*.jpg" -of rawvideo -mpegopts format=mpeg1:tsaf:muxrate=2000 -o output.mpg
-oac lavc -lavcopts acodec=mp2:abitrate=224 -ovc lavc
-lavcopts vcodec=mpeg2video:vbitrate=1152:keyint=15:mbd=2:aspect=4/3
Reference:
creating movies with Imagemagick
From http://meywang.wordpress.com/接着徐辉的帖子。这几天与徐辉、张伟讨论了PalaBos下sparse block的流场数据输出,把目前考虑的东西整理一下。1. VTK XML格式 VTK格式参见官方文档(http://www.vtk.org/VTK/img/file-formats.pdf)。
ParaView
是对二维和三维数据进行分析和可视化的程序,它既是一个应用程序框架,也可以直接使用(Turn-Key)。
ParaView
支持并行,可以运行于单处理器的工作站,也可以运行于分布式存储器的大型计算机。
ParaView
用C++编写,基于VTK(Visualization ToolKit)开发,图形用户界面用Qt开发,开源、跨平台。
ParaView
是一个开源的,跨平台的数据处理和可视化程序。
ParaView
用户可以迅速的建立起可视化环境利用定量或者是定性的手段去分析数据。利用它的批量处理能力可以在三维或者是在报表中交互进行“数据挖掘”(这里不知道翻译的对不对)。
ParaView
开发使用分布式的内存计算资源来对非常大的数据集进行分析。它可以在超级计算机上运行万亿次的数据集以及笔记本电脑更小的数据分析。
Vtu11
Vtu11是一个小的C ++仅标头库,用于使用vtu文件格式编写非结构化网格。它避免了处理不同格式文件的麻烦。当前,它不添加任何用于设置所需数据结构的功能,因为这在使用vtu11的上下文中有很大差异。
# include " vtu11/vtu11.hpp "
int main ( )
// Create data for 3x2 quad mesh: (x, y, z) coordinates of mesh vertices
std::vector< double> points
0.0 , 0.0 , 0.5 , 0.0 , 0.3 , 0.5 , 0.0 , 0.7 , 0.5 , 0.0 , 1.0 , 0.5 , // 0, 1, 2, 3
0.5 , 0.0 ,
paraView
做
动画
(终极教程)
前几天有网友问怎么将计算结果输出成
动画
,我想可以分以下几个步骤
1)计算结果case文件夹中,输入paraFoam打开后处理软件
paraview
,并作后处理作出你想要的效果。关于
paraview
怎么用?我以前在QQ爱好者群2中发过那个guide,看看就行了,不是很难。
2)作出想要的效果后,点击file菜单下的save animation 按钮,将每一针都输出成...
在2.11节中,我们已经了解了如何使数据集具有时间
动画
(点击 )和其它操纵时态数据的方法。但是,
ParaView
的
动画
功能远不止这些。使用
ParaView
,几乎可以设置任何管线对象的任何属性的
动画
。
练习2.32:设置属性
动画
我们将开始一个新的可视化,从工具栏选择 重置
ParaView
。
1.使用快速搜索框(ctrl+space Win/Linux,alt+space Mac)创建球体源,然后点击 。
2.如果
动画
视图不可见,点击View—>Animation View打开
动画
视图。
主要采用vtkXMLUnstructuredGridReader()类读取非结构化网格结构的vtk XML格式的文件。
#include vtkXMLUnstructuredGridReader.h>
#include vtkSmartPointer.h>
#include vtkDataSetMapper.h>
#include vtkActor.h>
#include vtkRenderWi
任何可视化最重要的输出之一是屏幕截图和可用于演示和报告的
动画
。在本节中,我们将保存屏幕截图(图片)和
动画
(电影)。我们将再次使用can.ex2数据集。
练习2.25:保存屏幕截图
我们将开始一个新的可视化,从工具栏选择 重置
ParaView
。
1.打开文件can.ex2,加载所有变量, 。
2.按下 按钮。
3.用GlobalNodeId变量上色。
4.选择File—>Save Screenshot 。
这将进入文件选择屏幕。如果你查看对话框底部的“Files of type”菜单,
因此我研究了一下
paraview
的基本用法,分享出来。
软件版本and安装
从
paraView
官网https://www.
paraview
.org/download/上下载需要的版本,由于本人仅仅是需要很小的功能,所以以免安装版本为例子
ParaView
-5.5.0-Qt5-Windows-64bit.zip”。
Paraview
是一种开源的可视化软件,可用于处理和分析大规模数据。在实际应用中,往往需要对大量的数据进行处理,这时使用手动操作就非常繁琐。因此,使用
Paraview
批处理,可以自动化地进行数据处理,提高效率。
Paraview
批处理可以通过Python脚本实现。首先,需要编写一个Python脚本,包括将要处理的数据的文件路径、处理方式、保存路径等信息。然后,通过在终端或命令行中运行脚本,即可对数据进行批量处理。
在
Paraview
中,可以通过Python programmable filter功能,实现数据处理的自动化。具体方法是,编写一个Python脚本,通过该脚本实现数据处理的具体操作,然后在
Paraview
中添加一个Python programmable filter并将该脚本导入其中。运行之后,
Paraview
将自动执行数据处理操作,并输出处理结果。
同时,
Paraview
还可以通过Python programmable source功能,实现数据的自动生成。具体方法是,编写一个Python脚本,通过该脚本实现数据的生成,并在
Paraview
中添加一个Python programmable source将该脚本导入其中。运行之后,
Paraview
将自动根据脚本生成数据,并进行后续处理。
总之,
Paraview
批处理可以实现自动化地对大规模数据进行处理,提高效率和准确性,具有广泛的应用前景。