Get from Ico-github-logo

Highlights from
Export figure to 3D interactive PDF

  • [strmodelshading, strface...
  • check_file_extension(fnam...
    See also CLEAR_FILE_EXTENSION, ISFILEXTENSION.
  • clear_file_extension(fnam...
    See also CHECK_FILE_EXTENSION, ISFILEXTENSION.
  • create_marker_lines(h, ty...
  • cut_line_to_pieces(x, npe...
  • doc_examples
  • draw_crystal_lattice
  • examples
  • fig2idtf(filename,...
    FIG2IDTF Save figure in IDTF format.
  • fig2latex(ax, fname, medi...
    FIG2LATEX Convert axes to U3D file, generating LaTeX code including it.
  • fig2pdf3d(ax, filename, m...
    FIG2PDF3D Convert axes to PDF with embedded interactive 3D image.
  • fig2u3d(ax, fname, imgtyp...
    FIG2U3D Convert figure to U3D file.
  • get_line_xyz(h)
  • get_quiver_data
  • heart3d
  • idtf2u3d(idtffile, u3dfile)
    IDTF2U3D Convert IDTF to U3D file.
  • idtf_model_nodes(n_meshes...
  • isfilextension(fname, ext...
    See also CHECK_FILE_EXTENSION, CLEAR_FILE_EXTENSION.
  • latex2pdf3d(fname, latex_...
    LATEX2PDF3D Compile LaTeX code to PDF.
  • line_pieces(vertices_all,...
    % See also u3d_pre_line, u3d_pre_contourgroup.
  • mesh_normals(points,faces)
    MESH_NORMALS compute mesh normals
  • populate_line_resource_st...
    % See also FACE_VERTEX_DATA_EQUALS_NPOINTS, VERBATIM.
  • populate_mesh_resource_st...
    % See also FACE_VERTEX_DATA_EQUALS_NPOINTS, MESH_NORMALS, VERBATIM.
  • populate_point_resource_s...
  • shaders_materials_modifie...
    File: shaders_materials_modifiers.m
  • single_mesh_resource_str(...
    % See also u3d_pre_patch.
  • test_hexagram_shape
  • u3d_in_latex(fname, media...
    U3D_IN_LATEX LaTeX code which includes a U3D file.
  • u3d_pre_contourgroup(ax)
    U3D_PRE_CONTOURGROUP Preprocess contour output to u3d.
  • u3d_pre_line(ax)
    U3D_PRE_LINE Preprocess line output to u3d.
  • u3d_pre_patch(ax)
    U3D_PRE_PATCH Preprocess surface output to u3d.
  • u3d_pre_quivergroup(ax)
    U3D_PRE_QUIVERGROUP Preprocess quiver output to u3d.
  • u3d_pre_surface(ax)
    U3D_PRE_SURFACE Preprocess surface output to u3d.
  • verbatim
    VERBATIM Get the text that appears in the next comment block.
  • view2vws(ax, filename, pa...
    VIE2VWS Saves current view in a views file for LaTeX media9 package.
  • test_fig2u3d_contour_surf.m
    function [] = test_fig2u3d_contour_surf
  • test_spiral.m
    function [] = test_fig2u3d_spiral
  • View all files

4.3

4.3 | 11 ratings Rate this file 80 Downloads (last 30 days) File Size: 50.4 KB File ID: #37640
image thumbnail

Export figure to 3D interactive PDF

by

 

27 Jul 2012 (Updated )

Export figure as U3D file or directly to 3D interactive graphics within PDF.

| Watch this File

File Information
Description

FIG2U3D saves the figure as a U3D file for inclusion as an interactive 3-dimensional figure within a PDF. Either LaTeX or Adobe Acrobat can be used to embed the U3D file in the PDF.
Development and releases on GitHub:
   https://github.com/johnyf/fig2u3d
including binaries there:
   https://github.com/johnyf/fig2u3d/releases
(linked also here).

The IDTF2U3D executables available in package from github are originally from:
   http://sourceforge.net/projects/u3d/
and can be downloaded from:
   http://www.mathworks.com/matlabcentral/fileexchange/25383-matlab-mesh-to-pdf-with-3d-interactive-object
If obtaining them from there, then place the "bin" directory in the "idtf2u3d" directory of the fig2u3d distribution.

A VWS file is also created, which contains the current camera view of the axes saved. This file can be used to set the figure's default view in the PDF to be the same with the open figure window in MATLAB.

The media9 LaTeX package can import U3D files with their associated VWS files in a PDF document. It can be found here:
   http://www.ctan.org/tex-archive/macros/latex/contrib/media9

For PDF readers which do not render 3D figures, it is possible to include an alternative 2D image as a substitute to the 3D object. For conveniency, the script saves a 2D image together with U3D file. File type and other options for exporting this 2D image can be specified as additional arguments.

FIG2PDF3D Converts the figure directly to a PDF containing only an interactive 3D graphics object.

Graphics object supported for export include:

   line, surface, patch, quivergroup, contourgroup.

Line colors and marker styles, surfaces and quivers with NaNs and surface shading are supported. Multiple instances of various objects can be plotted in the same axes and exported. Note that some limitations apply, for example filled contours are not yet supported.

Dependency detailed info:

for fig2u3d: idtf2u3d converter executable, download:
   http://www.mathworks.com/matlabcentral/fileexchange/25383-matlab-mesh-to-pdf-with-3d-interactive-object
and place the "bin" directory in the "idtf2u3d" directory of the fig2u3d distribution.

for fig2pdf3d: latex distribution (e.g. MikTeX, TeXLive, MacTeX etc.)
http://miktex.org/
http://www.tug.org/texlive/
http://tug.org/mactex/

and media9 (preferred) or movie15 LaTeX package
http://www.ctan.org/pkg/media9

Acknowledgements

Remnan, Verbatim: Get The Text Of A Block Comment., Export Fig, Create 3 D Interactive Html File From Matlab Surface, Matlab 3 D Figure To 3 D (X)Html, and Arclength inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Other requirements for fig2u3d: idtf2u3d converter executable for fig2pdf3d: latex distribution (e.g. MikTeX, TeXLive, MacTeX etc.) and media9 (preferred) or movie15 LaTeX package
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (30)
14 Oct 2014 Ioannis Filippidis

I am not sure what mathworks decided to change this time. In any case, please feel free to fork the project on github, make the fixes, and send a pull request.

14 Oct 2014 Jake

Delighted with this. However, not yet working with the Updated Graphics System on the 2014b Prerelease (can't see why). Is anyone else interested in trying this on the Prerelease?

Undefined function 'isnan' for input arguments of type
'matlab.graphics.GraphicsPlaceholder'.

Error in u3d_pre_quivergroup (line 63)
sh(isnan(sh) ) = [];

Error in fig2u3d (line 198)
[quiver_vertices, quiver_edges, quiver_colors] = u3d_pre_quivergroup(ax);

07 Aug 2014 Martin

Very nice program, thanks a lot!

Sadly the opacity of every pixel in a surface plot is not copied to the pdf. :(

@Francesco: I changed vol3d to draw the 3d-array without texture mapping. But that didn't fix the problem because the opacity is not copied.

17 Jul 2014 Danielle

I was wondering is there a way to set the line properties (i.e., line width) for the 3D pdf image? Changing the line properties in the figure in Matlab doesn't change the 3D image, other than color. Also is there a way to add the axes labels to the 3D image? Thanks!

13 Jun 2014 Ioannis Filippidis

Material opacity is supported by IDTF. You can try experimenting with changing the alpha value from 1.0 to less than 1.0, i.e., undoing this change:

https://github.com/johnyf/fig2u3d/commit/475d277406fdb9bb582d2fd800a5118f76519988#diff-c0c3531ea910fcde4b5e4439d9cbc028L126

in this file:

https://github.com/johnyf/fig2u3d/blob/475d277406fdb9bb582d2fd800a5118f76519988/fig2idtf/output/shaders_materials_modifiers.m

12 Jun 2014 Horst

Is there a way to export semi-transparent plots? It seems to always come out opaque but maybe I'm doing something wrong. Thanks a lot.

21 Mar 2014 Diogo

I would like to keep the shading as 'faceted' in the 3d pdf file, but the result looks like the 'interp' shading. How can I have 'faceted' shading in the 3d pdf?
How would I use this to plot oil wells or mining drill holes in 3d pdfs?

30 Dec 2013 Alexandre

@ Ionnis: It works!!! Thanks again for your work!
Alex

21 Dec 2013 Ioannis Filippidis

@Alexandre: If the desired effect is removing the points which have NaN color, then using NaN for those x,y,z coordinates (not the color) should work.

20 Dec 2013 Alexandre

Dear Ionnis,
Thank you for this very useful tool!!! Now I can export my matlab figures in a 3D pdf format!! wonderful! However I just have one question: I creat a surf figure using 4 matrix X,Y,Z and Cdata. In my cdata matrix I have some NaN in order to have no color at some specific area. On matlab the figure is ok but when I export into pdf3D areas where I have NaN become darkblue instead of no color!! Any idea to fix it?
Anyway thank you very much again for your work
Alex

18 Dec 2013 Ioannis Filippidis

No, there is no export for text annotations. One reason is that if I recollect correctly, U3D does not support text representation, so it would have to be exported as lines or surfaces (not very elegant and a lot of "manual" work on top of U3D). I think that text is supported much better by the PRC format (http://en.wikipedia.org/wiki/PRC_%28file_format%29) which is used for example by Asymptote (http://asymptote.sourceforge.net/)

18 Dec 2013 Jason

Is there by chance a way to export text annotations on the 3d plot to explain what parts of the plot?

27 Jun 2013 Francesco

Hi Loannis,

This is a great tool and I've gotten it to work on my computer for the example files you provided. Unfortunately, it doesn't seem to work when I apply it to a figure produced by the "vol3d.m" function (by Joe Conti), which produces a volume rendering of 3-D data using the matlab "surface" function. I get a lot of outputs in the command line that say "Empty cdata". I don't get an error with fig2u3d.m but when I convert the u3d result to 3d pdf with acrobat, I get an empty white box. If I use fig2pdf3d.m I get the following error "Undefined function or variable "use_vertex_color". Error in shaders_materials_modifiers (line 49)". Do you know what could be wrong?

22 Jun 2013 Ben

Hi Ioannis,
I have emailed you my revision. Wish it is helpful.

21 Jun 2013 Ioannis Filippidis

Hi Ben,

Thanks for the note, there is an OS X fix I've posted below (04 Dec 2012), but there is something else, please send me the fix. I planned to update the files here when time permitted.

20 Jun 2013 Ben

Very good though some modifications are needed in idtf2u3d.m for Mac OS X. If you like, I could send my modified and tested version to you.

24 May 2013 Ioannis Filippidis

Hi Devin,

Including the colorbar is not an implemented feature. The axes are included by plotting them in fig2u3d.m with the function plot_axes.

A suggestion would be to plot the colorbar within the axes (not as it is created by default, i.e., as a separate graphics object). An example which can be adapted according to your needs can be found here:

http://marine.rutgers.edu/~nstrands/MATLAB/googleplot/colorbarlegend.m

It looks like it needs some updating, but besides that it has the main idea of a colorbar comprised of patches. Then you can also select its preferred position and orientation.

Thanks for the idea, I will keep it mind for incorporating it in the next release.

Best,
Ioannis

07 May 2013 Devin Prescott

Hello Ioannis,

This is an excellent and very helpful set of tools. I would like to include my colorbar in the 3D PDFs created with Latex, but have failed in my (limited) attempts. Any suggestions or is this already an option I'm missing? I tried the including the axes in the U3D files but it doesn't seem to pick up the colorbar.

Regards,
Devin

23 Jan 2013 Ioannis Filippidis

Hi dan,

The issue is probably that the missing function is not in your path. You can add all the directories of the package to your path by using the :pathtool" command. Please try to see if its working with other plots (which have surfaces).

Apart from this, this software does not yet support scattergroups. I tried the scatter3 help example and although I got no errors, the geometry exported to the u3d file was essentially empty.

The reason is that some checks are performed. If you successfully run the script for a scatter3 plot, it will report that it did not find any surfaces, lines, patches, quivergroups or contourgroups.
It turns out that scatter3 produces hggroups and the quivergroup and contourgroup export functions look for hggroups. However, they then filter them to see if they are quivers or contours. Otherwise nothing is exported.

In the future there are plans to extend the supported plot types. For the moment all these tests aim to avoid cryptic errors caused by unsupported (or untested) plots. Probably the existing functionality does support scatter3 (i.e., they are only points, so the interface to the output functions will be relatively simple, compared to e.g. quiver output, which has to care about many details). But the wrapper for scatter3 is not yet part of the code.

18 Jan 2013 dan

Hi Ioannis,
the pdf output of your manual looks really nice.
Unfortunately, it the script always gives me the following error message:
"Undefined function 'u3d_pre_surface' for
input arguments of type 'double'."
I am using scatter3 to generate the matlab figure. Does the script support this?

Thank you for your nice work!
dan

20 Dec 2012 Ioannis Filippidis

Please note that if one is willing to employ another 4 to 5 programs, one of which is a proprietary plug-in costing $99, all of which should be manually handled using the mouse and keyboard, with the obvious issue of having to deal with all the possible incompatibilities and other bugs that may arise as these update and change, then the purpose of writing a compact and clean code for doing the same in code or with one short command at the MATLAB command prompt, with fully open source code (MATLAB excluded) which is free and transparent, is totally defeated.

11 Dec 2012 Martin Trauth

I have just (11 Dec 2012) posted an alternative way to create interactive PDFs without LaTeX:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/321562

04 Dec 2012 Ioannis Filippidis

Hi Mario Garcia and Sheng Yue,

If you are using OSX 10.8+ there may be issues with the environment variables.
Please try this fix in idtf2u3d.m, hope this helps:

%% prepare command
mfiledir = fileparts(mfilename('fullpath') );
curpath = pwd;

% Intel Mac
if ismac
idtf_executable_path = [mfiledir, '/bin/maci/'];
cd(idtf_executable_path)

IDTFcmd = './IDTFConverter';

%temp = [getenv('DYLD_LIBRARY_PATH'), ':"', mfiledir, '/bin/maci/"'];
%setenv('DYLD_LIBRARY_PATH', temp)
%IDTFcmd = ['"', mfiledir, '/bin/maci/', IDTFcmd, '"'];
end

% Linux
if isunix && ~ismac
idtf_executable_path = [mfiledir, '/bin/glx/'];
cd(idtf_executable_path)

IDTFcmd = './IDTFConverter.sh';

%temp = [getenv('LD_LIBRARY_PATH'), ':"', mfiledir, '/bin/glx/"'];
%setenv('LD_LIBRARY_PATH', temp)
%IDTFcmd = ['"', mfiledir, '/bin/glx/', IDTFcmd, '.sh"'];
end

% windows
if ispc
win_mfiledir = strrep(mfiledir, '\', '\\');
IDTFcmd = ['"', win_mfiledir, '\\bin\\w32\\IDTFConverter.exe"'];
end

%% idtf -> u3d conversion
s = [IDTFcmd, ' -input "%s" -output "%s"'];
idtf2u3dcmd = sprintf(s, idtffile, u3dfile);
disp(idtf2u3dcmd)
[status, result] = system(idtf2u3dcmd);
cd(curpath) % go back

disp(result)
if status ~= 0
error('idtf2u3d:conversion',...
'IDTFConverter executable returned with error.')
end

04 Dec 2012 Mario GarcĂ­a

Hi Sheng Yue,

idtf2u3d does not work correctly on my computer, can you help me?

Error using idtf2u3d (line 97)
IDTFConverter.exe returned with error.

09 Nov 2012 Ioannis Filippidis

Hi Delit,

3D PDF files can have text in 3D.
But this depends on which intermediate file is used to import the 3D information to the PDF. In principle it is possible to insert text in the U3D file, but it is much more difficult than in a PRC file. For the moment this code uses U3D files, because it is based on previous work by others, which developed the required intermediate tools. It is possible to create an exporter to PRC, but one would have to look at the code already used for this purpose in Asymptote for example, and convert it to MATLAB, which I would like to try, but is not planned for the near future.

09 Nov 2012 Delit

Is it possible to insert scatter and text in the 3D pdf interactive?

05 Oct 2012 Sheng Yue

need to change idtf2u3d.m to make it work on my computer.
Still a nice work!

30 Jul 2012 Joachim  
29 Jul 2012 Joachim  
27 Jul 2012 Sven Koerner  
Updates
19 Sep 2013

development on github, bugfixes (including Mac paths)

22 Aug 2014

link directly to github using matlabcentral itself

Contact us