0001 function hh= eidors_colourbar(max_scale,ref_lev, cb_shrink_move, greyscale)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 if ischar(max_scale) && strcmp(max_scale,'UNIT_TEST'); do_unit_test; return; end
0044
0045
0046 if isstruct(max_scale) && strcmp(max_scale.type,'image')
0047
0048
0049
0050 img = max_scale;
0051 pp=get_colours( img );
0052 img_data= get_img_data( img );
0053 [scl_data, ref_lev, max_scale] = scale_for_display( img_data(:), pp);
0054 try if strcmp(pp.component,'imag');
0055 ref_lev = imag(ref_lev);
0056 end; end
0057 ref_lev = real(ref_lev);
0058 end
0059
0060 hh= colorbar;
0061 drawnow
0062
0063 cbsm = [];
0064 try; cbsm = img.calc_colours.cb_shrink_move;
0065 end;
0066
0067 if nargin >= 3; cbsm = cb_shrink_move;
0068 end
0069
0070 axpos = get(gca,'Position');
0071 if ~isempty(cbsm)
0072 do_cb_shrink_move( hh, cbsm );
0073 end
0074
0075
0076 if nargin <4;
0077 greyscale=[];
0078 else
0079 warning(['eidors_colourbar: greyscale is an experimental feature'...
0080 'and will be re-implemented']);
0081 end
0082
0083
0084 if max_scale<abs(ref_lev)
0085 if max_scale < 1e-10; max_scale = 1e-10; end
0086 else
0087 if max_scale/abs(ref_lev) < 1e-4; max_scale = ref_lev*1e-4; end
0088 end
0089
0090
0091 ylim = get(hh,'Ylim');
0092 cmsz = size(colormap,1);
0093 cbsz = ylim(2) - ylim(1);
0094 unit = cbsz/cmsz;
0095 ylim(1)= ylim(1)+unit;
0096
0097 if ~isempty(greyscale); ylim(1) = ylim(1) + unit ; end
0098 set(hh,'Ylim',ylim);
0099
0100 c_ctr = mean(ylim);
0101 c_max = ylim(2) - c_ctr;
0102
0103
0104 try
0105 tick_vals = img.eidors_colourbar.tick_vals;
0106 catch
0107 try
0108 tick_div = img.eidors_colourbar.tick_divisions;
0109 catch
0110 tick_div = [];
0111 end
0112 tick_vals= get_tick_vals(max_scale, ref_lev, greyscale, tick_div);
0113 end
0114
0115
0116
0117 tick_locs = (tick_vals - ref_lev)/max_scale * c_max + c_ctr;
0118 if isempty(greyscale)
0119 tick_locs = (tick_vals - ref_lev)/max_scale * c_max + c_ctr;
0120 else
0121 tick_locs = tick_vals*c_max*2/max_scale +2.5;
0122 end
0123
0124 tick_locs(abs(tick_locs-ylim(1))<eps) = ylim(1);
0125 tick_locs(abs(tick_locs-ylim(2))<eps) = ylim(2);
0126
0127 set(hh,'YTick', tick_locs');
0128 set(hh,'YTickLabel', tick_vals');
0129
0130 if 0
0131 lab = get(hh,'YTickLabel');
0132 for i=1:size(lab,1);
0133 nsp = sum(lab(i,:)==' ');
0134 lab(i,:) = lab(i,[end-(nsp-1:-1:0),1:(end-nsp)]);
0135 end
0136 set(hh,'YTickLabel',lab);
0137 end
0138
0139 if ~isempty(cbsm)
0140 if ~all(cbsm == [1,1,0]);
0141 set(gca,'position',axpos);
0142 end
0143 end
0144
0145
0146 if nargout ==0; clear hh; end
0147
0148 end
0149
0150 function do_cb_shrink_move( hh, cbsm )
0151
0152
0153 axpos = get(gca,'Position');
0154 posn= get(hh,'Position');
0155 if ~all(cbsm == [1,1,0]);
0156 posn = [posn(1) - cbsm(3), posn(2) + posn(4)*(1-cbsm(2))/2, ...
0157 posn(3) * cbsm(1), posn(4) * cbsm(2)];
0158 set(hh,'Position', posn );
0159 set(gca,'Position',axpos);
0160 end
0161
0162 end
0163
0164
0165
0166
0167
0168 function pp=get_colours( img );
0169 global eidors_colours;
0170 pp= eidors_colours;
0171
0172 pp.component = 'real';
0173
0174
0175 try
0176
0177 fds= fieldnames(img(1).calc_colours);
0178 for fdn= fds(:)';
0179 fdn= fdn{1};
0180 pp.( fdn ) = img(1).calc_colours.(fdn);
0181 end
0182 end
0183 end
0184
0185 function tick_vals= get_tick_vals(max_scale, ref_lev, greyscale, tick_div_in)
0186
0187
0188 F= 2;
0189 OrdOfMag = 10^floor(log10(max_scale*F))/F;
0190
0191 scale1 = floor( max_scale / OrdOfMag + 2*eps );
0192
0193 if (scale1/F >= 8); fms = F*8; tick_div=2;
0194 elseif (scale1/F >= 6); fms = F*6; tick_div=2;
0195 elseif (scale1/F >= 4); fms = F*4; tick_div=2;
0196 elseif (scale1/F >= 3); fms = F*3; tick_div=3;
0197 elseif (scale1/F >= 2); fms = F*2; tick_div=2;
0198 elseif (scale1/F >= 1.5);fms = F*1.5; tick_div=3;
0199 elseif (scale1/F >= 1); fms = F*1; tick_div=2;
0200 else (scale1/F >= 0.5);fms = F*0.5; tick_div=2;
0201 end
0202
0203 if ~isempty(tick_div_in); tick_div = tick_div_in; end
0204
0205
0206
0207
0208 scale_r = OrdOfMag * fms;
0209
0210
0211 OrdOfMag = 10^floor(log10(max_scale));
0212 ref_r = OrdOfMag * round( ref_lev / OrdOfMag );
0213
0214
0215 if isempty(greyscale)
0216
0217 tick_vals = linspace(-2,2,tick_div*4+1)*scale_r + ref_r;
0218 else
0219
0220 tick_vals = [0:0.2:1]*scale_r;
0221 end
0222 end
0223
0224
0225 function debug_code
0226 a = get(hh);
0227 set(hh,'Position', posn );
0228 a = rmfield(a,'CurrentPoint');
0229 a = rmfield(a,'TightInset');
0230 a = rmfield(a,'BeingDeleted');
0231 a = rmfield(a,'Type');
0232 a.Position = posn;
0233 set(hh,a);
0234 op = get(hh,'OuterPosition')
0235 set(hh,'Position', posn );
0236 op1= get(hh,'OuterPosition')
0237 set(hh,'OuterPosition',op);
0238 op2= get(hh,'OuterPosition')
0239 set(gca,'Position',axpos);
0240 end
0241
0242 function do_unit_test
0243 imgno = 1;
0244 imdl = mk_common_model('n3r2',[16,2]);
0245 img = mk_image(imdl);
0246 img=rmfield(img,'elem_data');
0247 img.node_data(1:252)= (0:251)/100 - 1.05;
0248 if 0
0249 fprintf('CMAX = %4.2f CMIN = %4.2f\n', ...
0250 max(img.node_data), min(img.node_data) );
0251 end
0252
0253
0254 subplot(3,3,imgno); imgno=imgno+1;
0255 show_slices(img,2); eidors_colourbar(img);
0256
0257
0258 img.calc_colours.ref_level = -0.0234;
0259 subplot(3,3,imgno); imgno=imgno+1;
0260 img2= img;
0261 img2.eidors_colourbar.tick_divisions = 4;
0262 show_slices(img2,2); eidors_colourbar(img2);
0263
0264 img.calc_colours.cmax = 1;
0265 subplot(3,3,imgno); imgno=imgno+1;
0266 img2= img;
0267 img2.eidors_colourbar.tick_vals = [-10:10]/5;
0268 show_slices(img2,2); eidors_colourbar(img2);
0269
0270 MV =-0.05;
0271 img.calc_colours.cb_shrink_move = [.5,.8,MV];
0272 subplot(3,3,imgno); imgno=imgno+1;
0273 show_slices(img,2);
0274 eidors_colourbar(img);
0275
0276 subplot(3,3,imgno); imgno=imgno+1;
0277 show_fem(img,1);
0278
0279 subplot(3,3,imgno); imgno=imgno+1;
0280 show_slices(img,2);
0281 p = get(gca,'position');
0282 eidors_colourbar(img);
0283 set(gca,'position',p);
0284
0285 show_slices(img,2);
0286 eidors_colourbar(img);
0287
0288 subplot(3,3,imgno); imgno=imgno+1;
0289 img.node_data = 26e1*abs(img.node_data);
0290 show_slices(img,2);
0291 eidors_colourbar(img);
0292
0293 subplot(3,3,imgno); imgno=imgno+1;
0294 img.node_data(1:252)= abs( (0:251)/100 - 1.05 );
0295 show_slices(img,2);
0296 eidors_colourbar(img);
0297
0298
0299 subplot(3,3,imgno); imgno=imgno+1;
0300 img.calc_colours.ref_level = 0.5;
0301 img.calc_colours.clim = 0.5;
0302 show_slices(img,2);
0303 eidors_colourbar(img);
0304
0305 end