Skip to content

Commit

Permalink
Add example.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsp-spirit committed Jan 26, 2021
1 parent 9c8cc13 commit 39487db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/export_mesh.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Illustrates how to load a FreeSurfer brain mesh and export it to Wavefront Object format.
# You can open the result in Blender or other standard 3D modeling software.

using NeuroFormats

BRAIN_MESH_FILE = joinpath(ENV["HOME"], "develop/NeuroFormats.jl/test/data/subjects_dir/subject1/surf/lh.white")
surface = read_fs_surface(BRAIN_MESH_FILE)
export_to_obj(joinpath(ENV["HOME"], "brain.obj"), surface.mesh)

2 changes: 2 additions & 0 deletions src/fs_surface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ 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
Expand Down

0 comments on commit 39487db

Please sign in to comment.