OpenStructure
mat4.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef GEOM_MAT4_HH
20 #define GEOM_MAT4_HH
21 
22 #include <cassert>
23 #include <cstddef> // for size_t
24 #include <ostream>
25 #include <vector>
26 #include <stdexcept>
27 
28 #include <boost/operators.hpp>
29 
31 
32 namespace geom {
33 
34 // fw decl
35 class Mat2;
36 class Mat3;
37 class Vec3;
38 
40  private boost::equality_comparable<Mat4>,
41  private boost::additive<Mat4>,
42  private boost::multiplicative<Mat4, Real>
43 {
44 public:
45  static Mat4 Identity();
46 
48  Mat4();
49 
51 
62  Mat4(Real i00, Real i01, Real i02, Real i03, Real i10, Real i11, Real i12, Real i13,
63  Real i20, Real i21, Real i22, Real i23, Real i30, Real i31, Real i32, Real i33);
65  Mat4(const Mat4& m);
66 
68  explicit Mat4(const Mat2& m);
69 
71  explicit Mat4(const Mat3& m);
72 
74  explicit Mat4(const float[16]);
75 
76  explicit Mat4(const double[16]);
78  Mat4& operator=(const Mat4& m);
79 
81  bool operator==(const Mat4& rhs) const;
82 
83  const Real& At(std::size_t r, std::size_t c) const
84  {
85  if (r>3 || c>3) {
86  throw std::out_of_range("indices must be smaller than 4");
87  }
88  return data_[r][c];
89  }
90 
91  Real& At(std::size_t r, std::size_t c)
92  {
93  if (r>3 || c>3) {
94  throw std::out_of_range("indices must be smaller than 4");
95  }
96  return data_[r][c];
97  }
98 
99  Real& operator()(std::size_t r, std::size_t c)
100  {
101  assert(r<4 && c < 4);
102  return data_[r][c];
103  }
104 
105  const Real& operator()(std::size_t r, std::size_t c) const
106  {
107  assert(r<4 && c < 4);
108  return data_[r][c];
109  }
110 
112  Mat4& operator+=(const Mat4& rhs);
114  Mat4& operator-=(const Mat4& rhs);
115 
116  Mat4& operator*=(const Real d);
117  Mat4& operator/=(const Real d);
118 
119  Mat4& operator*=(const Mat4& m);
120 
122  void PasteRotation(const Mat3& m);
124  void PasteTranslation(const Vec3& v);
125 
126  Real* Data() {return &data_[0][0];}
127  const Real* Data() const {return &data_[0][0];}
128 
129 private:
130  Real data_[4][4];
131 
132  void set(float i00, float i01, float i02, float i03, float i10, float i11, float i12,
133 float i13, float i20, float i21, float i22, float i23, float i30, float i31, float i32,
134 float i33);
135  void set(double i00, double i01, double i02, double i03, double i10, double i11, double
136 i12, double i13, double i20, double i21, double i22, double i23, double i30, double i31,
137 double i32, double i33);
138 
139 };
140 
141 typedef std::vector<Mat4> Mat4List;
142 
143 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& os, const Mat4& m);
144 
145 } // ns geom
146 
147 
148 #endif
Mat4 & operator=(const Mat4 &m)
assignement op
Mat4 & operator+=(const Mat4 &rhs)
addable op
static Mat4 Identity()
Vec3 ExtractTranslation() const
Mat4(const double[16])
Mat4(const Mat4 &m)
Copy ctor.
Mat4 & operator-=(const Mat4 &rhs)
subtractable op
Mat4()
Default initialization, identity matrix.
Mat4 & operator*=(const Real d)
void PasteTranslation(const Vec3 &v)
Mat3 ExtractRotation() const
Mat4 & operator/=(const Real d)
Mat4(const Mat3 &m)
implicit initialization from mat3
Mat4 & operator*=(const Mat4 &m)
const Real & operator()(std::size_t r, std::size_t c) const
Definition: mat4.hh:105
const Real * Data() const
Definition: mat4.hh:127
const Real & At(std::size_t r, std::size_t c) const
Definition: mat4.hh:83
Real * Data()
Definition: mat4.hh:126
Mat4(const float[16])
initialization from array
void PasteRotation(const Mat3 &m)
bool operator==(const Mat4 &rhs) const
comparable
Real & At(std::size_t r, std::size_t c)
Definition: mat4.hh:91
Real & operator()(std::size_t r, std::size_t c)
Definition: mat4.hh:99
Mat4(Real i00, Real i01, Real i02, Real i03, Real i10, Real i11, Real i12, Real i13, Real i20, Real i21, Real i22, Real i23, Real i30, Real i31, Real i32, Real i33)
In with 16 values in row-major order.
Mat4(const Mat2 &m)
implicit initialization from mat2
Three dimensional vector class, using Real precision.
Definition: vec3.hh:48
#define DLLEXPORT_OST_GEOM
float Real
Definition: base.hh:44
std::vector< Mat4 > Mat4List
Definition: mat4.hh:141
std::ostream & operator<<(std::ostream &os, const AlignedCuboid &c)