JuliaGeometry / TetGen.jl

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

Voronoi edges #32

Open himcraft opened 2 years ago

himcraft commented 2 years ago

The function TetGen.voronoi() seems giving wrong results. I think Voronoi diagram should contain no nodes from the input by definition.

I want to generate a Voronoi diagram of points distributed in a cube, but the function gives this result:

julia> points
18-element Vector{Point3{Float64}}:
 [0.08456788617387545, 0.6497784220953491, 0.7651525711446618]
 [0.028556399240840413, 0.2317874394033026, 0.468892769192472]
 [0.26632804301123825, 0.8186148060679752, 0.7773876008016107]
 [0.13291567046032693, 0.07110853378792514, 0.6820381594695846]
 [0.9962270232031032, 0.5826099098133337, 0.578540445051634]
 [0.16635112279720943, 0.5001270334521524, 0.6245013162465198]
 [0.2314725162222675, 0.9871353669436038, 0.7652880990761379]
 [0.11753264631398874, 0.8913434319674096, 0.0834823244596401]
 [0.5786593524030887, 0.9099420749225255, 0.40876829495504174]
 [0.6076092814573353, 0.8845532830403793, 0.34616515245781887]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 1.0]
 [0.0, 1.0, 0.0]
 [1.0, 0.0, 0.0]
 [1.0, 1.0, 0.0]
 [1.0, 0.0, 1.0]
 [0.0, 1.0, 1.0]
 [1.0, 1.0, 1.0]

julia> TetGen.voronoi(points)
Mesh{3, Float64, Triangle}:
 Triangle([0.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 1.0, 1.0])
 Triangle([0.0, 1.0, 1.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0])
 Triangle([0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0])
 Triangle([0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0])
 Triangle([0.0, 1.0, 1.0], [0.0, 0.0, 1.0], [1.0, 1.0, 1.0])
 Triangle([1.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 0.0, 0.0])
 Triangle([0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0])
 Triangle([0.0, 1.0, 0.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0])
 Triangle([0.0, 1.0, 0.0], [1.0, 1.0, 0.0], [1.0, 0.0, 0.0])
 Triangle([0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0])
 Triangle([1.0, 0.0, 1.0], [0.0, 0.0, 1.0], [1.0, 0.0, 0.0])
 Triangle([1.0, 1.0, 0.0], [1.0, 1.0, 1.0], [1.0, 0.0, 0.0])

It is clearly not a correct Voronoi diagram. I tried vo=tetrahedralize(JLTetGenIO(points),"v"), it prompts Writing Voronoi edges. But I cannot see any Voronoi-related data in the struct of vo.

So could you please help me with how I can find the correct Voronoi edges information?

j-fu commented 2 years ago

Seen this, will try to find some time next week to address this. Meanwhile could you please prepare code for an MWE?

himcraft commented 2 years ago

Thanks for your reply. Looking forward to seeing the issue gets solved.

The MWE is the following, I omitted the REPL prompts.

# Using the function TetGen.voronoi() provided in the doc.
# The points are the vertices of a cube and randomly distribute a few points within the cube.
# However the function returns some triangles represented by those known input points, which are more like Delaunay tetrahedralizations rather than Voronoi diagrams.
using TetGen,GeometryBasics
points=Point.(vcat(rand(10),0,0,0,0,1,1,1,1),vcat(rand(10),0,0,1,1,0,0,1,1),vcat(rand(10),0,1,0,1,0,1,0,1)) 
@show TetGen.voronoi(points);
# ---------------
# The following codes mimic the behavior of the function TetGen.voronoi()
# It says "writing Voronoi vertices/edges/faces/cells. But I cannot see them represented in the result, in this case, vo.
using TetGen:JLTetGenIO
vo=tetrahedralize(JLTetGenIO(points),"v")
@show fieldnames(typeof(vo));

I do not know if it helps, If you need more information, I am willing to provide it.

j-fu commented 1 year ago

Hi, thanks - I checked the issue.

Currently, we don't pass the Voronoi cell information to the C wrapper called by Julia. So there currently is no way to access this information from Julia.

This needs an update for TetGen_jll.jll which will have to wait a bit as I am quite busy at work for the next 2 weeks. Once this is done, may be @SimonDanisch can help with updating the JLTetGenIO struct.

himcraft commented 1 year ago

Thanks for the update! I managed to use the original C++ TetGen and pass data through files to other Julia scripts for an urgent need. My problem is solved.