Skip to content

Commit b094882

Browse files
Added ability to create a Triangulation with only points and triangles as input (#192)
Co-authored-by: Daniel VandenHeuvel <[email protected]>
1 parent f7485ec commit b094882

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.5.0
4+
5+
- Introduced the ability to reconstruct unconstrained triangulations from an existing set of points and triangles using `Triangulation(points, triangles)`. See [#192](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/192)
6+
37
## 1.4.0
48

59
- Updated to AdaptivePredicates.jl v1.2, now allowing caches to be passed to the predicates involving `incircle` and `orient3`. These are only useful when using the `AdaptiveKernel()` kernel. Outside of triangulating, these caches are not passed by default, but can be provided. The functions `get_incircle_cache` and `get_orient3_cache` can be used for this purpose on a triangulation (without a triangulation, refer to AdaptivePredicate.jl's `incircleadapt_cache` and `orient3adapt_cache`). See [#185](https://github.com/JuliaGeometry/DelaunayTriangulation.jl/pull/185).

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DelaunayTriangulation"
22
uuid = "927a84f5-c5f4-47a5-9785-b46e178433df"
33
authors = ["Daniel VandenHeuvel <[email protected]>"]
4-
version = "1.4.2"
4+
version = "1.5.0"
55

66
[deps]
77
AdaptivePredicates = "35492f91-a3bd-45ad-95db-fcad7dcfedb7"

src/data_structures/triangulation/triangulation.jl

+48-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ Returns the `Triangulation` corresponding to the triangulation of `points` with
488488
489489
# Arguments
490490
- `points`: The points that the triangulation is of.
491-
- `triangles`: The triangles of the triangulation. These should be given in counter-clockwise order, with vertices corresponding to `points`. These should not include any ghost triangles.
491+
- `triangles`: The triangles of the triangulation. These should be given in counter-clockwise order, with vertices corresponding to `points`. Ghost triangles should not be included (and are ignored if they are).
492492
- `boundary_nodes`: The boundary nodes of the triangulation. These should match the specification given in the documentation or in [`check_args`](@ref).
493493
494494
# Keyword Arguments
@@ -520,6 +520,52 @@ Returns the `Triangulation` corresponding to the triangulation of `points` with
520520
return build_triangulation_from_data!(tri, triangles, _bn, delete_ghosts, predicates)
521521
end
522522

523+
"""
524+
Triangulation(points, triangles; kwargs...) -> Triangulation
525+
526+
Returns the unconstrained `Triangulation` corresponding to the triangulation of `points` with `triangles`.
527+
528+
!!! note "Valid boundary"
529+
530+
This constructor uses the [`convex_hull`](@ref) of `points` to determine the triangulation's boundary.
531+
If the set of triangles does not form a valid unconstrained triangulation, then this constructor may not
532+
return a valid triangulation. Similarly, if there is a point in `points` that is not a vertex of some
533+
triangle, but is a vertex of the convex hull, the triangulation will not be valid.
534+
535+
# Arguments
536+
- `points`: The points that the triangulation is of. There should not be any points not referenced in `triangles`.
537+
- `triangles`: The triangles of the triangulation. These should be given in counter-clockwise order, with vertices corresponding to `points`. Ghost triangles should not be included (and are ignored if they are).
538+
539+
# Keyword Arguments
540+
- `predicates::AbstractPredicateKernel=AdaptiveKernel()`: Method to use for computing predicates. Can be one of [`FastKernel`](@ref), [`ExactKernel`](@ref), and [`AdaptiveKernel`](@ref). See the documentation for a further discussion of these methods.
541+
- `IntegerType=Int`: The integer type to use for the triangulation. This is used for representing vertices.
542+
- `EdgeType=isnothing(segments) ? NTuple{2,IntegerType} : (edge_type ∘ typeof)(segments)`: The edge type to use for the triangulation.
543+
- `TriangleType=NTuple{3,IntegerType}`: The triangle type to use for the triangulation.
544+
- `EdgesType=isnothing(segments) ? Set{EdgeType} : typeof(segments)`: The type to use for storing the edges of the triangulation.
545+
- `TrianglesType=Set{TriangleType}`: The type to use for storing the triangles of the triangulation.
546+
- `weights=ZeroWeight()`: The weights associated with the triangulation.
547+
- `delete_ghosts=false`: Whether to delete the ghost triangles after the triangulation is computed. This is done using [`delete_ghost_triangles!`](@ref).
548+
549+
# Output
550+
- `tri`: The [`Triangulation`](@ref).
551+
"""
552+
@inline function Triangulation(
553+
points::P, triangles::T;
554+
IntegerType::Type{I}=Int,
555+
EdgeType::Type{E}=NTuple{2,IntegerType},
556+
TriangleType::Type{V}=NTuple{3,IntegerType},
557+
EdgesType::Type{Es}=Set{EdgeType},
558+
TrianglesType::Type{Ts}=Set{TriangleType},
559+
weights=ZeroWeight(),
560+
delete_ghosts=false,
561+
predicates::AbstractPredicateKernel=AdaptiveKernel(),
562+
) where {P,T,I,E,V,Es,Ts}
563+
bn = get_vertices(convex_hull(points; predicates, IntegerType))
564+
tri = Triangulation(points, triangles, bn; IntegerType, EdgeType, TriangleType, EdgesType, TrianglesType, weights, delete_ghosts, predicates)
565+
unlock_convex_hull!(tri)
566+
return tri
567+
end
568+
523569
"""
524570
build_triangulation_from_data!(tri::Triangulation, triangles, boundary_nodes, delete_ghosts, predicates::AbstractPredicateKernel=AdaptiveKernel())
525571
@@ -540,6 +586,7 @@ See the documentation for more information about these choices.
540586
graph = get_graph(tri)
541587
tris = get_triangles(tri)
542588
for τ in each_triangle(triangles)
589+
is_ghost_triangle(τ) && continue
543590
add_triangle!(adj, τ)
544591
add_triangle!(adj2v, τ)
545592
add_triangle!(graph, τ)

test/data_structures/triangulation.jl

+10
Original file line numberDiff line numberDiff line change
@@ -1475,3 +1475,13 @@ end
14751475
end
14761476
end
14771477
end
1478+
1479+
@testset "Constructor with only points and triangles" begin
1480+
points = [(0.0, 0.0), (0.87, 0.0), (1.0006, 0.7766), (0.0, 1.0), (0.5, 0.5)]
1481+
tri1 = triangulate(points)
1482+
triangles = tri1.triangles
1483+
tri2 = DT.Triangulation(points, triangles)
1484+
@test validate_triangulation(tri2)
1485+
@test tri1 == tri2
1486+
@test !DT.has_boundary_nodes(tri2)
1487+
end

test/triangulation/triangulate.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ end
3636
@test validate_triangulation(tri; predicates = PT())
3737
end
3838
end
39-
end
39+
end

0 commit comments

Comments
 (0)