frame.h
Go to the documentation of this file.
1 /****************************************************************************
2 
3  Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
4 
5  This file is part of the QGLViewer library version 2.6.3.
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 #include <QObject>
27 #include <QString>
28 
29 #include "constraint.h"
30 // #include "GL/gl.h" is now included in config.h for ease of configuration
31 
32 namespace qglviewer {
121 class QGLVIEWER_EXPORT Frame : public QObject
122 {
123  Q_OBJECT
124 
125 public:
126  Frame();
127 
129  virtual ~Frame() {}
130 
131  Frame(const Frame& frame);
132  Frame& operator=(const Frame& frame);
133 
134 Q_SIGNALS:
158  void modified();
159 
167  void interpolated();
168 
169 public:
172  Frame(const Vec& position, const Quaternion& orientation);
173 
174  void setPosition(const Vec& position);
175  void setPosition(qreal x, qreal y, qreal z);
176  void setPositionWithConstraint(Vec& position);
177 
178  void setOrientation(const Quaternion& orientation);
179  void setOrientation(qreal q0, qreal q1, qreal q2, qreal q3);
180  void setOrientationWithConstraint(Quaternion& orientation);
181 
182  void setPositionAndOrientation(const Vec& position, const Quaternion& orientation);
183  void setPositionAndOrientationWithConstraint(Vec& position, Quaternion& orientation);
184 
185  Vec position() const;
186  Quaternion orientation() const;
187 
188  void getPosition(qreal& x, qreal& y, qreal& z) const;
189  void getOrientation(qreal& q0, qreal& q1, qreal& q2, qreal& q3) const;
191 
192 
193 public:
201  void setTranslation(const Vec& translation) { t_ = translation; Q_EMIT modified(); }
202  void setTranslation(qreal x, qreal y, qreal z);
203  void setTranslationWithConstraint(Vec& translation);
204 
215  void setRotation(const Quaternion& rotation) { q_ = rotation; Q_EMIT modified(); }
216  void setRotation(qreal q0, qreal q1, qreal q2, qreal q3);
217  void setRotationWithConstraint(Quaternion& rotation);
218 
219  void setTranslationAndRotation(const Vec& translation, const Quaternion& rotation);
220  void setTranslationAndRotationWithConstraint(Vec& translation, Quaternion& rotation);
221 
228  Vec translation() const { return t_; }
237  Quaternion rotation() const { return q_; }
238 
239  void getTranslation(qreal& x, qreal& y, qreal& z) const;
240  void getRotation(qreal& q0, qreal& q1, qreal& q2, qreal& q3) const;
242 
243 public:
262  const Frame* referenceFrame() const { return referenceFrame_; }
263  void setReferenceFrame(const Frame* const refFrame);
264  bool settingAsReferenceFrameWillCreateALoop(const Frame* const frame);
266 
267 
270  void translate(Vec& t);
271  void translate(const Vec& t);
272  // Some compilers complain about "overloading cannot distinguish from previous declaration"
273  // Simply comment out the following method and its associated implementation
274  void translate(qreal x, qreal y, qreal z);
275  void translate(qreal& x, qreal& y, qreal& z);
276 
277  void rotate(Quaternion& q);
278  void rotate(const Quaternion& q);
279  // Some compilers complain about "overloading cannot distinguish from previous declaration"
280  // Simply comment out the following method and its associated implementation
281  void rotate(qreal q0, qreal q1, qreal q2, qreal q3);
282  void rotate(qreal& q0, qreal& q1, qreal& q2, qreal& q3);
283 
284  void rotateAroundPoint(Quaternion& rotation, const Vec& point);
285  void rotateAroundPoint(const Quaternion& rotation, const Vec& point);
286 
287  void alignWithFrame(const Frame* const frame, bool move=false, qreal threshold=0.0);
288  void projectOnLine(const Vec& origin, const Vec& direction);
290 
291 
294  Vec coordinatesOf(const Vec& src) const;
295  Vec inverseCoordinatesOf(const Vec& src) const;
296  Vec localCoordinatesOf(const Vec& src) const;
297  Vec localInverseCoordinatesOf(const Vec& src) const;
298  Vec coordinatesOfIn(const Vec& src, const Frame* const in) const;
299  Vec coordinatesOfFrom(const Vec& src, const Frame* const from) const;
300 
301  void getCoordinatesOf(const qreal src[3], qreal res[3]) const;
302  void getInverseCoordinatesOf(const qreal src[3], qreal res[3]) const;
303  void getLocalCoordinatesOf(const qreal src[3], qreal res[3]) const;
304  void getLocalInverseCoordinatesOf(const qreal src[3], qreal res[3]) const;
305  void getCoordinatesOfIn(const qreal src[3], qreal res[3], const Frame* const in) const;
306  void getCoordinatesOfFrom(const qreal src[3], qreal res[3], const Frame* const from) const;
308 
310  // A frame is as a new coordinate system, defined with respect to a reference frame (the world
311  // coordinate system by default, see the "Composition of frame" section).
312 
313  // The transformOf() (resp. inverseTransformOf()) functions transform a 3D vector from (resp.
314  // to) the world coordinates system. This section defines the 3D vector transformation
315  // functions. See the Coordinate system transformation of 3D points above for the transformation
316  // of 3D points. The difference between the two sets of functions is simple: for vectors, only
317  // the rotational part of the transformations is taken into account, while translation is also
318  // considered for 3D points.
319 
320  // The length of the resulting transformed vector is identical to the one of the source vector
321  // for all the described functions.
322 
323  // When local is prepended to the names of the functions, the functions simply transform from
324  // (and to) the reference frame.
325 
326  // When In (resp. From) is appended to the names, the functions transform from (resp. To) the
327  // frame that is given as an argument. The frame does not need to be in the same branch or the
328  // hierarchical tree, and can be \c NULL (the world coordinates system).
329 
330  // Combining any of these functions with its inverse (in any order) leads to the identity.
332  Vec transformOf(const Vec& src) const;
333  Vec inverseTransformOf(const Vec& src) const;
334  Vec localTransformOf(const Vec& src) const;
335  Vec localInverseTransformOf(const Vec& src) const;
336  Vec transformOfIn(const Vec& src, const Frame* const in) const;
337  Vec transformOfFrom(const Vec& src, const Frame* const from) const;
338 
339  void getTransformOf(const qreal src[3], qreal res[3]) const;
340  void getInverseTransformOf(const qreal src[3], qreal res[3]) const;
341  void getLocalTransformOf(const qreal src[3], qreal res[3]) const;
342  void getLocalInverseTransformOf(const qreal src[3], qreal res[3]) const;
343  void getTransformOfIn(const qreal src[3], qreal res[3], const Frame* const in) const;
344  void getTransformOfFrom(const qreal src[3], qreal res[3], const Frame* const from) const;
346 
347 
356  Constraint* constraint() const { return constraint_; }
361  void setConstraint(Constraint* const constraint) { constraint_ = constraint; }
363 
366 public:
367  const GLdouble* matrix() const;
368  void getMatrix(GLdouble m[4][4]) const;
369  void getMatrix(GLdouble m[16]) const;
370 
371  const GLdouble* worldMatrix() const;
372  void getWorldMatrix(GLdouble m[4][4]) const;
373  void getWorldMatrix(GLdouble m[16]) const;
374 
375  void setFromMatrix(const GLdouble m[4][4]);
376  void setFromMatrix(const GLdouble m[16]);
378 
381  Frame inverse() const;
390  Frame worldInverse() const { return Frame(-(orientation().inverseRotate(position())), orientation().inverse()); }
392 
395 public:
396  virtual QDomElement domElement(const QString& name, QDomDocument& document) const;
397 public Q_SLOTS:
398  virtual void initFromDOMElement(const QDomElement& element);
400 
401 private:
402  // P o s i t i o n a n d o r i e n t a t i o n
405 
406  // C o n s t r a i n t s
408 
409  // F r a m e c o m p o s i t i o n
411 };
412 
413 } // namespace qglviewer
414 
415 #endif // QGLVIEWER_FRAME_H
Constraint * constraint_
Definition: frame.h:407
void setConstraint(Constraint *const constraint)
Definition: frame.h:361
Frame worldInverse() const
Definition: frame.h:390
void setRotation(const Quaternion &rotation)
Definition: frame.h:215
#define QGLVIEWER_EXPORT
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:65
void setTranslation(const Vec &translation)
Definition: frame.h:201
Quaternion rotation() const
Definition: frame.h:237
Quaternion q_
Definition: frame.h:404
The Quaternion class represents 3D rotations and orientations.
Definition: quaternion.h:66
virtual ~Frame()
Definition: frame.h:129
Constraint * constraint() const
Definition: frame.h:356
const Frame * referenceFrame_
Definition: frame.h:410
The Frame class represents a coordinate system, defined by a position and an orientation.
Definition: frame.h:121
const Frame * referenceFrame() const
Definition: frame.h:262
Vec translation() const
Definition: frame.h:228
An interface class for Frame constraints.
Definition: constraint.h:117


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Wed Jun 5 2019 19:26:39