2011-10-29

Picking values from a point in Mayavi2

Sometimes we have scientific data, each point of which has multiple values associated with. If the data is visualized, we want to pick up values at certain points. I have been needing this features for too long. And today someone gave me some hints to figured it out.

Step 1 (optional): prepare your VTK file. Make sure you have POINT_DATA and/or CELL_DATA segment(s). Do NOT create multiple POINT_DATA n and/or CELL_DATA n lines in one file - VTK format is linear.

Step 2: Start Mayavi2 GUI application and load the VTK file. There are two ways to do so.

I am always lazy. So I run command like the one below from UNIX/Linux Shell.
mayavi2 -d  ../Data/brains/50201_surf/lh.sulc.fundi.from.pits.inflated.final.vtk -m Surface

You can also use GUI menu in Mayavi2. This will take two steps.
  1. Load the data: File-> Load data -> Open file ...
  2. Visualize: Suppose we want the surface of the data now. Visualize->Modules
Step 3: Choose the proper data attribute.
Click the data file in the Engine Tree View. Select the proper data attribute in Mayavi object editor below. For example, I select CmpntID in Point scalars name.


Step 4 (optional): Turn on LUT legend.
Click the Color and legends below the VTK file in Engine Tree View. If the data attribute is scalar, select Scalar LUT tab and check Show legend. Then you will see a legend bar on the right of your scene.


Step 5: Select points. This part a little bit tricky because 1) you are selecting a 3-D object on a 2-D interface and 2) the GUI of Mayavi2 isn't very user-friendly for this purpose.

  1. Move you mouse over a random place (or over your the point you wanna pick data) on the scene. 
  2. Press 'p' on your keyboard. A dialog box titled Edit properties will pop up. 
  3. Make sure that you selected Pick type as point_picker. And choose a small enough Tolerance level. I don't know what it means but if it is smaller, it's easier to precisely pick up a point. The default tolerance is 0.025. I prefer 0.01. 
  4. Now click on somewhere you really wanna pick on the scene, and then click 'p'. There will be a 3-D crosshair. It is very useful because it tells you where you really selected. 
  5. On the Edit properties window, there are some value. In our case, we care about the scalar (fundusID). It reads 41.0 on the snapshot, and it matches the value on legend bar for points of this color. If there is a mismatch, rotate the object and redo. 
  6. Repeat step 4 and 5 to find out scalar values you care at other places. Press 'p' every time after selecting somewhere. You should at least see coordinates changes when you select different places. The legend bar on the right can help you verify the scalar value you pick. You should read none for all fields if you move mouse out of the object. 
Troubleshooting: 
1. If coordinates do not change when your click different places, check whether the cursor falls in the History box in Edit Properties dialog box.) In that case, you shall see a lot of p's in the History box (on the top or at the end mostly).
2. If you keep missing a point while the mouse seems to be over it, rotate the object. Selection a 3-D subject in 2-D visualization means you will always miss on one dimension/axis. 
3. A help for the problem above is to press Alt+3 on the scene and put on a pair of 3-D anaglyph glasses. This will enable your real 3-D view. 

2011-10-28

Finding and deleting files in Shell

A quick mini wiki of my frequency used options for find files on Shell.

  • Find files containing a string in filenames, e.g.,
    find ./src/ -name ".cxx"
    This finds all files of suffix .cxx under path ./src/, which is a folder on current Path.
  • Find files containing a string in filenames and delete them, e.g.,
    find . -mindepth 1 -name '.*' -delete
  • Find folders containing a string in filenames and delete them, e.g.,
    find .  -name "CVS" -exec rm -rf {} \;
    Please note the direction of slash in the line above. It's backslash, not forward slash. You can use the -exec option to do everything you wanna do on the shell.

2011-10-24

Deleting all FreeSurfer original files in surf folder

I need to delete, or purge, all original files in FreeSurfer's $subject/surf folder - because i only need my result files in that folder but not original ones.

Here is a Shell script that i hope to help others, who also need to do the same. Please replace SUBJECT by the subject ID. I assume you have already setup $SUBJECTD_DIR environment variable. You may also replace $D by a real path. You can also embed the script below into a loop block so you can process many surf folders at once.

#!/bin/sh
   $D=$SUBJECTS_DIR/SUBJECTID/surf
   echo $D
   rm $D/rh.smoothwm.C.crv
   rm $D/ rh.smoothwm.FI.crv
   rm $D/rh.smoothwm.H.crv
   rm $D/rh.smoothwm.K1.crv
   rm $D/rh.smoothwm.K2.crv
   rm $D/rh.smoothwm.K.crv
   rm $D/rh.smoothwm.nofix
   rm $D/rh.smoothwm.S.crv
   rm $D/rh.sphere
   rm $D/rh.sphere.reg
   rm $D/rh.sulc
   rm $D/rh.thickness
   rm $D/rh.volume
   rm $D/rh.white
   rm $D/lh.sphere
   rm $D/lh.sphere.reg
   rm $D/lh.sulc
   rm $D/lh.thickness
   rm $D/lh.volume
   rm $D/lh.white
   rm $D/rh.area
   rm $D/rh.area.mid
   rm $D/rh.area.pial
   rm $D/rh.avg_curv
   rm $D/rh.curv
   rm $D/rh.curv.pial
   rm $D/rh.defect_borders
   rm $D/rh.defect_chull
   rm $D/rh.defect_labels
   rm $D/rh.inflated
   rm $D/rh.inflated.H
   rm $D/rh.inflated.K
   rm $D/rh.inflated.nofix
   rm $D/rh.jacobian_white
  rm $D/rh.orig
  rm $D/rh.orig.nofix
  rm $D/rh.pial
  rm $D/rh.qsphere.nofix
  rm $D/rh.smoothwm
  rm $D/rh.smoothwm.BE.crv
  rm $D/lh.area
  rm $D/lh.area.mid
  rm $D/lh.area.pial
  rm $D/lh.avg_curv
  rm $D/lh.curv
  rm $D/lh.curv.pial
  rm $D/lh.defect_borders
  rm $D/lh.defect_chull
  rm $D/lh.defect_labels
  rm $D/lh.inflated
  rm $D/lh.inflated.H
  rm $D/lh.inflated.K
  rm $D/lh.inflated.nofix
  rm $D/lh.jacobian_white
  rm $D/lh.orig
  rm $D/lh.orig.nofix
  rm $D/lh.pial
  rm $D/lh.qsphere.nofix
  rm $D/lh.smoothwm
  rm $D/lh.smoothwm.BE.crv
  rm $D/lh.smoothwm.C.crv
  rm $D/lh.smoothwm.FI.crv
  rm $D/lh.smoothwm.H.crv
  rm $D/lh.smoothwm.K1.crv
  rm $D/lh.smoothwm.K2.crv
  rm $D/lh.smoothwm.K.crv
  rm $D/lh.smoothwm.nofix
  rm $D/lh.smoothwm.S.crv

2011-10-20

What is death?

A friend, a non-religious friend, lately had a conversation with me. Triggered by Steve Jobs's death, he gave me the best plain (no fancy scientific, philosophical or religious words) definition to death I have ever heard in my life.

He said, "Death means that you can no longer do things you wanna do."

That's right. That's a big reason when I was young I was so afraid of dying. I thought, "I will have to say bye to all my toys and all my games."

We are all gonna die.

We all have things we love to do and dreams we are chasing. But, "your time is limited."

From the movie "Bridge to Terabithia," I learned a quote of Teddy Roosevelt that "Far and away the best prize that life has to offer is the chance to work hard at work worth doing."

Cherish the time that we can still do things we wanna do. It's very luxury.

PS: When I was young, i heard a Chinese proverb, saying "Given an inch of gold and an inch of time, you cannot buy the inch of time by the inch of gold." (一寸光阴一寸金,寸金难买寸光阴)

2011-10-18

Best Asian font ever. And it's on Mac.

I would have to admit that Apple makes high quality fonts, even for Asian languages.

Here is an example.

I love you, West Texas!

I finally, experienced the first sand storm in Lubbock. I have been waiting to see this extraordinary natural power for more than 4 years!

A local news network reported that the wind lifted "one FedEx jumbo jet completely off its front wheels, pointing its nose toward the sky while it was still on the ground."

The news network also shows how the sand storm invaded the city. OMG, when it came, i really couldn't see any light from the outside of the window.



Here are two videos I found on Youtube. You can find a lot more.



Allow me to be religious in this geeky blog. Praise the God, for the power He has and the wonder He made. May He bless my beloved West Texas, forever!

Tonight, when I said I loved something BIG (like this) that you cannot see in Canada, a Canadian girl replied this back to me, which is also funny.

2011-10-11

Font matters, on papers and webpages

by Forrest Sheng Bao http://fsbao.net

Kindle does not like Modern Serif fonts!

I just got a Kindle 3 from a friend. I tried to read some PDF papers on it. But the experience was horrible! It took me longer than normal to recognize letters in words. They are so blur and dim to my eyes. Since those papers are written by myself, I thought that changing font type or size may help. So I studied fonts today, to the best of my time allowance and brain power.

So a flash card about fonts
  • There are 4 major types of fonts, Serif, San Serif, typewritter and handwritten. 
  • On most publications (papers, newspapers, magazines) you see, San-Serif fonts are used for titles and Serif fonts are used for contents, because most people feel (including me) Serif fonts more pleasant than San-Serif fonts.
  • Besides titles, San-Serif fonts are widely used at places where people should pay attention to, such as signs, presentation slides, trademarks, etc. 
  • In each of these 4 types, some can be classified as Modern. Modern fonts have high contrast between thick and thin curves.
  • Also, in each of these 4 types, some have the name Mono in font name, meaning monospaced, i.e., fixed width for all symbols, such as Courier
Serif fonts look great on hardcopies but not always so on digital devices. The default LaTeX font, Computer Modern Serif looks horrible on Kindle. You may also notice many webpages in San-Serif fonts, such as Helvetica. Even cell phone interfaces. Why? Because pixels on digital device are much larger than ink drops. Therefore, Serif fonts look blur and difficult to read. Serif fonts look even worse when they are magnified (e.g., http://webdesignref.com/examples/textex.htm). Computer algorithms are also optimized for San-Serif fonts. Like below are font appearance settings of Ubuntu Linux.




But since Serif fonts look more pleasant, some new Serif fonts have come out in the mobile era, such as Google's Droid Serif. To me, with proper type and size, Serif fonts have no problem on digital devices.

For similar reason, Modern fonts are not welcomed on digital device - too many details to render.

So where to get pretty and open source fonts? Here are my recommendations:
Many years ago, I started reading and writing (in LaTeX) papers. I noticed 3 interesting things.
  1. Letters on most papers looked blur on the computer screen (in PDF) but very clear after being printed out on papers. 
  2. Knuth spent much time on developing METAFONT and designing the font for LaTeX. 
  3. Papers prepared in LaTeX's default font looked more appealing than papers in Micro$oft Times New Roman.
Now I've got all their answers.

PS: Microsoft's Windows cannot even render their own fonts properly. See how zigzag the edges are. Image not scaled.

2011-10-10

Some very simple examples for Linux command ls

ls is one of the few frequently used commands in my daily life. I decide to show some examples of it so my colleagues can easily pick up.

  • ls -rtl *.ac: Show all *.ac files and their details (-l), sorted by their modification time (-t) in ascending order (-r)
  • ls -rSl *.ac: Show all *.ac files and their details (-l), sorted by their size (-S) in ascending order (-r)

A note for using ls on Mac OS X: Using option -G will give folder and non-folder files different colors.

2011-10-03

Giving $30 to Mozilla Foundation today

I donated $30 to Mozilla Foundation today - because Firefox is so far the safest browser to me.