matlab: add logarithmic option to VTK export

pull/2/head
Stefan Mahr 2013-05-29 14:05:46 +02:00
parent 8698f7a448
commit 8e8351d038
6 changed files with 50 additions and 14 deletions

View File

@ -1,10 +1,28 @@
function DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale) function DumpFF2VTK2(filename, farfield, thetaRange, phiRange, varargin)
% DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale) % DumpFF2VTK(filename, farfield, thetaRange, phiRange, varargin)
% %
% Dump 3D far field pattern to a vtk file % Dump 3D far field pattern to a vtk file
% %
% input:
% filename: filename of VTK file, existing file will be overwritten
% farfield: farfield in V/m
% thetaRange: theta range in deg
% phiRange: phi range in deg
%
% variable input:
% 'scale': - linear scale of plot, doesn't affect gain values
% 'logscale': - if set, show farfield with logarithmic scale
% - set the dB value for point of origin
% - values below will be clamped
% 'maxgain': - add max gain in dB to normalized farfield
% - only valid if logscale is set
% - default is 0dB
%
% example: % example:
% see examples/NF2FF/infDipol.m % DumpFF2VTK(filename, farfield, thetaRange, phiRange, ...
% 'scale', 2, 'logscale', -20, 'maxgain', 3)
%
% see also examples/NF2FF/infDipol.m
% %
% See also CreateNF2FFBox, AnalyzeNF2FF % See also CreateNF2FFBox, AnalyzeNF2FF
% %
@ -13,8 +31,27 @@ function DumpFF2VTK(filename, farfield, thetaRange, phiRange, scale)
% author: Thorsten Liebig % author: Thorsten Liebig
if (nargin<5) % defaults
scale = 1; scale = 1;
maxgain = 0;
logscale = [];
for n=1:2:numel(varargin)
if (strcmp(varargin{n},'maxgain')==1);
maxgain = varargin{n+1};
elseif (strcmp(varargin{n},'logscale')==1);
logscale = varargin{n+1};
elseif (strcmp(varargin{n},'scale')==1);
scale = varargin{n+1};
end
end
if ~isempty(logscale)
farfield = 20*log10(farfield) + maxgain;
ind = find(farfield<0);
farfield(ind)=0;
else
maxgain = 0; % force 0 for linear plot
end end
t = thetaRange*pi/180; t = thetaRange*pi/180;
@ -63,6 +100,5 @@ fprintf(fid,'POINT_DATA %d\n',numel(t)*numel(a));
fprintf(fid,['SCALARS gain double 1\nLOOKUP_TABLE default\n']); fprintf(fid,['SCALARS gain double 1\nLOOKUP_TABLE default\n']);
fclose(fid); fclose(fid);
dumpField = farfield(:); dumpField = farfield(:) + maxgain;
save('-ascii','-append',filename,'dumpField') save('-ascii','-append',filename,'dumpField')

View File

@ -164,6 +164,6 @@ drawnow
disp( 'dumping 3D far field pattern to vtk, use Paraview to visualize...' ); disp( 'dumping 3D far field pattern to vtk, use Paraview to visualize...' );
for n=1:numel(f_rad) for n=1:numel(f_rad)
E_far_normalized_3D = nf2ff.E_norm{n} / max(max(nf2ff.E_norm{n})) * nf2ff.Dmax(n); E_far_normalized_3D = nf2ff.E_norm{n} / max(max(nf2ff.E_norm{n})) * nf2ff.Dmax(n);
DumpFF2VTK( [Sim_Path '/FF_Pattern_' int2str(f_rad(n)/1e6) 'MHz.vtk'],E_far_normalized_3D,theta,phi,1e-3); DumpFF2VTK( [Sim_Path '/FF_Pattern_' int2str(f_rad(n)/1e6) 'MHz.vtk'],E_far_normalized_3D,theta,phi,'scale',1e-3);
end end

View File

@ -194,4 +194,4 @@ ylabel( 'y' );
zlabel( 'z' ); zlabel( 'z' );
%% %%
DumpFF2VTK([Sim_Path '/Conical_Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,1e-3); DumpFF2VTK([Sim_Path '/Conical_Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);

View File

@ -197,7 +197,7 @@ plot(thetaRange, 10*log10(directivity_CPLH(:,1)'),'r-.','LineWidth',2);
legend('norm','CPRH','CPLH'); legend('norm','CPRH','CPLH');
%% dump to vtk %% dump to vtk
DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],directivity,thetaRange,phiRange,1e-3); DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],directivity,thetaRange,phiRange,'scale',1e-3);
DumpFF2VTK([Sim_Path '/3D_Pattern_CPRH.vtk'],directivity_CPRH,thetaRange,phiRange,1e-3); DumpFF2VTK([Sim_Path '/3D_Pattern_CPRH.vtk'],directivity_CPRH,thetaRange,phiRange,'scale',1e-3);
DumpFF2VTK([Sim_Path '/3D_Pattern_CPLH.vtk'],directivity_CPLH,thetaRange,phiRange,1e-3); DumpFF2VTK([Sim_Path '/3D_Pattern_CPLH.vtk'],directivity_CPLH,thetaRange,phiRange,'scale',1e-3);

View File

@ -213,4 +213,4 @@ ylabel( 'y' );
zlabel( 'z' ); zlabel( 'z' );
%% %%
DumpFF2VTK([Sim_Path '/Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,1e-3); DumpFF2VTK([Sim_Path '/Horn_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);

View File

@ -175,4 +175,4 @@ phiRange = (0:2:360) - 180;
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180,'Verbose',1,'Outfile','3D_Pattern.h5'); nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180,'Verbose',1,'Outfile','3D_Pattern.h5');
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax; E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,1e-3); DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,'scale',1e-3);