00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPALGEBRA_TRANSFORMATION_3D_H
00009 #define IMPALGEBRA_TRANSFORMATION_3D_H
00010
00011 #include "algebra_config.h"
00012 #include "Vector3D.h"
00013 #include "Rotation3D.h"
00014 #include "Transformation2D.h"
00015
00016 IMPALGEBRA_BEGIN_NAMESPACE
00017
00018 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
00019 class Transformation3D;
00020 Transformation3D compose(const Transformation3D &a,
00021 const Transformation3D &b);
00022 #endif
00023
00024
00025
00026
00027
00028 class IMPALGEBRAEXPORT Transformation3D
00029 {
00030 public:
00031
00032 IMP_NO_DOXYGEN(typedef Transformation3D This);
00033
00034 Transformation3D(){}
00035
00036 Transformation3D(const Rotation3D& r,
00037 const VectorD<3>& t=VectorD<3>(0,0,0)):
00038 trans_(t), rot_(r){}
00039
00040 Transformation3D(const VectorD<3>& t):
00041 trans_(t), rot_(get_identity_rotation_3d()){}
00042 ~Transformation3D();
00043
00044 VectorD<3> get_transformed(const VectorD<3> &o) const {
00045 return rot_.get_rotated(o) + trans_;
00046 }
00047
00048 VectorD<3> operator*(const VectorD<3> &v) const {
00049 return get_transformed(v);
00050 }
00051
00052
00053 Transformation3D operator*(const Transformation3D &tr) const {
00054 return compose(*this, tr);
00055 }
00056 const Transformation3D& operator*=(const Transformation3D &o) {
00057 *this=compose(*this, o);
00058 return *this;
00059 }
00060
00061
00062
00063
00064
00065
00066 Transformation3D operator/(const Transformation3D &b) const {
00067 Transformation3D ret= compose(*this, b.get_inverse());
00068 return ret;
00069 }
00070 const Transformation3D& operator/=(const Transformation3D &o) {
00071 *this= *this/o;
00072 return *this;
00073 }
00074 const Rotation3D& get_rotation() const {
00075 return rot_;
00076 }
00077 const VectorD<3>& get_translation()const{return trans_;}
00078
00079 IMP_SHOWABLE_INLINE({
00080 rot_.show(out);
00081 out<<" || "<<trans_;
00082 }
00083 )
00084 Transformation3D get_inverse() const;
00085 private:
00086 VectorD<3> trans_;
00087 Rotation3D rot_;
00088 };
00089
00090 IMP_OUTPUT_OPERATOR(Transformation3D);
00091
00092
00093
00094
00095 inline Transformation3D get_identity_transformation_3d() {
00096 return Transformation3D(get_identity_rotation_3d(),VectorD<3>(0.0,0.0,0.0));
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 inline Transformation3D
00118 get_transformation_from_reference_frame(const VectorD<3> &u,
00119 const VectorD<3> &w,
00120 const VectorD<3> &base) {
00121 VectorD<3> x = (u-base);
00122 VectorD<3> z = get_vector_product(x,w-base);
00123 VectorD<3> y = get_vector_product(z,x);
00124 VectorD<3> xu = x.get_unit_vector();
00125 VectorD<3> zu = z.get_unit_vector();
00126 VectorD<3> yu = y.get_unit_vector();
00127 Rotation3D rot = get_rotation_from_matrix(xu[0],xu[1],xu[2],
00128 yu[0],yu[1],yu[2],
00129 zu[0],zu[1],zu[2]).get_inverse();
00130 return Transformation3D(rot,base);
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140 inline Transformation3D
00141 get_rotation_about_point(const VectorD<3> &point,
00142 const Rotation3D &rotation) {
00143 return Transformation3D(rotation, (rotation*(-point)+point));
00144 }
00145
00146
00147
00148
00149
00150 inline Transformation3D compose(const Transformation3D &a,
00151 const Transformation3D &b){
00152 return Transformation3D(compose(a.get_rotation(), b.get_rotation()),
00153 a.get_transformed(b.get_translation()));
00154 }
00155
00156
00157
00158
00159
00160
00161
00162 IMPALGEBRAEXPORT Transformation3D get_transformation_3d(
00163 const Transformation2D &t2d);
00164
00165
00166 IMPALGEBRA_END_NAMESPACE
00167
00168 #endif