vec.cpp
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 #include "domUtils.h"
24 #include "vec.h"
25 
26 // Most of the methods are declared inline in vec.h
27 
28 using namespace qglviewer;
29 using namespace std;
30 
34 void Vec::projectOnAxis(const Vec& direction)
35 {
36 #ifndef QT_NO_DEBUG
37  if (direction.squaredNorm() < 1.0E-10)
38  qWarning("Vec::projectOnAxis: axis direction is not normalized (norm=%f).", direction.norm());
39 #endif
40 
41  *this = (((*this)*direction) / direction.squaredNorm()) * direction;
42 }
43 
47 void Vec::projectOnPlane(const Vec& normal)
48 {
49 #ifndef QT_NO_DEBUG
50  if (normal.squaredNorm() < 1.0E-10)
51  qWarning("Vec::projectOnPlane: plane normal is not normalized (norm=%f).", normal.norm());
52 #endif
53 
54  *this -= (((*this)*normal) / normal.squaredNorm()) * normal;
55 }
56 
60 {
61  // Find smallest component. Keep equal case for null values.
62  if ((fabs(y) >= 0.9*fabs(x)) && (fabs(z) >= 0.9*fabs(x)))
63  return Vec(0.0, -z, y);
64  else
65  if ((fabs(x) >= 0.9*fabs(y)) && (fabs(z) >= 0.9*fabs(y)))
66  return Vec(-z, 0.0, x);
67  else
68  return Vec(-y, x, 0.0);
69 }
70 
78 Vec::Vec(const QDomElement& element)
79 {
80  QStringList attribute;
81  attribute << "x" << "y" << "z";
82  for (int i=0; i<attribute.size(); ++i)
83 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED
84  this->operator[](i) = DomUtils::qrealFromDom(element, attribute[i], 0.0);
85 #else
86  v_[i] = DomUtils::qrealFromDom(element, attribute[i], 0.0);
87 #endif
88 }
89 
124 QDomElement Vec::domElement(const QString& name, QDomDocument& document) const
125 {
126  QDomElement de = document.createElement(name);
127  de.setAttribute("x", QString::number(x));
128  de.setAttribute("y", QString::number(y));
129  de.setAttribute("z", QString::number(z));
130  return de;
131 }
132 
154 void Vec::initFromDOMElement(const QDomElement& element)
155 {
156  const Vec v(element);
157  *this = v;
158 }
159 
160 ostream& operator<<(ostream& o, const Vec& v)
161 {
162  return o << v.x << '\t' << v.y << '\t' << v.z;
163 }
164 
qglviewer::Vec::domElement
QDomElement domElement(const QString &name, QDomDocument &document) const
Definition: vec.cpp:124
qglviewer::Vec::Vec
Vec()
Definition: vec.h:109
domUtils.h
qglviewer::Vec
The Vec class represents 3D positions and 3D vectors.
Definition: vec.h:85
qglviewer::Vec::projectOnAxis
void projectOnAxis(const Vec &direction)
Definition: vec.cpp:34
qglviewer::Vec::norm
qreal norm() const
Definition: vec.h:355
qglviewer::Vec::x
qreal x
Definition: vec.h:101
qglviewer
Definition: camera.h:29
operator<<
ostream & operator<<(ostream &o, const Vec &v)
Definition: vec.cpp:160
qglviewer::Vec::z
qreal z
Definition: vec.h:101
vec.h
qglviewer::Vec::squaredNorm
qreal squaredNorm() const
Definition: vec.h:352
qglviewer::Vec::projectOnPlane
void projectOnPlane(const Vec &normal)
Definition: vec.cpp:47
DomUtils::qrealFromDom
static qreal qrealFromDom(const QDomElement &e, const QString &attribute, qreal defValue)
Definition: domUtils.h:64
qglviewer::Vec::initFromDOMElement
void initFromDOMElement(const QDomElement &element)
Definition: vec.cpp:154
qglviewer::Vec::orthogonalVec
Vec orthogonalVec() const
Definition: vec.cpp:59
qglviewer::Vec::y
qreal y
Definition: vec.h:101


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Apr 3 2025 02:40:44