Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
SbDPMatrix.h
1 #ifndef COIN_SBDPMATRIX_H
2 #define COIN_SBDPMATRIX_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <cstdio>
37 #include <Inventor/SbBasic.h>
38 
39 class SbDPLine;
40 class SbDPRotation;
41 class SbVec3d;
42 class SbVec4d;
43 class SbMatrix;
44 
45 typedef double SbDPMat[4][4];
46 
47 class COIN_DLL_API SbDPMatrix {
48 public:
49  SbDPMatrix(void);
50  SbDPMatrix(const double a11, const double a12, const double a13, const double a14,
51  const double a21, const double a22, const double a23, const double a24,
52  const double a31, const double a32, const double a33, const double a34,
53  const double a41, const double a42, const double a43, const double a44);
54  SbDPMatrix(const SbDPMat & matrix);
55  SbDPMatrix(const SbDPMat * matrix);
56  SbDPMatrix(const SbMatrix & matrix);
57  ~SbDPMatrix(void);
58 
59  void setValue(const SbDPMat & m);
60  void setValue(const SbMatrix & m);
61  void setValue(const double * pMat);
62  const SbDPMat & getValue(void) const;
63 
64  void makeIdentity(void);
65  void setRotate(const SbDPRotation & q);
66  SbDPMatrix inverse(void) const;
67  double det3(int r1, int r2, int r3,
68  int c1, int c2, int c3) const;
69  double det3(void) const;
70  double det4(void) const;
71 
72  SbBool equals(const SbDPMatrix & m, double tolerance) const;
73 
74 
75  void getValue(SbDPMat & m) const;
76  static SbDPMatrix identity(void);
77  void setScale(const double s);
78  void setScale(const SbVec3d & s);
79  void setTranslate(const SbVec3d & t);
80  void setTransform(const SbVec3d & t, const SbDPRotation & r, const SbVec3d & s);
81  void setTransform(const SbVec3d & t, const SbDPRotation & r, const SbVec3d & s,
82  const SbDPRotation & so);
83  void setTransform(const SbVec3d & translation,
84  const SbDPRotation & rotation, const SbVec3d & scaleFactor,
85  const SbDPRotation & scaleOrientation, const SbVec3d & center);
86  void getTransform(SbVec3d & t, SbDPRotation & r,
87  SbVec3d & s, SbDPRotation & so) const;
88  void getTransform(SbVec3d & translation, SbDPRotation & rotation,
89  SbVec3d & scaleFactor, SbDPRotation & scaleOrientation,
90  const SbVec3d & center) const;
91  SbBool factor(SbDPMatrix & r, SbVec3d & s, SbDPMatrix & u, SbVec3d & t,
92  SbDPMatrix & proj);
93  SbBool LUDecomposition(int index[4], double & d);
94  void LUBackSubstitution(int index[4], double b[4]) const;
95  SbDPMatrix transpose(void) const;
96  SbDPMatrix & multRight(const SbDPMatrix & m);
97  SbDPMatrix & multLeft(const SbDPMatrix & m);
98  void multMatrixVec(const SbVec3d & src, SbVec3d & dst) const;
99  void multVecMatrix(const SbVec3d & src, SbVec3d & dst) const;
100  void multDirMatrix(const SbVec3d & src, SbVec3d & dst) const;
101  void multLineMatrix(const SbDPLine & src, SbDPLine & dst) const;
102  void multVecMatrix(const SbVec4d & src, SbVec4d & dst) const;
103 
104  void print(FILE * fp) const;
105 
106  operator double*(void);
107  operator SbDPMat&(void);
108  double * operator [](int i);
109  const double * operator [](int i) const;
110 
111  SbDPMatrix & operator =(const SbDPMat & m);
112  SbDPMatrix & operator =(const SbDPMatrix & m);
113  SbDPMatrix & operator =(const SbDPRotation & q);
114  SbDPMatrix & operator *=(const SbDPMatrix & m);
115 
116  friend COIN_DLL_API SbDPMatrix operator *(const SbDPMatrix & m1, const SbDPMatrix & m2);
117  friend COIN_DLL_API int operator ==(const SbDPMatrix & m1, const SbDPMatrix & m2);
118  friend COIN_DLL_API int operator !=(const SbDPMatrix & m1, const SbDPMatrix & m2);
119 private:
120  double matrix[4][4];
121 
122  void operator /=(const double v);
123  void operator *=(const double v);
124 };
125 
126 typedef SbDPMatrix SbMatrixd;
127 
128 COIN_DLL_API SbDPMatrix operator *(const SbDPMatrix & m1, const SbDPMatrix & m2);
129 COIN_DLL_API int operator ==(const SbDPMatrix & m1, const SbDPMatrix & m2);
130 COIN_DLL_API int operator !=(const SbDPMatrix & m1, const SbDPMatrix & m2);
131 
132 #endif // !COIN_SBDPMATRIX_H
The SbDPLine class represents a line using double precision coordinates.
Definition: SbDPLine.h:41
The SbVec3d class is a 3 dimensional vector with double precision floating point coordinates.
Definition: SbVec3d.h:50
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:102
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.h:106
The SbDPRotation class represents a rotation in 3D space using double precision data.
Definition: SbDPRotation.h:42
The SbMatrix class is a 4x4 dimensional representation of a matrix.
Definition: SbMatrix.h:47
The SbVec4d class is a 4 dimensional vector with double precision floating point coordinates.
Definition: SbVec4d.h:49
SbVec2s operator*(const SbVec2s &v, int d)
The SbDPMatrix class is a 4x4 dimensional representation of a double-precision matrix.
Definition: SbDPMatrix.h:47