
A screenshot from Acrobat Reader. The example file is here.
Would it not be helpful to be able to navigate through tri-dimensional, surface-based representations of the brain when reading a paper, without having to download separate datasets, or using external software? Since 2004, with the release of the version 1.6 of the Portable Document Format (PDF), this has been possible. However, the means to generate the file were not easily available until about 2008, when Intel released of a set of libraries and tools. This still did not help much to improve popularity, as in-document rendering of complex 3D models requires a lot of memory and processing, making its use difficult in practice at the time. The fact that Acrobat Reader was a lot bloated did not help much either.
Now, almost eight years later, things have become easier for users who want to open these documents. Newer versions of Acrobat are much lighter, and capabilities of ordinary computers have increased. Yet, it seems the interest on this kind of visualisation have faded. The objective of this post is to show that it is remarkably simple to have interactive 3D objects in PDF documents, which can be used in any document published online, including theses, presentations, and papers: journals as PNAS and Journal of Neuroscience are at the forefront in accepting interactive manuscripts.
Requirements
- U3D Tools: Make sure you have the IDTFConverter utility, from the U3D tools, available on SourceForge as part of the MathGL library. A direct link to version 1.4.4 is here; an alternative link, of a repackaged version of the same, is here. Compiling instructions for Linux and Mac are in the “readme” file. There are some dependencies that must be satisfied, and are described in the documentation. If you decide not to install the U3D tools, but only compile them, make sure the path of the executable is both in the
$PATH
and in the$LD_LIBRARY_PATH
. This can be done with:
cd /path/to/the/directory/of/IDTFConverter export PATH=${PATH}:$(pwd) export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)
- The ply2idtf function: Make sure you have the latest version of the areal package, which contains the MATLAB/Octave function ply2idtf.m used below.
- Certain LaTeX packages: The packages movie15 or media9, that allow embedding the 3D object into the PDF using LaTeX. Either will work. Below it is assumed the older, movie15 package, is used.
Step 1: Generate the PLY maps
Once you have a map of vertexwise cortical data that needs to be shown, follow the instructions from this earlier blog post that explains how to generate Stanford PLY files to display colour-coded vertexwise data. These PLY files will be used below.
Step 2: Convert the PLY to IDTF files
IDTF stands for Intermediate Data Text Format. As the name implies, it is a text, intermediate file, used as a step before the creation of the U3D files, the latter that are embedded into the PDF. Use the function ply2idtf for this:
ply2idtf(... {'lh.pial.thickness.avg.ply','LEFT', eye(4);... 'rh.pial.thickness.avg.ply','RIGHT',eye(4)},... 'thickness.idtf');
The first argument is a cell array with 3 columns, and as many rows as PLY files being added to the IDTF file. The first column contains the file name, the second the label (or node) that for that file, and the third an affine matrix that maps the coordinates from the PLY file to the world coordinate system of the (to be created) U3D. The second (last) argument to the command is the name of the output file.
Step 3: Convert the IDTF to U3D files
From a terminal window (not MATLAB or Octave), run:
IDTFConverter -input thickness.idtf -output thickness.u3d
Step 4: Configure default views
Here we use the older movie15 LaTeX package, and the same can be accomplished with the newer, media9 package. Various viewing options are configurable, all of which are described in the documentation. These options can be saved in a text file with extension .vws
, and later supplied in the LaTeX document. An example is below.
VIEW=Both Hemispheres COO=0 -14 0, C2C=-0.75 0.20 0.65 ROO=325 AAC=30 ROLL=-0.03 BGCOLOR=.5 .5 .5 RENDERMODE=Solid LIGHTS=CAD PART=LEFT VISIBLE=true END PART=RIGHT VISIBLE=true END END VIEW=Left Hemisphere COO=0 -14 0, C2C=-1 0 0 ROO=325 AAC=30 ROLL=-0.03 BGCOLOR=.5 .5 .5 RENDERMODE=Solid LIGHTS=CAD PART=LEFT VISIBLE=true END PART=RIGHT VISIBLE=false END END VIEW=Right Hemisphere COO=0 -14 0, C2C=1 0 0 ROO=325 AAC=30 ROLL=0.03 BGCOLOR=.5 .5 .5 RENDERMODE=Solid LIGHTS=CAD PART=LEFT VISIBLE=false END PART=RIGHT VISIBLE=true END END
Step 5: Add the U3D to the LaTeX source
Interactive, 3D viewing is unfortunately not supported by most PDF readers. However, it is supported by the official Adobe Acrobat Reader since version 7.0, including the recent version DC. Thus, it is important to let the users/readers of the document know that they must open the file using a recent version of Acrobat. This can be done in the document itself, using a message placed with the option text
of the \includemovie
command of the movie15 package. A minimalistic LaTeX source is shown below (it can be downloaded here).
\documentclass{article} % Relevant package: \usepackage[3D]{movie15} % pdfLaTeX and color links setup: \usepackage{color} \usepackage[pdftex]{hyperref} \definecolor{colorlink}{rgb}{0, 0, .6} % dark blue \hypersetup{colorlinks=true,citecolor=colorlink,filecolor=colorlink,linkcolor=colorlink,urlcolor=colorlink} \begin{document} \title{Interactive 3D brains in PDF documents} \author{} \date{} \maketitle \begin{figure}[!h] \begin{center} \includemovie[ text=\fbox{\parbox[c][9cm][c]{9cm}{\centering {\footnotesize (Use \href{http://get.adobe.com/reader/}{Adobe Acrobat Reader 7.0+} \\to view the interactive content.)}}}, poster,label=Average,3Dviews2=pial.vws]{10cm}{10cm}{thickness.u3d} \caption{An average 3D brain, showing colour-coded average thickness (for simplicity, colour scale not shown). Click to rotate. Right-click to for a menu with various options. Details at \href{http://brainder.org}{http://brainder.org}.} \end{center} \end{figure} \end{document}
Step 6: Generate the PDF
For LaTeX, use pdfLaTeX as usual:
pdflatex document.tex
What you get
After generating the PDF, the result of this example is shown here (a screenshot is at the top). It is possible to rotate in any direction, zoom, pan, change views to predefined modes, and alternate between orthogonal and perspective projections. It’s also possible to change rendering modes (including transparency), and experiment with various lightning options.
In Acrobat Reader, by right-clicking, a menu with various useful options is presented. A toolbar (as shown in the top image) can also be enabled through the menu.
The same strategy works also with the Beamer class, such that interactive slides can be created and used in talks, and with XeTeX, allowing these with a richer variety of text fonts.
See also
- Wikipedia has an article on U3D files.
- Alexandre Gramfort has developed a set of tools that covers quite much the same as above. It’s freely available in Matlab FileExchange.
- To display molecules interactively (including proteins), the steps are similar. Instructions for Jmol and Pymol are available.
- Commercial products offering features that build on these resources are also available.
Pingback: Downsampling (decimating) a brain surface | Brainder.
Pingback: Displaying vertexwise and facewise brain maps | Brainder.
Hello Brainder, I am trying to replicate your example with my own figure but am running into trouble on the ply -> idtf step. When I run ply2idtf({‘figure.ply’, ‘FIG’, eye(4)}, ‘fig.idtf’) in the octave prompt, I get a number of warnings related to short circuit operations and then this error: structure has no member ‘vertex_index’. I am fairly new to meshes but I am using an ascii ply file produced in meshlab so I would imagine it is well formed. Any ideas on what might be going wrong? I appreciate your help.
Hi Brandon,
The PLY file has to have a very simple internal structure. I’m not sure MeshLab doesn’t add more elements inside it that, while PLY-valid, aren’t supported by the other functions down the line. Try to use a PLY in ASCII format and check that it doesn’t contain anything not strictly necessary. Also, please check out this article, that describes a basic internal structure for the PLY format: https://brainder.org/2011/09/25/braindering-with-ascii-files/
All the best, and Merry Christmas!
Anderson