On Sun, Nov 16, 2008 at 7:45 AM, David Seery <dj...@cam.ac.uk> wrote:
>
> On 15 Nov 2008, at 02:06, Hezekiah M. Carty wrote:
>> I have seen this same issue in output from other plotting packages as
>> well. One possible workaround is to plot the shaded regions as a
>> bitmap embedded in the PS/PDF/SVG output. PLplot does not have
>> support for this directly at this time. However, you can accomplish
>> this with extra effort using the extcairo driver and a few Cairo
>> tricks. I can go in to how to do this in more detail if desired.
>
> That would be extremely useful if it were possible! I'm trying to produce a
> graph which is scalable and can be embedded within another document. It
> probably won't be possible to turn anti-aliasing off when the document is
> viewed, so this would otherwise seem to be an insurmoutable obstacle. I'm
> slightly perplexed, because I am sure I have seen plplot output before which
> contains contiguous shaded regions.
David,
I am terribly sorry for the several month delay in responding to this.
The original problem (gaps/fractures in filled regions) should be
fixed now thanks to the core devs' work. However, if you or others
have any interest, here is an OCaml function which allows one to
rasterize a PLplot plotting operation. The basic idea is that the
function "f" will be plotted on to a Cairo image surface which matches
the dimensions of the actual plot surface. The function then plots
the contents of this temporary image surface on to the Cairo
context/surface "plot", resulting in a raster image embedded in the
plot PS/PDF/SVG. This plot Cairo context is associated with PLplot
through the extcairo driver.
I have this and a set of extcairo-related functions for OCaml which I
plan on submitting some time soon or (temporarily) releasing as an
extra/add-on for OCaml's PLplot support until a suitable way of
working it in to the main source tree is found.
I think this would be useful in some form internally for PLplot. This
would allow, for instance, examples 16 and 20 to take up far less
space on disk in Postscript form. See [1] for an example 20
postscript output with rasterized images -- 859 kilobytes versus 54
megabytes for the vector form. The rasterized form renders much more
quickly and wouldn't require the extra outlining step in plfill. If
this is deemed useful, then a set of plstartraster/plendraster
functions could be used to delimit the start and end of a section of
to-be-rasterized plot functions. Output drivers which don't have
support could ignore the calls. Any thoughts?
[1] - A version of the example 20 output with rasterized plimage and
plimagefr calls using the extcairo driver and Postscript Cairo output.
Sorry for the white background - my extcairo init functions default
to a white background. I think it would look even better without the
extra outline strokes on the plfill calls:
http://www.atmos.umd.edu/~hcarty/x20_raster.ps
Hez
--
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
(** [plrasterize ?alpha plot f] applies the plotting function [f ()] to [plot],
with the caveat that the output will be rasterized for all plot
output drivers, including vector-based output drivers such as PS, PDF and
SVG.
The [alpha] parameter may be provided to make the rasterized overlay
transparent, even if the current color palette is not. *)
let plrasterize ?alpha plot f =
(* Create a Cairo image surface and context to plot the rasterized image
on. This will be a duplicate in size and shape of the current plot's
surface. Leave the background transparent, so only the plotted image
is transfered over to the main plot surface. *)
let img_sfc =
Cairo.image_surface_create
Cairo.FORMAT_ARGB32
~width:(int_of_float plot.width)
~height:(int_of_float plot.height)
in
let img_context = Cairo.create img_sfc in
(* Assign the transformation matrix from the main plot context to maintain
consistency. It will also have to be applied to the main plot context
again once back to it. *)
let plot_matrix = Cairo.get_matrix plot.context in
Cairo.set_matrix img_context plot_matrix;
plset_cairo_context img_context;
(* Make sure antialiasing is turned OFF for the. The output looks bad
otherwise. *)
Cairo.set_antialias img_context Cairo.ANTIALIAS_NONE;
(* This will now be plotted on to the Cairo image surface. *)
f ();
(* Blit the raster image on to the main plot surface *)
Cairo.set_source_surface plot.context img_sfc 0.0 0.0;
let () =
match alpha with
| None -> Cairo.paint plot.context
| Some a -> Cairo.paint_with_alpha plot.context a
in
(* Now set PLplot back to using the proper plot context. *)
plset_cairo_context plot.context;
Cairo.set_matrix plot.context plot_matrix;
(* Don't forget to do a [Cairo.surface_finish] when everything is done!
Of course, that isn't done here because the plot may not be finished
yet... and plend () may do this anyway? *)
()
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel