Jun 29, 2009

解决英文版Windows的中文乱码问题

  1. Open "Control Panel"
  2. Switch to "Category View"
  3. Open "Regional and Language Options"
  4. Switch to "Languages" tab
  5. Click "Install files for East Asian languages", and click "Apply".
  6. Switch to "Advanced" tab
  7. In the combo box "Language for non-Unicode programs", select "Chinese(PRC)"
  8. Switch to "Regional Options" tab
  9. Select "Chinese(PRC)" and "China" respectively for each of the two combo boxes.
  10. Click "OK"
Tips: 如果原有的中文软件还是有乱码问题,可以重新安装程序。

Learning OpenCV, the E-book

Learning OpenCV, the E-book

Jun 28, 2009

DocView Mode for Emacs

The wiki page.
Shift-+ to enlarge the displaying (.pdf)
C-c C-c to switch between docview mode and text mode

Jun 23, 2009

Make Emacs Warns for Long Lines

On Linux, we can use function font-lock-set-up-width-warning to tell Emacs warning for too long lines in source code:
(add-hook 'c++-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'java-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
(add-hook 'python-mode-hook
'(lambda () (font-lock-set-up-width-warning 80)))
On Mac OS X, above method fails. However, With Carbon Emacs or Aquamacs, we can do as follows:
; for CarbonEmacs (MacOSX)
(defun font-lock-width-keyword (width)
"Return a font-lock style keyword for a string beyond width WIDTH
thatuses 'font-lock-warning-face'."
`((,(format "^%s\\(.+\\)" (make-string width ?.))
(1 font-lock-warning-face t))))

(font-lock-add-keywords 'c++-mode (font-lock-width-keyword 80))
(font-lock-add-keywords 'objc-mode (font-lock-width-keyword 80))
(font-lock-add-keywords 'python-mode (font-lock-width-keyword 80))
(font-lock-add-keywords 'java-mode (font-lock-width-keyword 80))
An easier solution for 80-column-rule is lineker. The usage is pretty simple (tested on my IBM T60p, Emacs for Windows): add the following into your .emacs file.
(require 'lineker)
(add-hook 'c-mode-hook 'lineker-mode)
(add-hook 'c++-mode-hook 'lineker-mode)

GCC Does Not Support Mutable Set/MultiSet Iterator

Although C++ STL standard requires that std::set and set::multiset supports both constant iterator and mutable iterator, but libstdc++ supports only the constant one. In /usr/include/c++/4.0.0/bits/stl_set.h (as well stl_multiset.h), we can see the following iterator typedefs:
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 103. set::iterator is required to be modifiable,
// but this allows modification of keys.
typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
This would lead many STL algorithms incompatible with set and multiset. For example, the following code does not compile in GCC 4.0.x:
set myset;             // or multiset myset;
*myset.begin() = 100; // fails due to begin() returns const_iterator
remove_if(myset.begin(), myset.end(), Is71()); // remove_if invokes remove_copy_if, which requires mutable myset.begin().
It is notable that Microsoft Visual C++ 7.0 and later versions are more restrictive to the STL standard on above issue. Above code works with Visual C++.

Jun 22, 2009

Fast Approximate of 2D Water Ripples

Here is a very fast approximation algorithm. The author is really good at observing and finding highly effective approximations, in this case, the value of sine(x+o) is proportional to sine(x), where o is a small phase offset.

Jun 21, 2009

Useful Documents for CUDA Development

Make CUDA Works on MacBook Pro

  1. Download and install CUDA toolkit and CUDA SDK.
  2. When installing the CUDA toolkit, click the Customize button on the Installation Type panel of the installer. Then be sure that CUDAKext is selected for installation. If we do not do this, CUDA applications will complain "no CUDA capable device".
  3. After installing add the following to .bash_profile.
    export PATH=/usr/local/cuda/bin:$PATH
    export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
  4. After installing the CUDA SDK,
    cd /Developer/CUDA/lib
    ranlib *.lib
    Otherwise, we will get the following linker error when building CUDA applications:
    ld: in ../../lib/libcutil.a, archive has no table of contents
  5. Build CUDA sample applications:
    cd /Developer/CUDA
    make
    The result application binaries will be installed to /Developer/CUDA/bin/darwin/release.
A useful reference for installation and system requirement is a PDF file named CUDA_Getting_Started_2.2_MacOS.pdf.

A Good Xcode/C++/QuickDraw Tutorial

Xcode C++ Tutorials is a C++ tutorial using Xcode as the development tool and QuickDraw (the 2D graphics engine of Carbon under Mac OS X) as the basic framework. It is good for C++ beginners using Mac OS X, as well developers with experience with other platforms.

Jun 20, 2009

Mix Intel IPP with OpenCV

http://software.intel.com/en-us/articles/intel-integrated-performance-primitives-intel-ipp-open-source-computer-vision-library-opencv-faq/

Build OpenCV under Mac OS X

Install OpenCV on Mac OS X
  1. Install Xcode on Mac OS X computer.
  2. Download OpenCV source package (for Linux) from SourceForge.
  3. Unpack the source package
  4. Generate Makefile.in/am
    autoreconf -i --force
  5. Configure
    ./configure --prefix=/usr/local --with-python --with-swig
  6. Build and test building result
    make
    make check
  7. Install
    make install
  8. Building applications
    g++ -o capcam main.cc -I /usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lcvaux -lhighgui -lml
Other sources of information:

Package Management under Mac OS X

Under Windows, we can use Cygwin to manage software packages. Under Mac OS X, we can use Macports. Download and install the Macports dmg file, open a terminal window, and type commands like:
sudo port install cmake
Macports will download the source package and compile it for you.

Note: To make Macports knows the most recent package list, type the following commands regularly:
sudo port -v selfupdate

Note: After installing Macports, open a new terminal windows (program), which will use the system environment variables newly updated by the installation program. Using a terminal window which had been opened before Macports installation will leads to an error complaining cannot find 'port'.

Jun 18, 2009

ActionScript 3.0 Mode for Emacs

EmacsWiki suggests an actionscript mode which can be downloaded from a post at PetTomato. After download the .el file, I added the following lines into my .emacs configuration file. This works for my Aquaemacs for Mac OS X.
(load-file "~/.emacs.d/actionscript-mode.el")
(autoload 'actionscript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.as\\'" . actionscript-mode))

Jun 14, 2009

Gmsh: a three-dimensional finite element mesh generator

Gmsh is an automatic 3D finite element grid generator with a built-in CAD engine and post-processor. Its design goal is to provide a simple meshing tool for academic problems with parametric input and advanced visualization capabilities.

Jun 13, 2009

Fullscreen Mode of Aquamacs

We can type Command-Shift-Return to invoke the function aquamacs-toggle-full-frame, which switches between fullscreen mode.  For your customization skills for Aquamacs, refer to http://www.emacswiki.org/emacs/CustomizeAquamacs.

Robust Ray Intersect with Triangle Test

Tomas Moller and Ben Trumbore proposed a robust algorithm in their paper, Fast, Minimum Storage Ray/Triangle Intersection.  A reference implementation of this algorithm can be referred to as http://www.lighthouse3d.com/opengl/maths/index.php?raytriint, which implements the non-culling branch presented in that paper.

Alt and Meta in Aquamacs

The default Meta key in the Aquamacs distribution is Option (and also Esc). If this is unusable for you (your fingers are too well trained on other platforms), you can either press Apple-; (Options → Option Key → Option Key for Meta) to switch to Esc only.

For other interesting things about Aquamacs, refer to Aquamacs FAQ.

Jun 9, 2009

Password-less Login Using SSH

Consider we want to login from a MacBook Pro (mbp) to a remote Linux machine (tsingyi), where both computers have OpenSSH installed. In order to make tsingyi trust mbp, we use RSA cryptographic method to generate a public and a private key for mbp, which will be used to identify mbp during login.

To generate the pair of keys, on mbp, type
ssh-keygen -t rsa
Accept all default answers, and we get two files:
~/.ssh/id_rsa     --- the private key
~/.ssh/id_rsa.pub --- the public key

Now, copy the public key file to tsingyi by typing following command on mbp:
scp ~/.ssh/id_rsa.pub wyi@tsingyi:/home/wyi/.ssh/id_rsa-mbp.pub
and add the public key of mbp to ~/.ssh/authorized_keys of tsingyi by typing following command on tsingyi:
cat ~/.ssh/id_rsa-mbp.pub >> ~/.ssh/authorized_keys

Here we are. We should be able to ssh to tsingyi from mbp without typing password now.

Buld OpenGL/GLUT Applications under Mac OS X

Xcode comes with all what we need to build a Cocoa application with OpenGL and GLUT and GCC. So, first of all, we need to install Xcode.

Writing Code

An GLUT C/C++ program for Mac OS X should include three header files:
#include   // Header File For The OpenGL32 Library
#include // Header File For The GLu32 Library
#include // Header File For The GLut Library
Note that the locations of these header files in Mac OS X differs from where they are in Linux and Windows (e.g., GL/glut.h)

Building Using GCC

The command line using GCC to build a program main.c is as follows:
gcc -framework GLUT -framework OpenGL -framework Cocoa main.c -o learning
It is notable here that MacOSX uses the concept of so called frameworks. Instead of adding include paths and library names yourself, you add a framework to your compiler call. This is a MacOSX specific extension to gcc.

Building Using Xcode IDE

We can also manage our OpenGL/GLUT projects using Xcode IDE. To create a project, select the project type of "Cocoa Application". To add/edit the code, remove the auto-generated main.m, add a new main.c, and write our code into main.c. To specify the frameworks in IDE, right click the project and choose "Add Exisiting Frameworks" to add OpenGL and GLUT.

Jun 8, 2009

Open Source Software on Mac OS X

http://www.opensourcemac.org/
http://www.freemacware.com/
http://www.linuxbeacon.com/doku.php?id=opensourcemac

Jun 7, 2009

Simulation of Cracks

The paper: Simulation of the typical Poisson-Voronoi-Cox-Voronoi cell

Multivariate Poisson Models

  1. The slides on Multivariate Poisson Models.
  2. The paper: An Algorithm for Fast Generation of Bivariate Poisson Random Vectors

Crystalization

  1. Stochastic and Deterministic Simulation of Nonisothermal Crystalization of Polymers
  2. The Structure of Crystals.