matrixDisplayDlg.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #include "matrixDisplayDlg.h"
  18. #include "ui_matrixDisplayDlg.h"
  19. #include "CCMath.h"
  20. //local
  21. #include "ccPersistentSettings.h"
  22. //qCC_gl
  23. #include <ccGuiParameters.h>
  24. // qCC_db
  25. #include "ccFileUtils.h"
  26. //Qt
  27. #include <QClipboard>
  28. #include <QFileDialog>
  29. #include <QSettings>
  30. MatrixDisplayDlg::MatrixDisplayDlg(QWidget* parent/*=nullptr*/)
  31. : QWidget(parent)
  32. , m_ui( new Ui::MatrixDisplayDlg )
  33. {
  34. m_ui->setupUi(this);
  35. connect(m_ui->exportToAsciiPushButton, &QAbstractButton::clicked, this, &MatrixDisplayDlg::exportToASCII);
  36. connect(m_ui->exportToClipboardPushButton, &QAbstractButton::clicked, this, &MatrixDisplayDlg::exportToClipboard);
  37. show();
  38. }
  39. MatrixDisplayDlg::~MatrixDisplayDlg()
  40. {
  41. delete m_ui;
  42. }
  43. void MatrixDisplayDlg::fillDialogWith(const ccGLMatrix& mat)
  44. {
  45. m_mat = ccGLMatrixd(mat.data());
  46. int precision = ccGui::Parameters().displayedNumPrecision;
  47. //display as 4x4 matrix
  48. m_ui->maxTextEdit->setText(mat.toString(precision));
  49. //display as rotation vector/angle
  50. {
  51. PointCoordinateType angle_rad;
  52. CCVector3 axis3D;
  53. CCVector3 t3D;
  54. mat.getParameters(angle_rad, axis3D, t3D);
  55. fillDialogWith(axis3D, angle_rad, t3D, precision);
  56. }
  57. }
  58. void MatrixDisplayDlg::fillDialogWith(const ccGLMatrixd& mat)
  59. {
  60. m_mat = mat;
  61. int precision = ccGui::Parameters().displayedNumPrecision;
  62. //display as 4x4 matrix
  63. m_ui->maxTextEdit->setText(mat.toString(precision));
  64. //display as rotation vector/angle
  65. {
  66. double angle_rad;
  67. CCVector3d axis3D;
  68. CCVector3d t3D;
  69. mat.getParameters(angle_rad, axis3D, t3D);
  70. fillDialogWith(axis3D,angle_rad,t3D,precision);
  71. }
  72. }
  73. void MatrixDisplayDlg::fillDialogWith(const CCVector3d& axis, double angle_rad, const CCVector3d& T, int precision)
  74. {
  75. //center position
  76. QString centerStr = QStringLiteral("%0 ; %1 ; %2").arg(T.x,0,'f',precision).arg(T.y,0,'f',precision).arg(T.z,0,'f',precision);
  77. //rotation axis
  78. QString axisStr = QStringLiteral("%0 ; %1 ; %2").arg(axis.x,0,'f',precision).arg(axis.y,0,'f',precision).arg(axis.z,0,'f',precision);
  79. //rotation angle
  80. QString angleStr = QStringLiteral("%1 deg.").arg( CCCoreLib::RadiansToDegrees( angle_rad ), 0, 'f', precision );
  81. m_ui->axisLabel->setText(axisStr);
  82. m_ui->angleLabel->setText(angleStr);
  83. m_ui->centerLabel->setText(centerStr);
  84. }
  85. void MatrixDisplayDlg::clear()
  86. {
  87. m_ui->maxTextEdit->setText("Invalid transformation");
  88. m_ui->axisLabel->setText(QString());
  89. m_ui->angleLabel->setText(QString());
  90. m_ui->centerLabel->setText(QString());
  91. m_mat.toZero();
  92. }
  93. void MatrixDisplayDlg::exportToASCII()
  94. {
  95. //persistent settings
  96. QSettings settings;
  97. settings.beginGroup(ccPS::LoadFile()); //use the same folder as the load one
  98. QString currentPath = settings.value(ccPS::CurrentPath(), ccFileUtils::defaultDocPath()).toString();
  99. QString outputFilename = QFileDialog::getSaveFileName(this, "Select output file", currentPath, "*.mat.txt");
  100. if (outputFilename.isEmpty())
  101. return;
  102. if (m_mat.toAsciiFile(outputFilename))
  103. {
  104. ccLog::Print(QString("[I/O] Matrix saved as '%1'").arg(outputFilename));
  105. }
  106. else
  107. {
  108. ccLog::Error(QString("Failed to save matrix as '%1'").arg(outputFilename));
  109. }
  110. //save last saving location
  111. settings.setValue(ccPS::CurrentPath(),QFileInfo(outputFilename).absolutePath());
  112. settings.endGroup();
  113. }
  114. void MatrixDisplayDlg::exportToClipboard()
  115. {
  116. QClipboard* clipboard = QApplication::clipboard();
  117. if (clipboard)
  118. {
  119. clipboard->setText(m_mat.toString());
  120. ccLog::Print("Matrix saved to clipboard!");
  121. }
  122. }