| 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-2012 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 |
%-------------------------------------------------- |
| 28 |
% \pgfqkeys{/pgfplots/surf shading}{ |
| 29 |
% cols=3, |
| 30 |
% % test colormap 1, |
| 31 |
% } |
| 32 |
% \pgfplotslibrarysurfstreamstart |
| 33 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{0pt}{10pt}}{0} |
| 34 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{100pt}{10pt}}{100} |
| 35 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{180pt}{10pt}}{30} |
| 36 |
% % |
| 37 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{0pt}{100pt}}{300} |
| 38 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{110pt}{90pt}}{1000} |
| 39 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{190pt}{110pt}}{600} |
| 40 |
% % |
| 41 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{0pt}{200pt}}{0} |
| 42 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{110pt}{200pt}}{100} |
| 43 |
% \pgfplotslibrarysurfstreamcoord{\pgfqpoint{190pt}{200pt}}{60} |
| 44 |
% \pgfplotslibrarysurfstreamend |
| 45 |
% \fbox{% |
| 46 |
% \pgfplotslibrarysurfdraw |
| 47 |
% }% |
| 48 |
%-------------------------------------------------- |
| 49 |
|
| 50 |
|
| 51 |
\newif\ifpgfplotslibrarysurf@updatebb |
| 52 |
\newif\ifpgfplotslibrarysurf@usecolormap |
| 53 |
\pgfplotslibrarysurf@updatebbtrue |
| 54 |
|
| 55 |
\pgfkeys{% |
| 56 |
/pgfplots/surf shading/anchor/.initial=\pgfpointorigin,% |
| 57 |
/pgfplots/surf shading/shading type/.initial=5,% triangles in form of lattice |
| 58 |
% |
| 59 |
% If this is true, the embedding picture's bounding box will be updated using |
| 60 |
% the shading's bounding box. |
| 61 |
% This bounding box may be (highly!) inaccurate for coons shadings and tensor product shadings. |
| 62 |
% The 'patch' plot handler disables it and takes control over it explicitly (using interpolation |
| 63 |
% points rather than bezier control points). |
| 64 |
/pgfplots/surf shading/update BB/.is if=pgfplotslibrarysurf@updatebb, |
| 65 |
% |
| 66 |
% can only have values '' (empty) for binary encoding or |
| 67 |
% ASCIIHexEncode for base 16 encoding. Use this if some driver |
| 68 |
% cannot produce binary encoding. This is undocumented; for use in |
| 69 |
% emergency only. |
| 70 |
/pgfplots/surf shading/pdf stream filter/.initial=,% |
| 71 |
% |
| 72 |
/pgfplots/surf shading/precision/.is choice, |
| 73 |
/pgfplots/surf shading/precision/pdf/.code={% |
| 74 |
% Lossless coordinate output. |
| 75 |
\def\pgfplotslibrarysurf@bitspercoordinate{32}% |
| 76 |
\def\pgfplotslibrarysurf@bytespercoordinate{4}% |
| 77 |
\def\pgfplotslibrarysurf@filter@encode{}% raw binary. |
| 78 |
\def\pgfplotslibrarysurf@filter@decode{}% |
| 79 |
},% |
| 80 |
/pgfplots/surf shading/precision/ps/.code={% |
| 81 |
% quantized coordinate output (introduces quantization error). |
| 82 |
\def\pgfplotslibrarysurf@bitspercoordinate{24}% |
| 83 |
\def\pgfplotslibrarysurf@bytespercoordinate{3}% |
| 84 |
% doesn't improve behavior of pdf2ps: |
| 85 |
%\def\pgfplotslibrarysurf@filter@encode{ASCIIHexEncode}% |
| 86 |
%\def\pgfplotslibrarysurf@filter@decode{ASCIIHexDecode}% |
| 87 |
\def\pgfplotslibrarysurf@filter@encode{}% raw binary. |
| 88 |
\def\pgfplotslibrarysurf@filter@decode{}% |
| 89 |
},% |
| 90 |
/pgfplots/surf shading/precision/postscript/.style={% |
| 91 |
/pgfplots/surf shading/precision/ps},% |
| 92 |
/pgfplots/surf shading/precision/ps,% |
| 93 |
% columns: |
| 94 |
/pgfplots/surf shading/cols/.initial=,% |
| 95 |
/pgfplots/surf shading/colorspace/.initial=rgb,% rgb or cmyk or gray |
| 96 |
% |
| 97 |
% the colormap. If this key is empty, we assume that individual |
| 98 |
% color components are provided for EVERY vertex for which cdata |
| 99 |
% is expected. |
| 100 |
/pgfplots/surf shading/colormap/.initial={% |
| 101 |
<< |
| 102 |
/FunctionType 2 |
| 103 |
/Domain [0 1] |
| 104 |
/C0 [0 0 1] /C1 [1 0 0] /N 1 |
| 105 |
>> |
| 106 |
},% |
| 107 |
/pgfplots/surf shading/test colormap 1/.style={% |
| 108 |
/pgfplots/surf shading/colormap={ |
| 109 |
<< |
| 110 |
/FunctionType 3 |
| 111 |
/Domain [0 1] |
| 112 |
/Functions [ |
| 113 |
<< |
| 114 |
/FunctionType 2 |
| 115 |
/Domain [0 1] |
| 116 |
/C0 [0 0 1] /C1 [1 1 0] /N 1 |
| 117 |
>> |
| 118 |
<< |
| 119 |
/FunctionType 2 |
| 120 |
/Domain [0 1] |
| 121 |
/C0 [1 1 0] /C1 [1 0.5 0] /N 1 |
| 122 |
>> |
| 123 |
<< |
| 124 |
/FunctionType 2 |
| 125 |
/Domain [0 1] |
| 126 |
/C0 [1 0.5 0] /C1 [1 0 0] /N 1 |
| 127 |
>> |
| 128 |
] |
| 129 |
/Bounds [ 0.3 0.6 ] |
| 130 |
/Encode [0 1 0 1 0 1] |
| 131 |
%/Range [0 1 0 1 0 1] INCOMPATIBLE WITH ACROBAT 6.0 |
| 132 |
>> |
| 133 |
}% |
| 134 |
},% |
| 135 |
/pgfplots/surf shading/debug text/.initial=\the\c@pgfplotslibrarysurf@no, |
| 136 |
/pgfplots/surf shading/every debug coord/.style={ |
| 137 |
circle, |
| 138 |
draw, |
| 139 |
fill=yellow, |
| 140 |
}, |
| 141 |
/pgfplots/surf shading/debug/.is choice, |
| 142 |
/pgfplots/surf shading/debug/false/.code={% |
| 143 |
\let\pgfplotslibrarysurfprocesscoordinate=\pgfplotslibrarysurfprocesscoordinate@orig |
| 144 |
\let\pgfplotslibrarysurfusepath=\pgfplotslibrarysurfusepath@orig |
| 145 |
}, |
| 146 |
/pgfplots/surf shading/debug/true/.code={% |
| 147 |
\let\pgfplotslibrarysurfprocesscoordinate=\pgfplotslibrarysurfprocesscoordinate@debug |
| 148 |
\def\pgfplotslibrarysurfusepath{\pgfusepath{stroke,fill}} |
| 149 |
}, |
| 150 |
/pgfplots/surf shading/debug/.default=true, |
| 151 |
}% |
| 152 |
|
| 153 |
\def\pgfplotslibrarysurf@corner@sw{\pgfplots@error{This is unavailable until \string\pgfplotslibrarysurfstreamend}} |
| 154 |
\let\pgfplotslibrarysurf@corner@ne\pgfplotslibrarysurf@corner@sw |
| 155 |
|
| 156 |
% parametric colors (colormap) are always in [0,1000]. I |
| 157 |
% 2 bytes suffice for that range. |
| 158 |
\def\pgfplotslibrarysurf@bytespercomponent{2}% |
| 159 |
\def\pgfplotslibrarysurf@bitspercomponent{16}% |
| 160 |
|
| 161 |
\def\pgfplotslibrarysurf@decode{% |
| 162 |
-16383.999992 16384 % see the docs of \pgfplotsbinaryencodedimenmaplinearly |
| 163 |
-16383.999992 16384 % |
| 164 |
\pgfplotslibrarysurf@decode@colors |
| 165 |
}% |
| 166 |
\def\pgfplotslibrarysurf@decode@colors@colormap{% |
| 167 |
0 \pgfplotscolormappdfmax % map [0,2^BitsPerComponent-1] linearly to [0 1] for parametric color data |
| 168 |
}% |
| 169 |
\def\pgfplotslibrarysurf@decode@colors@explicit@one@component{% |
| 170 |
% this is just one component for explicit color data. |
| 171 |
% it will be replicated for every color component. |
| 172 |
0 1 % the target value for color component values. |
| 173 |
}% |
| 174 |
|
| 175 |
\def\pgfplotslibrarysurf@count{0}% |
| 176 |
\newcount\c@pgfplotslibrarysurf@no |
| 177 |
|
| 178 |
% driver specific: |
| 179 |
\def\pgfplotslibrarysurf@initstream{% |
| 180 |
\edef\pgfplots@loc@TMPa{\pgfkeysvalueof{/pgfplots/surf shading/pdf stream filter}}% |
| 181 |
\ifx\pgfplots@loc@TMPa\pgfutil@empty |
| 182 |
\else |
| 183 |
\let\pgfplotslibrarysurf@filter@encode=\pgfplots@loc@TMPa |
| 184 |
\let\pgfplotslibrarysurf@filter@decode=\pgfplotslibrarysurf@filter@encode |
| 185 |
\fi |
| 186 |
} |
| 187 |
|
| 188 |
\def\pgfplotslibrarysurf@advancestreamlen#1{}% |
| 189 |
|
| 190 |
\def\pgfplotslibrarysurfstreamstart{% |
| 191 |
\pgfplotslibrarysurfstreamstart@init@colors |
| 192 |
\pgfkeysgetvalue{/pgfplots/surf shading/shading type}\pgfplotslibrarysurf@type |
| 193 |
\pgfplotsapplistXglobalnewempty\pgfplotslibrarysurf@binarystream@accum |
| 194 |
\pgfplotslibrarysurf@initstream |
| 195 |
\ifx\pgfplotslibrarysurf@filter@encode\pgfutil@empty |
| 196 |
\def\pgfplotslibrarysurf@filter@encode{binary encoding}% |
| 197 |
\fi |
| 198 |
\pgfkeysalso{/pgfplots/bin/\pgfplotslibrarysurf@filter@encode}% |
| 199 |
% |
| 200 |
\pgfplotsbinarysetbytes1% |
| 201 |
\pgfplotsbinaryencodeunsigned{0}% use this method - it respects any special encodings. |
| 202 |
\let\pgfplots@loc@TMPa=\pgfplotsbinaryresult |
| 203 |
\ifcase\pgfplotslibrarysurf@type\relax |
| 204 |
% 0 |
| 205 |
\pgfplotslibrarysurf@initstream@wrongtype |
| 206 |
\or% 1 |
| 207 |
\pgfplotslibrarysurf@initstream@wrongtype |
| 208 |
\or% 2 |
| 209 |
\pgfplotslibrarysurf@initstream@wrongtype |
| 210 |
\or% 3 |
| 211 |
\or% 4 |
| 212 |
% ok, triangle meshes. |
| 213 |
\let\pgfplotslibrarysurf@edgeflag=\pgfplots@loc@TMPa |
| 214 |
\or% 5 triangles in lattice form. disable edge flag: |
| 215 |
\let\pgfplotslibrarysurf@edgeflag=\pgfutil@empty |
| 216 |
\or% 6 coons patches: |
| 217 |
\global\let\pgfplotslibrarysurf@cubicpatch@cdata=\pgfutil@empty |
| 218 |
\global\c@pgfplotslibrarysurf@no=0 |
| 219 |
\def\pgfplotslibrarysurf@cubicpatch@numverts{12}% |
| 220 |
\let\pgfplotslibrarysurfstreamcoord=\pgfplotslibrarysurfstreamcoord@cubicpatch |
| 221 |
\let\pgfplotslibrarysurf@edgeflag=\pgfplots@loc@TMPa |
| 222 |
\or% 7 full tensor product cubic bezier patches: |
| 223 |
\global\let\pgfplotslibrarysurf@cubicpatch@cdata=\pgfutil@empty |
| 224 |
\global\c@pgfplotslibrarysurf@no=0 |
| 225 |
\def\pgfplotslibrarysurf@cubicpatch@numverts{16}% |
| 226 |
\let\pgfplotslibrarysurfstreamcoord=\pgfplotslibrarysurfstreamcoord@cubicpatch |
| 227 |
\let\pgfplotslibrarysurf@edgeflag=\pgfplots@loc@TMPa |
| 228 |
\else |
| 229 |
\pgfplotslibrarysurf@initstream@wrongtype |
| 230 |
\fi |
| 231 |
% |
| 232 |
% |
| 233 |
% we want to establish a bounding box for THIS shading only! Otherwise the pdf XFORM might have a larger bounding box than we want. Is that ok here? Or does it hurt somewhere? |
| 234 |
\pgf@getpathsizes{\pgfplots@loc@TMPa}% |
| 235 |
\global\let\pgfplotslibrarysurf@pathsizes@before=\pgfplots@loc@TMPa |
| 236 |
}% |
| 237 |
|
| 238 |
|
| 239 |
\def\pgfplotslibrarysurfstreamstart@init@colors{% |
| 240 |
% |
| 241 |
\pgfkeysgetvalue{/pgfplots/surf shading/colormap}\pgfplots@loc@TMPa |
| 242 |
\ifx\pgfplots@loc@TMPa\pgfutil@empty |
| 243 |
\pgfplotslibrarysurf@usecolormapfalse |
| 244 |
\else |
| 245 |
\pgfplotslibrarysurf@usecolormaptrue |
| 246 |
\fi |
| 247 |
% |
| 248 |
\ifpgfplotslibrarysurf@usecolormap |
| 249 |
\let\pgfplotslibrarysurf@decode@colors=\pgfplotslibrarysurf@decode@colors@colormap |
| 250 |
\else |
| 251 |
\pgfplotscolorspacegetcomponents{\pgfkeysvalueof{/pgfplots/surf shading/colorspace}}% |
| 252 |
\c@pgf@counta=0 % |
| 253 |
\c@pgf@countb=\pgfplotsretval\relax |
| 254 |
% |
| 255 |
\def\pgfplotslibrarysurf@decode@colors{}% |
| 256 |
\pgfplotslibrarysurf@decode@colors@loop |
| 257 |
\fi |
| 258 |
% |
| 259 |
\pgfplotslibrarysurf@translate@colorspace |
| 260 |
\let\pgfplotslibrarysurf@colorspace=\pgfplotsretval |
| 261 |
}% |
| 262 |
|
| 263 |
\def\pgfplotslibrarysurf@decode@colors@loop{% |
| 264 |
\ifnum\c@pgf@counta<\c@pgf@countb |
| 265 |
% |
| 266 |
\edef\pgfplotslibrarysurf@decode@colors{% |
| 267 |
\pgfplotslibrarysurf@decode@colors |
| 268 |
\pgfplotslibrarysurf@decode@colors@explicit@one@component |
| 269 |
}% |
| 270 |
\advance\c@pgf@counta by1 % |
| 271 |
% |
| 272 |
\expandafter\pgfplotslibrarysurf@decode@colors@loop |
| 273 |
\fi |
| 274 |
}% |
| 275 |
|
| 276 |
\def\pgfplotslibrarysurf@initstream@wrongtype{% |
| 277 |
\pgfplots@error{CRITICAL: shader=interp: got unsupported pdf shading type '\pgfplotslibrarysurf@type'. This may corrupt your pdf!}% |
| 278 |
}% |
| 279 |
\def\pgfplotslibrarysurfstreamend{% |
| 280 |
\pgfplotsapplistXgloballet\pgfplotslibrarysurf@binarystream=\pgfplotslibrarysurf@binarystream@accum |
| 281 |
\pgfplotsapplistXglobalnewempty\pgfplotslibrarysurf@binarystream@accum |
| 282 |
% |
| 283 |
\pgfplotslibrarysurfstreamend@set@BB |
| 284 |
} |
| 285 |
|
| 286 |
\def\pgfplotslibrarysurfdraw{% |
| 287 |
\ifx\pgfplotslibrarysurf@binarystream\pgfutil@empty |
| 288 |
\else |
| 289 |
\pgfplotslibrarysurfdraw@sys |
| 290 |
\fi |
| 291 |
}% |
| 292 |
|
| 293 |
\def\pgfplotslibrarysurfstreamend@set@BB{% |
| 294 |
\xdef\pgfplotslibrarysurf@corner@sw{% |
| 295 |
\global\pgf@x=\the\pgf@pathminx\space |
| 296 |
\global\pgf@y=\the\pgf@pathminy\space |
| 297 |
}% |
| 298 |
\xdef\pgfplotslibrarysurf@corner@ne{% |
| 299 |
\global\pgf@x=\the\pgf@pathmaxx\space |
| 300 |
\global\pgf@y=\the\pgf@pathmaxy\space |
| 301 |
}% |
| 302 |
\pgf@setpathsizes\pgfplotslibrarysurf@pathsizes@before |
| 303 |
}% |
| 304 |
|
| 305 |
% ATTENTION: see also \pgfplotslibrarysurfstreamcoord@cubicpatch |
| 306 |
% #1: a pgf point. |
| 307 |
% #2: a color coordinate in the range [0,1000] |
| 308 |
\def\pgfplotslibrarysurfstreamcoord#1#2{% |
| 309 |
\pgfplotsbinarysetbytes\pgfplotslibrarysurf@bytespercoordinate% |
| 310 |
\pgfplotslibrarysurf@advancestreamlen{\pgfplotslibrarysurf@bytespercoordinate}% |
| 311 |
\pgfplotslibrarysurf@advancestreamlen{\pgfplotslibrarysurf@bytespercoordinate}% |
| 312 |
%\pgf@process{#1}% this here causes `{retaining \pgf@x}' messages and pollutes the save stack! Avoid it. See \tracingrestores=2 |
| 313 |
\pgfplotslibrarysurfprocesscoordinate{#1}% |
| 314 |
% The idea is to map |
| 315 |
% the low-level point coordinates LINEARLY into [0,2^{8*<bytes>}]. |
| 316 |
% |
| 317 |
% This is what the pdf standard expects for surface shadings. |
| 318 |
% |
| 319 |
% To do that, we simply map |
| 320 |
% [-16384,16384] linearly into [0,2^{32}] |
| 321 |
% and write the resulting integer in big endian binary format to |
| 322 |
% the pdf low level stream. |
| 323 |
% |
| 324 |
% The decode procedure tells the pdf viewer how to invert that |
| 325 |
% stuff. |
| 326 |
% |
| 327 |
\pgf@xa=\pgf@x |
| 328 |
\pgf@sys@bp@correct\pgf@xa% |
| 329 |
\pgfplotsbinaryencodedimenmaplinearly\pgf@xa |
| 330 |
%\message{POINT \the\c@pgfplots@scanlineindex: ENCODING(x=\the\pgf@x)=\pgfplotsbinaryresult.}\advance\c@pgfplots@scanlineindex by1 |
| 331 |
\t@pgfplots@toka=\expandafter{\pgfplotsbinaryresult}% |
| 332 |
\pgf@ya=\pgf@y |
| 333 |
\pgf@sys@bp@correct\pgf@ya% |
| 334 |
\pgfplotsbinaryencodedimenmaplinearly\pgf@ya |
| 335 |
%\message{ENCODING(y=\the\pgf@y)=\pgfplotsbinaryresult.}% |
| 336 |
\t@pgfplots@tokb=\expandafter{\pgfplotsbinaryresult}% |
| 337 |
% |
| 338 |
\pgfplotslibrarysurf@encode@cdata{#2}% |
| 339 |
%\message{\pgfplotsbinaryresult.}% |
| 340 |
\t@pgfplots@tokc=\expandafter{\pgfplotsbinaryresult}% |
| 341 |
\ifx\pgfplotslibrarysurf@edgeflag\pgfutil@empty |
| 342 |
\else |
| 343 |
% for shading type 4, the edge flag is given for EVERY |
| 344 |
% coordinate (unlike all other shading types). |
| 345 |
\pgfplotslibrarysurf@advancestreamlen{1}% |
| 346 |
\fi |
| 347 |
\edef\pgfplots@loc@TMPa{\pgfplotslibrarysurf@edgeflag\the\t@pgfplots@toka\the\t@pgfplots@tokb\the\t@pgfplots@tokc}% |
| 348 |
\expandafter\pgfplotsapplistXglobalpushback\pgfplots@loc@TMPa\to\pgfplotslibrarysurf@binarystream@accum |
| 349 |
} |
| 350 |
|
| 351 |
% defines \pgfplotsbinaryresult to contain the result of a CDATA |
| 352 |
% entry and advances the stream counters. |
| 353 |
\def\pgfplotslibrarysurf@encode@cdata#1{% |
| 354 |
\ifpgfplotslibrarysurf@usecolormap |
| 355 |
\pgfplotslibrarysurf@map@to@FFF@colormap{#1}% |
| 356 |
\else |
| 357 |
% oh. No cdata. Ok, then encode stuff individually! |
| 358 |
% We expect data of the form |
| 359 |
% {<comma-separated-components>} |
| 360 |
\edef\pgfplots@loc@TMPa{#1}% |
| 361 |
\def\pgfplotsretval{}% |
| 362 |
\expandafter\pgfplotslibrarysurf@encode@cdata@loop\pgfplots@loc@TMPa,,% |
| 363 |
\global\let\pgfplotsbinaryresult=\pgfplotsretval |
| 364 |
\fi |
| 365 |
} |
| 366 |
|
| 367 |
\def\pgfplotslibrarysurf@encode@cdata@loop#1,{% |
| 368 |
\def\pgfplots@loc@TMPa{#1}% |
| 369 |
\ifx\pgfplots@loc@TMPa\pgfutil@empty |
| 370 |
\else |
| 371 |
% |
| 372 |
% |
| 373 |
\pgfplotslibrarysurf@map@to@FFF@component{#1}% |
| 374 |
\edef\pgfplotsretval{\pgfplotsretval\pgfplotsbinaryresult}% |
| 375 |
% |
| 376 |
% |
| 377 |
% continue loop: |
| 378 |
\expandafter\pgfplotslibrarysurf@encode@cdata@loop |
| 379 |
\fi |
| 380 |
}% |
| 381 |
|
| 382 |
% Defines \pgfplotsbinaryresult |
| 383 |
\def\pgfplotslibrarysurf@map@to@FFF@colormap#1{% |
| 384 |
\begingroup |
| 385 |
% read fixed point input (in the range [0,1000]). |
| 386 |
\pgf@xa=#1pt % |
| 387 |
% convert to integer (= *65536): |
| 388 |
\c@pgf@counta=\pgf@xa |
| 389 |
% provide map [0,1000] -> [0,2^16-1] |
| 390 |
\divide\c@pgf@counta by1000 |
| 391 |
% now, we have \c@pgf@counta in [0,2^16]. Simply strip it into |
| 392 |
% the required range, that's ok. |
| 393 |
\ifnum\c@pgf@counta<0 |
| 394 |
\c@pgf@counta=0 |
| 395 |
\else |
| 396 |
\ifnum\c@pgf@counta>65535 |
| 397 |
\c@pgf@counta=65535 |
| 398 |
\fi |
| 399 |
\fi |
| 400 |
% Now, we have CDATA in the range [0,65535] |
| 401 |
\xdef\pgfplots@glob@TMPa{\the\c@pgf@counta}% |
| 402 |
%\message{ENCODING(C=\pgfplots@glob@TMPa\space for \the\pgf@xa)=}% |
| 403 |
\endgroup |
| 404 |
\pgfplotsbinarysetbytes\pgfplotslibrarysurf@bytespercomponent% |
| 405 |
\pgfplotsbinaryencodeunsigned\pgfplots@glob@TMPa |
| 406 |
\pgfplotslibrarysurf@advancestreamlen{\pgfplotslibrarysurf@bytespercomponent}% |
| 407 |
} |
| 408 |
|
| 409 |
% Defines \pgfplotsbinaryresult |
| 410 |
\def\pgfplotslibrarysurf@map@to@FFF@component#1{% |
| 411 |
\begingroup |
| 412 |
% read fixed point input (in the range [0,1]). |
| 413 |
\pgf@xa=#1pt % |
| 414 |
% convert to integer (= *65536): |
| 415 |
\c@pgf@counta=\pgf@xa |
| 416 |
% provide map [0,1] -> [0,2^16-1] |
| 417 |
% well, there is nothing to do! it was in [0,1], we multiplied by 65536 implicitly... that's it. |
| 418 |
% |
| 419 |
% now, we have \c@pgf@counta in [0,2^16]. Simply strip it into |
| 420 |
% the required range, that's ok. |
| 421 |
\ifnum\c@pgf@counta<0 |
| 422 |
\c@pgf@counta=0 |
| 423 |
\else |
| 424 |
\ifnum\c@pgf@counta>65535 |
| 425 |
\c@pgf@counta=65535 |
| 426 |
\fi |
| 427 |
\fi |
| 428 |
% Now, we have CDATA in the range [0,65535] |
| 429 |
\xdef\pgfplots@glob@TMPa{\the\c@pgf@counta}% |
| 430 |
%\message{ENCODING(C=\pgfplots@glob@TMPa\space for \the\pgf@xa)=}% |
| 431 |
\endgroup |
| 432 |
\pgfplotsbinarysetbytes\pgfplotslibrarysurf@bytespercomponent% |
| 433 |
\pgfplotsbinaryencodeunsigned\pgfplots@glob@TMPa |
| 434 |
\pgfplotslibrarysurf@advancestreamlen{\pgfplotslibrarysurf@bytespercomponent}% |
| 435 |
} |
| 436 |
|
| 437 |
\def\pgfplotslibrarysurf@translate@colorspace{% |
| 438 |
\pgfkeysgetvalue{/pgfplots/surf shading/colorspace}\pgfplots@loc@TMPd |
| 439 |
\edef\pgfplots@loc@TMPd{\pgfplots@loc@TMPd}% |
| 440 |
\def\pgfplots@loc@TMPa{rgb}% |
| 441 |
\ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPd |
| 442 |
\def\pgfplotsretval{RGB}% |
| 443 |
\else |
| 444 |
\def\pgfplots@loc@TMPa{cmyk}% |
| 445 |
\ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPd |
| 446 |
\def\pgfplotsretval{CMYK}% |
| 447 |
\else |
| 448 |
\def\pgfplots@loc@TMPa{cmy}% |
| 449 |
\ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPd |
| 450 |
\def\pgfplotsretval{CMY}% |
| 451 |
\else |
| 452 |
\def\pgfplots@loc@TMPa{gray}% |
| 453 |
\ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPd |
| 454 |
\def\pgfplotsretval{Gray}% |
| 455 |
\else |
| 456 |
\pgfplots@error{Sorry, the 'surfshading' lib failed to recognise the choice '/pgfplots/surf shading/colorspace=\pgfplots@loc@TMPd'... maybe you misspelled it?}% |
| 457 |
\def\pgfplotsretval{RGB}% |
| 458 |
\fi |
| 459 |
\fi |
| 460 |
\fi |
| 461 |
\fi |
| 462 |
}% |
| 463 |
|
| 464 |
\def\pgfplotslibrarysurfusepath{\pgfusepath{fill}} |
| 465 |
\let\pgfplotslibrarysurfusepath@orig=\pgfplotslibrarysurfusepath |
| 466 |
|
| 467 |
% We DO want to protocol the size of the shading. In fact, we NEED a |
| 468 |
% bounding box which contains the whole shading, otherwise it will be |
| 469 |
% clipped. More precisely, it will be packed into a pdf XForm object |
| 470 |
% and that appears to need a correct bounding box. |
| 471 |
% |
| 472 |
% But we do NOT want to update the picture's bounding box, only that |
| 473 |
% of the pdf XForm. The picture's bounding box will be updated as soon |
| 474 |
% as we *use* the shading anyway (in |
| 475 |
% \pgfplotslibrarysurfdrawinpicture). This here takes care of that detail: |
| 476 |
\def\pgfplotslibrarysurf@protocolsizes@#1#2{% |
| 477 |
\ifpgf@relevantforpicturesize |
| 478 |
\pgfplots@loc@tmptrue |
| 479 |
\else |
| 480 |
\pgfplots@loc@tmpfalse |
| 481 |
\fi |
| 482 |
\pgf@relevantforpicturesizefalse |
| 483 |
\pgf@protocolsizes{#1}{#2}% |
| 484 |
\ifpgfplots@loc@tmp |
| 485 |
\pgf@relevantforpicturesizetrue |
| 486 |
\fi |
| 487 |
}% |
| 488 |
|
| 489 |
\def\pgfplotslibrarysurfprocesscoordinate#1{% |
| 490 |
#1\relax% |
| 491 |
\pgfplotslibrarysurf@protocolsizes@{\pgf@x}{\pgf@y}% |
| 492 |
}% |
| 493 |
\let\pgfplotslibrarysurfprocesscoordinate@orig=\pgfplotslibrarysurfprocesscoordinate% |
| 494 |
|
| 495 |
\def\pgfplotslibrarysurfprocesscoordinate@debug#1{% |
| 496 |
\pgfinterruptpath |
| 497 |
\scope |
| 498 |
\pgftransformshift{#1}% |
| 499 |
\node[/pgfplots/surf shading/every debug coord] at (0pt,0pt) {\pgfkeysvalueof{/pgfplots/surf shading/debug text}};% |
| 500 |
\endscope |
| 501 |
\endpgfinterruptpath |
| 502 |
#1\relax% |
| 503 |
\pgfplotslibrarysurf@protocolsizes@{\pgf@x}{\pgf@y}% |
| 504 |
}% |
| 505 |
|
| 506 |
% ATTENTION: see also \pgfplotslibrarysurfstreamcoord |
| 507 |
% special routine for coons type patches and cubic tensor product type |
| 508 |
% patches. It has FIRST all vertices, |
| 509 |
% THEN the cdata. Furthermore, it only has 4 CDATA points, but a total |
| 510 |
% of 12 vertices. |
| 511 |
% |
| 512 |
% #1: a pgf point. |
| 513 |
% #2: a color coordinate in the range [0,1000] |
| 514 |
\def\pgfplotslibrarysurfstreamcoord@cubicpatch#1#2{% |
| 515 |
\pgfplotsbinarysetbytes\pgfplotslibrarysurf@bytespercoordinate% |
| 516 |
\pgfplotslibrarysurf@advancestreamlen{\pgfplotslibrarysurf@bytespercoordinate}% |
| 517 |
\pgfplotslibrarysurf@advancestreamlen{\pgfplotslibrarysurf@bytespercoordinate}% |
| 518 |
%\pgf@process{#1}% this here causes `{retaining \pgf@x}' messages and pollutes the save stack! Avoid it. See \tracingrestores=2 |
| 519 |
\pgfplotslibrarysurfprocesscoordinate{#1}% |
| 520 |
% The idea is to map |
| 521 |
% the low-level point coordinates LINEARLY into [0,2^{8*<bytes>}]. |
| 522 |
% |
| 523 |
% This is what the pdf standard expects for surface shadings. |
| 524 |
% |
| 525 |
% To do that, we simply map |
| 526 |
% [-16384,16384] linearly into [0,2^{32}] |
| 527 |
% and write the resulting integer in big endian binary format to |
| 528 |
% the pdf low level stream. |
| 529 |
% |
| 530 |
% The decode procedure tells the pdf viewer how to invert that |
| 531 |
% stuff. |
| 532 |
% |
| 533 |
\pgf@xa=\pgf@x |
| 534 |
\pgf@sys@bp@correct\pgf@xa% |
| 535 |
\pgfplotsbinaryencodedimenmaplinearly\pgf@xa |
| 536 |
%\message{POINT \the\c@pgfplots@scanlineindex: ENCODING(x=\the\pgf@x)=\pgfplotsbinaryresult.}\advance\c@pgfplots@scanlineindex by1 |
| 537 |
\t@pgfplots@toka=\expandafter{\pgfplotsbinaryresult}% |
| 538 |
\pgf@ya=\pgf@y |
| 539 |
\pgf@sys@bp@correct\pgf@ya% |
| 540 |
\pgfplotsbinaryencodedimenmaplinearly\pgf@ya |
| 541 |
%\message{ENCODING(y=\the\pgf@y)=\pgfplotsbinaryresult.}% |
| 542 |
\t@pgfplots@tokb=\expandafter{\pgfplotsbinaryresult}% |
| 543 |
\def\pgfplotslibrarysurf@cubicpatch@hascdata{0}% |
| 544 |
\ifnum\c@pgfplotslibrarysurf@no=0 |
| 545 |
\def\pgfplotslibrarysurf@cubicpatch@hascdata{1}% |
| 546 |
% prepend edge flag. it is a new patch. |
| 547 |
\t@pgfplots@toka=\expandafter{\expandafter\pgfplotslibrarysurf@edgeflag\the\t@pgfplots@toka}% |
| 548 |
\pgfplotslibrarysurf@advancestreamlen{1}% |
| 549 |
\else |
| 550 |
\ifnum\c@pgfplotslibrarysurf@no=3 |
| 551 |
\def\pgfplotslibrarysurf@cubicpatch@hascdata{1}% |
| 552 |
\else |
| 553 |
\ifnum\c@pgfplotslibrarysurf@no=6 |
| 554 |
\def\pgfplotslibrarysurf@cubicpatch@hascdata{1}% |
| 555 |
\else |
| 556 |
\ifnum\c@pgfplotslibrarysurf@no=9 |
| 557 |
\def\pgfplotslibrarysurf@cubicpatch@hascdata{1}% |
| 558 |
\fi |
| 559 |
\fi |
| 560 |
\fi |
| 561 |
\fi |
| 562 |
\if1\pgfplotslibrarysurf@cubicpatch@hascdata |
| 563 |
% |
| 564 |
\pgfplotslibrarysurf@encode@cdata{#2}% |
| 565 |
%\message{\pgfplotsbinaryresult.}% |
| 566 |
\t@pgfplots@tokc=\expandafter{\pgfplotslibrarysurf@cubicpatch@cdata}% |
| 567 |
\xdef\pgfplotslibrarysurf@cubicpatch@cdata{% |
| 568 |
\the\t@pgfplots@tokc |
| 569 |
\pgfplotsbinaryresult |
| 570 |
}% |
| 571 |
\fi |
| 572 |
\global\advance\c@pgfplotslibrarysurf@no by1 |
| 573 |
% |
| 574 |
\ifnum\pgfplotslibrarysurf@cubicpatch@numverts=\c@pgfplotslibrarysurf@no %finalize patch. |
| 575 |
\t@pgfplots@tokc=\expandafter{\pgfplotslibrarysurf@cubicpatch@cdata}% |
| 576 |
\global\let\pgfplotslibrarysurf@cubicpatch@cdata=\pgfutil@empty |
| 577 |
\global\c@pgfplotslibrarysurf@no=0 |
| 578 |
\else |
| 579 |
\t@pgfplots@tokc={}% |
| 580 |
\fi |
| 581 |
% edge flag is already in \t@pgfplots@toka (if this is the first |
| 582 |
% vertex) |
| 583 |
\edef\pgfplots@loc@TMPa{\the\t@pgfplots@toka\the\t@pgfplots@tokb\the\t@pgfplots@tokc}% |
| 584 |
\expandafter\pgfplotsapplistXglobalpushback\pgfplots@loc@TMPa\to\pgfplotslibrarysurf@binarystream@accum |
| 585 |
} |
| 586 |
|
| 587 |
\def\pgfplotslibrarysurfactivateshadefill{% |
| 588 |
\pgfplotssys@do@surfshading@fillpaths\pgfplots@loc@TMPa% |
| 589 |
\expandafter\pgfutil@addpdfresource@patterns\expandafter{\pgfplots@loc@TMPa}%% |
| 590 |
} |
| 591 |
|
| 592 |
%-------------------------------------------------- |
| 593 |
% \def\pgfplotslibrarysurfdraw{% |
| 594 |
% % \pgftext[at=\pgfqpoint{0pt}{0pt}]% |
| 595 |
% {\pgfplotssys@do@surfshading}% |
| 596 |
% }% |
| 597 |
%-------------------------------------------------- |
| 598 |
|
| 599 |
\def\pgfplotslibrarysurfdrawinpicture{% |
| 600 |
\begingroup |
| 601 |
% this statement will modify both the picture's BB and the path's BB |
| 602 |
% unless we take control. |
| 603 |
% |
| 604 |
% Note that the path's BB will eventually be updated into the |
| 605 |
% picture's BB as well (meaning that 'overlay' is of no use inside |
| 606 |
% of this group). |
| 607 |
% |
| 608 |
% Implement the 'surf shading/update BB' functionality here: |
| 609 |
\let\pgfplots@@protocolsizes=\pgf@protocolsizes |
| 610 |
\ifpgfplotslibrarysurf@updatebb |
| 611 |
\else |
| 612 |
% NO update to any BB. this implies 'overlay' |
| 613 |
% *and* disables updates to the path's BB. |
| 614 |
\def\pgf@protocolsizes##1##2{\relax}% |
| 615 |
\fi |
| 616 |
\pgftext[at=\pgfplotslibrarysurf@corner@sw,left,bottom] {% |
| 617 |
\begingroup |
| 618 |
% inside of this box, we *always* need bounding boxes. |
| 619 |
% restore functionality. |
| 620 |
\let\pgf@protocolsizes=\pgfplots@@protocolsizes |
| 621 |
\pgfplotslibrarysurfdraw |
| 622 |
\endgroup |
| 623 |
% this does NOT work because I can't undo the box' shift: |
| 624 |
%\pgfplotssys@do@surfshading |
| 625 |
}% |
| 626 |
\endgroup |
| 627 |
} |
| 628 |
|
| 629 |
\pgfplotsiffileexists{pgflibrarypgfplots.surfshading.\pgfsysdriver}{% |
| 630 |
\input pgflibrarypgfplots.surfshading.\pgfsysdriver\relax |
| 631 |
\def\pgflibrarysurfshadingifactive#1#2{#1}% |
| 632 |
}{% |
| 633 |
\def\pgfplotslibrarysurfdraw@sys{% |
| 634 |
\pgfplots@error{Sorry, surfshading (shader=interp) is NOT available for the selected driver `\pgfsysdriver'.}% |
| 635 |
}% |
| 636 |
\def\pgflibrarysurfshadingifactive#1#2{#2}% |
| 637 |
} |
| 638 |
\endinput |