ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvCameraParamEditDlg.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 
9 
10 #include "ui_cameraParamDlg.h"
11 
12 // Local
14 #include "ecvFileUtils.h"
15 #include "ecvPersistentSettings.h"
16 #include "ecvPickingHub.h"
17 #include "ecvSettingManager.h"
18 
19 // CV_DB_LIB
20 #include <ecvGenericCameraTool.h>
21 
22 // CV_CORE_LIB
23 #include <CVConst.h>
24 #include <CVTools.h>
25 #include <GenericTriangle.h>
26 
27 // Qt
28 #include <QFileDialog>
29 #include <QMdiSubWindow>
30 #include <QtMath>
31 
32 namespace {
33 QStringList getListOfStrings(ecvSettingManager* settings,
34  const QString& defaultTxt,
35  int min,
36  int max) {
37  QStringList val;
38  for (int cc = 0; cc < max; ++cc) {
39  const QString key = QString::number(cc);
40  if (cc < min || settings->contains(key)) {
41  val << settings->value(key, defaultTxt).toString();
42  } else {
43  break;
44  }
45  }
46  return val;
47 }
48 } // namespace
49 
50 //=============================================================================
51 class CameraDialogInternal : public Ui::CameraParamDlg {
52  QVector<QPointer<QToolButton>> CustomViewpointButtons;
53  QPointer<QToolButton> PlusButton;
54 
55 public:
56  CameraDialogInternal() {
57  // Add + bouton
58  this->PlusButton = new QToolButton();
59  this->PlusButton->setObjectName("AddButton");
60  this->PlusButton->setToolTip(QToolButton::tr("Add Current Viewpoint"));
61  this->PlusButton->setIcon(QIcon(":/Resources/images/svg/pqPlus.png"));
62  this->PlusButton->setMinimumSize(QSize(34, 34));
63  }
64 
65  ~CameraDialogInternal() { delete this->PlusButton; }
66 
67  void updateCustomViewpointButtons(::ecvCameraParamEditDlg* self) {
68  QStringList toolTips = self->CustomViewpointToolTips();
69 
70  // Remove supplemental buttons
71  this->PlusButton->disconnect();
72  this->customViewpointGridLayout->removeWidget(this->PlusButton);
73 
74  for (int cc = this->CustomViewpointButtons.size(); cc > toolTips.size();
75  cc--) {
76  this->customViewpointGridLayout->removeWidget(
77  this->CustomViewpointButtons[cc - 1]);
78  delete this->CustomViewpointButtons[cc - 1];
79  }
80  if (this->CustomViewpointButtons.size() > toolTips.size()) {
81  this->CustomViewpointButtons.resize(toolTips.size());
82  }
83 
84  // add / change remaining buttons.
85  for (int cc = 0; cc < toolTips.size(); ++cc) {
86  if (this->CustomViewpointButtons.size() > cc) {
87  this->CustomViewpointButtons[cc]->setToolTip(toolTips[cc]);
88  } else {
89  QToolButton* tb = new QToolButton(self);
90  tb->setObjectName(QString("customViewpoint%1").arg(cc));
91  tb->setText(QString::number(cc + 1));
92  tb->setToolTip(toolTips[cc]);
93  tb->setProperty("pqCameraDialog_INDEX", cc);
94  tb->setMinimumSize(QSize(34, 34));
95  self->connect(tb, SIGNAL(clicked()),
96  SLOT(ApplyCustomViewpoint()));
97  this->CustomViewpointButtons.push_back(tb);
98  this->customViewpointGridLayout->addWidget(tb, cc / 6, cc % 6);
99  }
100  }
101 
102  // Add Plus Button if needed
103  if (toolTips.size() <
105  self->connect(this->PlusButton, SIGNAL(clicked()),
106  SLOT(addCurrentViewpointToCustomViewpoints()));
107  this->customViewpointGridLayout->addWidget(
108  this->PlusButton, toolTips.size() / 6, toolTips.size() % 6);
109  }
110  }
111 };
112 
114  ccPickingHub* pickingHub)
115  //: ccOverlayDialog(parent, pickingHub ? Qt::FramelessWindowHint | Qt::Tool
116  //: : Qt::Tool) //pickingHub = ACloudViewer / otherwise = ccViewer
117  : ccOverlayDialog(parent, Qt::Tool), m_pickingHub(pickingHub) {
118  this->Internal = new CameraDialogInternal;
119  this->Internal->setupUi(this);
120  QObject::connect(this->Internal->viewXPlus, SIGNAL(clicked()), this,
121  SLOT(resetViewDirectionPosX()));
122  QObject::connect(this->Internal->viewXMinus, SIGNAL(clicked()), this,
123  SLOT(resetViewDirectionNegX()));
124  QObject::connect(this->Internal->viewYPlus, SIGNAL(clicked()), this,
125  SLOT(resetViewDirectionPosY()));
126  QObject::connect(this->Internal->viewYMinus, SIGNAL(clicked()), this,
127  SLOT(resetViewDirectionNegY()));
128  QObject::connect(this->Internal->viewZPlus, SIGNAL(clicked()), this,
129  SLOT(resetViewDirectionPosZ()));
130  QObject::connect(this->Internal->viewZMinus, SIGNAL(clicked()), this,
131  SLOT(resetViewDirectionNegZ()));
132 
133  QObject::connect(this->Internal->AutoPickCenterOfRotation,
134  SIGNAL(toggled(bool)), this,
135  SLOT(autoPickRotationCenterWithCamera()));
136 
137  QObject::connect(this->Internal->rollButton, SIGNAL(clicked()), this,
138  SLOT(applyCameraRoll()));
139  QObject::connect(this->Internal->elevationButton, SIGNAL(clicked()), this,
140  SLOT(applyCameraElevation()));
141  QObject::connect(this->Internal->azimuthButton, SIGNAL(clicked()), this,
142  SLOT(applyCameraAzimuth()));
143  QObject::connect(this->Internal->zoomInButton, SIGNAL(clicked()), this,
144  SLOT(applyCameraZoomIn()));
145  QObject::connect(this->Internal->zoomOutButton, SIGNAL(clicked()), this,
146  SLOT(applyCameraZoomOut()));
147 
148  QObject::connect(this->Internal->saveCameraConfiguration, SIGNAL(clicked()),
149  this, SLOT(saveCameraConfiguration()));
150 
151  QObject::connect(this->Internal->loadCameraConfiguration, SIGNAL(clicked()),
152  this, SLOT(loadCameraConfiguration()));
153 
154  QObject::connect(this->Internal->rcxDoubleSpinBox,
155  static_cast<void (QDoubleSpinBox::*)(double)>(
156  &QDoubleSpinBox::valueChanged),
158  QObject::connect(this->Internal->rcyDoubleSpinBox,
159  static_cast<void (QDoubleSpinBox::*)(double)>(
160  &QDoubleSpinBox::valueChanged),
162  QObject::connect(this->Internal->rczDoubleSpinBox,
163  static_cast<void (QDoubleSpinBox::*)(double)>(
164  &QDoubleSpinBox::valueChanged),
166 
167  QObject::connect(this->Internal->rotationFactor,
168  static_cast<void (QDoubleSpinBox::*)(double)>(
169  &QDoubleSpinBox::valueChanged),
171  QObject::connect(this->Internal->factorHorizontalSlider,
172  &QAbstractSlider::valueChanged, this,
174 
175  QObject::connect(this->Internal->configureCustomViewpoints,
176  SIGNAL(clicked()), this,
177  SLOT(ConfigureCustomViewpoints()));
178 
179  this->Internal->AutoPickCenterOfRotation->setChecked(
181 
182  QObject::connect(this->Internal->updatePushButton, SIGNAL(clicked()), this,
183  SLOT(updateCamera()));
184  QObject::connect(this->Internal->pivotPickingToolButton,
185  &QAbstractButton::toggled, this,
187  QObject::connect(ecvSettingManager::TheInstance(), SIGNAL(modified()),
188  SLOT(updateCustomViewpointButtons()));
189  QObject::connect(ecvDisplayTools::TheInstance(),
192 
193  // load custom view buttons with any tool tips set by the user in a previous
194  // session.
195  this->updateCustomViewpointButtons();
196 }
197 
199  delete this->Internal;
200  if (m_tool) {
201  delete m_tool;
202  m_tool = nullptr;
203  }
204 }
205 
207  if (!tool) return false;
208 
209  m_tool = tool;
210  return true;
211 }
212 
214  // with picking hub (CloudViewer)
215  if (!m_associatedWin || !m_pickingHub) {
216  assert(false);
217  return;
218  }
219 
222 
223  pickPointAsPivot(false);
224 }
225 
227  ccHObject* entity, unsigned, int, int, const CCVector3& P) {
228  // without picking hub (ccViewer)
229  if (!m_associatedWin) {
230  assert(false);
231  return;
232  }
233 
234  if (!entity) {
235  return;
236  }
237 
240 
241  pickPointAsPivot(false);
242 }
243 
246 
247  // no such concept for this dialog!
248  // (+ we want to allow dynamic change of associated window)
249  m_processing = false;
250 
251  return true;
252 }
253 
254 void ecvCameraParamEditDlg::linkWith(QMdiSubWindow* qWin) {
255  // corresponding MainWindow
256  QWidget* associatedWin =
257  (qWin ? static_cast<QWidget*>(qWin->widget()) : nullptr);
258 
259  linkWith(associatedWin);
260 }
261 
263  QWidget* oldWin = m_associatedWin;
264 
265  if (!ccOverlayDialog::linkWith(win)) {
266  return false;
267  }
268 
269  if (oldWin != m_associatedWin &&
270  this->Internal->pivotPickingToolButton->isChecked()) {
271  // automatically disable picking mode when changing th
272  pickPointAsPivot(false);
273  }
274 
275  if (oldWin) {
276  oldWin->disconnect(this);
277  }
278 
279  if (m_associatedWin) {
287  connect(ecvDisplayTools::TheInstance(), &ecvDisplayTools::destroyed,
288  this, &QWidget::hide);
289  }
290 
291  return true;
292 }
293 
295  setEnabled(win != nullptr);
296  if (!win) return;
297 
298  // update view mode
299  updateViewMode();
300 
301  if (m_tool) {
302  m_tool->updateCameraParameters();
303  this->updateUi();
304  }
305 }
306 
307 void ecvCameraParamEditDlg::reflectParamChange() {
308  if (!m_tool) return;
309 
310  m_tool->updateCamera();
311 }
312 
314  this->Internal->rcxDoubleSpinBox->blockSignals(true);
315  this->Internal->rcyDoubleSpinBox->blockSignals(true);
316  this->Internal->rczDoubleSpinBox->blockSignals(true);
317  this->Internal->rcxDoubleSpinBox->setValue(P.x);
318  this->Internal->rcyDoubleSpinBox->setValue(P.y);
319  this->Internal->rczDoubleSpinBox->setValue(P.z);
320  this->Internal->rcxDoubleSpinBox->blockSignals(false);
321  this->Internal->rcyDoubleSpinBox->blockSignals(false);
322  this->Internal->rczDoubleSpinBox->blockSignals(false);
323 }
324 
326  if (m_associatedWin) {
327  bool objectBased = true;
328  bool perspective = ecvDisplayTools::GetPerspectiveState();
329 
330  if (!perspective) {
331  this->Internal->currentModeLabel->setText("parallel projection");
332  } else {
333  this->Internal->currentModeLabel->setText("perspective projection");
334  }
335 
336  this->Internal->pivotPickingToolButton->setEnabled(objectBased);
337  this->Internal->eyeAngle->setEnabled(perspective);
338  }
339 }
340 
342  if (!m_tool) return;
343 
344  m_tool->CurrentCameraParam.position.x = this->Internal->xPosition->value();
345  m_tool->CurrentCameraParam.position.y = this->Internal->zPosition->value();
346  m_tool->CurrentCameraParam.position.z = this->Internal->yPosition->value();
347 
348  m_tool->CurrentCameraParam.focal.x = this->Internal->xFocal->value();
349  m_tool->CurrentCameraParam.focal.y = this->Internal->yFocal->value();
350  m_tool->CurrentCameraParam.focal.z = this->Internal->zFocal->value();
351 
352  m_tool->CurrentCameraParam.viewUp.x = this->Internal->xViewup->value();
353  m_tool->CurrentCameraParam.viewUp.y = this->Internal->yViewup->value();
354  m_tool->CurrentCameraParam.viewUp.z = this->Internal->zViewup->value();
355 
357  this->Internal->rotationFactor->value();
358  m_tool->CurrentCameraParam.viewAngle = this->Internal->viewAngle->value();
359  m_tool->CurrentCameraParam.eyeAngle = this->Internal->eyeAngle->value();
361  this->Internal->nearClipping->value();
363  this->Internal->farClipping->value();
364 
365  reflectParamChange();
366 }
367 
369  if (!this->m_tool) return;
370 
371  this->m_tool->updateCameraParameters();
372  this->updateUi();
373 }
374 
375 //-----------------------------------------------------------------------------
376 void ecvCameraParamEditDlg::autoPickRotationCenterWithCamera() {
378  this->Internal->AutoPickCenterOfRotation->isChecked());
379  // m_app->setAutoPickPivot(this->Internal->AutoPickCenterOfRotation->isChecked());
380 }
381 
383  if (!m_tool) return;
384 
385  this->Internal->xPosition->blockSignals(true);
386  this->Internal->zPosition->blockSignals(true);
387  this->Internal->yPosition->blockSignals(true);
388  this->Internal->xPosition->setValue(m_tool->CurrentCameraParam.position.x);
389  this->Internal->zPosition->setValue(m_tool->CurrentCameraParam.position.y);
390  this->Internal->yPosition->setValue(m_tool->CurrentCameraParam.position.z);
391  this->Internal->xPosition->blockSignals(false);
392  this->Internal->zPosition->blockSignals(false);
393  this->Internal->yPosition->blockSignals(false);
394 
395  this->Internal->xFocal->blockSignals(true);
396  this->Internal->yFocal->blockSignals(true);
397  this->Internal->zFocal->blockSignals(true);
398  this->Internal->xFocal->setValue(m_tool->CurrentCameraParam.focal.x);
399  this->Internal->yFocal->setValue(m_tool->CurrentCameraParam.focal.y);
400  this->Internal->zFocal->setValue(m_tool->CurrentCameraParam.focal.z);
401  this->Internal->xFocal->blockSignals(false);
402  this->Internal->yFocal->blockSignals(false);
403  this->Internal->zFocal->blockSignals(false);
404 
405  this->Internal->xViewup->blockSignals(true);
406  this->Internal->yViewup->blockSignals(true);
407  this->Internal->zViewup->blockSignals(true);
408  this->Internal->xViewup->setValue(m_tool->CurrentCameraParam.viewUp.x);
409  this->Internal->yViewup->setValue(m_tool->CurrentCameraParam.viewUp.y);
410  this->Internal->zViewup->setValue(m_tool->CurrentCameraParam.viewUp.z);
411  this->Internal->xViewup->blockSignals(false);
412  this->Internal->yViewup->blockSignals(false);
413  this->Internal->zViewup->blockSignals(false);
414 
415  this->Internal->nearClipping->blockSignals(true);
416  this->Internal->farClipping->blockSignals(true);
417  this->Internal->nearClipping->setValue(
419  this->Internal->farClipping->setValue(
421  this->Internal->nearClipping->blockSignals(false);
422  this->Internal->farClipping->blockSignals(false);
423 
424  this->Internal->viewAngle->blockSignals(true);
425  this->Internal->viewAngle->setValue(m_tool->CurrentCameraParam.viewAngle);
426  this->Internal->viewAngle->blockSignals(false);
427 
428  this->Internal->eyeAngle->blockSignals(true);
429  this->Internal->eyeAngle->setValue(m_tool->CurrentCameraParam.eyeAngle);
430  this->Internal->eyeAngle->blockSignals(false);
431 
432  this->Internal->rcxDoubleSpinBox->blockSignals(true);
433  this->Internal->rcyDoubleSpinBox->blockSignals(true);
434  this->Internal->rczDoubleSpinBox->blockSignals(true);
435  this->Internal->rcxDoubleSpinBox->setValue(
436  m_tool->CurrentCameraParam.pivot.x);
437  this->Internal->rcyDoubleSpinBox->setValue(
438  m_tool->CurrentCameraParam.pivot.y);
439  this->Internal->rczDoubleSpinBox->setValue(
440  m_tool->CurrentCameraParam.pivot.z);
441  this->Internal->rcxDoubleSpinBox->blockSignals(false);
442  this->Internal->rcyDoubleSpinBox->blockSignals(false);
443  this->Internal->rczDoubleSpinBox->blockSignals(false);
444 
445  this->Internal->factorHorizontalSlider->blockSignals(true);
446  this->Internal->factorHorizontalSlider->setValue(
447  qFloor(m_tool->CurrentCameraParam.rotationFactor * 10.0));
448  this->Internal->factorHorizontalSlider->blockSignals(false);
449 
450  this->Internal->rotationFactor->blockSignals(true);
451  this->Internal->rotationFactor->setValue(
453  this->Internal->rotationFactor->blockSignals(false);
454 }
455 
457  if (!m_associatedWin) return;
458 
459  m_associatedWin->blockSignals(true);
460  m_tool->CurrentCameraParam.pivot =
461  CCVector3d(this->Internal->rcxDoubleSpinBox->value(),
462  this->Internal->rcyDoubleSpinBox->value(),
463  this->Internal->rczDoubleSpinBox->value());
464  m_associatedWin->blockSignals(false);
465 
466  reflectParamChange();
467 }
468 
470  this->Internal->factorHorizontalSlider->blockSignals(true);
471  this->Internal->factorHorizontalSlider->setValue(qFloor(val * 10.0));
472  this->Internal->factorHorizontalSlider->blockSignals(false);
473 
475  this->Internal->rotationFactor->value();
476  reflectParamChange();
477 }
478 
480  this->Internal->rotationFactor->setValue(val / 10.0);
481 }
482 
483 //-----------------------------------------------------------------------------
485  auto& internal = (*this->Internal);
486  internal.viewXMinus->setEnabled(enabled);
487  internal.viewXPlus->setEnabled(enabled);
488  internal.viewYMinus->setEnabled(enabled);
489  internal.viewYPlus->setEnabled(enabled);
490  internal.viewZMinus->setEnabled(enabled);
491  internal.viewZPlus->setEnabled(enabled);
492 
493  internal.customViewpointGridLayout->setEnabled(enabled);
494  internal.configureCustomViewpoints->setEnabled(enabled);
495 
496  internal.rcxDoubleSpinBox->setEnabled(enabled);
497  internal.rcyDoubleSpinBox->setEnabled(enabled);
498  internal.rczDoubleSpinBox->setEnabled(enabled);
499  internal.AutoPickCenterOfRotation->setEnabled(enabled);
500 
501  internal.rotationFactor->setEnabled(enabled);
502 
503  internal.xPosition->setEnabled(enabled);
504  internal.yPosition->setEnabled(enabled);
505  internal.zPosition->setEnabled(enabled);
506  internal.xFocal->setEnabled(enabled);
507  internal.yFocal->setEnabled(enabled);
508  internal.zFocal->setEnabled(enabled);
509  internal.xViewup->setEnabled(enabled);
510  internal.yViewup->setEnabled(enabled);
511  internal.zViewup->setEnabled(enabled);
512  internal.viewAngle->setEnabled(enabled);
513  internal.nearClipping->setEnabled(enabled);
514  internal.farClipping->setEnabled(enabled);
515  internal.loadCameraConfiguration->setEnabled(enabled);
516  internal.saveCameraConfiguration->setEnabled(enabled);
517  internal.updatePushButton->setEnabled(enabled);
518 
519  internal.rollButton->setEnabled(enabled);
520  internal.rollAngle->setEnabled(enabled);
521  internal.elevationButton->setEnabled(enabled);
522  internal.elevationAngle->setEnabled(enabled);
523  internal.azimuthButton->setEnabled(enabled);
524  internal.azimuthAngle->setEnabled(enabled);
525  internal.zoomInButton->setEnabled(enabled);
526  internal.zoomFactor->setEnabled(enabled);
527  internal.zoomOutButton->setEnabled(enabled);
528 }
529 
530 //-----------------------------------------------------------------------------
531 void ecvCameraParamEditDlg::resetViewDirection(double look_x,
532  double look_y,
533  double look_z,
534  double up_x,
535  double up_y,
536  double up_z) {
537  if (this->m_tool) {
538  this->m_tool->resetViewDirection(look_x, look_y, look_z, up_x, up_y,
539  up_z);
540  this->cameraChanged();
541  }
542 }
543 
544 //-----------------------------------------------------------------------------
545 void ecvCameraParamEditDlg::resetViewDirectionPosX() {
546  this->resetViewDirection(1, 0, 0, 0, 0, 1);
547 }
548 //-----------------------------------------------------------------------------
549 void ecvCameraParamEditDlg::resetViewDirectionNegX() {
550  this->resetViewDirection(-1, 0, 0, 0, 0, 1);
551 }
552 
553 //-----------------------------------------------------------------------------
554 void ecvCameraParamEditDlg::resetViewDirectionPosY() {
555  this->resetViewDirection(0, 1, 0, 0, 0, 1);
556 }
557 
558 //-----------------------------------------------------------------------------
559 void ecvCameraParamEditDlg::resetViewDirectionNegY() {
560  this->resetViewDirection(0, -1, 0, 0, 0, 1);
561 }
562 
563 //-----------------------------------------------------------------------------
564 void ecvCameraParamEditDlg::resetViewDirectionPosZ() {
565  this->resetViewDirection(0, 0, 1, 0, 1, 0);
566 }
567 
568 //-----------------------------------------------------------------------------
569 void ecvCameraParamEditDlg::resetViewDirectionNegZ() {
570  this->resetViewDirection(0, 0, -1, 0, 1, 0);
571 }
572 
573 //-----------------------------------------------------------------------------
574 void ecvCameraParamEditDlg::adjustCamera(CameraAdjustmentType enType,
575  double value) {
576  if (this->m_tool) {
577  this->m_tool->adjustCamera(
579  this->cameraChanged();
580  }
581 }
582 
583 //-----------------------------------------------------------------------------
584 void ecvCameraParamEditDlg::applyCameraRoll() {
585  this->adjustCamera(CameraAdjustmentType::Roll,
586  this->Internal->rollAngle->value());
587 }
588 
589 //-----------------------------------------------------------------------------
590 void ecvCameraParamEditDlg::applyCameraElevation() {
591  this->adjustCamera(CameraAdjustmentType::Elevation,
592  this->Internal->elevationAngle->value());
593 }
594 
595 //-----------------------------------------------------------------------------
596 void ecvCameraParamEditDlg::applyCameraAzimuth() {
597  this->adjustCamera(CameraAdjustmentType::Azimuth,
598  this->Internal->azimuthAngle->value());
599 }
600 
601 //-----------------------------------------------------------------------------
602 void ecvCameraParamEditDlg::applyCameraZoomIn() {
603  this->adjustCamera(CameraAdjustmentType::Zoom,
604  this->Internal->zoomFactor->value());
605 }
606 
607 //-----------------------------------------------------------------------------
608 void ecvCameraParamEditDlg::applyCameraZoomOut() {
609  this->adjustCamera(CameraAdjustmentType::Zoom,
610  1.0 / this->Internal->zoomFactor->value());
611 }
612 
613 //-----------------------------------------------------------------------------
615  if (ecvCameraParamEditDlg::ConfigureCustomViewpoints(this)) {
616  this->updateCustomViewpointButtons();
617  }
618 }
619 
620 //-----------------------------------------------------------------------------
622  QStringList toolTips = ecvCameraParamEditDlg::CustomViewpointToolTips();
623  QStringList configs =
625 
626  // user modifies the configuration
627  QString currentConfig =
629  ecvCustomViewpointButtonDlg dialog(parentWidget, Qt::WindowFlags(),
630  toolTips, configs, currentConfig);
631  if (dialog.exec() == QDialog::Accepted) {
632  // save the new configuration into the app wide settings.
633  configs = dialog.getConfigurations();
635  settings->beginGroup("CustomViewButtons");
636  settings->beginGroup("Configurations");
637  settings->remove(""); // remove all items in the group.
638  int index = 0;
639  for (const QString& config : configs) {
640  settings->setValue(QString::number(index++), config);
641  }
642  settings->endGroup();
643 
644  toolTips = dialog.getToolTips();
645  settings->beginGroup("ToolTips");
646  settings->remove(""); // remove all items in the group.
647  index = 0;
648  for (const QString& toolTip : toolTips) {
649  settings->setValue(QString::number(index++), toolTip);
650  }
651  settings->endGroup();
652  settings->endGroup();
653  settings->alertSettingsModified();
654  return true;
655  }
656  return false;
657 }
658 
659 void ecvCameraParamEditDlg::addCurrentViewpointToCustomViewpoints() {
661  this->updateCustomViewpointButtons();
662  }
663 }
664 
665 //-----------------------------------------------------------------------------
667  // grab the current camera configuration.
668  QString curCameraParam =
670  // load the existing button configurations from the app wide settings.
671  QStringList configs =
673 
674  // Add current viewpoint config to setting
676  settings->beginGroup("CustomViewButtons");
677  settings->beginGroup("Configurations");
678  settings->setValue(QString::number(configs.size()), curCameraParam);
679  settings->endGroup();
680  settings->beginGroup("ToolTips");
681  settings->setValue(QString::number(configs.size()),
682  QString("Current Viewpoint %1").arg(configs.size() + 1));
683  settings->endGroup();
684  settings->endGroup();
685  settings->alertSettingsModified();
686  return true;
687 }
688 
689 //-----------------------------------------------------------------------------
690 void ecvCameraParamEditDlg::ApplyCustomViewpoint() {
691  int buttonId = -1;
692  if (QObject* asender = this->sender()) {
693  buttonId = asender->property("pqCameraDialog_INDEX").toInt();
694  } else {
695  return;
696  }
697 
698  if (ecvCameraParamEditDlg::ApplyCustomViewpoint(buttonId)) {
699  // camera configuration has been modified update the scene.
700  this->updateUi();
701  this->reflectParamChange();
702  }
703 }
704 
705 //-----------------------------------------------------------------------------
706 bool ecvCameraParamEditDlg::ApplyCustomViewpoint(int CustomViewpointIndex) {
708  settings->beginGroup("CustomViewButtons");
709  settings->beginGroup("Configurations");
710  QString config = settings->value(QString::number(CustomViewpointIndex), "")
711  .toString();
712  settings->endGroup();
713  settings->endGroup();
714  if (config.isEmpty()) {
715  return false;
716  }
717 
720 
721  return true;
722 }
723 
724 //-----------------------------------------------------------------------------
725 bool ecvCameraParamEditDlg::DeleteCustomViewpoint(int CustomViewpointIndex) {
726  QStringList toolTips = ecvCameraParamEditDlg::CustomViewpointToolTips();
727  if (CustomViewpointIndex >= toolTips.size()) {
728  return false;
729  }
730 
732  settings->beginGroup("CustomViewButtons");
733  settings->beginGroup("Configurations");
734  for (int i = 0; i < toolTips.size() - 1; i++) {
735  if (i < CustomViewpointIndex) {
736  continue;
737  }
738  settings->setValue(QString::number(i),
739  settings->value(QString::number(i + 1)));
740  }
741  settings->remove(QString::number(toolTips.size() - 1));
742  settings->endGroup();
743  settings->beginGroup("ToolTips");
744  for (int i = 0; i < toolTips.size() - 1; i++) {
745  if (i < CustomViewpointIndex) {
746  continue;
747  }
748  settings->setValue(QString::number(i),
749  settings->value(QString::number(i + 1)));
750  }
751  settings->remove(QString::number(toolTips.size() - 1));
752  settings->endGroup();
753  settings->endGroup();
754  settings->alertSettingsModified();
755  return true;
756 }
757 
758 //-----------------------------------------------------------------------------
759 bool ecvCameraParamEditDlg::SetToCurrentViewpoint(int CustomViewpointIndex) {
760  // Add current viewpoint config to setting
762  settings->beginGroup("CustomViewButtons");
763  settings->beginGroup("Configurations");
764  settings->setValue(
765  QString::number(CustomViewpointIndex),
767  .c_str()));
768  settings->endGroup();
769  settings->endGroup();
770  settings->alertSettingsModified();
771  return true;
772 }
773 
774 //-----------------------------------------------------------------------------
776  // Recover configurations from settings
778  settings->beginGroup("CustomViewButtons");
779  settings->beginGroup("Configurations");
780  const QStringList configs = getListOfStrings(
784  settings->endGroup();
785  settings->endGroup();
786  return configs;
787 }
788 
789 //-----------------------------------------------------------------------------
791  // Recover tooltTips from settings
793  settings->beginGroup("CustomViewButtons");
794  settings->beginGroup("ToolTips");
795  const QStringList toolTips = getListOfStrings(
799  settings->endGroup();
800  settings->endGroup();
801  return toolTips;
802 }
803 
804 //-----------------------------------------------------------------------------
805 void ecvCameraParamEditDlg::updateCustomViewpointButtons() {
806  this->Internal->updateCustomViewpointButtons(this);
807 }
808 
809 //-----------------------------------------------------------------------------
810 void ecvCameraParamEditDlg::saveCameraConfiguration() {
811  QString filters = ".cam";
812 
813  // default output path (+ filename)
814  QString currentPath =
817  .toString();
818 
819  // ask the user for the output filename
820  QString selectedFilename = QFileDialog::getSaveFileName(
821  this, tr("Save Custom Viewpoints Configuration"), currentPath,
822  filters);
823 
824  if (selectedFilename.isEmpty()) {
825  // process cancelled by the user
826  return;
827  }
828 
829  QString filename = selectedFilename;
831 }
832 
833 //-----------------------------------------------------------------------------
834 void ecvCameraParamEditDlg::loadCameraConfiguration() {
835  QString filters = ".cam";
836 
837  // persistent settings
838  QString currentPath =
841  .toString();
842  QStringList selectedFiles = QFileDialog::getOpenFileNames(
843  this, QString("Load Custom Camera Configuration"), currentPath,
844  filters);
845 
846  if (selectedFiles.isEmpty()) return;
847  QString filename;
848  filename = selectedFiles[0];
850 }
851 
853  if (m_pickingHub) {
854  if (state) {
855  if (!m_pickingHub->addListener(this, true)) {
856  CVLog::Error(
857  "Can't start the picking process (another tool is "
858  "using it)");
859  state = false;
860  }
861  } else {
863  }
864  } else if (m_associatedWin) {
865  if (state) {
871  } else {
873  disconnect(ecvDisplayTools::TheInstance(),
876  }
877  }
878 
879  this->Internal->pivotPickingToolButton->blockSignals(true);
880  this->Internal->pivotPickingToolButton->setChecked(state);
881  this->Internal->pivotPickingToolButton->blockSignals(false);
882 }
Vector3Tpl< double > CCVector3d
Double 3D Vector.
Definition: CVGeom.h:804
std::string filename
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
static std::string FromQString(const QString &qs)
Definition: CVTools.cpp:100
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
Type x
Definition: CVGeom.h:36
Type y
Definition: CVGeom.h:36
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Definition: CVGeom.h:268
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Generic overlay dialog interface.
virtual bool start()
Starts process.
bool m_processing
Running/processing state.
QWidget * m_associatedWin
Associated (MDI) window.
virtual bool linkWith(QWidget *win)
Links the overlay dialog with a MDI window.
Point/triangle picking hub.
Definition: ecvPickingHub.h:29
void removeListener(ccPickingListener *listener, bool autoStopPickingIfLast=true)
Removes a listener.
bool addListener(ccPickingListener *listener, bool exclusive=false, bool autoStartPicking=true, ecvDisplayTools::PICKING_MODE mode=ecvDisplayTools::POINT_OR_TRIANGLE_PICKING)
Adds a listener.
Dialog to interactively edit the camera pose parameters.
void updatePivotPoint(const CCVector3d &P)
Updates dialog values with pivot point.
ccPickingHub * m_pickingHub
Picking hub.
bool setCameraTool(ecvGenericCameraTool *tool)
void SetCameraGroupsEnabled(bool enabled)
void processPickedItem(ccHObject *, unsigned, int, int, const CCVector3 &)
static QStringList CustomViewpointConfigurations()
static bool ApplyCustomViewpoint(int CustomViewpointIndex)
void onItemPicked(const PickedItem &pi) override
Method called whenever an item is picked.
ecvCameraParamEditDlg(QWidget *parent, ccPickingHub *pickingHub)
Default constructor.
void initWith(QWidget *win)
Inits dialog values with specified window.
~ecvCameraParamEditDlg() override
Destructor.
bool start() override
Starts process.
static bool SetToCurrentViewpoint(int CustomViewpointIndex)
static bool AddCurrentViewpointToCustomViewpoints()
void updateViewMode()
Updates current view mode.
static bool ConfigureCustomViewpoints(QWidget *parentWidget)
bool linkWith(QWidget *win) override
Links the overlay dialog with a MDI window.
static QStringList CustomViewpointToolTips()
static bool DeleteCustomViewpoint(int CustomViewpointIndex)
static ecvDisplayTools * TheInstance()
void cameraParamChanged()
static void SetPivotPoint(const CCVector3d &P, bool autoUpdateCameraPos=false, bool verbose=false)
Sets pivot point.
void perspectiveStateChanged()
static void SetPickingMode(PICKING_MODE mode=DEFAULT_PICKING)
void itemPicked(ccHObject *entity, unsigned subEntityID, int x, int y, const CCVector3 &P)
Signal emitted when a point (or a triangle) is picked.
static void UpdateScreen()
void pivotPointChanged(const CCVector3d &)
Signal emitted when the pivot point is changed.
static bool AutoPickPivotAtCenter()
Whether the pivot point is automatically set at the center of the screen.
static void SendAutoPickPivotAtCenter(bool state)
virtual void updateCamera()=0
static CameraInfo CurrentCameraParam
virtual void saveCameraConfiguration(const std::string &file)
virtual void loadCameraConfiguration(const std::string &file)
virtual void resetViewDirection(double look_x, double look_y, double look_z, double up_x, double up_y, double up_z)
virtual void updateCameraParameters()=0
virtual void adjustCamera(CameraAdjustmentType enType, double value)=0
static bool GetPerspectiveState()
Returns perspective mode.
static const QString CurrentPath()
static const QString SaveFile()
static const QString LoadFile()
static void setValue(const QString &section, const QString &key, const QVariant &value)
virtual void remove(const QString &key)
static QVariant getValue(const QString &section, const QString &key, const QVariant &defaultValue=QVariant())
static ecvSettingManager * TheInstance(bool autoInit=true)
Returns the (unique) static instance.
virtual void endGroup()
virtual QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
virtual void beginGroup(const QString &prefix)
virtual void alertSettingsModified()
std::string toString(T x)
Definition: Common.h:80
QString defaultDocPath()
Shortcut for getting the documents location path.
Definition: ecvFileUtils.h:30