Skip to content

Commit

Permalink
add return value testing in all system calls, polish i2m
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Aug 6, 2018
1 parent b1feced commit 4a4c03f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 17 deletions.
5 changes: 4 additions & 1 deletion cgals2m.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
cmd=sprintf('"%s%s" "%s" "%s" %.16f %.16f %.16f %.16f %.16f %d',mcpath('cgalpoly'),exesuff,...
mwpath('pre_cgalpoly.off'),mwpath('post_cgalpoly.mesh'),ang,ssize,...
approx,reratio,maxvol,randseed);
system(cmd);
status=system(cmd);
if(status)
error('cgalpoly command failed');
end
if(~exist(mwpath('post_cgalpoly.mesh'),'file'))
error(sprintf('output file was not found, failure was encountered when running command: \n%s\n',cmd));
end
Expand Down
Binary file modified img2mesh.fig
Binary file not shown.
56 changes: 48 additions & 8 deletions img2mesh.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ function i2m_OpeningFcn(hObject, eventdata, handles, varargin)

cm = uicontextmenu;
uimenu(cm,'Label','Plot','CallBack',{@processdata,handles});
uimenu(cm,'Label','Refresh all','CallBack',{@miRefresh_Callback,handles});
uimenu(cm,'Label','Rename','CallBack',{@processdata,handles});
uimenu(cm,'Label','Delete','CallBack',{@processdata,handles});
uimenu(cm,'Label','Export to JMesh','CallBack',{@processdata,handles});

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

mirefresh=uimenu(cm,'Label','Refresh','CallBack',{@miRefresh_Callback,handles});
uimenu(cm,'Label','Save as','CallBack',{@processdata,handles});

miv2s.Separator='on';
mimeshing.Separator='on';
mirefresh.Separator='on';

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

Expand Down Expand Up @@ -133,17 +136,21 @@ function processdata(source,callbackdata,handles)
[newdata,newtype]=v2sgui(nodedata);
prefix='Vol2Surf';
else
warndlg('no volume data found');
error('no volume data found');
end
case 'Volume to mesh'
if(nodetype.hasvol)
[newdata,newtype]=v2mgui(nodedata);
prefix='Vol2Mesh';
else
error('no volume data found');
end
case 'Surface to mesh'
if(nodetype.hasnode && nodetype.hasface)
[newdata,newtype]=s2mgui(nodedata);
prefix='Surf2Mesh';
else
error('no surface data found');
end
case 'Surface to volume'
if(nodetype.hasnode && nodetype.hasface)
Expand All @@ -155,13 +162,17 @@ function processdata(source,callbackdata,handles)
newdata.vol=s2v(nodedata.node,nodedata.face,str2num(ndiv{1}));
newtype.hasvol=1;
prefix='Surf2Vol';
else
error('no surface data found');
end
case 'Close and fill volume'
if(nodetype.hasvol)
rad=inputdlg('maximum gap length in voxel (scalar)','Close and fill a volume',1,{'1'});
newdata.vol=fillholes3d(nodedata.vol,str2num(rad{1}));
newtype=nodetype;
prefix='FillVol';
else
error('no volume data found');
end
case 'Extract surface'
if(isstruct(nodetype) && isfield(nodetype,'hasvol') && nodetype.hasvol)
Expand All @@ -183,12 +194,16 @@ function processdata(source,callbackdata,handles)
[newdata.node,newdata.face]=meshcheckrepair(nodedata.node,nodedata.face,'deep');
newtype=nodetype;
prefix='CleanSurf';
else
error('no surface data found');
end
case 'Repair surface'
if(nodetype.hasnode && nodetype.hasface)
[newdata.node,newdata.face]=meshcheckrepair(nodedata.node,nodedata.face,'meshfix');
newtype=nodetype;
prefix='RepairSurf';
else
error('no surface data found');
end
case 'Smooth surface'
if(nodetype.hasnode && nodetype.hasface)
Expand All @@ -201,6 +216,8 @@ function processdata(source,callbackdata,handles)
newtype=nodetype;
newdata.node=sms(nodedata.node,nodedata.face,str2num(res{2}),str2num(res{3}),res{1});
prefix='SmoothSurf';
else
error('no surface data found');
end
case 'Simplify surface'
if(nodetype.hasnode && nodetype.hasface)
Expand All @@ -212,6 +229,8 @@ function processdata(source,callbackdata,handles)
[newdata.node,newdata.face]=meshresample(nodedata.node,nodedata.face,str2num(res{1}));
newtype=nodetype;
prefix='SimplifySurf';
else
error('no surface data found');
end
case 'Remesh surface'
if(nodetype.hasnode && nodetype.hasface)
Expand All @@ -227,6 +246,8 @@ function processdata(source,callbackdata,handles)
newtype.hasnode=1;
newtype.hasface=1;
prefix='RemeshSurf';
else
error('no surface data found');
end
case 'Tessellate surface'
if(nodetype.hasnode && nodetype.hasface)
Expand All @@ -235,6 +256,8 @@ function processdata(source,callbackdata,handles)
newtype=nodetype;
newtype.haselem=1;
prefix='TessMesh';
else
error('no surface data found');
end
case 'Reorient mesh elements'
if(nodetype.hasnode && nodetype.haselem)
Expand All @@ -245,6 +268,8 @@ function processdata(source,callbackdata,handles)
[newdata.node,newdata.face]=surfreorient(nodedata.node,nodedata.face);
newtype=nodetype;
prefix='ReorientSurf';
else
error('no surface or tetrahedral mesh data found');
end
case 'Mesh quality histogram'
if(nodetype.hasnode && nodetype.haselem)
Expand Down Expand Up @@ -296,14 +321,16 @@ function processdata(source,callbackdata,handles)
msgbox(msg,'Mesh data report');
return;
case 'Plot'
if(isstruct(nodetype) && isfield(nodetype,'hasnode'))
if(isstruct(nodetype) && isfield(nodetype,'hasnode') && nodetype.hasnode)
if(isfield(nodetype,'haselem') && nodetype.haselem)
figure;plotmesh(nodedata.node,[],nodedata.elem);
else
figure;plotmesh(nodedata.node,nodedata.face);
end
else
hs=slice(double(nodedata.vol),[],[ceil(size(nodedata.vol,2)*0.5)],ceil(size(nodedata.vol,3)*0.5),'parent',ax);
figure;
hs=slice(double(nodedata.vol),[],[ceil(size(nodedata.vol,2)*0.5)],ceil(size(nodedata.vol,3)*0.5));
set(hs,'linestyle','none');
end
case {'Or','And','Diff','All','First','Second'}
if(isstruct(nodetype) && isfield(nodetype,'hasnode'))
Expand Down Expand Up @@ -339,7 +366,18 @@ function processdata(source,callbackdata,handles)
end
root.graph=rmnode(root.graph,root.graph.Nodes.Name{nodeid});
updategraph(root,handles);
case 'Export to JMesh'
case 'Rename'
newname = inputdlg('Define a new name:',...
'Rename',1,{root.graph.Nodes.Name{nodeid}});
if(isempty(newname))
return;
end
if(isempty(newname{1}) || ~isempty(cell2mat(regexp( root.graph.Nodes.Name, ['^' newname{1} '$']))))
error('empty or duplicated node name');
end
root.graph.Nodes.Name{nodeid}=newname{1};
updategraph(root,handles);
case 'Save as'
if(~nodetype.haselem && ~nodetype.hasnode)
error('selected data does not have a mesh');
return;
Expand Down Expand Up @@ -368,8 +406,10 @@ function processdata(source,callbackdata,handles)
end

catch ME
msg=sprintf('Error: \n%s\n\nFile: %s\nFunction: %s\nLine: %d',...
ME.message,ME.stack.file,ME.stack.name,ME.stack.line);
msg=sprintf('Error: \n%s\n',ME.message);
for e=1:length(ME.stack)
msg=sprintf('%s\nFile: %s\nFunction: %s\nLine: %d\n\n',msg,ME.stack(e).file,ME.stack(e).name,ME.stack(e).line);
end
uiwait(warndlg(msg,'I2M ERROR'));
updategraph(root,handles);
end
Expand Down
10 changes: 8 additions & 2 deletions meshcheckrepair.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@
exesuff=fallbackexeext(exesuff,'jmeshlib');
deletemeshfile(mwpath('post_sclean.off'));
saveoff(node(:,1:3),elem(:,1:3),mwpath('pre_sclean.off'));
system([' "' mcpath('jmeshlib') exesuff '" "' mwpath('pre_sclean.off') '" "' mwpath('post_sclean.off') '"']);
status=system([' "' mcpath('jmeshlib') exesuff '" "' mwpath('pre_sclean.off') '" "' mwpath('post_sclean.off') '"']);
if(status)
error('jmeshlib command failed');
end
[node,elem]=readoff(mwpath('post_sclean.off'));
end

Expand All @@ -73,8 +76,11 @@
deletemeshfile(mwpath('pre_sclean.off'));
deletemeshfile(mwpath('pre_sclean_fixed.off'));
saveoff(node,elem,mwpath('pre_sclean.off'));
system([' "' mcpath('meshfix') exesuff '" "' mwpath('pre_sclean.off') ...
status=system([' "' mcpath('meshfix') exesuff '" "' mwpath('pre_sclean.off') ...
'" ' moreopt]);
if(status)
error('meshfix command failed');
end
[node,elem]=readoff(mwpath('pre_sclean_fixed.off'));
end

Expand Down
15 changes: 12 additions & 3 deletions meshrefine.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,24 @@
end

if(size(elem,2)==3 && setquality==0)
system([' "' mcpath('gtsrefine') exesuff '" ' moreopt ' < "' ...
status=system([' "' mcpath('gtsrefine') exesuff '" ' moreopt ' < "' ...
mwpath('pre_refine.gts') '" > "' mwpath('post_refine.gts') '"']);
if(status)
error('gtsrefine command failed');
end
[newnode,newelem]=readgts(mwpath('post_refine.gts'));
newface=newelem;
elseif(size(elem,2)==3)
system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -p -A "' mwpath('pre_refine.poly') '"']);
status=system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -p -A "' mwpath('pre_refine.poly') '"']);
if(status)
error('tetgen command failed');
end
[newnode,newelem,newface]=readtetgen(mwpath('pre_refine.1'));
elseif(~isempty(moreopt))
system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -r "' mwpath('pre_refine.1') '"']);
status=system([' "' mcpath('tetgen') exesuff '" ' moreopt ' -r "' mwpath('pre_refine.1') '"']);
if(status)
error('tetgen command failed');
end
[newnode,newelem,newface]=readtetgen(mwpath('pre_refine.2'));
else
newnode=node;
Expand Down
5 changes: 4 additions & 1 deletion meshresample.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

saveoff(v,f,mwpath('pre_remesh.off'));
deletemeshfile(mwpath('post_remesh.off'));
system([' "' mcpath('cgalsimp2') exesuff '" "' mwpath('pre_remesh.off') '" ' num2str(keepratio) ' "' mwpath('post_remesh.off') '"']);
[status, cmdout]=system([' "' mcpath('cgalsimp2') exesuff '" "' mwpath('pre_remesh.off') '" ' num2str(keepratio) ' "' mwpath('post_remesh.off') '"']);
if(status~=0)
error(sprintf('cgalsimp2 command failed'));
end
[node,elem]=readoff(mwpath('post_remesh.off'));
end
8 changes: 6 additions & 2 deletions surf2mesh.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@
end
end
if(isempty(cmdopt))
system([' "' mcpath(method,exesuff) '" -A -q1.414a' num2str(maxvol) ' ' moreopt ' "' mwpath('post_vmesh.poly') '"']);
[status, cmdout]=system([' "' mcpath(method,exesuff) '" -A -q1.414a' num2str(maxvol) ' ' moreopt ' "' mwpath('post_vmesh.poly') '"']);
else
system([' "' mcpath(method,exesuff) '" ' cmdopt ' "' mwpath('post_vmesh.poly') '"']);
[status, cmdout]=system([' "' mcpath(method,exesuff) '" ' cmdopt ' "' mwpath('post_vmesh.poly') '"']);
end

if(status~=0)
error(sprintf('Tetgen command failed'));
end

% read in the generated mesh
Expand Down

0 comments on commit 4a4c03f

Please sign in to comment.