forked from dengwirda/jigsaw-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marche.m
127 lines (106 loc) · 3.24 KB
/
marche.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function [varargout] = marche(opts)
%MARCHE an interface to JIGSAW's "gradient-limiting" solver.
%
% HFUN = MARCHE(OPTS);
%
% Call the "fast-marching" solver MARCHE using the config.
% options specified in the OPTS structure. MARCHE solves
% the Eikonal equations
%
% MAX(|dh/dx|, g) = g,
%
% where g = g(x) is a gradient threshold applied to h. See
% the SAVEMSH/LOADMSH functions for a description of the
% HFUN output structure.
%
% OPTS is a user-defined set of meshing options:
%
% REQUIRED fields:
% ---------------
%
% OPTS.HFUN_FILE - 'HFUNNAME.MSH', a string containing the
% name of the file defining h(x). Data is overwritten
% *in-place*. See SAVEMSH for additional details regar-
% ding the creation of *.MSH files.
%
% OPTS.JCFG_FILE - 'JCFGNAME.JIG', a string containing the
% name of the cofig. file (will be created on output).
%
% OPTIONAL fields (MISC):
% ----------------------
%
% OPTS.VERBOSITY - {default=0} verbosity of log-file gene-
% rated by JIGSAW. Set VERBOSITY >= 1 for more output.
%
% See also LOADMSH, SAVEMSH
%
%-----------------------------------------------------------
% Darren Engwirda
% github.com/dengwirda/jigsaw-matlab
% 18-Apr-2021
% d.engwirda@gmail.com
%-----------------------------------------------------------
%
jexename = '' ; status = -1 ;
if ( isempty(opts))
error('MARCHE: insufficient inputs!!') ;
end
if (~isempty(opts) && ~isstruct(opts))
error('MARCHE: invalid input types!!') ;
end
savejig(opts.jcfg_file,opts);
%---------------------------- set-up path for "local" binary
if (strcmp(jexename,''))
filename = ...
mfilename('fullpath') ;
filepath = ...
fileparts( filename ) ;
if (ispc())
jexename = [filepath, ...
'\external\jigsaw\bin\marche.exe'];
elseif (ismac ())
jexename = [filepath, ...
'/external/jigsaw/bin/marche'];
elseif (isunix())
jexename = [filepath, ...
'/external/jigsaw/bin/marche'];
end
end
if (exist(jexename,'file')~=2), jexename=''; end
%---------------------------- search machine path for binary
if (strcmp(jexename,''))
if (ispc())
jexename = 'marche.exe' ;
elseif (ismac ())
jexename = 'marche' ;
elseif (isunix())
jexename = 'marche' ;
end
end
if (exist(jexename,'file')~=2), jexename=''; end
%---------------------------- call MARCHE and capture stdout
if (exist(jexename,'file')==2)
[status, result] = system( ...
['"',jexename,'"',' ','"',opts.jcfg_file,'"'], ...
'-echo') ;
%---------------------------- OCTAVE doesn't handle '-echo'!
if (exist('OCTAVE_VERSION', 'builtin') > 0)
fprintf(1, '%s', result) ;
end
else
%---------------------------- couldn't find JIGSAW's backend
error([ ...
'MARCHE''s executable not found -- ', ...
'has JIGSAW been compiled from src?', ...
'See COMPILE for additional detail.', ...
] ) ;
end
if (nargout == +1)
%---------------------------- read mesh if output requested!
if (status == +0)
varargout{1} = loadmsh (opts.hfun_file) ;
else
varargout{1} = [];
end
end
end