45 #include <Inventor/SbLinear.h> 46 #include <Inventor/nodes/SoTransform.h> 50 #include "OpCounter.h" 195 Vect3(Real x_, Real y_, Real z_) {
set(x_, y_, z_);}
199 void set(Real x_, Real y_, Real z_) {x = x_; y = y_; z = z_;}
209 inline void set(
const SbVec3f &v);
210 inline void toSbVec3f(SbVec3f &v)
const;
215 ostream &
print(ostream &os)
const;
221 istream &read(istream &is);
227 inline Real
dot(
const Vect3 &other)
const;
228 inline Real
norm()
const;
229 inline Real
norm2()
const;
230 inline Real distance (
const Vect3 &other)
const;
231 inline Real distance2(
const Vect3 &other)
const;
232 inline Real
min()
const;
233 inline Real
max()
const;
234 inline Real minAbs()
const;
235 inline Real maxAbs()
const;
236 inline void swap(
Vect3 &other);
252 inline void normalize();
253 inline void negate(
const Vect3 &v);
254 inline void negate();
255 inline void add(
const Vect3 &u,
const Vect3 &v);
256 inline void add(
const Vect3 &v);
257 inline void sub(
const Vect3 &u,
const Vect3 &v);
258 inline void sub(
const Vect3 &v);
259 inline void mult(
const Vect3 &u,
const Vect3 &v);
260 inline void mult(
const Vect3 &v);
261 inline void scale(
const Vect3 &v, Real s);
262 inline void scale(Real s);
264 inline void precross(
const Vect3 &v);
265 inline void postcross(
const Vect3 &v);
268 inline void crossAdd(
const Vect3 &u,
const Vect3 &v);
270 inline void displace(
const Vect3 &v,
const Vect3 &u, Real lambda);
272 inline void displace(
const Vect3 &u, Real lambda);
273 inline void interpolate(
const Vect3 &u,
const Vect3 &v, Real lambda);
316 Mat3(
const Vect3 &axis, Real angle,
int normalizeAxis = 1)
317 {
set(axis, angle, normalizeAxis);}
325 inline void set(
const Vect3 &diag,
const Vect3 &sym);
328 inline void set(
const Vect3 &axis, Real angle,
int normalizeAxis = 1);
329 void set(
const Quat &q);
336 inline void setSkew(
const Vect3 &v);
352 inline void setXcol(
const Vect3 &v);
353 inline void setYcol(
const Vect3 &v);
354 inline void setZcol(
const Vect3 &v);
363 ostream&
print(ostream &os)
const;
367 inline Real
det()
const;
378 inline void xpose(
const Mat3 &M);
380 inline void symmetrize(
const Mat3 &M);
381 inline void symmetrize();
382 int invert(
const Mat3 &M);
384 inline void negate(
const Mat3 &M);
385 inline void negate();
386 inline void add(
const Mat3 &M,
const Mat3 &N);
387 inline void add(
const Mat3 &M);
388 inline void sub(
const Mat3 &M,
const Mat3 &N);
389 inline void sub(
const Mat3 &M);
390 inline void scale(
const Mat3 &M, Real s);
391 inline void scale(Real s);
392 void mult(
const Mat3 &M,
const Mat3 &N);
393 void premult(
const Mat3 &M);
394 void postmult(
const Mat3 &M);
398 inline void xform(
const Vect3 &v,
Vect3 &xv)
const;
400 inline void xform(
Vect3 &v)
const;
405 inline void invXform(
const Vect3 &v,
Vect3 &xv)
const;
406 inline void invXform(
Vect3 &v)
const;
444 inline void set(
const Mat3 &R_,
const Vect3 &d_) {R = R_; d = d_;}
445 inline void set(
const Se3 &T);
454 inline ostream&
print(ostream &os)
const;
455 inline istream& read(istream &is);
463 void mult(
const MatX &M,
const MatX &N);
464 void premult(
const MatX &M);
465 void postmult(
const MatX &M);
466 void invert(
const MatX &M);
474 inline void xformVect(
const Vect3 &v,
Vect3 &xv)
const;
475 inline void xformVect(
Vect3 &v)
const;
476 inline void xformPoint(
const Vect3 &p,
Vect3 &xp)
const;
477 inline void xformPoint(
Vect3 &p)
const;
481 inline void invXformVect(
const Vect3 &v,
Vect3 &xv)
const;
482 inline void invXformVect(
Vect3 &v)
const;
483 inline void invXformPoint(
const Vect3 &p,
Vect3 &xp)
const;
484 inline void invXformPoint(
Vect3 &p)
const;
519 Quat(Real angle,
const Vect3 &axis,
int normalizeAxis = 1)
520 {
set(angle, axis, normalizeAxis);}
525 void set(Real s, Real
x, Real
y, Real
z) {s_=s; x_=
x; y_=
y; z_=
z;}
528 void set(Real angle,
const Vect3 &axis,
int normalizeAxis = 1);
529 void set(
const Mat3 &
R);
531 inline void set(
const SbRotation &
R);
532 inline void toSbRotation(SbRotation &
R)
const;
535 Real
s()
const {
return s_;}
536 Real
x()
const {
return x_;}
537 Real
y()
const {
return y_;}
538 Real
z()
const {
return z_;}
539 inline Vect3 axis()
const;
540 inline Real angle()
const;
544 ostream&
print(ostream &os)
const;
549 {
return s_ == other.
s_ && x_ == other.
x_ 550 && y_ == other.
y_ && z_ == other.
z_;}
560 inline void normalize();
561 inline void invert(
const Quat &q);
562 inline void invert();
563 void mult(
const Quat &p,
const Quat &q);
564 void premult(
const Quat &q);
565 void postmult(
const Quat &q);
570 void xform(
Vect3 &v)
const;
574 void invXform(
const Vect3 &v,
Vect3 &xv)
const;
575 void invXform(
Vect3 &v)
const;
584 inline void deriv(
const Quat &q,
const Vect3 &
w);
620 void set(
const Quat &q_,
const Vect3 &d_) {q = q_; d = d_;}
623 inline void set(
const SoTransform *T);
624 inline void toSoTransform(SoTransform *T)
const;
635 inline ostream&
print(ostream &os)
const;
645 istream& read(istream &is);
653 inline void mult(
const Se3 &T,
const Se3 &U);
654 inline void premult(
const Se3 &T);
655 inline void postmult(
const Se3 &T);
656 inline void invert(
const Se3 &T);
657 inline void invert();
664 inline void xformVect(
const Vect3 &v,
Vect3 &xv)
const;
665 inline void xformVect(
Vect3 &v)
const;
666 inline void xformPoint(
const Vect3 &p,
Vect3 &xp)
const;
667 inline void xformPoint(
Vect3 &p)
const;
671 inline void invXformVect(
const Vect3 &v,
Vect3 &xv)
const;
672 inline void invXformVect(
Vect3 &v)
const;
673 inline void invXformPoint(
const Vect3 &p,
Vect3 &xp)
const;
674 inline void invXformPoint(
Vect3 &p)
const;
711 void Vect3::set(
const SbVec3f &vec)
713 const float *v = vec.getValue();
714 x = v[0];
y = v[1];
z = v[2];
720 void Vect3::toSbVec3f(SbVec3f &vec)
const 723 vec.setValue(
x.toDouble(),
y.toDouble(),
z.toDouble());
725 vec.setValue(
x,
y,
z);
733 return x == other.
x &&
y == other.
y &&
z == other.
z;
737 Real Vect3::dot(
const Vect3 &other)
const 739 return x * other.
x +
y * other.
y +
z * other.
z;
743 Real Vect3::norm()
const 745 return sqrt(
x *
x +
y *
y +
z *
z);
749 Real Vect3::norm2()
const 751 return (
x *
x +
y *
y +
z *
z);
755 Real Vect3::distance(
const Vect3 &other)
const 764 Real Vect3::distance2(
const Vect3 &other)
const 775 return (
x <=
y) ? ((
x <=
z) ?
x :
z) : ((
y <=
z) ?
y : z);
781 return (
x >=
y) ? ((
x >=
z) ?
x :
z) : ((
y >=
z) ?
y : z);
785 Real Vect3::minAbs()
const 792 return (ax <= ay) ? ((ax <= az) ? ax : az) : ((ay <= az) ? ay : az);
796 Real Vect3::maxAbs()
const 803 return (ax >= ay) ? ((ax >= az) ? ax : az) : ((ay >= az) ? ay : az);
817 void Vect3::normalize(
const Vect3 &v)
821 s = 1.0 / sqrt(v.
x * v.
x + v.
y * v.
y + v.
z * v.
z);
828 void Vect3::normalize()
832 s = 1.0 / sqrt(
x *
x +
y *
y +
z *
z);
903 void Vect3::scale(
const Vect3 &v, Real s)
911 void Vect3::scale(Real s)
922 x = u.
y * v.
z - u.
z * v.
y;
923 y = u.
z * v.
x - u.
x * v.
z;
924 z = u.
x * v.
y - u.
y * v.
x;
928 void Vect3::precross(
const Vect3 &v)
934 x = v.
y *
z - v.
z * oy;
935 y = v.
z * ox - v.
x *
z;
936 z = v.
x * oy - v.
y * ox;
940 void Vect3::postcross(
const Vect3 &v)
946 x = oy * v.
z -
z * v.
y;
947 y =
z * v.
x - ox * v.
z;
948 z = ox * v.
y - oy * v.
x;
954 x = u.
y * v.
z - u.
z * v.
y + w.
x;
955 y = u.
z * v.
x - u.
x * v.
z + w.
y;
956 z = u.
x * v.
y - u.
y * v.
x + w.
z;
962 x += u.
y * v.
z - u.
z * v.
y;
963 y += u.
z * v.
x - u.
x * v.
z;
964 z += u.
x * v.
y - u.
y * v.
x;
968 void Vect3::displace(
const Vect3 &v,
const Vect3 &u, Real lambda)
970 x = v.
x + lambda * u.
x;
971 y = v.
y + lambda * u.
y;
972 z = v.
z + lambda * u.
z;
976 void Vect3::displace(
const Vect3 &u, Real lambda)
984 void Vect3::interpolate(
const Vect3 &u,
const Vect3 &v, Real lambda)
986 Real lambda2 = 1.0 - lambda;
988 x = lambda2 * u.
x + lambda * v.
x;
989 y = lambda2 * u.
y + lambda * v.
y;
990 z = lambda2 * u.
z + lambda * v.
z;
1005 void Mat3::set(
const Vect3 &axis, Real angle,
int normalizeAxis)
1009 q.
set(angle, axis, normalizeAxis);
1049 Real Mat3::det()
const 1051 return xx * (yy * zz - yz * zy)
1052 + xy * (yz * zx - yx * zz)
1053 + xz * (yx * zy - yy * zx);
1091 void Mat3::symmetrize(
const Mat3 &M)
1096 xy = yx = M.
xy + M.
yx;
1097 yz = zy = M.
yz + M.
zy;
1098 zx = xz = M.
zx + M.
xz;
1102 void Mat3::symmetrize()
1209 void Mat3::scale(
const Mat3 &M, Real s)
1223 void Mat3::scale(Real s)
1239 xv.
x = xx * v.
x + xy * v.
y + xz * v.
z;
1240 xv.
y = yx * v.
x + yy * v.
y + yz * v.
z;
1241 xv.
z = zx * v.
x + zy * v.
y + zz * v.
z;
1250 v.
x = xx * ox + xy * oy + xz * v.
z;
1251 v.
y = yx * ox + yy * oy + yz * v.
z;
1252 v.
z = zx * ox + zy * oy + zz * v.
z;
1258 xv.
x = xx * v.
x + yx * v.
y + zx * v.
z;
1259 xv.
y = xy * v.
x + yy * v.
y + zy * v.
z;
1260 xv.
z = xz * v.
x + yz * v.
y + zz * v.
z;
1269 v.
x = xx * ox + yx * oy + zx * v.
z;
1270 v.
y = xy * ox + yy * oy + zy * v.
z;
1271 v.
z = xz * ox + yz * oy + zz * v.
z;
1281 ostream& MatX::print(ostream &os)
const 1283 return os <<
R <<
d << endl;
1287 istream& MatX::read(istream &is)
1340 void MatX::invXformPoint(
Vect3 &p)
const 1348 void Quat::set(
const SbRotation &rot)
1350 const float *q = rot.getValue();
1351 s_ = q[3]; x_ = q[0]; y_ = q[1]; z_ = q[2];
1357 void Quat::toSbRotation(SbRotation &rot)
const 1360 rot.setValue(x_.toDouble(), y_.toDouble(), z_.toDouble(), s_.toDouble());
1362 rot.setValue(x_, y_, z_, s_);
1370 Vect3 v(x_, y_, z_);
1377 Real Quat::angle()
const 1380 return 2 * acos(s_.toDouble());
1382 return 2 * acos(s_);
1387 void Quat::normalize(
const Quat &q)
1399 void Quat::normalize()
1403 scale = 1.0 / sqrt(s_*s_ + x_*x_ + y_*y_ + z_*z_);
1428 s_ = 0.5 * (-q.
x_ * w.
x - q.
y_ * w.
y - q.
z_ * w.
z);
1429 x_ = 0.5 * ( q.
s_ * w.
x - q.
z_ * w.
y + q.
y_ * w.
z);
1430 y_ = 0.5 * ( q.
z_ * w.
x + q.
s_ * w.
y - q.
x_ * w.
z);
1431 z_ = 0.5 * (-q.
y_ * w.
x + q.
x_ * w.
y + q.
s_ * w.
z);
1436 void Se3::set(
const SoTransform *xform)
1441 quat = xform->rotation.getValue().getValue();
1442 q.x_ = quat[0]; q.y_ = quat[1]; q.z_ = quat[2]; q.s_ = quat[3];
1444 trans = xform->translation.getValue().getValue();
1453 void Se3::toSoTransform(SoTransform *xform)
const 1456 xform->rotation.setValue
1457 (q.x_.toDouble(), q.y_.toDouble(), q.z_.toDouble(), q.s_.toDouble());
1458 xform->translation.setValue(
d.x.toDouble(),
d.y.toDouble(),
d.z.toDouble());
1460 xform->rotation.setValue(q.x_, q.y_, q.z_, q.s_);
1461 xform->translation.setValue(
d.x,
d.y,
d.z);
1467 ostream& Se3::print(ostream &os)
const 1469 return os << q <<
d;
1481 void Se3::premult(
const Se3 &T)
1489 void Se3::postmult(
const Se3 &T)
1499 void Se3::invert(
const Se3 &T)
1571 #endif // #ifndef MV_H Mat3(const Vect3 &axis, Real angle, int normalizeAxis=1)
Vect3 & operator[](int i)
static Real distance2(const Vect3 &u, const Vect3 &v)
ostream & print(ostream &os) const
std::string normalize(std::string &str)
istream & operator>>(istream &is, Se3 &T)
const Vect3 & trans() const
Mat3(const Vect3 &diag, const Vect3 &sym)
static Real distance(const Vect3 &u, const Vect3 &v)
const Vect3 & xrow() const
Se3(const Quat &q_, const Vect3 &d_)
int operator==(const PolyTreePair &ptree1, const PolyTreePair &ptree2)
ostream & print(ostream &os) const
static void swap(Vect3 &u, Vect3 &v)
ostream & print(ostream &os) const
ostream & operator<<(ostream &os, const Se3 &T)
int operator==(const Quat &other)
png_infop png_bytep * trans
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
double det(const dmatrix &_a)
ostream & print(ostream &os) const
ostream & print(ostream &os) const
void normalize(const Vect3 &v)
istream & read(istream &is)
void xform(const Vect3 &u, Vect3 &v) const
istream & read(istream &is)
Quat(Real s, Real x, Real y, Real z)
const Vect3 & zrow() const
static Real dot(const Vect3 &u, const Vect3 &v)
Vect3(Real x_, Real y_, Real z_)
Quat(Real angle, const Vect3 &axis, int normalizeAxis=1)
Vector3 cross(const Vector3 &v1, const Vector3 &v2)
double dot(const Vector3 &v1, const Vector3 &v2)
MatX(const Mat3 &R_, const Vect3 &d_)
Real distance2(const Vect3 &other) const
double norm2(const Vector3 &v)
Real dot(const Vect3 &other) const
void set(Real s, Real x, Real y, Real z)
Real distance(const Vect3 &other) const
const Vect3 & yrow() const
void add(const Vect3 &u, const Vect3 &v)
const Vect3 & operator[](int i) const
const Vect3 & trans() const
istream & read(istream &is)
void sub(const Vect3 &u, const Vect3 &v)
const Real & operator[](int i) const