Thread Subject: objects with transparency rendered using opengl looks wrong in export

Subject: objects with transparency rendered using opengl looks wrong in export

From: Abe Lau

Date: 1 Jul, 2008 09:35:08

Message: 1 of 8

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,
the datum points plotted will look as if it is inside the
surface, even when the point is definitely outside the
object (as confirmed by rotating the object). The datum
points look in front of the transparent object on screen
(expected), but not in the exported pdf/png file. Is it a
known bug, or is there any workaround? Thanks

Subject: objects with transparency rendered using opengl looks wrong in export

From: tpl@eng.cam.ac.uk (Tim Love)

Date: 1 Jul, 2008 09:53:18

Message: 2 of 8

"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")

Subject: objects with transparency rendered using opengl looks wrong in export

From: Abe Lau

Date: 2 Jul, 2008 01:43:05

Message: 3 of 8

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

Subject: objects with transparency rendered using opengl looks wrong in export

From: Rebecca

Date: 29 Jul, 2008 12:05:02

Message: 4 of 8

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

Subject: objects with transparency rendered using opengl looks wrong in export

From: Abe Lau

Date: 31 Jul, 2008 06:05:11

Message: 5 of 8

"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);

Subject: objects with transparency rendered using opengl looks wrong in export

From: Tim Hellwig

Date: 29 Sep, 2009 09:48:01

Message: 6 of 8

Do you have any working solution to your problem yet?
How do you workaround using plot3?
I tried Scatter3 in combination with your implementation of a transparent sphere but i am getting the same results. Points appear to be inside the sphere.

Best regards,
Tim


"Abe Lau" <abe@nonexistancegmail.com> wrote in message <g6rkmn$ld9$1@fred.mathworks.com>...
> "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);

Subject: objects with transparency rendered using opengl looks wrong in export

From: Sebastiaan

Date: 29 Sep, 2009 10:42:05

Message: 7 of 8

"Tim Hellwig" <tim.hellwig@googlemail.com> wrote in message <h9sl4h$30i$1@fred.mathworks.com>...
> Do you have any working solution to your problem yet?
> How do you workaround using plot3?
> I tried Scatter3 in combination with your implementation of a transparent sphere but i am getting the same results. Points appear to be inside the sphere.
>
Exporting figures seldomly works as expected. I use export_fig to export figures:
http://www.mathworks.com/matlabcentral/fileexchange/23629

which solved a lot of issues I had with the Matlab default export. I have no idea if it works for your problem, but it is worth to try.

Subject: objects with transparency rendered using opengl looks wrong in export

From: Tim Hellwig

Date: 29 Sep, 2009 12:39:02

Message: 8 of 8

"Sebastiaan " <s.breedveld@erasmusmc.REMOVE.BOO.BOO.nl> wrote in message <h9so9s$34l$1@fred.mathworks.com>...
>
> Exporting figures seldomly works as expected. I use export_fig to export figures:
> http://www.mathworks.com/matlabcentral/fileexchange/23629
>
> which solved a lot of issues I had with the Matlab default export. I have no idea if it works for your problem, but it is worth to try.

Unfortunately it doesn't solve the problem. Seems to be a problem with opengl renderer and transperancy. Thx a lot though the tool seems to be nice for other plots.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
patch isosurfac... Abe Lau 1 Jul, 2008 21:45:14
opengl patch tr... Abe Lau 1 Jul, 2008 05:40:08
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com