frame.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.4.0.
6 
7  http://www.libqglviewer.com - contact@libqglviewer.com
8 
9  This file may be used under the terms of the GNU General Public License
10  versions 2.0 or 3.0 as published by the Free Software Foundation and
11  appearing in the LICENSE file included in the packaging of this file.
12  In addition, as a special exception, Gilles Debunne gives you certain
13  additional rights, described in the file GPL_EXCEPTION in this package.
14 
15  libQGLViewer uses dual licensing. Commercial/proprietary software must
16  purchase a libQGLViewer Commercial License.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21 *****************************************************************************/
22 
23 #ifndef QGLVIEWER_FRAME_H
24 #define QGLVIEWER_FRAME_H
25 
26 #if QT_VERSION >= 0x040000
27 # include <QObject>
28 # include <QString>
29 #else
30 # include <qobject.h>
31 # include <qstring.h>
32 #endif
33 
34 #include "constraint.h"
35 // #include "GL/gl.h" is now included in config.h for ease of configuration
36 
37 namespace qglviewer {
126  class QGLVIEWER_EXPORT Frame : public QObject
127  {
128  Q_OBJECT
129 
130  public:
131  Frame();
132 
134  virtual ~Frame() {};
135 
136  Frame(const Frame& frame);
137  Frame& operator=(const Frame& frame);
138 
139  Q_SIGNALS:
163  void modified();
164 
172  void interpolated();
173 
174  public:
177  Frame(const Vec& position, const Quaternion& orientation);
178 
179  void setPosition(const Vec& position);
180  void setPosition(float x, float y, float z);
181  void setPositionWithConstraint(Vec& position);
182 
183  void setOrientation(const Quaternion& orientation);
184  void setOrientation(double q0, double q1, double q2, double q3);
185  void setOrientationWithConstraint(Quaternion& orientation);
186 
187  void setPositionAndOrientation(const Vec& position, const Quaternion& orientation);
188  void setPositionAndOrientationWithConstraint(Vec& position, Quaternion& orientation);
189 
192  Vec position() const { return inverseCoordinatesOf(Vec(0.0,0.0,0.0)); };
193  Quaternion orientation() const;
194 
195  void getPosition(float& x, float& y, float& z) const;
196  void getOrientation(double& q0, double& q1, double& q2, double& q3) const;
198 
199 
200  public:
208  void setTranslation(const Vec& translation) { t_ = translation; Q_EMIT modified(); };
209  void setTranslation(float x, float y, float z);
210  void setTranslationWithConstraint(Vec& translation);
211 
222  void setRotation(const Quaternion& rotation) { q_ = rotation; Q_EMIT modified(); };
223  void setRotation(double q0, double q1, double q2, double q3);
224  void setRotationWithConstraint(Quaternion& rotation);
225 
226  void setTranslationAndRotation(const Vec& translation, const Quaternion& rotation);
227  void setTranslationAndRotationWithConstraint(Vec& translation, Quaternion& rotation);
228 
235  Vec translation() const { return t_; };
244  Quaternion rotation() const { return q_; };
245 
246  void getTranslation(float& x, float& y, float& z) const;
247  void getRotation(double& q0, double& q1, double& q2, double& q3) const;
249 
250  public:
269  const Frame* referenceFrame() const { return referenceFrame_; };
270  void setReferenceFrame(const Frame* const refFrame);
271  bool settingAsReferenceFrameWillCreateALoop(const Frame* const frame);
273 
274 
277  void translate(Vec& t);
278  void translate(const Vec& t);
279  // Some compilers complain about "overloading cannot distinguish from previous declaration"
280  // Simply comment out the following method and its associated implementation
281  void translate(float x, float y, float z);
282  void translate(float& x, float& y, float& z);
283 
284  void rotate(Quaternion& q);
285  void rotate(const Quaternion& q);
286  // Some compilers complain about "overloading cannot distinguish from previous declaration"
287  // Simply comment out the following method and its associated implementation
288  void rotate(double q0, double q1, double q2, double q3);
289  void rotate(double& q0, double& q1, double& q2, double& q3);
290 
291  void rotateAroundPoint(Quaternion& rotation, const Vec& point);
292  void rotateAroundPoint(const Quaternion& rotation, const Vec& point);
293 
294  void alignWithFrame(const Frame* const frame, bool move=false, float threshold=0.85f);
295  void projectOnLine(const Vec& origin, const Vec& direction);
297 
298 
301  Vec coordinatesOf(const Vec& src) const;
302  Vec inverseCoordinatesOf(const Vec& src) const;
303  Vec localCoordinatesOf(const Vec& src) const;
304  Vec localInverseCoordinatesOf(const Vec& src) const;
305  Vec coordinatesOfIn(const Vec& src, const Frame* const in) const;
306  Vec coordinatesOfFrom(const Vec& src, const Frame* const from) const;
307 
308  void getCoordinatesOf(const float src[3], float res[3]) const;
309  void getInverseCoordinatesOf(const float src[3], float res[3]) const;
310  void getLocalCoordinatesOf(const float src[3], float res[3]) const;
311  void getLocalInverseCoordinatesOf(const float src[3], float res[3]) const;
312  void getCoordinatesOfIn(const float src[3], float res[3], const Frame* const in) const;
313  void getCoordinatesOfFrom(const float src[3], float res[3], const Frame* const from) const;
315 
317  // A frame is as a new coordinate system, defined with respect to a reference frame (the world
318  // coordinate system by default, see the "Composition of frame" section).
319 
320  // The transformOf() (resp. inverseTransformOf()) functions transform a 3D vector from (resp.
321  // to) the world coordinates system. This section defines the 3D vector transformation
322  // functions. See the Coordinate system transformation of 3D points above for the transformation
323  // of 3D points. The difference between the two sets of functions is simple: for vectors, only
324  // the rotational part of the transformations is taken into account, while translation is also
325  // considered for 3D points.
326 
327  // The length of the resulting transformed vector is identical to the one of the source vector
328  // for all the described functions.
329 
330  // When local is prepended to the names of the functions, the functions simply transform from
331  // (and to) the reference frame.
332 
333  // When In (resp. From) is appended to the names, the functions transform from (resp. To) the
334  // frame that is given as an argument. The frame does not need to be in the same branch or the
335  // hierarchical tree, and can be \c NULL (the world coordinates system).
336 
337  // Combining any of these functions with its inverse (in any order) leads to the identity.
339  Vec transformOf(const Vec& src) const;
340  Vec inverseTransformOf(const Vec& src) const;
341  Vec localTransformOf(const Vec& src) const;
342  Vec localInverseTransformOf(const Vec& src) const;
343  Vec transformOfIn(const Vec& src, const Frame* const in) const;
344  Vec transformOfFrom(const Vec& src, const Frame* const from) const;
345 
346  void getTransformOf(const float src[3], float res[3]) const;
347  void getInverseTransformOf(const float src[3], float res[3]) const;
348  void getLocalTransformOf(const float src[3], float res[3]) const;
349  void getLocalInverseTransformOf(const float src[3], float res[3]) const;
350  void getTransformOfIn(const float src[3], float res[3], const Frame* const in) const;
351  void getTransformOfFrom(const float src[3], float res[3], const Frame* const from) const;
353 
354 
363  Constraint* constraint() const { return constraint_; }
368  void setConstraint(Constraint* const constraint) { constraint_ = constraint; }
370 
373  public:
374  const GLdouble* matrix() const;
375  void getMatrix(GLdouble m[4][4]) const;
376  void getMatrix(GLdouble m[16]) const;
377 
378  const GLdouble* worldMatrix() const;
379  void getWorldMatrix(GLdouble m[4][4]) const;
380  void getWorldMatrix(GLdouble m[16]) const;
381 
382  void setFromMatrix(const GLdouble m[4][4]);
383  void setFromMatrix(const GLdouble m[16]);
385 
388  Frame inverse() const;
397  Frame worldInverse() const { return Frame(-(orientation().inverseRotate(position())), orientation().inverse()); }
399 
402  public:
403  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
404  public Q_SLOTS:
405  virtual void initFromDOMElement(const QDomElement& element);
407 
408  private:
409  // P o s i t i o n a n d o r i e n t a t i o n
412 
413  // C o n s t r a i n t s
415 
416  // F r a m e c o m p o s i t i o n
418  };
419 
420 } // namespace qglviewer
421 
422 #endif // QGLVIEWER_FRAME_H
Constraint * constraint_
Definition: frame.h:414
Vec position() const
Definition: frame.h:192
void setConstraint(Constraint *const constraint)
Definition: frame.h:368
Frame worldInverse() const
Definition: frame.h:397
#define Q_SLOTS
Definition: config.h:119
void setRotation(const Quaternion &rotation)
Definition: frame.h:222
#define QGLVIEWER_EXPORT
Definition: config.h:75
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:69
#define Q_SIGNALS
Definition: config.h:120
void setTranslation(const Vec &translation)
Definition: frame.h:208
Quaternion rotation() const
Definition: frame.h:244
Quaternion q_
Definition: frame.h:411
#define Q_EMIT
Definition: config.h:121
The Quaternion class represents 3D rotations and orientations.
Definition: quaternion.h:66
virtual ~Frame()
Definition: frame.h:134
Constraint * constraint() const
Definition: frame.h:363
const Frame * referenceFrame_
Definition: frame.h:417
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:126
const Frame * referenceFrame() const
Definition: frame.h:269
Vec translation() const
Definition: frame.h:235
An interface class for Frame constraints.
Definition: constraint.h:117


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Mon Jun 10 2019 14:00:24