3D Brain Models: Difference between revisions
(2 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
=Free Surfer= | =Free Surfer= | ||
The FreeSurfer surface meshes will be found in a participant's /surf directory. The surface meshes that look most like what you're probably thinking of are the .pial surface files, of which there are two: lh.pial and rh.pial. These will be the files we are working from for this process. | |||
==Create a WaveFront OBJ File== | ==Create a WaveFront OBJ File== | ||
Use mris_convert to convert from FreeSurfer binary to ASCII: | Use mris_convert to convert from FreeSurfer binary to ASCII: | ||
Line 48: | Line 50: | ||
=Blender= | =Blender= | ||
Blender is a free 3D modeling and animation software package available for Windows, Mac and Linux. You can download it | Blender is a free 3D modeling and animation software package available for Windows, Mac and Linux. You can download it [http://www.blender.org here]. It has loads of features that will be meaningless to anyone without formal training in computer animation, but it has two features that are useful to this project: 1) it's free, and 2) it can import/export and manipulate 3D mesh files saved in different formats. | ||
==Import== | ==Import== | ||
Line 59: | Line 61: | ||
==Scale== | ==Scale== | ||
Blender uses arbitrary ''Blender Units'' to describe the size of modeled objects. The units aren't important for animation, but are quite relevant when the objects represent something in the physical world. I don't want to recreate the instructions for changing scale | Blender uses arbitrary ''Blender Units'' to describe the size of modeled objects. The units aren't important for animation, but are quite relevant when the objects represent something in the physical world. I don't want to recreate the instructions for changing scale in blender, but will instead point you to [https://daler.github.io/blender-for-3d-printing/interface/transforms.html a link]. | ||
You will need to change the units to something meaningful (I prefer Metric), and you will find that after conversion, the brains will be absurdly large. I mean, like the brain will have the footprint of a small city block. I found that changing the units to metric, and then setting the scale to 0.001 (1 square equals .001m, or 1mm) and then scaling the object to 0.3 in the X,Y and Z axes yields brains that fit in a 4x4x5cm bounding box which is a reasonable desk trinket size. | You will need to change the units to something meaningful (I prefer Metric), and you will find that after conversion, the brains will be absurdly large. I mean, like the brain will have the footprint of a small city block. I found that changing the units to metric, and then setting the scale to 0.001 (1 square equals .001m, or 1mm) and then scaling the object to 0.3 in the X,Y and Z axes yields brains that fit in a 4x4x5cm bounding box which is a reasonable desk trinket size. | ||
Latest revision as of 11:32, 29 May 2019
This page is all about turning FreeSurfer surface files into 3D printable models. Inspiration comes from here
Free Surfer
The FreeSurfer surface meshes will be found in a participant's /surf directory. The surface meshes that look most like what you're probably thinking of are the .pial surface files, of which there are two: lh.pial and rh.pial. These will be the files we are working from for this process.
Create a WaveFront OBJ File
Use mris_convert to convert from FreeSurfer binary to ASCII:
mris_convert lh.pial lh.pial.asc
Repeat for both hemispheres
Rename Files
mv lh.pial.asc lh.pial.srf
Repeat for both hemispheres
Use srf2obj to create a Blender-Compatible File
The srf2obj script requires the installation of gawk if it's not already installed. The script can be found in the scripts/Shell folder on ubfs, and should be in your path (copy it to your ~/bin directory if you don't already have it).
srf2obj lh.pial.srf > lh.pial.obj
Repeat for both hemispheres.
If you are reading this wiki and aren't part of my lab, here is the srf2obj gawk script. I stole it from Anderson WInkler's blog. The only change I made is that gawk is installed in /usr/bin/ on my distribution of Ubuntu. You can copy/paste the script below to a text file to make a script (you'll still have to make it executable).
srf2obj Shell Script
#!/usr/bin/gawk -f BEGIN { if (ARGV[1] == "") { print "Convert Surface ASCII format to OBJ." print "" print "Usage:" print "srf2obj input.srf > output.obj" print "" print "The output goes to stdout. Use > to redirect to" print "a file, as shown above" print "" print "_____________________________________" print "Anderson M. Winkler" print "Yale University / Institute of Living" print "Jan/2010" print "http://brainder.org" exit } } # Count number of vertices and faces from the 2nd record NR == 2 { nV=$1 ; nF=$2 } # Convert vertex coordinates NR>=3 && NR<=nV+2 { print "v", $1, $2, $3} # Convert faces' vertex indices NR>=nV+3 && NR<=nV+nF+2 { print "f", $1+1, $2+1, $3+1 }
Blender
Blender is a free 3D modeling and animation software package available for Windows, Mac and Linux. You can download it here. It has loads of features that will be meaningless to anyone without formal training in computer animation, but it has two features that are useful to this project: 1) it's free, and 2) it can import/export and manipulate 3D mesh files saved in different formats.
Import
After converting the pial layer meshes, you're next going to want to import one file at a time into Blender. Note that blender only natively opens its native .blend files, and so we are going to be importing, rather then opening the files we created above. When you first open blender, you will be greeted with a splash screen. When that clears, you will see the default scene contains a cube. Right click it and hit the delete key because we don't want a cube embedded in our brain. Next, on the file menu, find import... and then locate the the .obj files you created. you will need to import the left and right files separately, but it doesn't matter what order you do it in. After the first hemisphere is imported, repeat for the .obj file for the other hemisphere.
Join
You may find as you import the hemisphere meshes that they are really large and you are zoomed in very close. If you have a mouse with a scroll wheel or similar capability, you can use the wheel to zoom out so you can see the whole brain at once. If this is your first time using Blender, you might want to accustom yourself with how to rotate your view of the object. Maybe even find a video on YouTube introducing the Blender interface (again, most features aren't relevant, but I expect a video would cover some of these really basic features).
When zoomed out, you can right click on a hemisphere and you will see it is selected because it will have an orange outline to it. If you hold down the shift-key as you select objects, all objects you click on are selected simultaneously. Hold down the shift key and right-click both hemispheres so that both are selected (outlined). With both hemispheres selected, hit CTRL+J on your keyboard to join both meshes into a single object. If your hemispheres are slightly out of alignment, you might want to align them before joining them together. You can nudge one of them by selecting the hemisphere you want to move and then using the arrow key. Again a YouTube video might be helpful if this is something you want to do.
Scale
Blender uses arbitrary Blender Units to describe the size of modeled objects. The units aren't important for animation, but are quite relevant when the objects represent something in the physical world. I don't want to recreate the instructions for changing scale in blender, but will instead point you to a link.
You will need to change the units to something meaningful (I prefer Metric), and you will find that after conversion, the brains will be absurdly large. I mean, like the brain will have the footprint of a small city block. I found that changing the units to metric, and then setting the scale to 0.001 (1 square equals .001m, or 1mm) and then scaling the object to 0.3 in the X,Y and Z axes yields brains that fit in a 4x4x5cm bounding box which is a reasonable desk trinket size.
Export
When your brain hemispheres have been joined and scaled to the size you would like it printed at, your last step is to find the file > export menu item, and export the model to a .STL file. Save it somewhere you can easily find it.
3D Printing
The 3D printers at UB use a multitude of files, but all of the printers will accept .stl files. Before printing you will need to fix your STL files using the Netfabb online service. This web-based utility requires a free autodesk account, but after you go through the registration process, you will be able to log in and upload your STL brain file. After a short upload and processing period (a couple of minutes), the website will tell you the file has been processed and provide you with a download link. The file will have the label "_fixed" added to it, so you can easily tell which of your brain files have been checked to ensure printability.
If you are printing at UB, there is a form you can complete at this link.
If you do not have access to UB's printing facility, there are many web-based companies that will print and mail you 3D prints of files you upload, such as Shapeways and Sculpteo (which I have personally used).