📄 srf_saveasjvx.m
字号:
function hfile = srf_SaveAsJVX(hfile, jvxfile)
% SRF::SaveAsJVX - save SRF to a JavaView JVX file
%
% FORMAT: srf.SaveAsJVX(jvxfile);
%
% Input fields:
%
% jvxfile filename of JVX file to write
%
% No output fields.
% Version: v0.7b
% Build: 7090215
% Date: Sep-02 2007, 3:38 PM CEST
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% check input arguments
if nargin < 2 || ...
numel(hfile) ~= 1 || ...
~isBVQXfile(hfile, 'srf') || ...
~ischar(jvxfile) || ...
isempty(jvxfile)
error( ...
'BVQXfile:BadArgument', ...
'Invalid call to %s.', ...
mfilename ...
);
end
sc = bvqxfile_getscont(hfile.L);
bc = sc.C;
jvxfile = jvxfile(:)';
% try to open output for writing
jf = fopen(jvxfile, 'w');
if jf < 1
error( ...
'BVQXfile:FileNotWritable', ...
'Destination file not writable.' ...
);
end
% print header
fwrite(jf, ['<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>' char(10)]);
fwrite(jf, ['<!DOCTYPE jvx-model SYSTEM "http://www.javaview.de/rsrc/jvx.dtd">' char(10)]);
fwrite(jf, ['<jvx-model>' char([10,9]) '<meta generator="bvsrf2jvx"/>' char([10,9])]);
fwrite(jf, ['<title>' sc.F '</title>' char([10,9]) '<geometries>' char([10,9,9])]);
fwrite(jf, ['<geometry name="' sc.F '">' char(10)]);
% write points/normals
numvert = bc.NrOfVertices;
fwrite(jf, sprintf('\t\t\t<pointSet point="hide" color="hide" dim=3>\n'));
fwrite(jf, sprintf('<points num=%d>\n', numvert));
fprintf(jf, '\t<p>%8.5f %8.5f %8.5f</p>\n', ...
bc.VertexCoordinate' - ...
bc.MeshCenter' * ones(1, numvert));
fwrite(jf, sprintf('</points>\n'));
fwrite(jf, sprintf('<colors num=%d>\n', numvert));
oc0 = fix(255 * bc.ConvexRGBA(1:3));
oc1 = fix(255 * bc.ConcaveRGBA(1:3));
vcol = bc.VertexColor;
col1 = find(~isnan(vcol(:, 1)) & vcol(:, 1) == 0);
col2 = find(~isnan(vcol(:, 1)) & vcol(:, 1) == 1);
vcol(col1, 2:4) = ones(numel(col1), 1) * oc0;
vcol(col2, 2:4) = ones(numel(col2), 1) * oc1;
vcol(vcol < 0) = 0;
vcol(vcol > 255) = 255;
vcol = vcol(:, 2:4);
fprintf(jf, '\t<c>%d %d %d</c>\n', vcol');
fwrite(jf, sprintf('</colors>\n'));
clear vcol;
sn = bc.VertexNormal;
fwrite(jf, sprintf('<normals num=%d>\n', numvert));
fprintf(jf,'\t<p>%9.6f %9.6f %9.6f</p>\n', sn');
fwrite(jf, sprintf('\t<length>1</length>\n'));
fwrite(jf, sprintf('</normals>\n'));
clear sn;
fwrite(jf, sprintf('\t\t\t</pointSet>\n'));
% write faces
fwrite(jf, sprintf('\t\t\t<faceSet color="show" colorFromPoints="show" edge="hide" face="show" colorSmooth="show">\n'));
sf = bc.TriangleVertex - 1;
fwrite(jf, sprintf('<faces num=%d>\n', size(sf, 1)));
fprintf(jf, '\t<f>%d %d %d</f>\n', sf');
fwrite(jf, sprintf('</faces>\n'));
clear sf;
fwrite(jf, sprintf('\t\t\t</faceSet>\n'));
% write footer
fwrite(jf, [char([9,9]) '</geometry>' char([10,9])]);
fwrite(jf, ['</geometries>' char(10) '</jvx-model>' char(10)]);
% close file
fclose(jf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -