JuliaGeometry/DelaunayTriangulation.jl

Delete_point

Closed this issue · 3 comments

@DanielVandH thanks for putting this package together. In the below I attempt to create a crossed square mesh (4 corners and a central point). I then wanted to test the removal of points from this set using delete_point!. Perhaps I am using it wrong, but this function does not seem to work properly. In the below example I use delete_point!(TR,5), which seems to work. However, the 5th point is the only point I can remove, any other point, e.g. 1:4 will produce this error: ERROR: BoundsError: attempt to access 5-element Vector{Point3{Float64}} at index [0].

Any help would be appreciated.

using GeometryBasics
using DelaunayTriangulation

# Create a crossed square grid (4 corners and 1 central point)
V = reshape([ Point{3,Float64}(i,j,0.0) for i in -1:2:1, j in -1:2:1],4)
push!(V,Point{3,Float64}(0.0,0.0,0.0))

# Delaunay triangulation
TR = triangulate(V)

# Get faces 
F1 =  [TriangleFace{Int64}(tr) for tr in TR.triangles]
println(F1)

# Remove a selected point
delete_point!(TR,5)

F2 =  [TriangleFace{Int64}(tr) for tr in TR.triangles]
println(F2)

For context, I am removing these red points (which are 3 or 4 connected) in this triangulation:
Screenshot from 2024-04-23 10-06-43

To obtain the following:
Screenshot from 2024-04-23 10-05-53

Currently I just repeat your Delaunay method on the set of reduced points. However I was wondering if the delete_point! approach is more efficient.

Thanks.

In your example, what version of DelaunayTriangulation are you on? Here's what I get for deleting 1:

julia> begin
           using GeometryBasics
           using DelaunayTriangulation

           # Create a crossed square grid (4 corners and 1 central point)
           V = reshape([Point{3,Float64}(i, j, 0.0) for i in -1:2:1, j in -1:2:1], 4)
           push!(V, Point{3,Float64}(0.0, 0.0, 0.0))

           # Delaunay triangulation
           TR = triangulate(V)

           # Get faces
           F1 = [TriangleFace{Int64}(tr) for tr in TR.triangles]
           println(F1)

           # Remove a selected point
           delete_point!(TR, 1)

           F2 = [TriangleFace{Int64}(tr) for tr in TR.triangles]
           println(F2)
       end
TriangleFace{Int64}[TriangleFace(3, -1, 1), TriangleFace(3, 1, 5), TriangleFace(4, 5, 2), TriangleFace(3, 5, 4), TriangleFace(4, 2, -1), TriangleFace(5, 1, 2), TriangleFace(2, 1, -1), TriangleFace(3, 4, -1)]
ERROR: Tried to delete the vertex 1 which forms part of the boundary of the triangulation. This is not allowed - only interior vertices not adjoining a segment may be deleted.
Stacktrace:
 [1] check_delete_point_args(tri::Triangulation{…}, vertex::Int64, S::Vector{…})
   @ DelaunayTriangulation c:\Users\User\.julia\dev\DelaunayTriangulation\src\algorithms\triangulation\basic_operations\delete_point.jl:87
 [2] delete_point!(tri::Triangulation{…}, vertex::Int64; store_event_history::Val{…}, event_history::Nothing, rng::Random.TaskLocalRNG)
   @ DelaunayTriangulation c:\Users\User\.julia\dev\DelaunayTriangulation\src\algorithms\triangulation\basic_operations\delete_point.jl:143
 [3] delete_point!(tri::Triangulation{…}, vertex::Int64)
   @ DelaunayTriangulation c:\Users\User\.julia\dev\DelaunayTriangulation\src\algorithms\triangulation\basic_operations\delete_point.jl:135
 [4] top-level scope
   @ c:\Users\User\.julia\dev\DelaunayTriangulation\test\triangulation\constrained.jl:1121
Some type information was truncated. Use `show(err)` to see complete types.

Going to close this due to lack of activity and since it doesn't seem reproducible. Feel free to open if needed.