ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvGLMatrix.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // Local
11 #include "CV_db.h"
12 #include "ecvGLMatrixTpl.h"
13 
14 // CV_CORE_LIB
15 #include <Eigen.h>
16 #include <SquareMatrix.h>
17 
19 class CV_DB_LIB_API ccGLMatrix : public ccGLMatrixTpl<float> {
20 public:
22 
24  ccGLMatrix() : ccGLMatrixTpl<float>() {}
25 
27 
29  ccGLMatrix(const ccGLMatrixTpl<float>& mat) : ccGLMatrixTpl<float>(mat) {}
30 
32 
34  explicit ccGLMatrix(const float* mat16f) : ccGLMatrixTpl<float>(mat16f) {}
35 
37 
40  explicit ccGLMatrix(const double* mat16d) : ccGLMatrixTpl<float>(mat16d) {}
41 
43 
49  const Vector3Tpl<float>& Y,
50  const Vector3Tpl<float>& Z,
51  const Vector3Tpl<float>& Tr)
52  : ccGLMatrixTpl<float>(X, Y, Z, Tr) {}
53 };
54 
56 class CV_DB_LIB_API ccGLMatrixd : public ccGLMatrixTpl<double> {
57 public:
59 
61  ccGLMatrixd() : ccGLMatrixTpl<double>() {}
62 
64 
67  : ccGLMatrixTpl<double>(mat) {}
68 
70 
72  explicit ccGLMatrixd(const float* mat16f) : ccGLMatrixTpl<double>(mat16f) {}
73 
75 
77  explicit ccGLMatrixd(const double* mat16d)
78  : ccGLMatrixTpl<double>(mat16d) {}
79 
81 
87  const Vector3Tpl<double>& Y,
88  const Vector3Tpl<double>& Z,
89  const Vector3Tpl<double>& Tr)
90  : ccGLMatrixTpl<double>(X, Y, Z, Tr) {}
91 };
92 
93 /*** Helpers ***/
94 
96 template <typename Tin, typename Tout>
98  const Vector3Tpl<Tin>& Tr) {
99  ccGLMatrixTpl<Tout> outputMat;
100  // outputMat.toIdentity(); //already done in the constructor
101 
102  if (R.isValid() && R.size() == 3) {
103  // we copy each column
104  Tout* mat = outputMat.data();
105  for (unsigned j = 0; j < 3; ++j) {
106  *mat++ = static_cast<Tout>(R.m_values[0][j]);
107  *mat++ = static_cast<Tout>(R.m_values[1][j]);
108  *mat++ = static_cast<Tout>(R.m_values[2][j]);
109  mat++;
110  }
111  }
112 
113  outputMat.setTranslation(Vector3Tpl<Tout>(static_cast<Tout>(Tr.x),
114  static_cast<Tout>(Tr.y),
115  static_cast<Tout>(Tr.z)));
116 
117  return outputMat;
118 }
119 
121 template <typename Tin, typename Tout>
123  const Vector3Tpl<Tin>& Tr,
124  Tin S) {
125  ccGLMatrixTpl<Tout> outputMat;
126  // outputMat.toIdentity(); //already done in the constructor
127 
128  if (R.isValid() && R.size() == 3) {
129  // we copy each column
130  Tout* mat = outputMat.data();
131  for (unsigned j = 0; j < 3; ++j) {
132  *mat++ = static_cast<Tout>(R.m_values[0][j] * S);
133  *mat++ = static_cast<Tout>(R.m_values[1][j] * S);
134  *mat++ = static_cast<Tout>(R.m_values[2][j] * S);
135  mat++;
136  }
137  }
138 
139  outputMat.setTranslation(Vector3Tpl<Tout>(static_cast<Tout>(Tr.x),
140  static_cast<Tout>(Tr.y),
141  static_cast<Tout>(Tr.z)));
142 
143  return outputMat;
144 }
145 
148 template <typename Tin, typename Tout>
150  const Vector3Tpl<Tin>& Tr,
151  const Vector3Tpl<Tin>& rotCenter) {
152  ccGLMatrixTpl<Tout> outputMat = FromCCLibMatrix<Tin, Tout>(R, Tr);
153 
154  outputMat.shiftRotationCenter(rotCenter);
155 
156  return outputMat;
157 }
#define CV_DB_LIB_API
Definition: CV_db.h:15
void * X
Definition: SmallVector.cpp:45
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
A 4x4 'transformation' matrix (column major order)
T * data()
Returns a pointer to internal data.
void shiftRotationCenter(const Vector3Tpl< T > &vec)
Shifts rotation center.
void setTranslation(const Vector3Tpl< float > &Tr)
Sets translation (float version)
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
ccGLMatrix(const Vector3Tpl< float > &X, const Vector3Tpl< float > &Y, const Vector3Tpl< float > &Z, const Vector3Tpl< float > &Tr)
Constructor from 4 columns (X,Y,Z,Tr)
Definition: ecvGLMatrix.h:48
ccGLMatrix(const double *mat16d)
Constructor from a double GL matrix array.
Definition: ecvGLMatrix.h:40
ccGLMatrix(const ccGLMatrixTpl< float > &mat)
Copy constructor from a ccGLMatrixTpl.
Definition: ecvGLMatrix.h:29
ccGLMatrix(const float *mat16f)
Constructor from a float GL matrix array.
Definition: ecvGLMatrix.h:34
ccGLMatrix()
Default constructor.
Definition: ecvGLMatrix.h:24
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
ccGLMatrixd(const ccGLMatrixTpl< double > &mat)
Copy constructor from a ccGLMatrixTpl.
Definition: ecvGLMatrix.h:66
ccGLMatrixd(const double *mat16d)
Constructor from a double GL matrix array.
Definition: ecvGLMatrix.h:77
ccGLMatrixd(const Vector3Tpl< double > &X, const Vector3Tpl< double > &Y, const Vector3Tpl< double > &Z, const Vector3Tpl< double > &Tr)
Constructor from 4 columns (X,Y,Z,Tr)
Definition: ecvGLMatrix.h:86
ccGLMatrixd(const float *mat16f)
Constructor from a float GL matrix array.
Definition: ecvGLMatrix.h:72
ccGLMatrixd()
Default constructor.
Definition: ecvGLMatrix.h:61
Scalar ** m_values
The matrix rows.
Definition: SquareMatrix.h:157
bool isValid() const
Returns matrix validity.
Definition: SquareMatrix.h:138
unsigned size() const
Returns matrix size.
Definition: SquareMatrix.h:133
ccGLMatrixTpl< Tout > FromCCLibMatrix(const cloudViewer::SquareMatrixTpl< Tin > &R, const Vector3Tpl< Tin > &Tr)
Constructor from a 3x3 rotation matrix R and a vector Tr.
Definition: ecvGLMatrix.h:97