Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TetGen files import unsuccesful #169

Open
felipebm1996 opened this issue Jun 2, 2023 · 4 comments
Open

TetGen files import unsuccesful #169

felipebm1996 opened this issue Jun 2, 2023 · 4 comments

Comments

@felipebm1996
Copy link

Hi all,

I'm using the gibbon toolbox on Matlab R2021b, Windows 11. A bit of context, I run multiple demos to validate that the Gibbon's functions work (they worked perfectly) and I also adapted an example to my specific problem using the runTetGen function and also worked. Then, I created a new script, in the same folder of the previous .m files, and appears the next warning:

Warning: \Documents\GIBBON-master\data\temp\skin.1.node import unsuccesful

Because of this, the meshOutput is empty. This error is bizarre and I tried a ton of things but now I'm out of ideas.

Thanks in advance for your help!

@Kevin-Mattheus-Moerman
Copy link
Member

@felipebm1996 sorry to hear about this issue.

Can you produce copy and paste the runTetGen text produced in the command window here? Are there any error messages there?

@felipebm1996
Copy link
Author

@Kevin-Mattheus-Moerman thanks for your reply.

Here is text of the command window. The first TETGEN is done without smoothing, as you see there is self-interections. Then, the second on shows the error of import unsuccesful. I also attach a .zip with the files and codes that I'm using. Thanks again.

github issue.zip

` %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- TETGEN Tetrahedral meshing --- 09-Jun-2023 11:42:53

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- Writing SMESH file --- 09-Jun-2023 11:42:53
----> Adding node field
----> Adding facet field
----> Adding holes specification
----> Adding region specification
--- Done --- 09-Jun-2023 11:42:53

--- Running TetGen to mesh input boundary--- 09-Jun-2023 11:42:53
Opening C:<mypath>\Documents\GIBBON-master\data\temp\softtissue.smesh.
Delaunizing vertices...
Delaunay seconds: 0.104
Creating surface mesh ...
Surface mesh seconds: 0.007
Detecting self-intersecting facets...
Facet #1 intersects facet #1 at triangles:
(6011, 5845, 6354) and (5845, 5769, 6273)
Facet #1 intersects facet #1 at triangles:
(6011, 5845, 6354) and (5769, 6330, 6273)
Facet #1 intersects facet #1 at triangles:
(5845, 6273, 6354) and (5769, 6330, 6273)
Facet #1 intersects facet #1 at triangles:
(5947, 5623, 6072) and (6072, 5709, 6349)
Facet #1 intersects facet #1 at triangles:
(5947, 5623, 6072) and (6349, 5709, 5959)
Facet #1 intersects facet #1 at triangles:
(5947, 5623, 6072) and (5709, 5413, 5959)
Facet #1 intersects facet #1 at triangles:
(5947, 5623, 6072) and (5248, 5413, 5709)
Facet #1 intersects facet #1 at triangles:
(5623, 5709, 6072) and (5248, 5413, 5709)
Facet #1 intersects facet #1 at triangles:
(7569, 7058, 7368) and (7804, 7507, 7308)
Facet #1 intersects facet #1 at triangles:
(7569, 7308, 7058) and (7804, 7507, 7308)
Facet #1 intersects facet #1 at triangles:
(7058, 6850, 6550) and (6850, 6836, 6533)
Facet #1 intersects facet #1 at triangles:
(7058, 6850, 6550) and (6850, 6836, 6533)
Facet #1 intersects facet #1 at triangles:
(7058, 6850, 6550) and (6836, 6327, 6533)
Facet #1 intersects facet #1 at triangles:
(6850, 6533, 6550) and (6836, 6327, 6533)
Facet #1 intersects facet #1 at triangles:
(8328, 8157, 7832) and (8431, 7948, 8257)
Facet #1 intersects facet #1 at triangles:
(8704, 8157, 8328) and (8431, 7948, 8257)
Facet #1 intersects facet #1 at triangles:
(7832, 7569, 7368) and (7948, 7507, 7804)
Facet #1 intersects facet #1 at triangles:
(8157, 7569, 7832) and (8257, 7948, 7804)
Facet #1 intersects facet #1 at triangles:
(8157, 7569, 7832) and (8431, 7948, 8257)
Facet #1 intersects facet #1 at triangles:
(8157, 7569, 7832) and (7948, 7507, 7804)
Facet #1 intersects facet #1 at triangles:
(7569, 7058, 7368) and (7804, 7507, 7308)
Facet #1 intersects facet #1 at triangles:
(7569, 7058, 7368) and (7948, 7507, 7804)
Facet #1 intersects facet #1 at triangles:
(8704, 8655, 8157) and (8655, 8431, 8257)
Facet #1 intersects facet #1 at triangles:
(8704, 8655, 8157) and (8431, 7948, 8257)
Facet #1 intersects facet #1 at triangles:
(8157, 7804, 7569) and (8257, 7948, 7804)
Facet #1 intersects facet #1 at triangles:
(8157, 7804, 7569) and (7948, 7507, 7804)
Facet #1 intersects facet #1 at triangles:
(7569, 7308, 7058) and (7804, 7507, 7308)
Facet #1 intersects facet #1 at triangles:
(9729, 9572, 9242) and (9572, 9496, 9092)
Facet #1 intersects facet #1 at triangles:
(9729, 9572, 9242) and (9496, 8916, 9092)
Facet #1 intersects facet #1 at triangles:
(9572, 9092, 9242) and (9496, 8916, 9092)
Facet #1 intersects facet #1 at triangles:
(10040, 9572, 9729) and (10138, 9496, 10040)
Facet #1 intersects facet #1 at triangles:
(9729, 9572, 9242) and (9572, 9496, 9092)
Facet #1 intersects facet #1 at triangles:
(9729, 9572, 9242) and (10138, 9496, 10040)
Facet #1 intersects facet #1 at triangles:
(9729, 9572, 9242) and (10040, 9496, 9572)
Facet #1 intersects facet #1 at triangles:
(9729, 9572, 9242) and (9496, 8916, 9092)
Facet #1 intersects facet #1 at triangles:
(9572, 9092, 9242) and (9496, 8916, 9092)
Facet #1 intersects facet #1 at triangles:
(9928, 9869, 9911) and (9712, 9672, 9928)
Facet #1 intersects facet #1 at triangles:
(9712, 9672, 9928) and (9869, 9531, 9911)
Facet #1 intersects facet #1 at triangles:
(9928, 9672, 9869) and (9869, 9531, 9911)
Facet #1 intersects facet #1 at triangles:
(12247, 11994, 12558) and (11586, 11630, 12084)
Facet #1 intersects facet #1 at triangles:
(12558, 11994, 12492) and (11994, 11586, 12084)
Facet #1 intersects facet #1 at triangles:
(12558, 11994, 12492) and (11586, 11630, 12084)
Facet #1 intersects facet #1 at triangles:
(12247, 11625, 11994) and (11586, 11630, 12084)
Facet #1 intersects facet #1 at triangles:
(11625, 11586, 11994) and (11586, 11630, 12084)

!! Found 44 pairs of faces are intersecting.

Self-intersection seconds: 0.228
Writing C:<mypath>\Documents\GIBBON-master\data\temp\softtissue.1.node.
Writing C:<mypath>\Documents\GIBBON-master\data\temp\softtissue.1.face.
--- Done --- 09-Jun-2023 11:42:54

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- Importing TetGen files --- 09-Jun-2023 11:42:54
--- Done --- 09-Jun-2023 11:42:54

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- TETGEN Tetrahedral meshing --- 09-Jun-2023 11:43:01

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- Writing SMESH file --- 09-Jun-2023 11:43:01
----> Adding node field
----> Adding facet field
----> Adding holes specification
----> Adding region specification
--- Done --- 09-Jun-2023 11:43:01
--- Running TetGen to mesh input boundary--- 09-Jun-2023 11:43:01
Opening C:<mypath>\Documents\GIBBON-master\data\temp\softtissue.smesh.
Delaunizing vertices...
Delaunay seconds: 0.031
Creating surface mesh ...
Surface mesh seconds: 0.003
Detecting self-intersecting facets...

No faces are intersecting.

Self-intersection seconds: 0.213
--- Done --- 09-Jun-2023 11:43:01

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--- Importing TetGen files --- 09-Jun-2023 11:43:01
Warning: C:<mypath>\Documents\GIBBON-master\data\temp\softtissue.1.node import unsuccesful
--- Done --- 09-Jun-2023 11:43:01 `

@Kevin-Mattheus-Moerman
Copy link
Member

The input STL you have contains intersecting triangles which is an invalid mesh for tetgen. The error messages from tetgen above are useful e.g. if it says:

Facet https://github.com/gibbonCode/GIBBON/issues/1 intersects facet https://github.com/gibbonCode/GIBBON/issues/1 at triangles:
(6011, 5845, 6354) and (5845, 5769, 6273)

Then you can debug/diagnose the issue in MATLAB e.g. by visualizing your mesh along with those bad triangles:

gpatch([6011, 5845, 6354],V,'r','r',1,3)

GIBBON's ggremesh function doesn't just resample but it also fixes several invalidity issues with the mesh. E.g. it removes/fixes intersecting mesh regions. Hence the result can now be passed to TetGen. You could, if you prefer also use a different e.g. external tool for removal/curing of intersecting triangles.

In the below zip I went through the steps and do not get an error. Can you test it?

Note I also added a quick attempt (not really needed, so you can delete/ignore it, but might be nice to check out) to label the faces ("feature detection"), and to reorient the model (e.g. the grouping with the current settings on my machine picked out surface 4 as the inner cylinder, principal component directions for this inner hole surface help rotate it).

testing_code.zip

Let me know if you need more help.

@felipebm1996
Copy link
Author

Thanks for the code, it also doesn't show errors.

Here some clarifications:

Before I used tetgen, the 'import_segment.m' function uses ggremesh on the input STL to redefine the number of vertices (on this step I believe that fixes the issues that you mentioned), then these faces and vertices are used by patchThick to create a inner shell. Finally, the output faces Fp2 (or F2_2 as I named in the testing_code.m) plus the corresponding vertices are the input for the tetgen, here is the error. The idea is create a inner shell first and then use tetgen with the inner faces and vertices.

Let me know if you have more questions about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants