hi Luca, the boolean tool (cork) can not process co-planar surfaces (such as two planes that are exactly overlapping, or a sphere exactly touching the bounding box.
although surfboolean may output a mesh, tetgen can't process it. in such case, please expand or contract the shapes so that the domain is free of co-planar surfaces, then run surfboolean again.
Qianqian
Thanks,Luca--
You received this message because you are subscribed to the Google Groups "iso2mesh-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iso2mesh-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/19f43322-6467-4ddc-8e3d-5eb4c27cbed2n%40googlegroups.com.

Dear Dr. fang,
Thanks for the help.I have created the 3-layered lattice using latticegrid: would that create a problem for the coplanarity of the three layers for surfboolean or would the error be generated only by the overlapping of surfaces between one of the layers and the inclusion (as this is the case in my application)?I have attached a figure file of the XZ cross-section of the surface of the mesh I am trying to convert into a volume, for clarity.
please send me a short script so I can reproduce the issue. with just a figure, it is hard to know what was wrong.
Qianqian
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/9aa55e0d-06fb-426b-9063-c6cd41760ea9n%40googlegroups.com.
Dear Dr. Fang,
Is there any mistake in the script that might generate the tetgen error?
hi Luca,
by only changing
[no,fa]=meshabox([-15 -10 8.6],[15 10 10.61],10);
to
[no,fa]=meshabox([-15 -10 8.6],[15 10 11],10);
your script eventually produced a very dense mesh after running 30 seconds on my machine. the mesh contains 503246 nodes and 2568343 elements, as you can see from the attached screenshot.
what happened was that your top-most layer only has a thickness of 0.1mm, which is dramatically shorter than other layers. To mesh such a multi-scaled domain, tetgen had to apply extensive refinement to satisfy the desired mesh quality metric (-q), thus, resulting in a very dense mesh.
if I don't change 10.61 to 11, tetgen will also eventually produce a mesh (if your computer has the needed memory), and it will be even denser than this one, because the layer thickness between your bbx top-face and the top of the lattice is only 0.01mm!
if you use DMMC algorithm, can you disable the mesh refinement by
attaching '-Y' in the last parameter of s2m, this will return a
coarse mesh
[newnode,newelem]=s2m(mrgnode,mrgface(:,1:3),1,50,'tetgen',c0,[],'-Y');
the best way to deal with thin-membrane in mmc is to use our
recently published implicit mmc (iMMC) algorithm by attaching a
thickness parameter to the selected faces of a coarse mesh. please
see the paper below (my student Yaoshen Yuan is CCed here),
especially Figs. 3c, 4g-i and 5c.
https://www.osapublishing.org/boe/fulltext.cfm?uri=boe-12-1-147&id=444347
a ready-to-adapt mmclab script can be found here
https://github.com/fangq/mmc/blob/master/mmclab/example/demo_immc_basic.m#L98-L119
Qianqian
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/60f57589-7ab2-4f15-bb88-f78b4332dad8n%40googlegroups.com.

Dear Dr. Fang,
I have tried to modify the script as you suggested, see below:
% Create inclusion:[no,fa]=meshabox([-15 -10 8.6],[15 10 11],10);
% Create the two layers surrounding the inclusion and the third layer beneath:[node,face,c0]=latticegrid([-30 30],[-30 30],[0 8 10.5 10.6]); % Create the three-layered mesh surface;fc2=cell2mat(face); face=[fc2(:,[1 2 3]); fc2(:,[1 3 4])];
% Combine the three layers and the inclusion:[mrgnode,mrgface]=surfboolean(node,face(:,[3 2 1]),'first',no,fa); % Merge the surfaces of the three layers with the surface of the inclusion;c0=[c0; 0 0 9.6]; c0(2,3)=8.3; c0(3,1:2)=[-20 20]; % Define the regions of the meshed domain by index;[newnode,newelem]=s2m(mrgnode,mrgface(:,1:3),1,20,'tetgen',c0,[],'-Y'); % Convert the merged surface mesh into volume;
Unfortunately, I do not obtain the same mesh as you attached in the figure, but something completely different. I have attached a figure to show you this.Do you have any idea why this is happening?
if you remove '-Y' you should get the mesh I previously attached, but if you don't have enough memory, tetgen can crash
are you going to use this for mmc? if so, the coarse mesh you saw is sufficient if you turn on the dual-grid mmc method (-M G, or cfg.method='grid').
Furthermore, I am not sure how s2m deals with the fact that the two top layers intersect the inclusion, which then has a plane overlapping the top surface of the lattice.Is that a problem?
because you used surfboolean('first'), the lattice is sliced by the bbx, so, the top layer is fine at least on my machine.
Qianqian
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/92de5c0c-1cbd-4ab9-8f7b-c4b9761f0a5en%40googlegroups.com.



Dear Dr. Fang,
I still can't manage to merge the inclusion correctly with the three-layered lattice.I was wondering: is it perhaps that I have not defined the centroids c0 correctly for all the three regions??
now I see the problem, yes, the surfboolean, or specifically, the cork utility that surfboolean calls, can not handle surface boolean operations between multi-compartment/multi-layered meshes.
when I added the '-first' and '-second' options for cork (https://github.com/fangq/cork/commit/3faf80d079dc9fb306c74f387bb256f1afd59921) back in 2016, I noticed the same - in that case it was a multi-layeled brain mesh. because cork utilizes the orientation of the triangles nodes (clock-wise/counter-clockwise) to determine in/out to perform the boolean operation, a multi-layered mesh makes it difficult for cork to determine which direction it should keep.
I still don't have a solution how to solve this, maybe try other utilities, such as meshlab, and see if you can do this manually.
Qianqian
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/77161fb2-be49-4964-9b83-953b3b6b17aan%40googlegroups.com.
Dear Dr. Fang,
Is there a way to produce a multi-scale domain, like the 3-layered mesh I have shown you here with a thin-membrane (0.1 mm) on top, using MMC instead of MMClab?
the fastest way to convert a working mmclab simulation (cfg) is
to call mmc2json.m and save the settings to a .json+mesh files
https://github.com/fangq/mmc/blob/master/mmclab/mmc2json.m
the function is side-by-side with mmclab.m
I have to admit that we don't use this function often, so it is
possible the converted input file may not work directly - in such
case, please follow up in this thread.
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/bab5623f-67c3-4963-b58f-c0c6f7834627n%40googlegroups.com.
Dera Dr. Fang,
Picking up from the last thread: I have tried to add a planar source to use with MMC to the domain you helped me debug and create (minus the inclusion, which i removed, so now it is just a 3-layered mesh), using the following script:
source=struct('srctype','planar','srcpos',[-0.5 -0.5 20.6],'srcdir',[0 0 -1 -1.111],'srcparam1',[1 0 0 0],'srcparam2',[0 1 0 0]);[srcnode,srcelem]=mmcaddsrc(node,elem,source,'KeepShape',1);srcelem(:,1:4)=meshreorient(srcnode,srcelem(:,1:4));
hi Luca, sorry for the delay.
I could not reproduce this. I ran this below script and it worked fine
%% Create inclusion:
[no,fa]=meshabox([-15 -10 8.6],[15 10 11],10);
%% Create the two layers surrounding the inclusion
and the third skin layer (subcutis) beneath:
[node,face,c0]=latticegrid([-30 30],[-30 30],[0 8
10.5 10.6]); % Create the three-layered mesh surface;
fc2=cell2mat(face); face=[fc2(:,[1 2 3]); fc2(:,[1 3
4])];
%% Combine the three layers and the inclusion:
[mrgnode,mrgface]=surfboolean(node,face(:,[3 2
1]),'first',no,fa); % Merge the surfaces of the three layers
with the surface of the inclusion;
[mrgnode,mrgface]=removeisolatednode(mrgnode(:,1:3),mrgface);
% Remove isolated nodes in the the merged surface mesh;
c0=[c0; 0 0 9.6]; c0(2,3)=8.3; c0(3,1:2)=[-20 20]; %
Define the regions of the meshed domain by index;
[newnode,newelem]=s2m(mrgnode,mrgface(:,1:3),1,50,'tetgen',c0);
% Convert the merged surface mesh into volume;
[newnode,newelem]=sortmesh([],newnode,newelem,1:4); %
Sort nodes and elements;
newelem(:,1:4)=meshreorient(newnode,newelem(:,1:4));
% Re-orient elements;
source=struct('srctype','planar','srcpos',[-0.5 -0.5
20.6],'srcdir',[0 0 -1 -1.111],'srcparam1',[1 0 0
0],'srcparam2',[0 1 0 0]);
[srcnode,srcelem]=mmcaddsrc(newnode,newelem,source,'KeepShape',1);
srcelem(:,1:4)=meshreorient(srcnode,srcelem(:,1:4));
plotmesh(srcnode, srcelem)
the output mesh looks like the one attached. Ubuntu Linux 18.04, MATLAB R2018a, latest git version of mmc/iso2mesh.
Qianqian
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/b1fb2737-659a-4746-b60c-c72302764970n%40googlegroups.com.
I ran the script in windows 10 matlab 2016b, and got the same error as yours. so, I guess the script works under Linux, but not on windows.
Qianqian
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/c6c11c9d-b51a-472c-af13-afe8fc22658dn%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iso2mesh-users/adf54c67-268a-4483-922c-3b807a3aa688n%40googlegroups.com.