Skip to content

Commit

Permalink
cleanup docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Jun 23, 2024
1 parent 3612c46 commit 70069be
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 137 deletions.
136 changes: 9 additions & 127 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Given 3D levelset data such as a CT scan, we can do:

```
```julia
using Meshing

A = rand(50,50,50) # 3D Matrix
Expand All @@ -14,43 +14,17 @@ points,faces = isosurface(A)

An iso-level is specified within the algorithm specification as follows:

```
```julia
using Meshing

A = rand(50,50,50) # 3D Matrix

points,faces = isosurface(A, MarchingCubes(iso=1))
```

Alternatively, we can use the `isosurface` API to sample a function, avoiding allocations:

## Quick Start - GeometryBasics

Meshing is well-integrated with [GeometryBasics.jl](https://github.com/JuliaGeometry/GeometryBasics.jl) by extending the [mesh constructors](http://juliageometry.github.io/GeometryBasics.jl/latest/types.html#Meshes-1) for convience.

The algorithms operate on a `Function`, `AbstractArray`, or `SignedDistanceField` and output a concrete `AbstractMesh`.
For example, we can use the GeometryBasics API as follows, using `Rect` to specify the bounds:

```
using Meshing
using GeometryBasics
using LinearAlgebra: dot, norm
using FileIO
# Mesh an equation of sphere in the Axis-Aligned Bounding box starting
# at -1,-1,-1 and widths of 2,2,2 using Marching Cubes
m = GLNormalMesh(Rect(Vec(-1,-1,-1.), Vec(2,2,2.)), MarchingCubes()) do v
sqrt(sum(dot(v,v))) - 1
end
# save the Sphere as a PLY file
save("sphere.ply",m)
```

For a full listing of concrete `AbstractMesh` types see [GeometryBasics.jl mesh documentation](http://juliageometry.github.io/GeometryBasics.jl/latest/types.html#Meshes-1).

Alternatively, we can use the `isosurface` API to sample a function:

```
```julia
using Meshing
using LinearAlgebra
using StaticArrays
Expand All @@ -66,60 +40,19 @@ points, faces = isosurface(MarchingTetrahedra(), origin=SVector(-1,-1,-1.), widt
end
```

## Quick Start - GeometryTypes


!!! warning

GeometryTypes is in the process of being deprecated across the Julia ecosystem.
GeometryBasics is the recommended replacement.


Meshing is well-integrated with [GeometryTypes.jl](https://github.com/JuliaGeometry/GeometryTypes.jl) by extending the [mesh constructors](http://juliageometry.github.io/GeometryTypes.jl/latest/types.html#Meshes-1) for convience.

The algorithms operate on a `Function`, `AbstractArray`, or `SignedDistanceField` and output a concrete `AbstractMesh`.
For example, we can use the GeometryTypes API as follows, using `HyperRectangle` to specify the bounds:

```
using Meshing
using GeometryTypes
using LinearAlgebra: dot, norm
using FileIO
# Mesh an equation of sphere in the Axis-Aligned Bounding box starting
# at -1,-1,-1 and widths of 2,2,2 using Marching Cubes
m = GLNormalMesh(HyperRectangle(Vec(-1,-1,-1.), Vec(2,2,2.)), MarchingCubes()) do v
sqrt(sum(dot(v,v))) - 1
end
# save the Sphere as a PLY file
save("sphere.ply",m)
```

For a full listing of concrete `AbstractMesh` types see [GeometryTypes.jl mesh documentation](http://juliageometry.github.io/GeometryTypes.jl/latest/types.html#Meshes-1).

Alternatively, we can use the `isosurface` API to sample a function:

```
using Meshing
using LinearAlgebra
using StaticArrays
points, faces = isosurface(origin=SVector(-1,-1,-1.), widths = SVector(2,2,2.), samples = (40,40,40)) do v
sqrt(sum(dot(v,v))) - 1
end
## Isosurface

# by default MarchingCubes() is used, but we may specify a different algorithm as follows
`isosurface` is the common and generic API for isosurface extraction with any type of abstract vector/vertex/face type.

points, faces = isosurface(MarchingTetrahedra(), origin=SVector(-1,-1,-1.), widths = SVector(2,2,2.), samples = (40,40,40)) do v
sqrt(sum(dot(v,v))) - 1
end
```@docs
isosurface
```


## Meshing Algorithms

Three meshing algorithms exist:

* `MarchingCubes()`
* `MarchingTetrahedra()`
* `NaiveSurfaceNets()`
Expand Down Expand Up @@ -150,54 +83,3 @@ MarchingTetrahedra
NaiveSurfaceNets
Meshing.AbstractMeshingAlgorithm
```

## Isosurface

`isosurface` is the common and generic API for isosurface extraction with any type of abstract vector/vertex/face type.

```@docs
isosurface
```

## GeometryBasics

Meshing extends the mesh types in GeometryBasics for convenience and use with visualization tools such as Makie and MeshCat.
Any instance of a `Mesh` may be created as follows:

```
mesh(df::SignedDistanceField{3,ST,FT}, method::AbstractMeshingAlgorithm; pointtype=nothing, facetype=nothing) where {ST, FT}
mesh(f::Function, h::Rect, samples::NTuple{3,T}, method::AbstractMeshingAlgorithm; pointtype=nothing, facetype=nothing) where {T <: Integer}
mesh(f::Function, h::Rect, method::AbstractMeshingAlgorithm; pointtype=nothing, facetype=nothing, samples::NTuple{3,T}=_DEFAULT_SAMPLES) where {T <: Integer}
mesh(volume::AbstractArray{T, 3}, method::AbstractMeshingAlgorithm; pointtype=nothing, facetype=nothing, vargs...) where {T}
```

With the GeometryBasics API, the bounding box is specified by a `Rect`, or keyword specified `origin` and `widths`.

Some notes on pointtype and facetype. They can be used to create a mesh with the desired point & face types.
If they're left at nothing, the element type best matching the method and signed distancefield is used.
Both the element type of the volume, element type of the `vertextype`, and type of `iso` in the `AbstractMeshingAlgorithm`
are all promoted. This also allows the use of auto differentiation tools on the isosurface construction.

## GeometryTypes

Meshing extends the mesh types in GeometryTypes for convience and use with visualization tools such as Makie and MeshCat.
Any instance of an `AbstractMesh` may be called with arguments as follows:

```
(::Type{MT})(df::SignedDistanceField{3,ST,FT}, method::AbstractMeshingAlgorithm)::MT where {MT <: AbstractMesh, ST, FT}
(::Type{MT})(f::Function, h::HyperRectangle, samples::NTuple{3,T}, method::AbstractMeshingAlgorithm)::MT where {MT <: AbstractMesh, T <: Integer}
(::Type{MT})(f::Function, h::HyperRectangle, method::AbstractMeshingAlgorithm; samples::NTuple{3,T}=_DEFAULT_SAMPLES)::MT where {MT <: AbstractMesh, T <: Integer}
(::Type{MT})(volume::AbstractArray{T, 3}, method::AbstractMeshingAlgorithm; vargs...) where {MT <: AbstractMesh, T}
```

With the GeometryTypes API, the bounding box is specified by a `HyperRectangle`, or keyword specified `origin` and `widths`.

Some notes on VertType and FaceType. Since it is common to simply call `HomogenousMesh` or `GLNormalMesh`, we have added promotion and default type logic
to the GeometryTypes API to improve type stability and therefore performance.
Both the element type of the volume, element type of the `vertextype`, and type of `iso` in the `AbstractMeshingAlgorithm`
are all promoted. This also allows the use of auto differentiation tools on the isosurface construction.

If for example a `HomogenousMesh` is requested, the default types will be `Point{3,Float64}` and `Face{3,Int}`
Similarly, a `GLNormalMesh` specifies `Point{3, Float32}` and `Face{3, OffsetInteger{-1,UIn32}}` so these these types will be used.

See: `isosurface` for the generic API.
42 changes: 39 additions & 3 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Examples


# NRRD Data
## NRRD Data

The file for this example can be found here: [http://www.slicer.org/slicerWiki/images/0/00/CTA-cardio.nrrd](http://www.slicer.org/slicerWiki/images/0/00/CTA-cardio.nrrd)

Expand Down Expand Up @@ -35,7 +34,7 @@ save("ctacardio_mc.ply", mc)

![cta cardio](./img/ctacardio.png)

# Functions
## Functions

```julia
using Meshing
Expand All @@ -59,3 +58,40 @@ Makie.mesh(gy_mesh, color=[norm(v) for v in coordinates(gy_mesh)])
```

![gyroid](./img/gyroid.png)


```julia
using Meshing
using GeometryBasics
using LinearAlgebra: dot, norm
using FileIO

# Mesh an equation of sphere in the Axis-Aligned Bounding box starting
# at -1,-1,-1 and widths of 2,2,2 using Marching Cubes
m = GLNormalMesh(Rect(Vec(-1,-1,-1.), Vec(2,2,2.)), MarchingCubes()) do v
sqrt(sum(dot(v,v))) - 1
end

# save the Sphere as a PLY file
save("sphere.ply",m)
```

For a full listing of concrete `AbstractMesh` types see [GeometryBasics.jl mesh documentation](http://juliageometry.github.io/GeometryBasics.jl/latest/types.html#Meshes-1).

Alternatively, we can use the `isosurface` API to sample a function:

```julia
using Meshing
using LinearAlgebra
using StaticArrays

points, faces = isosurface(origin=SVector(-1,-1,-1.), widths = SVector(2,2,2.), samples = (40,40,40)) do v
sqrt(sum(dot(v,v))) - 1
end

# by default MarchingCubes() is used, but we may specify a different algorithm as follows

points, faces = isosurface(MarchingTetrahedra(), origin=SVector(-1,-1,-1.), widths = SVector(2,2,2.), samples = (40,40,40)) do v
sqrt(sum(dot(v,v))) - 1
end
```
10 changes: 6 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This package provides a suite of meshing (isosurface extraction) algorithms.

Algorithms included:

* [Marching Tetrahedra](https://en.wikipedia.org/wiki/Marching_tetrahedra)
* [Marching Cubes](https://en.wikipedia.org/wiki/Marching_cubes)
* [Naive Surface Nets](https://0fps.net/2012/07/12/smooth-voxel-terrain-part-2/)
Expand All @@ -13,7 +14,8 @@ Isosurface extraction is a common technique to visualize and analyze scalar fiel
It takes scalar data that is structured in grids and converts this into a series of points and faces suitable for 3D visualization, GPU computing, 3D Printing, or other analyses.

There are several applications for these techniques such as:
- Medical Imaging of CT and MRI data
- Visualization of Functions
- Solid Modeling
- Terrain Generation

* Medical Imaging of CT and MRI data
* Visualization of Functions
* Solid Modeling
* Terrain Generation
1 change: 0 additions & 1 deletion docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
The internals of Meshing have been optimized for performance and to be generic.
This is some brief documentation on the basic internal functions.


## Common

```@docs
Expand Down
2 changes: 0 additions & 2 deletions src/Meshing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Meshing

using StaticArrays


"""
_DEFAULT_SAMPLES = (24,24,24)
Expand All @@ -17,7 +16,6 @@ include("marching_cubes.jl")
include("surface_nets.jl")
include("roots.jl")
include("adaptive.jl")
include("marching_tetrahedra_adaptive.jl")

export isosurface,
MarchingCubes,
Expand Down
Empty file.

0 comments on commit 70069be

Please sign in to comment.