How to get the vector of vertices and connectivity

How can I obtain the vectors of the vertices and connectivity from the primitive geometry defined by Meshes.jl?


julia> b = Meshes.Box((0.0, 0.0, 0.0), (1.0, 1.0, 1.0))
Box
├─ min: Point(x: 0.0 m, y: 0.0 m, z: 0.0 m)
└─ max: Point(x: 1.0 m, y: 1.0 m, z: 1.0 m)

julia> b = discretize(b)
5 SimpleMesh
  8 vertices
  ├─ Point(x: 0.0 m, y: 0.0 m, z: 0.0 m)
  ├─ Point(x: 1.0 m, y: 0.0 m, z: 0.0 m)
  ├─ Point(x: 1.0 m, y: 1.0 m, z: 0.0 m)
  ├─ Point(x: 0.0 m, y: 1.0 m, z: 0.0 m)
  ├─ Point(x: 0.0 m, y: 0.0 m, z: 1.0 m)
  ├─ Point(x: 1.0 m, y: 0.0 m, z: 1.0 m)
  ├─ Point(x: 1.0 m, y: 1.0 m, z: 1.0 m)
  └─ Point(x: 0.0 m, y: 1.0 m, z: 1.0 m)
  5 elements
  ├─ Tetrahedron(1, 5, 6, 8)
  ├─ Tetrahedron(1, 3, 4, 8)
  ├─ Tetrahedron(1, 3, 6, 8)
  ├─ Tetrahedron(1, 2, 3, 6)
  └─ Tetrahedron(3, 6, 7, 8)

What I want is

vertices = [
    [0.0, 0.0, 0.0]
    [1.0, 0.0, 0.0]
    [1.0, 1.0, 0.0]
    [0.0, 1.0, 0.0]
    [0.0, 0.0, 1.0]
    [1.0, 0.0, 1.0]
    [1.0, 1.0, 1.0]
    [0.0, 1.0, 1.0]
]

connectivity = [
    [1, 5, 6, 8]
    [1, 3, 4, 8]
    [1, 3, 6, 8]
    [1, 2, 3, 6]
    [3, 6, 7, 8]
]

You can use to function to turn point into vector.

using Meshes, Unitful
b = Meshes.Box((0.0, 0.0, 0.0), (1.0, 1.0, 1.0))
b = discretize(b)
A = to.(b.vertices)
vertices = [[v[1].val, v[2].val, v[3].val] for v in A]
connectivity = [collect(tetra.indices) for tetra in b.topology.connec]
1 Like

You can use vertices(mesh) to get the list of vertices. For the list of connectivities you can collect(topology(mesh)).

In practice you rarely need to collect the connectivities. You can iterate over the topology instead:

for c in topology(mesh)
  indices(c)
end
2 Likes

Thank you very much! That resolved my issue!

1 Like