From 4a2aaeff176c10532efdda3020ea999465608604 Mon Sep 17 00:00:00 2001 From: Gilberto Galvis Date: Wed, 15 Sep 2021 18:53:45 -0400 Subject: [PATCH] fix issues and awesome improvements in mesh functionality --- plotly/plotlyfig_aux/core/updateData.m | 4 +- .../plotlyfig_aux/handlegraphics/updateMesh.m | 390 ++++++++++++++++++ .../handlegraphics/updateScatterhistogram.m | 12 +- .../plotlyfig_aux/handlegraphics/updateSurf.m | 294 +++++++++---- 4 files changed, 617 insertions(+), 83 deletions(-) create mode 100644 plotly/plotlyfig_aux/handlegraphics/updateMesh.m diff --git a/plotly/plotlyfig_aux/core/updateData.m b/plotly/plotlyfig_aux/core/updateData.m index 5e8bd670..f27aff46 100644 --- a/plotly/plotlyfig_aux/core/updateData.m +++ b/plotly/plotlyfig_aux/core/updateData.m @@ -30,7 +30,9 @@ elseif strcmpi(obj.PlotOptions.TreatAs, 'surf') updateSurf(obj, dataIndex); elseif strcmpi(obj.PlotOptions.TreatAs, 'fmesh') - updateFmesh(obj, dataIndex); + updateFmesh(obj, dataIndex); + elseif strcmpi(obj.PlotOptions.TreatAs, 'mesh') + updateMesh(obj, dataIndex); % this one will be revomed elseif strcmpi(obj.PlotOptions.TreatAs, 'streamtube') diff --git a/plotly/plotlyfig_aux/handlegraphics/updateMesh.m b/plotly/plotlyfig_aux/handlegraphics/updateMesh.m new file mode 100644 index 00000000..4f1c6ca4 --- /dev/null +++ b/plotly/plotlyfig_aux/handlegraphics/updateMesh.m @@ -0,0 +1,390 @@ +function obj = updateMesh(obj, surfaceIndex) + +%-AXIS INDEX-% +axIndex = obj.getAxisIndex(obj.State.Plot(surfaceIndex).AssociatedAxis); + +%-CHECK FOR MULTIPLE AXES-% +[xsource, ysource] = findSourceAxis(obj,axIndex); + +%-SURFACE DATA STRUCTURE- % +meshData = get(obj.State.Plot(surfaceIndex).Handle); +figureData = get(obj.State.Figure.Handle); + +%-AXIS STRUCTURE-% +axisData = get(ancestor(meshData.Parent,'axes')); + +%-SCENE DATA-% +eval( sprintf('scene = obj.layout.scene%d;', xsource) ); + +%-GET CONTOUR INDEX-% +obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; +contourIndex = obj.PlotOptions.nPlots; +obj.PlotOptions.contourIndex(surfaceIndex) = contourIndex; + +%-------------------------------------------------------------------------% + +%-associate scene-% +obj.data{surfaceIndex}.scene = sprintf('scene%d', xsource); +obj.data{contourIndex}.scene = sprintf('scene%d', xsource); + +%-------------------------------------------------------------------------% + +%-surface type for face color-% +obj.data{surfaceIndex}.type = 'surface'; + +%-scatter3d type for contour mesh lines-% +obj.data{contourIndex}.type = 'scatter3d'; +obj.data{contourIndex}.mode = 'lines'; + +%-------------------------------------------------------------------------% + +%-get plot data-% +xData = meshData.XData; +yData = meshData.YData; +zData = meshData.ZData; + +%-reformat data to mesh-% +xDataSurface = xData; +yDataSurface = yData; +zDataSurface = zData; + +xDataContourDir1 = [xDataSurface; NaN(1, size(xDataSurface, 2))]; +yDataContourDir1 = [yDataSurface; NaN(1, size(yDataSurface, 2))]; +zDataContourDir1 = [zDataSurface; NaN(1, size(zDataSurface, 2))]; + +xDataContourDir2 = xDataContourDir1(1:end-1,:)'; +yDataContourDir2 = yDataContourDir1(1:end-1,:)'; +zDataContourDir2 = zDataContourDir1(1:end-1,:)'; + +xDataContourDir2 = [xDataContourDir2; NaN(1, size(xDataContourDir2, 2))]; +yDataContourDir2 = [yDataContourDir2; NaN(1, size(yDataContourDir2, 2))]; +zDataContourDir2 = [zDataContourDir2; NaN(1, size(zDataContourDir2, 2))]; + +xDataContour = [xDataContourDir1(:); xDataContourDir2(:)]; +yDataContour = [yDataContourDir1(:); yDataContourDir2(:)]; +zDataContour = [zDataContourDir1(:); zDataContourDir2(:)]; + +%-------------------------------------------------------------------------% + +%-set data on surface-% +obj.data{surfaceIndex}.x = xDataSurface; +obj.data{surfaceIndex}.y = yDataSurface; +obj.data{surfaceIndex}.z = zDataSurface; + +%-------------------------------------------------------------------------% + +%-set data on scatter3d-% +obj.data{contourIndex}.x = xDataContour(:); +obj.data{contourIndex}.y = yDataContour(:); +obj.data{contourIndex}.z = zDataContour(:); + +%-------------------------------------------------------------------------% + +%-COLORING-% + +%-------------------------------------------------------------------------% + +%-get colormap-% +cMap = figureData.Colormap; +fac = 1/(length(cMap)-1); +colorScale = {}; + +for c = 1: length(cMap) + colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; +end + +%-------------------------------------------------------------------------% + +%-get edge color-% +if isnumeric(meshData.EdgeColor) + cDataContour = sprintf('rgb(%f,%f,%f)', 255*meshData.EdgeColor); + +elseif strcmpi(meshData.EdgeColor, 'interp') + cDataContour = zDataContour(:); + obj.data{contourIndex}.line.colorscale = colorScale; + +elseif strcmpi(meshData.EdgeColor, 'flat') + cData = meshData.CData; + + if size(cData, 3) ~= 1 + cMap = unique( reshape(cData, ... + [size(cData,1)*size(cData,2), size(cData,3)]), 'rows' ); + cData = rgb2ind(cData, cMap); + + edgeColorScale = {}; + fac = 1/(length(cMap)-1); + + for c = 1: length(cMap) + edgeColorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; + end + + obj.data{surfaceIndex}.line.cmin = 0; + obj.data{surfaceIndex}.line.cmax = 255; + obj.data{contourIndex}.line.colorscale = edgeColorScale; + else + obj.data{contourIndex}.line.cmin = axisData.CLim(1); + obj.data{contourIndex}.line.cmax = axisData.CLim(2); + obj.data{contourIndex}.line.colorscale = colorScale; + end + + cDataContourDir1 = [cData; NaN(1, size(cData, 2))]; + cDataContourDir2 = cDataContourDir1(1:end-1,:)'; + cDataContourDir2 = [cDataContourDir2; NaN(1, size(cDataContourDir2, 2))]; + cDataContour = [cDataContourDir1(:); cDataContourDir2(:)]; + +elseif strcmpi(meshData.EdgeColor, 'none') + cDataContour = 'rgba(0,0,0,0)'; + +end + +%-set edge color-% +obj.data{contourIndex}.line.color = cDataContour; + +%-------------------------------------------------------------------------% + +%-get face color-% +faceColor = meshData.FaceColor; + +if isnumeric(faceColor) + + if all(faceColor == [1, 1, 1]) + faceColor = [0.96, 0.96, 0.96]; + end + + for n = 1:size(zDataSurface, 2) + for m = 1:size(zDataSurface, 1) + cDataSurface(m, n, :) = faceColor; + end + end + + [cDataSurface, cMapSurface] = rgb2ind(cDataSurface, 256); + cDataSurface = double(cDataSurface) + axisData.CLim(1); + + for c = 1: size(cMapSurface, 1) + colorScale{c} = { (c-1)*fac , sprintf('rgba(%f,%f,%f, 1)', cMapSurface(c, :))}; + end + + obj.data{surfaceIndex}.cmin = axisData.CLim(1); + obj.data{surfaceIndex}.cmax = axisData.CLim(2); + +elseif strcmpi(faceColor, 'interp') + cDataSurface = zDataSurface; + + if surfaceIndex > xsource + cData = []; + + for idx = xsource:surfaceIndex + cData = [cData; obj.data{idx}.z]; + end + + cMin = min(cData(:)); + cMax = max(cData(:)); + + for idx = xsource:surfaceIndex + obj.data{idx}.cmin = cMin; + obj.data{idx}.cmax = cMax; + end + end + +elseif strcmpi(faceColor, 'flat') + cData = meshData.CData; + + if size(cData, 3) ~= 1 + cMap = unique( reshape(cData, ... + [size(cData,1)*size(cData,2), size(cData,3)]), 'rows' ); + cDataSurface = rgb2ind(cData, cMap); + + colorScale = {}; + fac = 1/(length(cMap)-1); + + for c = 1: length(cMap) + colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; + end + else + cDataSurface = cData; + end + +end + +%-set face color-% +obj.data{surfaceIndex}.colorscale = colorScale; +obj.data{surfaceIndex}.surfacecolor = cDataSurface; + +%-lighting settings-% + +if isnumeric(meshData.FaceColor) && all(meshData.FaceColor == [1, 1, 1]) + obj.data{surfaceIndex}.lighting.diffuse = 0.5; + obj.data{surfaceIndex}.lighting.ambient = 0.725; +else + % obj.data{surfaceIndex}.lighting.diffuse = 1.0; + % obj.data{surfaceIndex}.lighting.ambient = 0.9; +end + +if meshData.FaceAlpha ~= 1 + obj.data{surfaceIndex}.lighting.diffuse = 0.5; + obj.data{surfaceIndex}.lighting.ambient = 0.725 + (1-meshData.FaceAlpha); +end + +if obj.PlotlyDefaults.IsLight + obj.data{surfaceIndex}.lighting.diffuse = 1.0; + obj.data{surfaceIndex}.lighting.ambient = 0.3; +end + +%-opacity-% +obj.data{surfaceIndex}.opacity = meshData.FaceAlpha; + +%-------------------------------------------------------------------------% + +%-line style-% + +obj.data{contourIndex}.line.width = 3*meshData.LineWidth; + +switch meshData.LineStyle + case '-' + obj.data{contourIndex}.line.dash = 'solid'; + case '--' + obj.data{contourIndex}.line.dash = 'dash'; + case '-.' + obj.data{contourIndex}.line.dash = 'dashdot'; + case ':' + obj.data{contourIndex}.line.dash = 'dot'; +end + +%-------------------------------------------------------------------------% + +%-SCENE CONFIGUTATION-% + +%-------------------------------------------------------------------------% + +%-aspect ratio-% +asr = obj.PlotOptions.AspectRatio; + +if ~isempty(asr) + if ischar(asr) + scene.aspectmode = asr; + elseif isvector(ar) && length(asr) == 3 + xar = asr(1); + yar = asr(2); + zar = asr(3); + end +else + + %-define as default-% + xar = max(xData(:)); + yar = max(yData(:)); + xyar = max([xar, yar]); + zar = 0.75*xyar; +end + +scene.aspectratio.x = 1.1*xyar; +scene.aspectratio.y = 1.0*xyar; +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-% + xey = - xyar; if xey>0 xfac = -0.0; else xfac = 0.0; end + yey = - xyar; if yey>0 yfac = -0.3; else yfac = 0.3; end + if zar>0 zfac = -0.1; else zfac = 0.1; end + + scene.camera.eye.x = xey + xfac*xey; + scene.camera.eye.y = yey + yfac*yey; + scene.camera.eye.z = zar + zfac*zar; +end + +%-------------------------------------------------------------------------% + +%-scene axis configuration-% + +scene.xaxis.range = axisData.XLim; +scene.yaxis.range = axisData.YLim; +scene.zaxis.range = axisData.ZLim; + +scene.xaxis.tickvals = axisData.XTick; +scene.xaxis.ticktext = axisData.XTickLabel; + +scene.yaxis.tickvals = axisData.YTick; +scene.yaxis.ticktext = axisData.YTickLabel; + +scene.zaxis.tickvals = axisData.ZTick; +scene.zaxis.ticktext = axisData.ZTickLabel; + +scene.xaxis.zeroline = false; +scene.yaxis.zeroline = false; +scene.zaxis.zeroline = false; + +scene.xaxis.showline = true; +scene.yaxis.showline = true; +scene.zaxis.showline = true; + +scene.xaxis.tickcolor = 'rgba(0,0,0,1)'; +scene.yaxis.tickcolor = 'rgba(0,0,0,1)'; +scene.zaxis.tickcolor = 'rgba(0,0,0,1)'; + +scene.xaxis.ticklabelposition = 'outside'; +scene.yaxis.ticklabelposition = 'outside'; +scene.zaxis.ticklabelposition = 'outside'; + +scene.xaxis.title = axisData.XLabel.String; +scene.yaxis.title = axisData.YLabel.String; +scene.zaxis.title = axisData.ZLabel.String; + +scene.xaxis.tickfont.size = axisData.FontSize; +scene.yaxis.tickfont.size = axisData.FontSize; +scene.zaxis.tickfont.size = axisData.FontSize; + +scene.xaxis.tickfont.family = matlab2plotlyfont(axisData.FontName); +scene.yaxis.tickfont.family = matlab2plotlyfont(axisData.FontName); +scene.zaxis.tickfont.family = matlab2plotlyfont(axisData.FontName); + +%-------------------------------------------------------------------------% + +%-SET SCENE TO LAYOUT-% +obj.layout = setfield(obj.layout, sprintf('scene%d', xsource), scene); + +%-------------------------------------------------------------------------% + +%-surface name-% +obj.data{surfaceIndex}.name = meshData.DisplayName; +obj.data{contourIndex}.name = meshData.DisplayName; + +%-------------------------------------------------------------------------% + +%-surface showscale-% +obj.data{surfaceIndex}.showscale = false; +obj.data{contourIndex}.showscale = false; + +%-------------------------------------------------------------------------% + +%-surface visible-% +obj.data{surfaceIndex}.visible = strcmp(meshData.Visible,'on'); +obj.data{contourIndex}.visible = strcmp(meshData.Visible,'on'); + +%-------------------------------------------------------------------------% + +leg = get(meshData.Annotation); +legInfo = get(leg.LegendInformation); + +switch legInfo.IconDisplayStyle + case 'on' + showleg = true; + case 'off' + showleg = false; +end + +obj.data{surfaceIndex}.showlegend = showleg; + +%-------------------------------------------------------------------------% + +end diff --git a/plotly/plotlyfig_aux/handlegraphics/updateScatterhistogram.m b/plotly/plotlyfig_aux/handlegraphics/updateScatterhistogram.m index 380249aa..3b92d330 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateScatterhistogram.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateScatterhistogram.m @@ -65,8 +65,8 @@ function updateScatterhistogram(obj,scatterIndex) p = t; if t > 1 - obj.PlotOptions.nplots = obj.PlotOptions.nplots + 1; - p = obj.PlotOptions.nplots; + obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; + p = obj.PlotOptions.nPlots; end %-----------------------------------------------------------------------% @@ -253,8 +253,8 @@ function updateScatterhistogram(obj,scatterIndex) for t=1:length(xdata) - obj.PlotOptions.nplots = obj.PlotOptions.nplots + 1; - p = obj.PlotOptions.nplots; + obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; + p = obj.PlotOptions.nPlots; if t == 1 ps = p; @@ -367,8 +367,8 @@ function updateScatterhistogram(obj,scatterIndex) for t=1:length(xdata) - obj.PlotOptions.nplots = obj.PlotOptions.nplots + 1; - p = obj.PlotOptions.nplots; + obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; + p = obj.PlotOptions.nPlots; if t == 1 ps = p; diff --git a/plotly/plotlyfig_aux/handlegraphics/updateSurf.m b/plotly/plotlyfig_aux/handlegraphics/updateSurf.m index ecc66c04..a4f27c3b 100644 --- a/plotly/plotlyfig_aux/handlegraphics/updateSurf.m +++ b/plotly/plotlyfig_aux/handlegraphics/updateSurf.m @@ -7,114 +7,248 @@ [xsource, ysource] = findSourceAxis(obj,axIndex); %-SURFACE DATA STRUCTURE- % -surfData = get(obj.State.Plot(surfaceIndex).Handle); +meshData = get(obj.State.Plot(surfaceIndex).Handle); figureData = get(obj.State.Figure.Handle); %-AXIS STRUCTURE-% -axisData = get(ancestor(surfData.Parent,'axes')); +axisData = get(ancestor(meshData.Parent,'axes')); -%-GET SCENE-% -eval(['scene = obj.layout.scene' num2str(xsource) ';']); +%-SCENE DATA-% +eval( sprintf('scene = obj.layout.scene%d;', xsource) ); + +%-GET CONTOUR INDEX-% +obj.PlotOptions.nPlots = obj.PlotOptions.nPlots + 1; +contourIndex = obj.PlotOptions.nPlots; +obj.PlotOptions.contourIndex(surfaceIndex) = contourIndex; %-------------------------------------------------------------------------% %-associate scene-% obj.data{surfaceIndex}.scene = sprintf('scene%d', xsource); +obj.data{contourIndex}.scene = sprintf('scene%d', xsource); %-------------------------------------------------------------------------% - -%-surface type-% + +%-surface type for face color-% obj.data{surfaceIndex}.type = 'surface'; + +%-scatter3d type for contour mesh lines-% +obj.data{contourIndex}.type = 'scatter3d'; +obj.data{contourIndex}.mode = 'lines'; -%---------------------------------------------------------------------% +%-------------------------------------------------------------------------% %-get plot data-% -xData = surfData.XData; -yData = surfData.YData; -zData = surfData.ZData; -cData = surfData.CData; +xData = meshData.XData; +yData = meshData.YData; +zData = meshData.ZData; -%---------------------------------------------------------------------% +%-reformat data to mesh-% +xDataSurface = xData; +yDataSurface = yData; +zDataSurface = zData; -%-set surface data-% -obj.data{surfaceIndex}.x = xData; -obj.data{surfaceIndex}.y = yData; -obj.data{surfaceIndex}.z = zData; +xDataContourDir1 = [xDataSurface; NaN(1, size(xDataSurface, 2))]; +yDataContourDir1 = [yDataSurface; NaN(1, size(yDataSurface, 2))]; +zDataContourDir1 = [zDataSurface; NaN(1, size(zDataSurface, 2))]; -%---------------------------------------------------------------------% +xDataContourDir2 = xDataContourDir1(1:end-1,:)'; +yDataContourDir2 = yDataContourDir1(1:end-1,:)'; +zDataContourDir2 = zDataContourDir1(1:end-1,:)'; -%-setting grid mesh by default-% +xDataContourDir2 = [xDataContourDir2; NaN(1, size(xDataContourDir2, 2))]; +yDataContourDir2 = [yDataContourDir2; NaN(1, size(yDataContourDir2, 2))]; +zDataContourDir2 = [zDataContourDir2; NaN(1, size(zDataContourDir2, 2))]; -edgeColor = surfData.EdgeColor; +xDataContour = [xDataContourDir1(:); xDataContourDir2(:)]; +yDataContour = [yDataContourDir1(:); yDataContourDir2(:)]; +zDataContour = [zDataContourDir1(:); zDataContourDir2(:)]; -if isnumeric(edgeColor) - edgeColor = sprintf('rgb(%f,%f,%f)', 255*edgeColor); -elseif strcmpi(edgeColor, 'none') - edgeColor = 'rgba(1,1,1,0)'; -end +%-------------------------------------------------------------------------% + +%-set data on surface-% +obj.data{surfaceIndex}.x = xDataSurface; +obj.data{surfaceIndex}.y = yDataSurface; +obj.data{surfaceIndex}.z = zDataSurface; -% x-direction -xMin = min(xData(:)); -xMax = max(xData(:)); -xsize = (xMax - xMin) / (size(xData, 2)-1); -obj.data{surfaceIndex}.contours.x.start = xMin; -obj.data{surfaceIndex}.contours.x.end = xMax; -obj.data{surfaceIndex}.contours.x.size = xsize; -obj.data{surfaceIndex}.contours.x.show = true; -obj.data{surfaceIndex}.contours.x.color = edgeColor; - -% y-direction -yMin = min(yData(:)); -yMax = max(yData(:)); -ysize = (yMax - yMin) / (size(yData, 1)-1); -obj.data{surfaceIndex}.contours.y.start = yMin; -obj.data{surfaceIndex}.contours.y.end = yMax; -obj.data{surfaceIndex}.contours.y.size = ysize; -obj.data{surfaceIndex}.contours.y.show = true; -obj.data{surfaceIndex}.contours.y.color = edgeColor; - -%-------------------------------------------------------------------------% - -%-set colorscales-% +%-------------------------------------------------------------------------% + +%-set data on scatter3d-% +obj.data{contourIndex}.x = xDataContour(:); +obj.data{contourIndex}.y = yDataContour(:); +obj.data{contourIndex}.z = zDataContour(:); + +%-------------------------------------------------------------------------% + +%-COLORING-% + +%-------------------------------------------------------------------------% + +%-get colormap-% cMap = figureData.Colormap; +fac = 1/(length(cMap)-1); +colorScale = {}; -if isnumeric(surfData.FaceColor) - for n = 1:size(cData, 2) - for m = 1:size(cData, 1) - cDataNew(m, n, :) = surfData.FaceColor; +for c = 1: length(cMap) + colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; +end + +%-------------------------------------------------------------------------% + +%-get edge color-% +if isnumeric(meshData.EdgeColor) + cDataContour = sprintf('rgb(%f,%f,%f)', 255*meshData.EdgeColor); + +elseif strcmpi(meshData.EdgeColor, 'interp') + cDataContour = zDataContour(:); + obj.data{contourIndex}.line.colorscale = colorScale; + +elseif strcmpi(meshData.EdgeColor, 'flat') + cData = meshData.CData; + + if size(cData, 3) ~= 1 + cMap = unique( reshape(cData, ... + [size(cData,1)*size(cData,2), size(cData,3)]), 'rows' ); + cData = rgb2ind(cData, cMap); + + edgeColorScale = {}; + fac = 1/(length(cMap)-1); + + for c = 1: length(cMap) + edgeColorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; end + + obj.data{surfaceIndex}.line.cmin = 0; + obj.data{surfaceIndex}.line.cmax = 255; + obj.data{contourIndex}.line.colorscale = edgeColorScale; + else + obj.data{contourIndex}.line.cmin = axisData.CLim(1); + obj.data{contourIndex}.line.cmax = axisData.CLim(2); + obj.data{contourIndex}.line.colorscale = colorScale; end - cData = rgb2ind(cDataNew, cMap); - obj.data{surfaceIndex}.cmin = 0; - obj.data{surfaceIndex}.cmax = 255; -end + cDataContourDir1 = [cData; NaN(1, size(cData, 2))]; + cDataContourDir2 = cDataContourDir1(1:end-1,:)'; + cDataContourDir2 = [cDataContourDir2; NaN(1, size(cDataContourDir2, 2))]; + cDataContour = [cDataContourDir1(:); cDataContourDir2(:)]; + +elseif strcmpi(meshData.EdgeColor, 'none') + cDataContour = 'rgba(0,0,0,0)'; -if size(cData, 3) ~= 1 - cMap = unique( reshape(cData, ... - [size(cData,1)*size(cData,2), size(cData,3)]), 'rows' ); - cData = rgb2ind(cData, cMap); end -colorScale = {}; -fac = 1/(length(cMap)-1); +%-set edge color-% +obj.data{contourIndex}.line.color = cDataContour; -for c = 1: length(cMap) - colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; +%-------------------------------------------------------------------------% + +%-get face color-% +faceColor = meshData.FaceColor; + +if isnumeric(faceColor) + + if all(faceColor == [1, 1, 1]) + faceColor = [0.96, 0.96, 0.96]; + end + + for n = 1:size(zDataSurface, 2) + for m = 1:size(zDataSurface, 1) + cDataSurface(m, n, :) = faceColor; + end + end + + [cDataSurface, cMapSurface] = rgb2ind(cDataSurface, 256); + cDataSurface = double(cDataSurface) + axisData.CLim(1); + + for c = 1: size(cMapSurface, 1) + colorScale{c} = { (c-1)*fac , sprintf('rgba(%f,%f,%f, 1)', cMapSurface(c, :))}; + end + + obj.data{surfaceIndex}.cmin = axisData.CLim(1); + obj.data{surfaceIndex}.cmax = axisData.CLim(2); + +elseif strcmpi(faceColor, 'interp') + cDataSurface = zDataSurface; + + if surfaceIndex > xsource + cData = []; + + for idx = xsource:surfaceIndex + cData = [cData; obj.data{idx}.z]; + end + + cMin = min(cData(:)); + cMax = max(cData(:)); + + for idx = xsource:surfaceIndex + obj.data{idx}.cmin = cMin; + obj.data{idx}.cmax = cMax; + end + end + +elseif strcmpi(faceColor, 'flat') + cData = meshData.CData; + + if size(cData, 3) ~= 1 + cMap = unique( reshape(cData, ... + [size(cData,1)*size(cData,2), size(cData,3)]), 'rows' ); + cDataSurface = rgb2ind(cData, cMap); + + colorScale = {}; + fac = 1/(length(cMap)-1); + + for c = 1: length(cMap) + colorScale{c} = { (c-1)*fac , sprintf('rgb(%f,%f,%f)', 255*cMap(c, :))}; + end + else + cDataSurface = cData; + end + end +%-set face color-% obj.data{surfaceIndex}.colorscale = colorScale; +obj.data{surfaceIndex}.surfacecolor = cDataSurface; + +%-lighting settings-% + +if isnumeric(meshData.FaceColor) && all(meshData.FaceColor == [1, 1, 1]) + obj.data{surfaceIndex}.lighting.diffuse = 0.5; + obj.data{surfaceIndex}.lighting.ambient = 0.725; +else + % obj.data{surfaceIndex}.lighting.diffuse = 1.0; + % obj.data{surfaceIndex}.lighting.ambient = 0.9; +end + +if meshData.FaceAlpha ~= 1 + obj.data{surfaceIndex}.lighting.diffuse = 0.5; + obj.data{surfaceIndex}.lighting.ambient = 0.725 + (1-meshData.FaceAlpha); +end + +if obj.PlotlyDefaults.IsLight + obj.data{surfaceIndex}.lighting.diffuse = 1.0; + obj.data{surfaceIndex}.lighting.ambient = 0.3; +end -%-surface coloring-% -obj.data{surfaceIndex}.surfacecolor = cData; +%-opacity-% +obj.data{surfaceIndex}.opacity = meshData.FaceAlpha; %-------------------------------------------------------------------------% -%-surface opacity-% -obj.data{surfaceIndex}.opacity = surfData.FaceAlpha; +%-line style-% -%-surface showscale-% -obj.data{surfaceIndex}.showscale = false; +obj.data{contourIndex}.line.width = 3*meshData.LineWidth; + +switch meshData.LineStyle + case '-' + obj.data{contourIndex}.line.dash = 'solid'; + case '--' + obj.data{contourIndex}.line.dash = 'dash'; + case '-.' + obj.data{contourIndex}.line.dash = 'dashdot'; + case ':' + obj.data{contourIndex}.line.dash = 'dot'; +end %-------------------------------------------------------------------------% @@ -139,7 +273,7 @@ xar = max(xData(:)); yar = max(yData(:)); xyar = max([xar, yar]); - zar = 0.65*xyar; + zar = 0.75*xyar; end scene.aspectratio.x = 1.1*xyar; @@ -160,9 +294,9 @@ else %-define as default-% - xey = - xyar; if xey>0 xfac = -0.2; else xfac = 0.2; end - yey = - xyar; if yey>0 yfac = -0.2; else yfac = 0.2; end - if zar>0 zfac = 0.2; else zfac = -0.2; end + xey = - xyar; if xey>0 xfac = -0.0; else xfac = 0.0; end + yey = - xyar; if yey>0 yfac = -0.3; else yfac = 0.3; end + if zar>0 zfac = -0.1; else zfac = 0.1; end scene.camera.eye.x = xey + xfac*xey; scene.camera.eye.y = yey + yfac*yey; @@ -222,16 +356,24 @@ %-------------------------------------------------------------------------% %-surface name-% -obj.data{surfaceIndex}.name = surfData.DisplayName; +obj.data{surfaceIndex}.name = meshData.DisplayName; +obj.data{contourIndex}.name = meshData.DisplayName; + +%-------------------------------------------------------------------------% + +%-surface showscale-% +obj.data{surfaceIndex}.showscale = false; +obj.data{contourIndex}.showscale = false; %-------------------------------------------------------------------------% %-surface visible-% -obj.data{surfaceIndex}.visible = strcmp(surfData.Visible,'on'); +obj.data{surfaceIndex}.visible = strcmp(meshData.Visible,'on'); +obj.data{contourIndex}.visible = strcmp(meshData.Visible,'on'); %-------------------------------------------------------------------------% -leg = get(surfData.Annotation); +leg = get(meshData.Annotation); legInfo = get(leg.LegendInformation); switch legInfo.IconDisplayStyle