Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed load_structure_from_ply for latest Meshes.jl version #12

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DoseCalculations"
uuid = "b0d14063-c48a-4081-83d5-5a5ab48cb495"
authors = ["lmejn <33491793+lmejn@users.noreply.github.com>"]
version = "0.7.0"
version = "0.7.1"

[deps]
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
Expand Down
26 changes: 7 additions & 19 deletions src/Structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@ mesh into a Meshes.SimpleMesh.
From https://github.com/JuliaIO/MeshIO.jl/issues/67#issuecomment-913353708
"""
function load_structure_from_ply(filename)
mesh = FileIO.load(filename)

vertexToIdx = Dict()
for i = 1:length(mesh.position)
vertex = mesh.position[i]
if !haskey(vertexToIdx, vertex) # duplicated vertices
vertexToIdx[vertex] = i
end
end
faces = []
for triangle in mesh
i1 = vertexToIdx[triangle[1]]
i2 = vertexToIdx[triangle[2]]
i3 = vertexToIdx[triangle[3]]
push!(faces, (i1, i2, i3))
end
topology = FullTopology(connect.(faces))

SimpleMesh([convert(Point{3, Float64}, Point([x[1], x[2], x[3]])) for x in mesh.position], topology)
mesh = FileIO.load(filename)
points = [Float64.(Tuple(p)) for p in Set(mesh.position)]
indices = Dict(p => i for (i, p) in enumerate(points))
connectivities = map(mesh) do el
Meshes.connect(Tuple(indices[Tuple(p)] for p in el))
end
Meshes.SimpleMesh(points, connectivities)
end

#--- Mesh Transformations -----------------------------------------------------
Expand Down