ccAdjustZoomDlg.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "ccAdjustZoomDlg.h"
  18. //local
  19. #include "ccGLWindowInterface.h"
  20. ccAdjustZoomDlg::ccAdjustZoomDlg(ccGLWindowInterface* win, QWidget* parent/*=nullptr*/)
  21. : QDialog(parent, Qt::Tool)
  22. , Ui::AdjustZoomDialog()
  23. , m_windowWidth_pix(0)
  24. , m_distanceToWidthRatio(0.0)
  25. {
  26. setupUi(this);
  27. if (win)
  28. {
  29. windowLabel->setText(QString("%1 [%2 x %3]").arg(win->getWindowTitle()).arg(win->glWidth()).arg(win->glHeight()));
  30. const ccViewportParameters& params = win->getViewportParameters();
  31. assert(!params.perspectiveView);
  32. m_windowWidth_pix = win->glWidth();
  33. m_distanceToWidthRatio = params.computeDistanceToWidthRatio();
  34. double focalDist = params.getFocalDistance();
  35. if (m_windowWidth_pix < 1)
  36. {
  37. assert(false);
  38. m_windowWidth_pix = 1;
  39. }
  40. if (m_distanceToWidthRatio <= 0.0)
  41. {
  42. assert(false);
  43. m_distanceToWidthRatio = 1.0;
  44. }
  45. focalDoubleSpinBox->setValue(focalDist);
  46. pixelCountSpinBox->setValue(1);
  47. pixelSizeDoubleSpinBox->setValue(focalDist * m_distanceToWidthRatio / m_windowWidth_pix);
  48. }
  49. else
  50. {
  51. windowLabel->setText("Error");
  52. }
  53. connect(focalDoubleSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &ccAdjustZoomDlg::onFocalChanged);
  54. connect(pixelSizeDoubleSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &ccAdjustZoomDlg::onPixelSizeChanged);
  55. connect(pixelCountSpinBox, qOverload<int>(&QSpinBox::valueChanged), this, &ccAdjustZoomDlg::onPixelCountChanged);
  56. }
  57. double ccAdjustZoomDlg::getFocalDistance() const
  58. {
  59. return focalDoubleSpinBox->value();
  60. }
  61. void ccAdjustZoomDlg::onFocalChanged(double focalDist)
  62. {
  63. assert(pixelCountSpinBox->value() > 0);
  64. pixelSizeDoubleSpinBox->blockSignals(true);
  65. double pixelSizeNPixels = (focalDist * m_distanceToWidthRatio * pixelCountSpinBox->value()) / m_windowWidth_pix;
  66. pixelSizeDoubleSpinBox->setValue(pixelSizeNPixels);
  67. pixelSizeDoubleSpinBox->blockSignals(false);
  68. }
  69. void ccAdjustZoomDlg::onPixelSizeChanged(double pixelSizeNPixels)
  70. {
  71. assert(pixelCountSpinBox->value() > 0);
  72. focalDoubleSpinBox->blockSignals(true);
  73. double focalDist = (pixelSizeNPixels * m_windowWidth_pix) / (pixelCountSpinBox->value() * m_distanceToWidthRatio);
  74. focalDoubleSpinBox->setValue(focalDist);
  75. focalDoubleSpinBox->blockSignals(false);
  76. }
  77. void ccAdjustZoomDlg::onPixelCountChanged(int pixelCount)
  78. {
  79. assert(pixelCount > 0);
  80. pixelSizeDoubleSpinBox->blockSignals(true);
  81. double pixelSizeNPixels = (focalDoubleSpinBox->value() * m_distanceToWidthRatio * pixelCount) / m_windowWidth_pix;
  82. pixelSizeDoubleSpinBox->setValue( pixelSizeNPixels );
  83. pixelSizeDoubleSpinBox->blockSignals(false);
  84. }