/src/rdkit/Code/Geometry/Transform3D.h
Line | Count | Source |
1 | | // |
2 | | // Copyright (C) 2005-2006 Rational Discovery LLC |
3 | | // |
4 | | // @@ All Rights Reserved @@ |
5 | | // This file is part of the RDKit. |
6 | | // The contents are covered by the terms of the BSD license |
7 | | // which is included in the file license.txt, found at the root |
8 | | // of the RDKit source tree. |
9 | | // |
10 | | #include <RDGeneral/export.h> |
11 | | #ifndef __RD_TRANSFORM3D_H__ |
12 | | #define __RD_TRANSFORM3D_H__ |
13 | | |
14 | | #include "Transform.h" |
15 | | |
16 | | #include <Numerics/SquareMatrix.h> |
17 | | |
18 | | namespace RDGeom { |
19 | | class Point3D; |
20 | | const unsigned int DIM_3D = 4; |
21 | | |
22 | | class RDKIT_RDGEOMETRYLIB_EXPORT Transform3D |
23 | | : public RDNumeric::SquareMatrix<double> { |
24 | | public: |
25 | | //! Constructor |
26 | | /*! |
27 | | Initialize to an identity matrix transformation. |
28 | | This is a 4x4 matrix that includes the rotation and translation parts |
29 | | see Foley's "Introduction to Computer Graphics" for the representation |
30 | | |
31 | | Operator *= and = are provided by the parent class square matrix. |
32 | | Operator *= needs some explanation, since the order matters. This transform |
33 | | gets set to |
34 | | the combination other and the current state of this transform |
35 | | If this_old and this_new are the states of this object before and after this |
36 | | function |
37 | | we have |
38 | | this_new(point) = this_old(other(point)) |
39 | | */ |
40 | | |
41 | 0 | Transform3D() : RDNumeric::SquareMatrix<double>(DIM_3D, 0.0) { |
42 | 0 | for (unsigned int i = 0; i < DIM_3D; i++) { |
43 | 0 | unsigned int id = i * (DIM_3D + 1); |
44 | 0 | d_data[id] = 1.0; |
45 | 0 | } |
46 | 0 | } |
47 | | Transform3D(const Transform3D &t) = default; |
48 | | Transform3D(Transform3D &&t) = default; |
49 | | ~Transform3D() = default; |
50 | | |
51 | | Transform3D &operator=(const Transform3D &t) = default; |
52 | | Transform3D &operator=(Transform3D &&t) = default; |
53 | | |
54 | | void setToIdentity(); |
55 | | |
56 | | void TransformPoint(Point3D &pt) const; |
57 | | void TransformPoint(double *pt) const; |
58 | | |
59 | | /*! \brief Set the translation vector |
60 | | */ |
61 | | void SetTranslation(const Point3D &move); |
62 | | |
63 | | /*! \brief set the rotation matrix |
64 | | * |
65 | | * The rotation matrix is set to rotation by the specified angle |
66 | | * about the specified axis |
67 | | */ |
68 | | void SetRotation(double angle, AxisType axis); |
69 | | |
70 | | /*! \brief set the rotation matrix |
71 | | * |
72 | | * The rotation matrix is set to rotation by the specified angle |
73 | | * about an arbitrary axis. |
74 | | * Note: if the axis is not a unit vector scaling will also occur. |
75 | | * This can be ensured by a call to Point3D#normalize() prior to calling |
76 | | * this method |
77 | | */ |
78 | | void SetRotation(double angle, const Point3D &axis); |
79 | | void SetRotation(double cosT, double sinT, const Point3D &axis); |
80 | | |
81 | | //! Set the rotation matrix from a quaternion |
82 | | void SetRotationFromQuaternion(const double quaternion[4]); |
83 | | |
84 | | //! Reflect the rotation |
85 | | void Reflect(); |
86 | | |
87 | | private: |
88 | | }; |
89 | | } // namespace RDGeom |
90 | | |
91 | | /*! \brief Combine two transforms and return the results as a new transform |
92 | | * |
93 | | * The order is important here, on two transforms t1 and t2 |
94 | | * t3 = t1*t2 |
95 | | * The resulting transform t3 has the following effect |
96 | | * t3(point) = t1(t2(point)) |
97 | | */ |
98 | | RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Transform3D operator*( |
99 | | const RDGeom::Transform3D &t1, const RDGeom::Transform3D &t2); |
100 | | |
101 | | /*! \brief Transform a point: |
102 | | * |
103 | | */ |
104 | | RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator*( |
105 | | const RDGeom::Transform3D &t, const RDGeom::Point3D &pt); |
106 | | |
107 | | #endif |