From p.murrell at auckland.ac.nz  Sun Oct  3 01:35:52 2010
From: p.murrell at auckland.ac.nz (Paul Murrell)
Date: Sun, 03 Oct 2010 12:35:52 +1300
Subject: [Rd] strange interaction between rasterImage and Grid graphics
In-Reply-To: <AANLkTimX=5B478CCrEjCX0Y0Kw-FVuu=6ED5kYQ0iykY@mail.gmail.com>
References: <AANLkTimX=5B478CCrEjCX0Y0Kw-FVuu=6ED5kYQ0iykY@mail.gmail.com>
Message-ID: <4CA7C1D8.7050202@auckland.ac.nz>

Hi

baptiste auguie wrote:
> Dear all,
> 
> This may be specific to Mac, I haven't had a chance to test another
> platform. Consider this,
> 
> plot(1,1,t="n")
> rasterImage(matrix(1),1,1,1,1)
> library(grid)
> grid.rect(gp=gpar(fill="grey"))
 >
> The grid.rect covers the full device window as expected. However, when
> I resize the window ever so slightly (interactive device) the rectGrob
> is suddenly clipped to the previous plot window. I cannot understand
> this behavior, and it doesn't happen if one removes the rasterImage()
> call, so I suspect something iffy is going on with the display list or
> something.

It happens like this:

# 1. Clip to the device and draw axes and labels
plot(1,1,t="n")
# 2. Clip to the plot region and draw raster
rasterImage(matrix(1),1,1,1,1)
library(grid)
# Oooh!  This is the first time any grid drawing
# has occurred on the device, so initialize grid
# stuff, including the top-level viewport,
# *which clips to the device*
# 3. Draw a rectangle
grid.rect(gp=gpar(fill="grey"))

# Resize the window ...
# which triggers a redraw ...
# Oooh! There is grid output on this device so
# initialize grid stuff, including the top-level
# viewport *which clips to the device* ...
# 1. Clip to the device and draw axes and labels
# 2. Clip to the plot region and draw raster
# 3. Draw a rectangle

A workaround is to explicitly do a clip before the grid.rect(), i.e., ...

plot(1,1,t="n")
rasterImage(matrix(1),1,1,1,1)
library(grid)
grid.clip()
grid.rect(gp=gpar(fill="grey"))

... and I will add this example to the things I will look at when I am 
trying to clean up the grid code a bit.

> The only device I've tried is quartz(), x11() crashed with rasterImage,

That is more serious.  I have heard of a couple of others like this and 
I think the common thread may be 64-bit MacOS X.  I need to get access 
to such a beast to take a look.

Paul

>  *** caught segfault ***
> address 0x28, cause 'memory not mapped'
> 
> Traceback:
>  1: rasterImage(matrix(1), 1, 1, 1, 1)
> 
> sessionInfo()
> R version 2.11.1 (2010-05-31)
> x86_64-apple-darwin9.8.0
> 
> locale:
> [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8
> 
> attached base packages:
> [1] grid      stats     graphics  grDevices utils     datasets  methods   base
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



[Rd] strange interaction between rasterImage and Grid graphics
Paul Murrell