BitArray{3} mesh

What is the recommended process to mesh a BitArray?

The meshing method requires an isovalue. For a BitArray, an isovalue of 1, true or :true don’t seem to work: 0 faces are returned.

Another method is to convert from BitArray to an Array: MyData = 1MyData. Then isovalue=0.5 could work.

In general, is isovalue to be interpreted as “everything in MyArray .>= isovalue”?

Thanks!

I don’t know what this means. Lack of context may be the reason why you are not getting answers to this.

1 Like

You’re right, thanks for the reminder, Tamas. Couldn’t edit my post, so here’s a MWE:

# Packages
using Random
using Meshing
using GeometryBasics
using Makie#master

# Generate Mesh
A               = bitrand(5,5,5)
algo            = MarchingCubes(iso=1, insidepositive=true)
vertices, faces = isosurface(A, algo, Point{3,Float32}, TriangleFace{Int})
m               = GeometryBasics.Mesh(vertices,faces)

# Visualize Mesh
Makie.mesh(m, color=:blue, shading=false)
Makie.wireframe!(m)

Question is: why doesn’t iso=1 work given that this is a BitArray? It returns 0 faces.

After playing with the isovalue, I see that any value 0 <= iso < 1 will return a consistent number of faces. I am a bit puzzled as to why iso=1 does not work.

I guess I’m looking to answer the general question of how the isovalue is interpreted. Is it A .>= iso?

Much appreciated!

edit: I wonder if it has to do with the default tolerance eps = 1e-3. It breaks down when it can’t find a value greater than 1 in a boolean array. If I set eps=0, iso=1 still does not work.

1 Like

Your isosurface should follow grid edges between nodes with value 1 which are connected nodes with value 0. Since marching cubes doesn’t seem to like this situation where there is no value greater than 1, I would just set iso to some value close to but less than 1, say 0.999 and then round-up all the resulting isosurface coordinates to the nearest grid node.

3 Likes

Yes, that seems to work. As I mention in my previous post, any value 0 <= iso < 1 will work (and produce the same results), so I suppose this is the solution in this case.

Just as an additional data point, when visualizing with Makie.volume, isovalue=1 will work.