Skip to content

Commit 4a4c03f

Browse files
committed
add return value testing in all system calls, polish i2m
1 parent b1feced commit 4a4c03f

7 files changed

+82
-17
lines changed

cgals2m.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868
cmd=sprintf('"%s%s" "%s" "%s" %.16f %.16f %.16f %.16f %.16f %d',mcpath('cgalpoly'),exesuff,...
6969
mwpath('pre_cgalpoly.off'),mwpath('post_cgalpoly.mesh'),ang,ssize,...
7070
approx,reratio,maxvol,randseed);
71-
system(cmd);
71+
status=system(cmd);
72+
if(status)
73+
error('cgalpoly command failed');
74+
end
7275
if(~exist(mwpath('post_cgalpoly.mesh'),'file'))
7376
error(sprintf('output file was not found, failure was encountered when running command: \n%s\n',cmd));
7477
end

img2mesh.fig

13 Bytes
Binary file not shown.

img2mesh.m

+48-8
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ function i2m_OpeningFcn(hObject, eventdata, handles, varargin)
4848

4949
cm = uicontextmenu;
5050
uimenu(cm,'Label','Plot','CallBack',{@processdata,handles});
51-
uimenu(cm,'Label','Refresh all','CallBack',{@miRefresh_Callback,handles});
51+
uimenu(cm,'Label','Rename','CallBack',{@processdata,handles});
5252
uimenu(cm,'Label','Delete','CallBack',{@processdata,handles});
53-
uimenu(cm,'Label','Export to JMesh','CallBack',{@processdata,handles});
5453

5554
mimeshing = uimenu(cm,'Label','Meshing');
5655
miv2s = uimenu(mimeshing,'Label','Volume to surface','CallBack',{@processdata,handles});
@@ -83,8 +82,12 @@ function i2m_OpeningFcn(hObject, eventdata, handles, varargin)
8382
uimenu(mireport,'Label','Element volume histogram','CallBack',{@processdata,handles});
8483
uimenu(mireport,'Label','Total volume','CallBack',{@processdata,handles});
8584

85+
mirefresh=uimenu(cm,'Label','Refresh','CallBack',{@miRefresh_Callback,handles});
86+
uimenu(cm,'Label','Save as','CallBack',{@processdata,handles});
87+
8688
miv2s.Separator='on';
8789
mimeshing.Separator='on';
90+
mirefresh.Separator='on';
8891

8992
root=get(handles.fgI2M,'userdata');
9093

@@ -133,17 +136,21 @@ function processdata(source,callbackdata,handles)
133136
[newdata,newtype]=v2sgui(nodedata);
134137
prefix='Vol2Surf';
135138
else
136-
warndlg('no volume data found');
139+
error('no volume data found');
137140
end
138141
case 'Volume to mesh'
139142
if(nodetype.hasvol)
140143
[newdata,newtype]=v2mgui(nodedata);
141144
prefix='Vol2Mesh';
145+
else
146+
error('no volume data found');
142147
end
143148
case 'Surface to mesh'
144149
if(nodetype.hasnode && nodetype.hasface)
145150
[newdata,newtype]=s2mgui(nodedata);
146151
prefix='Surf2Mesh';
152+
else
153+
error('no surface data found');
147154
end
148155
case 'Surface to volume'
149156
if(nodetype.hasnode && nodetype.hasface)
@@ -155,13 +162,17 @@ function processdata(source,callbackdata,handles)
155162
newdata.vol=s2v(nodedata.node,nodedata.face,str2num(ndiv{1}));
156163
newtype.hasvol=1;
157164
prefix='Surf2Vol';
165+
else
166+
error('no surface data found');
158167
end
159168
case 'Close and fill volume'
160169
if(nodetype.hasvol)
161170
rad=inputdlg('maximum gap length in voxel (scalar)','Close and fill a volume',1,{'1'});
162171
newdata.vol=fillholes3d(nodedata.vol,str2num(rad{1}));
163172
newtype=nodetype;
164173
prefix='FillVol';
174+
else
175+
error('no volume data found');
165176
end
166177
case 'Extract surface'
167178
if(isstruct(nodetype) && isfield(nodetype,'hasvol') && nodetype.hasvol)
@@ -183,12 +194,16 @@ function processdata(source,callbackdata,handles)
183194
[newdata.node,newdata.face]=meshcheckrepair(nodedata.node,nodedata.face,'deep');
184195
newtype=nodetype;
185196
prefix='CleanSurf';
197+
else
198+
error('no surface data found');
186199
end
187200
case 'Repair surface'
188201
if(nodetype.hasnode && nodetype.hasface)
189202
[newdata.node,newdata.face]=meshcheckrepair(nodedata.node,nodedata.face,'meshfix');
190203
newtype=nodetype;
191204
prefix='RepairSurf';
205+
else
206+
error('no surface data found');
192207
end
193208
case 'Smooth surface'
194209
if(nodetype.hasnode && nodetype.hasface)
@@ -201,6 +216,8 @@ function processdata(source,callbackdata,handles)
201216
newtype=nodetype;
202217
newdata.node=sms(nodedata.node,nodedata.face,str2num(res{2}),str2num(res{3}),res{1});
203218
prefix='SmoothSurf';
219+
else
220+
error('no surface data found');
204221
end
205222
case 'Simplify surface'
206223
if(nodetype.hasnode && nodetype.hasface)
@@ -212,6 +229,8 @@ function processdata(source,callbackdata,handles)
212229
[newdata.node,newdata.face]=meshresample(nodedata.node,nodedata.face,str2num(res{1}));
213230
newtype=nodetype;
214231
prefix='SimplifySurf';
232+
else
233+
error('no surface data found');
215234
end
216235
case 'Remesh surface'
217236
if(nodetype.hasnode && nodetype.hasface)
@@ -227,6 +246,8 @@ function processdata(source,callbackdata,handles)
227246
newtype.hasnode=1;
228247
newtype.hasface=1;
229248
prefix='RemeshSurf';
249+
else
250+
error('no surface data found');
230251
end
231252
case 'Tessellate surface'
232253
if(nodetype.hasnode && nodetype.hasface)
@@ -235,6 +256,8 @@ function processdata(source,callbackdata,handles)
235256
newtype=nodetype;
236257
newtype.haselem=1;
237258
prefix='TessMesh';
259+
else
260+
error('no surface data found');
238261
end
239262
case 'Reorient mesh elements'
240263
if(nodetype.hasnode && nodetype.haselem)
@@ -245,6 +268,8 @@ function processdata(source,callbackdata,handles)
245268
[newdata.node,newdata.face]=surfreorient(nodedata.node,nodedata.face);
246269
newtype=nodetype;
247270
prefix='ReorientSurf';
271+
else
272+
error('no surface or tetrahedral mesh data found');
248273
end
249274
case 'Mesh quality histogram'
250275
if(nodetype.hasnode && nodetype.haselem)
@@ -296,14 +321,16 @@ function processdata(source,callbackdata,handles)
296321
msgbox(msg,'Mesh data report');
297322
return;
298323
case 'Plot'
299-
if(isstruct(nodetype) && isfield(nodetype,'hasnode'))
324+
if(isstruct(nodetype) && isfield(nodetype,'hasnode') && nodetype.hasnode)
300325
if(isfield(nodetype,'haselem') && nodetype.haselem)
301326
figure;plotmesh(nodedata.node,[],nodedata.elem);
302327
else
303328
figure;plotmesh(nodedata.node,nodedata.face);
304329
end
305330
else
306-
hs=slice(double(nodedata.vol),[],[ceil(size(nodedata.vol,2)*0.5)],ceil(size(nodedata.vol,3)*0.5),'parent',ax);
331+
figure;
332+
hs=slice(double(nodedata.vol),[],[ceil(size(nodedata.vol,2)*0.5)],ceil(size(nodedata.vol,3)*0.5));
333+
set(hs,'linestyle','none');
307334
end
308335
case {'Or','And','Diff','All','First','Second'}
309336
if(isstruct(nodetype) && isfield(nodetype,'hasnode'))
@@ -339,7 +366,18 @@ function processdata(source,callbackdata,handles)
339366
end
340367
root.graph=rmnode(root.graph,root.graph.Nodes.Name{nodeid});
341368
updategraph(root,handles);
342-
case 'Export to JMesh'
369+
case 'Rename'
370+
newname = inputdlg('Define a new name:',...
371+
'Rename',1,{root.graph.Nodes.Name{nodeid}});
372+
if(isempty(newname))
373+
return;
374+
end
375+
if(isempty(newname{1}) || ~isempty(cell2mat(regexp( root.graph.Nodes.Name, ['^' newname{1} '$']))))
376+
error('empty or duplicated node name');
377+
end
378+
root.graph.Nodes.Name{nodeid}=newname{1};
379+
updategraph(root,handles);
380+
case 'Save as'
343381
if(~nodetype.haselem && ~nodetype.hasnode)
344382
error('selected data does not have a mesh');
345383
return;
@@ -368,8 +406,10 @@ function processdata(source,callbackdata,handles)
368406
end
369407

370408
catch ME
371-
msg=sprintf('Error: \n%s\n\nFile: %s\nFunction: %s\nLine: %d',...
372-
ME.message,ME.stack.file,ME.stack.name,ME.stack.line);
409+
msg=sprintf('Error: \n%s\n',ME.message);
410+
for e=1:length(ME.stack)
411+
msg=sprintf('%s\nFile: %s\nFunction: %s\nLine: %d\n\n',msg,ME.stack(e).file,ME.stack(e).name,ME.stack(e).line);
412+
end
373413
uiwait(warndlg(msg,'I2M ERROR'));
374414
updategraph(root,handles);
375415
end

meshcheckrepair.m

+8-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@
5959
exesuff=fallbackexeext(exesuff,'jmeshlib');
6060
deletemeshfile(mwpath('post_sclean.off'));
6161
saveoff(node(:,1:3),elem(:,1:3),mwpath('pre_sclean.off'));
62-
system([' "' mcpath('jmeshlib') exesuff '" "' mwpath('pre_sclean.off') '" "' mwpath('post_sclean.off') '"']);
62+
status=system([' "' mcpath('jmeshlib') exesuff '" "' mwpath('pre_sclean.off') '" "' mwpath('post_sclean.off') '"']);
63+
if(status)
64+
error('jmeshlib command failed');
65+
end
6366
[node,elem]=readoff(mwpath('post_sclean.off'));
6467
end
6568

@@ -73,8 +76,11 @@
7376
deletemeshfile(mwpath('pre_sclean.off'));
7477
deletemeshfile(mwpath('pre_sclean_fixed.off'));
7578
saveoff(node,elem,mwpath('pre_sclean.off'));
76-
system([' "' mcpath('meshfix') exesuff '" "' mwpath('pre_sclean.off') ...
79+
status=system([' "' mcpath('meshfix') exesuff '" "' mwpath('pre_sclean.off') ...
7780
'" ' moreopt]);
81+
if(status)
82+
error('meshfix command failed');
83+
end
7884
[node,elem]=readoff(mwpath('pre_sclean_fixed.off'));
7985
end
8086

meshrefine.m

+12-3
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,24 @@
185185
end
186186

187187
if(size(elem,2)==3 && setquality==0)
188-
system([' "' mcpath('gtsrefine') exesuff '" ' moreopt ' < "' ...
188+
status=system([' "' mcpath('gtsrefine') exesuff '" ' moreopt ' < "' ...
189189
mwpath('pre_refine.gts') '" > "' mwpath('post_refine.gts') '"']);
190+
if(status)
191+
error('gtsrefine command failed');
192+
end
190193
[newnode,newelem]=readgts(mwpath('post_refine.gts'));
191194
newface=newelem;
192195
elseif(size(elem,2)==3)
193-
system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -p -A "' mwpath('pre_refine.poly') '"']);
196+
status=system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -p -A "' mwpath('pre_refine.poly') '"']);
197+
if(status)
198+
error('tetgen command failed');
199+
end
194200
[newnode,newelem,newface]=readtetgen(mwpath('pre_refine.1'));
195201
elseif(~isempty(moreopt))
196-
system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -r "' mwpath('pre_refine.1') '"']);
202+
status=system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -r "' mwpath('pre_refine.1') '"']);
203+
if(status)
204+
error('tetgen command failed');
205+
end
197206
[newnode,newelem,newface]=readtetgen(mwpath('pre_refine.2'));
198207
else
199208
newnode=node;

meshresample.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343

4444
saveoff(v,f,mwpath('pre_remesh.off'));
4545
deletemeshfile(mwpath('post_remesh.off'));
46-
system([' "' mcpath('cgalsimp2') exesuff '" "' mwpath('pre_remesh.off') '" ' num2str(keepratio) ' "' mwpath('post_remesh.off') '"']);
46+
[status, cmdout]=system([' "' mcpath('cgalsimp2') exesuff '" "' mwpath('pre_remesh.off') '" ' num2str(keepratio) ' "' mwpath('post_remesh.off') '"']);
47+
if(status~=0)
48+
error(sprintf('cgalsimp2 command failed'));
49+
end
4750
[node,elem]=readoff(mwpath('post_remesh.off'));
4851
end

surf2mesh.m

+6-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@
105105
end
106106
end
107107
if(isempty(cmdopt))
108-
system([' "' mcpath(method,exesuff) '" -A -q1.414a' num2str(maxvol) ' ' moreopt ' "' mwpath('post_vmesh.poly') '"']);
108+
[status, cmdout]=system([' "' mcpath(method,exesuff) '" -A -q1.414a' num2str(maxvol) ' ' moreopt ' "' mwpath('post_vmesh.poly') '"']);
109109
else
110-
system([' "' mcpath(method,exesuff) '" ' cmdopt ' "' mwpath('post_vmesh.poly') '"']);
110+
[status, cmdout]=system([' "' mcpath(method,exesuff) '" ' cmdopt ' "' mwpath('post_vmesh.poly') '"']);
111+
end
112+
113+
if(status~=0)
114+
error(sprintf('Tetgen command failed'));
111115
end
112116

113117
% read in the generated mesh

0 commit comments

Comments
 (0)