A Binary Tree Node Example

From OO Lab
Revision as of 15:48, 2 December 2011 by RyanYang (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Binary Tree Node Example

In this tutorial, we present an example of binary tree node. The Binary Tree node has the following structure

    class bt {
       boolean travel ;
       btnode left;
       btnode right;
    };

and we want to visualize its object as

Binarytree.jpg

Good luck and let's rock !


  1. Open the Examples/java/bt.java
  2. set break points at line 59
  3. run the debuggee
  4. visualize "root"
  5. When mapping dialog pops up for the root, input the mapping below. In this mapping, we use a ball_laser to visualize root. Since we want the variable name to appear on the ball, so we link the variable to port varname

Bt-root.jpg

  1. Click on the ball
  2. When mapping dialog pops up for the bt, the goal of the visualization is
  • let a ball represent the travel. In addition, let true/false be visualized by the colors red/black to gain the advantages of visualization.
  • pointers left and right are also visualized as smaller balls but they are supposed to locate themselves at the southwest and southeast corners of travel and have a laser to mimic the directed arcs in textbooks. So, to complete this visualization goal, the following mappings is the final objective.

BigbintreeMDS.jpg

Let's complete the mapping step by step.

  1. Create the Red/Black ball
    1. Place a Math mapping node (select tab "arith" in the left subwindow)
    2. link travel to the mapping node.
    3. Right click the math node -> select "key in the formula"
    4. enter "$0*1.0" This formula transform a boolean variables to a floating point variable. The variables connected to the Math node can be accessed at $0,$1,$2... in the formula
    5. Place a Sphere_UBVM mapping node
    6. Right Click at the node-> select "Set Node Attributes"
    7. Click on "COLOR" to makes color attributes (RGB) of Sphere_UBVM visible.
    8. link the OUT port of the Math node to port _vm_r (the Red color)
  2. Create the ball laser for pointer left
    1. Select tab "Composite"
    2. click "ball_laser"
    3. link left to port varname and wop
    4. Right click the "ball_laser" -> select "Set Node Attributes" to pop up the following dialog
    5. Select port _vm_rx
    6. Click "edit attributes" -> enter -50
    7. Select port _vm_ry
    8. Click "edit attributes" -> enter value -50
    9. press OK

Attribute Dialog.jpg

The above setting is to place the ball_laser at a relative position of (-50,-50,0) which will be the southwest corner of Red/Black ball.

Please follow the above steps to set up pointer "right" except the relative position is (50,-50,0)

  1. Add a "vmcollector" at the tab of "basic" - the role of vmcollector is explained in collectors?
  2. Add a "Container_ubvm" at the tab of "ubvm" - what is the purpose of containers is explained in containers?
  3. Complete all the links
  4. Press "APPLY ALL" . This step is important to tell xDIVA that this mapping is automatically applied to any future object whose type is bt. If you forget to do so, you will need to redo the mappings!
  5. Press OK.

Good Job! You will have a visualization. Try to click the left and right pointers and see what happens.

Personal tools