1+ function obj = updateIsosurface(obj , isoIndex )
2+
3+ % -------------------------------------------------------------------------%
4+
5+ % -INITIALIZATIONS-%
6+
7+ axIndex = obj .getAxisIndex(obj .State .Plot(isoIndex ).AssociatedAxis);
8+ plotData = get(obj .State .Plot(isoIndex ).Handle);
9+ axisData = get(plotData .Parent );
10+ [xSource , ySource ] = findSourceAxis(obj , axIndex );
11+
12+ % -update scene-%
13+ updateScene(obj , isoIndex )
14+
15+ % -get mesh data-%
16+ xData = plotData .Vertices(: , 1 );
17+ yData = plotData .Vertices(: , 2 );
18+ zData = plotData .Vertices(: , 3 );
19+
20+ iData = plotData .Faces(: , 1 ) - 1 ;
21+ jData = plotData .Faces(: , 2 ) - 1 ;
22+ kData = plotData .Faces(: , 3 ) - 1 ;
23+
24+ % -------------------------------------------------------------------------%
25+
26+ % -get trace-%
27+ obj.data{isoIndex }.type = ' mesh3d' ;
28+ obj.data{isoIndex }.name = plotData .DisplayName ;
29+ obj.data{isoIndex }.showscale = false ;
30+
31+ % -------------------------------------------------------------------------%
32+
33+ % -set mesh data-%
34+ obj.data{isoIndex }.x = xData ;
35+ obj.data{isoIndex }.y = yData ;
36+ obj.data{isoIndex }.z = zData ;
37+
38+ obj.data{isoIndex }.i = iData ;
39+ obj.data{isoIndex }.j = jData ;
40+ obj.data{isoIndex }.k = kData ;
41+
42+ % -------------------------------------------------------------------------%
43+
44+ % -mesh coloring-%
45+ faceColor = getFaceColor(plotData , axisData );
46+
47+ if iscell(faceColor )
48+ obj.data{isoIndex }.facecolor = faceColor ;
49+ else
50+ obj.data{isoIndex }.color = faceColor ;
51+ end
52+
53+ % -------------------------------------------------------------------------%
54+
55+ % -lighting settings-%
56+ if ~strcmp(plotData .FaceLighting , ' flat' )
57+ obj.data{isoIndex }.lighting.diffuse = plotData .DiffuseStrength ;
58+ obj.data{isoIndex }.lighting.ambient = plotData .AmbientStrength ;
59+ obj.data{isoIndex }.lighting.specular = plotData .SpecularStrength ;
60+ obj.data{isoIndex }.lighting.roughness = 0.2 ;
61+ obj.data{isoIndex }.lighting.fresnel = 0.5 ;
62+ obj.data{isoIndex }.lighting.vertexnormalsepsilon = 1e- 12 ;
63+ obj.data{isoIndex }.lighting.facenormalsepsilon = 1e-6 ;
64+ end
65+
66+ % -------------------------------------------------------------------------%
67+
68+ % -associate scene to trace-%
69+ obj.data{isoIndex }.scene = sprintf(' scene%d ' , xSource );
70+
71+ % -------------------------------------------------------------------------%
72+ end
73+
74+ function updateScene(obj , isoIndex )
75+
76+ % -INITIALIZATIONS-%
77+ axIndex = obj .getAxisIndex(obj .State .Plot(isoIndex ).AssociatedAxis);
78+ plotData = get(obj .State .Plot(isoIndex ).Handle);
79+ axisData = get(plotData .Parent );
80+ [xSource , ySource ] = findSourceAxis(obj , axIndex );
81+ scene = eval( sprintf(' obj.layout.scene%d ' , xSource ) );
82+
83+ aspectRatio = axisData .PlotBoxAspectRatio ;
84+ cameraPosition = axisData .CameraPosition ;
85+ dataAspectRatio = axisData .DataAspectRatio ;
86+ cameraUpVector = axisData .CameraUpVector ;
87+ cameraEye = cameraPosition ./ dataAspectRatio ;
88+ normFac = 0.5 * abs(min(cameraEye ));
89+
90+ % -aspect ratio-%
91+ scene.aspectratio.x = aspectRatio(1 );
92+ scene.aspectratio.y = aspectRatio(2 );
93+ scene.aspectratio.z = aspectRatio(3 );
94+
95+ % -camera eye-%
96+ scene.camera.eye.x = cameraEye(1 ) / normFac ;
97+ scene.camera.eye.y = cameraEye(2 ) / normFac ;
98+ scene.camera.eye.z = cameraEye(3 ) / normFac ;
99+
100+ % -camera up-%
101+ scene.camera.up.x = cameraUpVector(1 );
102+ scene.camera.up.y = cameraUpVector(2 );
103+ scene.camera.up.z = cameraUpVector(3 );
104+
105+ % -camera projection-%
106+ % scene.camera.projection.type = axisData.Projection;
107+
108+ % -scene axis configuration-%
109+ scene.xaxis.range = axisData .XLim ;
110+ scene.yaxis.range = axisData .YLim ;
111+ scene.zaxis.range = axisData .ZLim ;
112+
113+ scene.xaxis.zeroline = false ;
114+ scene.yaxis.zeroline = false ;
115+ scene.zaxis.zeroline = false ;
116+
117+ scene.xaxis.showline = true ;
118+ scene.yaxis.showline = true ;
119+ scene.zaxis.showline = true ;
120+
121+ scene.xaxis.ticklabelposition = ' outside' ;
122+ scene.yaxis.ticklabelposition = ' outside' ;
123+ scene.zaxis.ticklabelposition = ' outside' ;
124+
125+ scene.xaxis.title = axisData .XLabel .String ;
126+ scene.yaxis.title = axisData .YLabel .String ;
127+ scene.zaxis.title = axisData .ZLabel .String ;
128+
129+ % -tick labels-%
130+ scene.xaxis.tickvals = axisData .XTick ;
131+ scene.xaxis.ticktext = axisData .XTickLabel ;
132+ scene.yaxis.tickvals = axisData .YTick ;
133+ scene.yaxis.ticktext = axisData .YTickLabel ;
134+ scene.zaxis.tickvals = axisData .ZTick ;
135+ scene.zaxis.ticktext = axisData .ZTickLabel ;
136+
137+ scene.xaxis.tickcolor = ' rgba(0,0,0,1)' ;
138+ scene.yaxis.tickcolor = ' rgba(0,0,0,1)' ;
139+ scene.zaxis.tickcolor = ' rgba(0,0,0,1)' ;
140+ scene.xaxis.tickfont.size = axisData .FontSize ;
141+ scene.yaxis.tickfont.size = axisData .FontSize ;
142+ scene.zaxis.tickfont.size = axisData .FontSize ;
143+ scene.xaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
144+ scene.yaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
145+ scene.zaxis.tickfont.family = matlab2plotlyfont(axisData .FontName );
146+
147+ % -grid-%
148+ if strcmp(axisData .XGrid , ' off' ), scene.xaxis.showgrid = false ; end
149+ if strcmp(axisData .YGrid , ' off' ), scene.yaxis.showgrid = false ; end
150+ if strcmp(axisData .ZGrid , ' off' ), scene.zaxis.showgrid = false ; end
151+
152+ % -SET SCENE TO LAYOUT-%
153+ obj.layout = setfield(obj .layout , sprintf(' scene%d ' , xSource ), scene );
154+ end
155+
156+ function fillColor = getFaceColor(plotData , axisData )
157+
158+ % -initializations-%
159+ faceColor = plotData .FaceColor ;
160+ cData = plotData .CData ;
161+ cLim = axisData .CLim ;
162+ colorMap = axisData .Colormap ;
163+
164+ % -get face color depending of faceColor attribute
165+ if isnumeric(faceColor )
166+ numColor = 255 * faceColor ;
167+ fillColor = sprintf(' rgb(%f ,%f ,%f )' , numColor );
168+
169+ elseif strcmpi(faceColor , ' flat' )
170+ fillColor = getStringColor(cData , colorMap , cLim );
171+
172+ elseif strcmpi(faceColor , ' interp' )
173+ if size(cData , 1 ) ~= 1
174+ for n = 1 : size(cData , 2 )
175+ fillColor{n } = getStringColor(mean(cData(: , n )), colorMap , cLim );
176+ end
177+ else
178+ % TODO
179+ end
180+ end
181+ end
182+
183+ function stringColor = getStringColor(cData , colorMap , cLim )
184+ nColors = size(colorMap , 1 );
185+ cIndex = max( min( cData , cLim(2 ) ), cLim(1 ) );
186+ scaleColor = (cIndex - cLim(1 )) / diff(cLim );
187+ cIndex = 1 + floor(scaleColor *(nColors - 1 ));
188+ numColor = 255 * colorMap(cIndex , : );
189+ stringColor = sprintf(' rgb(%f ,%f ,%f )' , numColor );
190+ end
0 commit comments