From 194e457bc6c6b5238ef2c8d1598506f0ea4f250f Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Fri, 27 Aug 2021 17:40:03 -0400 Subject: [PATCH] add quality and zmin parameter to improve elapsed time working with steamtube function --- plotly/plotly_aux/plotly.m | 2 +- plotly/plotlyfig.m | 8 ++ .../handlegraphics/updateStreamtube.m | 100 +++++++++++++++--- 3 files changed, 94 insertions(+), 16 deletions(-) diff --git a/plotly/plotly_aux/plotly.m b/plotly/plotly_aux/plotly.m index 3a977f00..cf16bf76 100644 --- a/plotly/plotly_aux/plotly.m +++ b/plotly/plotly_aux/plotly.m @@ -10,7 +10,7 @@ % % For full documentation and examples, see https://plot.ly/api origin = 'plot'; -offline = true; +offline = false; struct_provided = false; if isstruct(varargin{end}) diff --git a/plotly/plotlyfig.m b/plotly/plotlyfig.m index 7ab2c173..432f1230 100644 --- a/plotly/plotlyfig.m +++ b/plotly/plotlyfig.m @@ -57,6 +57,8 @@ obj.PlotOptions.AspectRatio = []; obj.PlotOptions.CameraEye = []; obj.PlotOptions.is_headmap_axis = false; + obj.PlotOptions.Quality = -1; + obj.PlotOptions.Zmin = []; % offline options obj.PlotOptions.Offline = true; @@ -224,6 +226,12 @@ if(strcmpi(varargin{a},'CameraEye')) obj.PlotOptions.CameraEye = varargin{a+1}; end + if(strcmpi(varargin{a},'Quality')) + obj.PlotOptions.Quality = varargin{a+1}; + end + if(strcmpi(varargin{a},'Zmin')) + obj.PlotOptions.Zmin = varargin{a+1}; + end end end diff --git a/plotly/plotlyfig_aux/handlegraphics/updateStreamtube.m b/plotly/plotlyfig_aux/handlegraphics/updateStreamtube.m index f19ab522..fe26cc10 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateStreamtube.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateStreamtube.m @@ -1,7 +1,7 @@ function obj = updateStreamtube(obj, surfaceIndex) -if strcmpi(obj.State.Plot(surfaceIndex).Class, 'surface') + if strcmpi(obj.State.Plot(surfaceIndex).Class, 'surface') updateSurfaceStreamtube(obj, surfaceIndex) -end + end end function updateSurfaceStreamtube(obj, surfaceIndex) @@ -38,28 +38,45 @@ function updateSurfaceStreamtube(obj, surfaceIndex) %---------------------------------------------------------------------% -%-format x an y data-% -ymax = 100; +%-getting plot data-% x = image_data.XData; y = image_data.YData; z = image_data.ZData; cdata = image_data.CData; -ysize = size(x,1); -xsize = size(x,2); +%-playing with level quality-% +quality = obj.PlotOptions.Quality/100; +apply_quality = quality > 0; -if ysize > ymax - ystep = round(ysize/ymax); - x = x(1:ystep:end, :); - y = y(1:ystep:end, :); - z = z(1:ystep:end, :); - cdata = cdata(1:ystep:end, :); -end +if apply_quality + x = imresize(x, quality); + y = imresize(y, quality); + z = imresize(z, quality); + cdata = imresize(cdata, quality); +end -if isvector(x) - [x, y] = meshgrid(x,y); +if ~isempty(obj.PlotOptions.Zmin) + if any(z < obj.PlotOptions.Zmin) + return; + end end +xymax = 100; +xsize = size(x,2); +ysize = size(x,1); + +xsize = min([xsize, xymax]); +ysize = min([ysize, xymax]); +x = imresize(x, [ysize, xsize]); +y = imresize(y, [ysize, xsize]); +z = imresize(z, [ysize, xsize]); +cdata = imresize(cdata, [ysize, xsize]); + +%-optional-% +% if isvector(x) +% [x, y] = meshgrid(x,y); +% end + %---------------------------------------------------------------------% %-surface x-% @@ -105,6 +122,59 @@ function updateSurfaceStreamtube(obj, surfaceIndex) obj.data{surfaceIndex}.contours.y.show = true; obj.data{surfaceIndex}.contours.y.color = 'black'; +%------------------------------------------------------------------------% + +%-get data-% + +%-aspect ratio-% +ar = obj.PlotOptions.AspectRatio; + +if ~isempty(ar) + if ischar(ar) + scene.aspectmode = ar; + elseif isvector(ar) && length(ar) == 3 + xar = ar(1); + yar = ar(2); + zar = ar(3); + end + else + + %-define as default-% + xar = 0.5*max(x(:)); + yar = 0.5*max(y(:)); + zar = 0.4*max([xar, yar]); +end + +scene.aspectratio.x = xar; +scene.aspectratio.y = yar; +scene.aspectratio.z = zar; + +%---------------------------------------------------------------------% + +%-camera eye-% +ey = obj.PlotOptions.CameraEye; + +if ~isempty(ey) +if isvector(ey) && length(ey) == 3 + scene.camera.eye.x = ey(1); + scene.camera.eye.y = ey(2); + scene.camera.eye.z = ey(3); +end +else + +%-define as default-% +fac = 0.35; +xey = - xar; if xey>0 xfac = -fac; else xfac = fac; end +yey = - yar; if yey>0 yfac = -fac; else yfac = fac; end +if zar>0 zfac = fac; else zfac = -fac; end + +scene.camera.eye.x = xey + xfac*xey; +scene.camera.eye.y = yey + yfac*yey; +scene.camera.eye.z = zar + zfac*zar; +end + +obj.layout = setfield(obj.layout,['scene'], scene); + %-------------------------------------------------------------------------% %-image colorscale-%