| 7 | == Example == |
| 8 | |
| 9 | The following matlab script will prompt for a file, import the data, and plot the surface in matlab using the default colormap |
| 10 | {{{ |
| 11 | [filename,pathname]=uigetfile('*.vtk','Please select a file','*.vtk') |
| 12 | data=read2DScalarVTK([pathname,filename]) |
| 13 | patch(data,'LineStyle','None','FaceColor','flat') |
| 14 | }}} |
| 15 | |
| 16 | == Line integral convolution == |
| 17 | You can also use velocity data to do line integral convolution |
| 18 | |
| 19 | |
| 20 | {{{ |
| 21 | % Fix these to point to the LIC toolbox and update the pathname to your rho.vtk, vx.vtk, and vz.vtk files |
| 22 | addpath('T:\Documents and Settings\jcarroll\My Documents\MATLAB\LIC\toolbox_image\') |
| 23 | addpath('T:\Documents and Settings\jcarroll\My Documents\MATLAB\LIC\toolbox_image\toolbox\') |
| 24 | pathname='Y:\visualizations\iigu\2\data\'; |
| 25 | |
| 26 | %% Read in rho.vtk, vx.vtk, and vz.vtk (since my slice was in the y direction) |
| 27 | N=512; %resolution of lic image |
| 28 | |
| 29 | filename='rho.vtk'; |
| 30 | data=read2DScalarVTK([pathname,filename]) |
| 31 | [xx,yy]=generatemesh(data,N); %We are going to use the same mesh for all regridding all of the data |
| 32 | rho=regridmesh(data,xx,yy); |
| 33 | |
| 34 | filename='vx.vtk'; |
| 35 | data=read2DScalarVTK([pathname,filename]); |
| 36 | vx=regridmesh(data,xx,yy); |
| 37 | |
| 38 | filename='vz.vtk'; |
| 39 | data=read2DScalarVTK([pathname,filename]); |
| 40 | vz=regridmesh(data,xx,yy); |
| 41 | |
| 42 | %% Normalize velocities since this is expected by LIC routine |
| 43 | maxnorm=sqrt(max(max(vx.^2+vz.^2))); |
| 44 | vx=vx/maxnorm; |
| 45 | vz=vz/maxnorm; |
| 46 | |
| 47 | %% Set the options and perform the line integral convolution |
| 48 | options.histogram = 'linear'; |
| 49 | options.verb = 0; |
| 50 | options.dt = .5; % time stepping for LIC |
| 51 | options.flow_correction = 1; |
| 52 | options.niter_lic = 10; % several iterations gives better results |
| 53 | options.M0=randn(N); %mask for noise |
| 54 | z=zeros(N,N,2); |
| 55 | z(:,:,1)=vz; |
| 56 | z(:,:,2)=vx; |
| 57 | result=perform_lic(z,10,options); |
| 58 | imageplot(result) |
| 59 | |
| 60 | %% Now we can use the noise mask generated from LIC on the velocity data, to adjust the brightness of a false color image of the density |
| 61 | f=.8; %Brightening factor - so that you can still see color through black/white noise |
| 62 | rho_min=min(min(rho)) %get lower bound |
| 63 | rho_max=max(max(rho)) %get upper bound |
| 64 | cmap=colormap('hsv'); |
| 65 | cmap=cmap(1:200,:); %restrict colormap to first 200 entries instead of 256 to avoid circling back around to red |
| 66 | cdata=interp1(linspace(log(rho_min),log(rho_max),size(cmap,1)), double(cmap), log(rho(:))); %get cdata from scalar field using log scaling |
| 67 | cdata=reshape(cdata,[N,N,3]).*repmat((1-f)+f*result,[1,1,3]); %multiply by mask |
| 68 | image(cdata) %draw image |
| 69 | }}} |