fangq / iso2mesh

Iso2Mesh - a 3D surface and volumetric mesh generator for MATLAB/Octave
http://iso2mesh.sf.net
Other
182 stars 73 forks source link

fix savemsh.m error #58

Closed shihan-ma closed 3 years ago

shihan-ma commented 3 years ago

Fix the index error when building the table of regions.

fangq commented 3 years ago

@shihan-ma, I don't use msh file myself. but using reg(k) makes it possible to make the actual labels in the file. doesn't your change removes the old label and renumber those sequentially?

shihan-ma commented 3 years ago

The savemsh function failed when used in the sample scripts and in my stl to mesh script. I found out that the region id is numbered from 0 in elem. However, Matlab indices start from 1. Using M.Regions.name{reg(k)} causes an error. I guess it could be fixed by simply add 1 to reg(k). If the old labels are numbered in sequence, reg(k)+1 and k will be the same.

fangq commented 3 years ago

hi @shihan-ma, if the issue is the presence of 0-label (tetgen assigns regions a 0 label if it is not region seed defined), then, a proper fix is to replace it with a non-zero label (perhaps max(label)+1).

if you add all labels by 1, then the numbering will not match the desired region label according to the region seeds.

I think inserting the following line before the for-loop should fix the problem, do you agree?

reg(reg==0)=max(reg)+1;