Skip to content

Commit

Permalink
add export func for FsSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsp-spirit committed Jan 26, 2021
1 parent 39487db commit 1716358
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/fs_surface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ function read_fs_surface(file::AbstractString)
file_io = open(file, "r")
header = read_fs_surface_header(file_io)

#@printf("Reading %d vertices and %d faces at current position %d.\n", header.num_vertices, header.num_faces, Base.position(file_io))

vertices_raw::Array{Float32,1} = reinterpret(Float32, read(file_io, sizeof(Float32) * header.num_vertices * 3))
vertices_raw .= ntoh.(vertices_raw)
vertices::Array{Float32,2} = Base.reshape(vertices_raw, (3, Base.length(vertices_raw)÷3))'
Expand All @@ -89,16 +87,18 @@ function export_to_obj(file:: AbstractString, bm::BrainMesh)
open(file, "w") do f
for row_idx in 1:size(bm.vertices, 1)
row = bm.vertices[row_idx, :]
@assert Base.length(row) == 3
vertex_rep = @sprintf("v %f %f %f\n", row[1], row[2], row[3])
write(f, vertex_rep)
end
for row_idx in 1:size(bm.faces, 1)
row = bm.faces[row_idx, :]
@assert Base.length(row) == 3
face_rep = @sprintf("f %d %d %d\n", row[1]+1, row[2]+1, row[3]+1)
write(f, face_rep)
end
end
end


""" Export the mesh of a FreeSurfer surface to a Wavefront Object File. """
export_to_obj(file:: AbstractString, x::FsSurface) = export_to_obj(file, x.mesh)

0 comments on commit 1716358

Please sign in to comment.