1
- function obj = updateIsosurface(obj , isoIndex )
2
- % -INITIALIZATIONS-%
3
-
1
+ function data = updateIsosurface(obj , isoIndex )
4
2
axIndex = obj .getAxisIndex(obj .State .Plot(isoIndex ).AssociatedAxis);
5
3
plotData = obj .State .Plot(isoIndex ).Handle;
6
4
axisData = plotData .Parent ;
7
5
xSource = findSourceAxis(obj , axIndex );
8
6
9
- % -update scene-%
10
7
updateScene(obj , isoIndex )
11
8
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
+ );
34
21
35
- % -mesh coloring-%
36
22
faceColor = getFaceColor(plotData , axisData );
37
-
38
23
if iscell(faceColor )
39
- obj. data{ isoIndex } .facecolor = faceColor ;
24
+ data.facecolor = faceColor ;
40
25
else
41
- obj. data{ isoIndex } .color = faceColor ;
26
+ data.color = faceColor ;
42
27
end
43
28
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
+ );
53
39
end
54
-
55
- % -associate scene to trace-%
56
- obj.data{isoIndex }.scene = sprintf(' scene%d ' , xSource );
57
40
end
58
41
59
42
function updateScene(obj , isoIndex )
60
- % -INITIALIZATIONS-%
61
43
axIndex = obj .getAxisIndex(obj .State .Plot(isoIndex ).AssociatedAxis);
62
44
plotData = obj .State .Plot(isoIndex ).Handle;
63
45
axisData = plotData .Parent ;
@@ -71,75 +53,61 @@ function updateScene(obj, isoIndex)
71
53
cameraEye = cameraPosition ./ dataAspectRatio ;
72
54
normFac = 0.5 * abs(min(cameraEye ));
73
55
74
- % -aspect ratio-%
75
56
scene.aspectratio.x = aspectRatio(1 );
76
57
scene.aspectratio.y = aspectRatio(2 );
77
58
scene.aspectratio.z = aspectRatio(3 );
78
59
79
- % -camera eye-%
80
60
scene.camera.eye.x = cameraEye(1 ) / normFac ;
81
61
scene.camera.eye.y = cameraEye(2 ) / normFac ;
82
62
scene.camera.eye.z = cameraEye(3 ) / normFac ;
83
63
84
- % -camera up-%
85
64
scene.camera.up.x = cameraUpVector(1 );
86
65
scene.camera.up.y = cameraUpVector(2 );
87
66
scene.camera.up.z = cameraUpVector(3 );
88
67
89
- % -camera projection-%
90
- % scene.camera.projection.type = axisData.Projection;
91
-
92
- % -scene axis configuration-%
93
68
scene.xaxis.range = axisData .XLim ;
94
- scene.yaxis.range = axisData .YLim ;
95
- scene.zaxis.range = axisData .ZLim ;
96
-
97
69
scene.xaxis.zeroline = false ;
98
- scene.yaxis.zeroline = false ;
99
- scene.zaxis.zeroline = false ;
100
-
101
70
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" ;
109
72
scene.xaxis.title = axisData .XLabel .String ;
110
- scene.yaxis.title = axisData .YLabel .String ;
111
- scene.zaxis.title = axisData .ZLabel .String ;
112
-
113
- % -tick labels-%
114
73
scene.xaxis.tickvals = axisData .XTick ;
115
74
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 ;
116
84
scene.yaxis.tickvals = axisData .YTick ;
117
85
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 ;
118
95
scene.zaxis.tickvals = axisData .ZTick ;
119
96
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)" ;
126
98
scene.zaxis.tickfont.size = axisData .FontSize ;
127
- scene.xaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
128
- scene.yaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
129
99
scene.zaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
130
100
131
- % -grid-%
132
- if strcmp(axisData .XGrid , ' off' )
101
+ if axisData .XGrid == " off"
133
102
scene.xaxis.showgrid = false ;
134
103
end
135
- if strcmp( axisData .YGrid , ' off' )
104
+ if axisData .YGrid == " off"
136
105
scene.yaxis.showgrid = false ;
137
106
end
138
- if strcmp( axisData .ZGrid , ' off' )
107
+ if axisData .ZGrid == " off"
139
108
scene.zaxis.showgrid = false ;
140
109
end
141
110
142
- % -SET SCENE TO LAYOUT-%
143
111
obj .layout.(" scene" + xSource ) = scene ;
144
112
end
145
113
@@ -152,26 +120,24 @@ function updateScene(obj, isoIndex)
152
120
153
121
% -get face color depending of faceColor attribute
154
122
if isnumeric(faceColor )
155
- numColor = round(255 * faceColor );
156
- fillColor = sprintf(" rgb(%d,%d,%d)" , numColor );
123
+ fillColor = getStringColor(round(255 * faceColor ));
157
124
elseif strcmpi(faceColor , " flat" )
158
- fillColor = getStringColor (cData , colorMap , cLim );
125
+ fillColor = getColor (cData , colorMap , cLim );
159
126
elseif strcmpi(faceColor , " interp" )
160
127
if size(cData , 1 ) ~= 1
161
128
for n = 1 : size(cData , 2 )
162
- fillColor{n } = getStringColor (mean(cData(: , n )), colorMap , cLim );
129
+ fillColor{n } = getColor (mean(cData(: , n )), colorMap , cLim );
163
130
end
164
131
else
165
132
% TODO
166
133
end
167
134
end
168
135
end
169
136
170
- function stringColor = getStringColor (cData , colorMap , cLim )
137
+ function color = getColor (cData , colorMap , cLim )
171
138
nColors = size(colorMap , 1 );
172
- cIndex = max( min( cData , cLim(2 ) ), cLim(1 ) );
139
+ cIndex = max(min(cData , cLim(2 )), cLim(1 ));
173
140
scaleColor = (cIndex - cLim(1 )) / diff(cLim );
174
141
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 , : )));
177
143
end
0 commit comments