Error with s2m

371 views
Skip to first unread message

Luca Giannoni

unread,
Jun 7, 2021, 10:46:25 AM6/7/21
to iso2mesh-users
Dear iso2mesh users,

I am encountering the following error when using s2m to convert a surface mesh composed of a 3-layer lattice and a random-shaped inclusion (created using surfboolean 'all') into a 3D volume mesh:

Error using surf2mesh (line 117)
Tetgen command failed:
Opening C:\Users\lucag\AppData\Local\Temp\iso2mesh-lucag\post_vmesh.poly.
Constructing Delaunay tetrahedralization.
Delaunay seconds:  0.245
Creating surface mesh.
Recovering boundaries.
Error:  Invalid PLC! A point and a subface intersect
  Point 40573. Subface (#1733) (16586, 16564, 16566)
Program stopped.

Can anyone help me with this?

Thanks,
Luca

Fang, Qianqian

unread,
Jun 7, 2021, 3:07:43 PM6/7/21
to iso2mes...@googlegroups.com, Luca Giannoni

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.


Luca Giannoni

unread,
Jun 8, 2021, 3:13:31 AM6/8/21
to iso2mesh-users
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.

Thanks again, 
Luca

Surface_combined.png

Fang, Qianqian

unread,
Jun 8, 2021, 4:25:55 PM6/8/21
to iso2mes...@googlegroups.com, Luca Giannoni
On 6/8/21 3:13 AM, Luca Giannoni wrote:
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


Luca Giannoni

unread,
Jun 30, 2021, 4:16:51 AM6/30/21
to iso2mesh-users
Dear Dr. Fang,

Here attached a short version of the script I use to (try to) generate the 3D layered volume, simplified using a rectangular inclusion:

%% Create inclusion:
[no,fa]=meshabox([-15 -10 8.6],[15 10 10.61],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;

If I run it, I still get a 'tetgen error', even though I expanded the inclusion surface to avoid overlapping of planes.

Thanks,
Luca

Luca Giannoni

unread,
Jul 5, 2021, 4:11:02 AM7/5/21
to iso2mesh-users
Dear Dr. Fang,

Is there any mistake in the script that might generate the tetgen error?

Thanks,
Luca

Qianqian Fang

unread,
Jul 5, 2021, 5:59:52 PM7/5/21
to iso2mes...@googlegroups.com, Luca Giannoni, Yaoshen Yuan, mmc-...@googlegroups.com
On 7/5/21 4:11 AM, Luca Giannoni wrote:
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


dense_mesh_adpative_lattice.png

Luca Giannoni

unread,
Jul 6, 2021, 5:09:08 AM7/6/21
to iso2mesh-users
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?

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?

Thanks,
Luca
test result.jpg

Fang, Qianqian

unread,
Jul 6, 2021, 10:03:28 AM7/6/21
to iso2mes...@googlegroups.com, Luca Giannoni
On 7/6/21 5:09 AM, Luca Giannoni wrote:
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


Luca Giannoni

unread,
Jul 6, 2021, 11:20:02 AM7/6/21
to iso2mesh-users
Dear Dr. Fang,

I have tried removing '-Y' as you suggested and the script does create a volumetric mesh now. 
However, there is one issue I found with my machine: the box inclusion is not merged properly with both top layers and only the intersection with the uppermost layer (0.1-mm thickness) is extracted from s2m! Thus the 2-mm thick box is now a 0.1-mm thick slab.
I have attached the cross-sections X>0 and Z>9.6 of the mesh and the plot of what is left of the box after merging it with the lattice.
Do you have any idea why this is happening?

Thanks,
Luca
Cross_X.jpgCross_Z.jpgBox.jpg

Luca Giannoni

unread,
Jul 13, 2021, 3:21:32 AM7/13/21
to iso2mesh-users
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??

Thanks,
Luca

Fang, Qianqian

unread,
Jul 16, 2021, 2:07:05 PM7/16/21
to iso2mes...@googlegroups.com, Luca Giannoni
On 7/13/21 3:21 AM, Luca Giannoni wrote:
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


Luca Giannoni

unread,
Aug 26, 2021, 6:03:46 AM8/26/21
to iso2mesh-users
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?

Thanks,
Luca

Qianqian Fang

unread,
Sep 3, 2021, 11:41:09 AM9/3/21
to iso2mes...@googlegroups.com, Luca Giannoni, mmc-...@googlegroups.com
On 8/26/21 6:03 AM, Luca Giannoni wrote:
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.

Luca Giannoni

unread,
Nov 10, 2021, 6:11:16 AM11/10/21
to iso2mesh-users
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)); 

However I get the following error:

Error using surf2mesh (line 117)
Tetgen command failed:
Opening C:\Users\lucag\AppData\Local\Temp\iso2mesh-lucag\post_vmesh.poly.
Constructing Delaunay tetrahedralization.
Delaunay seconds:  29.517
Creating surface mesh.
Recovering boundaries.
Error:  Invalid PLC! A point and a segment intersect.
  Point: 3015809. Segment: (2513736, 2509629).
Program stopped.

Error in meshrefine (line 251)
            [no,el]=surf2mesh(allnode,bothsides,[],[],1,10);

Error in mmcaddsrc (line 71)
[newnode,newelem]=meshrefine(node,elem,opt);

Error in MMC_create_skin_mesh_v2 (line 43)
[srcnode,srcelem]=mmcaddsrc(node,elem,source,'KeepShape',1); % Add planar source to the mesh domain;
 
If i increase the thickness of the upper layer from 0.1 mm t0 1 mm and it seems to work. I assume the problem is connected to the small size of the upper layer. Is there a way to circumvent this problem?

Thanks,
Luca

On Monday, 5 July 2021 at 23:59:52 UTC+2 q.fang wrote:

Qianqian Fang

unread,
Nov 15, 2021, 3:49:34 PM11/15/21
to iso2mes...@googlegroups.com, Luca Giannoni
On 11/10/21 6:11 AM, Luca Giannoni wrote:
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


mmc_3layer_src.png

Luca Giannoni

unread,
Nov 17, 2021, 3:40:54 AM11/17/21
to iso2mesh-users
Dear Dr. Fang,

I have copied your script and run it on my machine (Windows 10 Pro, Matlab R2021a, MMC version Moon Cake Beta 2020) and I still get the error:

Error using surf2mesh (line 117)
Tetgen command failed:
Opening C:\Users\lucag\AppData\Local\Temp\iso2mesh-lucag\post_vmesh.poly.
Constructing Delaunay tetrahedralization.
Delaunay seconds:  4.909
Creating surface mesh.
Recovering boundaries.
Error:  Invalid PLC. Two segments intersect.
  1st: (479271, 479485), 2nd: (479544, 479202).
Program stopped.

Error in meshrefine (line 251)
            [no,el]=surf2mesh(allnode,bothsides,[],[],1,10);

Error in mmcaddsrc (line 71)
[newnode,newelem]=meshrefine(node,elem,opt);

Error in Untitled (line 14)
[srcnode,srcelem]=mmcaddsrc(newnode,newelem,source,'KeepShape',1);

Is there something wrong with my software or desktop??

Thanks,
Luca

mari sadat

unread,
Nov 20, 2021, 9:57:44 AM11/20/21
to iso2mesh-users
Hi
I have the same problem too. whenever I want to mesh thin layer(for example 0.02mm) accompany with thick layers( for example 4mm ) the same errors like 'Delaunay seconds ' and 'invalid PLC, Two segments intersect' appear. Also when I want to merge a cylinder with this grid, the errors like that, don't let me to choose my favorite cylinder radius. For example I can't put the cylinder radius more than 1mm.

Qianqian Fang

unread,
Jan 21, 2022, 12:30:22 AM1/21/22
to iso2mesh-users
marisadat66, please see FAQ#1
if the input surfaces are self-intersecting, you will have to manually intersect them by calling surfboolean(), or call meshcheckrepair(...,'meshfix') to remove self-intersection

Luca Giannoni

unread,
Mar 17, 2022, 10:18:46 AM3/17/22
to iso2mesh-users
Dear Dr. Fang, 

I still have not figured out the issue of why the script works fine on your machine but in mine gives me a ' two segments intersect' error.

I have downloaded the most recent github master versions of both MMC and iso2mesh, but the error persists.

May it be connected to the version of Matlab I am using (Matlab R2021b)?

Thanks,
Luca

Luca Giannoni

unread,
Mar 17, 2022, 10:37:46 AM3/17/22
to iso2mesh-users
In addition to my previous post:

I have downloaded Matlab R2018a (the same versione you used) and rerun exactly the same script that worked on your machine, but the error comes up anyway.
This is really puzzling me...

Luca

Qianqian Fang

unread,
Apr 10, 2022, 11:11:19 PM4/10/22
to iso2mesh-users
> I have downloaded Matlab R2018a (the same versione you used) and rerun exactly the same script that worked on your machine, but the error comes up anyway.
> This is really puzzling me...

what OS do you use?

Luca Giannoni

unread,
Apr 11, 2022, 2:37:06 AM4/11/22
to iso2mesh-users
Dear Dr. Fang,

I am currently using Windows 10 Pro, version 21H2 (up to the latest system updates)

Luca

Qianqian Fang

unread,
Apr 11, 2022, 8:00:10 PM4/11/22
to iso2mes...@googlegroups.com, Luca Giannoni

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

Luca Giannoni

unread,
Apr 12, 2022, 3:23:38 AM4/12/22
to iso2mesh-users
This is interesting! Why using two different OS should affect som much the results?

Luca

Qianqian Fang

unread,
Apr 12, 2022, 12:39:38 PM4/12/22
to iso2mes...@googlegroups.com, Luca Giannoni
this is a known problem. the meshing utilities used in iso2mesh (tetgen, cork, cgal*) are compiled individually on each platform. even the source code compiled are identical, the behaviors of the binaries do not have the guarantee that they will be deterministic. some of such behavior is a result is handling numerical round-off errors, some others are related to random-number-generator included in each tool.

so, generally, we still can't ensure reproducibility of meshes across platforms. see this issue:



in this particular case, it is because windows version of tetgen (1.4.3 and 1.5) do not see to have the same level of tolerance to input accuracy.

Qianqian
Reply all
Reply to author
Forward
0 new messages