2012-01-18

The Internet is on Strike!

200+ years ago, American Founding Fathers fought for liberty. Today, their legacy continues.

Google is doing something. http://www.google.com/landing/takeaction/



Wikipedia is doing something. http://en.wikipedia.org/wiki/Wikipedia:SOPA_initiative/Learn_more



Reddit is doing something. http://blog.reddit.com/2012/01/stopped-they-must-be-on-this-all.html


And more websites.

Join them by doing something on your website.

2012-01-12

Mathematically, you are my 23-rd cousin!

I made a complain on my Facebook and Google+ status today. I arbitrarily assumed that any Asian is at least my 100-th cousin. Then I realized I made a big mistake - there aren't \( 2^{100} \) people in Asia + Asian population in the US and Canada!

So, what ``degree'' of cousin are you to me?

Let's assume all humans on planet Earth at this moment has a pair of common ancestors, according to either some religious documents (e.g., Biblical Adam and Eve) or some molecular biology hypotheses (e.g., Y-chromosomal Adam and Mitochondrial Eve).

And, there are 6.5 billion people on planet Earth now.

Let's assume every couple in the history of mankind has \( e= \lim_{n \rightarrow \infty}{\left (1 + \frac{1}{n}\right)^n} \approx 2.718\) children that can reproduce grandchildren on average. (e is the mathematical constant a.k.a. Euler's number that can magically describe many phenomena in our universe.)

Because the natural logarithm of 6.5 billion is around 23 (\(\ln(6.5\times 10^9) \approx 22.595\) ), everyone on planet Earth now is at least my 23-rd cousin.

Thanks for reading this blog post from your 23-rd cousin.

Dear NASA, please find my 100-th cousin on another planet and say hi to him/her for me.

(This blog post contains math formulas rendered by MathJax from LaTeX. )

2012-01-07

Double and Float types of data in VTK files

by Forrest Sheng Bao http://fsbao.net

I just realized that they are different, at least to python-vtk, the official Python wrapper for VTK library. If a scalar is of type Float, python-vtk will pad many digits after the decimal point. For example, 205187 in a pure ASCII VTK file becomes 0.20518699288368225. All Float data are padded to the 16-th digit after decimal point. However, if the type is Double, no such a problem.

I don't know what VTK's semantics for Double and Float are. But it should be related.

I am using python-vtk and Python2.7 that comes with Ubuntu Linux 11.10 64bit.

2012-01-05

Trimming suffix or perfix of a string in Shell

by Forrest Sheng Bao http://fsbao.net

How to trim/truncate a string in Linux? Especially when it is a path or file name?

See this demo below.

test="~/bin/test_label"

echo ${test%_label} # the percentage sign means from the end

echo ${test#?/*/} # the pound sign means from the start 

Save it as a Shell script (e.g., test.sh) and test it on your Shell:

$ sh test.sh 
~/bin/test
test_label

Got the idea?

This is very simple string matching, where question mark and asterisk have their normal meanings in UNIX regular expression.

2012-01-04

Adding two SCALARS in POINTDATA for one vtkPolyData object in VTK

by Forrest Sheng Bao http://fsbao.net

In VTK (either the file format or the library), we sometimes associate more than one scalars to points. I just figured out how to do this in VTK (in C++, similarly in its Python, Tcl or Java wrapper).

Suppose I have a vtkPolyData pointer
vtkPolyData* mesh;
and two vtkDoubleArray (you can consider a vtkDoubleArray as a list of scalars) pointers
vtkDoubleArray* depth; 
 vtkDoubleArray* curv; 

This is how I do it:

depth->SetName("Depth");
mesh->GetPointData()->SetScalars(depth);
curv->SetName("Curvature");
mesh->GetPointData()->AddArray(curv);

You may test this by writing mesh into a VTK-format file:

vtkPolyDataWriter* writer=vtkPolyDataWriter::New();
 writer->SetFileName("test_dump.vtk");
 
 writer->SetInput(mesh);
 writer->Update();
 writer->Write();
 writer->Delete();

My only question is whether the use of AddArray() function is correct. What is I wanna set a Normal? or a Tensor?

2012-01-01

What Nimbus is

On Solaris 10 and 11, the default desktop theme is called Nimbus.

That's the only thing I like about Solaris.

So I did some googling to find out what it means. It means ``dark cloud'' in Latin