ccGBLSensorProjectionDlg.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 "ccGBLSensorProjectionDlg.h"
  18. //local
  19. #include "ccCustomDoubleValidator.h"
  20. //qCC_db
  21. #include <ccGBLSensor.h>
  22. //Qt
  23. #include <QSharedPointer>
  24. static QSharedPointer<ccGBLSensor> s_previousSensor; //!< Previous sensor (if any)
  25. ccGBLSensorProjectionDlg::ccGBLSensorProjectionDlg(QWidget* parent)
  26. : QDialog(parent)
  27. , Ui::GBLSensorProjectDialog()
  28. {
  29. setupUi(this);
  30. posXEdit->setValidator(new ccCustomDoubleValidator(this));
  31. posYEdit->setValidator(new ccCustomDoubleValidator(this));
  32. posZEdit->setValidator(new ccCustomDoubleValidator(this));
  33. x1rot->setValidator(new ccCustomDoubleValidator(this));
  34. x2rot->setValidator(new ccCustomDoubleValidator(this));
  35. x3rot->setValidator(new ccCustomDoubleValidator(this));
  36. y1rot->setValidator(new ccCustomDoubleValidator(this));
  37. y2rot->setValidator(new ccCustomDoubleValidator(this));
  38. y3rot->setValidator(new ccCustomDoubleValidator(this));
  39. z1rot->setValidator(new ccCustomDoubleValidator(this));
  40. z2rot->setValidator(new ccCustomDoubleValidator(this));
  41. z3rot->setValidator(new ccCustomDoubleValidator(this));
  42. }
  43. void ccGBLSensorProjectionDlg::initWithPrevious()
  44. {
  45. if (s_previousSensor)
  46. {
  47. initWithGBLSensor(s_previousSensor.data());
  48. }
  49. }
  50. void ccGBLSensorProjectionDlg::saveForNextTime()
  51. {
  52. if (!s_previousSensor)
  53. {
  54. s_previousSensor.reset(new ccGBLSensor);
  55. }
  56. updateGBLSensor(s_previousSensor.data());
  57. }
  58. void ccGBLSensorProjectionDlg::initWithGBLSensor(const ccGBLSensor* sensor)
  59. {
  60. if( !sensor)
  61. return;
  62. const int precision = sizeof(PointCoordinateType) == 8 ? 12 : 8;
  63. /*** Rotation order ***/
  64. {
  65. if (sensor->getRotationOrder() == ccGBLSensor::YAW_THEN_PITCH)
  66. rotationOrderComboBox->setCurrentIndex(0);
  67. else if (sensor->getRotationOrder() == ccGBLSensor::PITCH_THEN_YAW)
  68. rotationOrderComboBox->setCurrentIndex(1);
  69. }
  70. /*** Position + Orientation ***/
  71. {
  72. //rotation matrix
  73. const ccGLMatrix& rot = sensor->getRigidTransformation();
  74. {
  75. const float* mat = rot.data();
  76. x1rot->setText(QString::number(mat[0], 'f', precision));
  77. y1rot->setText(QString::number(mat[1], 'f', precision));
  78. z1rot->setText(QString::number(mat[2], 'f', precision));
  79. x2rot->setText(QString::number(mat[4], 'f', precision));
  80. y2rot->setText(QString::number(mat[5], 'f', precision));
  81. z2rot->setText(QString::number(mat[6], 'f', precision));
  82. x3rot->setText(QString::number(mat[8], 'f', precision));
  83. y3rot->setText(QString::number(mat[9], 'f', precision));
  84. z3rot->setText(QString::number(mat[10], 'f', precision));
  85. }
  86. //center
  87. const float* C = sensor->getRigidTransformation().getTranslation();
  88. posXEdit->setText(QString::number(C[0], 'f', precision));
  89. posYEdit->setText(QString::number(C[1], 'f', precision));
  90. posZEdit->setText(QString::number(C[2], 'f', precision));
  91. }
  92. /*** Angular steps ***/
  93. {
  94. //pitch step
  95. pitchStepSpinBox->setValue(CCCoreLib::RadiansToDegrees(sensor->getPitchStep()));
  96. //yaw step
  97. yawStepSpinBox->setValue(CCCoreLib::RadiansToDegrees(sensor->getYawStep()));
  98. }
  99. /*** Other ***/
  100. {
  101. //max range
  102. maxRangeDoubleSpinBox->setValue(sensor->getSensorRange());
  103. //uncertainty
  104. uncertaintyDoubleSpinBox->setValue(sensor->getUncertainty());
  105. }
  106. }
  107. void ccGBLSensorProjectionDlg::updateGBLSensor(ccGBLSensor* sensor)
  108. {
  109. if (!sensor)
  110. return;
  111. /*** rotation order ***/
  112. {
  113. ccGBLSensor::ROTATION_ORDER rotOrder = (rotationOrderComboBox->currentIndex() == 0 ? ccGBLSensor::YAW_THEN_PITCH : ccGBLSensor::PITCH_THEN_YAW);
  114. sensor->setRotationOrder(rotOrder);
  115. }
  116. /*** Position + Orientation ***/
  117. {
  118. //orientation matrix
  119. ccGLMatrix rot;
  120. {
  121. float* mat = rot.data();
  122. mat[0] = x1rot->text().toFloat();
  123. mat[1] = y1rot->text().toFloat();
  124. mat[2] = z1rot->text().toFloat();
  125. mat[4] = x2rot->text().toFloat();
  126. mat[5] = y2rot->text().toFloat();
  127. mat[6] = z2rot->text().toFloat();
  128. mat[8] = x3rot->text().toFloat();
  129. mat[9] = y3rot->text().toFloat();
  130. mat[10] = z3rot->text().toFloat();
  131. }
  132. //center
  133. CCVector3 C(static_cast<PointCoordinateType>(posXEdit->text().toDouble()),
  134. static_cast<PointCoordinateType>(posYEdit->text().toDouble()),
  135. static_cast<PointCoordinateType>(posZEdit->text().toDouble()));
  136. rot.setTranslation(C);
  137. sensor->setRigidTransformation(rot);
  138. }
  139. /*** Angular steps ***/
  140. {
  141. //pitch step
  142. sensor->setPitchStep(static_cast<PointCoordinateType>(CCCoreLib::DegreesToRadians(pitchStepSpinBox->value())));
  143. //yax step
  144. sensor->setYawStep(static_cast<PointCoordinateType>(CCCoreLib::DegreesToRadians(yawStepSpinBox->value())));
  145. }
  146. /*** Other ***/
  147. {
  148. //max. range
  149. sensor->setSensorRange(static_cast<ScalarType>(maxRangeDoubleSpinBox->value()));
  150. //uncertainty
  151. sensor->setUncertainty(static_cast<ScalarType>(uncertaintyDoubleSpinBox->value()));
  152. }
  153. }