ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
BundlerImportDlg.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 
8 #include "BundlerImportDlg.h"
9 
10 // Qt
11 #include <QDoubleSpinBox>
12 #include <QFileDialog>
13 #include <QLineEdit>
14 #include <QMessageBox>
15 #include <QPushButton>
16 #include <QSettings>
17 #include <QToolButton>
18 
19 // system
20 #include <assert.h>
21 #include <stdio.h>
22 
23 // CV_DB_LIB
24 #include <ecvGLMatrix.h>
25 
26 BundlerImportDlg::BundlerImportDlg(QWidget* parent) : QDialog(parent) {
27  setupUi(this);
28 
29  applyTransfoMatrixTextEdit->setVisible(false);
30 
32 
33  connect(buttonBox, &QDialogButtonBox::accepted, this,
35  connect(browseImageListFileToolButton, &QAbstractButton::clicked, this,
37  connect(browseAltKeypointsFileToolButton, &QAbstractButton::clicked, this,
39 }
40 
42 
44  QSettings settings;
45  settings.beginGroup("BundlerImport");
46 
47  // read parameters
48  double scaleFactor =
49  settings.value("scaleFactor", imageScaleDoubleSpinBox->value())
50  .toDouble();
51  bool orthoRectifyAsCloud =
52  settings.value("orthoRectifyAsClouds",
53  orthoRectifyAsCloudCheckBox->isChecked())
54  .toBool();
55  bool orthoRectifyAsImage =
56  settings.value("orthoRectifyAsImages",
57  orthoRectifyAsImageCheckBox->isChecked())
58  .toBool();
59  bool undistortImages = settings.value("undistortImages",
60  undistortImagesCheckBox->isChecked())
61  .toBool();
62  bool generateColoredDTM =
63  settings.value("generateColoredDTM",
64  generateColoredDTMGroupBox->isChecked())
65  .toBool();
66  bool keepImagesInMemory =
67  settings.value("keepImagesInMemory",
68  keepImagesInMemoryCheckBox->isChecked())
69  .toBool();
70  bool importImages =
71  settings.value("importImages", imagesGroupBox->isChecked())
72  .toBool();
73  bool useAltKeypoints = /*settings.value("useAltKeypoints",
74  altKeypointsCheckBox->isChecked()).toBool()*/
75  false; // DGM: if we don't handle the filename, it's too dangerous
76  bool importKeypoints = settings.value("importKeypoints",
77  importKeypointsGroupBox->isChecked())
78  .toBool();
79  int dtmVerticesCount =
80  settings.value("dtmVerticesCount", dtmVerticesSpinBox->value())
81  .toInt();
82  int orthoRectMethod =
83  settings.value("orthoRectMethod",
84  orthoRectMethodComboBox->currentIndex())
85  .toInt();
86 
87  // apply parameters
88  imageScaleDoubleSpinBox->setValue(scaleFactor);
89  orthoRectifyAsCloudCheckBox->setChecked(orthoRectifyAsCloud);
90  orthoRectifyAsImageCheckBox->setChecked(orthoRectifyAsImage);
91  undistortImagesCheckBox->setChecked(undistortImages);
92  generateColoredDTMGroupBox->setChecked(generateColoredDTM);
93  imagesGroupBox->setChecked(importImages);
94  altKeypointsCheckBox->setChecked(useAltKeypoints);
95  importKeypointsGroupBox->setChecked(importKeypoints);
96  dtmVerticesSpinBox->setValue(dtmVerticesCount);
97  keepImagesInMemoryCheckBox->setChecked(keepImagesInMemory);
98  orthoRectMethodComboBox->setCurrentIndex(orthoRectMethod);
99 
100  settings.endGroup();
101 }
102 
104  // check matrix validity
105  if (customVertAxisRadioButton->isChecked()) {
106  bool success;
107  ccGLMatrixd::FromString(applyTransfoMatrixTextEdit->toPlainText(),
108  success);
109  if (!success) {
110  QMessageBox::critical(this, "Invalid matrix",
111  "Invalid input 4x4 matrix!");
112  return;
113  }
114  }
115 
116  QSettings settings;
117  settings.beginGroup("BundlerImport");
118 
119  // write parameters
120  settings.setValue("scaleFactor", imageScaleDoubleSpinBox->value());
121  settings.setValue("orthoRectifyAsClouds",
122  orthoRectifyAsCloudCheckBox->isChecked());
123  settings.setValue("orthoRectifyAsImages",
124  orthoRectifyAsImageCheckBox->isChecked());
125  settings.setValue("undistortImages", undistortImagesCheckBox->isChecked());
126  settings.setValue("generateColoredDTM",
127  generateColoredDTMGroupBox->isChecked());
128  settings.setValue("keepImagesInMemory",
129  keepImagesInMemoryCheckBox->isChecked());
130  settings.setValue("importImages", imagesGroupBox->isChecked());
131  settings.setValue("useAltKeypoints", altKeypointsCheckBox->isChecked());
132  settings.setValue("importKeypoints", importKeypointsGroupBox->isChecked());
133  settings.setValue("dtmVerticesCount", dtmVerticesSpinBox->value());
134  settings.setValue("orthoRectMethod",
135  orthoRectMethodComboBox->currentIndex());
136 
137  settings.endGroup();
138 
139  accept();
140 }
141 
143  return altKeypointsCheckBox->isChecked();
144 }
145 
147  return importKeypointsGroupBox->isEnabled() &&
148  importKeypointsGroupBox->isChecked();
149 }
150 
152  return imagesGroupBox->isEnabled() && imagesGroupBox->isChecked();
153 }
154 
156  return imagesGroupBox->isEnabled() &&
157  undistortImagesCheckBox->isEnabled() &&
158  undistortImagesCheckBox->isChecked();
159 }
160 
162  return imagesGroupBox->isEnabled() &&
163  orthoRectifyAsCloudCheckBox->isChecked();
164 }
165 
167  return imagesGroupBox->isEnabled() &&
168  orthoRectifyAsImageCheckBox->isChecked();
169 }
170 
172  return imagesGroupBox->isEnabled() &&
173  generateColoredDTMGroupBox->isChecked();
174 }
175 
177  return imagesGroupBox->isEnabled() &&
178  keepImagesInMemoryCheckBox->isChecked();
179 }
180 
183  switch (orthoRectMethodComboBox->currentIndex()) {
184  case 0:
185  return OPTIMIZED;
186  case 1:
187  return DIRECT_UNDISTORTED;
188  case 2:
189  return DIRECT;
190  default:
191  assert(false);
192  break;
193  }
194 
195  return OPTIMIZED;
196 }
197 
199  keyPointsCountLabel->setText(QString::number(count));
200  importKeypointsGroupBox->setEnabled(count != 0);
201  if (count == 0) // can't ortho-rectify without keypoints!
202  {
203  orthoRectifyAsImageCheckBox->setChecked(false);
204  orthoRectifyAsImageCheckBox->setEnabled(false);
205  orthoRectifyAsCloudCheckBox->setChecked(false);
206  orthoRectifyAsCloudCheckBox->setEnabled(false);
207  }
208 }
209 
211  cameraCountLabel->setText(QString::number(count));
212  imagesGroupBox->setEnabled(count != 0);
213 }
214 
215 void BundlerImportDlg::setVer(unsigned majorVer, unsigned minorVer) {
216  versionLabel->setText(QString("v%1.%2").arg(majorVer).arg(minorVer));
217 }
218 
220  imageListFilePathLineEdit->setText(filename);
221 }
222 
224  return imageListFilePathLineEdit->text();
225 }
226 
228  altKeypointsFilePathLineEdit->setText(filename);
229 }
230 
232  return altKeypointsFilePathLineEdit->text();
233 }
234 
236  QString imageListFilename = QFileDialog::getOpenFileName(
237  this, "Open image list file", imageListFilePathLineEdit->text(),
238  "Image list (*.txt)");
239 
240  if (!imageListFilename.isEmpty())
241  imageListFilePathLineEdit->setText(imageListFilename);
242 }
243 
245  QString altKeypointsFilename = QFileDialog::getOpenFileName(
246  this, "Open alternative keypoints file",
247  altKeypointsFilePathLineEdit->text(), "Cloud/mesh (*.*)");
248 
249  if (!altKeypointsFilename.isEmpty())
250  altKeypointsFilePathLineEdit->setText(altKeypointsFilename);
251 }
252 
254  return imageScaleDoubleSpinBox->value();
255 }
256 
258  return dtmVerticesSpinBox->value();
259 }
260 
262  if (xVertAxisRadioButton->isChecked()) {
263  // rotation around Y
264  mat.toZero();
265  mat.data()[2] = -1.0f;
266  mat.data()[5] = 1.0f;
267  mat.data()[8] = 1.0f;
268  mat.data()[15] = 1.0f;
269  return true;
270  } else if (yVertAxisRadioButton->isChecked()) {
271  // rotation around X
272  mat.toZero();
273  mat.data()[0] = 1.0f;
274  mat.data()[6] = -1.0f;
275  mat.data()[9] = -1.0f;
276  mat.data()[15] = 1.0f;
277  return true;
278  } else if (customVertAxisRadioButton->isChecked()) {
279  bool success = false;
280  mat = ccGLMatrix::FromString(applyTransfoMatrixTextEdit->toPlainText(),
281  success);
282  return success;
283  }
284 
285  return false;
286 }
std::string filename
int count
bool importImages() const
Returns whether images should be imported.
bool orthoRectifyImagesAsImages() const
Returns whether images should be ortho-rectified as images.
bool getOptionalTransfoMatrix(ccGLMatrix &mat)
Returns the optional transformation matrix (if defined)
bool importKeypoints() const
Returns whether keypoints should be imported.
unsigned getDTMVerticesCount() const
Returns desired number of vertices for DTM.
bool keepImagesInMemory() const
Returns images should be kept in memory or not.
QString getAltKeypointsFilename() const
Gets alternative keypoints filename (full path)
void setImageListFilename(const QString &filename)
Sets default image list filename (full path)
bool orthoRectifyImagesAsClouds() const
Returns whether images should be ortho-rectified as clouds.
void setVer(unsigned majorVer, unsigned minorVer)
Sets file version on initialization.
OrthoRectMethod getOrthorectificationMethod() const
Returns the ortho-rectification method (for images)
bool useAlternativeKeypoints() const
Returns whether alternative keypoints should be used.
virtual ~BundlerImportDlg()
Destructor.
void setCamerasCount(unsigned count)
Sets cameras count on initialization.
double getScaleFactor() const
Returns scale factor.
bool undistortImages() const
Returns whether images should be undistorted.
bool generateColoredDTM() const
Returns whether colored pseudo-DTM should be generated.
void setAltKeypointsFilename(const QString &filename)
Sets default alternative keypoints filename (full path)
void setKeypointsCount(unsigned count)
Sets keypoints count on initialization.
void initFromPersistentSettings()
Inits dialog state from persistent settings.
OrthoRectMethod
Image ortho-rectification methods.
QString getImageListFilename() const
Gets image list filename (full path)
BundlerImportDlg(QWidget *parent=0)
Default constructor.
virtual void toZero()
Clears matrix.
T * data()
Returns a pointer to internal data.
static ccGLMatrixTpl< double > FromString(const QString &matText, bool &success)
Converts a 'text' matrix to a ccGLMatrix.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19