Transforms
Geometric (e.g. coordinates) transforms are implemented according to the TransformsBase.jl interface. Please read their documentation for more details.
Meshes.GeometricTransform
— TypeGeometricTransform
A method to transform the geometry (e.g. coordinates) of objects. See https://en.wikipedia.org/wiki/Geometric_transformation.
Meshes.CoordinateTransform
— TypeCoordinateTransform
A method to transform the coordinates of objects. See https://en.wikipedia.org/wiki/Listofcommoncoordinatetransformations.
Rotate
Meshes.Rotate
— TypeRotate(rot)
Rotate geometry or mesh with rotation rot
from Rotations.jl.
Examples
Rotate(one(RotXYZ{Float64})) # Generate identity rotation
Rotate(AngleAxis(0.2, 1.0, 0.0, 0.0)) # Rotate 0.2 radians around X-axis
Rotate(rand(QuatRotation{Float64})) # Generate random rotation
using Rotations: Angle2d
grid = CartesianGrid(10, 10)
mesh = grid |> Rotate(Angle2d(π/4))
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], grid)
viz(fig[1,2], mesh)
fig
Translate
Meshes.Translate
— TypeTranslate(o₁, o₂, ...)
Translate coordinates of geometry or mesh by given offsets o₁, o₂, ...
.
grid = CartesianGrid(10, 10)
mesh = grid |> Translate(10., 20.)
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], grid)
viz(fig[1,2], mesh)
fig
Affine
Meshes.Affine
— TypeAffine(A, b)
Affine transform Ax + b
with matrix A
and vector b
.
Examples
Affine(AngleAxis(0.2, 1.0, 0.0, 0.0), [-2, 2, 2])
Affine(Angle2d(π / 2), SVector(2, -2))
Affine([0 -1; 1 0], [-2, 2])
grid = CartesianGrid(10, 10)
mesh = grid |> Affine(Angle2d(π/4), [10., 20.])
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], grid)
viz(fig[1,2], mesh)
fig
Scale
Meshes.Scale
— TypeScale(s₁, s₂, ...)
Scale geometry or domain with strictly positive scaling factors s₁, s₂, ...
.
Examples
Scale(1.0, 2.0, 3.0)
grid = CartesianGrid(10, 10)
mesh = grid |> Scale(2., 3.)
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], grid)
viz(fig[1,2], mesh)
fig
Stretch
Meshes.Stretch
— TypeStretch(s₁, s₂, ...)
Stretch geometry or domain outwards with strictly positive scaling factors s₁, s₂, ...
.
Examples
Stretch(1.0, 2.0, 3.0)
grid = CartesianGrid(10, 10)
mesh = grid |> Stretch(2., 3.)
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], grid)
viz(fig[1,2], mesh)
fig
StdCoords
Meshes.StdCoords
— TypeStdCoords()
Standardize coordinates of all geometries to the interval [-0.5, 0.5]
.
Examples
julia> CartesianGrid(10, 10) |> StdCoords()
10×10 CartesianGrid{2,Float64}
minimum: Point(-0.5, -0.5)
maximum: Point(0.5, 0.5)
spacing: (0.1, 0.1)
# Cartesian grid with coordinates [0,10] x [0,10]
grid = CartesianGrid(10, 10)
# scale coordinates to [-1,1] x [-1,1]
mesh = grid |> StdCoords()
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], grid)
viz(fig[1,2], mesh)
fig
Repair
Meshes.Repair
— TypeRepair{K}
Perform repairing operation with code K
.
Available operations
- K = 0: duplicated vertices and faces are removed
- K = 1: unused vertices are removed
- K = 2: non-manifold faces are removed
- K = 3: degenerate faces are removed
- K = 4: non-manifold vertices are removed
- K = 5: non-manifold vertices are split by threshold
- K = 6: close vertices are merged (given a radius)
- K = 7: faces are coherently oriented
- K = 8: zero-area ears are removed
- K = 9: rings of polygon are sorted
- K = 10: outer rings are expanded
Examples
# remove duplicates and degenerates
mesh |> Repair{0}() |> Repair{3}()
# mesh with unreferenced point
points = Point3[(0, 0, 0), (0, 0, 1), (5, 5, 5), (0, 1, 0), (1, 0, 0)]
connec = connect.([(1, 2, 4), (1, 2, 5), (1, 4, 5), (2, 4, 5)])
mesh = SimpleMesh(points, connec)
rmesh = mesh |> Repair{1}()
4 SimpleMesh{3,Float64}
4 vertices
├─ Point(0.0, 0.0, 0.0)
├─ Point(0.0, 0.0, 1.0)
├─ Point(0.0, 1.0, 0.0)
└─ Point(1.0, 0.0, 0.0)
4 elements
├─ Triangle(1, 2, 3)
├─ Triangle(1, 2, 4)
├─ Triangle(1, 3, 4)
└─ Triangle(2, 3, 4)
Bridge
Meshes.Bridge
— TypeBridge(δ=0)
Transform polygon with holes into a single outer ring via bridges of given width δ
as described in Held 1998.
References
# polygon with two holes
outer = [(0, 0), (1, 0), (1, 1), (0, 1)]
hole1 = [(0.2, 0.2), (0.4, 0.2), (0.4, 0.4), (0.2, 0.4)]
hole2 = [(0.6, 0.2), (0.8, 0.2), (0.8, 0.4), (0.6, 0.4)]
poly = PolyArea([outer, hole1, hole2])
# polygon with single outer ring
bpoly = poly |> Bridge(0.01)
fig = Mke.Figure(size = (800, 400))
viz(fig[1,1], poly)
viz(fig[1,2], bpoly)
fig
Smoothing
Meshes.LambdaMuSmoothing
— TypeLambdaMuSmoothing(n, λ, μ)
Perform n
smoothing iterations with parameters λ
and μ
.
See also LaplaceSmoothing
, TaubinSmoothing
.
References
- Taubin, G. 1995. Curve and Surface Smoothing without Shrinkage
Meshes.LaplaceSmoothing
— FunctionLaplaceSmoothing(n, λ=0.5)
Perform n
iterations of Laplace smoothing with parameter λ
.
References
- Sorkine, O. 2005. Laplacian Mesh Processing
Meshes.TaubinSmoothing
— FunctionTaubinSmoothing(n, λ=0.5)
Perform n
iterations of Taubin smoothing with parameter 0 < λ < 1
.
References
- Taubin, G. 1995. Curve and Surface Smoothing without Shrinkage
using PlyIO
# helper function to read *.ply files
function readply(fname)
ply = load_ply(fname)
x = ply["vertex"]["x"]
y = ply["vertex"]["y"]
z = ply["vertex"]["z"]
points = Point3.(x, y, z)
connec = [connect(Tuple(c.+1)) for c in ply["face"]["vertex_indices"]]
SimpleMesh(points, connec)
end
# download mesh from the web
file = download(
"https://raw.githubusercontent.com/juliohm/JuliaCon2021/master/data/beethoven.ply"
)
# read mesh from disk
mesh = readply(file)
# smooth mesh with 30 iterations
smesh = mesh |> TaubinSmoothing(30)
fig = Mke.Figure(size = (800, 1200))
viz(fig[1,1], mesh)
viz(fig[2,1], smesh)
fig