Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #include "domUtils.h"
00024 #include "vec.h"
00025 
00026 
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   
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