# Hierarchical Models

#### What we have

How to render any polygon anywhere

1. Put the polygon where you want it to be in world coordinates
2. Transform to view coordinates
3. Perspective transform
4. Clip in normalized device coordinates.
5. Scan convert each polygon in any order, using z-buffer to remove occuded pixels

#### What we want to have

Objects made of polygons that we can feed into the rendering pipeline.

• Making the objects is called modelling.
• Here we discuss the data structures and algorithms associated with hierarchical modelling
• Hierarchical is a synonym for `divide and conquer'.

#### An example

1. A forest is many trees, each at a different location, scale and orientation
• Use only two or three different trees, each defined with respect to a tree-centred coordinate system (TCS)
• With respect to the world coordinate system (WCS) define, for each tree, a matrix that expressed the relationship between the TCS and the WCS.
2. Each tree has a trunk (in a TkCS) and a root (in an RCS)
• Choose from a few of each
• Define matrices that define RCS and TkCS to the TCS
3. Each Trunk has several branches, each with a BCS
• Choose from a few of each
• Define BCS/TkCS matrices
4. Each branch has several twigs, each having a TgCS
• Choose
• Define TgCS/BCS
5. Each twig has several leaves, LCS
• Choose
• Define LCS/TgCS

#### How do we render a leaf?

1. Transform points from LCS to TgCS (MLTg)
2. Transform points from TgCS to BCS (MTgB)
3. Transform points from BCS to TkCS (MBTk)
4. Transform points from TkCS to TCS (MTkT)
5. Transform points from TCS to WCS (MTW)
6. Transform points to view coordinates (MWV)
7. Perspective Transform points (MVP)

Make up the matrix M = MVP * MWV * MTW * MTkT * MBTk * MTgB * MLTg

• and use it on each point (probably polygon vertex) in the leaf

## Scene Graph

#### Render a scene

```proc scene
unitMatrix( )
multMatrix(MVP)
multMatrix(MWV)
pushMatrix( )
multMatrix(MTW1)
tree1( )
popMatrix( )
pushMatrix( )
multMatrix(MTW2)
tree2( )
popMatrix( )
etc.
```

Render a forest

```proc tree1( )
pushMatrix( )
multMatrix(MTTk11)
trunk1( )
popMatrix( )
pushMatrix( )
multMatrix(MTR12)
root2( )
popMatrix( )

proc tree2( )
pushMatrix( )
multMatrix(MTTk11)
trunk1( )
popMatrix( )
pushMatrix( )
multMatrix(MTR12)
root2( )
...
```

We don't want always to write a program, so we encapsulate the program as data.

Traverse a DAG

```traverse( root )

proc traverse( node ) {
if ( primitve( node ) ) {
draw( node )
} else { for each child {
traverse( child )
}
}```

Build a DAG

• This is done by a modelling tool, or program
```scene = gr.transform( )

tree1 = gr.transform( )
gr.set_transform( tree1, gr.translation(...)*gr.rotation(...)*...)
...

root = gr.transform( )
rootshape = gr.cylinder( )
gr.set_transform( root, gr.scaling(...)*... )
gr.setmaterial( rootshape, rough_bark )

trunk = gr.transform( )
gr.set_transform( trunk, gr.scaling(...)*... )
trunkshape = gr.cylinder( )
// The code below is repeated for each branch
branch = gr_transform( )
gr.set_transform( branch, gr... )
branchshape = gr_cylinder( )
gr.setmaterial( branchshape, mediumbark )
twig = grtransform( )
...

column1 = gr.transform( )
gr.set_transform( column1, gr.translation(...)*gr.scaling(...)
...```

## Colour

What is needed for colour?

1. An eye.
2. A source of illumination.
3. A surface.

How is colour created?

1. Source of illumination emits light (photons of differing wavelength).
2. Surface modifies light.
• reflectance
3. Eye compares surfaces and notices different modifications.

How do we represent colour?

• As some kind of sum of photons?
• As a distribution of photons (over wavelength)?
• As a ratio of distributions of photons?

To the rescue,

• A nineteenth century mathematician
• Grassmann

and a nineteenth century physicist

• Maxwell
• All colours are subjectively the same as a linear combination of three basis colours
• Linear combination defined in a special way
• Is there anything special about three?
• Change of basis, etc., etc.
• Display-dependent standard bases: RGB.
• Display-independent standard bases: XYZ.
• Non-linear bases
• HSV
• Opponent colours

But,

• Only approximately correct
• but to within 1-2% for most humans,
• only describes matching, not appearance
• Doesn't describe non-additive colour mixture
• CMY(K) for printing inks

More precise requires illumination as well

CIELab, CIELuv