Matrix4.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_MATRIX4_HH_
18 #define _GAZEBO_MATRIX4_HH_
19 
20 #include <assert.h>
21 #include <iostream>
22 #include <ignition/math/Matrix4.hh>
23 
24 #include "gazebo/math/Vector3.hh"
25 #include "gazebo/math/Matrix3.hh"
26 #include "gazebo/util/system.hh"
27 
28 namespace gazebo
29 {
30  namespace math
31  {
32  class Quaternion;
33  class Pose;
34 
37 
40  class GZ_MATH_VISIBLE Matrix4
41  {
44  public: Matrix4()
45  GAZEBO_DEPRECATED(8.0);
46 
50  public: Matrix4(const Matrix4 &_m)
51  GAZEBO_DEPRECATED(8.0);
52 
56  public: Matrix4(const ignition::math::Matrix4d &_m)
57  GAZEBO_DEPRECATED(8.0);
58 
77  public: Matrix4(double _v00, double _v01, double _v02, double _v03,
78  double _v10, double _v11, double _v12, double _v13,
79  double _v20, double _v21, double _v22, double _v23,
80  double _v30, double _v31, double _v32, double _v33)
81  GAZEBO_DEPRECATED(8.0);
82 
84  public: virtual ~Matrix4();
85 
103  public: void Set(double _v00, double _v01, double _v02, double _v03,
104  double _v10, double _v11, double _v12, double _v13,
105  double _v20, double _v21, double _v22, double _v23,
106  double _v30, double _v31, double _v32, double _v33);
107 
108 
109 
112  public: void SetTranslate(const Vector3 &_t);
113 
116  public: Vector3 GetTranslation() const;
117 
120  public: Quaternion GetRotation() const;
121 
124  public: Vector3 GetEulerRotation(unsigned int solution_number = 1) const;
125 
128  public: math::Pose GetAsPose() const;
129 
132  public: void SetScale(const Vector3 &_s);
133 
136  public: bool IsAffine() const;
137 
141  public: Vector3 TransformAffine(const Vector3 &_v) const;
142 
145  public: Matrix4 Inverse() const;
146 
150  public: Matrix4 &operator =(const Matrix4 &_mat);
151 
155  public: Matrix4 &operator=(const ignition::math::Matrix4d &_mat);
156 
160  public: const Matrix4 & operator =(const Matrix3 &_mat);
161 
165  public: Matrix4 operator*(const Matrix4 &_mat) const;
166 
170  public: Matrix4 operator*(const Matrix3 &_mat) const;
171 
172 
176  public: Vector3 operator*(const Vector3 &_vec) const;
177 
181  public: inline double *operator[](size_t _row)
182  {
183  assert(_row < 4);
184  return this->m[_row];
185  }
188  public: inline const double *operator[](size_t _row) const
189  {
190  assert(_row < 4);
191  return this->m[_row];
192  }
193 
198  public: bool operator==(const Matrix4 &_m) const;
199 
202  public: ignition::math::Matrix4d Ign() const;
203 
208  public: friend std::ostream &operator<<(std::ostream &_out,
209  const gazebo::math::Matrix4 &_m)
210  {
211  for (int i = 0; i < 4; i++)
212  {
213  for (int j = 0; j < 4; j++)
214  {
215  _out << (fabs(_m.m[i][j]) < 1e-6 ? 0 : _m.m[i][j]) << " ";
216  }
217  _out << "\n";
218  }
219 
220  return _out;
221  }
222 
224  public: static const Matrix4 IDENTITY;
225 
227  public: static const Matrix4 ZERO;
228 
230  protected: double m[4][4];
231  };
233  }
234 }
235 #endif
236 
237 
238 
Forward declarations for the common classes.
Definition: Animation.hh:33
Encapsulates a position and rotation in three space.
Definition: Pose.hh:42
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:44
static const double GAZEBO_DEPRECATED(8.0) MAX_D
Double maximum value. This value will be similar to 1.79769e+308.
Definition: Helpers.hh:140
static const Matrix4 IDENTITY
Identity matrix.
Definition: Matrix4.hh:224
A 3x3 matrix class.
Definition: Matrix4.hh:40
double * operator[](size_t _row)
Array subscript operator.
Definition: Matrix4.hh:181
A 3x3 matrix class.
Definition: Matrix3.hh:40
A quaternion class.
Definition: Quaternion.hh:48
GAZEBO_VISIBLE void Set(common::Image &_img, const msgs::Image &_msg)
Convert a msgs::Image to a common::Image.
double m[4][4]
The 4x4 matrix.
Definition: Matrix4.hh:230
const double * operator[](size_t _row) const
Definition: Matrix4.hh:188
static const Matrix4 ZERO
Zero matrix.
Definition: Matrix4.hh:227
friend std::ostream & operator<<(std::ostream &_out, const gazebo::math::Matrix4 &_m)
Stream insertion operator.
Definition: Matrix4.hh:208