Class architecture

An algorithm to determine whether a point lies inside or outside of a TGArea needs to do several things. This section describes the classes available for setting up this process.

Extract the geometries

TGArea has the Extract function shown in the code fragment below and diagramed in Figure 69. The Extract function is called when you need to express the geometric structure of an area in terms of its basic geometries.

      virtual void TGArea::Extract( TGrafExtractor& extractor, TCAGNode* node,
                          const TMatrixState& = TRootMatrixState() ) const;

TMatrixState: The coordinate system of the geometries in the TGArea.

TCAGNode: Parent to the CAG classes, which provide the functionality for determining whether a point lies inside or outside of the calling TGArea. The CAG classes hierarchy is shown in Figure 70. The TCAGUnary derived classes are described below.


TGrafExtractor: The TGArea::Extract function calls the TGrafExtractor::Extract function for each basic 2D geometry contained in the TGArea. When the TGArea::Extract function is called, the TGArea makes calls to the TGrafExtractor instance to express its internal geometry structure. The function declaration for extracting a TGRect is shown here and illustrated in Figure 71.

      virtual void TGrafExtractor::ExtractRect( const TGRect& aRect, TCAGUnary* aNode, 
                  const TMatrixState& matrixState=TRootMatrixState() ) = 0;

TCAGUnary: Makes the TCAGNode binary tree that mirrors the TGArea binary tree. The binary tree represents the internal structure of the TGArea. Each TCAGUnary node in the TCAGNode binary tree represents a geometry in the TGArea. Binary trees and geometry edges are described below.

TMatrixState: Represents the coordinate system of the geometries in the TGArea.

The root (TCAGRoot) of the binary tree is passed to the TGrafExtractor::Render function, which processes the data collected by the TGrafExtractor instance as shown in the code fragment below and illustrated in Figure 72.

    virtual void Render( TCAGRoot& root ) = 0;

Create a binary tree

Before the area is drawn, the TGArea class automatically sets up a TCAGNode binary tree that mirrors the binary tree of the TGArea. Figure 73 shows the structure of the binary tree for the TGArea on the left in the figure. The TGArea binary tree is identical to the TCAGNode binary tree, and is not shown.


Every leaf in the TGArea binary tree corresponds to a leaf in the TCAGNode binary tree. Each leaf in both trees corresponds to the edges for each geometry in the area.

Calculate edge transition

At run time, when an edge of any geometry in the area is encountered, the TGArea binary tree informs the appropriate TCAGUnary node that a transition has occurred. The TCAGUnary node sends a message to its parent in the tree. The tree performs calculations to determine whether the current point lies inside or outside of the area, and the result is stored in the TCAGRoot.

For example in a scanconversion process, each row of pixels represents a horizontal path that crosses the area at a different y value. Each horizontal path causes transitions to occur for every geometry edge it crosses from left to right. When a transition is made, the scanconverter queries the root of the TCAGNode binary tree to determine whether or not the current position is within the area and determines which pixels to turn on.

Figure 74 shows the transitions for an area made up of a rectangle, ellipse, and a polygon. The rectangle and ellipse have two edges each, and the polygon has 5 edges. The area is created by adding the ellipse to the rectangle and subtracting the polygon. A transition occurs every time an edge is crossed in the iteration. The type of operation (add or subtract in this case) determines whether the point lies inside or outside the area, and the result is stored in TCAGRoot.


TCAGRoot: Accumulates the result of the CAG binary tree. Its GetCount functions return the current fill and frame values for the entire CAG binary tree. The functions are called by the code that uses the tree to determine which part of the geometry the current position is in.

TCAGEvenOdd: Provides evenodd fill behavior. A loop or polygon that uses the evenodd fill algorithm should use this class.

TCAGWindNum: Provides winding number fill behavior. A loop or polygon that uses the winding number fill algorithm should use this class.

NOTE Geometries such as TGRect and TGEllipse can use either the TCAGEvenOdd or the TCAGWindNum class. It makes no difference because they do not overlap themselves.

TCAGAdd, TCAGSubtract: Provide union and difference fill behavior. These and TCAGExclusiveOr and TCAGIntersect descend from TCAGBinary.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker