gibbonCode / GIBBON

The Geometry and Image-Based Bioengineering add-On for MATLAB
http://gibboncode.org/
GNU Affero General Public License v3.0
191 stars 60 forks source link

Smoothing a Quad Mesh #138

Closed LawSmith408 closed 2 years ago

LawSmith408 commented 2 years ago

I am looking to obtain a smooth hexahedral mesh of a thin gyroid triply periodic minimal surface. The end result I'm looking for is something like this (except using hex elements instead of tets. This image generated using the triplyPeriodicMinimal and runTetGen documentation)

image

I use tri2quad to subdivide triangular faces of a zero-thickness gyroid isosurface into quads.

image

It appears that the algorithm used follows the first half of the algorithm presented in this paper:

https://acdl.mit.edu/ESP/Publications/IMR28.pdf

I'd like to smooth the resulting quad mesh, but I am having trouble... in part because I'm not sure whether to use quad_smooth, tesSmooth, or patchSmooth.

I created a demo script to play around with quad_smooth, but I'm not able to parse exactly how the inputs are used. Could you shed a little light for me? Here's my demo code!

[F,V]=stanford_bunny; [Fq,Vq]=tri2quad(F,V,2);

Ev = 2:size(Vq,1); % Is this a list of the indices of nodes we will adjust IND_V_not_Ev = 1; %this might be the complement of Lc = Ev'; %not sure what this is n = 20; %number of algorithm iterations Ls = 0.75; %this seems like a scaling parameter for adjusting positions w1 = 0.9; %not sure what this weight is

% V2=quad_smooth(Vq,Ev,IND_V_not_Ev,Lc,n,Ls,w1);

cPar.Method='HC'; cPar.n=15; cPar.RigidConstraints=[]; % [V2]=tesSmooth(Fq,Vq,[],cPar);

[V2]=patchSmooth(Fq,Vq,[],cPar);

if ~norm(Vq-V2) disp('Input and Output Meshes Identical') end

subplot(1,2,1); gpatch(Fq,Vq); view(3); axis equal; hold on subplot(1,2,2); gpatch(Fq,V2); view(3); axis equal set(gcf,'Position',[302 248 1224 733])

LawSmith408 commented 2 years ago

I will also add that it appears like this is a nontrivial problem... not a lot of other options for generating smooth quad meshes on arbitrary geometries.

Here is the best result I could get using Blender: image

Which is quad-dominated but still contains some tris.

This is what I get using InstantMeshes, a free tool based on a SIGGRAPH paper: https://github.com/wjakob/instant-meshes

Which appears to do a slightly better job, but still includes some tris and also some pentagons (which would eventually require transition elements for finite element analysis) image

The is another commercial option which claims to outperform InstantMeshes: https://geometryfactory.com/products/igm-quad-meshing/

Kevin-Mattheus-Moerman commented 2 years ago

Hi @LawSmith408, thanks for using GIBBON and for posting this issue. Apologies for the slow response.

Why is it that you need quad or hex elements? Could you use tetrahedral elements or pentahedral elements (thickened triangles).

You may be interested in this way to create quad meshes from triangulations: https://www.gibboncode.org/html/HELP_tri2quadGroupSplit.html Note, this approach does split the elements once if you want a full quad mesh. Also this code is slow since it loops over elements.

Isosurfaces provide horrible triangulations, here is a code which can resample it in an improved way (although it does smooth the surface a little too), or perhaps you have used this already?: https://www.gibboncode.org/html/HELP_ggremesh.html You could consider doing ggremesh first prior to element conversion.

The best approach to get a quisi-regular quad mesh, which I have not implemented yet, is something like what is done here:, https://onlinelibrary.wiley.com/doi/full/10.1002/adfm.202101373 I.e. to create a quad mesh in the hyperbolic space and project to Euclidian space. I am talking to that author to implement it. He is also part of the GIBBON community. @SebastienCallens :wave:

On smoothing, I think you might not need that. I think when you say smooth, you might actually mean "regular" or quasi-regular quads, e.g. that the quad mesh looks rather ordered (not a mess). Smoothing for meshes is different, it makes rough and noisy shapes more smooth. It can make the mesh more regular looking too but I would say the primary action is also to alter the shape, which is probably not what you want. On smoothing methods, yes my apologies I implemented it a couple of times. quad_smooth is old and should be deprecated. tesSmooth is intended also for volumetric meshes. The one to use for general surface meshes is patchSmooth.

I hope these comments help. It would be fantastic if @SebastienCallens could help implement (in MATLAB) that better way to encode the triply periodic minimal surfaces.

I hope this helps.

LawSmith408 commented 2 years ago

Thank you for the great pointers - especially the Callens paper. It is a very interesting read!

I am interested in quad elements just out of curiosity - I would like to compare the finite element results for crushing TPMS structures as simulated by triangular shell, quadrilateral shell, and tetrahedral elements. I will check out the tri2quadGroupSplit function you mentioned!

You're right, I am aiming "regularization" and not "smoothing" - thanks for pointing that out.

I am well familiar with ggremesh and I currently use it to remesh triangulations extracted by calling isosurface().

Kevin-Mattheus-Moerman commented 2 years ago

@LawSmith408 how are you getting on? Let me know if you need more help.

Kevin-Mattheus-Moerman commented 2 years ago

@LawSmith408 I'll close this issue for now, but do let me know if you need any more help.