~vcs-imports/openbabel/trunk

« back to all changes in this revision

Viewing changes to ctransform.h

  • Committer: ghutchis
  • Date: 2001-11-27 18:50:36 UTC
  • Revision ID: svn-v4:86f38270-e075-4da6-bf68-7dcd545c500b:openbabel/trunk:46
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
 
3
 
 
4
This program is free software; you can redistribute it and/or modify
 
5
it under the terms of the GNU General Public License as published by
 
6
the Free Software Foundation version 2 of the License.
 
7
 
 
8
This program is distributed in the hope that it will be useful,
 
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
GNU General Public License for more details.
 
12
***********************************************************************/
 
13
 
 
14
#ifndef OE_COORDTRANSFORM_INCLUDED
 
15
#define OE_COORDTRANSFORM_INCLUDED
 
16
 
 
17
#include <math.h>
 
18
 
 
19
#include "binary_io.h"
 
20
#include "Vector.h"
 
21
using namespace OpenEye;
 
22
 
 
23
namespace OpenEye {
 
24
 
 
25
/*!
 
26
**\brief An object for storing, manipulating and applying coordinate transformations.
 
27
**\par Setup
 
28
**The most basic way to setup a transformation is to use the member function Setup(float* xyz),
 
29
**which requires you to supply a specific set of 4 coordinates from the initial reference frame
 
30
**in the final reference frame.  The function Setup(float *init_xyz, float* final_xyz, unsigned int N)
 
31
**will set up a transformation given an arbitrary set of coordinates in the final and initial
 
32
**reference frame.  A rotation/translation or a translation/rotation can also be supplied,
 
33
**see the various member functions begining with Setup.
 
34
**\param Applying the transformation
 
35
**The Transform(float *xyz, unsigned int N) member function applies the objects transform
 
36
**to a set of coordinates.
 
37
**\par Utilities
 
38
**The Invert() member function will reverses the current transformation such that it changes
 
39
**what was originally the final reference frame into what was originally the initial reference frame.
 
40
**A rotation/translation or translation/rotation cooresponding to the objects transformation
 
41
**can be extracted, see the various member functions begining with Get.  The operator+(const OECoordTrans& ct2)
 
42
**and operator+=(const OECoordTrans& ct) are also defined for combining transformation.
 
43
**\note \b IMPORTANT : This object can only handle transformations that can be described
 
44
**with Euler angles (i.e., No inversions).  Several member function will take rotation
 
45
**matricies as input, however, it is assumed that these matricies only apply simple
 
46
**rotations that can be described with Euler angles.
 
47
*/
 
48
class OECoordTrans {
 
49
    protected:
 
50
        float _trans[3];
 
51
        float _euler[3];
 
52
        float _rmat[9];
 
53
 
 
54
        double Angle(double sn, double cs);
 
55
        void ApplyTranslation(float *trans, float *xyz, unsigned int N) const;
 
56
        void ApplyEulerInvert(float *euler, float *xyz, unsigned int N) const;
 
57
        void ApplyEuler(float *euler, float *xyz, unsigned int N) const;
 
58
        void ApplyRmatrix(float *rmat, float *xyz, unsigned int N) const;
 
59
        void EulerToRmatrix(float *euler, float *rmat) const;
 
60
    public:
 
61
        //Constructor, destructor and copy constructor
 
62
        OECoordTrans();
 
63
        OECoordTrans(const OECoordTrans& cp);
 
64
        ~OECoordTrans();
 
65
 
 
66
        //Operator overloads
 
67
        OECoordTrans& operator=(const OECoordTrans& cp);
 
68
        OECoordTrans& operator+=(const OECoordTrans& ct);
 
69
        OECoordTrans operator+(const OECoordTrans& ct2) const;
 
70
 
 
71
        //Clear function
 
72
        void Clear();
 
73
 
 
74
        //Read/Write to binary array/stream
 
75
        unsigned int WriteBinary(char* ccc);
 
76
        unsigned int ReadBinary(char* ccc);
 
77
        void WriteBinary(ostream& ostr);
 
78
        void ReadBinary(istream& istr);
 
79
 
 
80
        //Setup functions
 
81
        bool Setup(float *xyz);
 
82
        void Setup(float *init_xyz, float *final_xyz, unsigned int N);
 
83
        void SetupEulerTranslation(float *euler, float *trans);
 
84
        void SetupTranslationEuler(float *trans, float *euler);
 
85
        void SetupRmatrixTranslation(float *rmat, float *trans);
 
86
        void SetupTranslationRmatrix(float *trans, float *rmat);
 
87
        void SetupRmatrixTranslation(Matrix3x3& rmat, Vector& tvec);
 
88
        void SetupTranslationRmatrix(Vector& tvec, Matrix3x3& rmat);
 
89
 
 
90
        //Retrieve transform
 
91
        void GetEulerTranslation(float *euler, float *trans) const;
 
92
        void GetTranslationEuler(float *trans, float *euler) const;
 
93
        void GetRmatrixTranslation(float *rmat, float *trans) const;
 
94
        void GetTranslationRmatrix(float *trans, float *rmat) const;
 
95
        void GetRmatrixTranslation(Matrix3x3& rmat, Vector& tvec);
 
96
        void GetTranslationRmatrix(Vector& tvec, Matrix3x3& rmat);
 
97
        
 
98
        //Transformation functions
 
99
        void Transform(float *xyz, unsigned int N) const;
 
100
 
 
101
        //Invert
 
102
        void Invert();
 
103
  };
 
104
 
 
105
/*!
 
106
**\fn OECoordTrans::_trans()
 
107
**\brief Stores the translation part of the transformation.  This
 
108
**translation is applied after the rotation.
 
109
*/
 
110
 
 
111
/*!
 
112
**\fn OECoordTrans::_euler()
 
113
**\brief Stores the rotation part of the transformation in euler angles.
 
114
**This rotation is applied before the translation.  The elements of
 
115
**the array are : euler[0], a rotation about the z-axis; euler[1],
 
116
**a rotation about the x-axis; euler[2], a rotation about the z-axis.
 
117
**The rotations are applied in the order given.
 
118
*/
 
119
 
 
120
/*!
 
121
**\fn OECoordTrans::_rmat()
 
122
**\brief Stores the rotation part of the transformation as a
 
123
**rotation matrix.  This rotation is applied before the translation.
 
124
**_rmat[3*i+j] hold the matrix element in the i'th row and j'th column.
 
125
*/
 
126
 
 
127
 
 
128
} //End OpenEye namespace
 
129
 
 
130
#endif
 
131