XdkWrl: Using the Transformator class

Home | Hierarchy | Members | Alphabetical | Related Pages

# Using the Transformator class

In the Tools part of the library, there is a wrl::Transformator class that encapsulates the possible transformations of a 3D point in the VRML language. It can also compose and inverse transformations. See the class documentation for more detail. Hierarchy of transformations can also be represented using the wrl::TransformatorHierarchy class. This last class is very efficient because it uses an internally computed equivalent matrix, and yet very robust because it keeps track of the pushed transformations and therefore does not suffer from any numerical issues when popping a previously pushed transformation.

You will probably not use these directly, except for their transform() methods. Indeed the Traverser class maintains the current transformation for any traversed node as described below.

## Integration with Traverser

The TransformatorHierarchy is particularly handy when you hierarchically traverse a VRML scene graph (See page Traversing a VRML2 tree for a introduction to the wrl::Traverser class). Indeed when "treating" a node, you need to know what its local frame is, namely, what is the hierarchy of transform "above" the node. When we introduced the wrl::Traverser class, we said that the default treatment for a wrl::Transform was to merely traverse its children. Actually, the default wrl::Traverser(wrl::Transform* t) does a little bit more. It construct a wrl::Transformator object to represent the transformation described in `t` and pushes in a TransformatorHierarchy object accessible by the member function wrl::Traverser::transformHierarchy().

When writing your own traversal by subclassing the Traverser class, you can use the transformHierarchy() to devise the local coordinate frame. Here is for example a traverser that outpouts the absolute coordinate of the center of all the spheres in a VRML file.

    #ifndef SPHEREFLATTENER_H
    #define SPHEREFLATTENER_H

    #include <xdkwrl/tools/traverser.h>

    class SphereFlattener : public wrl::Traverser
    {
    protected:
      virtual void treat(wrl::Sphere*);
    };

    #endif // SPHEREFLATTENER_H

    #include "sphereflattener.h"

    #include <xdkwrl/nodes/sphere.h>
    #include <iostream>

    using namespace wrl;
    using namespace std;

    void
    SphereFlattener::treat(wrl::Sphere* s)
    {
      SFVec3f center(0.0f,0.0f,0.0f) ;
      SFVec3f C;

      transformHierarchy().transform(center,C);

      cout<<" sphere center                 : "<<C<<endl;
      cout<<" sphere *untransformed* radius : "<<s->radius<<endl;
    }

Note that non rigid transformation do not usually preserve the distance and therefore we cannot transform the "radius" of the transform sphere because it might not be a sphere anymore (e.g. it can be an ellipsis). In a future release we might add some functionality to the Transformator class to test if it has scales or not.

Generated on 5 Jan 2007 with version 1.5.1. |