1- function obj = updateIsosurface(obj , isoIndex )
2- % -INITIALIZATIONS-%
3-
1+ function data = updateIsosurface(obj , isoIndex )
42 axIndex = obj .getAxisIndex(obj .State .Plot(isoIndex ).AssociatedAxis);
53 plotData = obj .State .Plot(isoIndex ).Handle;
64 axisData = plotData .Parent ;
75 xSource = findSourceAxis(obj , axIndex );
86
9- % -update scene-%
107 updateScene(obj , isoIndex )
118
12- % -get mesh data-%
13- xData = plotData .Vertices(: , 1 );
14- yData = plotData .Vertices(: , 2 );
15- zData = plotData .Vertices(: , 3 );
16-
17- iData = plotData .Faces(: , 1 ) - 1 ;
18- jData = plotData .Faces(: , 2 ) - 1 ;
19- kData = plotData .Faces(: , 3 ) - 1 ;
20-
21- % -get trace-%
22- obj.data{isoIndex }.type = ' mesh3d' ;
23- obj.data{isoIndex }.name = plotData .DisplayName ;
24- obj.data{isoIndex }.showscale = false ;
25-
26- % -set mesh data-%
27- obj.data{isoIndex }.x = xData ;
28- obj.data{isoIndex }.y = yData ;
29- obj.data{isoIndex }.z = zData ;
30-
31- obj.data{isoIndex }.i = iData ;
32- obj.data{isoIndex }.j = jData ;
33- obj.data{isoIndex }.k = kData ;
9+ data = struct( ...
10+ " type" , " mesh3d" , ...
11+ " name" , plotData .DisplayName , ...
12+ " showscale" , false , ...
13+ " x" , plotData .Vertices(: , 1 ), ...
14+ " y" , plotData .Vertices(: , 2 ), ...
15+ " z" , plotData .Vertices(: , 3 ), ...
16+ " i" , plotData .Faces(: , 1 ) - 1 , ...
17+ " j" , plotData .Faces(: , 2 ) - 1 , ...
18+ " k" , plotData .Faces(: , 3 ) - 1 , ...
19+ " scene" , " scene" + xSource ...
20+ );
3421
35- % -mesh coloring-%
3622 faceColor = getFaceColor(plotData , axisData );
37-
3823 if iscell(faceColor )
39- obj. data{ isoIndex } .facecolor = faceColor ;
24+ data.facecolor = faceColor ;
4025 else
41- obj. data{ isoIndex } .color = faceColor ;
26+ data.color = faceColor ;
4227 end
4328
44- % -lighting settings-%
45- if ~strcmp(plotData .FaceLighting , ' flat' )
46- obj.data{isoIndex }.lighting.diffuse = plotData .DiffuseStrength ;
47- obj.data{isoIndex }.lighting.ambient = plotData .AmbientStrength ;
48- obj.data{isoIndex }.lighting.specular = plotData .SpecularStrength ;
49- obj.data{isoIndex }.lighting.roughness = 0.2 ;
50- obj.data{isoIndex }.lighting.fresnel = 0.5 ;
51- obj.data{isoIndex }.lighting.vertexnormalsepsilon = 1e- 12 ;
52- obj.data{isoIndex }.lighting.facenormalsepsilon = 1e-6 ;
29+ if plotData .FaceLighting ~= " flat"
30+ data.lighting = struct( ...
31+ " diffuse" , plotData .DiffuseStrength , ...
32+ " ambient" , plotData .AmbientStrength , ...
33+ " specular" , plotData .SpecularStrength , ...
34+ " roughness" , 0.2 , ...
35+ " fresnel" , 0.5 , ...
36+ " vertexnormalsepsilon" , 1e- 12 , ...
37+ " facenormalsepsilon" , 1e-6 ...
38+ );
5339 end
54-
55- % -associate scene to trace-%
56- obj.data{isoIndex }.scene = sprintf(' scene%d ' , xSource );
5740end
5841
5942function updateScene(obj , isoIndex )
60- % -INITIALIZATIONS-%
6143 axIndex = obj .getAxisIndex(obj .State .Plot(isoIndex ).AssociatedAxis);
6244 plotData = obj .State .Plot(isoIndex ).Handle;
6345 axisData = plotData .Parent ;
@@ -71,75 +53,61 @@ function updateScene(obj, isoIndex)
7153 cameraEye = cameraPosition ./ dataAspectRatio ;
7254 normFac = 0.5 * abs(min(cameraEye ));
7355
74- % -aspect ratio-%
7556 scene.aspectratio.x = aspectRatio(1 );
7657 scene.aspectratio.y = aspectRatio(2 );
7758 scene.aspectratio.z = aspectRatio(3 );
7859
79- % -camera eye-%
8060 scene.camera.eye.x = cameraEye(1 ) / normFac ;
8161 scene.camera.eye.y = cameraEye(2 ) / normFac ;
8262 scene.camera.eye.z = cameraEye(3 ) / normFac ;
8363
84- % -camera up-%
8564 scene.camera.up.x = cameraUpVector(1 );
8665 scene.camera.up.y = cameraUpVector(2 );
8766 scene.camera.up.z = cameraUpVector(3 );
8867
89- % -camera projection-%
90- % scene.camera.projection.type = axisData.Projection;
91-
92- % -scene axis configuration-%
9368 scene.xaxis.range = axisData .XLim ;
94- scene.yaxis.range = axisData .YLim ;
95- scene.zaxis.range = axisData .ZLim ;
96-
9769 scene.xaxis.zeroline = false ;
98- scene.yaxis.zeroline = false ;
99- scene.zaxis.zeroline = false ;
100-
10170 scene.xaxis.showline = true ;
102- scene.yaxis.showline = true ;
103- scene.zaxis.showline = true ;
104-
105- scene.xaxis.ticklabelposition = ' outside' ;
106- scene.yaxis.ticklabelposition = ' outside' ;
107- scene.zaxis.ticklabelposition = ' outside' ;
108-
71+ scene.xaxis.ticklabelposition = " outside" ;
10972 scene.xaxis.title = axisData .XLabel .String ;
110- scene.yaxis.title = axisData .YLabel .String ;
111- scene.zaxis.title = axisData .ZLabel .String ;
112-
113- % -tick labels-%
11473 scene.xaxis.tickvals = axisData .XTick ;
11574 scene.xaxis.ticktext = axisData .XTickLabel ;
75+ scene.xaxis.tickcolor = " rgba(0,0,0,1)" ;
76+ scene.xaxis.tickfont.size = axisData .FontSize ;
77+ scene.xaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
78+
79+ scene.yaxis.range = axisData .YLim ;
80+ scene.yaxis.zeroline = false ;
81+ scene.yaxis.showline = true ;
82+ scene.yaxis.ticklabelposition = " outside" ;
83+ scene.yaxis.title = axisData .YLabel .String ;
11684 scene.yaxis.tickvals = axisData .YTick ;
11785 scene.yaxis.ticktext = axisData .YTickLabel ;
86+ scene.yaxis.tickcolor = " rgba(0,0,0,1)" ;
87+ scene.yaxis.tickfont.size = axisData .FontSize ;
88+ scene.yaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
89+
90+ scene.zaxis.range = axisData .ZLim ;
91+ scene.zaxis.zeroline = false ;
92+ scene.zaxis.showline = true ;
93+ scene.zaxis.ticklabelposition = " outside" ;
94+ scene.zaxis.title = axisData .ZLabel .String ;
11895 scene.zaxis.tickvals = axisData .ZTick ;
11996 scene.zaxis.ticktext = axisData .ZTickLabel ;
120-
121- scene.xaxis.tickcolor = ' rgba(0,0,0,1)' ;
122- scene.yaxis.tickcolor = ' rgba(0,0,0,1)' ;
123- scene.zaxis.tickcolor = ' rgba(0,0,0,1)' ;
124- scene.xaxis.tickfont.size = axisData .FontSize ;
125- scene.yaxis.tickfont.size = axisData .FontSize ;
97+ scene.zaxis.tickcolor = " rgba(0,0,0,1)" ;
12698 scene.zaxis.tickfont.size = axisData .FontSize ;
127- scene.xaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
128- scene.yaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
12999 scene.zaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
130100
131- % -grid-%
132- if strcmp(axisData .XGrid , ' off' )
101+ if axisData .XGrid == " off"
133102 scene.xaxis.showgrid = false ;
134103 end
135- if strcmp( axisData .YGrid , ' off' )
104+ if axisData .YGrid == " off"
136105 scene.yaxis.showgrid = false ;
137106 end
138- if strcmp( axisData .ZGrid , ' off' )
107+ if axisData .ZGrid == " off"
139108 scene.zaxis.showgrid = false ;
140109 end
141110
142- % -SET SCENE TO LAYOUT-%
143111 obj .layout.(" scene" + xSource ) = scene ;
144112end
145113
@@ -152,26 +120,24 @@ function updateScene(obj, isoIndex)
152120
153121 % -get face color depending of faceColor attribute
154122 if isnumeric(faceColor )
155- numColor = round(255 * faceColor );
156- fillColor = sprintf(" rgb(%d,%d,%d)" , numColor );
123+ fillColor = getStringColor(round(255 * faceColor ));
157124 elseif strcmpi(faceColor , " flat" )
158- fillColor = getStringColor (cData , colorMap , cLim );
125+ fillColor = getColor (cData , colorMap , cLim );
159126 elseif strcmpi(faceColor , " interp" )
160127 if size(cData , 1 ) ~= 1
161128 for n = 1 : size(cData , 2 )
162- fillColor{n } = getStringColor (mean(cData(: , n )), colorMap , cLim );
129+ fillColor{n } = getColor (mean(cData(: , n )), colorMap , cLim );
163130 end
164131 else
165132 % TODO
166133 end
167134 end
168135end
169136
170- function stringColor = getStringColor (cData , colorMap , cLim )
137+ function color = getColor (cData , colorMap , cLim )
171138 nColors = size(colorMap , 1 );
172- cIndex = max( min( cData , cLim(2 ) ), cLim(1 ) );
139+ cIndex = max(min(cData , cLim(2 )), cLim(1 ));
173140 scaleColor = (cIndex - cLim(1 )) / diff(cLim );
174141 cIndex = 1 + floor(scaleColor *(nColors - 1 ));
175- numColor = round(255 * colorMap(cIndex , : ));
176- stringColor = sprintf(" rgb(%d,%d,%d)" , numColor );
142+ color = getStringColor(round(255 * colorMap(cIndex , : )));
177143end
0 commit comments