File Exchange

image thumbnail

Generate vertices, faces and color for u3d format

version 1.0.0.0 (24.8 KB) by Sven Koerner
Generate vertices, faces and color for u3d format and display it in pdf or doc, xls and ppt

7 Downloads

Updated 14 Apr 2010

View License

This function generates the input for the MESH_TO_LATEX function from Alexandre Gramfort from your surface-graphs. The surface graphs 3d-model can be displayed in u3d - format in pdf or if you don't delete the u3d-files which are generated by MesSH_TO_LATEX you can use deepview from righthemisphere(http://www.righthemisphere.com/products/client-products/deep-view) to embed the modell in Microsoft-Office products (Word, Excel, PowerPoint).

The output is a structure generated by the standard MATLAB function
surf2patch which can used in MESH_TO_LATEX:
fvc.vertices --> points
fvc.faces --> faces
fvc.facevertexcdata --> face_vertex_data

Comments and Ratings (10)

Hi,
First of all thank you for all these instructions.
I managed to run the demo script and generate the brain but when I try to use this script to grab data from my 3D plot it gives me:

%%%%%%%%%%%%%

No surface graph found.
Error using patchnormals (line 40)
The vertice list is not a m x 3 array

Error in mesh_normals (line 30)
normals = patchnormals(FV);

Error in mesh_to_latex (line 30)
normals = mesh_normals(points,faces);

%%%%%%%%%%%%%%%%%%%%%

I believe it could be about my type of data, I used trisurf to plot 5 3D surfaces in one diagram. They were generated with delaunayn

Dear all,
I made the code running for Matlab for surf! Thanks it looks nice in the pdf.
However, I have a question.
I want to take a .fig which is generated with surfs but also with points and lines drawn on R3.
Is this possible with your code? taking an image .fig and create the points,faces, and face_vertex_data?
Best,
Julian

Shibo Zou

Many thanks! Though it took a little bit effort to make it work.

As described in the requirements, mesh_to_latex by Alexandre Gramfort is needed.

https://www.mathworks.com/matlabcentral/fileexchange/25383-matlab-mesh-to-pdf-with-3d-interactive-object

If you go to this webpage for the mesh_to_latex, you will find there are more things to do to make mesh_to_latex work. Thanks to Francis Esmonde-White in the comment who described all the steps to make mesh_to_latex work:

1. Download & unpack the file "mesh2pdf_2.0.zip" for the folder named mesh2pdf. Set the working directory of your MATLAB as this folder so that you can have citation right.

2. Download & install MiKTeX: https://miktex.org/download

3.Open mesh2pdf\demo_mesh2pdf.m in matlab editor and update lines 16-23 to point to the directory where MiKTeK is installed.

For example, mine looks like this:

pdflatex_cmp = ['C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe'];

if isunix
pdflatex_cmp = 'pdflatex';
else
addpath(['C:\Program Files\MiKTeX 2.9\miktex\bin\x64\']);
pdflatex_cmp = 'pdflatex.exe';
end

4.Go to MikTex directory and make all files editable by the current windows user. (Right click MiKTeK 2.8 folder, select permissions -> select current user -> check 'allow' for all Permissions -> hit apply)

5.Update all required packages: run demo_mesh2pdf.m and you will get a notice which asks you to install new packages. Then go to C:\Program Files\MiKTeX 2.9\miktex\bin\x64, find & run mpm.exe. Search the name of the package and right click on it, and install, it should take a few seconds to install. Then run demo_mesh2pdf.m again, install required packages till everything has been installed.

6. With the matlab working directory (current folder) set to the mesh2pdf directory, run the demo_mesh2pdf.m script. It will call the pdflatex command 3 times and generate a pdf file with a 3D model (I think it's a brain). The demo pdf will be in the mesh2pdf_2.0\mesh2pdf\tex directory.

Till now you've made mesh_to_latex work.

7. Then, with the matlab working directory (current folder) set to the mesh2pdf (folder) directory run the following script which needs XYZ data as input, and then utilizes the u3d_pre script to generate input file for mesh_to_latex. In the end, a pdf file named demo_mesh2pdf.pdf will be generated in the mesh2pdf_2.0\mesh2pdf\tex directory. Good luck!

[X,Y,Z] = peaks(30);
surf(X,Y,Z);
shading interp
fvc = u3d_pre;
mesh_to_latex('tex/mesh',fvc.vertices,uint32(fvc.faces),fvc.facevertexcdata);

pdflatex_cmp = ['C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe'];

if isunix
pdflatex_cmp = 'pdflatex';
else
addpath(['C:\Program Files\MiKTeX 2.9\miktex\bin\x64\']);
pdflatex_cmp = 'pdflatex.exe';
end

cd tex
dos([pdflatex_cmp,' -interaction=nonstopmode demo_mesh2pdf.tex']);
dos([pdflatex_cmp,' -interaction=nonstopmode demo_mesh2pdf.tex']); % re-run (required by movie15 package)
dos([pdflatex_cmp,' -interaction=nonstopmode demo_mesh2pdf.tex']); % re-run (required by movie15 package)
cd ../

Sven Koerner

Dear gayane, please send me more information.
Normally there is no codeline 79, so I can't guess what is wrong.

Gayane

Looks as something I have been searching for quite a long time! However, I get Error in ==> u3d_pre at 79
fvc = u3d_pre;
Could you tell me what is the reason?

If you have v7 or v8 of acrobat you can go straight from VRML to RH files and to pdf. I notice that adobe appears to dropped support for 3d authoring for some formats in recent versions of acrobat (v9 and v10). If you have recent versions you will need to use the u3d format. Another option is to convert to u3d using free MeshLab software...

Sven Koerner

adobe acrobat 9, but i guess the probelms depend on the selected render mode

adobe reader 9. You ?

Sven Koerner

Which renderer do you use (3D & multimedia setting in Acrobat)? Try with an other e.g. "software")

Very nice, but there are still bugs because in the proposed pdf, if you rotate the figure, it becomes white from the bottom.

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor