cryph utilities [subset]  2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
Matrix4x4.h
Go to the documentation of this file.
1 
8 #ifndef MATRIX4x4_H
9 #define MATRIX4x4_H
10 
11 #include <iostream>
12 
13 #include "AffPoint.h"
14 #include "AffVector.h"
15 #include "Matrix3x3.h"
16 
17 namespace cryph
18 {
19 
20 class ProjPoint;
21 class ViewVolume;
22 
23 class Matrix4x4
24 {
25 public:
27  Matrix4x4();
28 
32  Matrix4x4(const Matrix4x4& m);
33 
37  Matrix4x4(
38  double m11, double m12, double m13, double m14,
39  double m21, double m22, double m23, double m24,
40  double m31, double m32, double m33, double m34,
41  double m41, double m42, double m43, double m44);
42 
51  Matrix4x4(const Matrix3x3& M);
52 
62  Matrix4x4(const Matrix3x3& M, const AffVector& t);
63 
72  Matrix4x4(const Matrix3x3& M, const AffPoint& FixedPoint);
73 
74  // From an affine matrix M and a point whose pre- and post-image are known
86  Matrix4x4(const Matrix3x3& M,
87  const AffPoint& PreImage, const AffPoint& PostImage);
88 
90  virtual ~Matrix4x4();
91 
99  static Matrix4x4 fromColMajor(const float* m);
100 
108  static Matrix4x4 fromColMajor(const double* m);
109 
116  static Matrix4x4 fromRowMajor(const float* m);
117 
125  static Matrix4x4 fromRowMajor(const double* m);
126 
135  static Matrix4x4 generalRotationDegrees(const AffPoint& B,
136  const AffVector& axis, double angle);
137 
145  static Matrix4x4 generalRotationRadians(const AffPoint& B,
146  const AffVector& axis, double angle);
147 
154  static Matrix4x4 mirror(const AffPoint& B, const AffVector& n);
155 
161  static Matrix4x4 xRotationDegrees(double angle);
162 
168  static Matrix4x4 yRotationDegrees(double angle);
169 
175  static Matrix4x4 zRotationDegrees(double angle);
176 
182  static Matrix4x4 xRotationRadians(double angle);
183 
189  static Matrix4x4 yRotationRadians(double angle);
190 
196  static Matrix4x4 zRotationRadians(double angle);
197 
202  static Matrix4x4 translation(const AffVector& trans);
203 
210  static Matrix4x4 translation(double dx, double dy, double dz);
211 
219  static Matrix4x4 scale(double sx, double sy, double sz);
220 
236  static Matrix4x4 lookAt(const cryph::AffPoint& eye,
237  const cryph::AffPoint& center,
238  const cryph::AffVector& up);
239 
252  static Matrix4x4 orthogonal(double xmin, double xmax, double ymin,
253  double ymax, double zmin, double zmax);
254 
276  static Matrix4x4 oblique(double zpp, double xmin, double xmax, double ymin,
277  double ymax, double zmin, double zmax,
278  const cryph::AffVector& projDir);
279 
304  static Matrix4x4 perspective(double zpp, double xmin, double xmax,
305  double ymin, double ymax, double zmin, double zmax, double h=0.0);
306 
326  static bool getECvw(const cryph::AffPoint& eye,
327  const cryph::AffPoint& center, const cryph::AffVector& up,
329 
334  Matrix4x4 operator=(const Matrix4x4& rhs);
335 
340  Matrix4x4 operator*=(const Matrix4x4& rhs);
341 
347  Matrix4x4 operator*=(double f);
348 
353  Matrix4x4 operator+=(const Matrix4x4& rhs);
354 
362  AffPoint operator*(const AffPoint& p) const;
363 
368  ProjPoint operator*(const ProjPoint& p) const;
369 
376  AffVector operator*(const AffVector& v) const;
377 
382  Matrix4x4 operator*(const Matrix4x4& m2) const;
383 
388  Matrix4x4 operator+(const Matrix4x4& m2) const;
389 
394  Matrix4x4 operator-(const Matrix4x4& m2) const;
395 
401  friend Matrix4x4 operator*(double f, const Matrix4x4& m);
402 
403  friend std::ostream& operator<<(std::ostream& os, const Matrix4x4& m);
404  friend std::istream& operator>>(std::istream& is, Matrix4x4& m);
405 
409  double determinant() const;
410 
417  double elementAt(int r, int c) const;
418 
427  float* extractColMajor(float m[16]) const;
428 
437  double* extractColMajor(double m[16]) const;
438 
447  float* extractRowMajor(float m[16]) const;
448 
457  double* extractRowMajor(double m[16]) const;
458 
471  void extractAffineMt(Matrix3x3& M, AffVector& t) const;
472 
488  int extractAxisAngle(AffPoint& B, AffVector& w, double& theta,
489  AffVector& postTranslation) const;
490 
498  bool inverse(Matrix4x4& mInv) const;
499 
504  int isAffineTransformation() const;
505 
514  void multiply(const double a[], double b[], int nElements=4) const;
515 
524  void multiply(const float a[], float b[], int nElements=4) const;
525 
532  void setElementAt(int r, int c, double newValue);
533 
540  Matrix3x3 subMatrix(int skipRow, int skipCol) const;
541 
542  // 1. Special Matrices
543  static const Matrix4x4 IdentityMatrix;
544  static const Matrix4x4 ZeroMatrix;
546  // 2. Return codes for extraction of base point, unit axis vector,
547  // and rotation angle from 4x4 matrices that are 'supposed to
548  // describe' affine transformations whose upper 3x3 matrix is
549  // 'supposed to be' orthogonal and right-handed. (See the Matrix3x3
550  // method "extractAxisAngle".)
551 
552  // 2.1: Abnormal internal errors that should never be returned:
553  static const int InternalBasePointComputationError;
554 
555  // 2.2: "Normal" errors if user provides inappropriate matrix:
556  static const int NotAffine;
557  // (Note that the Matrix3x3 error codes may be returned as well.)
558 
559  // 2.3: Successful extraction of unit axis vector and angle:
560  // If the 3x3 extraction of (unit axis vector, angle) is successful,
561  // then the 4x4 utility tries to determine a base point. If
562  // successful, then "Matrix4x4::Extracted_BwTheta" is returned,
563  // otherwise the 3x3 code ("Matrix3x3::Extracted_wTheta") is returned,
564  // signifying that the (unit axis vector, angle) information was
565  // successfully computed and returned, but only an approximation to
566  // a rotation axis base point was able to be determined. In this case,
567  // 'postTranslation' will contain a non-zero vector which, if added to
568  // a point after rotation, will yield the correct point.
569  static const int Extracted_BwTheta;
570 
571 protected:
572  double mElem[4][4];
573 
574 private:
575  void copy(const Matrix4x4& rhs);
576 
577  static int determineBasePoint(AffVector ImMRows[], int maxWCompLoc,
578  int r1, int r2, const AffVector& trans, AffPoint& B);
579 
580  void installMt(const Matrix3x3& M, const AffVector& t);
581 };
582 
583 }
584 
585 #endif
Matrix3x3 subMatrix(int skipRow, int skipCol) const
Definition: Matrix4x4.c++:773
static Matrix4x4 fromRowMajor(const float *m)
Definition: Matrix4x4.c++:356
Definition: ProjPoint.h:15
static Matrix4x4 zRotationRadians(double angle)
Definition: Matrix4x4.c++:868
double elementAt(int r, int c) const
Definition: Matrix4x4.c++:226
static Matrix4x4 generalRotationRadians(const AffPoint &B, const AffVector &axis, double angle)
Definition: Matrix4x4.c++:382
Definition: AffPoint.c++:12
Matrix4x4 operator+(const Matrix4x4 &m2) const
Definition: Matrix4x4.c++:655
static Matrix4x4 xRotationDegrees(double angle)
Definition: Matrix4x4.c++:810
static Matrix4x4 translation(const AffVector &trans)
Definition: Matrix4x4.c++:792
double determinant() const
Definition: Matrix4x4.c++:140
Matrix4x4()
Definition: Matrix4x4.c++:71
AffPoint operator*(const AffPoint &p) const
Definition: Matrix4x4.c++:589
static Matrix4x4 fromColMajor(const float *m)
Definition: Matrix4x4.c++:336
static Matrix4x4 yRotationDegrees(double angle)
Definition: Matrix4x4.c++:833
Matrix4x4 operator-(const Matrix4x4 &m2) const
Definition: Matrix4x4.c++:665
float * extractRowMajor(float m[16]) const
Definition: Matrix4x4.c++:318
Definition: Matrix4x4.h:23
void setElementAt(int r, int c, double newValue)
Definition: Matrix4x4.c++:767
void multiply(const double a[], double b[], int nElements=4) const
Definition: Matrix4x4.c++:486
bool inverse(Matrix4x4 &mInv) const
Definition: Matrix4x4.c++:427
static Matrix4x4 perspective(double zpp, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double h=0.0)
Definition: Matrix4x4.c++:728
static Matrix4x4 lookAt(const cryph::AffPoint &eye, const cryph::AffPoint &center, const cryph::AffVector &up)
Definition: Matrix4x4.c++:462
Definition: AffVector.h:24
Matrix4x4 operator=(const Matrix4x4 &rhs)
Definition: Matrix4x4.c++:561
int extractAxisAngle(AffPoint &B, AffVector &w, double &theta, AffVector &postTranslation) const
Definition: Matrix4x4.c++:248
static Matrix4x4 scale(double sx, double sy, double sz)
Definition: Matrix4x4.c++:758
static Matrix4x4 orthogonal(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
Definition: Matrix4x4.c++:709
int isAffineTransformation() const
Definition: Matrix4x4.c++:449
Definition: Matrix3x3.h:25
static Matrix4x4 mirror(const AffPoint &B, const AffVector &n)
Definition: Matrix4x4.c++:480
static Matrix4x4 generalRotationDegrees(const AffPoint &B, const AffVector &axis, double angle)
Definition: Matrix4x4.c++:376
static const Matrix4x4 IdentityMatrix
Definition: Matrix4x4.h:543
void extractAffineMt(Matrix3x3 &M, AffVector &t) const
Definition: Matrix4x4.c++:234
static Matrix4x4 xRotationRadians(double angle)
Definition: Matrix4x4.c++:822
static const Matrix4x4 ZeroMatrix
Definition: Matrix4x4.h:544
static Matrix4x4 oblique(double zpp, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, const cryph::AffVector &projDir)
Definition: Matrix4x4.c++:530
static Matrix4x4 yRotationRadians(double angle)
Definition: Matrix4x4.c++:845
Matrix4x4 operator+=(const Matrix4x4 &rhs)
Definition: Matrix4x4.c++:581
virtual ~Matrix4x4()
Definition: Matrix4x4.c++:129
Matrix4x4 operator*=(const Matrix4x4 &rhs)
Definition: Matrix4x4.c++:567
static Matrix4x4 zRotationDegrees(double angle)
Definition: Matrix4x4.c++:856
static bool getECvw(const cryph::AffPoint &eye, const cryph::AffPoint &center, const cryph::AffVector &up, cryph::AffVector &v, cryph::AffVector &w)
Definition: Matrix4x4.c++:389
float * extractColMajor(float m[16]) const
Definition: Matrix4x4.c++:300
Definition: AffPoint.h:25