/usr/include/QGLViewer/vec.h is in libqglviewer-dev 2.5.3+dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | /****************************************************************************
Copyright (C) 2002-2014 Gilles Debunne. All rights reserved.
This file is part of the QGLViewer library version 2.5.3.
http://www.libqglviewer.com - contact@libqglviewer.com
This file may be used under the terms of the GNU General Public License
versions 2.0 or 3.0 as published by the Free Software Foundation and
appearing in the LICENSE file included in the packaging of this file.
In addition, as a special exception, Gilles Debunne gives you certain
additional rights, described in the file GPL_EXCEPTION in this package.
libQGLViewer uses dual licensing. Commercial/proprietary software must
purchase a libQGLViewer Commercial License.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*****************************************************************************/
#ifndef QGLVIEWER_VEC_H
#define QGLVIEWER_VEC_H
#include <math.h>
#include <iostream>
# include <QDomElement>
// Included by all files as vec.h is at the end of the include hierarchy
#include "config.h" // Specific configuration options.
namespace qglviewer {
/*! \brief The Vec class represents 3D positions and 3D vectors.
\class Vec vec.h QGLViewer/vec.h
Vec is used as a parameter and return type by many methods of the library. It provides classical
algebraic computational methods and is compatible with OpenGL:
\code
// Draws a point located at 3.0 OpenGL units in front of the camera
Vec pos = camera()->position() + 3.0 * camera()->viewDirection();
glBegin(GL_POINTS);
glVertex3fv(pos);
glEnd();
\endcode
This makes of Vec a good candidate for representing positions and vectors in your programs. Since
it is part of the \c qglviewer namespace, specify \c qglviewer::Vec or use the qglviewer
namespace:
\code
using namespace qglviewer;
\endcode
<h3>Interface with other vector classes</h3>
Vec implements a universal explicit converter, based on the \c [] \c operator.
Everywhere a \c const \c Vec& argument is expected, you can use your own vector type
instead, as long as it implements this operator (see the Vec(const C& c) documentation).
See also the Quaternion and the Frame documentations.
\nosubgrouping */
class QGLVIEWER_EXPORT Vec
{
// If your compiler complains the "The class "qglviewer::Vec" has no member "x"."
// Add your architecture Q_OS_XXXX flag (see qglobal.h) in this list.
#if defined (Q_OS_IRIX) || defined (Q_OS_AIX) || defined (Q_OS_HPUX)
# define QGLVIEWER_UNION_NOT_SUPPORTED
#endif
public:
/*! The internal data representation is public. One can use v.x, v.y, v.z. See also operator[](). */
#if defined (DOXYGEN) || defined (QGLVIEWER_UNION_NOT_SUPPORTED)
double x, y, z;
#else
union
{
struct { double x, y, z; };
double v_[3];
};
#endif
/*! @name Setting the value */
//@{
/*! Default constructor. Value is set to (0,0,0). */
Vec() : x(0.0), y(0.0), z(0.0) {}
/*! Standard constructor with the x, y and z values. */
Vec(double X, double Y, double Z) : x(X), y(Y), z(Z) {}
/*! Universal explicit converter from any class to Vec. You can use your own vector class everywhere
a \c const \c Vec& parameter is required, as long as it implements the \c operator[ ]:
\code
class MyVec
{
// ...
double operator[](int i) const { returns x, y or z when i=0, 1 or 2; }
}
MyVec v(...);
camera()->setPosition(v);
\endcode
Note that standard vector types (STL, \c double[3], ...) implement this operator and can hence
be used in place of Vec. See also operator const double*() .*/
template <class C>
explicit Vec(const C& c) : x(c[0]), y(c[1]), z(c[2]) {}
// Should NOT be explicit to prevent conflicts with operator<<.
// ! Copy constructor
// Vec(const Vec& v) : x(v.x), y(v.y), z(v.z) {}
/*! Equal operator. */
Vec& operator=(const Vec& v)
{
x = v.x; y = v.y; z = v.z;
return *this;
}
/*! Set the current value. May be faster than using operator=() with a temporary Vec(x,y,z). */
void setValue(double X, double Y, double Z)
{ x=X; y=Y; z=Z; }
// Universal equal operator which allows the use of any type in place of Vec,
// as long as the [] operator is implemented (v[0]=v.x, v[1]=v.y, v[2]=v.z).
// template <class C>
// Vec& operator=(const C& c)
// {
// x=c[0]; y=c[1]; z=c[2];
// return *this;
// }
//@}
/*! @name Accessing the value */
//@{
/*! Bracket operator, with a constant return value. \p i must range in [0..2]. */
double operator[](int i) const {
#ifdef QGLVIEWER_UNION_NOT_SUPPORTED
return (&x)[i];
#else
return v_[i];
#endif
}
/*! Bracket operator returning an l-value. \p i must range in [0..2]. */
double& operator[](int i) {
#ifdef QGLVIEWER_UNION_NOT_SUPPORTED
return (&x)[i];
#else
return v_[i];
#endif
}
#ifndef DOXYGEN
/*! This method is deprecated since version 2.0. Use operator const double* instead. */
const double* address() const { qWarning("Vec::address() is deprecated, use operator const double* instead."); return operator const double*(); }
#endif
/*! Conversion operator returning the memory address of the vector.
Very convenient to pass a Vec pointer as a parameter to OpenGL functions:
\code
Vec pos, normal;
glNormal3dv(normal);
glVertex3dv(pos);
\endcode */
operator const double*() const {
#ifdef QGLVIEWER_UNION_NOT_SUPPORTED
return &x;
#else
return v_;
#endif
}
/*! Non const conversion operator returning the memory address of the vector.
Useful to pass a Vec to a method that requires and fills a \c double*, as provided by certain libraries. */
operator double*() {
#ifdef QGLVIEWER_UNION_NOT_SUPPORTED
return &x;
#else
return v_;
#endif
}
/*! Conversion operator returning the memory address of the vector.
Very convenient to pass a Vec pointer as a parameter to OpenGL functions:
\code
Vec pos, normal;
glNormal3fv(normal);
glVertex3fv(pos);
\endcode
\note The returned float array is a static shared by all \c Vec instances. */
operator const float*() const {
static float* const result = new float[3];
result[0] = (float)x;
result[1] = (float)y;
result[2] = (float)z;
return result;
}
//@}
/*! @name Algebraic computations */
//@{
/*! Returns the sum of the two vectors. */
friend Vec operator+(const Vec &a, const Vec &b)
{
return Vec(a.x+b.x, a.y+b.y, a.z+b.z);
}
/*! Returns the difference of the two vectors. */
friend Vec operator-(const Vec &a, const Vec &b)
{
return Vec(a.x-b.x, a.y-b.y, a.z-b.z);
}
/*! Unary minus operator. */
friend Vec operator-(const Vec &a)
{
return Vec(-a.x, -a.y, -a.z);
}
/*! Returns the product of the vector with a scalar. */
friend Vec operator*(const Vec &a, double k)
{
return Vec(a.x*k, a.y*k, a.z*k);
}
/*! Returns the product of a scalar with the vector. */
friend Vec operator*(double k, const Vec &a)
{
return a*k;
}
/*! Returns the division of the vector with a scalar.
Too small \p k values are \e not tested (unless the library was compiled with the "debug" Qt \c
CONFIG flag) and may result in \c NaN values. */
friend Vec operator/(const Vec &a, double k)
{
#ifndef QT_NO_DEBUG
if (fabs(k) < 1.0E-10)
qWarning("Vec::operator / : dividing by a null value (%f)", k);
#endif
return Vec(a.x/k, a.y/k, a.z/k);
}
/*! Returns \c true only when the two vector are not equal (see operator==()). */
friend bool operator!=(const Vec &a, const Vec &b)
{
return !(a==b);
}
/*! Returns \c true when the squaredNorm() of the difference vector is lower than 1E-10. */
friend bool operator==(const Vec &a, const Vec &b)
{
const double epsilon = 1.0E-10f;
return (a-b).squaredNorm() < epsilon;
}
/*! Adds \p a to the vector. */
Vec& operator+=(const Vec &a)
{
x += a.x; y += a.y; z += a.z;
return *this;
}
/*! Subtracts \p a to the vector. */
Vec& operator-=(const Vec &a)
{
x -= a.x; y -= a.y; z -= a.z;
return *this;
}
/*! Multiply the vector by a scalar \p k. */
Vec& operator*=(double k)
{
x *= k; y *= k; z *= k;
return *this;
}
/*! Divides the vector by a scalar \p k.
An absolute \p k value lower than 1E-10 will print a warning if the library was compiled with the
"debug" Qt \c CONFIG flag. Otherwise, no test is performed for efficiency reasons. */
Vec& operator/=(double k)
{
#ifndef QT_NO_DEBUG
if (fabs(k)<1.0E-10)
qWarning("Vec::operator /= : dividing by a null value (%f)", k);
#endif
x /= k; y /= k; z /= k;
return *this;
}
/*! Dot product of the two Vec. */
friend double operator*(const Vec &a, const Vec &b)
{
return a.x*b.x + a.y*b.y + a.z*b.z;
}
/*! Cross product of the two vectors. Same as cross(). */
friend Vec operator^(const Vec &a, const Vec &b)
{
return cross(a,b);
}
/*! Cross product of the two Vec. Mind the order ! */
friend Vec cross(const Vec &a, const Vec &b)
{
return Vec(a.y*b.z - a.z*b.y,
a.z*b.x - a.x*b.z,
a.x*b.y - a.y*b.x);
}
Vec orthogonalVec() const;
//@}
/*! @name Norm of the vector */
//@{
#ifndef DOXYGEN
/*! This method is deprecated since version 2.0. Use squaredNorm() instead. */
double sqNorm() const { return x*x + y*y + z*z; }
#endif
/*! Returns the \e squared norm of the Vec. */
double squaredNorm() const { return x*x + y*y + z*z; }
/*! Returns the norm of the vector. */
double norm() const { return sqrt(x*x + y*y + z*z); }
/*! Normalizes the Vec and returns its original norm.
Normalizing a null vector will result in \c NaN values. */
double normalize()
{
const double n = norm();
#ifndef QT_NO_DEBUG
if (n < 1.0E-10)
qWarning("Vec::normalize: normalizing a null vector (norm=%f)", n);
#endif
*this /= n;
return n;
}
/*! Returns a unitary (normalized) \e representation of the vector. The original Vec is not modified. */
Vec unit() const
{
Vec v = *this;
v.normalize();
return v;
}
//@}
/*! @name Projection */
//@{
void projectOnAxis(const Vec& direction);
void projectOnPlane(const Vec& normal);
//@}
/*! @name XML representation */
//@{
explicit Vec(const QDomElement& element);
QDomElement domElement(const QString& name, QDomDocument& document) const;
void initFromDOMElement(const QDomElement& element);
//@}
#ifdef DOXYGEN
/*! @name Output stream */
//@{
/*! Output stream operator. Enables debugging code like:
\code
Vec pos(...);
cout << "Position=" << pos << endl;
\endcode */
std::ostream& operator<<(std::ostream& o, const qglviewer::Vec&);
//@}
#endif
};
} // namespace
std::ostream& operator<<(std::ostream& o, const qglviewer::Vec&);
#endif // QGLVIEWER_VEC_H
|