Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: objects with transparency rendered using opengl looks wrong in export
Date: Thu, 31 Jul 2008 06:05:11 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 109
Message-ID: <g6rkmn$ld9$1@fred.mathworks.com>
References: <g4ctoc$5li$1@fred.mathworks.com> <g4cuqe$hr0$1@gemini.csx.cam.ac.uk> <g4emf9$7fa$1@fred.mathworks.com> <g6n11e$anh$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1217484311 21929 172.30.248.37 (31 Jul 2008 06:05:11 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 31 Jul 2008 06:05:11 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1395525
Xref: news.mathworks.com comp.soft-sys.matlab:482840



"Rebecca " <rebecca.hodge@ges.gla.ac.uk> wrote in message
<g6n11e$anh$1@fred.mathworks.com>...
> I've got the same problem, and have just tried your code and
> get the same result as you. Have you found a solution yet?
> 
> "Abe Lau" <abe@nonexistancegmail.com> wrote in message
> <g4emf9$7fa$1@fred.mathworks.com>...
> > tpl@eng.cam.ac.uk (Tim Love) wrote in message
> > <g4cuqe$hr0$1@gemini.csx.cam.ac.uk>...
> > > "Abe Lau" <abe@nonexistancegmail.com> writes:
> > > 
> > > >Hi all,
> > > >I have been trying to plot some datum points using
plot3 to
> > > >a figure with a transparent surfaces created using
> patch and
> > > >isosurface.
> > > 
> > > >However, whenever I want to export the figure to png/pdf
> > > If you've not already done so, it's worth reading about
> > print's renderer
> > > and how it's chosen.
> > > 
> > > Note also that in matlab 7.4 "help print" says
> > >  There are cases, however, where the printed output is not
> > exactly
> > >  like the screen representation because of this. In these
> > instances
> > >  specifying -zbuffer or -opengl will more likely give you
> > output that
> > >  emulates the screen.
> > > (note, alas, the "more likely")
> > 
> > tpl, thx for your suggestion.  This is an interesting thing
> > to try!  but unfortunately this doesn't fix the wrong
> > viewpoint in the exported file.  The points which is
> > obviously in front of the transparent surface still looks
> > "behind" in the exported pdf
> > 
> > just an example:
> > load mri;
> > figure; patch(isosurface(squeeze(D), 10),...
> >     'FaceColor', [0.8 0.8 0.8],...
> >     'EdgeColor','none',...
> >     'FaceAlpha', 0.8,...
> >     'AmbientStrength', 0.5,...
> >     'DiffuseStrength', 0.1,...
> >     'SpecularColorReflectance', 1,...
> >     'SpecularExponent', 0.5,...
> >     'SpecularStrength', 0.5);
> > hold on; 
> > plot3(64,10,20, 'o',...
> >     'MarkerSize', 20,...
> >     'MarkerFaceColor', 'Blue')
> > 
> > The blue dot is obviously way in front of the head if you
> > rotate it, but when exported to pdf/png, the point looks as
> > if it's hidden inside the head!  Would that be something
> > wrong with my graphics card/OpenGL implementation?  would be
> > great if someone can try the above out and let me know if
> > they have the same issue or not.
> > 
> > Thanks
> 
Hi Rebecca,
unfortunately I have to say my experience with matlab export
is really bad whenever there're transparent OpenGL object. 
The version I'm currently using (2008a) is even worse in
this regard with saved figures not appearing the same when
reopened, and all sorts of redrawing issues.

I haven't found a decent solution, but a workaround is to
avoid using plot3 at all.

I just write up something like this to replace (or overlay)
3D points (basically a sphere), not very sure what option
you have for more complicated plots...

function draw_sphere(centre, r, handle, varargin)

% default no. of faces on the sphere
n = 20;
facealpha = 0.5;

if nargin > 3
    n = varargin{1};
end

if nargin > 4
    facealpha = varargin{2};
end

% change to current axes
figure(handle);

[x y z] = sphere(n);

% scale to radius
x = x*r + centre(1);
y = y*r + centre(2);
z = z*r + centre(3);

hold on;
h_sphere = surface(x,y,z);
hold off;

% set alpha transparency and line width
set(h_sphere, 'FaceAlpha', facealpha);
set(h_sphere, 'LineWidth', 1);