10 #include "ui_cameraParamDlg.h"
28 #include <QFileDialog>
29 #include <QMdiSubWindow>
34 const QString& defaultTxt,
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();
51 class CameraDialogInternal :
public Ui::CameraParamDlg {
52 QVector<QPointer<QToolButton>> CustomViewpointButtons;
53 QPointer<QToolButton> PlusButton;
56 CameraDialogInternal() {
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));
65 ~CameraDialogInternal() {
delete this->PlusButton; }
68 QStringList toolTips =
self->CustomViewpointToolTips();
71 this->PlusButton->disconnect();
72 this->customViewpointGridLayout->removeWidget(this->PlusButton);
74 for (
int cc = this->CustomViewpointButtons.size(); cc > toolTips.size();
76 this->customViewpointGridLayout->removeWidget(
77 this->CustomViewpointButtons[cc - 1]);
78 delete this->CustomViewpointButtons[cc - 1];
80 if (this->CustomViewpointButtons.size() > toolTips.size()) {
81 this->CustomViewpointButtons.resize(toolTips.size());
85 for (
int cc = 0; cc < toolTips.size(); ++cc) {
86 if (this->CustomViewpointButtons.size() > cc) {
87 this->CustomViewpointButtons[cc]->setToolTip(toolTips[cc]);
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);
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);
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()));
133 QObject::connect(this->Internal->AutoPickCenterOfRotation,
134 SIGNAL(toggled(
bool)),
this,
135 SLOT(autoPickRotationCenterWithCamera()));
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()));
148 QObject::connect(this->Internal->saveCameraConfiguration, SIGNAL(clicked()),
149 this, SLOT(saveCameraConfiguration()));
151 QObject::connect(this->Internal->loadCameraConfiguration, SIGNAL(clicked()),
152 this, SLOT(loadCameraConfiguration()));
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),
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,
175 QObject::connect(this->Internal->configureCustomViewpoints,
176 SIGNAL(clicked()),
this,
179 this->Internal->AutoPickCenterOfRotation->setChecked(
182 QObject::connect(this->Internal->updatePushButton, SIGNAL(clicked()),
this,
184 QObject::connect(this->Internal->pivotPickingToolButton,
185 &QAbstractButton::toggled,
this,
188 SLOT(updateCustomViewpointButtons()));
195 this->updateCustomViewpointButtons();
199 delete this->Internal;
207 if (!tool)
return false;
256 QWidget* associatedWin =
257 (qWin ?
static_cast<QWidget*
>(qWin->widget()) :
nullptr);
270 this->Internal->pivotPickingToolButton->isChecked()) {
276 oldWin->disconnect(
this);
288 this, &QWidget::hide);
295 setEnabled(win !=
nullptr);
307 void ecvCameraParamEditDlg::reflectParamChange() {
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);
327 bool objectBased =
true;
331 this->Internal->currentModeLabel->setText(
"parallel projection");
333 this->Internal->currentModeLabel->setText(
"perspective projection");
336 this->Internal->pivotPickingToolButton->setEnabled(objectBased);
337 this->Internal->eyeAngle->setEnabled(perspective);
357 this->Internal->rotationFactor->value();
361 this->Internal->nearClipping->value();
363 this->Internal->farClipping->value();
365 reflectParamChange();
369 if (!this->m_tool)
return;
376 void ecvCameraParamEditDlg::autoPickRotationCenterWithCamera() {
378 this->Internal->AutoPickCenterOfRotation->isChecked());
385 this->Internal->xPosition->blockSignals(
true);
386 this->Internal->zPosition->blockSignals(
true);
387 this->Internal->yPosition->blockSignals(
true);
391 this->Internal->xPosition->blockSignals(
false);
392 this->Internal->zPosition->blockSignals(
false);
393 this->Internal->yPosition->blockSignals(
false);
395 this->Internal->xFocal->blockSignals(
true);
396 this->Internal->yFocal->blockSignals(
true);
397 this->Internal->zFocal->blockSignals(
true);
401 this->Internal->xFocal->blockSignals(
false);
402 this->Internal->yFocal->blockSignals(
false);
403 this->Internal->zFocal->blockSignals(
false);
405 this->Internal->xViewup->blockSignals(
true);
406 this->Internal->yViewup->blockSignals(
true);
407 this->Internal->zViewup->blockSignals(
true);
411 this->Internal->xViewup->blockSignals(
false);
412 this->Internal->yViewup->blockSignals(
false);
413 this->Internal->zViewup->blockSignals(
false);
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);
424 this->Internal->viewAngle->blockSignals(
true);
426 this->Internal->viewAngle->blockSignals(
false);
428 this->Internal->eyeAngle->blockSignals(
true);
430 this->Internal->eyeAngle->blockSignals(
false);
432 this->Internal->rcxDoubleSpinBox->blockSignals(
true);
433 this->Internal->rcyDoubleSpinBox->blockSignals(
true);
434 this->Internal->rczDoubleSpinBox->blockSignals(
true);
435 this->Internal->rcxDoubleSpinBox->setValue(
437 this->Internal->rcyDoubleSpinBox->setValue(
439 this->Internal->rczDoubleSpinBox->setValue(
441 this->Internal->rcxDoubleSpinBox->blockSignals(
false);
442 this->Internal->rcyDoubleSpinBox->blockSignals(
false);
443 this->Internal->rczDoubleSpinBox->blockSignals(
false);
445 this->Internal->factorHorizontalSlider->blockSignals(
true);
446 this->Internal->factorHorizontalSlider->setValue(
448 this->Internal->factorHorizontalSlider->blockSignals(
false);
450 this->Internal->rotationFactor->blockSignals(
true);
451 this->Internal->rotationFactor->setValue(
453 this->Internal->rotationFactor->blockSignals(
false);
461 CCVector3d(this->Internal->rcxDoubleSpinBox->value(),
462 this->Internal->rcyDoubleSpinBox->value(),
463 this->Internal->rczDoubleSpinBox->value());
466 reflectParamChange();
470 this->Internal->factorHorizontalSlider->blockSignals(
true);
471 this->Internal->factorHorizontalSlider->setValue(qFloor(val * 10.0));
472 this->Internal->factorHorizontalSlider->blockSignals(
false);
475 this->Internal->rotationFactor->value();
476 reflectParamChange();
480 this->Internal->rotationFactor->setValue(val / 10.0);
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);
493 internal.customViewpointGridLayout->setEnabled(enabled);
494 internal.configureCustomViewpoints->setEnabled(enabled);
496 internal.rcxDoubleSpinBox->setEnabled(enabled);
497 internal.rcyDoubleSpinBox->setEnabled(enabled);
498 internal.rczDoubleSpinBox->setEnabled(enabled);
499 internal.AutoPickCenterOfRotation->setEnabled(enabled);
501 internal.rotationFactor->setEnabled(enabled);
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);
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);
531 void ecvCameraParamEditDlg::resetViewDirection(
double look_x,
545 void ecvCameraParamEditDlg::resetViewDirectionPosX() {
546 this->resetViewDirection(1, 0, 0, 0, 0, 1);
549 void ecvCameraParamEditDlg::resetViewDirectionNegX() {
550 this->resetViewDirection(-1, 0, 0, 0, 0, 1);
554 void ecvCameraParamEditDlg::resetViewDirectionPosY() {
555 this->resetViewDirection(0, 1, 0, 0, 0, 1);
559 void ecvCameraParamEditDlg::resetViewDirectionNegY() {
560 this->resetViewDirection(0, -1, 0, 0, 0, 1);
564 void ecvCameraParamEditDlg::resetViewDirectionPosZ() {
565 this->resetViewDirection(0, 0, 1, 0, 1, 0);
569 void ecvCameraParamEditDlg::resetViewDirectionNegZ() {
570 this->resetViewDirection(0, 0, -1, 0, 1, 0);
574 void ecvCameraParamEditDlg::adjustCamera(CameraAdjustmentType enType,
584 void ecvCameraParamEditDlg::applyCameraRoll() {
585 this->adjustCamera(CameraAdjustmentType::Roll,
586 this->Internal->rollAngle->value());
590 void ecvCameraParamEditDlg::applyCameraElevation() {
591 this->adjustCamera(CameraAdjustmentType::Elevation,
592 this->Internal->elevationAngle->value());
596 void ecvCameraParamEditDlg::applyCameraAzimuth() {
597 this->adjustCamera(CameraAdjustmentType::Azimuth,
598 this->Internal->azimuthAngle->value());
602 void ecvCameraParamEditDlg::applyCameraZoomIn() {
603 this->adjustCamera(CameraAdjustmentType::Zoom,
604 this->Internal->zoomFactor->value());
608 void ecvCameraParamEditDlg::applyCameraZoomOut() {
609 this->adjustCamera(CameraAdjustmentType::Zoom,
610 1.0 / this->Internal->zoomFactor->value());
615 if (ecvCameraParamEditDlg::ConfigureCustomViewpoints(
this)) {
616 this->updateCustomViewpointButtons();
623 QStringList configs =
627 QString currentConfig =
630 toolTips, configs, currentConfig);
631 if (dialog.exec() == QDialog::Accepted) {
639 for (
const QString& config : configs) {
640 settings->
setValue(QString::number(index++), config);
648 for (
const QString& toolTip : toolTips) {
649 settings->
setValue(QString::number(index++), toolTip);
659 void ecvCameraParamEditDlg::addCurrentViewpointToCustomViewpoints() {
661 this->updateCustomViewpointButtons();
668 QString curCameraParam =
671 QStringList configs =
678 settings->
setValue(QString::number(configs.size()), curCameraParam);
681 settings->
setValue(QString::number(configs.size()),
682 QString(
"Current Viewpoint %1").arg(configs.size() + 1));
690 void ecvCameraParamEditDlg::ApplyCustomViewpoint() {
692 if (QObject* asender = this->sender()) {
693 buttonId = asender->property(
"pqCameraDialog_INDEX").toInt();
698 if (ecvCameraParamEditDlg::ApplyCustomViewpoint(buttonId)) {
701 this->reflectParamChange();
710 QString config = settings->
value(QString::number(CustomViewpointIndex),
"")
714 if (config.isEmpty()) {
727 if (CustomViewpointIndex >= toolTips.size()) {
734 for (
int i = 0; i < toolTips.size() - 1; i++) {
735 if (i < CustomViewpointIndex) {
738 settings->
setValue(QString::number(i),
739 settings->
value(QString::number(i + 1)));
741 settings->
remove(QString::number(toolTips.size() - 1));
744 for (
int i = 0; i < toolTips.size() - 1; i++) {
745 if (i < CustomViewpointIndex) {
748 settings->
setValue(QString::number(i),
749 settings->
value(QString::number(i + 1)));
751 settings->
remove(QString::number(toolTips.size() - 1));
765 QString::number(CustomViewpointIndex),
780 const QStringList configs = getListOfStrings(
795 const QStringList toolTips = getListOfStrings(
805 void ecvCameraParamEditDlg::updateCustomViewpointButtons() {
806 this->Internal->updateCustomViewpointButtons(
this);
810 void ecvCameraParamEditDlg::saveCameraConfiguration() {
811 QString filters =
".cam";
814 QString currentPath =
820 QString selectedFilename = QFileDialog::getSaveFileName(
821 this, tr(
"Save Custom Viewpoints Configuration"), currentPath,
824 if (selectedFilename.isEmpty()) {
829 QString
filename = selectedFilename;
834 void ecvCameraParamEditDlg::loadCameraConfiguration() {
835 QString filters =
".cam";
838 QString currentPath =
842 QStringList selectedFiles = QFileDialog::getOpenFileNames(
843 this, QString(
"Load Custom Camera Configuration"), currentPath,
846 if (selectedFiles.isEmpty())
return;
857 "Can't start the picking process (another tool is "
879 this->Internal->pivotPickingToolButton->blockSignals(
true);
880 this->Internal->pivotPickingToolButton->setChecked(state);
881 this->Internal->pivotPickingToolButton->blockSignals(
false);
Vector3Tpl< double > CCVector3d
Double 3D Vector.
static bool Error(const char *format,...)
Display an error dialog with formatted message.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
Hierarchical CLOUDVIEWER Object.
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.
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 rotationFactorChanged(double)
void onItemPicked(const PickedItem &pi) override
Method called whenever an item is picked.
ecvCameraParamEditDlg(QWidget *parent, ccPickingHub *pickingHub)
Default constructor.
void pickPointAsPivot(bool)
void zfactorSliderMoved(int val)
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 const QString CurrentPath()
static const QString SaveFile()
static const QString LoadFile()
static void setValue(const QString §ion, const QString &key, const QVariant &value)
virtual void remove(const QString &key)
static QVariant getValue(const QString §ion, const QString &key, const QVariant &defaultValue=QVariant())
static ecvSettingManager * TheInstance(bool autoInit=true)
Returns the (unique) static instance.
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)
QString defaultDocPath()
Shortcut for getting the documents location path.