OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMatrix4x4.h
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts (gpotts@imagelinks.com)
6 //
7 // Description:
8 //
9 //*******************************************************************
10 // $Id: ossimMatrix4x4.h 19824 2011-07-15 16:01:34Z dburken $
11 
12 #ifndef ossimMatrix4x4_HEADER
13 #define ossimMatrix4x4_HEADER
14 #include <iostream>
15 #include <ossim/matrix/newmat.h>
16 #include <ossim/matrix/newmatio.h>
20 
22 {
23  public:
25  const ossimMatrix4x4& data)
26  {
27  return out << data.getData();
28  }
30  ossimMatrix4x4(const NEWMAT::Matrix& m);
31  ossimMatrix4x4(double v00, double v01, double v02, double v03,
32  double v10, double v11, double v12, double v13,
33  double v20, double v21, double v22, double v23,
34  double v30, double v31, double v32, double v33);
35  inline explicit ossimMatrix4x4(const ossim::Quaternion& quat){ makeRotate(quat);}
37  :theData(4,4)
38  {
39  theData[0][0] = rhs.theData[0][0];
40  theData[0][1] = rhs.theData[0][1];
41  theData[0][2] = rhs.theData[0][2];
42  theData[0][3] = rhs.theData[0][3];
43  theData[1][0] = rhs.theData[1][0];
44  theData[1][1] = rhs.theData[1][1];
45  theData[1][2] = rhs.theData[1][2];
46  theData[1][3] = rhs.theData[1][3];
47  theData[2][0] = rhs.theData[2][0];
48  theData[2][1] = rhs.theData[2][1];
49  theData[2][2] = rhs.theData[2][2];
50  theData[2][3] = rhs.theData[2][3];
51  theData[3][0] = rhs.theData[3][0];
52  theData[3][1] = rhs.theData[3][1];
53  theData[3][2] = rhs.theData[3][2];
54  theData[3][3] = rhs.theData[3][3];
55  }
56  void makeRotate( const ossim::Quaternion& quat);
57  void setRotate( const ossim::Quaternion& quat);
58  ossim::Quaternion getRotate()const;
59  void getRotate(ossim::Quaternion& quat)const;
60 
62  {
63  return ossimMatrix4x4(theData[0][0] + rhs.theData[0][0], theData[0][1] + rhs.theData[0][1], theData[0][2] + rhs.theData[0][2], theData[0][3] + rhs.theData[0][3],
64  theData[1][0] + rhs.theData[1][0], theData[1][1] + rhs.theData[1][1], theData[1][2] + rhs.theData[1][2], theData[1][3] + rhs.theData[1][3],
65  theData[2][0] + rhs.theData[2][0], theData[2][1] + rhs.theData[2][1], theData[2][2] + rhs.theData[2][2], theData[2][3] + rhs.theData[2][3],
66  theData[3][0] + rhs.theData[3][0], theData[3][1] + rhs.theData[3][1], theData[3][2] + rhs.theData[3][2], theData[3][3] + rhs.theData[3][3]);
67  }
69  {
70  return ossimMatrix4x4(theData[0][0] - rhs.theData[0][0], theData[0][1] - rhs.theData[0][1], theData[0][2] - rhs.theData[0][2], theData[0][3] - rhs.theData[0][3],
71  theData[1][0] - rhs.theData[1][0], theData[1][1] - rhs.theData[1][1], theData[1][2] - rhs.theData[1][2], theData[1][3] - rhs.theData[1][3],
72  theData[2][0] - rhs.theData[2][0], theData[2][1] - rhs.theData[2][1], theData[2][2] - rhs.theData[2][2], theData[2][3] - rhs.theData[2][3],
73  theData[3][0] - rhs.theData[3][0], theData[3][1] - rhs.theData[3][1], theData[3][2] - rhs.theData[3][2], theData[3][3] - rhs.theData[3][3]);
74  }
76  {
77  return ossimColumnVector4d( (lhs.theData[0][0]*rhs[0] + lhs.theData[0][1]*rhs[1] + lhs.theData[0][2]*rhs[2] + lhs.theData[0][3]*rhs[3]),
78  (lhs.theData[1][0]*rhs[0] + lhs.theData[1][1]*rhs[1] + lhs.theData[1][2]*rhs[2] + lhs.theData[1][3]*rhs[3]),
79  (lhs.theData[2][0]*rhs[0] + lhs.theData[2][1]*rhs[1] + lhs.theData[2][2]*rhs[2] + lhs.theData[2][3]*rhs[3]),
80  (lhs.theData[3][0]*rhs[0] + lhs.theData[3][1]*rhs[1] + lhs.theData[3][2]*rhs[2] + lhs.theData[3][3]*rhs[3]));
81 
82  }
84  {
85  // assume the 4 coordinate (homogeneous coord) of the 3d vector is 1
86  return ossimColumnVector3d( (lhs.theData[0][0]*rhs[0] + lhs.theData[0][1]*rhs[1] + lhs.theData[0][2]*rhs[2] + lhs.theData[0][3]),
87  (lhs.theData[1][0]*rhs[0] + lhs.theData[1][1]*rhs[1] + lhs.theData[1][2]*rhs[2] + lhs.theData[1][3]),
88  (lhs.theData[2][0]*rhs[0] + lhs.theData[2][1]*rhs[1] + lhs.theData[2][2]*rhs[2] + lhs.theData[2][3]));
89  }
91  {
92  // multiply only by the 3x3 submatrix.
93  return ossimColumnVector4d( (theData[0][0]*rhs[0] + theData[0][1]*rhs[1] + theData[0][2]*rhs[2]),
94  (theData[1][0]*rhs[0] + theData[1][1]*rhs[1] + theData[1][2]*rhs[2]),
95  (theData[2][0]*rhs[0] + theData[2][1]*rhs[1] + theData[2][2]*rhs[2]));
96  }
98  {
99  // assume the 4 coordinate (homogeneous coord) of the 3d vector is 1
100  return ossimColumnVector3d( (theData[0][0]*rhs[0] + theData[0][1]*rhs[1] + theData[0][2]*rhs[2]),
101  (theData[1][0]*rhs[0] + theData[1][1]*rhs[1] + theData[1][2]*rhs[2]),
102  (theData[2][0]*rhs[0] + theData[2][1]*rhs[1] + theData[2][2]*rhs[2]));
103  }
104  ossimMatrix4x4 operator*(double scalar)const
105  {
106  return ossimMatrix4x4(theData[0][0]*scalar, theData[0][1]*scalar, theData[0][2]*scalar, theData[0][3]*scalar,
107  theData[1][0]*scalar, theData[1][1]*scalar, theData[1][2]*scalar, theData[1][3]*scalar,
108  theData[2][0]*scalar, theData[2][1]*scalar, theData[2][2]*scalar, theData[2][3]*scalar,
109  theData[0][0]*scalar, theData[0][1]*scalar, theData[0][2]*scalar, theData[0][3]*scalar);
110 
111  }
113  {
114  ossimMatrix4x4 m;
115 
116  // element 0,0 is first row time first column
117  m.theData[0][0] = (theData[0][0]*rhs.theData[0][0] +
118  theData[0][1]*rhs.theData[1][0] +
119  theData[0][2]*rhs.theData[2][0] +
120  theData[0][3]*rhs.theData[3][0]);
121 
122  // element 0, 1 is first row second column
123  m.theData[0][1] = (theData[0][0]*rhs.theData[0][1] +
124  theData[0][1]*rhs.theData[1][1] +
125  theData[0][2]*rhs.theData[2][1] +
126  theData[0][3]*rhs.theData[3][1]);
127 
128  // element 0, 2 is first row third column
129  m.theData[0][2] = (theData[0][0]*rhs.theData[0][2] +
130  theData[0][1]*rhs.theData[1][2] +
131  theData[0][2]*rhs.theData[2][2] +
132  theData[0][3]*rhs.theData[3][2]);
133 
134  // element 0, 3 is first row fourth column
135  m.theData[0][3] = (theData[0][0]*rhs.theData[0][3] +
136  theData[0][1]*rhs.theData[1][3] +
137  theData[0][2]*rhs.theData[2][3] +
138  theData[0][3]*rhs.theData[3][3]);
139 
140  // element 1, 0 is second row first column
141  m.theData[1][0] = (theData[1][0]*rhs.theData[0][0] +
142  theData[1][1]*rhs.theData[1][0] +
143  theData[1][2]*rhs.theData[2][0] +
144  theData[1][3]*rhs.theData[3][0]);
145 
146  // element 1, 1 is second row second column
147  m.theData[1][1] = (theData[1][0]*rhs.theData[0][1] +
148  theData[1][1]*rhs.theData[1][1] +
149  theData[1][2]*rhs.theData[2][1] +
150  theData[1][3]*rhs.theData[3][1]);
151 
152  // element 1, 2 is second row third column
153  m.theData[1][2] = (theData[1][0]*rhs.theData[0][2] +
154  theData[1][1]*rhs.theData[1][2] +
155  theData[1][2]*rhs.theData[2][2] +
156  theData[1][3]*rhs.theData[3][2]);
157 
158  // element 1, 3 is second row fourth column
159  m.theData[1][3] = (theData[1][0]*rhs.theData[0][3] +
160  theData[1][1]*rhs.theData[1][3] +
161  theData[1][2]*rhs.theData[2][3] +
162  theData[1][3]*rhs.theData[3][3]);
163 
164  // element 2, 0 is third row first column
165  m.theData[2][0] = (theData[2][0]*rhs.theData[0][0] +
166  theData[2][1]*rhs.theData[1][0] +
167  theData[2][2]*rhs.theData[2][0] +
168  theData[2][3]*rhs.theData[3][0]);
169 
170  // element 2, 1 is third row second column
171  m.theData[2][1] = (theData[2][0]*rhs.theData[0][1] +
172  theData[2][1]*rhs.theData[1][1] +
173  theData[2][2]*rhs.theData[2][1] +
174  theData[2][3]*rhs.theData[3][1]);
175 
176  // element 2, 2 is third row third column
177  m.theData[2][2] = (theData[2][0]*rhs.theData[0][2] +
178  theData[2][1]*rhs.theData[1][2] +
179  theData[2][2]*rhs.theData[2][2] +
180  theData[2][3]*rhs.theData[3][2]);
181 
182  // element 2, 3 is third row fourth column
183  m.theData[2][3] = (theData[2][0]*rhs.theData[0][3] +
184  theData[2][1]*rhs.theData[1][3] +
185  theData[2][2]*rhs.theData[2][3] +
186  theData[2][3]*rhs.theData[3][3]);
187 
188  // element 3, 0 is fourth row first column
189  m.theData[3][0] = (theData[3][0]*rhs.theData[0][0] +
190  theData[3][1]*rhs.theData[1][0] +
191  theData[3][2]*rhs.theData[2][0] +
192  theData[3][3]*rhs.theData[3][0]);
193 
194  // element 3, 1 is fourth row second column
195  m.theData[3][1] = (theData[3][0]*rhs.theData[0][1] +
196  theData[3][1]*rhs.theData[1][1] +
197  theData[3][2]*rhs.theData[2][1] +
198  theData[3][3]*rhs.theData[3][1]);
199 
200  // element 3, 2 is fourth row third column
201  m.theData[3][2] = (theData[3][0]*rhs.theData[0][2] +
202  theData[3][1]*rhs.theData[1][2] +
203  theData[3][2]*rhs.theData[2][2] +
204  theData[3][3]*rhs.theData[3][2]);
205 
206  // element 3, 3 is fourth row fourth column
207  m.theData[3][3] = (theData[3][0]*rhs.theData[0][3] +
208  theData[3][1]*rhs.theData[1][3] +
209  theData[3][2]*rhs.theData[2][3] +
210  theData[3][3]*rhs.theData[3][3]);
211 
212  return m;
213  }
214 
219  {
220  theData = theData.i();
221 
222  return *this;
223  }
224 
229  {
230  theData = theData.t();
231 
232  return *this;
233  }
234 
238  double getDeterminant()const
239  {
240  return theData.Determinant();
241  }
242 
247  ossimColumnVector3d getEigenValues()const;
248 
249  bool isEqualTo(const ossimMatrix4x4& rhs,
250  ossimCompareType compareType=OSSIM_COMPARE_FULL)const;
251 
252  void setZero();
253  void setIdentity();
254  static NEWMAT::Matrix createIdentity();
255  static NEWMAT::Matrix createRotateOnly(const ossimMatrix4x4& aMatrix);
256 
257  static NEWMAT::Matrix createZero();
258  static NEWMAT::Matrix createTranslationMatrix(double x,
259  double y,
260  double z);
261  static NEWMAT::Matrix createRotationMatrix(double angleX,
262  double angleY,
263  double angleZ,
265  static NEWMAT::Matrix createRotationXMatrix(double angle,
267  static NEWMAT::Matrix createRotationYMatrix(double angle,
269  static NEWMAT::Matrix createRotationZMatrix(double angle,
271 
272  static NEWMAT::Matrix createScaleMatrix(double X, double Y, double Z);
273 
274  const NEWMAT::Matrix& getData()const{return theData;}
275  NEWMAT::Matrix& getData(){return theData;}
276 
277 private:
278  NEWMAT::Matrix theData;
279 
280 }; // class OSSIM_DLL ossimMatrix4x4
281 
283  ossimCompareType /* compareType */)const
284 {
285  return (ossim::almostEqual(theData[0][0], rhs.theData[0][0])&&
286  ossim::almostEqual(theData[0][1], rhs.theData[0][1])&&
287  ossim::almostEqual(theData[0][2], rhs.theData[0][2])&&
288  ossim::almostEqual(theData[0][3], rhs.theData[0][3])&&
289  ossim::almostEqual(theData[1][0], rhs.theData[1][0])&&
290  ossim::almostEqual(theData[1][1], rhs.theData[1][1])&&
291  ossim::almostEqual(theData[1][2], rhs.theData[1][2])&&
292  ossim::almostEqual(theData[1][3], rhs.theData[1][3])&&
293  ossim::almostEqual(theData[2][0], rhs.theData[2][0])&&
294  ossim::almostEqual(theData[2][1], rhs.theData[2][1])&&
295  ossim::almostEqual(theData[2][2], rhs.theData[2][2])&&
296  ossim::almostEqual(theData[2][3], rhs.theData[2][3])&&
297  ossim::almostEqual(theData[3][0], rhs.theData[3][0])&&
298  ossim::almostEqual(theData[3][1], rhs.theData[3][1])&&
299  ossim::almostEqual(theData[3][2], rhs.theData[3][2])&&
300  ossim::almostEqual(theData[3][3], rhs.theData[3][3]));
301 }
302 
303 #endif /* #ifndef ossimMatrix4x4_HEADER */
ossim_uint32 x
const NEWMAT::Matrix & getData() const
ossimMatrix4x4 operator*(double scalar) const
ossimRationalNumber operator-(ossim_int32 i, ossimRationalNumber &r)
ossimMatrix4x4 operator*(const ossimMatrix4x4 &rhs) const
ossimMatrix4x4 & i()
NEWMAT::Matrix theData
ossim_uint32 y
A quaternion class.
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
double getDeterminant() const
ossimMatrix4x4(const ossim::Quaternion &quat)
ossimCompareType
ossimRationalNumber operator*(ossim_int32 i, ossimRationalNumber &r)
ossimCoordSysOrientMode
ossimMatrix4x4 & t()
ossimColumnVector4d rotateOnly(const ossimColumnVector4d &rhs) const
NEWMAT::Matrix & getData()
friend std::ostream & operator<<(std::ostream &out, const ossimMatrix4x4 &data)
ossimColumnVector3d rotateOnly(const ossimColumnVector3d &rhs) const
#define OSSIM_DLL
bool isEqualTo(const ossimMatrix4x4 &rhs, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
ossimMatrix4x4(const ossimMatrix4x4 &rhs)
ossimRationalNumber operator+(ossim_int32 i, ossimRationalNumber &r)
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23