Debian Codegraph @

texmf-dist/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex

raw
1 %--------------------------------------------
2 %
3 % Package pgfplots
4 %
5 % Provides a user-friendly interface to create function plots (normal
6 % plots, semi-logplots and double-logplots).
7 %
8 % It is based on Till Tantau's PGF package.
9 %
10 % Copyright 2007-2015 by Christian Feuersänger.
11 %
12 % This program is free software: you can redistribute it and/or modify
13 % it under the terms of the GNU General Public License as published by
14 % the Free Software Foundation, either version 3 of the License, or
15 % (at your option) any later version.
16 %
17 % This program is distributed in the hope that it will be useful,
18 % but WITHOUT ANY WARRANTY; without even the implied warranty of
19 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 % GNU General Public License for more details.
21 %
22 % You should have received a copy of the GNU General Public License
23 % along with this program. If not, see <http://www.gnu.org/licenses/>.
24 %
25 %--------------------------------------------
26
27 % The low-level tikz plot handler for 3D mesh and surface plots.
28 %
29 % It expects
30 % a) a coordinate stream which is a linearized matrix, iterated either
31 % rowwise or column wise,
32 % b) the current set of options in /pgfplots/mesh/.
33 %
34 %
35 % ATTENTION:
36 % this handler is NOT as general as the others. In particular, it
37 % can't be interrupted by TeX groups: every single statement,
38 % starting with streamstart and ending with stream end, must be in
39 % the same scope!
40 %
41 % As a consequence, you can't use this handler inside of (all) TikZ
42 % input streams. Try it out. It will work in pgfplots, however.
43 %
44 % Furthermore, it relies on a couple of pgfplots macros. This may
45 % change in future versions.
46 % It relies on:
47 % - \ifpgfplots@curplot@threedim
48 % - \pgfplots@current@point@meta
49 % -> it also invokes \pgfplots@perpointmeta@preparetrafo and its
50 % @APPLY counterpart which checks for
51 % - \pgfplots@metamax
52 % If you use it outside of pgfplots, use
53 % \global\let\pgfplots@metamax=\pgfutil@empty
54 % This is can be used without an initialised
55 % pgfplots axes - as long as \pgfplots@current@point@meta is in
56 % the range [0,1000].
57 % - for the case 'shader=interp', a bounding box must be established
58 % before the plot is finished. This must be done using
59 % \def\pgfplotspointbbupperright{\pgfqpointxyz{2}{2}{0.9}}
60 % \def\pgfplotspointbblowerleft {\pgfqpointxyz{0}{0}{0.1}}
61 % or something like that.
62 %
63 % Besides these internals, it also relies on all public /pgfplots
64 % configuration keys related to mesh/surface plots.
65 %
66 % Please note that the 'z buffer' feature will not work without
67 % pgfplots (especially the z buffer=sort feature).
68 %
69 % Here is an example which compiles without a pgfplots axes:
70 % ----------------------------------------------------------
71 % \begin{tikzpicture}
72 % \scope[
73 % /pgfplots/.cd,
74 % surf,
75 % shader=faceted,
76 % mesh/rows=4,
77 % mesh/cols=4,
78 % mesh/num points=,
79 % /tikz/x={(0.44237cm,-0.07439cm)},
80 % /tikz/y={(0.30942cm,0.23932cm)},
81 % /tikz/z={(0.0cm,1.5cm)},
82 % ]
83 % \makeatletter
84 %
85 % \global\let\pgfplots@metamax=\pgfutil@empty
86 % \pgfplots@curplot@threedimtrue
87 %
88 % \pgfplotsplothandlermesh
89 % \pgfplotstreamstart
90 %
91 % \def\rangea{0.21}%
92 % \def\rangeb{0.9}%
93 %
94 % \pgfmathparse{1000/(\rangeb-\rangea)}
95 % \let\factor=\pgfmathresult
96 %
97 % \def\simplecoordinate(#1,#2,#3){%
98 % \pgfmathparse{\factor*(#3 - \rangea)}%
99 % \let\pgfplots@current@point@meta=\pgfmathresult
100 % \pgfplotstreampoint{\pgfqpointxyz{#1}{#2}{#3}}%
101 % }%
102 % % for the case 'shaer=interp':
103 % \def\pgfplotspointbbupperright{\pgfqpointxyz{2}{2}{0.9}}
104 % \def\pgfplotspointbblowerleft {\pgfqpointxyz{0}{0}{0.1}}
105 %
106 % \simplecoordinate(0,3,0.7)
107 % \simplecoordinate(1,3,0.5)
108 % \simplecoordinate(2,3,0.58)
109 % \simplecoordinate(3,3,0.9)
110 %
111 % \simplecoordinate(0,2,0.68)
112 % \simplecoordinate(1,2,0.22)
113 % \simplecoordinate(2,2,0.25)
114 % \simplecoordinate(3,2,0.4)
115 %
116 % \simplecoordinate(0,1,0.6)
117 % \simplecoordinate(1,1,0.3)
118 % \simplecoordinate(2,1,0.21)
119 % \simplecoordinate(3,1,0.3)
120 %
121 % \simplecoordinate(0,0,0.8)
122 % \simplecoordinate(1,0,0.56)
123 % \simplecoordinate(2,0,0.5)
124 % \simplecoordinate(3,0,0.75)
125 %
126 %
127 % \pgfplotstreamend
128 % \pgfusepath{stroke}
129 %
130 % \endscope
131 % \end{tikzpicture}
132 % ----------------------------------------------------------
133 % END OF EXAMPLE
134 % -> see also the legend image for mesh plots.
135 %
136
137 \input pgfplotsmeshplotimage.code.tex
138
139 \def\pgfplotsplothandlermesh{%
140 \def\pgfplotsplothandlername{mesh}%
141 %
142 % acquire values as they are known right now. Note that these values may change during the survey phase, so they will be updated later.
143 \pgfkeysgetvalue{/pgfplots/mesh/rows}\pgfplotsplothandlermesh@rows
144 \pgfkeysgetvalue{/pgfplots/mesh/cols}\pgfplotsplothandlermesh@cols
145 \pgfkeysgetvalue{/pgfplots/mesh/num points}\pgfplotsplothandlermesh@numpoints
146 \edef\pgfplotsplothandlermesh@numpoints{\pgfplotsplothandlermesh@numpoints}%
147 \edef\pgfplotsplothandlermesh@cols{\pgfplotsplothandlermesh@cols}%
148 \edef\pgfplotsplothandlermesh@rows{\pgfplotsplothandlermesh@rows}%
149 %
150 \pgfkeysgetvalue{/pgfplots/patch type}\pgfplotsplothandlermesh@patchclass
151 \ifx\pgfplotsplothandlermesh@patchclass\pgfplotsplothandlermesh@patchclass@defaulttext
152 \let\pgfplotsplothandlermesh@patchclass=\pgfutil@empty
153 \fi
154 \ifx\pgfplotsplothandlermesh@patchclass\pgfutil@empty
155 % assign default patch class.
156 \if0\pgfplotsplothandlermesh@matrixinput
157 \def\pgfplotsplothandlermesh@patchclass{triangle}%
158 \else
159 \def\pgfplotsplothandlermesh@patchclass{rectangle}%
160 \fi
161 \pgfkeyslet{/pgfplots/patch type}\pgfplotsplothandlermesh@patchclass
162 \fi
163 %
164 \if0\pgfplotsplothandlermesh@matrixinput
165 % mesh input=patches: simply skip empty input lines:
166 \pgfkeyssetvalue{/pgfplots/empty line}{none}%
167 \fi
168 %
169 \let\pgfplotsplothandlersurveystart=\pgfplotsplothandlersurveystart@mesh
170 \let\pgfplotsplothandlersurveypoint=\pgfplotsplothandlersurveypoint@mesh
171 \let\pgfplotsplothandlersurveyend=\pgfplotsplothandlersurveyend@mesh
172 \let\pgfplotsplothandlersurveyaftersetpointmeta=\pgfplotsplothandlersurveyaftersetpointmeta@mesh@cdatanormalize
173 \let\pgfplotsplothandlernotifyscanlinecomplete=\pgfplotsplothandlersurvey@mesh@scanlinecomplete
174 %
175 \def\pgfplotsplothandlerLUAfactory{pgfplots.MeshPlothandler.new}%
176 \if2\pgfplotsplothandlermesh@matrixinput
177 % mesh input=image
178 % this is currently unsupported in LUA:
179 \let\pgfplotsplothandlerLUAfactory=\pgfutil@empty
180 \fi
181 %
182 \pgfkeysgetvalue{/pgfplots/patch table/value}\pgfplotsplothandlermesh@patchtable
183 \ifx\pgfplotsplothandlermesh@patchtable\pgfutil@empty
184 \else
185 \def\pgfplotsplothandlermesh@matrixinput{0}% implies 'patch input=patches'
186 \let\pgfplotsplothandlersurveystart=\pgfplotsplothandlersurveystart@mesh@patchtable
187 \let\pgfplotsplothandlersurveypoint=\pgfplotsplothandlersurveypoint@mesh@patchtable
188 \let\pgfplotsplothandlersurveyend=\pgfplotsplothandlersurveyend@mesh@patchtable
189 %
190 % this is currently unsupported in LUA:
191 \let\pgfplotsplothandlerLUAfactory=\pgfutil@empty
192 \fi
193 \if0\pgfplotsplothandlermesh@colorinput
194 % mesh/color input=colormap
195 \else
196 % mesh/color input=explicit
197 \if0\csname pgfpmeta@\pgfplotspointmetainputhandler @issymbolic\endcsname
198 \pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{Sorry, color input!=colormap requires 'point meta=symbolic' or 'explicit symbolic'. Please adjust the format of your input point meta data}\pgfeov%
199 \fi
200 \fi
201 %
202 %
203 \pgfplotsifisvisualizationphase{%
204 \pgfplotsplothandlermesh@init@variables
205 }{}%
206 %
207 %
208 \def\pgf@plotstreamstart{%
209 % \scope
210 %
211 % this shouldn't be necessary, but it doesn't hurt either.
212 \pgfplots@perpointmeta@preparetrafo
213 %
214 %
215 \pgfplotsplothandlermesh@init@DECODE
216 \pgfplotsplothandlermesh@init@REFINE
217 %
218 \pgfutil@IfUndefined{pgfplots@drawmodes}{%
219 \let\pgfplots@drawmodes=\tikz@mode
220 \let\pgfplots@drawoptions=\tikz@options
221 }{}%
222 %
223 %
224 % Prepare color data source:
225 \ifx\pgfplotspointmetainputhandler\pgfutil@empty%
226 % oh. There is no color data!?
227 \pgfplotsplothandlermesh@init@path@without@point@meta
228 %
229 \else
230 \pgfplotsplothandlermesh@init@cdata
231 \pgfplotsplothandlermesh@init@shader
232 \pgfplotsplothandlermesh@init@flat@color
233 \fi
234 % PREPARE THE STREAM PROCESSING:
235 % handling of jumps.
236 \pgfplotsplothandlermesh@init@jumphandling
237 %
238 \ifpgfplotsplothandlermesh@shownormals
239 \let\pgfplotsplothandlermesh@show@normals@if@configured=\pgfplotsplothandlermesh@show@normals
240 % actually store 3d coordinates:
241 \let\pgfplotsplothandlermesh@serialize@logical@coords=\pgfplotsplothandlermesh@serialize@logical@coords@doit
242 \fi
243 %
244 % z buffering:
245 \pgfplotsplothandlermesh@init@zbuffer
246 %
247 \pgfplotsplothandlermesh@init@mesh@stream
248 %
249 \c@pgfplots@scanlineindex=0
250 }%
251 %
252 \let\pgfplotsplothandlerifcurrentpointcanbefirstlast=\pgfplotsplothandlerifcurrentpointcanbefirstlast@mesh
253 }%
254
255 \def\pgfplotsplothandlermesh@init@variables{%
256 % Check if the current shader needs to be reset.
257 % Do this early as some processing steps depend on it:
258 \if\pgfplots@meshmode m% mesh
259 % this is processed by the 'shader=flat' code below.
260 \def\pgfplotsplothandlermesh@shader{0}% 'flat'
261 \fi
262 \ifnum\pgfplotsplothandlermesh@shader>1% 'shader=interp' and 'shader=faceted interp'
263 \pgflibrarysurfshadingifactive
264 {}%
265 {%
266 \pgfutil@ifundefined{pgfplotsplothandlermesh@shader@warning}{%
267 \pgfplots@error{Sorry, surface shading (shader=interp) is NOT available for the selected driver `\pgfsysdriver'. I will use 'shader=flat' if you continue now}%
268 \gdef\pgfplotsplothandlermesh@shader@warning{x}%
269 }{}%
270 \def\pgfplotsplothandlermesh@shader{0}%
271 }%
272 \fi
273 %
274 \def\pgfplotsplothandlermesh@ONEDIMMODE{0}%
275 \pgfplotsplothandlermesh@init@meshkeys
276 %
277 %
278 \let\pgfplotsplothandlermesh@patchclass@input=\pgfplotsplothandlermesh@patchclass
279 \let\pgfplotsplothandlermesh@patchclass@output=\pgfplotsplothandlermesh@patchclass@input
280 \if0\pgfplotsplothandlermesh@triangulate
281 \else
282 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@input}{triangulate class}%
283 \let\pgfplotsplothandlermesh@patchclass@output=\pgfplotsretval
284 \fi
285 %
286 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@input}{init}%
287 \ifx\pgfplotsplothandlermesh@patchclass@input\pgfplotsplothandlermesh@patchclass@output
288 \else
289 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{init}%
290 \fi
291 %
292 % assign boolean:
293 \ifcase\pgfplotsplothandlermesh@matrixinput
294 % mesh input=patches
295 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
296 \or
297 % mesh input=lattice
298 \def\b@pgfplotsplothandlermesh@matrixoutput{1}%
299 \or
300 % mesh input=image
301 % while it _could_ potentially provide matrix output, the
302 % implementation is quite involved. We don't have it.
303 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
304 \fi
305 %
306 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{allow matrix}%
307 \if0\pgfplotsretval
308 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
309 \fi
310 \ifnum\pgfkeysvalueof{/pgfplots/patch refines}>0
311 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
312 \fi
313 \if1\pgfplotsaxisplothasjumps
314 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
315 \fi
316 \if1\pgfplotsaxisplothasunboundedpointmeta
317 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
318 \fi
319 \if\pgfplotsplothandlermesh@zbuffer@choice4% 'z buffer=sort':
320 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
321 \fi
322 %
323 \if2\pgfplotsplothandlermesh@shader
324 % shader=interp
325 %
326 \pgfkeysgetvalue{/pgfplots/mesh/interior colormap name}\pgfplots@loc@TMPc
327 \ifx\pgfplots@loc@TMPc\pgfutil@empty
328 \else
329 \pgfplotswarning{interior colormap inefficient}\pgfeov%
330 \pgfplotsset{shader=faceted interp,faceted color=none}%
331 \fi
332 \fi
333 \if2\pgfplotsplothandlermesh@shader
334 % shader=interp
335 \if0\pgfplotsplothandlermesh@triangulate
336 % patch to triangles=false
337 \else
338 % no matrix output possible:
339 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
340 \fi
341 \else
342 % 'shader!=interp'
343 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
344 \fi
345 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{get pdf shading type}%
346 \if5\pgfplotsretval
347 \else
348 \def\b@pgfplotsplothandlermesh@matrixoutput{0}%
349 \fi
350 %
351 % special handling: check if Type=5 shadings need to be
352 % converted to Type=4
353 \if0\b@pgfplotsplothandlermesh@matrixoutput
354 % no matrix output possible
355 \if5\pgfplotsretval
356 % pdf shading type=5 (matrix output)
357 \if2\pgfplotsplothandlermesh@shader
358 % shader=interp
359 %
360 % FIXME : I am unsure if this here is still
361 % necessary as of 3fc734d7ac3020600c06258b1bc80b22da53edf3
362 % -> perhaps the check can be skipped entirely.
363 %
364 % oh. shading type=5 is *essentially* the same as
365 % matrix output, but matrix output is forbidden.
366 % In that case, triangulate the matrix and shade the
367 % triangles:
368 \def\pgfplotsplothandlermesh@triangulate{1}%
369 \def\pgfplotsplothandlermesh@patchclass@output{triangle}%
370 % Note shader=faceted interp can be written as
371 % matrix -- it shades individual elements anyway;
372 % and one single patch can be written as matrix.
373 \fi
374 \fi
375 \fi
376 %
377 %
378 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{LUA class}%
379 \ifx\pgfplotsretval\pgfutil@empty
380 \let\pgfplotsplothandlerLUAvisualizerfactory=\pgfutil@empty
381 \else
382 \edef\pgfplotsplothandlerLUAvisualizerfactory{
383 function(plothandler) return pgfplots.MeshVisualizer.new(
384 plothandler,
385 \pgfplotsretval(),
386 pgfplots.pgftonumber("\pgfkeysvalueof{/pgfplots/mesh/rows}"),
387 pgfplots.pgftonumber("\pgfkeysvalueof{/pgfplots/mesh/cols}"),
388 \if0\pgfplots@plot@mesh@ordering true\else false\fi,
389 \if1\pgfplotsplothandlermesh@matrixinput true\else false\fi,
390 \if1\b@pgfplotsplothandlermesh@matrixoutput true\else false\fi,
391 \if4\pgfplotsplothandlermesh@zbuffer@choice true\else false\fi)% 'z buffer=sort'
392 end
393 }%
394 \fi
395 }%
396
397 \def\pgfplotsplothandlerifcurrentpointcanbefirstlast@mesh#1#2{%
398 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{if current point can be first last}{#1}{#2}%
399 }%
400
401 % Assigns default values to 'rows' and 'cols' in case
402 % their values are empty.
403 %
404 % PRECONDITION:
405 % The values of
406 % - '/pgfplots/mesh/rows'
407 % - '/pgfplots/mesh/cols'
408 % - '/pgfplots/mesh/num points'
409 % - \pgfplotsscanlinelength
410 % - '/pgfplots/mesh/ordering'
411 % are assigned properly.
412 %
413 % POSTCONDITION:
414 % 'rows' and 'cols' now incorporates \pgfplotsscanlinelength if
415 % their values had been empty. However, there may still be empty
416 % values.
417 %
418 % @see \pgfplotsautocompletemeshkeys
419 \def\pgfplotspreparemeshkeydefaults{%
420 \pgfplots@autocomplete@meshkeys0%
421 }%
422
423 % Completes and sanitizes 'mesh/rows' and 'mesh/cols' such that they
424 % have useful integer values afterwards.
425 %
426 % This method works similarly to \pgfplotspreparemeshkeydefaults.
427 % However, it really completes values and issues error messages if
428 % that proves to be impossible.
429 %
430 % PRECONDITION:
431 % The values of
432 % - '/pgfplots/mesh/rows'
433 % - '/pgfplots/mesh/cols'
434 % - '/pgfplots/mesh/num points'
435 % - '/pgfplots/mesh/ordering'
436 % are assigned properly.
437 % If
438 % - \pgfplotsscanlinelength
439 % exists and is positive, it may also be used.
440 %
441 % POSTCONDITION:
442 % 'rows' and 'cols' have useful integer values.
443 \def\pgfplotsautocompletemeshkeys{%
444 \pgfplots@autocomplete@meshkeys1%
445 }%
446 \def\pgfplots@autocomplete@meshkeys#1{%
447 % For #1 = 0, the values are only partially completed (which is
448 % also compatible with patch plots)
449 %
450 % get (potentially) updated values:
451 \pgfkeysgetvalue{/pgfplots/mesh/rows}\pgfplotsplothandlermesh@rows
452 \pgfkeysgetvalue{/pgfplots/mesh/cols}\pgfplotsplothandlermesh@cols
453 \pgfkeysgetvalue{/pgfplots/mesh/num points}\pgfplotsplothandlermesh@numpoints
454 \edef\pgfplotsplothandlermesh@numpoints{\pgfplotsplothandlermesh@numpoints}%
455 \edef\pgfplotsplothandlermesh@cols{\pgfplotsplothandlermesh@cols}%
456 \edef\pgfplotsplothandlermesh@rows{\pgfplotsplothandlermesh@rows}%
457 %
458 \def\pgfplots@loc@TMPa{0}%
459 \ifpgfplots@curplot@threedim
460 \def\pgfplots@loc@TMPa{1}%
461 \else
462 \if s\pgfplots@meshmode
463 % we have a 'surf' plot. That doesn't make sense unless
464 % one has a matrix, even for a two--dimensional plot. Try it.
465 \def\pgfplots@loc@TMPa{1}%
466 \fi
467 \fi
468 \if1\pgfplots@loc@TMPa
469 \ifx\pgfplotsplothandlermesh@rows\pgfutil@empty
470 \ifx\pgfplotsplothandlermesh@cols\pgfutil@empty
471 \pgfutil@ifundefined{pgfplotsscanlinelength}{\def\pgfplotsscanlinelength{-1}}{}%
472 \ifpgfplots@scanline@verbose
473 \ifnum\pgfplotsscanlinelength>0
474 % we have scanlinelength set! Use it:
475 \message{PGFPlots: Scanline length is \pgfplotsscanlinelength.}%
476 \else
477 \ifnum\pgfplotsscanlinelength=-2
478 \message{PGFPlots: Scanline length could not be determined since multiple, different scan line lengths have been found.}%
479 \else
480 \message{PGFPlots: No end-of-scanline marker found in input stream.}%
481 \fi
482 \fi
483 \fi
484 \ifnum\pgfplotsscanlinelength>0
485 % we have scanlinelength set! Use it:
486 \if\pgfplots@plot@mesh@ordering0%
487 % ordering = x varies= rowwise -> scanline is cols!
488 \edef\pgfplotsplothandlermesh@cols{\pgfplotsscanlinelength}%
489 \else
490 % ordering = y varies = colwise: scanline is rows!
491 \edef\pgfplotsplothandlermesh@rows{\pgfplotsscanlinelength}%
492 \fi
493 \else
494 \if1#1%
495 % try to get reasonable values:
496 \ifx\pgfplotsplothandlermesh@numpoints\pgfutil@empty
497 \pgfplots@error{Sorry, a mesh needs either '[mesh/rows=<N>]' or '[mesh/cols=<N>]' set - or at least '[mesh/num points=<N>]'. But it did not find any of them...}%
498 \def\pgfplotsplothandlermesh@cols{5}%
499 \def\pgfplotsplothandlermesh@rows{5}%
500 \else
501 % We don't have rows/cols. Well, try using
502 % sqrt(num points) for both of them!
503 \ifnum\pgfplotsplothandlermesh@numpoints<16380
504 \pgfmath@basic@sqrt@{\pgfplotsplothandlermesh@numpoints}%
505 \else
506 \pgfmathfloatparsenumber{\pgfplotsplothandlermesh@numpoints}%
507 \pgfmathfloatsqrt@{\pgfmathresult}%
508 \pgfmathfloattofixed{\pgfmathresult}%
509 \fi
510 \begingroup
511 % Try whether this rows*rows yields numpoints:
512 \afterassignment\pgfplots@gobble@until@relax
513 \c@pgf@counta=\pgfmathresult\relax
514 \c@pgf@countb=\c@pgf@counta
515 \multiply\c@pgf@counta by\c@pgf@counta
516 \def\pgfplotsretval{1}%
517 \ifnum\c@pgf@counta=\pgfplotsplothandlermesh@numpoints\relax
518 % ok, rows*rows = numpoints.
519 \edef\pgfplotsplothandlermesh@rows{\the\c@pgf@countb}%
520 \else
521 % oh. Did not work. Check for rounding errors:
522 \c@pgf@counta=\c@pgf@countb
523 \advance\c@pgf@counta by1
524 \c@pgf@countb=\c@pgf@counta
525 \multiply\c@pgf@counta by\c@pgf@counta
526 \ifnum\c@pgf@counta=\pgfplotsplothandlermesh@numpoints
527 % ok, (rows+1)*(rows+1) = numpoints.
528 \edef\pgfplotsplothandlermesh@rows{\the\c@pgf@countb}%
529 \else
530 % no... did not work. num points doesn't
531 % appear to be a squared number.
532 \def\pgfplotsretval{0}%
533 \edef\pgfplotsplothandlermesh@rows{5}%
534 \fi
535 \fi
536 \if\pgfplotsretval1
537 \pgfplotswarning{matrix delinearize uses sqrt}{\pgfplotsplothandlermesh@rows}{\pgfplotsplothandlermesh@cols}{\pgfplotsplothandlermesh@numpoints}{\pgfmathresult}\pgfeov%
538 \else
539 \pgfplots@error{Sorry, 'plot mesh' needs either '[mesh/rows=<N>]' or '[mesh/cols=<N>]' set,
540 but it did not find any of them.
541 I also tried rows = sqrt(num points) = sqrt(\pgfplotsplothandlermesh@numpoints) = \pgfmathresult\space without success.}%
542 \fi
543 \pgfmath@smuggleone\pgfplotsplothandlermesh@rows
544 \endgroup
545 \let\pgfplotsplothandlermesh@cols=\pgfplotsplothandlermesh@rows
546 \fi
547 \else
548 % #1=0 -> leave them empty.
549 \fi
550 \fi
551 \fi
552 \fi
553 \if1#1%
554 \ifx\pgfplotsplothandlermesh@rows\pgfutil@empty
555 \ifx\pgfplotsplothandlermesh@cols\pgfutil@empty
556 \else
557 % Compute 'rows' out of 'num points' and 'cols':
558 \ifx\pgfplotsplothandlermesh@numpoints\pgfutil@empty
559 \pgfplots@error{Sorry, matrix input needs a valid '[mesh/num points=<N>]' variable if only one of '[mesh/rows=<N>]' or '[mesh/cols=<N>]' is given.}%
560 \def\pgfplotsplothandlermesh@numpoints{100}%
561 \fi
562 \begingroup
563 \c@pgf@counta=\pgfplotsplothandlermesh@numpoints\relax
564 \divide\c@pgf@counta by\pgfplotsplothandlermesh@cols\relax
565 \xdef\pgfplots@glob@TMPa{\the\c@pgf@counta}%
566 \endgroup
567 \let\pgfplotsplothandlermesh@rows=\pgfplots@glob@TMPa
568 \fi
569 \else
570 \ifx\pgfplotsplothandlermesh@cols\pgfutil@empty
571 % Compute 'cols' out of 'num points' and 'rows':
572 \ifx\pgfplotsplothandlermesh@numpoints\pgfutil@empty
573 \pgfplots@error{Sorry, matrix input needs a valid '[mesh/num points=<N>]' variable if only one of '[mesh/cols=<N>]' or '[mesh/rows=<N>]' is given.}%
574 \def\pgfplotsplothandlermesh@numpoints{100}%
575 \fi
576 \begingroup
577 \c@pgf@counta=\pgfplotsplothandlermesh@numpoints\relax
578 \divide\c@pgf@counta by\pgfplotsplothandlermesh@rows\relax
579 \xdef\pgfplots@glob@TMPa{\the\c@pgf@counta}%
580 \endgroup
581 \let\pgfplotsplothandlermesh@cols=\pgfplots@glob@TMPa
582 \fi
583 \fi
584 \ifx\pgfplotsplothandlermesh@numpoints\pgfutil@empty
585 \c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@rows\relax
586 \multiply\c@pgfplots@scanlineindex by \pgfplotsplothandlermesh@cols\relax
587 \edef\pgfplotsplothandlermesh@numpoints{\the\c@pgfplots@scanlineindex}%
588 \fi
589 %
590 \c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@rows\relax
591 \multiply\c@pgfplots@scanlineindex by\pgfplotsplothandlermesh@cols\relax
592 \ifnum\c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@numpoints\relax
593 \else
594 \ifcase\pgfplots@mesh@checkmode\relax
595 % mesh/check=false
596 \def\pgfplots@loc@TMPa##1{}%
597 \or
598 % mesh/check=warning
599 \def\pgfplots@loc@TMPa##1{\pgfplotsthrow@warning{##1}}%
600 \or
601 % mesh/check=error
602 \def\pgfplots@loc@TMPa##1{\pgfplots@error{##1}}%
603 \fi
604 \pgfplotswarning{matrix check}{\pgfplots@loc@TMPa}{\pgfplotsplothandlermesh@rows}{\pgfplotsplothandlermesh@cols}{\pgfplotsplothandlermesh@numpoints}{\the\c@pgfplots@scanlineindex}\pgfeov%
605 \fi
606 \fi
607 \else
608 % 2d visualization has no mesh:
609 \edef\pgfplotsplothandlermesh@rows{\pgfplotsplothandlermesh@numpoints}%
610 \def\pgfplotsplothandlermesh@cols{1}%
611 \fi
612 %
613 \def\pgfplots@loc@TMPa{\pgfkeyssetvalue{/pgfplots/mesh/rows}}%
614 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplotsplothandlermesh@rows}%
615 \def\pgfplots@loc@TMPa{\pgfkeyssetvalue{/pgfplots/mesh/cols}}%
616 \expandafter\pgfplots@loc@TMPa\expandafter{\pgfplotsplothandlermesh@cols}%
617 }%
618
619 %%
620 %% Helper structs for patch plots (surfaces)
621
622 % #1: the canvas x coordinate
623 % #2: the canvas y coordinate
624 % #3: the point meta data (cdata)
625 % #4: the vertex'es depth (if required)
626 % #5: the 3d coordinates of the vertex (will only be stored if it is deemed necessary)
627 \def\pgfplotspatchvertex#1#2#3#4:#5\endvertex{%
628 \def\pgfplotspatchvertexstruct{{#1}{#2}{#3}#4:#5}%
629 \def\pgfplotspatchvertexx{#1}%
630 \def\pgfplotspatchvertexy{#2}%
631 \def\pgfplotspatchvertexmeta{#3}%
632 \def\pgfplotspatchvertexdepth{#4}%
633 \def\pgfplotspatchvertexcoords{#5}%
634 }%
635
636 % Assumes that #1 expands to an argument of \pgfplotspatchvertex and
637 % that #2 is a macro containing another patch vertex.
638 %
639 % It then replaces #2 by a new vector which is equal to #2 except for
640 % the point meta which is taken from #1.
641 \def\pgfplotspatchvertexcopymeta#1\to#2{%
642 \begingroup
643 \expandafter\pgfplotspatchvertex#1\endvertex
644 \let\pgfplots@loc@TMPa=\pgfplotspatchvertexmeta
645 \expandafter\pgfplotspatchvertex#2\endvertex
646 \xdef\pgfplots@glob@TMPc{%
647 {\pgfplotspatchvertexx}%
648 {\pgfplotspatchvertexy}%
649 {\pgfplots@loc@TMPa}%
650 \pgfplotspatchvertexdepth:\pgfplotspatchvertexcoords
651 }%
652 \endgroup
653 \let#2=\pgfplots@glob@TMPc
654 }%
655
656 % Same as \pgfplotspatchvertexcopymeta but it becomes a no-op if the
657 % point meta in #1 is bounded (according to
658 % \pgfplotsifpointmetaisbounded)
659 \def\pgfplotspatchvertexcopymetaifbounded#1\to#2{%
660 \begingroup
661 \expandafter\pgfplotspatchvertex#1\endvertex
662 \let\pgfplots@loc@TMPa=\pgfplotspatchvertexmeta
663 \pgfplotsifpointmetaisbounded{\pgfplots@loc@TMPa}{%
664 \expandafter\pgfplotspatchvertex#2\endvertex
665 \xdef\pgfplots@glob@TMPc{%
666 {\pgfplotspatchvertexx}%
667 {\pgfplotspatchvertexy}%
668 {\pgfplots@loc@TMPa}%
669 \pgfplotspatchvertexdepth:\pgfplotspatchvertexcoords
670 }%
671 }{%
672 \global\let\pgfplots@glob@TMPc=#2%
673 }%
674 \endgroup
675 \let#2=\pgfplots@glob@TMPc
676 }%
677
678 \def\pgfplotspointpatchvertex#1#2#3#4:#5\endvertex{%
679 \global\pgf@x=#1
680 \global\pgf@y=#2
681 }%
682
683 % Allows to combined different vertices in the form
684 % \pgfplotspatchvertexaccumstart
685 % \expandafter\pgfplotspatchvertexadd\vertexA\times{0.25}%
686 % \expandafter\pgfplotspatchvertexadd\vertexB\times{0.5}%
687 % \expandafter\pgfplotspatchvertexadd\vertexC\times{0.75}%
688 % \pgfplotspatchvertexfinish\finalvertex
689 % --> now, \finalvertex contains the result vertex, 0.25*A + 0.5*B + 0.75*C .
690 %
691 % THERE MUST NOT BE MATH INBETWEEN.
692 % More precisely, this overwrites the macros
693 % \pgf@x,\pgf@y, \pgf@xa,\pgf@ya, \pgf@yb, \pgfmathresult and \pgfplotspatchvertexdepth
694 \def\pgfplotspatchvertexaccumstart{%
695 \pgf@xa=0pt
696 \pgf@ya=0pt
697 \pgf@yb=0pt
698 \def\b@pgfplotspatchvertexaccum@ignore@unbounded@metadata{0}%
699 \if0\pgfplotsplothandlermesh@colorinput
700 % mesh/color input=colormap
701 %\if m\pgfplots@colormap@access
702 \iftrue
703 % colormap access=map
704 \pgfplotscoordmath{meta}{zero}%
705 \else
706 % colormap access=direct
707 % FIXME : this causes lots of problems because the result is
708 % of an unexpected format at consumer side:
709 \begingroup
710 \pgfplotscolorzero{\pgfplotsplothandlermesh@explicit@color@num@comps}%
711 \let\pgfmathresult=\pgfplotsretval
712 \pgfmath@smuggleone\pgfmathresult
713 \endgroup
714 \fi
715 \else
716 % mesh/color input=explicit
717 \begingroup
718 \pgfplotscolorzero{\pgfplotsplothandlermesh@explicit@color@num@comps}%
719 \let\pgfmathresult=\pgfplotsretval
720 \pgfmath@smuggleone\pgfmathresult
721 \endgroup
722 \fi
723 }%
724
725 % if this is called, all following accumulation commands will replace unbounded point meta by the fixed zero value.
726 \def\pgfplotspatchvertexaccum@configure@ignore@unboundedmetadata{%
727 \def\b@pgfplotspatchvertexaccum@ignore@unbounded@metadata{1}%
728 }%
729
730 % #1 scale
731 % #2 meta
732 \def\pgfplotspatchvertexaddscaledmeta@if@applicable@colormap#1#2{%
733 \let\pgfmathresult@=\pgfmathresult
734 \if1\b@pgfplotspatchvertexaccum@ignore@unbounded@metadata
735 \pgfplotsifpointmetaisbounded{#2}{\pgfplots@loc@tmptrue}{\pgfplots@loc@tmpfalse}%
736 \else
737 \pgfplots@loc@tmptrue
738 \fi
739 \ifpgfplots@loc@tmp
740 %\if m\pgfplots@colormap@access
741 \iftrue
742 % colormap access=map
743 \pgfplotscoordmath{meta}{parsenumber}{#1}%
744 \pgfplotscoordmath{meta}{op}{multiply}{{#2}{\pgfmathresult}}%
745 \pgfplotscoordmath{meta}{op}{add}{{\pgfmathresult@}{\pgfmathresult}}%
746 \else
747 % colormap access=direct
748 % FIXME : this causes lots of problems because the result is
749 % of an unexpected format at consumer side:
750 % colormap access=direct
751 % interpolate colors, not their indices:
752 \begingroup
753 \pgfplotscoordmath{meta}{parsenumber}{#1}%
754 \pgfplotscoordmath{meta}{tofixed}{\pgfmathresult}%
755 \pgfplotscolormapgetindex{\pgfmathresult}{\pgfplotsplothandlermesh@colormapname}%
756 \global\let\pgfplots@glob@TMPc=\pgfmathresult
757 \endgroup
758 \pgfplotspatchvertexaddscaledmeta@if@applicable@explicit{#1}{\pgfplots@glob@TMPc}%
759 \fi
760 \else
761 \pgfplotscoordmath{meta}{op}{multiply}{{\pgfplots@metamin}{\pgfmathresult}}%
762 \pgfplotscoordmath{meta}{op}{add}{{\pgfmathresult@}{\pgfmathresult}}%
763 \fi
764 }%
765
766 % #1 scale
767 % #2 meta
768 \def\pgfplotspatchvertexaddscaledmeta@if@applicable@explicit#1#2{%
769 \if1\b@pgfplotspatchvertexaccum@ignore@unbounded@metadata
770 \edef\pgfmathresult@{#2}%
771 \ifx\pgfmathresult@\pgfutil@empty
772 \pgfplots@loc@tmpfalse
773 \else
774 \pgfplots@loc@tmptrue
775 \fi
776 \else
777 \pgfplots@loc@tmptrue
778 \fi
779 \let\pgfmathresult@=\pgfmathresult
780 \ifpgfplots@loc@tmp
781 \begingroup
782 \pgfplotscoloraddweighted{\pgfplotsplothandlermesh@explicit@color@num@comps}
783 {\pgfmathresult@}{#1}{#2}%
784 \let\pgfmathresult=\pgfplotsretval
785 \pgfmath@smuggleone\pgfmathresult
786 \endgroup
787 \fi
788 }
789
790 % #1: the patch's x coordinate
791 % #2: the patch's y coordinate
792 % #3: the patch's point meta value
793 % #4: depth (if required)
794 % #5: 3d coordinate of the vertex
795 \def\pgfplotspatchvertexadd#1#2#3#4:#5\times#6{%
796 \global\pgf@x=#1 %
797 \global\pgf@y=#2 %
798 \advance\pgf@xa by#6\pgf@x
799 \advance\pgf@ya by#6\pgf@y
800 \if0\pgfplotsplothandlermesh@colorinput
801 % mesh/color input=colormap
802 \pgfplotspatchvertexaddscaledmeta@if@applicable@colormap{#6}{#3}%
803 \else
804 % mesh/color input=explicit
805 \pgfplotspatchvertexaddscaledmeta@if@applicable@explicit{#6}{#3}%
806 \fi
807 \def\pgfplotspatchvertexdepth{#4}%
808 \ifx\pgfplotspatchvertexdepth\pgfutil@empty
809 \else
810 \global\pgf@y=#4pt %
811 \advance\pgf@yb by#6\pgf@y
812 \fi
813 }%
814 \def\pgfplotspatchvertexfinish#1{%
815 \edef#1{%
816 {\the\pgf@xa}%
817 {\the\pgf@ya}%
818 {\pgfmathresult}%
819 \ifx\pgfplotspatchvertexdepth\pgfutil@empty\else\pgf@sys@tonumber\pgf@yb\fi%
820 :%
821 }%
822 }
823 % Same as \pgfplotspatchvertexadd, but it only adds the X and Y
824 % coordinates (ignoring the rest).
825 \def\pgfplotspatchvertexaddXY#1#2#3#4:#5\times#6{%
826 \global\pgf@x=#1
827 \global\pgf@y=#2
828 \advance\pgf@xa by#6\pgf@x
829 \advance\pgf@ya by#6\pgf@y
830 }%
831 % Same as \pgfplotspatchvertexfinish, but it only saves X and Y.
832 \def\pgfplotspatchvertexfinishXY#1{%
833 \edef#1{{\the\pgf@xa}{\the\pgf@ya}{}:}%
834 }
835
836 % #1 class name
837 % #2 method
838 % <any method arguments follow>
839 \def\pgfplotspatchclass#1#2{%
840 \pgfutil@ifundefined{pgfpptch@#1@#2}{%
841 \pgfplotspatchclasserror{#1}{#2}%
842 }{%
843 \edef\pgfplotspatchclassname{#1}%
844 \csname pgfpptch@#1@#2\endcsname
845 }%
846 }%
847 \def\pgfplotspatchclasserror#1#2{%
848 \pgfutil@ifundefined{pgfpptch@#1@}{%
849 \pgfplots@error{Sorry, the 'patch type=#1' is not defined. Maybe you misspelled it? Or perhaps you need to load \string\usepgfplotslibrary{patchplots}?}%
850 }{%
851 \pgfplots@error{Sorry, the patch class '#1' has no method '#2' (or it is not yet implemented)}%
852 }%
853 }%
854
855 % #1: will be expanded with \edef
856 \def\pgfplotsplothandlermesh@setnextvertex#1{%
857 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set next vertex}{#1}%
858 }%
859
860 % Declares a new patch class named #1.
861 %
862 % #1: a string name.
863 % #2: methods defining the class, provided as key values. See the
864 % predefined classes to adjust your own ones. Documentation about the
865 % available methods and their arguments can be found below in this
866 % file.
867 %
868 % @see \usepgfplotslibrary{patchplots}
869 \def\pgfplotsdeclarepatchclass#1#2{%
870 \edef\pgfplotsdeclarepatchclass@{@#1@}%
871 \pgfutil@ifundefined{pgfpptch@#1@}{%
872 % Ok. This is the FIRST declaration of this patch class.
873 % Define some default algorithms.
874 %
875 \expandafter\def\csname pgfpptch@#1@\endcsname{#1}%
876 \pgfqkeys{/pgfplots/@declare patch}{%
877 init=,
878 allow matrix=\def\pgfplotsretval{0},
879 init pdf shading=,
880 stream to shader={%
881 %\message{\pgfplotspatchclassname: stream to shader: Starting ^^J}%
882 \pgfplotspatchclass{\pgfplotspatchclassname}{foreach vertex}{%
883 %\message{vertex (\pgfplotspatchvertexx,\pgfplotspatchvertexy[\pgfplotspatchvertexmeta]. ^^J}%
884 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
885 \pgfplotsaxisvisphasetransformpointmeta
886 \pgfplotslibrarysurfstreamcoord{%
887 \global\pgf@x=\pgfplotspatchvertexx\space
888 \global\pgf@y=\pgfplotspatchvertexy\space
889 }{\pgfplotspointmetatransformed}%
890 }%
891 },%
892 fill path={%
893 \def\b@pgfplotsmeshplothandler@fillpath@default@isfirst{1}%
894 \pgfplotspatchclass{\pgfplotspatchclassname}{foreach vertex}{%
895 %\message{vertex (\pgfplotspatchvertexx,\pgfplotspatchvertexy[\pgfplotspatchvertexmeta]. ^^J}%
896 \if1\b@pgfplotsmeshplothandler@fillpath@default@isfirst
897 \expandafter\pgfpathmoveto
898 \else
899 \expandafter\pgfpathlineto
900 \fi
901 {\global\pgf@x=\pgfplotspatchvertexx\space\global\pgf@y=\pgfplotspatchvertexy\space}%
902 \def\b@pgfplotsmeshplothandler@fillpath@default@isfirst{0}%
903 }%
904 \pgfpathclose
905 },
906 get num cdata vertices=\pgfplotspatchclass{\pgfplotspatchclassname}{get num vertices},
907 get dimension=\def\pgfplotsretval{2},
908 supports global path=\def\pgfplotsretval{0},
909 set edge visible=\expandafter\edef\csname pgfppatchedge@##1\endcsname{##2},
910 uses view depth=\def\pgfplotsretval{0},
911 if current point can be first last=##1,
912 serialize except vertices=\let\pgfplotsretval\pgfutil@empty,
913 deserialize except vertices=##1,
914 serialize={%
915 % the default serialization is not necessarily the fastest
916 % possible. But it should work.
917 \pgfplotspatchclass{\pgfplotspatchclassname}{serialize except vertices}%
918 \t@pgfplots@toka=\expandafter{\pgfplotsretval
919 \let\pgfplotspatchready@defaultserialize=\pgfplotspatchready
920 \let\pgfplotspatchready=\relax
921 }%
922 \edef\pgfplotsretval{%
923 \noexpand\pgfplotspatchclass{\pgfplotspatchclassname}{new}%
924 \the\t@pgfplots@toka
925 }%
926 \pgfplotspatchclass{\pgfplotspatchclassname}{foreach vertex}{%
927 \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
928 \edef\pgfplotsretval{\the\t@pgfplots@toka
929 \noexpand\pgfplotspatchclass{\pgfplotspatchclassname}{set next vertex}{\pgfplotspatchvertexstruct}%
930 }%
931 }%
932 \expandafter\def\expandafter\pgfplotsretval\expandafter{\pgfplotsretval
933 \let\pgfplotspatchready=\pgfplotspatchready@defaultserialize
934 }%
935 },
936 deserialize=##1,
937 triangulate class=\def\pgfplotsretval{triangle},
938 triangulate={%
939 \pgfplots@error{triangulate: not yet implemented for \pgfplotspatchclassname}%
940 },%
941 refine={%
942 \let\pgfplotsrefinedpatchready=\pgfplotspatchready
943 \pgfplotspatchclass@recursiverefine{##1}%
944 },%
945 recursive refine@={%
946 \pgfplots@error{refine: not yet implemented for \pgfplotspatchclassname}%
947 },%
948 compute normal={%
949 \pgfplotsplothandlermesh@compute@normal@default
950 },%
951 sample in unit cube={%
952 \pgfplots@error{sample in unit cube: not implemented for \pgfplotspatchclassname}%
953 },
954 LUA class=,
955 }%
956 }{}%
957 %
958 %
959 \pgfqkeys{/pgfplots/@declare patch}{#2}%
960 %
961 %
962 \pgfutil@ifundefined{pgfpptch\pgfplotsdeclarepatchclass@ foreach cdata vertex}{%
963 \pgfutil@namelet
964 {pgfpptch\pgfplotsdeclarepatchclass@ foreach cdata vertex}
965 {pgfpptch\pgfplotsdeclarepatchclass@ foreach vertex}%
966 }{%
967 }%
968 \pgfutil@ifundefined{pgfpptch\pgfplotsdeclarepatchclass@ stroke path}{%
969 \pgfutil@namelet
970 {pgfpptch\pgfplotsdeclarepatchclass@ stroke path}
971 {pgfpptch\pgfplotsdeclarepatchclass@ fill path}%
972 }{%
973 }%
974 }%
975 \pgfqkeys{/pgfplots/@declare patch}{%
976 % may do any more or less global preparations. It is some sort (!)
977 % of constructor.
978 init/.code=
979 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ init\endcsname{#1}},%
980 allow matrix/.code=
981 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ allow matrix\endcsname{#1}},%
982 %
983 % FIXME : this is NOT properly used in higher order patches!?
984 % Uses view depth defines \pgfplotsretval to '1' if and only if it
985 % does ALWAYS needs the view depth. Note that 'z buffer=sort' will
986 % automatically provide the view depth. Use this key if view depth
987 % is necessary even for 'z buffer!=sort'.
988 uses view depth/.code=
989 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ uses view depth\endcsname{#1}},%
990 %
991 % creates a new patch. The vertices need to be added by 'set next
992 % vertex'
993 new/.code=
994 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ new\endcsname{#1}},%
995 %
996 % sets the next vertex value of the patch.
997 %
998 % if the patch has all expected vertices, \pgfplotspatchready is
999 % invoked and the next call to 'set next vertex' will start a new
1000 % patch.
1001 %
1002 % #1: encodes the current vertex such that
1003 % \pgfplotspatchvertex#1\endvertex
1004 % is accepted.
1005 set next vertex/.code=
1006 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ set next vertex\endcsname##1{#1}},%
1007 %
1008 %
1009 % Creates a new patch by means of sampling. The sampling is
1010 % applied in the unit cube [0,1]x[0,1] (unit interval if this is an 1d patch
1011 % type).
1012 %
1013 % 'sample in unit cube={<code to invoke for each sampled point>}'
1014 %
1015 % It will invoke <code to invoke for each sampled point> once for
1016 % every sampled vertex. The complete unit cube will be covered.
1017 % Depending on the patch type, either one or more patches are
1018 % required to fill the unit cube. As soon as one patch is ready,
1019 % \pgfplotspatchready will be invoked.
1020 %
1021 %
1022 % PRECONDITION:
1023 % -\pgfplotspatchready is defined.
1024 %
1025 % Arguments:
1026 % #1: code which will be invoked whenever a new coordinate is
1027 % ready. Inside of #1, the macros \pgfplotspatchclassx and
1028 % \pgfplotspatchclassy result in the x and y coordinate (inside
1029 % of the unit cube), in fixed point representation.
1030 %
1031 % Example:
1032 % \def\pgfplotspatchready{}
1033 % \pgfplotspatchclass{biquadratic}{sample in unit cube}{%
1034 % point ready at (\pgfplotspatchclassx, \pgfplotspatchclassy)
1035 % }
1036 sample in unit cube/.code=
1037 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ sample in unit cube\endcsname##1{#1}},%
1038 %
1039 % declares whether a single edge is visible or not.
1040 % #1: an integer denoting the edge, either 0,1,2,...,N-1 where N = num verts
1041 % #2: 0 if the edge is not to be stroked and 1 if it is stroked.
1042 %
1043 % This command doesn't need to be called; but if it is, it needs
1044 % to be called for every edge.
1045 %
1046 % ATTENTION: this is *only* used by 'stroke path'. You will never
1047 % need 'stroke path' unless some edges are invisible. If all edges
1048 % are visible, 'stroke path' and 'fill path' are the same.
1049 %
1050 % This is currently *only* used for triangle triangulations!
1051 set edge visible/.code=
1052 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ set edge visible\endcsname##1##2{#1}},%
1053 %
1054 % Defines \pgfplotsretval to be a serialized representation of
1055 % this patch.
1056 serialize/.code=
1057 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ serialize\endcsname{#1}},%
1058 % Defines \pgfplotsretval to be a serialized representation of
1059 % this patches extra data fields, excluding vertices.
1060 % This is often a NO-OP (unless 'set edge visible' has been used)
1061 serialize except vertices/.code=
1062 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ serialize except vertices\endcsname{#1}},%
1063 %
1064 % Restores a serialized representation from #1.
1065 deserialize/.code=
1066 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ deserialize\endcsname##1{#1}},%
1067 % Restores a serialized representation from #1. Only vertices are
1068 % not stored here.
1069 deserialize except vertices/.code=
1070 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ deserialize except vertices\endcsname##1{#1}},%
1071 %
1072 % issues \pgfplotspatchvertex{...}\endvertex for the first vertex.
1073 first vertex/.code=
1074 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ first vertex\endcsname{#1}},%
1075 % issues \pgfplotspatchvertex{...}\endvertex for the vertex which
1076 % was the first BEFORE any z buffer reorderings changed the
1077 % sequence (i.e. it undoes the effect of z buffer for the patch).
1078 first vertex before z buffer/.code=
1079 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ first vertex before z buffer\endcsname{#1}},%
1080 %
1081 % invokes
1082 % \pgfplotspatchvertex...\endvertex
1083 % #1
1084 % for the every vertex.
1085 foreach vertex/.code=
1086 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ foreach vertex\endcsname##1{#1}},%
1087 %
1088 % invokes
1089 % \pgfplotspatchvertex...\endvertex
1090 % #1
1091 % for every colored vertex.
1092 % See 'get num cdata vertices'
1093 foreach cdata vertex/.code=
1094 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ foreach cdata vertex\endcsname##1{#1}},%
1095 %
1096 % generates a pgf path which is readily usable for filling.
1097 fill path/.code=
1098 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ fill path\endcsname{#1}},%
1099 %
1100 % Similar to 'fill path', this here paints the edges. It is only
1101 % useful if 'set edge visible' is in use. In all other cases, it
1102 % is the same as 'fill path'
1103 %
1104 % This is currently *only* used for triangle triangulations!
1105 stroke path/.code=
1106 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ stroke path\endcsname{#1}},%
1107 %
1108 init pdf shading/.code=
1109 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ init pdf shading\endcsname{#1}},%
1110 stream to shader/.code=
1111 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ stream to shader\endcsname{#1}},%
1112 %
1113 % defines \pgfplotsretval to contain the number of vertices.
1114 get num vertices/.code=
1115 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ get num vertices\endcsname{#1}},%
1116 %
1117 % defines \pgfplotsretval to contain the number of vertices which have color data
1118 % attached. This is usually the same as 'get num vertices' (but
1119 % see coons patches).
1120 get num cdata vertices/.code=
1121 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ get num cdata vertices\endcsname{#1}},%
1122 %
1123 % defines \pgfplotsretval to contain the dimension of this patch
1124 % (either 1 for lines or 2 for patches).
1125 get dimension/.code=
1126 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ get dimension\endcsname{#1}},%
1127 %
1128 % defines \pgfplotsretval to be 1 if and only if the patch class
1129 % supports global paths.
1130 % A global path is one which is drawn as one huge, uninterrupted
1131 % PGF path (except for jumps perhaps). Its area can be filled,
1132 % i.e. it behaves exactly like the 'sharp' plot handler. This is
1133 % used implicitly if 'point meta=none' (if there is point meta
1134 % data, we always want individual path segments and \pgfusepath
1135 % them after each segment).
1136 supports global path/.code=
1137 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ supports global path\endcsname{#1}},%
1138 %
1139 % Approximates the given patch by at least one triangle.
1140 % For every finished triangle, \pgfplotspatchready will be invoked
1141 % and \pgfplotsplothandlermesh@patchclass will be set to triangle.
1142 % More precisely, it is expected to be set to the return value of
1143 % 'triangulate class'.
1144 triangulate/.code=
1145 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ triangulate\endcsname{#1}},%
1146 % Defines \pgfplotsretval to be the classname returned by
1147 % 'triangulate'. This is usually 'triangle'
1148 triangulate class/.code=
1149 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ triangulate class\endcsname{#1}},%
1150 %
1151 % Refines the given patch #1 times.
1152 % For every finished patch, \pgfplotspatchready will be invoked.
1153 refine/.code=
1154 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ refine\endcsname##1{#1}},%
1155 %
1156 % shared helper method which can be invoked recursively by refine.
1157 % the default implementation of 'refine' will invoke this one.
1158 %
1159 % #1: a serialized representation of the given patch. Use it to
1160 % restore the current patch in intermediate steps. Note that you
1161 % may not use \begingroup/\endgroup in this method; otherwise the
1162 % 'z buffer' algorithm will need to be done with \global (and I
1163 % don't want that. You probably neither).
1164 %
1165 % The refinement loop as such will be controlled by the default
1166 % implementation of 'refine'. This macro is ONLY to be called by the
1167 % default implementation of 'refine'! Overwriting it should
1168 % automatically yield refinement facilities.
1169 %
1170 % the macro \pgfplotspatchready should be called for each refined
1171 % element (happens automatically if you use 'set next vertex').
1172 %
1173 % POSTCONDITION:
1174 % the element has been refined once.
1175 recursive refine@/.code=
1176 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ recursive refine@\endcsname##1{#1}},%
1177 %
1178 get pdf shading type/.style={get pdf shading type*={\def\pgfplotsretval{#1}}},
1179 get pdf shading type*/.code=
1180 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ get pdf shading type\endcsname{#1}},%
1181 %
1182 % A method which defines \pgfplotsretval to be the normal of the current segment.
1183 % The values will be given in a format understood by
1184 % \pgfplotsmathvectortostring{\pgfplotsretval}{default}
1185 %
1186 % This method REQUIRES that 3d coordinates are stored (see \pgfplotsplothandlermesh@serialize@logical@coords).
1187 compute normal/.code=
1188 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ compute normal\endcsname{#1}},%
1189 %
1190 % executes '##1' if the current point can be the first or last
1191 % point of the patch. Executes ##2 if that is not the case.
1192 if current point can be first last/.code=
1193 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ if current point can be first last\endcsname##1##2{#1}},%
1194 %
1195 % Defines \pgfplotsretval to contain LUA code which returns a
1196 % factory method (with no arguments) which returns an instance of the
1197 % associated LUA pgfplots.PatchType
1198 %
1199 % If the returned \pgfplotsretval is empty: there is no LUA implementation.
1200 LUA class/.code=
1201 {\expandafter\def\csname pgfpptch\pgfplotsdeclarepatchclass@ LUA class\endcsname{\def\pgfplotsretval{#1}}},%
1202 }
1203
1204 % This implements 'compute normal' :
1205 \def\pgfplotsplothandlermesh@compute@normal@default{%
1206 \begingroup
1207 \c@pgf@countd=0
1208 \pgfplotspatchclass{\pgfplotspatchclassname}{foreach vertex}{%
1209 \ifx\pgfplotspatchvertexcoords\pgfutil@empty
1210 \pgfplotsplothandlermesh@compute@normal@error
1211 \fi
1212 \pgfplotsmathvectorfromstring{\pgfplotspatchvertexcoords}{default}%
1213 \expandafter\let\csname point\the\c@pgf@countd\endcsname=\pgfplotsretval
1214 \let\pointlast=\pgfplotsretval
1215 \advance\c@pgf@countd by1 %
1216 }%
1217 \pgfplotsmathvectorsubtract{\csname point1\endcsname}{\csname point0\endcsname}{default}%
1218 \let\diffA=\pgfplotsretval
1219 % Hm. usually, I would use \point2 here... but it turned out that
1220 % the result looks ugly for rectangular patches -- so I used the
1221 % last point instead (which is, at least, consistent with the
1222 % patch boundaries)
1223 \pgfplotsmathvectorsubtract{\csname pointlast\endcsname}{\csname point0\endcsname}{default}%
1224 \let\diffB=\pgfplotsretval
1225 \pgfplotsmathvectorcrossprod{\diffA}{\diffB}{default}%
1226 \let\crossAB=\pgfplotsretval
1227 % this here is an experiment to use the MEAN of two normal
1228 % vectors for rectangular patches... but it did not work as good
1229 % as expected:
1230 % \pgfplotspatchclass{\pgfplotspatchclassname}{get num vertices}%
1231 % \ifnum\pgfplotsretval=4
1232 % \pgfplotsmathvectorsubtract{\csname point3\endcsname}{\csname point0\endcsname}{default}%
1233 % \let\diffC=\pgfplotsretval
1234 % \pgfplotsmathvectorcrossprod{\diffB}{\diffC}{default}%
1235 % \let\crossBC=\pgfplotsretval
1236 % \pgfplotsmathvectoradd{\crossAB}{\crossBC}{default}%
1237 % \pgfplotscoordmath{default}{parsenumber}{0.5}%
1238 % \pgfplotsmathvectorscale{\pgfplotsretval}{\pgfmathresult}{default}%
1239 % \let\normal=\pgfplotsretval
1240 % \else
1241 \let\normal=\crossAB
1242 %\fi
1243 %
1244 % specific choices of z buffering change the sequence of points.
1245 % If the number of reversals is off, we need to switch the
1246 % normal's sign:
1247 \def\pgfplots@switch@normal@dir{0}%
1248 \if1\pgfplotsplothandlermesh@zbuffer@choice
1249 % z buffer=reverse x seq
1250 \def\pgfplots@switch@normal@dir{1}%
1251 \else
1252 \if2\pgfplotsplothandlermesh@zbuffer@choice
1253 % z buffer=reverse y seq
1254 \def\pgfplots@switch@normal@dir{1}%
1255 \fi
1256 \fi
1257 \if1\pgfplots@switch@normal@dir
1258 \pgfplotscoordmath{default}{parsenumber}{-1}%
1259 \pgfplotsmathvectorscale{\normal}{\pgfmathresult}{default}%
1260 \fi
1261 \pgfmath@smuggleone\pgfplotsretval
1262 \endgroup
1263 }%
1264 \def\pgfplotsplothandlermesh@compute@normal@error{%
1265 \pgfplots@error{Cannot compute normal vectors: due to some reason, only canvas coordinates of the involved patch are available in this context, but the original input coordinates are required. This indicates an incompatible combination of variables (sorry). Please report this as a bug}%
1266 }%
1267
1268 \def\pgfplotspatchclass@recursiverefine#1{%
1269 \c@pgf@counta=#1
1270 \ifnum\c@pgf@counta=1
1271 \let\pgfplotspatchready=\pgfplotsrefinedpatchready
1272 \else
1273 \advance\c@pgf@counta by-1
1274 \edef\pgfplotspatchready{\noexpand\pgfplotspatchclass@recursiverefine{\the\c@pgf@counta}}%
1275 \fi
1276 %
1277 \pgfplotspatchclass{\pgfplotspatchclassname}{serialize}%
1278 \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
1279 \t@pgfplots@tokc=\expandafter{\pgfplotspatchready}%
1280 \edef\pgfplots@loc@TMPa{%
1281 \noexpand\pgfplotspatchclass{\pgfplotspatchclassname}{deserialize}{\the\t@pgfplots@toka}%
1282 \noexpand\def\noexpand\pgfplotspatchready{\the\t@pgfplots@tokc}%
1283 \noexpand\def\noexpand\pgfplotspatchclassname{\pgfplotspatchclassname}% % FIXME: is that correct?
1284 }%
1285 \expandafter\pgfplotspatchclass@recursiverefine@\expandafter{\pgfplots@loc@TMPa}%
1286 }%
1287 \def\pgfplotspatchclass@recursiverefine@{%
1288 \pgfplotspatchclass{\pgfplotspatchclassname}{recursive refine@}%
1289 }%
1290
1291
1292 % sequence macros preferred over integer indices.
1293 % using characters avoids the extensive use of \csname ...\endcsname
1294 % and \expandafter which would be necessary for integer indices.
1295 \def\pgfpptchindexnext@A{B}% 0->1
1296 \def\pgfpptchindexnext@B{C}% 1->2
1297 \def\pgfpptchindexnext@C{D}% 2->3
1298 \def\pgfpptchindexnext@D{E}% 3->4
1299 \def\pgfpptchindexnext@E{F}% 4->5
1300 \def\pgfpptchindexnext@F{G}% 5->6
1301 \def\pgfpptchindexnext@G{H}% 6->7
1302 \def\pgfpptchindexnext@H{I}% 7->8
1303 \def\pgfpptchindexnext@I{J}% 8->9
1304 \def\pgfpptchindexnext@J{K}% 9->10
1305 \def\pgfpptchindexnext@K{L}% 10->11
1306 \def\pgfpptchindexnext@L{M}% 11->12
1307 \def\pgfpptchindexnext@M{N}% 12->13
1308 \def\pgfpptchindexnext@N{O}% 13->14
1309 \def\pgfpptchindexnext@O{P}% 14->15
1310 \def\pgfpptchindexnext@P{Q}% 15->16
1311 \def\pgfpptchindexnext@Q{R}% 16->17
1312
1313 \pgfplotsdeclarepatchclass{line}{%
1314 allow matrix=\def\pgfplotsretval{0},
1315 new=\def\pgfplotspatchclass@line@no{0},
1316 set next vertex={%
1317 \if0\pgfplotspatchclass@line@no\relax
1318 \edef\pgfplotspatchclass@line@A{#1}%
1319 \def\pgfplotspatchclass@line@no{1}%
1320 \else
1321 \edef\pgfplotspatchclass@line@B{#1}%
1322 \def\pgfplotspatchclass@line@no{0}%
1323 \pgfplotspatchready%
1324 \fi
1325 },
1326 sample in unit cube={%
1327 \def\pgfplotspatchclassx{0}%
1328 \def\pgfplotspatchclassy{0}%
1329 #1%
1330 \def\pgfplotspatchclassx{1}%
1331 \def\pgfplotspatchclassy{0}%
1332 #1%
1333 \pgfplotspatchready
1334 },%
1335 get dimension=\def\pgfplotsretval{1},
1336 supports global path=\def\pgfplotsretval{1},
1337 first vertex=\expandafter\pgfplotspatchvertex\pgfplotspatchclass@line@A\endvertex,
1338 first vertex before z buffer=\expandafter\pgfplotspatchvertex\pgfplotspatchclass@line@A\endvertex,
1339 foreach vertex={%
1340 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@line@A\endvertex #1%
1341 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@line@B\endvertex #1%
1342 },
1343 fill path={%
1344 \pgfplotsplothandlermesh@pathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@line@A\endvertex}%
1345 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@line@B\endvertex}%
1346 \pgfplotsplothandlermesh@setlastpoint{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@line@B\endvertex}%
1347 },
1348 serialize except vertices=\let\pgfplotsretval\pgfutil@empty,%
1349 deserialize except vertices=,
1350 get num vertices=\def\pgfplotsretval{2},
1351 get pdf shading type=0,
1352 }%
1353
1354 \def\pgfplotsplothandlermesh@last@x{-16000pt}
1355 \def\pgfplotsplothandlermesh@last@y{-16000pt}
1356
1357 \def\pgfplotsplothandlermesh@pathmoveto#1{%
1358 \pgf@process{#1}%
1359 \pgfpathmoveto{}%
1360 }
1361 \def\pgfplotsplothandlermesh@setlastpoint#1{%
1362 }
1363
1364 % Applies a moveto to #1 - but only if #1 is NOT the last used path
1365 % segment.
1366 \def\pgfplotsplothandlermesh@pathmoveto@globalpath#1{%
1367 \pgf@process{#1}%
1368 \pgfplots@loc@tmptrue
1369 \ifdim\pgf@x=\pgfplotsplothandlermesh@last@x\relax
1370 \ifdim\pgf@y=\pgfplotsplothandlermesh@last@y\relax
1371 \pgfplots@loc@tmpfalse
1372 \fi
1373 \fi
1374 \ifpgfplots@loc@tmp
1375 \pgfpathmoveto{}%
1376 \fi
1377 }%
1378
1379 \def\pgfplotsplothandlermesh@setlastpoint@globalpath#1{%
1380 \pgf@process{#1}%
1381 \xdef\pgfplotsplothandlermesh@last@x{\the\pgf@x}%
1382 \xdef\pgfplotsplothandlermesh@last@y{\the\pgf@y}%
1383 }%
1384
1385 \pgfplotsdeclarepatchclass{triangle}{%
1386 allow matrix=\def\pgfplotsretval{0},
1387 new=\def\pgfplotspatchclass@tri@no{0}\let\pgfplotspatchclass@trie@AB\relax,
1388 set next vertex={%
1389 \ifcase\pgfplotspatchclass@tri@no\relax
1390 \edef\pgfplotspatchclass@tri@A{#1}%
1391 \def\pgfplotspatchclass@tri@no{1}%
1392 \or
1393 \edef\pgfplotspatchclass@tri@B{#1}%
1394 \def\pgfplotspatchclass@tri@no{2}%
1395 \or
1396 \edef\pgfplotspatchclass@tri@C{#1}%
1397 \def\pgfplotspatchclass@tri@no{0}%
1398 \pgfplotspatchready%
1399 \fi
1400 },
1401 sample in unit cube={%
1402 \def\pgfplotspatchclassx{0}%
1403 \def\pgfplotspatchclassy{0}%
1404 #1%
1405 \def\pgfplotspatchclassx{1}%
1406 \def\pgfplotspatchclassy{0}%
1407 #1%
1408 \def\pgfplotspatchclassx{0}%
1409 \def\pgfplotspatchclassy{1}%
1410 #1%
1411 \pgfplotspatchready
1412 %
1413 %
1414 \def\pgfplotspatchclassx{0}%
1415 \def\pgfplotspatchclassy{1}%
1416 #1%
1417 \def\pgfplotspatchclassx{1}%
1418 \def\pgfplotspatchclassy{0}%
1419 #1%
1420 \def\pgfplotspatchclassx{1}%
1421 \def\pgfplotspatchclassy{1}%
1422 #1%
1423 \pgfplotspatchready
1424 },%
1425 first vertex=\expandafter\pgfplotspatchvertex\pgfplotspatchclass@tri@A\endvertex,
1426 foreach vertex={%
1427 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@tri@A\endvertex #1%
1428 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@tri@B\endvertex #1%
1429 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@tri@C\endvertex #1%
1430 },
1431 fill path={%
1432 \pgfpathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@A\endvertex}%
1433 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@B\endvertex}%
1434 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@C\endvertex}%
1435 \pgfpathclose
1436 },
1437 stroke path={%
1438 \ifx\pgfplotspatchclass@trie@AB\relax
1439 \pgfpathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@A\endvertex}%
1440 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@B\endvertex}%
1441 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@C\endvertex}%
1442 \pgfpathclose
1443 \else
1444 \if1\pgfplotspatchclass@trie@AB
1445 \pgfpathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@A\endvertex}%
1446 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@B\endvertex}%
1447 \fi
1448 \if1\pgfplotspatchclass@trie@BC
1449 \pgfpathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@B\endvertex}%
1450 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@C\endvertex}%
1451 \fi
1452 \if1\pgfplotspatchclass@trie@CA
1453 \pgfpathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@C\endvertex}%
1454 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@A\endvertex}%
1455 \fi
1456 \fi
1457 },
1458 triangulate=\pgfplotspatchready,
1459 set edge visible={%
1460 \ifcase#1
1461 \edef\pgfplotspatchclass@trie@AB{#2}%
1462 \or
1463 \edef\pgfplotspatchclass@trie@BC{#2}%
1464 \or
1465 \edef\pgfplotspatchclass@trie@CA{#2}%
1466 \fi
1467 },
1468 serialize except vertices={%
1469 \ifx\pgfplotspatchclass@trie@AB\relax
1470 \let\pgfplotsretval\pgfutil@empty%
1471 \else
1472 \edef\pgfplotsretval{%
1473 \noexpand\def\noexpand\pgfplotspatchclass@trie@AB{\pgfplotspatchclass@trie@AB}%
1474 \noexpand\def\noexpand\pgfplotspatchclass@trie@BC{\pgfplotspatchclass@trie@BC}%
1475 \noexpand\def\noexpand\pgfplotspatchclass@trie@CA{\pgfplotspatchclass@trie@CA}%
1476 }%
1477 \fi
1478 },%
1479 recursive refine@={%
1480 %
1481 \pgfplotspatchclass{\pgfplotspatchclassname}{new}%
1482 %
1483 % Perform longest edge bisection.
1484 \pgfpointdiff
1485 {\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@A\endvertex}%
1486 {\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@B\endvertex}%
1487 \edef\pgfplots@loc@TMPa{{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}}%
1488 \expandafter\pgfmath@basic@veclen@\pgfplots@loc@TMPa
1489 \pgf@xa=\pgfmathresult pt
1490 \pgf@yc=\pgf@xa % "max so far"
1491 \def\pgfplotspatch@tri@longestedgestart{A}%
1492 %
1493 \pgfpointdiff
1494 {\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@B\endvertex}%
1495 {\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@C\endvertex}%
1496 \edef\pgfplots@loc@TMPa{{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}}%
1497 \expandafter\pgfmath@basic@veclen@\pgfplots@loc@TMPa
1498 \pgf@xa=\pgfmathresult pt
1499 \ifdim\pgf@xa>\pgf@yc
1500 \pgf@yc=\pgf@xa
1501 \def\pgfplotspatch@tri@longestedgestart{B}%
1502 \fi
1503 %
1504 \pgfpointdiff
1505 {\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@C\endvertex}%
1506 {\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@tri@A\endvertex}%
1507 \edef\pgfplots@loc@TMPa{{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}}%
1508 \expandafter\pgfmath@basic@veclen@\pgfplots@loc@TMPa
1509 \pgf@xa=\pgfmathresult pt
1510 \ifdim\pgf@xa>\pgf@yc
1511 \def\pgfplotspatch@tri@longestedgestart{C}%
1512 \fi
1513 % The ordering is not arbitrary
1514 % (unless z buffer=sort is in effect). Let's assume that the
1515 % AB edge is BACKGROUND and the CD edge is FOREGROUND. Then
1516 % this sequence here should have approximately the same depth
1517 % ordering:
1518 %
1519 \pgfplotspatchvertexaccumstart
1520 \if A\pgfplotspatch@tri@longestedgestart
1521 \expandafter\pgfplotspatchvertexadd\pgfplotspatchclass@tri@A\times{0.5}%
1522 \expandafter\pgfplotspatchvertexadd\pgfplotspatchclass@tri@B\times{0.5}%
1523 \def\pgfplots@loc@TMPa{ACM,BCM}%
1524 \else
1525 \if B\pgfplotspatch@tri@longestedgestart
1526 \expandafter\pgfplotspatchvertexadd\pgfplotspatchclass@tri@B\times{0.5}%
1527 \expandafter\pgfplotspatchvertexadd\pgfplotspatchclass@tri@C\times{0.5}%
1528 \def\pgfplots@loc@TMPa{ABM,ACM}%
1529 \else
1530 \expandafter\pgfplotspatchvertexadd\pgfplotspatchclass@tri@C\times{0.5}%
1531 \expandafter\pgfplotspatchvertexadd\pgfplotspatchclass@tri@A\times{0.5}%
1532 \def\pgfplots@loc@TMPa{ABM,BCM}%
1533 \fi
1534 \fi
1535 \pgfplotspatchvertexfinish\pgfplotspatchclass@tri@M
1536 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa;\pgfplotspatchclass@tri@M}%
1537 %
1538 % invoke helper method such that I don't need to restore or
1539 % recompute \pgfplotspatchclass@tri@M during recursion.
1540 \expandafter\pgfplotspatchclass@tri@recursiverefine@@\pgfplots@loc@TMPa\relax{#1}%
1541 },
1542 deserialize except vertices=%
1543 \let\pgfplotspatchclass@trie@AB\relax
1544 #1,
1545 get pdf shading type=4,
1546 get num vertices=\def\pgfplotsretval{3},
1547 LUA class=pgfplots.TrianglePatchType.new,
1548 }%
1549 \def\pgfplotspatchclass@tri@recursiverefine@@#1#2M,#3#4M;#5\relax#6{%
1550 \expandafter\let\expandafter\pgfplotspatchclass@tri@A@\csname pgfplotspatchclass@tri@#1\endcsname
1551 \expandafter\let\expandafter\pgfplotspatchclass@tri@B@\csname pgfplotspatchclass@tri@#2\endcsname
1552 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@tri@A@}%
1553 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@tri@B@}%
1554 \pgfplotsplothandlermesh@setnextvertex{#5}%
1555 #6%
1556 %
1557 \expandafter\let\expandafter\pgfplotspatchclass@tri@A@\csname pgfplotspatchclass@tri@#3\endcsname
1558 \expandafter\let\expandafter\pgfplotspatchclass@tri@B@\csname pgfplotspatchclass@tri@#4\endcsname
1559 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@tri@A@}%
1560 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@tri@B@}%
1561 \pgfplotsplothandlermesh@setnextvertex{#5}%
1562 #6%
1563 }%
1564
1565 % implements 'first vertex before z buffer' for rectangle
1566 % Note that 'mesh input=lattice' generates the rectangle patch as
1567 % follows: if the input matrix has the form
1568 %
1569 % (i-1,j-1) (i,j-1)
1570 %
1571 % (i-1,j) (i,j)
1572 %
1573 % it generates the rectangle
1574 %
1575 % A B
1576 %
1577 % D C
1578 %
1579 % (if you try to map this to a plot, ensure that you have 'y dir=reverse')
1580 \def\pgfplotspatchclass@rect@first@before@z@buffer{%
1581 \if\pgfplots@plot@mesh@ordering0%
1582 % ordering = rowwise -> scanline is cols!
1583 \ifcase\pgfplotsplothandlermesh@zbuffer@choice\relax
1584 % none
1585 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@A
1586 \or
1587 % reverse x seq
1588 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@B
1589 \or
1590 % reverse y seq
1591 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@D
1592 \or
1593 % reverse xy seq
1594 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@C
1595 \or
1596 % sort
1597 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@A
1598 \else
1599 % the choices 'default' or 'auto' should have been expanded already. Nothing to do here:
1600 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@A
1601 \fi
1602 \else
1603 % ordering = colwise: scanline is rows!
1604 \ifcase\pgfplotsplothandlermesh@zbuffer@choice\relax
1605 % none
1606 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@A
1607 \or
1608 % reverse x seq
1609 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@D
1610 \or
1611 % reverse y seq
1612 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@B
1613 \or
1614 % reverse xy seq
1615 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@C
1616 \or
1617 % sort
1618 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@A
1619 \else
1620 % the choices 'default' or 'auto' should have been expanded already. Nothing to do here:
1621 \let\pgfplots@loc@TMPa\pgfplotspatchclass@rect@A
1622 \fi
1623 \fi
1624 \expandafter\pgfplotspatchvertex\pgfplots@loc@TMPa\endvertex
1625 }%
1626
1627 % A rectangle specified in the sequence
1628 % D <-- C
1629 % | ^
1630 % v |
1631 % A --> B
1632 %
1633 \pgfplotsdeclarepatchclass{rectangle}{%
1634 allow matrix=\def\pgfplotsretval{1},
1635 new=\def\pgfplotspatchclass@rect@no{0},
1636 set next vertex={%
1637 \ifcase\pgfplotspatchclass@rect@no\relax
1638 \edef\pgfplotspatchclass@rect@A{#1}%
1639 \def\pgfplotspatchclass@rect@no{1}%
1640 \or
1641 \edef\pgfplotspatchclass@rect@B{#1}%
1642 \def\pgfplotspatchclass@rect@no{2}%
1643 \or
1644 \edef\pgfplotspatchclass@rect@C{#1}%
1645 \def\pgfplotspatchclass@rect@no{3}%
1646 \or
1647 \edef\pgfplotspatchclass@rect@D{#1}%
1648 \def\pgfplotspatchclass@rect@no{0}%
1649 \pgfplotspatchready%
1650 \fi
1651 },
1652 sample in unit cube={%
1653 \def\pgfplotspatchclassx{0}%
1654 \def\pgfplotspatchclassy{0}%
1655 #1%
1656 \def\pgfplotspatchclassx{1}%
1657 \def\pgfplotspatchclassy{0}%
1658 #1%
1659 \def\pgfplotspatchclassx{1}%
1660 \def\pgfplotspatchclassy{1}%
1661 #1%
1662 \def\pgfplotspatchclassx{0}%
1663 \def\pgfplotspatchclassy{1}%
1664 #1%
1665 \pgfplotspatchready
1666 },%
1667 first vertex=\expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@A\endvertex,
1668 first vertex before z buffer=\pgfplotspatchclass@rect@first@before@z@buffer,
1669 foreach vertex={%
1670 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@A\endvertex #1%
1671 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@B\endvertex #1%
1672 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@C\endvertex #1%
1673 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@D\endvertex #1%
1674 },
1675 stream to shader={%
1676 % a 'foreach vertex' with slightly different sequence:
1677 \def\pgfplots@foreachvertex@@{%
1678 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
1679 \pgfplotsaxisvisphasetransformpointmeta
1680 \pgfplotslibrarysurfstreamcoord{%
1681 \global\pgf@x=\pgfplotspatchvertexx\space
1682 \global\pgf@y=\pgfplotspatchvertexy\space
1683 }{\pgfplotspointmetatransformed}%
1684 }%
1685 \if1\b@pgfplotsplothandlermesh@matrixoutput
1686 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@A\endvertex\pgfplots@foreachvertex@@%
1687 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@B\endvertex\pgfplots@foreachvertex@@%
1688 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@D\endvertex\pgfplots@foreachvertex@@% EXCHANGED SEQUENCE
1689 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@C\endvertex\pgfplots@foreachvertex@@%
1690 \else
1691 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@A\endvertex\pgfplots@foreachvertex@@%
1692 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@B\endvertex\pgfplots@foreachvertex@@%
1693 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@D\endvertex\pgfplots@foreachvertex@@%
1694 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@B\endvertex\pgfplots@foreachvertex@@%
1695 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@C\endvertex\pgfplots@foreachvertex@@%
1696 \expandafter\pgfplotspatchvertex\pgfplotspatchclass@rect@D\endvertex\pgfplots@foreachvertex@@%
1697 \fi
1698 },%
1699 fill path={%
1700 \pgfpathmoveto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@rect@A\endvertex}%
1701 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@rect@B\endvertex}%
1702 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@rect@C\endvertex}%
1703 \pgfpathlineto{\expandafter\pgfplotspointpatchvertex\pgfplotspatchclass@rect@D\endvertex}%
1704 \pgfpathclose
1705 },
1706 init pdf shading={%
1707 \if0\b@pgfplotsplothandlermesh@matrixoutput
1708 \ifnum\pgfkeysvalueof{/pgfplots/surf shading/cols}=2
1709 \else
1710 \pgfplots@error{Sorry, (patch type=rectangle) and (rectangular patch shadings with more than one rectangle) is not supported (got \pgfkeysvalueof{/pgfplots/surf shading/cols} x * input points).
1711 It is supported if z buffer!=sort. Consider using 'patch to triangles=true' to combine it with z buffer=sort}%
1712 \fi
1713 \fi
1714 },
1715 recursive refine@={%
1716 \pgfplots@error{Please use \string\usepgfplotslibrary{patchplots} in order to use 'refine,patch type=\pgfplotspatchclassname'}%
1717 },
1718 triangulate={%
1719 \let\pgfplotsplothandlermesh@patchclass@=\pgfplotsplothandlermesh@patchclass
1720 \def\pgfplotsplothandlermesh@patchclass{triangle}%
1721 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{new}%
1722 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set edge visible}01%
1723 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set edge visible}10%
1724 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set edge visible}21%
1725 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@rect@A}%
1726 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@rect@B}%
1727 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@rect@D}%
1728 %
1729 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set edge visible}01%
1730 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set edge visible}11%
1731 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set edge visible}20%
1732 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@rect@B}%
1733 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@rect@C}%
1734 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotspatchclass@rect@D}%
1735 \let\pgfplotsplothandlermesh@patchclass=\pgfplotsplothandlermesh@patchclass@
1736 },%
1737 serialize except vertices=\let\pgfplotsretval\pgfutil@empty,%
1738 deserialize except vertices=,
1739 get pdf shading type=5,
1740 get num vertices=\def\pgfplotsretval{4},
1741 LUA class=pgfplots.RectanglePatchType.new,
1742 }%
1743
1744 \def\pgfplots@rect@next@A{B}
1745 \def\pgfplots@rect@next@B{C}
1746 \def\pgfplots@rect@next@C{D}
1747 \def\pgfplots@rect@next@D{A}
1748
1749 \def\pgfplots@rect@rnext@A{D}
1750 \def\pgfplots@rect@rnext@B{A}
1751 \def\pgfplots@rect@rnext@C{B}
1752 \def\pgfplots@rect@rnext@D{C}
1753
1754 % Ideas: make sure that the foreground edge is the 'v=1'
1755 % edge of the coons patch, i.e. that it is drawn on top of
1756 % the rest.
1757 %
1758 % Furthermore, for fixed v, the 'u=1' point should belong
1759 % to the foreground (as it is drawn on top of u=0).
1760 %
1761 % In other words, if the coons patch looks like
1762 %
1763 % BB-------CC <--v=1
1764 % | |
1765 % | |
1766 % | |
1767 % AA-------DD <--v=0
1768 % | |
1769 % u=0 u=1
1770 %
1771 % where the AA,BB,CC,DD are the corners of the coons
1772 % patch, The FOREGROUND POINT of our visualization here should be CC,
1773 % the second most foreground point BB (assuming that
1774 % foreground point and second most foreground point are
1775 % adjacent).
1776 %
1777 % Thus, if 'CC' is behind of 'BB' in the A,B,C,D ordering:
1778 % start the coons patch with AA := BB-1 in forward
1779 % direction.
1780 % else
1781 % start the coons patch with AA := BB+1 in reverse
1782 % direction.
1783 %
1784 % #1: the vertex prefix for the rectangular shape.
1785 % Thus, \csname #1A\endcsname is the first vertex, \csname #1B\endcsname the second
1786 % and #1C, #1D the third and fourth.
1787 %
1788 % [output] #2: A macro name which will be filled with the FIRST point
1789 % to stream to the shader. It will be defined to be either A,B,C or D.
1790 % [output] #3: A macro name which indicates whether the stream shall
1791 % be forward or backward. It will be defined to be either empty or 'r'. If
1792 % it is empty, the coons patch shall be in the sequence
1793 % #2,next(#2),next(next(#2),....
1794 % If it is 'r', the coons patch shall be in the sequence
1795 % #2,prev(#2),prev(prev(#2),...
1796 %
1797 % Note that this method works also for biquadratic patches since these
1798 % patches also have #1A, #1B, #1C and #1D as their corners.
1799 %
1800 \def\pgfplotspatchclass@rect@to@coonspatch@findshadingsequence@for@depth#1#2#3{%
1801 \def#2{A}%
1802 \def#3{}%
1803 %
1804 \expandafter\expandafter\expandafter\pgfplotspatchvertex\csname #1A\endcsname\endvertex
1805 \ifx\pgfplotspatchvertexdepth\pgfutil@empty
1806 \else
1807 % aaah -- we have z buffer information. Then we will use it!
1808 \edef\PA{\pgfplotspatchvertexdepth pt A}%
1809 \expandafter\expandafter\expandafter\pgfplotspatchvertex\csname #1B\endcsname\endvertex
1810 \edef\PB{\pgfplotspatchvertexdepth pt B}%
1811 \expandafter\expandafter\expandafter\pgfplotspatchvertex\csname #1C\endcsname\endvertex
1812 \edef\PC{\pgfplotspatchvertexdepth pt C}%
1813 \expandafter\expandafter\expandafter\pgfplotspatchvertex\csname #1D\endcsname\endvertex
1814 \edef\PD{\pgfplotspatchvertexdepth pt D}%
1815 \pgfplotsutilsortfour\PA\PB\PC\PD
1816 \def\toCHAR##1pt ##2{##2}% get original index
1817 %
1818 %
1819 \edef\PA{\expandafter\toCHAR\PA}%%
1820 \edef#2{\expandafter\toCHAR\PB}%%
1821 \edef\Pnext{\csname pgfplots@rect@next@#2\endcsname}% this here uses only A,B,C and D (also for biquadratic patches!)
1822 \if\Pnext\PA
1823 % ok, next(BB) = CC.
1824 % that means we have to advance forward.
1825 \def#3{}%
1826 \edef#2{\csname pgfplots@rect@rnext@#2\endcsname}%
1827 \else
1828 \edef#2{\csname pgfplots@rect@next@#2\endcsname}%
1829 \def#3{r}%
1830 \fi
1831 %\message{^^JDEPTH SEQUENCE for rectangle: \PA, \PB, \PC, \PD^^J}%
1832 %\message{COONS PATH ORDERING: starts with #2, direction: \ifx#3\pgfutil@empty forward\else backward\fi^^J}%
1833 \fi
1834 }%
1835
1836 \def\pgfplotspatchclass@rect@to@coonspatch@findshadingsequence@for@depth@no@op#1#2#3{%
1837 \def#2{A}%
1838 \def#3{}%
1839 }
1840
1841 \def\pgfplotsplothandlermesh@patchclass@defaulttext{default}%
1842
1843 % This is a VERY special case. The idea is to switch to
1844 % "normal" path mode:
1845 % \pgfpathmoveto \pgfpathlineto \pgfpathlineto
1846 % \pgfpathlineto \pgfusepath.
1847 %
1848 % Note that the mesh handler's default is to issue
1849 % \pgfusepath after *each* elementary patch.
1850 %
1851 % This special use-case might not cover all aspects of the
1852 % mesh/surf/patch plot handler.
1853 \def\pgfplotsplothandlermesh@init@path@without@point@meta{%
1854 %
1855 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{supports global path}%
1856 \ifnum\pgfplotsretval=1 %
1857 \def\pgfplotsplothandlermesh@definecolor{%
1858 % no-op
1859 }%
1860 % FIXME : this does not handle separate edges, i.e.
1861 % \pgfplotsplothandlermesh@VISUALIZE@std@separate@fillstroke
1862 \def\pgfplotsplothandlermesh@VISUALIZE{\pgfplotsplothandlermesh@VISUALIZE@globalpath@fill@andor@stroke}%
1863 \let\pgfplotsplothandlermesh@pathmoveto=\pgfplotsplothandlermesh@pathmoveto@globalpath
1864 \let\pgfplotsplothandlermesh@setlastpoint=\pgfplotsplothandlermesh@setlastpoint@globalpath
1865 %
1866 % This activates tikz colors:
1867 %\tikz@options
1868 \pgfplots@drawoptions
1869 % Acquire the values for \tikz@mode@* [used for faceted]
1870 \pgfplots@drawmodes
1871 \else
1872 \pgfplots@error{Please provide 'point meta' for your plot. Omitting point meta is only supported for 1d patch types.}%
1873 \fi
1874 }
1875
1876 % implements 'show normals'. Keep in mind that this is more-or-less a
1877 % debugging helper, not productive code.
1878 \def\pgfplotsplothandlermesh@show@normals{%
1879 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{compute normal}%
1880 \let\pgfplots@normal@vector=\pgfplotsretval
1881 %\pgfplotsmathvectortostring\pgfplots@normal@vector{default}%
1882 %\message{got normal \pgfplotsretval^^J}%
1883 \pgfplotsmathvectorlength{\pgfplots@normal@vector}{default}%
1884 \pgfplotscoordmath{default}{parsenumber}{\pgfkeysvalueof{/pgfplots/mesh/show normals length factor}}% FIXME
1885 \pgfplotscoordmath{default}{op}{divide}{{\pgfmathresult}{\pgfplotsretval}}%
1886 \pgfplotsmathvectorscale{\pgfplots@normal@vector}{\pgfmathresult}{default}%
1887 %\pgfplotsmathvectoradd{\pgfplotspatchvertexcoords}{\pgfplotsretval}{default}%
1888 \let\pgfplots@normal@vector=\pgfplotsretval
1889 %
1890 \draw[/pgfplots/every patch normal]
1891 \pgfextra{%
1892 \pgfpathmoveto
1893 {%
1894 \pgf@process{%
1895 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{get num vertices}%
1896 \pgfmath@basic@reciprocal@{\pgfplotsretval}%
1897 \let\scale=\pgfmathresult
1898 \pgfplotspatchvertexaccumstart
1899 \pgfplotspatchclass{\pgfplotspatchclassname}{foreach vertex}{%
1900 \expandafter\pgfplotspatchvertexadd\pgfplotspatchvertexstruct\times{\scale}%
1901 }%
1902 \pgfplotspatchvertexfinishXY{\pgfplots@loc@TMPa}%
1903 \expandafter\pgfplotspointpatchvertex\pgfplots@loc@TMPa\endvertex%
1904 }%
1905 }%
1906 \edef\pgfplots@loc@TMPa{\pgf@x=\the\pgf@x\space\pgf@y=\the\pgf@y\space}%
1907 %
1908 \pgfpathlineto{%
1909 \pgfpointadd
1910 {\pgfplots@loc@TMPa}
1911 {\pgfplotspointfromcsvvector\pgfplots@normal@vector{default}}%
1912 }%
1913 }%
1914 ;
1915 }%
1916
1917 % Defines \pgfplotsretval to be either empty or the current point's
1918 % depth according to z buffer information.
1919 \def\pgfplotsplothandlermesh@compute@vertex@depth{\let\pgfplotsretval\pgfutil@empty}%
1920
1921 % If \pgfplotsplothandlermesh@compute@vertex@depth is set to this
1922 % particular implementation, the \pgfplotspatchvertexdepth macro will
1923 % contain the view depth.
1924 %
1925 \def\pgfplotsplothandlermesh@compute@vertex@depth@doit{%
1926 \ifx\pgfplots@current@point@x\pgfutil@empty
1927 \let\pgfplotsretval\pgfutil@empty
1928 \else
1929 \pgfplotsmathvectorfromstring{\pgfplots@current@point@x,\pgfplots@current@point@y,\pgfplots@current@point@z}{default}%
1930 \pgfplotsmathvectorviewdepth{\pgfplotsretval}%
1931 \pgfplotscoordmath{default}{tofixed}{\pgfplotsretval}%
1932 \edef\pgfplotsretval{\pgfmathresult}%
1933 \fi
1934 }%
1935
1936 % A command which defines \pgfplotsretval to be either empty or to
1937 % the (x,y,z) 3d coordinates of the data point. Usually, the data
1938 % scaling transformation will already be applied to these points.
1939 %
1940 % Note that this is unnecessary for most applications of mesh plots.
1941 %
1942 % The resulting value will be available as \pgfplotspatchvertexcoords
1943 \def\pgfplotsplothandlermesh@serialize@logical@coords{%
1944 % empty by default
1945 \let\pgfplotsretval=\pgfutil@empty
1946 }%
1947 \def\pgfplotsplothandlermesh@serialize@logical@coords@doit{%
1948 \ifx\pgfplots@current@point@x\pgfutil@empty
1949 \let\pgfplotsretval=\pgfutil@empty
1950 \else
1951 % note that these points are the result of the data scaling
1952 % trafo. That is OK because the view normal is also in the
1953 % same coordinate space.
1954 \pgfplotsmathvectorfromstring{\pgfplots@current@point@x,\pgfplots@current@point@y,\pgfplots@current@point@z}{default}%
1955 \fi
1956 }
1957
1958 % the inverse for \pgfplotsplothandlermesh@serialize@logical@coords: it defines \pgfplots@current@point@[xyz].
1959 % You should only call it if you know that there IS something to deserialize.
1960 \def\pgfplotsplothandlermesh@deserialize@logical@coords#1{%
1961 \expandafter\pgfplotsplothandlermesh@deserialize@logical@coords@#1\relax
1962 }%
1963 \def\pgfplotsplothandlermesh@deserialize@logical@coords@#1,#2,#3\relax{%
1964 \def\pgfplots@current@point@x{#1}%
1965 \def\pgfplots@current@point@y{#2}%
1966 \def\pgfplots@current@point@z{#3}%
1967 }%
1968
1969 % The patch visualization works like a PIPELINE:
1970 %
1971 % DECODE -> CHECK JUMP -> REFINE -> FINISH
1972 %
1973 % where FINISH is usually nothing but VISUALIZE; but it can also mean
1974 % to collect patches, sort them according to view depth and visualize
1975 % the result.
1976 %
1977 % Each single PIPE element can be exchanged by a separate "subclass".
1978 % For example, DECODE can either DECODE from a matrix (a lattice) or a
1979 % sequence of patch coords.
1980 %
1981 \def\pgfplotsplothandlermesh@stream#1{%
1982 \pgfplotsplothandlermesh@PIPE@DECODE{#1}%
1983 }%
1984
1985 % accumulates a patch vertex-by-vertex.
1986 % #1 the next vertex of a patch (#1 defines canvas coordinates \pgf@x
1987 % and \pgf@y).
1988 %
1989 % @PRECONDITION \pgfplots@current@point@[xyz] and \pgfplots@current@point@meta
1990 % need to be defined.
1991 \def\pgfplotsplothandlermesh@PIPE@DECODE#1{%
1992 \let\pgfplotsplothandlermesh@patchclass\pgfplotsplothandlermesh@patchclass@input
1993 \pgfplotsplothandlermesh@compute@vertex@depth% <-- this modifies \pgfplotsretval
1994 \let\pgfplots@view@depth=\pgfplotsretval
1995 \pgf@process{#1}%
1996 % calls \pgfplotspatchready when ready
1997 \pgfplotsplothandlermesh@serialize@logical@coords
1998 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{set next vertex}{{\the\pgf@x}{\the\pgf@y}{\pgfplots@current@point@meta}\pgfplots@view@depth:\pgfplotsretval}%%
1999 }%
2000 \def\pgfplotspatchready{%
2001 \pgfplotsplothandlermesh@PIPE@CHECKJUMP
2002 }%
2003 \let\pgfplotspatchready@orig=\pgfplotspatchready
2004 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP{%
2005 \pgfplots@loc@tmptrue
2006 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{foreach vertex}{%
2007 \pgfplotsplothandlermesh@check@unbounded%
2008 }%
2009 %
2010 \ifpgfplots@loc@tmp
2011 \pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta
2012 \fi
2013 %
2014 \ifpgfplots@loc@tmp
2015 \expandafter\pgfplotsplothandlermesh@PIPE@REFINE
2016 \fi
2017 }%
2018
2019 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@noop{%
2020 }
2021
2022 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@noop
2023
2024 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@everyvertex{%
2025 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{foreach cdata vertex}{%
2026 \pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@check
2027 }%
2028 }%
2029 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@firstvertex{%
2030 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{first vertex before z buffer}%
2031 \pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@check
2032 }%
2033 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@firstvertex@legacy{%
2034 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{first vertex}%
2035 \pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@check
2036 }%
2037 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@check{%
2038 \if0\pgfplotsplothandlermesh@colorinput
2039 % mesh/color input=colormap
2040 \pgfplotsifpointmetaisbounded{\pgfplotspatchvertexmeta}{}{%
2041 \pgfplots@loc@tmpfalse
2042 }%
2043 \else
2044 % mesh/color input=explicit
2045 \ifx\pgfplotspatchvertexmeta\pgfutil@empty
2046 \pgfplots@loc@tmpfalse
2047 \fi
2048 \fi
2049 }
2050
2051 \def\pgfplotsplothandlermesh@PIPE@REFINE@no@op{%
2052 \pgfplotsplothandlermesh@PIPE@FINISH
2053 }%
2054 \let\pgfplotsplothandlermesh@PIPE@REFINE=\pgfplotsplothandlermesh@PIPE@REFINE@no@op
2055
2056 % invoked when a patch is completely processed.
2057 % This might be replaced by the z buffering algorithm
2058 \def\pgfplotsplothandlermesh@PIPE@FINISH{%
2059 \pgfplotsplothandlermesh@PIPE@interior@exterior@styles
2060 }%
2061
2062 \def\pgfplotsplothandlermesh@PIPE@interior@exterior@styles{%
2063 \pgfplotsplothandlermesh@interior@exterior@hook
2064 \pgfplotsplothandlermesh@VISUALIZE
2065 }%
2066
2067 % Standard implementation for VISUALIZE
2068 \def\pgfplotsplothandlermesh@VISUALIZE@std@fill@andor@stroke{%
2069 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{fill path}%
2070 \pgfplotsplothandlermesh@definecolor
2071 \pgfplotsplothandlermesh@usepath
2072 \pgfplotsplothandlermesh@show@normals@if@configured
2073 }%
2074
2075 % a special VISUALIZE implementation which allows to draw a CONTINUOUS
2076 % global path, i.e. one which is not "\pgfusepath"ed after each patch
2077 % segment. This is only used if 'point meta=none'
2078 \def\pgfplotsplothandlermesh@VISUALIZE@globalpath@fill@andor@stroke{%
2079 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{fill path}%
2080 }%
2081
2082 \def\pgfplotsplothandlermesh@VISUALIZE@std{\pgfplotsplothandlermesh@VISUALIZE@std@fill@andor@stroke}
2083
2084 \def\pgfplotsplothandlermesh@VISUALIZE{\pgfplotsplothandlermesh@VISUALIZE@std}
2085
2086 \let\pgfplotsplothandlermesh@show@normals@if@configured\relax
2087
2088
2089 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2090 \def\pgfplotsplothandlermesh@init@DECODE{%
2091 \if0\pgfplotsplothandlermesh@matrixinput
2092 %\message{initialised DECODE for patch output (from patch).^^J}%
2093 \else
2094 % mesh input=lattice|image
2095 % Init memory:
2096 %
2097 % And now finally: initialise the conversion from
2098 % LINEARIZED COORD STREAM -> DATA MATRIX:
2099 \if\pgfplots@plot@mesh@ordering0%
2100 % x varies (=rowwise):
2101 \let\pgfplotsplothandlermesh@scanlinelength=\pgfplotsplothandlermesh@cols
2102 \let\pgfplotsplothandlermesh@numscanlines=\pgfplotsplothandlermesh@rows
2103 \else
2104 % y varies (=colwise):
2105 \let\pgfplotsplothandlermesh@scanlinelength=\pgfplotsplothandlermesh@rows
2106 \let\pgfplotsplothandlermesh@numscanlines=\pgfplotsplothandlermesh@cols
2107 \fi
2108 %
2109 \if1\pgfplotsplothandlermesh@ONEDIMMODE
2110 %\message{initialised DECODE for 1d mode.^^J}%
2111 % FIXME : needs LUA support...
2112 \if2\pgfplotsplothandlermesh@matrixinput
2113 % mesh input=image
2114 \pgfplots@error{'matrix input=image' is unsupported for line plots (or matrix plots with just 1 row or 1 column). Please provide at least 2 rows and 2 cols for 'matrix input=image'}%
2115 \fi
2116 \let\pgfplotsplothandlermesh@PIPE@DECODE=\pgfplotsplothandlermesh@PIPE@DECODE@matrix@ONEDIMMODE
2117 \else
2118 \if0\b@pgfplotsplothandlermesh@matrixoutput
2119 \if1\b@pgfplots@LUA@visualization@enabled
2120 %\message{initialised DECODE for patch output (from matrix which has already been decoded in LUA).^^J}%
2121 \else
2122 % in fact, this does only remember the maximum capacity;
2123 % it doesn't fill the memory.
2124 \c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@scanlinelength\relax
2125 \advance\c@pgfplots@scanlineindex by1
2126 \pgfplotsdequenewempty{lastscanline}\capacity{\the\c@pgfplots@scanlineindex}%
2127 \if1\pgfplotsplothandlermesh@matrixinput
2128 % mesh input=lattice
2129 \let\pgfplotsplothandlermesh@PIPE@DECODE=\pgfplotsplothandlermesh@PIPE@DECODE@matrix@fillscanline
2130 %\message{initialised DECODE for patch output (from matrix).^^J}%
2131 \else
2132 % mesh input=image
2133 % lastinterpscanline contains a line of
2134 % interpolated points, and there is one more than points. Preallocate it:
2135 \advance\c@pgfplots@scanlineindex by1
2136 \pgfplotsdequenewempty{lastinterpscanline}\capacity{\the\c@pgfplots@scanlineindex}%
2137 % NOTE: implementation is in a separate file.
2138 \let\pgfplotsplothandlermesh@PIPE@DECODE=\pgfplotsplothandlermesh@PIPE@DECODE@image@fillscanline
2139 %\message{initialised DECODE for IMAGE output (from matrix).^^J}%
2140 \fi
2141 \fi
2142 \else
2143 % SPECIAL HANDLING!
2144 \if1\pgfplotsplothandlermesh@matrixinput
2145 % mesh input=lattice
2146 \let\pgfplotsplothandlermesh@PIPE@DECODE=\pgfplotsplothandlermesh@PIPE@DECODE@to@shader
2147 \else
2148 % mesh input=image
2149 % this should never happen because matrix output
2150 % is off for mesh input=image
2151 \pgfplots@error{Illegal internal state encountered}%
2152 \fi
2153 %\message{initialised DECODE for direct matrix output (from matrix).^^J}%
2154 \fi
2155 \fi
2156 \fi
2157 }%
2158
2159
2160 \def\pgfplotsplothandlermesh@PIPE@REFINE@triangulate{%
2161 \let\pgfplotspatchready\pgfplotsplothandlermesh@PIPE@FINISH
2162 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{triangulate}%
2163 \let\pgfplotspatchready\pgfplotspatchready@orig
2164 }%
2165 \def\pgfplotsplothandlermesh@PIPE@REFINE@recursively{%
2166 \let\pgfplotspatchready\pgfplotsplothandlermesh@PIPE@FINISH
2167 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{refine}{\pgfplotsplothandlermesh@refinecount}%
2168 \let\pgfplotspatchready\pgfplotspatchready@orig
2169 }%
2170 \def\pgfplotsplothandlermesh@PIPE@REFINE@triangulate@recursively{%
2171 \let\pgfplotspatchready=\pgfplotsplothandlermesh@PIPE@REFINE@triangulate@recursively@patchready
2172 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{refine}{\pgfplotsplothandlermesh@refinecount}%
2173 \let\pgfplotspatchready\pgfplotspatchready@orig
2174 }%
2175 \def\pgfplotsplothandlermesh@PIPE@REFINE@triangulate@recursively@patchready{%
2176 \let\pgfplotspatchready\pgfplotsplothandlermesh@PIPE@FINISH
2177 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{triangulate}%
2178 \let\pgfplotspatchready\pgfplotsplothandlermesh@PIPE@REFINE@triangulate@recursively@patchready
2179 }%
2180 \def\pgfplotsplothandlermesh@init@REFINE{%
2181 \pgfkeysgetvalue{/pgfplots/patch refines}\pgfplotsplothandlermesh@refinecount
2182 \if0\pgfplotsplothandlermesh@triangulate
2183 \ifnum\pgfplotsplothandlermesh@refinecount>0
2184 %\message{initialised REFINE to REFINE.}%
2185 \let\pgfplotsplothandlermesh@PIPE@REFINE=\pgfplotsplothandlermesh@PIPE@REFINE@recursively
2186 \else
2187 %\message{initialised REFINE to NOP.}%
2188 \let\pgfplotsplothandlermesh@PIPE@REFINE=\pgfplotsplothandlermesh@PIPE@REFINE@no@op
2189 \fi
2190 \else
2191 %\message{initialised REFINE to triangulate.}%
2192 \ifnum\pgfplotsplothandlermesh@refinecount>0
2193 \let\pgfplotsplothandlermesh@PIPE@REFINE=\pgfplotsplothandlermesh@PIPE@REFINE@triangulate@recursively
2194 \else
2195 \let\pgfplotsplothandlermesh@PIPE@REFINE=\pgfplotsplothandlermesh@PIPE@REFINE@triangulate
2196 \fi
2197 \fi
2198 }%
2199
2200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2201 % MESH SURVEY
2202 \def\pgfplotsplothandlersurveystart@mesh{%
2203 \pgfplotsplothandlersurveystart@default
2204 \if0\pgfplotsplothandlermesh@colorinput
2205 % mesh/color input=colormap
2206 \else
2207 % mesh/color input=explicit
2208 \if1\pgfplotsplothandlermesh@colorinput@mathparse
2209 \pgfkeysdef{/pgfplots/color sequence/every input component}{%
2210 \expandafter\pgfmathparse\expandafter{\pgfmathresult}%
2211 \ifpgfplots@usefpu
2212 \pgfmathfloattofixed\pgfmathresult
2213 \fi
2214 }%
2215 \else
2216 \pgfkeysdef{/pgfplots/color sequence/every input component}{}%
2217 \fi
2218 \pgfplotscolornormalizesequence[
2219 colorspace=\pgfkeysvalueof{/pgfplots/mesh/colorspace explicit color output},
2220 default input colorspace=\pgfkeysvalueof{/pgfplots/mesh/colorspace explicit color input},
2221 context message={point meta '\pgfplots@current@point@meta' of coord no \the\c@pgfplots@coordindex\space (\pgfplots@current@point@x,\pgfplots@current@point@y\ifpgfplots@curplot@threedim,\pgfplots@current@point@z\fi)},
2222 ]%
2223 \fi
2224 %
2225 \if2\pgfplotsplothandlermesh@matrixinput
2226 % mesh input=image
2227 \pgfplotsplothandlersurveystart@mesh@image
2228 \pgfplotsplothandlermesh@needs@scanlinecomplete@notificationstrue
2229 \fi
2230 %
2231 \pgfplotsplothandlersurveypoint@mesh@check@scanline@length@init
2232 }%
2233
2234 \def\pgfplotsplothandlersurveypoint@mesh{%
2235 \pgfplotsplothandlersurveypoint@default
2236 %
2237 \pgfplotsplothandlersurveypoint@mesh@common
2238 }
2239
2240 \def\pgfplotsplothandlersurveypoint@mesh@common{%
2241 \if2\pgfplotsplothandlermesh@matrixinput
2242 \pgfplotsplothandlersurveypoint@mesh@image
2243 \fi
2244 %
2245 \ifcase\pgfplotsplothandlermesh@matrixinput
2246 \else
2247 % mesh input=lattice|image
2248 \pgfplotsplothandlersurveypoint@mesh@check@scanline@length
2249 \fi
2250 }%
2251
2252 \def\pgfplotsplothandlersurveypoint@pseudoconstant@row@index{%
2253 \if\pgfplots@plot@mesh@ordering0%
2254 % ordering = x varies= rowwise -> scanline is cols!
2255 \else
2256 % ordering = y varies = colwise: scanline is rows!
2257 \ifx\pgfplotsplothandlermesh@rows\pgfutil@empty
2258 \fi
2259 }%
2260
2261 % initializes \pgfplotsplothandlersurveypoint@mesh@check@scanline@length, see its comments.
2262 \def\pgfplotsplothandlersurveypoint@mesh@check@scanline@length@init{%
2263 \pgfkeysgetvalue{/pgfplots/empty line}\pgfplots@loc@TMPa%
2264 \def\pgfplots@loc@TMPb{scanline}
2265 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPa
2266 \else
2267 % without end-of-scanline markers, the notification
2268 % \pgfplotsscanlinecomplete does not make sense anyway in this
2269 % context. Disable it:
2270 \let\pgfplotsplothandlersurveypoint@mesh@check@scanline@length=\relax
2271 \fi
2272 \if\pgfplots@plot@mesh@ordering0%
2273 % ordering = x varies= rowwise -> scanline is cols!
2274 \ifx\pgfplotsplothandlermesh@cols\pgfutil@empty
2275 % ... and without columns, we cannot generate the notification.
2276 \let\pgfplotsplothandlersurveypoint@mesh@check@scanline@length=\relax
2277 \fi
2278 \else
2279 % ordering = y varies = colwise: scanline is rows!
2280 \ifx\pgfplotsplothandlermesh@rows\pgfutil@empty
2281 % ... and without rows, we cannot generate the notification.
2282 \let\pgfplotsplothandlersurveypoint@mesh@check@scanline@length=\relax
2283 \fi
2284 \fi
2285 }
2286
2287 % Invokes \pgfplotsscanlinecomplete if the scanline is complete according to the keys 'mesh/rows' and/or 'mesh/cols'
2288 %
2289 % This routine improves the precision of the scanline computation, but not much.
2290 % At the time of this writing, its only purpose is to help 'matrix input=image'
2291 % as that requires information about the current scanline in order to update its
2292 % axis limits.
2293 %
2294 % Note that this macro is unnecessary in many cases: if the user input _contains_ end-of-scanline markers, it is redundant.
2295 %
2296 % Limitations of this routine:
2297 % 1. it requires 'empty line=scanline'.
2298 % 2. if mesh/ordering=x varies, it requires that mesh/cols is set.
2299 % if mesh/ordering=y varies, it requires that mesh/rows is set.
2300 %
2301 % In all other cases, it simply becomes a no-op without further notice (i.e. it will be \let to \relax)
2302 \def\pgfplotsplothandlersurveypoint@mesh@check@scanline@length{%
2303 %\message{checking scanline length for \the\c@pgfplots@scanlineindex. cols=\pgfplotsplothandlermesh@cols, rows=\pgfplotsplothandlermesh@rows. ordering = \pgfplots@plot@mesh@ordering^^J}%
2304 \if\pgfplots@plot@mesh@ordering0%
2305 % ordering = x varies= rowwise -> scanline is cols!
2306 \ifnum\pgfplotsplothandlermesh@cols=\c@pgfplots@scanlineindex\relax
2307 % it does not hurt to invoke this here multiple times -- it has to handle that case anyway:
2308 \pgfplotsscanlinecomplete
2309 \fi
2310 \else
2311 % ordering = y varies = colwise: scanline is rows!
2312 \ifnum\pgfplotsplothandlermesh@rows=\c@pgfplots@scanlineindex\relax
2313 % it does not hurt to invoke this here multiple times -- it has to handle that case anyway:
2314 \pgfplotsscanlinecomplete
2315 \fi
2316 \fi
2317 }%
2318
2319 \def\pgfplotsplothandlersurveypoint@mesh@noreset@of@pointmeta{%
2320 \pgfplotsplothandlersurveypoint@default@noreset@of@pointmeta
2321 \pgfplotsplothandlersurveypoint@mesh@common
2322 }%
2323
2324 \newif\ifpgfplotsplothandlermesh@needs@scanlinecomplete@notifications
2325
2326 \def\pgfplotsplothandlersurveyend@mesh{%
2327 \pgfplotsplothandlersurveyend@default
2328 \if0\pgfplotsplothandlermesh@colorinput
2329 % mesh/color input=colormap
2330 \else
2331 % mesh/color input=explicit
2332 \endpgfplotscolornormalizesequence
2333 \fi
2334 %
2335 \if2\pgfplotsplothandlermesh@matrixinput
2336 % mesh input=image
2337 \pgfplotsplothandlersurveyend@mesh@image
2338 \fi
2339 %
2340 \ifpgfplotsplothandlermesh@needs@scanlinecomplete@notifications
2341 %
2342 % OK, we EXPECT that the code generated
2343 % notifications of sorts \pgfplotsscanlinecomplete.
2344 %
2345 % If this turns out to be NOT the case, we generate a
2346 % warning/error.
2347 %
2348 % This, in turn, is restricted to the following cases:
2349 % 1. there have been end-of-scanline markers in the input
2350 % stream (that's why we can only decide it here, after the
2351 % input has been surveyed)
2352 % 2. OR \pgfplotsscanlinecomplete has been called due to scan
2353 % line length comparison with mesh/cols or mesh/rows. In this
2354 % case, the required argument must have been set, see
2355 % \pgfplotsplothandlersurveypoint@mesh@check@scanline@length@init
2356 %
2357 \ifnum\c@pgfplotsplothandlermesh@image@numscanlines<2
2358 \pgfplotsautocompletemeshkeys%
2359 \ifx\pgfplotsplothandlersurveypoint@mesh@check@scanline@length\relax
2360 % ah -- this routine has been cleared because the keys are
2361 % missing.
2362 %
2363 % Please see the comments on
2364 % \pgfplotsplothandlersurveypoint@mesh@check@scanline@length
2365 % for details.
2366 %
2367 \if\pgfplots@plot@mesh@ordering0%
2368 % ordering = x varies= rowwise -> scanline is cols!
2369 \pgfplotswarning{imagesc limits incomplete}{mesh/cols=\pgfplotsplothandlermesh@cols}\pgfeov%
2370 \else
2371 % ordering = y varies = colwise: scanline is rows!
2372 \pgfplotswarning{imagesc limits incomplete}{mesh/rows=\pgfplotsplothandlermesh@rows}\pgfeov%
2373 \fi
2374 \fi
2375 \fi
2376 \fi
2377 %
2378 }
2379
2380 \def\pgfplotsplothandlersurvey@mesh@scanlinecomplete{%
2381 %
2382 %
2383 \if2\pgfplotsplothandlermesh@matrixinput
2384 % mesh input=image
2385 \pgfplotsplothandlersurveyend@mesh@image@scanlinecomplete
2386 \fi
2387 }%
2388
2389 \def\pgfplotsplothandlersurveyaftersetpointmeta@mesh@cdatanormalize{%
2390 \pgfplotsplothandlersurveyaftersetpointmeta@default
2391 \if0\pgfplotsplothandlermesh@colorinput
2392 % mesh/color input=colormap
2393 \else
2394 % mesh/color input=explicit
2395 \pgfplotscolornormalizesequencenext{\pgfplots@current@point@meta}%
2396 \let\pgfplots@current@point@meta=\pgfplotsretval
2397 \fi
2398 }%
2399
2400 \newif\ifpgfplotsplothandlermesh@patchtable@hascdata
2401 \newif\ifpgfplotsplothandlermesh@patchtable@cdata@individual
2402 \def\pgfplotsplothandlersurveystart@mesh@patchtable{%
2403 \pgfplotsplothandlersurveystart@mesh
2404 \pgfplotsarraynewempty\pgfplots@verts
2405 }%
2406 \def\pgfplotsplothandlersurveypoint@mesh@patchtable{%
2407 \pgfplotscoordmath{x}{parsenumber}{\pgfplots@current@point@x}%
2408 \let\pgfplots@current@point@x=\pgfmathresult
2409 %
2410 \pgfplotscoordmath{y}{parsenumber}{\pgfplots@current@point@y}%
2411 \let\pgfplots@current@point@y=\pgfmathresult
2412 %
2413 \ifpgfplots@curplot@threedim
2414 \pgfplotscoordmath{z}{parsenumber}{\pgfplots@current@point@z}%
2415 \let\pgfplots@current@point@z=\pgfmathresult
2416 \fi
2417 %
2418 \ifpgfplotsplothandlermesh@patchtable@hascdata
2419 % will be handled later, using data from within 'patch table':
2420 \let\pgfplots@current@point@meta=\pgfutil@empty
2421 \else
2422 \pgfplotsaxissurveysetpointmeta
2423 \fi
2424 %
2425 \def\pgfplots@loc@TMPa{1}%
2426 \ifx\pgfplots@current@point@x\pgfutil@empty
2427 \def\pgfplots@loc@TMPa{0}%
2428 \else
2429 \ifx\pgfplots@current@point@y\pgfutil@empty
2430 \def\pgfplots@loc@TMPa{0}%
2431 \else
2432 \ifx\pgfplots@current@point@z\pgfutil@empty
2433 \ifpgfplots@curplot@threedim
2434 \def\pgfplots@loc@TMPa{0}%
2435 \fi
2436 \fi
2437 \fi
2438 \fi
2439 \if1\pgfplots@loc@TMPa
2440 \edef\pgfplots@loc@TMPa{\pgfplots@current@point@x,\pgfplots@current@point@y,\pgfplots@current@point@z;\pgfplots@current@point@meta;}%
2441 \expandafter\pgfplotsarraypushback\pgfplots@loc@TMPa\to\pgfplots@verts
2442 \fi
2443 }%
2444 \def\pgfplotsplothandlersurveyend@mesh@patchtable{%
2445 \pgfplotsplothandlersurveyend@mesh
2446 \let\pgfplotsplothandlersurveystart=\pgfplotsplothandlersurveystart@default
2447 \let\pgfplotsplothandlersurveyend=\pgfplotsplothandlersurveyend@default
2448 \let\pgfplotsplothandlersurveypoint=\pgfplotsplothandlersurveypoint@mesh@noreset@of@pointmeta
2449 \pgfplotsplothandlersurveystart
2450 \expandafter\pgfplotstable@isloadedtable\expandafter{\pgfplotsplothandlermesh@patchtable}{%
2451 \pgfplots@error{Sorry, 'patch table={<loaded table>}' has not been implemented; it would probably be too slow :-(. Please provide a file name or inline table data}%
2452 }{%
2453 \expandafter\pgfplotstableread\expandafter*\expandafter{\pgfplotsplothandlermesh@patchtable} to listener\pgfplotsplothandlermesh@patchtable@rowlistener
2454 }%
2455 \pgfplotsplothandlersurveyend
2456 }%
2457
2458 \def\pgfplotsplothandlermesh@patchtable@init{%
2459 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{get num vertices}%
2460 \let\pgfplotsplothandlermesh@patchtable@numverts=\pgfplotsretval
2461 %
2462 \ifpgfplotsplothandlermesh@patchtable@hascdata
2463 \ifpgfplotsplothandlermesh@patchtable@cdata@individual
2464 \else
2465 \ifnum\pgfplotsplothandlermesh@patchtable@numverts<\pgfplotstablecols\relax
2466 % prepare a pointer to data column: use the column
2467 % after the last vertex index.
2468 % this thing constitutes the "default" cdata source for
2469 % 'point meta=explicit'.
2470 \pgfplotstablereadgetptrtocolindex
2471 {\pgfplotsplothandlermesh@patchtable@numverts}
2472 {\pgfplots@table@PTR@CDATA}%
2473 \else
2474 \let\pgfplots@table@PTR@CDATA=\relax
2475 \fi
2476 \fi
2477 \else
2478 \pgfplotsplothandlermesh@patchtable@cdata@individualfalse
2479 \fi
2480 %
2481 \c@pgf@countb=0
2482 \pgfutil@loop
2483 \ifnum\c@pgf@countb<\pgfplotsplothandlermesh@patchtable@numverts\relax
2484 \edef\pgfplots@loc@TMPa{%
2485 \noexpand\pgfplotstablereadgetptrtocolindex{\the\c@pgf@countb}{\expandafter\noexpand\csname pgfplots@table@PTR@\the\c@pgf@countb\endcsname}%
2486 }%
2487 \pgfplots@loc@TMPa
2488 \advance\c@pgf@countb by1
2489 \pgfutil@repeat
2490 \let\pgfplotsplothandlermesh@patchtable@init=\relax
2491 }%
2492 \def\pgfplotsplothandlermesh@patchtable@rowlistener@exceptionmsg{%
2493 patch table \pgfplotsplothandlermesh@patchtable\space line \pgfplotstablelineno: could not read column no \the\c@pgf@countb: expected '\pgfplots@current@vertexindex' to be a valid index into the vertex arrays (the \pgfplotsarraysizeof\pgfplots@verts\space input coordinates)%
2494 }%
2495 \def\pgfplotsplothandlermesh@patchtable@rowlistener{%
2496 \pgfplotsplothandlermesh@patchtable@init%
2497 %
2498 \ifpgfplotsplothandlermesh@patchtable@hascdata
2499 \ifpgfplotsplothandlermesh@patchtable@cdata@individual
2500 \else
2501 \ifx\pgfplots@table@PTR@CDATA\relax
2502 \let\pgfplots@current@point@meta=\pgfutil@empty
2503 \else
2504 \pgfplotstablereadevalptr\pgfplots@table@PTR@CDATA\pgfplots@current@point@meta
2505 \fi
2506 \fi
2507 \fi
2508 %
2509 \c@pgf@countb=0
2510 \pgfutil@loop
2511 \ifnum\c@pgf@countb<\pgfplotsplothandlermesh@patchtable@numverts\relax
2512 \expandafter\pgfplotstablereadevalptr\csname pgfplots@table@PTR@\the\c@pgf@countb\endcsname\pgfplots@current@vertexindex%
2513 %
2514 \ifx\pgfplots@current@vertexindex\pgfutil@empty
2515 \else
2516 \pgfmathfloatparsenumber{\pgfplots@current@vertexindex}%
2517 \pgfmathfloattoint\pgfmathresult
2518 \let\pgfplots@current@vertexindex=\pgfmathresult
2519 %
2520 \let\pgfplotsexceptionmsg=\pgfplotsplothandlermesh@patchtable@rowlistener@exceptionmsg
2521 \pgfplotsarrayselect\pgfplots@current@vertexindex\of\pgfplots@verts\to\pgfplots@stored@pt
2522 \let\pgfplotsexceptionmsg=\relax
2523 %
2524 \ifpgfplotsplothandlermesh@patchtable@cdata@individual
2525 \c@pgf@countc=\c@pgf@countb\relax
2526 \advance\c@pgf@countc by\pgfplotsplothandlermesh@patchtable@numverts\relax
2527 \expandafter\getthisrowno\expandafter{\the\c@pgf@countc}\pgfplots@current@point@meta
2528 \fi
2529 %
2530 \expandafter\pgfplotsplothandlermesh@patchtable@stream\pgfplots@stored@pt
2531 \fi
2532 \advance\c@pgf@countb by1
2533 \pgfutil@repeat
2534 }
2535 \def\pgfplotsplothandlermesh@patchtable@stream#1,#2,#3;#4;{%
2536 \def\pgfplots@current@point@x{#1}%
2537 \def\pgfplots@current@point@y{#2}%
2538 \def\pgfplots@current@point@z{#3}%
2539 \ifpgfplotsplothandlermesh@patchtable@hascdata
2540 \def\pgfplots@set@perpointmeta@done{0}%
2541 \pgfplotsaxissurveysetpointmeta
2542 \else
2543 \def\pgfplots@current@point@meta{#4}%
2544 \fi
2545 \pgfplotsplothandlersurveypoint
2546 }%
2547 % MESH SURVEY
2548 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2549
2550 \def\pgfplotsplothandlermesh@init@meshkeys{%
2551 \ifcase\pgfplotsplothandlermesh@matrixinput\relax
2552 % mesh input=patches
2553 \pgfkeys{/pgfplots/mesh/ordering/x varies}% disable any special handling.
2554 \else
2555 % mesh input=lattice|image
2556 \pgfplotsautocompletemeshkeys%
2557 \pgfkeysgetvalue{/pgfplots/mesh/rows}\pgfplotsplothandlermesh@rows
2558 \pgfkeysgetvalue{/pgfplots/mesh/cols}\pgfplotsplothandlermesh@cols
2559 \pgfkeysgetvalue{/pgfplots/mesh/num points}\pgfplotsplothandlermesh@numpoints
2560 %
2561 % the \pgfplotsplothandlermesh@ONEDIMMODE macro is ONLY
2562 % interesting for matrix input.
2563 \ifnum\pgfplotsplothandlermesh@cols>1
2564 \else
2565 \def\pgfplotsplothandlermesh@ONEDIMMODE{1}%
2566 \fi
2567 \ifnum\pgfplotsplothandlermesh@rows>1
2568 \else
2569 \def\pgfplotsplothandlermesh@ONEDIMMODE{1}%
2570 \fi
2571 \if1\pgfplotsplothandlermesh@ONEDIMMODE
2572 \def\pgfplotsplothandlermesh@patchclass{line}%
2573 \pgfkeyslet{/pgfplots/patch type}\pgfplotsplothandlermesh@patchclass
2574 \fi
2575 \fi
2576 %
2577 \pgfplotspatchclass{\pgfkeysvalueof{/pgfplots/patch type}}{get dimension}%
2578 \ifnum\pgfplotsretval=1 %
2579 \def\pgfplots@meshmode{m}% mesh.
2580 \fi
2581 %
2582 }%
2583
2584 \let\pgfplotsplothandlermesh@interior@exterior@hook=\relax
2585 \def\pgfplotsplothandlermesh@interior@exterior@hook@active@zerothresh{%
2586 \begingroup
2587 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{compute normal}%
2588 % \let\pgfplots@normal=\pgfplotsretval
2589 % \pgfplotsmathvectorlength{\pgfplotsretval}{default}%
2590 % \pgfplotscoordmath{default}{op}{reciprocal}{{\pgfplotsretval}}%
2591 % \pgfplotsmathvectorscale{\pgfplots@normal}{\pgfmathresult}{default}%
2592 %
2593 \pgfplotsmathvectorscalarproduct{\pgfplots@view@dir@threedim}{\pgfplotsretval}{default}%
2594 \pgfplotscoordmath{default}{if is}{\pgfplotsretval}{-}{%
2595 % <0:
2596 \global\let\pgfplots@glob@TMPc\pgfplotsplothandlermesh@is@interior
2597 }{%
2598 % >=0:
2599 \global\let\pgfplots@glob@TMPc\pgfplotsplothandlermesh@is@exterior
2600 }%
2601 \endgroup
2602 \pgfplots@glob@TMPc
2603 }%
2604
2605 \def\pgfplotsplothandlermesh@interior@exterior@hook@active{%
2606 \begingroup
2607 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{compute normal}%
2608 \let\pgfplots@normal=\pgfplotsretval
2609 \pgfplotsmathvectorlength{\pgfplotsretval}{default}%
2610 \let\pgfplots@normal@len=\pgfplotsretval
2611 %
2612 \pgfplotsmathvectorscalarproduct{\pgfplots@view@dir@threedim}{\pgfplots@normal}{default}%
2613 \let\pgfplots@dot=\pgfplotsretval
2614 \pgfplotscoordmath{default}{op}{multiply}{{\pgfplots@view@dir@threedim@len}{\pgfplots@normal@len}}%
2615 \pgfplotscoordmath{default}{op}{divide}{{\pgfplots@dot}{\pgfmathresult}}%
2616
2617 \pgfplotscoordmath{default}{if less than}{\pgfmathresult}{\pgfplotsplothandlermesh@interior@thresh}{%
2618 % <0:
2619 \global\let\pgfplots@glob@TMPc\pgfplotsplothandlermesh@is@interior
2620 }{%
2621 % >=0:
2622 \global\let\pgfplots@glob@TMPc\pgfplotsplothandlermesh@is@exterior
2623 }%
2624 \endgroup
2625 \pgfplots@glob@TMPc
2626 }%
2627
2628
2629 % only used if
2630 % \pgfplotsplothandlermesh@interior@exterior@hook@active is
2631 % active
2632 \def\pgfplotsplothandlermesh@is@interior{%
2633 %\def\pgfplotsplothandlermesh@usepath{\pgfusepath{discard}}%
2634 \pgfkeyslet{/pgfplots/colormap name}\pgfplotsplothandlermesh@colormapname@interior
2635 \pgfkeyslet{/pgfplots/surf shading/colormap}\pgfplotsplothandlermesh@shader@colormap@interior
2636 }%
2637 \def\pgfplotsplothandlermesh@is@exterior{%
2638 %\let\pgfplotsplothandlermesh@usepath=\pgfplotsplothandlermeshusepathfillstroke
2639 \pgfkeyslet{/pgfplots/colormap name}\pgfplotsplothandlermesh@colormapname
2640 \pgfkeyslet{/pgfplots/surf shading/colormap}\pgfplotsplothandlermesh@shader@colormap
2641 }%
2642
2643 \def\pgfplotsplothandlermesh@init@cdata{%
2644 % Ok, we have color data.
2645 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsplothandlermesh@colormapname
2646 %
2647 %
2648 \if0\pgfplotsplothandlermesh@colorinput
2649 % mesh/color input=colormap
2650 \pgfplotscolormapgetcolorcomps{\pgfplotsplothandlermesh@colormapname}%
2651 \let\pgfplotsplothandlermesh@explicit@color@num@comps=\pgfplotsretval
2652 \else
2653 % mesh/color input=explicit
2654 \pgfkeysgetvalue{/pgfplots/mesh/colorspace explicit color output}\pgfplots@loc@TMPa
2655 \pgfplotscolorspacegetcomponents{\pgfplots@loc@TMPa}%
2656 \let\pgfplotsplothandlermesh@explicit@color@num@comps=\pgfplotsretval
2657 \fi
2658 %
2659 \pgfkeysgetvalue{/pgfplots/mesh/interior colormap name}\pgfplotsplothandlermesh@colormapname@interior
2660 \ifx\pgfplotsplothandlermesh@colormapname@interior\pgfutil@empty
2661 \else
2662 \pgfkeysgetvalue{/pgfplots/mesh/interior colormap thresh}\pgfplotsplothandlermesh@interior@thresh
2663 \pgfplotscoordmath{default}{parsenumber}{\pgfplotsplothandlermesh@interior@thresh}%
2664 \let\pgfplotsplothandlermesh@interior@thresh=\pgfmathresult
2665 \pgfplotscoordmath{default}{if is}{\pgfplotsplothandlermesh@interior@thresh}{0}{%
2666 \let\pgfplotsplothandlermesh@interior@exterior@hook=\pgfplotsplothandlermesh@interior@exterior@hook@active@zerothresh
2667 }{%
2668 \pgfplotsmathvectorlength{\pgfplots@view@dir@threedim}{default}% should be 1, but never mind
2669 \let\pgfplots@view@dir@threedim@len=\pgfplotsretval
2670 \let\pgfplotsplothandlermesh@interior@exterior@hook=\pgfplotsplothandlermesh@interior@exterior@hook@active
2671 }%
2672 % actually store 3d coordinates:
2673 \let\pgfplotsplothandlermesh@serialize@logical@coords=\pgfplotsplothandlermesh@serialize@logical@coords@doit
2674 \fi
2675 %
2676 % Prepare:
2677 \def\pgfplotsplothandlermesh@definecolor{%
2678 % FIXME : use lua backend to improve this here! it is
2679 % _extremely_ slow!
2680 \pgfplotsplothandlermesh@get@flat@color
2681 \pgfplotsplothandlermesh@definemappedcolor{\pgfplotsretval}%
2682 \pgfplots@drawoptions
2683 }%
2684 %
2685 % Acquire the values for \tikz@mode@* [used for faceted]
2686 \pgfplots@drawmodes
2687 }
2688
2689 \def\pgfplotsplothandlermesh@definemappedcolor#1{%
2690 \if0\pgfplotsplothandlermesh@colorinput
2691 % mesh/color input=colormap
2692 \if d\pgfplots@colormap@access
2693 % colormap access=direct
2694 % we assume that the color *is* already normalized,
2695 % i.e. it is {<comma-separate-components>} and to be
2696 % interpreted in the correct color space.
2697 \edef\pgfplots@loc@TMPb{%
2698 \noexpand\pgfutil@definecolor{mapped color}
2699 {\pgfplotscolormapcolorspaceof{\pgfplotsplothandlermesh@colormapname}}%
2700 {#1}%
2701 }%
2702 \pgfplots@loc@TMPb
2703 \else
2704 % colormap access=map|piecewise constant
2705 \pgfplotscolormapdefinemappedcolor{#1}%
2706 \fi
2707 \else
2708 % mesh/color input=explicit
2709 %
2710 % we assume that the color *is* already normalized,
2711 % i.e. it is {<comma-separate-components>} and to be
2712 % interpreted in the correct color space.
2713 \edef\pgfplots@loc@TMPb{%
2714 \noexpand\pgfutil@definecolor{mapped color}
2715 {\pgfkeysvalueof{/pgfplots/mesh/colorspace explicit color output}}
2716 {#1}%
2717 }%
2718 \pgfplots@loc@TMPb
2719 \fi
2720 }%
2721
2722 \let\pgfsetstrokecolor@orig=\pgfsetstrokecolor
2723 \def\pgfplotsplothandlermesh@VISUALIZE@std@separate@fillstroke@setstrokecolor#1{%
2724 \pgfsetstrokecolor@orig{.}%
2725 }%
2726 \def\pgfplotsplothandlermesh@VISUALIZE@std@separate@fillstroke{%
2727 \pgfplotsplothandlermesh@get@flat@color
2728 \pgfplotsplothandlermesh@definemappedcolor{\pgfplotsretval}%
2729 %
2730 \ifx\pgfplotsplothandlermesh@usepathfill\relax
2731 \else
2732 \let\pgfsetstrokecolor=\pgfplotsplothandlermesh@VISUALIZE@std@separate@fillstroke@setstrokecolor
2733 \pgfplots@drawoptions
2734 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{fill path}%
2735 \pgfplotsplothandlermesh@usepathfill
2736 \fi
2737 \ifx\pgfplotsplothandlermesh@usepathstroke\relax
2738 \else
2739 \let\pgfsetstrokecolor=\pgfsetstrokecolor@orig
2740 \pgfplots@drawoptions
2741 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{stroke path}%
2742 \pgfplotsplothandlermesh@usepathstroke
2743 \fi
2744 }%
2745
2746 % This is one of two places where shadings are served with
2747 % coordinates; the other one uses matrix output (which does not work
2748 % with 'stream to shader')
2749 \def\pgfplotsplothandlermesh@VISUALIZE@interp{%
2750 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{stream to shader}%
2751 \ifpgf@relevantforpicturesize
2752 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{foreach vertex}{%
2753 \global\pgf@x=\pgfplotspatchvertexx\space
2754 \global\pgf@y=\pgfplotspatchvertexy\space
2755 % compute the bounding box using the vertices:
2756 \pgfpointtransformed{}%
2757 \pgf@protocolsizes{\pgf@x}{\pgf@y}%
2758 }%
2759 \fi
2760 }%
2761
2762 \def\pgfplotsplothandlermesh@VISUALIZE@faceted@interp{%
2763 \pgfplotslibrarysurfstreamstart
2764 \pgfplotsplothandlermesh@VISUALIZE@interp
2765 \pgfplotslibrarysurfstreamend
2766 \pgfplotslibrarysurfdrawinpicture
2767 %
2768 \pgfplotsplothandlermesh@VISUALIZE@std
2769 }%
2770
2771 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP@disable{%
2772 \def\pgfplotsplothandlermesh@PIPE@CHECKJUMP{\pgfplotsplothandlermesh@PIPE@REFINE}%
2773 }%
2774
2775 \def\pgfplotsplothandlermesh@init@shader{%
2776 %
2777 \ifnum\pgfplotsplothandlermesh@shader>1
2778 % 'shader=2': 'interp':
2779 % very simple: defer work to surf library. Only
2780 % provide the mapped colordata.
2781 %
2782 % 'shader=3': 'faceted interp':
2783 % a mix of 'faceted' and 'interp'. (might be inefficient in
2784 % terms of pdf memory and rendering times)
2785 %
2786 % This won't be used for mesh plots, neither in one
2787 % nor in two dimensions.
2788 \pgfkeyssetvalue{/pgfplots/surf shading/anchor}{\pgfpointorigin}%
2789 %
2790 % do NOT update the picture's BB using the streamed low-level coordinates
2791 % (which are bezier control points in most cases).
2792 % We do that on our own using the input vertices.
2793 \pgfkeys{/pgfplots/surf shading/update BB=false}%
2794 \if1\b@pgfplotsplothandlermesh@matrixoutput
2795 % this *implies* a compatible patch class, see the
2796 % definition of \b@pgfplotsplothandlermesh@matrixoutput
2797 \def\pgfplotsretval{5}%
2798 \else
2799 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{get pdf shading type}%
2800 \if5\pgfplotsretval
2801 % we have no matrix output->
2802 % downgrade lattice triangular grid to individual
2803 % triangles:
2804 \def\pgfplotsretval{4}%
2805 \fi
2806 \fi
2807 \pgfkeyslet{/pgfplots/surf shading/shading type}\pgfplotsretval%
2808 %
2809 \pgfplotsplothandlermesh@set@shader@colormap
2810 \pgfkeysgetvalue{/pgfplots/mesh/interior colormap name}\pgfplots@loc@TMPa
2811 \ifx\pgfplots@loc@TMPa\pgfutil@empty
2812 \else
2813 \let\pgfplotsplothandlermesh@shader@colormap=\pgfplotsretval
2814 \begingroup
2815 \pgfkeyslet{/pgfplots/colormap name}\pgfplots@loc@TMPa
2816 \pgfplotsplothandlermesh@set@shader@colormap
2817 \pgfmath@smuggleone\pgfplotsretval
2818 \endgroup
2819 \let\pgfplotsplothandlermesh@shader@colormap@interior=\pgfplotsretval
2820 \fi
2821 %
2822 \if0\pgfplotsplothandlermesh@colorinput
2823 % mesh/color input=colormap
2824 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplots@loc@TMPa
2825 \pgfplotscolormapgetcolorspace\pgfplots@loc@TMPa
2826 \pgfkeyslet{/pgfplots/surf shading/colorspace}\pgfplotsretval
2827 \else
2828 % mesh/color input=explicit
2829 \pgfkeysgetvalue{/pgfplots/mesh/colorspace explicit color output}\pgfplots@loc@TMPa
2830 \edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
2831 \pgfkeyslet{/pgfplots/surf shading/colorspace}\pgfplots@loc@TMPa
2832 \fi
2833 \if2\pgfplotsplothandlermesh@shader
2834 % shader=interp
2835 \let\pgfplotsplothandlermesh@definecolor=\relax
2836 \let\pgfplotsplothandlermesh@VISUALIZE=\pgfplotsplothandlermesh@VISUALIZE@interp%
2837 \pgfkeyslet{/pgfplots/surf shading/cols}\pgfplotsplothandlermesh@scanlinelength
2838 %\if1\b@pgfplotsplothandlermesh@matrixoutput
2839 \iffalse% FIXME : is this special handling necessary!?
2840 \if\pgfplots@plot@mesh@ordering0%
2841 % ordering=x varies:
2842 % nothing special to do
2843 \else
2844 % FIXME
2845 % [this happens only for mesh input=lattice]
2846 % colwise:
2847 %
2848 % The low level shader NEEDS rowwise ordering. So, we need to transpose the data matrix.
2849 % As usual in TeX, we should save macros as much as possible. I guess we NEED at least one macro for each matrix row.
2850 % Idea:
2851 % while we iterate colwise through the input data, accumulate row vectors.
2852 % Then, process the row vectors.
2853 % Since vectors are expensive (in terms of number of macros), we use fast "append" lists instead of vectors.
2854 \let\pgfplotsplothandlermesh@shader@interp=\pgfplotsplothandlermesh@shader@interp@incremental@transpose
2855 %
2856 % init all required row vectors:
2857 \c@pgfplots@scanlineindex=0
2858 \pgfutil@loop
2859 \ifnum\c@pgfplots@scanlineindex<\pgfplotsplothandlermesh@rows\relax
2860 \expandafter\pgfplotsapplistXnewempty\csname pgfp@transprow@\the\c@pgfplots@scanlineindex\endcsname%
2861 \advance\c@pgfplots@scanlineindex by1
2862 \pgfutil@repeat
2863 %\pgfkeyslet{/pgfplots/surf shading/cols}\pgfplotsplothandlermesh@rows
2864 %\pgfplots@error{Sorry, the 'shader=interp' does not yet support 'mesh/ordering=colwise'... You can continue now, but the plot will be transposed.}%
2865 \fi
2866 \fi
2867 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{init pdf shading}%
2868 \pgfplotslibrarysurfstreamstart
2869 \else
2870 % shader='faceted interp'
2871 \def\pgfplotsplothandlermesh@VISUALIZE{\pgfplotsplothandlermesh@VISUALIZE@faceted@interp}%
2872 \pgfkeyssetvalue{/pgfplots/surf shading/cols}{2}%
2873 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{init pdf shading}%
2874 \fi
2875 \else
2876 \def\pgfplotsplothandlermesh@VISUALIZE{\pgfplotsplothandlermesh@VISUALIZE@std}%
2877 \fi
2878 %
2879 %%
2880 \ifpgfplotsplothandlermesh@internaldepth
2881 \else
2882 % disable internal sorting.
2883 \let\pgfplotspatchclass@rect@to@coonspatch@findshadingsequence@for@depth=\pgfplotspatchclass@rect@to@coonspatch@findshadingsequence@for@depth@no@op%
2884 \let\pgfplotspatchclass@tri@to@coonspatch@findshadingsequence@for@depth=\pgfplotspatchclass@tri@to@coonspatch@findshadingsequence@for@depth@no@op
2885 \fi
2886 }%
2887
2888 \def\pgfplotsplothandlermesh@init@flat@color{%
2889 \ifcase\pgfplotsplothandlermesh@shader
2890 % 0 == 'flat'
2891 \def\pgfplotsplothandlermesh@needs@flat@color{1}%
2892 \or
2893 % 1 == 'faceted'
2894 \def\pgfplotsplothandlermesh@needs@flat@color{1}%
2895 \or
2896 % 2 == 'interp'
2897 \def\pgfplotsplothandlermesh@needs@flat@color{0}%
2898 \or
2899 % 3 == 'faceted interp'
2900 \def\pgfplotsplothandlermesh@needs@flat@color{1}%
2901 \fi
2902 \if1\pgfplotsplothandlermesh@needs@flat@color
2903 \pgfplotsplothandlermesh@init@flat@color@getter
2904 %
2905 \pgfplotsplothandlermesh@init@flat@color@usepath
2906 %
2907 %
2908 \pgfplotsplothandlermesh@init@flat@color@visualize@pipe@step
2909 \fi
2910 }%
2911
2912 \def\pgfplotsplothandlermeshusepathstroke{\pgfusepathqstroke}%
2913 \def\pgfplotsplothandlermeshusepathfill{\pgfusepathqfill}%
2914 \def\pgfplotsplothandlermeshusepathfillstroke{\pgfusepathqfillstroke}%
2915
2916 \def\pgfplotsplothandlermesh@init@flat@color@visualize@pipe@step{%
2917 \ifx\pgfplotsplothandlermesh@PIPE@REFINE\pgfplotsplothandlermesh@PIPE@REFINE@no@op
2918 \let\pgfplotsplothandlermesh@VISUALIZE@std=\pgfplotsplothandlermesh@VISUALIZE@std@fill@andor@stroke
2919 \else
2920 \ifpgfplotsplothandlermesh@hide@refined@edges
2921 % this is (at most) partially implemented.
2922 \let\pgfplotsplothandlermesh@VISUALIZE@std=\pgfplotsplothandlermesh@VISUALIZE@std@separate@fillstroke
2923 \else
2924 \let\pgfplotsplothandlermesh@VISUALIZE@std=\pgfplotsplothandlermesh@VISUALIZE@std@fill@andor@stroke
2925 \fi
2926 %
2927 % FIXME : that doesn't work.
2928 % filling *always* seems to need a stroke operation,
2929 % otherwise there will be translucent edges.
2930 % I need to adjust the stroke color :-(
2931 %
2932 % FIXME : even that doesn't work correctly. The problem
2933 % is: drawing adjacent patches on top of each other
2934 % OVERDRAWS edges: once with the correct stroke color;
2935 % once with the fill color.
2936 %
2937 \ifx\pgfplotsplothandlermesh@usepath\pgfplotsplothandlermeshusepathstroke
2938 \let\pgfplotsplothandlermesh@usepathfill=\relax
2939 \let\pgfplotsplothandlermesh@usepathstroke=\plotsplothandlermeshusepathstroke
2940 \else
2941 \ifx\pgfplotsplothandlermesh@usepath\pgfplotsplothandlermeshusepathfillstroke
2942 \let\pgfplotsplothandlermesh@usepathfill=\pgfplotsplothandlermeshusepathfillstroke
2943 \let\pgfplotsplothandlermesh@usepathstroke=\pgfplotsplothandlermeshusepathstroke
2944 \else
2945 \let\pgfplotsplothandlermesh@usepathfill=\relax
2946 \let\pgfplotsplothandlermesh@usepathstroke=\relax
2947 \fi
2948 \fi
2949 \fi
2950 }%
2951
2952 \def\pgfplotsplothandlermesh@init@flat@color@usepath{%
2953 \if\pgfplots@meshmode m%
2954 % 'mesh' plot: stroke only and use the 'flat' code
2955 % here just to define the color for each mesh
2956 % segment.
2957 \let\pgfplotsplothandlermesh@usepath=\pgfplotsplothandlermeshusepathstroke
2958 \else
2959 % 'surf' plot:
2960 \let\pgfplotsplothandlermesh@usepath=\pgfplotsplothandlermeshusepathfillstroke
2961 \if\pgfplotsplothandlermesh@shader3% faceted interp
2962 % it has an extra fill command (shading)
2963 \let\pgfplotsplothandlermesh@usepath=\pgfplotsplothandlermeshusepathstroke
2964 \fi
2965 %
2966 % the distinction between 'faceted' and 'flat' is
2967 % technical: it is just the default draw color.
2968 %
2969 % 'flat,draw=black' is the same as 'faceted'.
2970 \pgfkeysgetvalue{/pgfplots/faceted color}\pgfplots@loc@TMPb
2971 \def\pgfplots@loc@TMPc{none}%
2972 \ifx\pgfplots@loc@TMPb\pgfplots@loc@TMPc
2973 \pgfkeyslet{/pgfplots/faceted color}\pgfutil@empty
2974 \def\pgfplots@loc@TMPb{}%
2975 \fi
2976 %
2977 \def\pgfplots@loc@TMPa{0}%
2978 \if\pgfplotsplothandlermesh@shader1% faceted
2979 \def\pgfplots@loc@TMPa{1}%
2980 \ifx\pgfplots@loc@TMPb\pgfutil@empty
2981 % oh. no faceted color. Then: fill only, use
2982 % whatever color is available.
2983 \def\pgfplots@loc@TMPa{0}%
2984 %\let\pgfplotsplothandlermesh@usepath=\pgfplotsplothandlermeshusepathfill
2985 \fi
2986 \fi
2987 \if\pgfplotsplothandlermesh@shader3% faceted interp
2988 \def\pgfplots@loc@TMPa{1}%
2989 \ifx\pgfplots@loc@TMPb\pgfutil@empty
2990 % oh. no faceted color. Then: no-op!
2991 % This is the same as interp with more overhead
2992 % (but allows z buffering).
2993 \def\pgfplots@loc@TMPa{0}%
2994 \def\pgfplotsplothandlermesh@usepath{\pgfusepath{discard}}%
2995 \fi
2996 \fi
2997 \if1\pgfplots@loc@TMPa
2998 % make sure there is a the correct color.
2999 \expandafter\def\expandafter\pgfplots@drawoptions\expandafter{%
3000 \pgfplots@drawoptions
3001 \pgfsetstrokecolor{\pgfkeysvalueof{/pgfplots/faceted color}}%
3002 }%
3003 \fi
3004 %
3005 \fi
3006 }
3007
3008 \def\pgfplotsplothandlermesh@init@flat@color@getter{%
3009 \if\pgfplotsplothandlermesh@flatmode c% 'flat corner':
3010 %
3011 % use colordata of ONE corner point. That's easy, not
3012 % much to do.
3013 \if1\b@pgfplots@correct@shader@flat
3014 \def\pgfplotsplothandlermesh@get@flat@color{%
3015 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{first vertex before z buffer}%
3016 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
3017 \pgfplotsaxisvisphasetransformpointmeta
3018 \let\pgfplotsretval=\pgfplotspointmetatransformed%
3019 }%
3020 \else
3021 \def\pgfplotsplothandlermesh@get@flat@color{%
3022 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{first vertex}%
3023 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
3024 \pgfplotsaxisvisphasetransformpointmeta
3025 \let\pgfplotsretval=\pgfplotspointmetatransformed%
3026 }%
3027 \fi
3028 \else
3029 % 'flat mean':
3030 %
3031 % use colordata as mean of all corners for shading.
3032 \if0\pgfplotsplothandlermesh@colorinput
3033 % mesh/color input=colormap
3034 \if d\pgfplots@colormap@access
3035 % colormap access=direct
3036 % interpolate adjacent colors, not their indices:
3037 \pgfplotsplothandlermesh@get@flat@color@explicit@prepare
3038 \def\pgfplotsplothandlermesh@get@flat@color{%
3039 \pgfplotsplothandlermesh@get@flat@color@explicit@accum{%
3040 \begingroup
3041 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
3042 \pgfplotsaxisvisphasetransformpointmeta
3043 \let\pgfplotspatchvertexmeta=\pgfplotspointmetatransformed
3044 \pgfmath@smuggleone\pgfplotspatchvertexmeta
3045 \endgroup
3046 }%
3047 }%
3048 \else
3049 % colormap access=map|piecewise constant
3050 \def\pgfplotsplothandlermesh@get@flat@color{%
3051 \global\pgfplots@tmpa=0pt
3052 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{foreach cdata vertex}{%
3053 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
3054 \pgfplotsaxisvisphasetransformpointmeta
3055 \global\advance\pgfplots@tmpa by\pgfplotspointmetatransformed pt
3056 }%
3057 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{get num cdata vertices}%
3058 \global\divide\pgfplots@tmpa by\pgfplotsretval\relax
3059 \edef\pgfplotsretval{\pgf@sys@tonumber\pgfplots@tmpa}%
3060 \global\pgfplots@tmpa=0pt
3061 }%
3062 \fi
3063 \else
3064 % mesh/color input=explicit
3065 \pgfplotsplothandlermesh@get@flat@color@explicit@prepare
3066 %
3067 \def\pgfplotsplothandlermesh@get@flat@color{%
3068 \pgfplotsplothandlermesh@get@flat@color@explicit@accum{}%
3069 \pgfplotsaxisvisphasetransformpointmeta
3070 }%
3071 \fi
3072 \fi
3073 }%
3074
3075 \def\pgfplotsplothandlermesh@get@flat@color@explicit@prepare{%
3076 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{get num cdata vertices}%
3077 \pgf@xa=1pt %
3078 \divide\pgf@xa by\pgfplotsretval\relax
3079 \edef\pgfplotsplothandlermesh@get@flat@color@@{\pgf@sys@tonumber\pgf@xa}%
3080 }%
3081 \def\pgfplotsplothandlermesh@get@flat@color@explicit@accum#1{%
3082 \pgfplotscolorzero{\pgfplotsplothandlermesh@explicit@color@num@comps}%
3083 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{foreach cdata vertex}{%
3084 #1%
3085 \pgfplotscoloraddweighted
3086 {\pgfplotsplothandlermesh@explicit@color@num@comps}%
3087 {\pgfplotsretval}
3088 {\pgfplotsplothandlermesh@get@flat@color@@}%
3089 {\pgfplotspatchvertexmeta}%
3090 }%
3091 % FIXME : this here sounds wrong: !? what is this good for:
3092 \let\pgfplots@current@point@meta=\pgfplotspatchvertexmeta
3093 }%
3094
3095 \def\pgfplotsplothandlermesh@init@jumphandling{%
3096 % For matrix input, a "jump" should result in something
3097 % visible although it must not destroy the matrix structure.
3098 %
3099 % try this here:
3100 \def\pgfplotsplothandlervisualizejump{%
3101 \pgfplotstreampoint{\global\pgf@x=-16000.0pt \global\pgf@y=-16000.0pt }%
3102 }%
3103 %
3104 % Prepare jumps according to point meta:
3105 \ifx\pgfplotspointmetainputhandler\pgfutil@empty%
3106 % oh. No point meta!?
3107 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@noop
3108 \else
3109 % we have point meta. This is the standard case.
3110 %
3111 % prepare the routine for "jump on unbounded point meta":
3112 \ifcase\pgfplotsplothandlermesh@shader
3113 % 0 == 'flat'
3114 \def\pgfplots@loc@TMPa{1}%
3115 \or
3116 % 1 == 'faceted'
3117 \def\pgfplots@loc@TMPa{1}%
3118 \else
3119 \def\pgfplots@loc@TMPa{0}%
3120 \fi
3121 %
3122 \if 1\pgfplots@loc@TMPa
3123 % ok, this uses (only) 'shader=flat'
3124 \if c\pgfplotsplothandlermesh@flatmode
3125 % 'flat corner':
3126 \if1\b@pgfplots@correct@shader@flat
3127 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@firstvertex
3128 \else
3129 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@firstvertex@legacy
3130 \fi
3131 \else
3132 % 'flat mean':
3133 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@everyvertex
3134 \fi
3135 \else
3136 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@everyvertex
3137 \fi
3138 \fi
3139 %
3140 \if0\pgfplotsaxisplothasunboundedpointmeta
3141 \let\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta=\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@noop
3142 \fi
3143 \if0\pgfplotsaxisplothasjumps
3144 \ifx\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta\pgfplotsplothandlermesh@PIPE@CHECKJUMP@meta@noop
3145 \pgfplotsplothandlermesh@PIPE@CHECKJUMP@disable
3146 \fi
3147 \fi
3148 }%
3149
3150
3151 \def\pgfplotsplothandlermesh@init@zbuffer{%
3152 \ifpgfplots@curplot@threedim
3153 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{uses view depth}%
3154 \if1\pgfplotsretval
3155 \let\pgfplotsplothandlermesh@compute@vertex@depth=\pgfplotsplothandlermesh@compute@vertex@depth@doit%
3156 \fi
3157 %
3158 \if\pgfplotsplothandlermesh@zbuffer@choice4%
3159 \def\pgfplotsplothandlermesh@zbuffer@sort@in@TeX{1}%
3160 \else
3161 \def\pgfplotsplothandlermesh@zbuffer@sort@in@TeX{0}%
3162 \fi
3163 \if1\b@pgfplots@LUA@visualization@enabled
3164 % set it to 'z buffer=none' -- LUA did the job already.
3165 \def\pgfplotsplothandlermesh@zbuffer@sort@in@TeX{0}%
3166 \fi
3167 %
3168 \if\pgfplotsplothandlermesh@zbuffer@sort@in@TeX1%
3169 % z buffer=sort:
3170 % create a z buffer:
3171 % the z buffer contains elements {<view depth>}{{<pt1>}{<pt2>}{<pt3>}{<pt4>}}
3172 \pgfplotsarraynewempty\pgfplots@zbuffer@local
3173 %
3174 \let\pgfplotsplothandlermesh@compute@vertex@depth=\pgfplotsplothandlermesh@compute@vertex@depth@doit%
3175 %
3176 % the "element depth" is defined to be the MEAN of all
3177 % vertex depths.
3178 % And since the mean is 1/n * sum_{i=1}^n V_i, we can
3179 % directly omit the 1/n --- it is the same for every
3180 % vertex anyway, and we only want to compare the depth
3181 % values.
3182 \let\pgfplotsplothandlermesh@accum@element@depth=\pgfmath@basic@add@
3183 %
3184 % and collect each point into the z buffer
3185 % (instead of drawing it):
3186 \def\pgfplotsplothandlermesh@PIPE@FINISH{%
3187 %
3188 % compute DEPTH(lattice element):= min{DEPTH(A),DEPTH(B),DEPTH(C),DEPTH(D)}
3189 \def\pgfmathresult{0}%
3190 \def\pgfplotsplothandlermesh@zbuffer@tmp{}%
3191 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{foreach vertex}{%
3192 \pgfplotsplothandlermesh@accum@element@depth\pgfplotspatchvertexdepth\pgfmathresult
3193 \t@pgfplots@toka=\expandafter{\pgfplotsplothandlermesh@zbuffer@tmp}%
3194 \t@pgfplots@tokb=\expandafter{\pgfplotspatchvertexstruct}%
3195 \edef\pgfplotsplothandlermesh@zbuffer@tmp{%
3196 \the\t@pgfplots@toka
3197 {\the\t@pgfplots@tokb}%
3198 }%
3199 }%
3200 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{serialize except vertices}%
3201 \t@pgfplots@toka=\expandafter{\pgfplotsretval}%
3202 \t@pgfplots@tokb=\expandafter{\pgfplotsplothandlermesh@zbuffer@tmp}%
3203 \edef\pgfplotsplothandlermesh@zbuffer@tmp{%
3204 {\the\t@pgfplots@toka}% first argument is meta data, then follow the vertices
3205 \the\t@pgfplots@tokb%
3206 }%
3207 %
3208 % assemble array element:
3209 \t@pgfplots@toka=\expandafter{\pgfplotsplothandlermesh@zbuffer@tmp}%
3210 \edef\pgfplots@loc@TMPa{%
3211 {\pgfmathresult}%
3212 {%
3213 \the\t@pgfplots@toka
3214 }%
3215 }%
3216 \expandafter\pgfplotsarraypushback\pgfplots@loc@TMPa\to\pgfplots@zbuffer@local
3217 }%
3218 \fi
3219 \else
3220 \def\pgfplotsplothandlermesh@zbuffer@sort@in@TeX{0}%
3221 \fi
3222 }%
3223 \def\pgfplotsplothandlermesh@init@mesh@stream{%
3224 \global\let\pgf@plotstreamspecial=\pgfutil@gobble%
3225 \global\let\pgf@plotstreamend=\pgfplotsplothandlermesh@finish%
3226 \global\let\pgf@plotstreampoint=\pgfplotsplothandlermesh@stream
3227 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass}{new}%
3228 }
3229
3230 \def\pgfplotsplothandlermesh@set@shader@colormap{%
3231 \if0\pgfplotsplothandlermesh@colorinput
3232 % mesh/color input=colormap
3233 \if d\pgfplots@colormap@access
3234 % colormap access=direct
3235 % tell it to expect explicit colors:
3236 \pgfkeyslet{/pgfplots/surf shading/colormap}\pgfutil@empty
3237 \else
3238 % colormap access=map|piecewise constant
3239 \pgfkeysgetvalue{/pgfplots/colormap name}\pgfplots@loc@TMPa
3240 \expandafter\pgfplotscolormaptopdffunction\expandafter{\pgfplots@loc@TMPa}%
3241 \pgfkeyslet{/pgfplots/surf shading/colormap}\pgfplotsretval
3242 \fi
3243 \else
3244 % mesh/color input=explicit
3245 %
3246 % tell it to expect explicit colors:
3247 \pgfkeyslet{/pgfplots/surf shading/colormap}\pgfutil@empty
3248 \fi
3249 }%
3250
3251 \def\pgfplotsplothandlermesh@check@unbounded@value{-16000.0pt}%
3252 {
3253 \dimen0=\pgfplotsplothandlermesh@check@unbounded@value
3254 \xdef\pgfplotsplothandlermesh@check@unbounded@text{\the\dimen0}%
3255 }
3256
3257 \def\pgfplotsplothandlermesh@check@unbounded{%
3258 \ifx\pgfplotspatchvertexx\pgfplotsplothandlermesh@check@unbounded@text
3259 \pgfplots@loc@tmpfalse
3260 \fi
3261 }%
3262
3263 \long\def\pgfplotsplothandlermesh@defaultlegend@img#1{%
3264 \scope[%
3265 #1,
3266 /pgfplots/mesh/rows=3,
3267 /pgfplots/mesh/cols=3,
3268 /pgfplots/mesh/num points=,
3269 /pgfplots/mesh input=lattice,
3270 /pgfplots/patch type=rectangle,
3271 /pgfplots/z buffer=default,
3272 /tikz/x={(0.44237cm,-0.07439cm)},
3273 /tikz/y={(0.30942cm,0.23932cm)},
3274 /tikz/z={(0.0cm,1.5cm)},
3275 scale=0.4,
3276 yshift=-0.7cm,
3277 /pgfplots/point meta=explicit,
3278 /pgfplots/mesh/color input=colormap,
3279 ]
3280 \let\pgfplots@metamax=\pgfutil@empty
3281 \pgfplots@curplot@threedimtrue
3282
3283 \pgfplotsplothandlermesh
3284 \pgfplotstreamstart
3285
3286 \def\rangea{0.21}%
3287 \def\rangeb{0.7}%
3288
3289 \pgfmathparse{1000/(\rangeb-\rangea)}
3290 \let\factor=\pgfmathresult
3291
3292 \def\simplecoordinate(##1,##2,##3){%
3293 \pgfmathparse{\factor*(##3 - \rangea)}%
3294 \pgfmathfloatparsenumber\pgfmathresult
3295 \let\pgfplots@current@point@meta=\pgfmathresult
3296 \pgfplotstreampoint{\pgfqpointxyz{##1}{##2}{##3}}%
3297 }%
3298 % for the case 'shader=interp':
3299 %\def\pgfplotspointbbupperright{\pgfqpointxyz{2}{2}{0.9}}
3300 %\def\pgfplotspointbblowerleft {\pgfqpointxyz{0}{0}{0.1}}
3301
3302 \simplecoordinate(0,2,0.7)
3303 \simplecoordinate(1,2,0.5)
3304 \simplecoordinate(2,2,0.43)
3305
3306 \simplecoordinate(0,1,0.68)
3307 \simplecoordinate(1,1,0.4)
3308 \simplecoordinate(2,1,0.25)
3309
3310 \simplecoordinate(0,0,0.6)
3311 \simplecoordinate(1,0,0.35)
3312 \simplecoordinate(2,0,0.21)
3313
3314 \pgfplotstreamend
3315 \pgfusepath{stroke}
3316 \endscope
3317 }%
3318
3319 \def\pgfplotsplothandlermesh@finish{%
3320 \if\pgfplotsplothandlermesh@zbuffer@sort@in@TeX1%
3321 % z buffer=sort:
3322 % process the z buffer:
3323 \pgfkeyslet{/pgfplots/iflessthan/.@cmd}\pgfplotsplothandlermesh@zbuffer@sort@iflessthen
3324 \pgfkeysdef{/pgfplots/array/unscope pre}{%
3325 \let\pgfplotsplothandlermesh@patchclass=\pgfplotsplothandlermesh@patchclass@output
3326 \def\pgfplotspatchready{\pgfplotsplothandlermesh@PIPE@interior@exterior@styles}%
3327 \pgfplotsarrayforeachungrouped\pgfplots@zbuffer@local\as\curelem{%
3328 \expandafter\pgfplotsplothandlermesh@draw@zbufferelement\curelem%
3329 }%
3330 }%
3331 \pgfkeysdef{/pgfplots/array/unscope post}{}%
3332 \pgfplotsarraysort\pgfplots@zbuffer@local
3333 \fi
3334 %
3335 \if2\pgfplotsplothandlermesh@shader
3336 % shader=interp:
3337 % FIXME : broken!
3338 %\ifx\pgfplotsplothandlermesh@shader@interp\pgfplotsplothandlermesh@shader@interp@incremental@transpose%
3339 % This is the case for 'mesh/ordering=colwise'. We need to finish the transpose procedure:
3340 % \pgfplotsplothandlermesh@shader@interp@transpose@finish
3341 %\fi
3342 \pgfplotslibrarysurfstreamend
3343 \pgfplotslibrarysurfdrawinpicture
3344 \fi
3345 }%
3346
3347
3348 % This is one of two places where the shader is served with
3349 % coordinates: it handles the special matrix-form shading which is
3350 % incompatible with the patch-wise sequence of coordinates
3351 \def\pgfplotsplothandlermesh@PIPE@DECODE@to@shader#1{%
3352 \pgfplotsaxisvisphasetransformpointmeta
3353 \ifpgf@relevantforpicturesize
3354 \pgfpointtransformed{#1}%
3355 \pgf@protocolsizes{\pgf@x}{\pgf@y}%
3356 \fi
3357 \pgfplotslibrarysurfstreamcoord
3358 {#1}%
3359 {\pgfplotspointmetatransformed}%
3360 }%
3361
3362 \def\pgfplotsplothandlermesh@PIPE@DECODE@matrix@ONEDIMMODE#1{%
3363 \let\pgfplotsplothandlermesh@patchclass\pgfplotsplothandlermesh@patchclass@input
3364 \pgfplotsplothandlermesh@compute@vertex@depth% <-- this modifies \pgfplotsretval
3365 \let\pgfplots@view@depth=\pgfplotsretval
3366 \pgf@process{#1}%
3367 \pgfplotsplothandlermesh@serialize@logical@coords
3368 \edef\pgfplotsplothandlermesh@i{{\the\pgf@x}{\the\pgf@y}{\pgfplots@current@point@meta}\pgfplots@view@depth:\pgfplotsretval}%
3369 \ifnum\c@pgfplots@scanlineindex>0
3370 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotsplothandlermesh@im}%
3371 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotsplothandlermesh@i}%
3372 \else
3373 \advance\c@pgfplots@scanlineindex by1
3374 \fi
3375 \let\pgfplotsplothandlermesh@im=\pgfplotsplothandlermesh@i
3376 }%
3377
3378 \def\pgfplotsplothandlermesh@PIPE@DECODE@matrix@fillscanline@common#1{%
3379 \pgfplotsplothandlermesh@compute@vertex@depth% <-- this modifies \pgfplotsretval
3380 \let\pgfplots@view@depth=\pgfplotsretval
3381 \pgf@process{#1}%
3382 \pgfplotsplothandlermesh@serialize@logical@coords
3383 \edef\pgfplots@loc@TMPa{{\the\pgf@x}{\the\pgf@y}{\pgfplots@current@point@meta}\pgfplots@view@depth:\pgfplotsretval}%
3384 \expandafter\pgfplotsdequepushback\pgfplots@loc@TMPa\to{lastscanline}%
3385 \advance\c@pgfplots@scanlineindex by1
3386 }%
3387
3388 % the pgf@plotstreampoint routine for the first scan line:
3389 \def\pgfplotsplothandlermesh@PIPE@DECODE@matrix@fillscanline#1{%
3390 \pgfplotsplothandlermesh@PIPE@DECODE@matrix@fillscanline@common{#1}%
3391 \ifnum\c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@scanlinelength\relax
3392 % second line!
3393 \let\pgfplotsplothandlermesh@PIPE@DECODE=\pgfplotsplothandlermesh@PIPE@DECODE@matrix%%
3394 \c@pgfplots@scanlineindex=0
3395 \fi
3396 }%
3397
3398 % This is the pgf@plotstreampoint for all scan lines starting with the
3399 % second.
3400 %
3401 % We perform
3402 % // i == y
3403 % // j == x
3404 % for i = 1 to rows (note the 1! 0 would be the first row)
3405 % for j = 0 to cols
3406 % get (i-1, j) from front of deque // remember: i: rows, j : cols. We iterate rowwise.
3407 % push (i,j) to back of deque
3408 % if j > 0
3409 % draw
3410 % (i-1,j-1) [from last iteration] -- (i-1,j ) [from deque]
3411 % -- ( i,j ) [from last iteration] -- (i ,j-1) [from #1]
3412 % -- cycle
3413 % endif
3414 % let (i-1,j-1) := (i-1,j) // for next iteration
3415 % let ( i,j-1) := ( i,j) // for next iteration
3416 % end
3417 % end
3418 %
3419 % This is a SWEEP through the data matrix.
3420 % #1: the current point of the linearized data matrix
3421 % #2: a callback (TeX code) which will be executed for each point with j>0
3422 % #3: a callback (TeX code) which will be executed if the scanline is completed, i.e. j=cols
3423 \def\pgfplotsplothandlermesh@PIPE@DECODE@matrix@collect@and@callback#1#2#3{%
3424 % NOTATION:
3425 % 'im == (i-1)'
3426 % 'jm == (j-1)'
3427 \pgfplotsplothandlermesh@compute@vertex@depth% <-- this modifies \pgfplotsretval
3428 \let\pgfplots@view@depth=\pgfplotsretval
3429 \pgf@process{#1}%
3430 \pgfplotsplothandlermesh@serialize@logical@coords
3431 \edef\pgfplotsplothandlermesh@i@j{{\the\pgf@x}{\the\pgf@y}{\pgfplots@current@point@meta}\pgfplots@view@depth:\pgfplotsretval}% FIXME relies on pgfplots macros
3432 %\message{##\the\c@pgfplots@scanlineindex: prepare rectangle with corner \meaning\pgfplotsplothandlermesh@i@j.}%
3433 \pgfplotsdequepopfront{lastscanline}\to\pgfplotsplothandlermesh@im@j
3434 \expandafter\pgfplotsdequepushback\pgfplotsplothandlermesh@i@j\to{lastscanline}%
3435 \ifnum\c@pgfplots@scanlineindex>0
3436 #2%
3437 \fi
3438 \let\pgfplotsplothandlermesh@im@jm=\pgfplotsplothandlermesh@im@j
3439 \let\pgfplotsplothandlermesh@i@jm=\pgfplotsplothandlermesh@i@j
3440 \advance\c@pgfplots@scanlineindex by1
3441 \ifnum\c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@scanlinelength\relax
3442 #3%
3443 \fi
3444 }%
3445 \def\pgfplotsplothandlermesh@PIPE@DECODE@matrix#1{%
3446 \pgfplotsplothandlermesh@PIPE@DECODE@matrix@collect@and@callback{#1}{%
3447 \let\pgfplotsplothandlermesh@patchclass\pgfplotsplothandlermesh@patchclass@input
3448 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotsplothandlermesh@im@jm}%
3449 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotsplothandlermesh@im@j}%
3450 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotsplothandlermesh@i@j}%
3451 \expandafter\pgfplotsplothandlermesh@setnextvertex\expandafter{\pgfplotsplothandlermesh@i@jm}%
3452 }{%
3453 % if scan line is completed, start the next one:
3454 \c@pgfplots@scanlineindex=0
3455 }%
3456 }%
3457
3458
3459 \def\pgfplotsplothandlermesh@shader@interp@incremental@transpose#1{%
3460 \pgfplotsaxisvisphasetransformpointmeta
3461 \pgf@process{#1}%
3462 \edef\pgfplotsplothandlermesh@i{\noexpand\pgfplotsplothandlermesh@shader@interp@next{\the\pgf@x}{\the\pgf@y}{\pgfplotspointmetatransformed}}%
3463 %
3464 % Store the postprocessed point into the appropriate row vector:
3465 \def\pgfplots@loc@TMPa{\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplotsplothandlermesh@i}\to}
3466 \expandafter\pgfplots@loc@TMPa\csname pgfp@transprow@\the\c@pgfplots@scanlineindex\endcsname%
3467 %
3468 \advance\c@pgfplots@scanlineindex by1
3469 \ifnum\c@pgfplots@scanlineindex=\pgfplotsplothandlermesh@scanlinelength\relax
3470 \c@pgfplots@scanlineindex=0
3471 \fi
3472 }%
3473 \def\pgfplotsplothandlermesh@shader@interp@transpose@finish{%
3474 % Now, "execute" each row vector:
3475 \def\pgfplotsplothandlermesh@shader@interp@next##1##2##3{%
3476 \pgfplotslibrarysurfstreamcoord{\global\pgf@x=##1 \global\pgf@y=##2 }{##3}%
3477 }%
3478 \c@pgfplots@scanlineindex=0
3479 \pgfutil@loop
3480 \ifnum\c@pgfplots@scanlineindex<\pgfplotsplothandlermesh@rows\relax
3481 \expandafter\pgfplotsapplistXlet\expandafter\pgfplots@loc@TMPd\expandafter=\csname pgfp@transprow@\the\c@pgfplots@scanlineindex\endcsname%
3482 \expandafter\pgfplotsapplistXnewempty\csname pgfp@transprow@\the\c@pgfplots@scanlineindex\endcsname% clear
3483 % execute the row:
3484 \pgfplots@loc@TMPd
3485 \advance\c@pgfplots@scanlineindex by1
3486 \pgfutil@repeat
3487 \let\pgfplots@loc@TMPd=\relax
3488 }%
3489
3490 \def\pgfplotsplothandlermesh@draw@zbufferelement#1#2{%
3491 \pgfplotsplothandlermesh@draw@zbufferelement@#2\pgfplots@EOI
3492 }
3493 \def\pgfplotsplothandlermesh@draw@zbufferelement@#1{%
3494 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{deserialize except vertices}{#1}%
3495 \pgfplotsplothandlermesh@draw@zbufferelement@@
3496 }
3497 \def\pgfplotsplothandlermesh@draw@zbufferelement@@#1{%
3498 \def\pgfplots@loc@TMPa{#1}%
3499 \ifx\pgfplots@loc@TMPa\pgfplots@EOI
3500 \else
3501 \pgfplotspatchclass{\pgfplotsplothandlermesh@patchclass@output}{set next vertex}{#1}%
3502 \expandafter\pgfplotsplothandlermesh@draw@zbufferelement@@
3503 \fi
3504 }%
3505
3506
3507 \def\pgfplotsplothandlermesh@zbuffer@sort@iflessthen#1#2#3#4\pgfeov{%
3508 \edef\pgfplots@loc@TMPa{#1}%
3509 \expandafter\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@\pgfplots@loc@TMPa\relax
3510 \let\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@a=\pgfmathresult
3511 \edef\pgfplots@loc@TMPb{#2}%
3512 \expandafter\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@\pgfplots@loc@TMPb\relax
3513 \let\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@b=\pgfmathresult
3514 \ifdim\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@b pt<\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@a pt%
3515 #3\relax
3516 \else
3517 #4\relax
3518 \fi
3519 }%
3520 \def\pgfplotsplothandlermesh@zbuffer@sort@iflessthen@#1#2{%
3521 \def\pgfmathresult{#1}%
3522 }%
3523 \def\pgfplotsplothandlermesh@unpack@zbuffer@pointdepth#1{%
3524 \expandafter\pgfplotsplothandlermesh@unpack@zbuffer@pointdepth@#1%
3525 }%
3526 \def\pgfplotsplothandlermesh@unpack@zbuffer@pointdepth@#1#2#3#4{%
3527 \def\pgfplotsretval{#4}%
3528 }%