Skip to content

Commit

Permalink
Make load_geometry type stable (#696)
Browse files Browse the repository at this point in the history
* make `load_geometry` type stable

* SVector instead of tuple

* implement suggestions

---------

Co-authored-by: LasNikas <[email protected]>
  • Loading branch information
LasNikas and LasNikas authored Jan 14, 2025
1 parent 51bc12e commit 1cad30d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/preprocessing/geometries/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,22 @@ function load(fs::FileIO.Stream{FileIO.format"STL_BINARY"}; ELTYPE=Float64)
vertices = fill(fill(zero(ELTYPE), SVector{3}), 3n_faces)
normals = fill(fill(zero(ELTYPE), SVector{3}), n_faces)

load_data!(face_vertices, vertices, normals, io)

return TriangleMesh(face_vertices, normals, vertices)
end

function load_data!(face_vertices::Vector{Tuple{SVector{3, T}, SVector{3, T},
SVector{3, T}}},
vertices, normals, io) where {T}
i = 0
while !eof(io)
normals[i + 1] = SVector{3, ELTYPE}(read(io, Float32), read(io, Float32),
read(io, Float32))
normals[i + 1] = SVector{3, T}(read(io, Float32), read(io, Float32),
read(io, Float32))

v1 = SVector{3, ELTYPE}(read(io, Float32), read(io, Float32), read(io, Float32))
v2 = SVector{3, ELTYPE}(read(io, Float32), read(io, Float32), read(io, Float32))
v3 = SVector{3, ELTYPE}(read(io, Float32), read(io, Float32), read(io, Float32))
v1 = SVector{3, T}(read(io, Float32), read(io, Float32), read(io, Float32))
v2 = SVector{3, T}(read(io, Float32), read(io, Float32), read(io, Float32))
v3 = SVector{3, T}(read(io, Float32), read(io, Float32), read(io, Float32))

face_vertices[i + 1] = (v1, v2, v3)

Expand All @@ -76,8 +84,6 @@ function load(fs::FileIO.Stream{FileIO.format"STL_BINARY"}; ELTYPE=Float64)
skip(io, 2) # Skip attribute byte count
i += 1
end

return TriangleMesh(face_vertices, normals, vertices)
end

function trixi2vtk(geometry::Polygon; output_directory="out", prefix="",
Expand Down

0 comments on commit 1cad30d

Please sign in to comment.