Transforms

Geometric (e.g. coordinates) transforms are implemented according to the TransformsBase.jl interface. Please read their documentation for more details.

Rotate

Meshes.RotateType
Rotate(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
source
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.TranslateType
Translate(o₁, o₂, ...)

Translate coordinates of geometry or mesh by given offsets o₁, o₂, ....

source
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.AffineType
Affine(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])
source
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.ScaleType
Scale(s₁, s₂, ...)

Scale geometry or domain with strictly positive scaling factors s₁, s₂, ....

Examples

Scale(1.0, 2.0, 3.0)
source
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.StretchType
Stretch(s₁, s₂, ...)

Stretch geometry or domain outwards with strictly positive scaling factors s₁, s₂, ....

Examples

Stretch(1.0, 2.0, 3.0)
source
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.StdCoordsType
StdCoords()

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)
source
# 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.RepairType
Repair{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}()
source
# 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

# 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

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