ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
LASOpenDlg.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 "LASOpenDlg.h"
9 
10 // Qt
11 #include <QFileDialog>
12 #include <QFileInfo>
13 #include <QMessageBox>
14 
15 // System
16 #include <assert.h>
17 #include <string.h>
18 
19 LASOpenDlg::LASOpenDlg(QWidget* parent)
20  : QDialog(parent), Ui::OpenLASFileDialog(), m_autoSkip(false) {
21  setupUi(this);
22 
23  clearEVLRs();
24 
25  connect(applyAllButton, &QAbstractButton::clicked, this,
27  connect(browseToolButton, &QAbstractButton::clicked, this,
29  connect(tileGroupBox, &QGroupBox::toggled, applyAllButton,
30  &QWidget::setDisabled);
31 
32  // can't use the 'Apply all' button if tiling mode is enabled
33  applyAllButton->setEnabled(!tileGroupBox->isChecked());
34 
35  if (tileGroupBox->isChecked()) {
36  tabWidget->setCurrentIndex(2);
37  }
38 }
39 
41 
43  m_autoSkip = true;
44  accept();
45 }
46 
48  QString outputPath = QFileDialog::getExistingDirectory(
49  this, "Output path", outputPathLineEdit->text());
50  if (outputPath.isEmpty()) {
51  // cancelled
52  return;
53  }
54 
55  outputPathLineEdit->setText(outputPath);
56 }
57 
58 bool FieldIsPresent(const std::vector<std::string>& dimensions,
59  LAS_FIELDS field) {
60  for (const std::string& dimension : dimensions) {
61  if (QString(dimension.c_str()).toUpper() ==
62  QString(LAS_FIELD_NAMES[field]).toUpper())
63  return true;
64  }
65 
66  return false;
67 }
68 
69 void LASOpenDlg::setDimensions(const std::vector<std::string>& dimensions) {
70  redCheckBox->setEnabled(FieldIsPresent(dimensions, LAS_RED));
71  greenCheckBox->setEnabled(FieldIsPresent(dimensions, LAS_GREEN));
72  blueCheckBox->setEnabled(FieldIsPresent(dimensions, LAS_BLUE));
73  intensityCheckBox->setEnabled(FieldIsPresent(dimensions, LAS_INTENSITY));
74 
75  bool hasClassif = FieldIsPresent(dimensions, LAS_CLASSIFICATION);
76  classifCheckBox->setEnabled(hasClassif);
77  decomposeClassifGroupBox->setEnabled(hasClassif);
78 
79  timeCheckBox->setEnabled(FieldIsPresent(dimensions, LAS_TIME));
80 
81  returnNumberCheckBox->setEnabled(
82  FieldIsPresent(dimensions, LAS_RETURN_NUMBER));
83  numberOfReturnsCheckBox->setEnabled(
85  scanDirFlagCheckBox->setEnabled(
86  FieldIsPresent(dimensions, LAS_SCAN_DIRECTION));
87  edgeOfFlightCheckBox->setEnabled(
89  scanAngleRankCheckBox->setEnabled(
90  FieldIsPresent(dimensions, LAS_SCAN_ANGLE_RANK));
91  userDataCheckBox->setEnabled(FieldIsPresent(dimensions, LAS_USER_DATA));
92  pointSourceIDCheckBox->setEnabled(
93  FieldIsPresent(dimensions, LAS_POINT_SOURCE_ID));
94 
95  // classifValueCheckBox;
96  // classifSyntheticCheckBox;
97  // classifKeypointCheckBox;
98  // classifWithheldCheckBox;
99 }
100 
101 bool LASOpenDlg::doLoad(LAS_FIELDS field) const {
102  switch (field) {
103  case LAS_X:
104  case LAS_Y:
105  case LAS_Z:
106  return true;
107  case LAS_INTENSITY:
108  return intensityCheckBox->isEnabled() &&
109  intensityCheckBox->isChecked();
110  case LAS_RETURN_NUMBER:
111  return returnNumberCheckBox->isEnabled() &&
112  returnNumberCheckBox->isChecked();
114  return numberOfReturnsCheckBox->isEnabled() &&
115  numberOfReturnsCheckBox->isChecked();
116  case LAS_SCAN_DIRECTION:
117  return scanDirFlagCheckBox->isEnabled() &&
118  scanDirFlagCheckBox->isChecked();
120  return edgeOfFlightCheckBox->isEnabled() &&
121  edgeOfFlightCheckBox->isChecked();
122  case LAS_CLASSIFICATION:
123  return classifCheckBox->isEnabled() &&
124  classifCheckBox->isChecked() &&
125  !decomposeClassifGroupBox->isChecked();
126  case LAS_SCAN_ANGLE_RANK:
127  return scanAngleRankCheckBox->isEnabled() &&
128  scanAngleRankCheckBox->isChecked();
129  case LAS_USER_DATA:
130  return userDataCheckBox->isEnabled() &&
131  userDataCheckBox->isChecked();
132  case LAS_POINT_SOURCE_ID:
133  return pointSourceIDCheckBox->isEnabled() &&
134  pointSourceIDCheckBox->isChecked();
135  case LAS_RED:
136  return redCheckBox->isEnabled() && redCheckBox->isChecked();
137  case LAS_GREEN:
138  return greenCheckBox->isEnabled() && greenCheckBox->isChecked();
139  case LAS_BLUE:
140  return blueCheckBox->isEnabled() && blueCheckBox->isChecked();
141  case LAS_TIME:
142  return timeCheckBox->isEnabled() && timeCheckBox->isChecked();
143  case LAS_EXTRA:
144  return extraFieldGroupBox->isEnabled() &&
145  extraFieldGroupBox->isChecked();
146  case LAS_CLASSIF_VALUE:
147  return classifCheckBox->isEnabled() &&
148  classifCheckBox->isChecked() &&
149  decomposeClassifGroupBox->isChecked() &&
150  classifValueCheckBox->isChecked();
152  return classifCheckBox->isEnabled() &&
153  classifCheckBox->isChecked() &&
154  decomposeClassifGroupBox->isChecked() &&
155  classifSyntheticCheckBox->isChecked();
157  return classifCheckBox->isEnabled() &&
158  classifCheckBox->isChecked() &&
159  decomposeClassifGroupBox->isChecked() &&
160  classifKeypointCheckBox->isChecked();
162  return classifCheckBox->isEnabled() &&
163  classifCheckBox->isChecked() &&
164  decomposeClassifGroupBox->isChecked() &&
165  classifWithheldCheckBox->isChecked();
166  case LAS_CLASSIF_OVERLAP:
167  return classifCheckBox->isEnabled() &&
168  classifCheckBox->isChecked() &&
169  decomposeClassifGroupBox->isChecked() &&
170  classifOverlapCheckBox->isChecked();
171  case LAS_INVALID:
172  default:
173  assert(false);
174  return false;
175  }
176 
177  return false;
178 }
179 
181  evlrListWidget->clear();
182  extraFieldGroupBox->setEnabled(false);
183  extraFieldGroupBox->setChecked(false);
184 }
185 
187  unsigned pointCount,
188  const CCVector3d& bbMin,
189  const CCVector3d& bbMax) {
190  // default output path (for tiling)
191  outputPathLineEdit->setText(QFileInfo(filename).absolutePath());
192 
193  // number of points
194  pointCountLineEdit->setText(
195  QLocale().toString(static_cast<uint>(pointCount)));
196 
197  // bounding-box
198  bbTextEdit->setText(QString("X = [%1 ; %2]\nY = [%3 ; %4]\nZ = [%5 ; %6]")
199  .arg(bbMin.x, 0, 'f')
200  .arg(bbMax.x, 0, 'f')
201  .arg(bbMin.y, 0, 'f')
202  .arg(bbMax.y, 0, 'f')
203  .arg(bbMin.z, 0, 'f')
204  .arg(bbMax.z, 0, 'f'));
205 }
206 
207 void LASOpenDlg::addEVLR(QString description) {
208  QListWidgetItem* item = new QListWidgetItem(description);
209  evlrListWidget->addItem(item);
210  // auto select the entry
211  item->setSelected(true);
212  // auto enable the extraFieldGroupBox
213  extraFieldGroupBox->setEnabled(true);
214  extraFieldGroupBox->setChecked(true);
215 }
216 
217 bool LASOpenDlg::doLoadEVLR(size_t index) const {
218  if (!extraFieldGroupBox->isChecked()) return false;
219 
220  QListWidgetItem* item = evlrListWidget->item(static_cast<int>(index));
221  return item && item->isSelected();
222 }
223 
225  return force8bitRgbCheckBox->isChecked();
226 }
227 
228 bool LASOpenDlg::getTimeShift(double& timeShift) const {
229  if (!timeShiftDoubleSpinBox->isEnabled()) {
230  return false;
231  }
232 
233  timeShift = timeShiftDoubleSpinBox->value();
234  return true;
235 }
std::string filename
const char LAS_FIELD_NAMES[][28]
Definition: LASFields.h:63
LAS_FIELDS
Definition: LASFields.h:35
@ LAS_INVALID
Definition: LASFields.h:60
@ LAS_CLASSIF_KEYPOINT
Definition: LASFields.h:56
@ LAS_Z
Definition: LASFields.h:38
@ LAS_SCAN_DIRECTION
Definition: LASFields.h:42
@ LAS_POINT_SOURCE_ID
Definition: LASFields.h:47
@ LAS_CLASSIF_OVERLAP
Definition: LASFields.h:58
@ LAS_RETURN_NUMBER
Definition: LASFields.h:40
@ LAS_Y
Definition: LASFields.h:37
@ LAS_CLASSIF_VALUE
Definition: LASFields.h:54
@ LAS_FLIGHT_LINE_EDGE
Definition: LASFields.h:43
@ LAS_TIME
Definition: LASFields.h:51
@ LAS_NUMBER_OF_RETURNS
Definition: LASFields.h:41
@ LAS_SCAN_ANGLE_RANK
Definition: LASFields.h:45
@ LAS_EXTRA
Definition: LASFields.h:52
@ LAS_CLASSIF_WITHHELD
Definition: LASFields.h:57
@ LAS_BLUE
Definition: LASFields.h:50
@ LAS_X
Definition: LASFields.h:36
@ LAS_GREEN
Definition: LASFields.h:49
@ LAS_RED
Definition: LASFields.h:48
@ LAS_CLASSIF_SYNTHETIC
Definition: LASFields.h:55
@ LAS_USER_DATA
Definition: LASFields.h:46
@ LAS_CLASSIFICATION
Definition: LASFields.h:44
@ LAS_INTENSITY
Definition: LASFields.h:39
bool FieldIsPresent(const std::vector< std::string > &dimensions, LAS_FIELDS field)
Definition: LASOpenDlg.cpp:58
bool doLoad(LAS_FIELDS field) const
Whether to load a given field.
Definition: LASOpenDlg.cpp:101
void onApplyAll()
Definition: LASOpenDlg.cpp:42
void resetApplyAll()
Resets the "apply all" flag (if set)
Definition: LASOpenDlg.cpp:40
void onBrowse()
Definition: LASOpenDlg.cpp:47
void addEVLR(QString description)
Adds an 'extra bytes' record entry.
Definition: LASOpenDlg.cpp:207
bool m_autoSkip
Definition: LASOpenDlg.h:70
bool doLoadEVLR(size_t index) const
Returns whether an EVLR is selected for laoding or not.
Definition: LASOpenDlg.cpp:217
bool getTimeShift(double &timeShift) const
Returns the timeshift (if any)
Definition: LASOpenDlg.cpp:228
LASOpenDlg(QWidget *parent=nullptr)
Default constructor.
Definition: LASOpenDlg.cpp:19
void setInfos(QString filename, unsigned pointCount, const CCVector3d &bbMin, const CCVector3d &bbMax)
Sets the information about the file.
Definition: LASOpenDlg.cpp:186
void setDimensions(const std::vector< std::string > &dimensions)
Sets available dimensions.
Definition: LASOpenDlg.cpp:69
bool forced8bitRgbMode() const
Whether 8-bit RGB mode is forced or not.
Definition: LASOpenDlg.cpp:224
void clearEVLRs()
Clears the 'extra bytes' record.
Definition: LASOpenDlg.cpp:180
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
unsigned int uint
Definition: cutil_math.h:28
std::string toString(T x)
Definition: Common.h:80