frame.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00004 
00005  This file is part of the QGLViewer library version 2.4.0.
00006 
00007  http://www.libqglviewer.com - contact@libqglviewer.com
00008 
00009  This file may be used under the terms of the GNU General Public License 
00010  versions 2.0 or 3.0 as published by the Free Software Foundation and
00011  appearing in the LICENSE file included in the packaging of this file.
00012  In addition, as a special exception, Gilles Debunne gives you certain 
00013  additional rights, described in the file GPL_EXCEPTION in this package.
00014 
00015  libQGLViewer uses dual licensing. Commercial/proprietary software must
00016  purchase a libQGLViewer Commercial License.
00017 
00018  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00019  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00020 
00021 *****************************************************************************/
00022 
00023 #ifndef QGLVIEWER_FRAME_H
00024 #define QGLVIEWER_FRAME_H
00025 
00026 #if QT_VERSION >= 0x040000
00027 # include <QObject>
00028 # include <QString>
00029 #else
00030 # include <qobject.h>
00031 # include <qstring.h>
00032 #endif
00033 
00034 #include "constraint.h"
00035 // #include "GL/gl.h" is now included in config.h for ease of configuration
00036 
00037 namespace qglviewer {
00126   class QGLVIEWER_EXPORT Frame : public QObject
00127   {
00128     Q_OBJECT
00129 
00130   public:
00131     Frame();
00132 
00134     virtual ~Frame() {};
00135 
00136     Frame(const Frame& frame);
00137     Frame& operator=(const Frame& frame);
00138 
00139   Q_SIGNALS:
00163     void modified();
00164 
00172     void interpolated();
00173 
00174   public:
00177     Frame(const Vec& position, const Quaternion& orientation);
00178 
00179     void setPosition(const Vec& position);
00180     void setPosition(float x, float y, float z);
00181     void setPositionWithConstraint(Vec& position);
00182 
00183     void setOrientation(const Quaternion& orientation);
00184     void setOrientation(double q0, double q1, double q2, double q3);
00185     void setOrientationWithConstraint(Quaternion& orientation);
00186 
00187     void setPositionAndOrientation(const Vec& position, const Quaternion& orientation);
00188     void setPositionAndOrientationWithConstraint(Vec& position, Quaternion& orientation);
00189 
00192     Vec position() const { return inverseCoordinatesOf(Vec(0.0,0.0,0.0)); };
00193     Quaternion orientation() const;
00194 
00195     void getPosition(float& x, float& y, float& z) const;
00196     void getOrientation(double& q0, double& q1, double& q2, double& q3) const;
00198 
00199 
00200     public:
00208     void setTranslation(const Vec& translation) { t_ = translation; Q_EMIT modified(); };
00209     void setTranslation(float x, float y, float z);
00210     void setTranslationWithConstraint(Vec& translation);
00211 
00222     void setRotation(const Quaternion& rotation) { q_ = rotation; Q_EMIT modified(); };
00223     void setRotation(double q0, double q1, double q2, double q3);
00224     void setRotationWithConstraint(Quaternion& rotation);
00225 
00226     void setTranslationAndRotation(const Vec& translation, const Quaternion& rotation);
00227     void setTranslationAndRotationWithConstraint(Vec& translation, Quaternion& rotation);
00228 
00235     Vec translation() const { return t_; };
00244     Quaternion rotation() const { return q_; };
00245 
00246     void getTranslation(float& x, float& y, float& z) const;
00247     void getRotation(double& q0, double& q1, double& q2, double& q3) const;
00249 
00250     public:
00269     const Frame* referenceFrame() const { return referenceFrame_; };
00270     void setReferenceFrame(const Frame* const refFrame);
00271     bool settingAsReferenceFrameWillCreateALoop(const Frame* const frame);
00273 
00274 
00277     void translate(Vec& t);
00278     void translate(const Vec& t);
00279     // Some compilers complain about "overloading cannot distinguish from previous declaration"
00280     // Simply comment out the following method and its associated implementation
00281     void translate(float x, float y, float z);
00282     void translate(float& x, float& y, float& z);
00283 
00284     void rotate(Quaternion& q);
00285     void rotate(const Quaternion& q);
00286     // Some compilers complain about "overloading cannot distinguish from previous declaration"
00287     // Simply comment out the following method and its associated implementation
00288     void rotate(double q0, double q1, double q2, double q3);
00289     void rotate(double& q0, double& q1, double& q2, double& q3);
00290 
00291     void rotateAroundPoint(Quaternion& rotation, const Vec& point);
00292     void rotateAroundPoint(const Quaternion& rotation, const Vec& point);
00293 
00294     void alignWithFrame(const Frame* const frame, bool move=false, float threshold=0.85f);
00295     void projectOnLine(const Vec& origin, const Vec& direction);
00297 
00298 
00301     Vec coordinatesOf(const Vec& src) const;
00302     Vec inverseCoordinatesOf(const Vec& src) const;
00303     Vec localCoordinatesOf(const Vec& src) const;
00304     Vec localInverseCoordinatesOf(const Vec& src) const;
00305     Vec coordinatesOfIn(const Vec& src, const Frame* const in) const;
00306     Vec coordinatesOfFrom(const Vec& src, const Frame* const from) const;
00307 
00308     void getCoordinatesOf(const float src[3], float res[3]) const;
00309     void getInverseCoordinatesOf(const float src[3], float res[3]) const;
00310     void getLocalCoordinatesOf(const float src[3], float res[3]) const;
00311     void getLocalInverseCoordinatesOf(const float src[3], float res[3]) const;
00312     void getCoordinatesOfIn(const float src[3], float res[3], const Frame* const in) const;
00313     void getCoordinatesOfFrom(const float src[3], float res[3], const Frame* const from) const;
00315 
00317     // A frame is as a new coordinate system, defined with respect to a reference frame (the world
00318     // coordinate system by default, see the "Composition of frame" section).
00319 
00320     // The transformOf() (resp. inverseTransformOf()) functions transform a 3D vector from (resp.
00321     // to) the world coordinates system. This section defines the 3D vector transformation
00322     // functions. See the Coordinate system transformation of 3D points above for the transformation
00323     // of 3D points. The difference between the two sets of functions is simple: for vectors, only
00324     // the rotational part of the transformations is taken into account, while translation is also
00325     // considered for 3D points.
00326 
00327     // The length of the resulting transformed vector is identical to the one of the source vector
00328     // for all the described functions.
00329 
00330     // When local is prepended to the names of the functions, the functions simply transform from
00331     // (and to) the reference frame.
00332 
00333     // When In (resp. From) is appended to the names, the functions transform from (resp. To) the
00334     // frame that is given as an argument. The frame does not need to be in the same branch or the
00335     // hierarchical tree, and can be \c NULL (the world coordinates system).
00336 
00337     // Combining any of these functions with its inverse (in any order) leads to the identity.
00339     Vec transformOf(const Vec& src) const;
00340     Vec inverseTransformOf(const Vec& src) const;
00341     Vec localTransformOf(const Vec& src) const;
00342     Vec localInverseTransformOf(const Vec& src) const;
00343     Vec transformOfIn(const Vec& src, const Frame* const in) const;
00344     Vec transformOfFrom(const Vec& src, const Frame* const from) const;
00345 
00346     void getTransformOf(const float src[3], float res[3]) const;
00347     void getInverseTransformOf(const float src[3], float res[3]) const;
00348     void getLocalTransformOf(const float src[3], float res[3]) const;
00349     void getLocalInverseTransformOf(const float src[3], float res[3]) const;
00350     void getTransformOfIn(const float src[3], float res[3], const Frame* const in) const;
00351     void getTransformOfFrom(const float src[3], float res[3], const Frame* const from) const;
00353 
00354 
00363     Constraint* constraint() const { return constraint_; }
00368     void setConstraint(Constraint* const constraint) { constraint_ = constraint; }
00370 
00373   public:
00374     const GLdouble* matrix() const;
00375     void getMatrix(GLdouble m[4][4]) const;
00376     void getMatrix(GLdouble m[16]) const;
00377 
00378     const GLdouble* worldMatrix() const;
00379     void getWorldMatrix(GLdouble m[4][4]) const;
00380     void getWorldMatrix(GLdouble m[16]) const;
00381 
00382     void setFromMatrix(const GLdouble m[4][4]);
00383     void setFromMatrix(const GLdouble m[16]);
00385 
00388     Frame inverse() const;
00397     Frame worldInverse() const { return Frame(-(orientation().inverseRotate(position())), orientation().inverse()); }
00399 
00402   public:
00403     virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
00404   public Q_SLOTS:
00405     virtual void initFromDOMElement(const QDomElement& element);
00407 
00408   private:
00409     // P o s i t i o n   a n d   o r i e n t a t i o n
00410     Vec t_;
00411     Quaternion q_;
00412 
00413     // C o n s t r a i n t s
00414     Constraint* constraint_;
00415 
00416     // F r a m e   c o m p o s i t i o n
00417     const Frame* referenceFrame_;
00418   };
00419 
00420 } // namespace qglviewer
00421 
00422 #endif // QGLVIEWER_FRAME_H


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Jun 6 2019 17:31:58