Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for GeometryBasics v0.5 #42

Merged
merged 11 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
- '1.9' # Replace this with the minimum Julia version that your package supports. E.g. if your package requires Julia 1.5 or higher, change this to '1.5'.
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
- 'nightly'
os:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
*.jl.mem
.repl_history.jl
.DS_Store
/Manifest.toml
/Manifest*.toml
docs/Manifest.toml
docs/build
QUARRY
quarry
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Changelog

All notable changes to this project since V1.0 will be documented in this file.

## [2.0]
- Allow for GeometryBasics v0.5 along with 0.4
- Breaking: with GeometryBasics v0.5, a MetaMesh has
to be provided as input for Tetrahedralize.
The RawTetGenIO based API is not affected. Users who
rely on the RawTetGenIO based API can use `TetGen="1,2"`
in their `[compat]` section.
- Breaking: remove deprecated `tetunsuitable`. Use `tetunsuitable!` instead

## [1.5.1] - 2024-02-27

- Fix version check for `MemoryRef`
- Add ci for apple silicon

## [1.5.0] - 2023-11-15

- Fix imports/named using from GeometryBasics
- add juliaformatter
- @deprecate tetunsuitable tetunsuitable!
- Pass pointer to unsafe_convert
- Test for type of return value of unsuitable function
- fix for 1.11 memory handling

## [1.4.0] - 2022-06-02
- allow to input stl files

## [1.3.0] - 2021-10-05

- Switch Julia package to MIT license (after the FFTW model).
- Remove checking of error catching from tests due to problems on windows.
- Point3f0->Point3f (GeometryBasics version)
- Add stl loading functionality
- Switch Julia package to MIT license (after the FFTW model).

## [1.2.1] - 2021-09-13
- allow for GeometryBasics 0.4

## [1.2.0] - 2021-05-26

- Added example for RawTetGenIO and holes
- Created holes for tetrahedralize(::Mesh, ...)
- Added test example for mesh API with holes

## [1.1.1] - 2021-01-02

- Bump version compat for StaticArrays

## [1.1.0] - 2020-12-22

- Thank you travis and bye bye
- Update of upstream patch version of TetGen to "August 18, 2018".
- Formally this still appears to be 1.5.1 , and it is manifest in TetGen_jll 1.5.1+1
- Catch errors thrown by TetGen in a rc variable, throw julia error if rc!=0
- Handle unsuitable callback to allow local refinement.

## [1.0.0] - 2020-11-30
- Dependency on artifacts
- Refactoring. API of API.jl stays the same.
- Provide array based API. and RawTetGenIO
14 changes: 5 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TetGen"
uuid = "c5d3f3f7-f850-59f6-8a2e-ffc6dc1317ea"
authors = ["SimonDanisch <sdanisch@gmail.com>", "Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de"]
version = "1.5.1"
version = "2.0.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand All @@ -13,13 +13,9 @@ TetGen_jll = "b47fdcd6-d2c1-58e9-bbba-c1cee8d8c179"

[compat]
DocStringExtensions = "0.8,0.9"
GeometryBasics = "0.2, 0.3, 0.4"
GeometryBasics = "0.4, 0.5"
LinearAlgebra = "1"
Printf = "1"
StaticArrays = "1"
TetGen_jll = "1.5.3"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
julia = "1.9"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/JuliaGeometry/TetGen.jl/blob/master/LICENSE)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaGeometry.github.io/TetGen.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaGeometry.github.io/TetGen.jl/dev)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)

The `TetGen.jl` package is a Julia wrapper for the C++ project [TetGen](https://wias-berlin.de/software/index.jsp?id=TetGen&lang=1). This wrapper enables TetGen based tetrahedral meshing, and (constrained) 3D Delaunay and Voronoi tesselation.

Expand Down Expand Up @@ -63,7 +64,7 @@ Plotted with Makie:
```julia
using TetGen
let
tetunsuitable() do pa,pb,pc,pd
tetunsuitable!() do pa,pb,pc,pd
vol=det(hcat(pb-pa,pc-pa,pd-pa))/6
center=0.25*(pa+pb+pc+pd)-[0.5,0.5,0.5]
vol> 0.05*norm(center)^2.5
Expand Down
1 change: 0 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function make_all()
makedocs(;
sitename = "TetGen.jl",
modules = [TetGen],
warnonly = true,
clean = false,
doctest = false,
authors = "Simon Danisch, Juergen Fuhrmann",
Expand Down
13 changes: 13 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ tetrahedralizations, constrained Delaunay tetrahedralizations, and
quality tetrahedral meshes. TetGen.jl provides a Julia interface to
TetGen.


```@docs
TetGen
```


## Mesh based API
This API uses instances of types from [GeometryBasics.jl](https://github.com/JuliaGeometry/GeometryBasics.jl)
to describe input and output of TetGen.
Expand All @@ -14,6 +20,8 @@ Modules = [TetGen]
Pages = ["api.jl"]
```



## Raw API
This API is closer to TetGen's C++ API in the sense that
input and output are described using arrays of integers
Expand All @@ -40,3 +48,8 @@ tetunsuitable!
Link to preprint [here](http://doi.org/10.20347/WIAS.PREPRINT.1762).


## Internal API
```@autodocs
Modules = [TetGen]
Pages = ["meshes.jl", "jltetgenio.jl", "cpptetgenio.jl"]
```
25 changes: 14 additions & 11 deletions src/TetGen.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
module TetGen
using DocStringExtensions
using TetGen_jll
"""
TetGen

$(read(joinpath(@__DIR__,"..","README.md"),String))
"""
module TetGen
using DocStringExtensions: DocStringExtensions, SIGNATURES, TYPEDEF,
TYPEDFIELDS, TYPEDSIGNATURES
import GeometryBasics
using GeometryBasics: Polygon, MultiPolygon, Point, Point3f, LineFace, Polytope, Line,
Simplex, connect, Triangle, NSimplex, Tetrahedron,
TupleView, TriangleFace, SimplexFace, LineString, Mesh, TetrahedronP, TriangleP,
NgonFace, Ngon, faces, coordinates, metafree, meta, faces

using Printf
using GeometryBasics: Point, Point3f, LineFace, Polytope, Triangle, NSimplex,
TriangleFace, SimplexFace, Mesh, Tetrahedron, Triangle,
NgonFace, faces, coordinates

using StaticArrays
using Printf: Printf
using StaticArrays: StaticArrays, SVector
using TetGen_jll: TetGen_jll, libtet

include("cpptetgenio.jl")
include("jltetgenio.jl")
Expand All @@ -19,7 +22,7 @@ include("meshes.jl")
include("api.jl")

export tetrahedralize
export tetunsuitable!, tetunsuitable
export tetunsuitable!
export TetGenError
export RawTetGenIO, facetlist!, RawFacet
export numberofpoints, numberoftetrahedra, numberoftrifaces, numberofedges
Expand Down
44 changes: 28 additions & 16 deletions src/api.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
"""
$(SIGNATURES)
voronoi(points::Vector{Point{3, T}}) where {T <: AbstractFloat}

Create voronoi diagram of point set.

Returns a mesh of triangles.
"""
function voronoi(points::Vector{Point{3, T}}) where {T <: AbstractFloat}
result = tetrahedralize(JLTetGenIO(points), "Qw")
Mesh{Triangle}(result)
return Mesh{Triangle}(result)
end

"""
$(SIGNATURES)

Tetrahedralize a mesh of polygons with optional facet markers.
Returns a mesh of tetrahdra.
Returns a mesh of tetrahdra.

With `GeometryBasics` version 0.4, the input mesh has to be a `GeometryBasics.Mesh` with
possible metadata. With `GeometryBasics` version 0.5, the input mesh has to be a `GeometryBasics.MetaMesh`.

Default command is "Qp", creating the Delaunay
triangulation of the point set. See the list of
possible flags in the documentation of [`tetrahedralize(::RawTetGenIO, flags)`](@ref).
"""
function TetGen.tetrahedralize(mesh::Mesh{3, Float64, <:TetGen.Ngon}, command = "Qp";
function TetGen.tetrahedralize(mesh, command = "Qp";
marker = :markers, holes = Point{3, Float64}[])
f = faces(mesh)
kw_args = Any[:facets => metafree(f), :holes => holes]
if pkgversion(GeometryBasics) < v"0.5"
kw_args = Any[:facets => GeometryBasics.metafree(f), :holes => holes]
else
kw_args = Any[:facets => f, :holes => holes]
end
if hasproperty(f, marker)
push!(kw_args, :facetmarkers => getproperty(f, marker))
end
Expand All @@ -28,14 +39,15 @@ function TetGen.tetrahedralize(mesh::Mesh{3, Float64, <:TetGen.Ngon}, command =
return Mesh{Tetrahedron}(result)
end

"""
$(SIGNATURES)

Tetrahedralize a domain described by a mesh of triangles.
Returns a mesh of tetrahdra.
"""
function TetGen.tetrahedralize(mesh::Mesh{3, Float64, <:TetGen.Triangle}, command = "Qp")
tio = JLTetGenIO(coordinates(mesh); facets = faces(mesh))
result = tetrahedralize(tio, command)
Mesh{Tetrahedron}(result)
end
# JF: probably this case is included in the case above
# """
# $(SIGNATURES)
#
# Tetrahedralize a domain described by a mesh of triangles.
# Returns a mesh of tetrahdra.
# """
# function TetGen.tetrahedralize(mesh, command = "Qp")
# tio = JLTetGenIO(coordinates(mesh); facets = faces(mesh))
# result = tetrahedralize(tio, command)
# return Mesh{Tetrahedron}(result)
# end
2 changes: 0 additions & 2 deletions src/cpptetgenio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,3 @@ function tetunsuitable!(unsuitable::Function; check_signature = true)
c_wrap_tetunsuitable = @cfunction(jl_wrap_tetunsuitable, Cint, (Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}))
ccall((:tetunsuitable_callback, libtet), Cvoid, (Ptr{Cvoid},), c_wrap_tetunsuitable)
end

@deprecate tetunsuitable(unsuitable::Function; kwargs...) tetunsuitable!(unsuitable::Function; kwargs...)
8 changes: 4 additions & 4 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function GeometryBasics.Mesh{P}(x::JLTetGenIO{T}) where {P <: Polytope{N, T} whe
Mesh{Polytope(P, Point{3, T})}(x)
end

function GeometryBasics.Mesh{TetrahedronP{ET, P}}(x::JLTetGenIO) where {ET, P}
Mesh(convert(Vector{P}, x.points), x.tetrahedra)
function GeometryBasics.Mesh{Tetrahedron{ET}}(x::JLTetGenIO) where {ET}
Mesh(x.points, x.tetrahedra)
end

function GeometryBasics.Mesh{TriangleP{3, ET, P}}(x::JLTetGenIO) where {ET, P}
Mesh(convert(Vector{P}, x.points), x.trifaces)
function GeometryBasics.Mesh{Triangle{3, ET}}(x::JLTetGenIO) where {ET}
Mesh(x.points, x.trifaces)
end
14 changes: 14 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.8"
ExplicitImports = "1.10"
GeometryBasics = "0.4, 0.5"
LinearAlgebra = "1"
Printf = "1"
51 changes: 41 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using TetGen
using TetGen: JLPolygon, JLFacet, Point
using GeometryBasics
using GeometryBasics: Mesh, Triangle, Tetrahedron, TriangleFace, QuadFace,
PointMeta, NgonFaceMeta, meta, faces, metafree
using GeometryBasics.StructArrays
using ExplicitImports, Aqua
using TetGen: TetGen, JLPolygon, JLFacet, Point, tetrahedralize
using GeometryBasics: GeometryBasics
using GeometryBasics: Mesh, Triangle, Tetrahedron, TriangleFace, QuadFace, faces
using Test

@testset "mesh based API" begin
Expand All @@ -22,11 +20,20 @@ using Test

markers = Cint[-1, -2, 0, 0, 0, 0]
# attach some additional information to our faces!
mesh = Mesh(points, meta(facets; markers = markers))
if pkgversion(GeometryBasics) < v"0.5"
mesh = Mesh(points, GeometryBasics.meta(facets; markers))
else
mesh = GeometryBasics.MetaMesh(points, facets; markers)
end
result = tetrahedralize(mesh)
@test result isa Mesh

# Make it similar to the README example
if pkgversion(GeometryBasics) < v"0.5"
mesh = Mesh(points, facets)
else
mesh = GeometryBasics.MetaMesh(points, facets)
end
result = tetrahedralize(mesh, "vpq1.414a0.1")
@test result isa Mesh

Expand All @@ -44,7 +51,11 @@ using Test
[1, 3, 4],
[2, 3, 4]]

tetmesh = Mesh(tetpoints, tetfacets)
if pkgversion(GeometryBasics) < v"0.5"
tetmesh = Mesh(tetpoints, tetfacets)
else
tetmesh = GeometryBasics.MetaMesh(tetpoints, tetfacets)
end
result = tetrahedralize(tetmesh, "pQqAa0.01")
@test result isa Mesh

Expand Down Expand Up @@ -81,8 +92,13 @@ using Test
[4, 8, 5, 1] .+ 8]

markers = ones(Cint, 12)
mesh = Mesh(points, meta(facets; markers = markers))
resultx = tetrahedralize(mesh, "pQqAa1.0"; holes = [Point{3, Float64}(0, 0, 0)])

if pkgversion(GeometryBasics) < v"0.5"
mesh = Mesh(points, GeometryBasics.meta(facets; markers = markers))
else
mesh = GeometryBasics.MetaMesh(points, facets; markers = markers)
end
result = tetrahedralize(mesh, "pQqAa1.0"; holes = [Point{3, Float64}(0, 0, 0)])
@test result isa Mesh

# s = Sphere{Float64}(Point(0.0, 0.0, 0.0), 2.0)
Expand Down Expand Up @@ -262,3 +278,18 @@ end
end
@test test_error_output()
end

@testset "ExplicitImports" begin
@test ExplicitImports.check_no_implicit_imports(TetGen) === nothing
@test ExplicitImports.check_no_stale_explicit_imports(TetGen) === nothing
end

@testset "Aqua" begin
Aqua.test_all(TetGen)
end

if isdefined(Docs, :undocumented_names)
@testset "UndocumentedNames" begin
@test isempty(Docs.undocumented_names(TetGen))
end
end