Transform3D.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef __RD_TRANSFORM3D_H__
00011 #define __RD_TRANSFORM3D_H__
00012 
00013 #include "Transform.h"
00014 
00015 #include <Numerics/SquareMatrix.h>
00016 
00017 namespace RDGeom {
00018   class Point3D;
00019   const unsigned int DIM_3D=4;
00020   
00021   class Transform3D : public RDNumeric::SquareMatrix<double> {
00022   public:
00023     //!  Constructor
00024     /*!
00025       Initialize to an identity matrix transformation.
00026       This is a 4x4 matrix that includes the rotation and translation parts
00027       see Foley's "Introduction to Computer Graphics" for the representation
00028       
00029       Operator *= and = are provided by the parent class square matrix. 
00030       Operator *= needs some explanation, since the order matters. This transform gets set to
00031       the combination other and the current state of this transform
00032       If this_old and this_new are the states of this object before and after this function
00033       we have
00034               this_new(point) = this_old(other(point))
00035      */
00036      
00037     Transform3D() : RDNumeric::SquareMatrix<double>(DIM_3D,0.0) {
00038       unsigned int i, id;
00039       for (i = 0; i < DIM_3D; i++) {
00040         id = i*(DIM_3D+1);
00041         d_data[id] = 1.0;
00042       }
00043     }
00044     
00045     void setToIdentity();
00046 
00047     void TransformPoint(Point3D &pt) const;
00048 
00049     /*! \brief Set the translation vector
00050      */
00051     void SetTranslation(const Point3D &move);
00052 
00053     /*! \brief set the rotation matrix 
00054      *
00055      * The rotation matrix is set to rotation by th specified angle
00056      * about the specified axis
00057      */
00058     void SetRotation(double angle, AxisType axis);
00059 
00060     /*! \brief set the rotation matrix 
00061      *
00062      * The rotation matrix is set to rotation by th specified angle
00063      * about an arbitrary axis
00064      */
00065     void SetRotation(double angle, const Point3D &axis);
00066     void SetRotation(double cosT,double sinT,const Point3D &axis);
00067 
00068     //! Set the rotation matrix from a quaternion
00069     void SetRotationFromQuaternion(double quaternion[4]);
00070 
00071     //! Reflect the rotation 
00072     void Reflect();
00073 
00074   private:
00075     
00076   };
00077 }
00078 
00079 /*! \brief Combine two transforms and return the results as a new transform
00080  *
00081  * The order is important here, on two transforms t1 and t2
00082  * t3 = t1*t2 
00083  * The resulting transform t3 has the folliwng effect
00084  *  t3(point) = t1(t2(point))
00085  */
00086 RDGeom::Transform3D operator* (const RDGeom::Transform3D &t1, const RDGeom::Transform3D &t2);
00087 
00088 /*! \brief Transform a point:
00089  *
00090  */
00091 RDGeom::Point3D operator* (const RDGeom::Transform3D &t, const RDGeom::Point3D &pt);
00092 
00093 
00094 #endif
00095    
00096