/** * \file IMP/algebra/Transformation3D.h * \brief Simple 3D transformation class. * * Copyright 2007-2013 IMP Inventors. All rights reserved. * */ #ifndef IMPALGEBRA_TRANSFORMATION_3D_H #define IMPALGEBRA_TRANSFORMATION_3D_H #include #include "Vector3D.h" #include "Rotation3D.h" #include "BoundingBoxD.h" #include "GeometricPrimitiveD.h" IMPALGEBRA_BEGIN_NAMESPACE #if !defined(IMP_DOXYGEN) && !defined(SWIG) class Transformation3D; Transformation3D compose(const Transformation3D &a, const Transformation3D &b); #endif //! Simple 3D transformation class /** The rotation is applied first, and then the point is translated. \see IMP::core::Transform \geometry */ class IMPALGEBRAEXPORT Transformation3D: public GeometricPrimitiveD<3> { public: //! construct an invalid transformation Transformation3D(){} /** basic constructor*/ Transformation3D(const Rotation3D& r, const Vector3D& t=Vector3D(0,0,0)): trans_(t), rot_(r){} /** Construct a transformation with an identity rotation.*/ Transformation3D(const Vector3D& t): trans_(t), rot_(get_identity_rotation_3d()){} ~Transformation3D(); //! transform Vector3D get_transformed(const Vector3D &o) const { return rot_.get_rotated(o) + trans_; } //! apply transformation (rotate and then translate) Vector3D operator*(const Vector3D &v) const { return get_transformed(v); } /** compose two rigid transformation such that for any vector v (rt1*rt2)*v = rt1*(rt2*v) */ Transformation3D operator*(const Transformation3D &tr) const { return compose(*this, tr); } const Transformation3D& operator*=(const Transformation3D &o) { *this=compose(*this, o); return *this; } /** Compute the transformation which, when composed with b, gives *this. That is a(x)== d(b(x)) for all x. For consistency, this should probably have a nice name, but I don't know what name to give it. */ Transformation3D operator/(const Transformation3D &b) const { Transformation3D ret= compose(*this, b.get_inverse()); return ret; } const Transformation3D& operator/=(const Transformation3D &o) { *this= *this/o; return *this; } const Rotation3D& get_rotation() const { return rot_; } const Vector3D& get_translation()const{return trans_;} IMP_SHOWABLE_INLINE(Transformation3D, { rot_.show(out); out<<" || "< get_transformed(const BoundingBoxD<3> &bb, const Transformation3D &tr) { BoundingBoxD<3> nbb; for (unsigned int i=0; i< 2; ++i) { for (unsigned int j=0; j< 2; ++j) { for (unsigned int k=0; k< 2; ++k) { algebra::Vector3D v(bb.get_corner(i)[0], bb.get_corner(j)[1], bb.get_corner(k)[2]); nbb+= tr.get_transformed(v); } } } return nbb; } IMPALGEBRA_END_NAMESPACE #endif /* IMPALGEBRA_TRANSFORMATION_3D_H */