Download Software Visualization in Prolog
Transcript
58 4.5. GENERATING VISUALIZATIONS Vnode Vattribute Vobject Vcompound Vassociation Figure 4.8. The base classes of graphical constraints. and implements the relation 4.5.2 Q V G! described in Section 3.7. !! v Generating the Scene Graph Each graphical constraint Constraint is a term that represents one node of a scene graph. The nodes in the scene graph are instances of the base classes shown in Figure 4.8. Thus each type of node is either a visual object or an attribute, and visual objects may be composite or binary associations. This base class hierarchy implements the basic graphical types in Section 3.5, which are objects, attributes and associations. Vobject refers to all constraints that can be rendered on the screen, Vcompound refers to all constraints that compose sub-objects, Vassociation is an association between two visual objects, and Vattribute is an attribute applied to visual objects. This base class hierarchy covers all graphical entities, attributes and associations that can make up an image. The C++ header file svtvisual.h implementing this class hierarchy is included in Section B.9.1. The complete class hierarchy of visuals provided by SVT is shown in Figure 4.9. As a naming convention, the graphical constraint’s functor has the same name as the class of the object with a prepended ‘V’. Thus the constraint string(1234, ‘Peter’) instantiates a class Vstring with identifier 1234 and string ‘Peter’. The functor’s arguments are passed directly to the object’s constructor for initialization. The complete list of graphical constraints provided by SVT is given in Section B.6. This class hierarchy is designed to be completely extensible to incorporate any method of graphical output. A C++ file can extend one of the classes of Figure 4.9, and declare a handler to instantiate the new graphical constraint for inclusion in the scene graph. Once the graphical constraints have been instantiated, they are structured into a graph. The objects must be cross-referenced, which means creating C++ pointers between the nodes in the scene graph. Each Vobject contains a term called its identifier, each Vattribute contains a term identifying the object to which it applies, and each Vassociation contains two terms identifying the objects that it associates. Cross-referencing is implemented using a hash table. Each Vobject inserts its identifier and address into the hash table. Each Vattribute looks up the address of its object from the hash table. Each Vassociation looks up the addresses of the objects it associates from the hash table. It follows that the cost of cross-referencing is linear with the number of graphical constraints in the scene. 4.5.3 Structuring The Scene Graph The cross-referenced nodes form a scene graph. A Vwindow object is created at the root node of the scene graph, and every object in this graph except the root node will have pointer to its parent. Any objects that do not have parents are automatically added to the Vwindow to ensure that the scene graph is connected. Before each node is cross referenced, the node is initialized by calling its On initialize() method. After each node has been cross referenced further initialization is done by calling the