ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
matrixDisplayDlg.cpp
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 #include "matrixDisplayDlg.h"
9 
10 // local
11 #include "ecvPersistentSettings.h"
12 
13 // CV_DB_LIB
14 #include <ecvFileUtils.h>
15 #include <ecvGuiParameters.h>
16 
17 // Qt
18 #include <QClipboard>
19 #include <QFileDialog>
20 #include <QSettings>
21 
22 MatrixDisplayDlg::MatrixDisplayDlg(QWidget* parent /*=0*/)
23  : QWidget(parent), Ui::MatrixDisplayDlg() {
24  setupUi(this);
25 
26  connect(exportToAsciiPushButton, &QAbstractButton::clicked, this,
28  connect(exportToClipboardPushButton, &QAbstractButton::clicked, this,
30 
31  show();
32 }
33 
35  m_mat = ccGLMatrixd(mat.data());
36 
37  int precision = ecvGui::Parameters().displayedNumPrecision;
38 
39  // display as 4x4 matrix
40  maxTextEdit->setText(mat.toString(precision));
41 
42  // display as rotation vector/angle
43  {
44  PointCoordinateType angle_rad;
45  CCVector3 axis3D, t3D;
46  mat.getParameters(angle_rad, axis3D, t3D);
47 
48  fillDialogWith(CCVector3d::fromArray(axis3D.u), angle_rad,
49  CCVector3d::fromArray(t3D.u), precision);
50  }
51 }
52 
54  m_mat = mat;
55 
56  int precision = ecvGui::Parameters().displayedNumPrecision;
57 
58  // display as 4x4 matrix
59  maxTextEdit->setText(mat.toString(precision));
60 
61  // display as rotation vector/angle
62  {
63  double angle_rad;
64  CCVector3d axis3D, t3D;
65  mat.getParameters(angle_rad, axis3D, t3D);
66 
67  fillDialogWith(axis3D, angle_rad, t3D, precision);
68  }
69 }
70 
72  double angle_rad,
73  const CCVector3d& T,
74  int precision) {
75  // center position
76  QString centerStr = QString("%0 ; %1 ; %2")
77  .arg(T.x, 0, 'f', precision)
78  .arg(T.y, 0, 'f', precision)
79  .arg(T.z, 0, 'f', precision);
80  // rotation axis
81  QString axisStr = QString("%0 ; %1 ; %2")
82  .arg(axis.x, 0, 'f', precision)
83  .arg(axis.y, 0, 'f', precision)
84  .arg(axis.z, 0, 'f', precision);
85  // rotation angle
86  QString angleStr = QString("%1 deg.").arg(
87  cloudViewer::RadiansToDegrees(angle_rad), 0, 'f', precision);
88 
89  axisLabel->setText(axisStr);
90  angleLabel->setText(angleStr);
91  centerLabel->setText(centerStr);
92 }
93 
95  maxTextEdit->setText("Invalid transformation");
96  axisLabel->setText(QString());
97  angleLabel->setText(QString());
98  centerLabel->setText(QString());
99  m_mat.toZero();
100 }
101 
103  // persistent settings
104  QSettings settings;
105  settings.beginGroup(
106  ecvPS::LoadFile()); // use the same folder as the load one
107  QString currentPath =
109  .toString();
110 
111  QString outputFilename = QFileDialog::getSaveFileName(
112  this, "Select output file", currentPath, "*.mat.txt");
113  if (outputFilename.isEmpty()) return;
114 
115  if (m_mat.toAsciiFile(outputFilename)) {
116  CVLog::Print(QString("[I/O] Matrix saved as '%1'").arg(outputFilename));
117  } else {
118  CVLog::Error(
119  QString("Failed to save matrix as '%1'").arg(outputFilename));
120  }
121 
122  // save last saving location
123  settings.setValue(ecvPS::CurrentPath(),
124  QFileInfo(outputFilename).absolutePath());
125  settings.endGroup();
126 }
127 
129  QClipboard* clipboard = QApplication::clipboard();
130  if (clipboard) {
131  clipboard->setText(m_mat.toString());
132  CVLog::Print("Matrix saved to clipboard!");
133  }
134 }
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
Simple widget to display a 4x4 matrix in various formats.
void exportToASCII()
Exports current matrix to an ASCII file.
void clear()
Clears widget.
MatrixDisplayDlg(QWidget *parent=0)
Default constructor.
void exportToClipboard()
Exports current matrix to the clipboard.
ccGLMatrixd m_mat
Matrix.
void fillDialogWith(const ccGLMatrix &mat)
Updates dialog with a given (float) matrix.
Type y
Definition: CVGeom.h:137
Type u[3]
Definition: CVGeom.h:139
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
QString toString(int precision=12, QChar separator=' ') const
Returns matrix as a string.
virtual void toZero()
Clears matrix.
T * data()
Returns a pointer to internal data.
void getParameters(T &alpha_rad, Vector3Tpl< T > &axis3D, Vector3Tpl< T > &t3D) const
virtual bool toAsciiFile(QString filename, int precision=12) const
Saves matrix to an ASCII file.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
static const ParamStruct & Parameters()
Returns the stored values of each parameter.
static const QString CurrentPath()
static const QString LoadFile()
float RadiansToDegrees(int radians)
Convert radians to degrees.
Definition: CVMath.h:71
QString defaultDocPath()
Shortcut for getting the documents location path.
Definition: ecvFileUtils.h:30
unsigned displayedNumPrecision
Displayed numbers precision.