JuliaGeometry / TetGen.jl

Julia's TetGen wrapper
MIT License
42 stars 9 forks source link

TetGen doesn't work for triangular input surfaces? #37

Open Kevin-Mattheus-Moerman opened 5 months ago

Kevin-Mattheus-Moerman commented 5 months ago

Based on the cube (quad) mesh example provided in the README, I've just tried to apply this to triangular boundary surfaces. E.g. like this:

F = TriangleFace{Cint}[TriangleFace(1, 2, 3), TriangleFace(4, 2, 1), TriangleFace(4, 3, 2), TriangleFace(4, 1, 3)]
V = Point{3, Float64}[[-0.8164965809277261, -0.47140452079103173, -0.3333333333333333], [0.8164965809277261, -0.47140452079103173, -0.3333333333333333], [0.0, 0.0, 1.0], [0.0, 0.9428090415820635, -0.3333333333333333]]
markers = Cint[-1, -2, 0, 0]

mesh = GeometryBasics.Mesh(V, meta(F, markers=markers))
result = tetrahedralize(mesh, "vpq1.414a0.1")

However, I get the following error:

ERROR: MethodError: no method matching unsafe_array_convert(::Type{Ptr{…}}, ::StructArrays.StructVector{GeometryBasics.NgonFaceMeta{…}, @NamedTuple{…}, Int64})

Closest candidates are:
  unsafe_array_convert(::Type{Ptr{T}}, ::Vector{T}) where T
   @ TetGen ~/.julia/packages/TetGen/QKVpk/src/jltetgenio.jl:251
  unsafe_array_convert(::Type{Ptr{T1}}, ::Vector{T2}) where {T1, T2}
   @ TetGen ~/.julia/packages/TetGen/QKVpk/src/jltetgenio.jl:255
  unsafe_array_convert(::Type{Ptr{TetGen.CFacet{T}}}, ::Tuple{Vector{F}, Vector{TetGen.CPolygon}, Array{TetGen.CFacet{T}, 1}}) where {F, T}
   @ TetGen ~/.julia/packages/TetGen/QKVpk/src/jltetgenio.jl:246
  ...
Stacktrace:
 [1] cconvert(CIO::Type{…}, obj::TetGen.JLTetGenIO{…})
   @ TetGen ~/.julia/packages/TetGen/QKVpk/src/jltetgenio.jl:293
 [2] tetrahedralize(input::TetGen.JLTetGenIO{Float64, 4, 0, 0, Int64, StructArrays.StructVector{…}}, command::String)
   @ TetGen ~/.julia/packages/TetGen/QKVpk/src/jltetgenio.jl:314
 [3] tetrahedralize(mesh::GeometryBasics.Mesh{3, Float64, GeometryBasics.Ngon{…}, FaceView{…}}, command::String)
   @ TetGen ~/.julia/packages/TetGen/QKVpk/src/api.jl:39
 [4] top-level scope
   @ ~/DATA/Julia/comodo_wip/wip/temp_use_TetGen.jl:37
Some type information was truncated. Use `show(err)` to see complete types.

Any help resolving this would be appreciated, thanks.

j-fu commented 5 months ago

This is unfortunate. I am not that much into this part of the API as I am focused on the "raw API"

May be @SimonDanisch can have a look at this before I try to figure this out.

Kevin-Mattheus-Moerman commented 5 months ago

@j-fu thanks for the quick response. I may need the raw interface too. Is there an example you can share for using it to create a tet mesh on an input domain?

I was also wondering how to retrieve the input boundary marker data, and how to mesh multiple regions and cope with holes. Usually it requires "interior points" to define the regions/holes. (I wrote a tegen wrapper for MATLAB in the past https://www.gibboncode.org/).

Thanks again

j-fu commented 5 months ago

This all should work. See examples/examples.jl (I see there is nothing with hole points though). I am mostly using TetGen via SimplexGridFactory.jl.

So perhaps it makes sense to have a more comprehensive set of examples.