Tuesday, 24 April 2012

Painting in AWT and Swing

AWT stands for abstract windowing toolkit. When the original AWT API was developed for JDK 1.0, only heavyweight components existed ("heavyweight" means that the component has its own opaque native window). Lightweight components are introduced in JDK 1.1 (a "lightweight" component is one that reuses the native window of its closest heavyweight ancestor). There are subtle differences in how painting works for heavyweight and lightweight components.

Swing Painting Guidelines

  1. For Swing components, paint() is always invoked as a result of both system-triggered and app-triggered paint requests; update() is never invoked on Swing components.
  2. Programs may trigger a future call to paint() by invoking repaint(), but shouldn't call paint() directly.
  3. On components with complex output, repaint() should be invoked with arguments which define only the rectangle that needs updating, rather than the no-arg version, which causes the entire component to be repainted.
  4. Swing's implementation of paint() factors the call into 3 separate callbacks:
    1. paintComponent()
    2. paintBorder()
    3. paintChildren()
    Extensions of Swing components which wish to implement their own paint code should place this code within the scope of the paintComponent() method (not within paint()).
Reference:

Tuesday, 17 April 2012

Some computational geometry terminologies

Convex hull
The convex hull of a set of points X can be visualized as the shape of a rubber band stretched around X. It is the smallest enclosing convex polygon of the set X in the plane.

Getting Started with Kinect for Windows SDK

I have been experimenting with Kinect for Windows SDK and here are the steps to get things started.

1. Download and install the Kinect for Windows SDK. Follow the system requirements and installation instructions on the website. The main software requirements are Visual Studio 2010 Express or other Visual Studio 2010 edition and .NET Framework 4.0.

2. To get started with the development, I find the Quickstart Series are very helpful.

3. Some other details about the API:
  • In the depth map, each pixel is labeled with a number from 1 to 7 to indicate that it is part of user 1, 2, and so on up to 7. If a pixel is not part of a user then it is assigned index of zero. Each pixel is a short value. We can extract the player index and the depth using the following:
    userIndex = s & DepthImageFrame.PlayerIndexBitmask; // The mask is 0x07.
    depth = ((ushort) s) >> DepthImageFrame.PlayerIndexBitmaskWidth; // The width is 3.
    
  • Depth values are in mm.
  • There are 20 joints in the skeleton tracking.