vec.cpp
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 #include "domUtils.h"
00024 #include "vec.h"
00025 
00026 // Most of the methods are declared inline in vec.h
00027 
00028 using namespace qglviewer;
00029 using namespace std;
00030 
00034 void Vec::projectOnAxis(const Vec& direction)
00035 {
00036 #ifndef QT_NO_DEBUG
00037   if (direction.squaredNorm() < 1.0E-10)
00038     qWarning("Vec::projectOnAxis: axis direction is not normalized (norm=%f).", direction.norm());
00039 #endif
00040 
00041   *this = (((*this)*direction) / direction.squaredNorm()) * direction;
00042 }
00043 
00047 void Vec::projectOnPlane(const Vec& normal)
00048 {
00049 #ifndef QT_NO_DEBUG
00050   if (normal.squaredNorm() < 1.0E-10)
00051     qWarning("Vec::projectOnPlane: plane normal is not normalized (norm=%f).", normal.norm());
00052 #endif
00053 
00054   *this -= (((*this)*normal) / normal.squaredNorm()) * normal;
00055 }
00056 
00059 Vec Vec::orthogonalVec() const
00060 {
00061   // Find smallest component. Keep equal case for null values.
00062   if ((fabs(y) >= 0.9*fabs(x)) && (fabs(z) >= 0.9*fabs(x)))
00063     return Vec(0.0, -z, y);
00064   else
00065     if ((fabs(x) >= 0.9*fabs(y)) && (fabs(z) >= 0.9*fabs(y)))
00066       return Vec(-z, 0.0, x);
00067     else
00068       return Vec(-y, x, 0.0);
00069 }
00070 
00078 Vec::Vec(const QDomElement& element)
00079 {
00080   QStringList attribute;
00081   attribute << "x" << "y" << "z";
00082 #if QT_VERSION >= 0x040000
00083   for (int i=0; i<attribute.size(); ++i)
00084 #else
00085   for (unsigned int i=0; i<attribute.count(); ++i)
00086 #endif
00087 #ifdef QGLVIEWER_UNION_NOT_SUPPORTED
00088     this->operator[](i) = DomUtils::doubleFromDom(element, attribute[i], 0.0);
00089 #else
00090     v_[i] = DomUtils::doubleFromDom(element, attribute[i], 0.0);
00091 #endif
00092 }
00093 
00128 QDomElement Vec::domElement(const QString& name, QDomDocument& document) const
00129 {
00130   QDomElement de = document.createElement(name);
00131   de.setAttribute("x", QString::number(x));
00132   de.setAttribute("y", QString::number(y));
00133   de.setAttribute("z", QString::number(z));
00134   return de;
00135 }
00136 
00158 void Vec::initFromDOMElement(const QDomElement& element)
00159 {
00160   const Vec v(element);
00161   *this = v;
00162 }
00163 
00164 ostream& operator<<(ostream& o, const Vec& v)
00165 {
00166   return o << v.x << '\t' << v.y << '\t' << v.z;
00167 }
00168 


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Aug 27 2015 14:13:26