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
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.

[strmodelshading, strfaces_colors, strfaceshading, strcolors,...
function [strmodelshading, strfaces_colors, strfaceshading, strcolors,...
          nface_vertex_data_unique] = mesh_diffuse_colors(faces, points, face_vertex_data)
% File:      mesh_diffuse_colors.m
% Author:    Ioannis Filippidis, jfilippidis@gmail.com
% Date:      2012.06.10- 2012.06.24
% Language:  MATLAB R2012a
% Purpose:   prepare colors and shading for exporting mesh to IDTF
% Copyright: Ioannis Filippidis, 2012-
%
% acknowledgment
%   Based on save_idtf by Alexandre Gramfort.
%   This can be found on the MATLAB Central File Exchange:
%       http://www.mathworks.com/matlabcentral/fileexchange/25383-matlab-mesh-to-pdf-with-3d-interactive-object
%   and is covered by the BSD License.

% depends
%   verbatim

%% no colors
if isempty(face_vertex_data)
    strmodelshading = sprintf(shading_description_str, [0, 0].');
    strfaces_colors = '';
    strfaceshading = sprintf(mesh_face_shading_list, '0');
    strcolors = '';
    nface_vertex_data_unique = 0;
    return
end

%% colors
nfaces = size(faces, 1);
npoints = size(points, 1);
nfvd = size(face_vertex_data, 1);

[face_vertex_data_unique, ~, face_vertex_data_idx] = ...
                                unique(face_vertex_data, 'rows');
nface_vertex_data_unique = size(face_vertex_data_unique, 1);
msg = ['Number of colors: ', num2str(nface_vertex_data_unique) ];
disp(msg);

% Colors correspond to points or faces ?
if nfvd == npoints
    strmodelshading = sprintf(shading_description_str, [0, 0].');
    
    strfaces_colors = sprintf('                %d %d %d\n', face_vertex_data_idx(faces).'-1);
    strfaces_colors = sprintf(mesh_face_diffuse_color_list, strfaces_colors);
    
    strfaceshading = sprintf('                    %d\n', zeros(nfaces, 1) );
    strfaceshading = sprintf(mesh_face_shading_list, strfaceshading);
    
    strcolors = sprintf('                %f %f %f\n', face_vertex_data_unique.');
    strcolors = sprintf(model_diffuse_color_list, strcolors);
elseif nfvd == nfaces
    shidx = (0:(nface_vertex_data_unique -1) ).';
    strmodelshading = sprintf(shading_description_str, [shidx, shidx].');
    
    strfaces_colors = '';
    
    strfaceshading = sprintf('                %d\n', face_vertex_data_idx -1);
    strfaceshading = sprintf(mesh_face_shading_list, strfaceshading);
    
    strcolors = '';
else
    error('#facevetrexdata ~= #faces, #points, 0')
end

function [str] = mesh_face_shading_list
str = verbatim;
%{
                MESH_FACE_SHADING_LIST {
                    %s
                }
%}

function [str] = mesh_face_diffuse_color_list
str = verbatim;
%{
                MESH_FACE_DIFFUSE_COLOR_LIST {
                    %s
                }
%}

function [str] = model_diffuse_color_list
str = verbatim;
%{
                MODEL_DIFFUSE_COLOR_LIST {
                    %s
                }
%}

function [str] = shading_description_str
str = verbatim;
%{
                    SHADING_DESCRIPTION %d {
                         TEXTURE_LAYER_COUNT 0
                         SHADER_ID %d
                    }
%}

Contact us