Matlab处理数据导出Paraview可读的vtk文件(一)

Paraview是一个开源的可视化软件。

用到matlab子程序从这里下载

或者到博客末尾复制粘贴

子程序名为 vtkwrite

示例1:

1 load mri  
2 D = squeeze(D);  
3 vtkwrite('mri.vtk', 'structured_points', 'mri', D) 

 

 

示例2:云图

1 load wind   
2 [cu,cv,cw] = curl(x, y, z, u, v, w);       
3 div = divergence(x, y, z, u, v, w);     
4 vtkwrite('wind.vtk', 'structured_grid', x, y, z, ...   
5 'vectors', 'vector_field', u, v, w, 'vectors', 'vorticity', cu, cv, cw, 'scalars', 'divergence', div);

示例3:二维曲线

1 x = 1:100; 
2 y = sin(x); 
3 z = sqrt(x);     
4 vtkwrite('execute','polydata','lines',x,y,z); 

示例4:三角形

1 [x,y,z] = peaks(100);     
2 z = .4*z;     
3 tri = delaunay(x,y);     
4 vtkwrite('peaks.vtk','polydata','triangle',x,y,z,tri); 

 

 示例5:四面体

1 d = [-1 1];     
2 [x, y, z] = meshgrid(d, d, d);     
3 DT = delaunayTriangulation(x(:), y(:), z(:));     
4 vtkwrite('execute', 'polydata','tetrahedron', x, y, z, DT.ConnectivityList);  

 

 

vtkwrite

  1 function vtkwrite( filename,dataType,varargin )
  2 % VTKWRITE Writes 3D Matlab array into VTK file format.
  3 %  vtkwrite(filename,'structured_grid',x,y,z,'vectors',title,u,v,w) writes
  4 %  a structured 3D vector data into VTK file, with name specified by the string
  5 %  filename. (u,v,w) are the vector components at the points (x,y,z). x,y,z
  6 %  should be 3-D matrices like those generated by meshgrid, where
  7 %  point(ijk) is specified by x(i,j,k), y(i,j,k) and z(i,j,k).
  8 %  The matrices x,y,z,u,v,w must all be the same size and contain
  9 %  corrresponding position and vector component. The string title specifies
 10 %  the name of the vector field to be saved. 
 11 %
 12 %  vtkwrite(filename,'structured_grid',x,y,z,'scalars',title,r) writes a 3D
 13 %  scalar data into VTK file whose name is specified by the string
 14 %  filename. r is the scalar value at the points (x,y,z). The matrices
 15 %  x,y,z,r must all be the same size and contain the corresponding position
 16 %  and scalar values. 
 17 %
 18 %  vtkwrite(filename,'structured_grid',x,y,z,'vectors',title,u,v,w,'scalars',
 19 %  title2,r) writes a 3D structured grid that contains both vector and scalar values.
 20 %  x,y,z,u,v,w,r must all be the same size and contain the corresponding
 21 %  positon, vector and scalar values.
 22 %
 23 %  vtkwrite(filename, 'structured_points', title, m) saves matrix m (could
 24 %  be 1D, 2D or 3D array) into vtk as structured points.
 25 %
 26 %  vtkwrite(filename, 'structured_points', title, m, 'spacing', sx, sy, sz)
 27 %  allows user to specify spacing. (default: 1, 1, 1). This is the aspect
 28 %  ratio of a single voxel. 
 29 %
 30 %  vtkwrite(filename, 'structured_points', title, m, 'origin', ox, oy, oz)
 31 %  allows user to speicify origin of dataset. (default: 0, 0, 0).
 32 %
 33 %  vtkwrite(filename,'unstructured_grid',x,y,z,'vectors',title,u,v,w,'scalars',
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值