ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
AsciiOpenDlg.h
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 #pragma once
9 
10 // local
11 #include "CV_io.h"
12 
13 // Qt
14 #include <QDialog>
15 #include <QString>
16 
17 // system
18 #include <vector>
19 
20 const unsigned ASCII_OPEN_DLG_TYPES_COUNT = 20;
21 
39  ASCII_OPEN_DLG_RGB32i = 16, // RGBA as a single 32 bits integer (PCL style)
40  ASCII_OPEN_DLG_RGB32f = 17, // RGBA as a single 32 bits float (PCL style)
43  1, // should always be the last one! (see
44  // AsciiOpenDlg::CheckOpenSequence)
45 };
46 
49 public:
50  static QString X() { return "X"; }
51  static QString Y() { return "Y"; }
52  static QString Z() { return "Z"; }
53  static QString Nx() { return "Nx"; }
54  static QString Ny() { return "Ny"; }
55  static QString Nz() { return "Nz"; }
56  static QString R() { return "R"; }
57  static QString G() { return "G"; }
58  static QString B() { return "B"; }
59  static QString A() { return "A"; }
60  static QString Rf() { return "Rf"; }
61  static QString Gf() { return "Gf"; }
62  static QString Bf() { return "Bf"; }
63  static QString Af() { return "Af"; }
64 
65  static QString Grey() { return "Intensity"; }
66  static QString Scalar() { return "SF"; }
67  static QString RGB32i() { return "RGB32i"; }
68  static QString RGB32f() { return "RGB32f"; }
69  static QString Label() { return "Label"; }
70 };
71 
73  "Ignore",
74  "coord. X",
75  "coord. Y",
76  "coord. Z",
77  "Nx",
78  "Ny",
79  "Nz",
80  "Red (0-255)",
81  "Green (0-255)",
82  "Blue (0-255)",
83  "Alpha (0-255)",
84  "Red.float (0-1)",
85  "Green.float (0-1)",
86  "Blue.float (0-1)",
87  "Alpha.float (0-1)",
88  "Grey",
89  "RGBAi",
90  "RGBAf",
91  "Label",
92  "Scalar"};
93 
94 class QComboBox;
95 class QPushButton;
96 class QTextStream;
97 class Ui_AsciiOpenDialog;
98 
100 class CV_IO_LIB_API AsciiOpenDlg : public QDialog {
101  Q_OBJECT
102 
103 public:
105 
107  explicit AsciiOpenDlg(QWidget* parent = nullptr);
108 
110  ~AsciiOpenDlg() override;
111 
113 
116  void setInput(const QString& filename, QTextStream* stream = nullptr);
117 
119 
122 
124  struct SequenceItem {
126  QString header;
127 
130 
132  SequenceItem(CC_ASCII_OPEN_DLG_TYPES _type, const QString& _header)
133  : type(_type), header(_header) {}
134  };
135 
137  using Sequence = std::vector<SequenceItem>;
138 
141 
143  unsigned getSkippedLinesCount() const { return m_skippedLines; }
144 
146  unsigned char getSeparator() const { return m_separator.cell(); }
147 
149  bool useCommaAsDecimal() const;
150 
152  double getAverageLineSize() const { return m_averageLineSize; }
153 
155  unsigned getColumnsCount() const { return m_columnsCount; }
156 
158  unsigned getMaxCloudSize() const;
159 
161  bool showLabelsIn2D() const;
162 
164 
167  bool safeSequence() const;
168 
170 
172  static bool CheckOpenSequence(const Sequence& sequence,
173  QString& errorMessage);
174 
176  static void ResetApplyAll();
177 
178 public:
180  void onSeparatorChange(const QString& separator);
182  void updateTable();
184  void setSkippedLines(int linesCount);
187 
188 protected:
189  bool apply();
190  void applyAll();
191  void columnsTypeHasChanged(int index);
194 
195 protected:
198 
200  void setSeparator(QChar);
201 
202  // associated UI
203  Ui_AsciiOpenDialog* m_ui;
204 
205  unsigned m_skippedLines;
206  QChar m_separator;
208  QString m_filename;
209  QTextStream* m_stream;
210  QString m_headerLine;
211 
212  enum ColumnType { TEXT = 0, UNKNOWN = 1, IGNORED = 2, VALID = 3 };
213 
215  std::vector<ColumnType> m_columnType;
216 
217  unsigned m_columnsCount;
218 };
const unsigned ASCII_OPEN_DLG_TYPES_COUNT
Definition: AsciiOpenDlg.h:20
const char ASCII_OPEN_DLG_TYPES_NAMES[ASCII_OPEN_DLG_TYPES_COUNT][20]
Definition: AsciiOpenDlg.h:72
CC_ASCII_OPEN_DLG_TYPES
Definition: AsciiOpenDlg.h:22
@ ASCII_OPEN_DLG_Label
Definition: AsciiOpenDlg.h:41
@ ASCII_OPEN_DLG_Grey
Definition: AsciiOpenDlg.h:38
@ ASCII_OPEN_DLG_NX
Definition: AsciiOpenDlg.h:27
@ ASCII_OPEN_DLG_RGB32i
Definition: AsciiOpenDlg.h:39
@ ASCII_OPEN_DLG_Rf
Definition: AsciiOpenDlg.h:34
@ ASCII_OPEN_DLG_A
Definition: AsciiOpenDlg.h:33
@ ASCII_OPEN_DLG_Y
Definition: AsciiOpenDlg.h:25
@ ASCII_OPEN_DLG_RGB32f
Definition: AsciiOpenDlg.h:40
@ ASCII_OPEN_DLG_R
Definition: AsciiOpenDlg.h:30
@ ASCII_OPEN_DLG_NY
Definition: AsciiOpenDlg.h:28
@ ASCII_OPEN_DLG_Gf
Definition: AsciiOpenDlg.h:35
@ ASCII_OPEN_DLG_NZ
Definition: AsciiOpenDlg.h:29
@ ASCII_OPEN_DLG_B
Definition: AsciiOpenDlg.h:32
@ ASCII_OPEN_DLG_Af
Definition: AsciiOpenDlg.h:37
@ ASCII_OPEN_DLG_X
Definition: AsciiOpenDlg.h:24
@ ASCII_OPEN_DLG_Scalar
Definition: AsciiOpenDlg.h:42
@ ASCII_OPEN_DLG_G
Definition: AsciiOpenDlg.h:31
@ ASCII_OPEN_DLG_Bf
Definition: AsciiOpenDlg.h:36
@ ASCII_OPEN_DLG_Z
Definition: AsciiOpenDlg.h:26
@ ASCII_OPEN_DLG_None
Definition: AsciiOpenDlg.h:23
std::string filename
#define CV_IO_LIB_API
Definition: CV_io.h:15
char type
Default ASCII header columns.
Definition: AsciiOpenDlg.h:48
static QString A()
Definition: AsciiOpenDlg.h:59
static QString G()
Definition: AsciiOpenDlg.h:57
static QString Nz()
Definition: AsciiOpenDlg.h:55
static QString RGB32i()
Definition: AsciiOpenDlg.h:67
static QString Label()
Definition: AsciiOpenDlg.h:69
static QString RGB32f()
Definition: AsciiOpenDlg.h:68
static QString Bf()
Definition: AsciiOpenDlg.h:62
static QString Ny()
Definition: AsciiOpenDlg.h:54
static QString Z()
Definition: AsciiOpenDlg.h:52
static QString Nx()
Definition: AsciiOpenDlg.h:53
static QString Y()
Definition: AsciiOpenDlg.h:51
static QString Gf()
Definition: AsciiOpenDlg.h:61
static QString B()
Definition: AsciiOpenDlg.h:58
static QString X()
Definition: AsciiOpenDlg.h:50
static QString Af()
Definition: AsciiOpenDlg.h:63
static QString Grey()
Definition: AsciiOpenDlg.h:65
static QString Rf()
Definition: AsciiOpenDlg.h:60
static QString R()
Definition: AsciiOpenDlg.h:56
static QString Scalar()
Definition: AsciiOpenDlg.h:66
Dialog for configuration of ASCII files opening sequence.
Definition: AsciiOpenDlg.h:100
double m_averageLineSize
Definition: AsciiOpenDlg.h:207
Ui_AsciiOpenDialog * m_ui
Definition: AsciiOpenDlg.h:203
bool useCommaAsDecimal() const
Returns whether comma should be used as decimal point.
void checkSelectedColumnsValidity()
void setSkippedLines(int linesCount)
Sets the number of lines to skip.
unsigned char getSeparator() const
Returns user selected separator.
Definition: AsciiOpenDlg.h:146
void columnsTypeHasChanged(int index)
static bool CheckOpenSequence(const Sequence &sequence, QString &errorMessage)
Checks the "opening" sequence as set by the user.
void commaDecimalCheckBoxToggled(bool)
Slot called when the 'comma as decimal' checkbox is toggled.
unsigned m_skippedLines
Definition: AsciiOpenDlg.h:205
void setInput(const QString &filename, QTextStream *stream=nullptr)
Sets the input filename or text stream.
QChar m_separator
Definition: AsciiOpenDlg.h:206
unsigned getSkippedLinesCount() const
Returns number of lines to skip.
Definition: AsciiOpenDlg.h:143
bool showLabelsIn2D() const
Whether labels should be visible in 2D.
std::vector< ColumnType > m_columnType
Identifies columns with numbers only [mandatory].
Definition: AsciiOpenDlg.h:215
double getAverageLineSize() const
Returns roughly estimated average line size (in bytes)
Definition: AsciiOpenDlg.h:152
unsigned getColumnsCount() const
Returns columns count per line.
Definition: AsciiOpenDlg.h:155
static void ResetApplyAll()
Resets the "apply all" flag (if set)
std::vector< SequenceItem > Sequence
ASCII open sequence.
Definition: AsciiOpenDlg.h:137
bool restorePreviousContext()
Restores the previous context ('Apply all' button)
void shortcutButtonPressed()
QTextStream * m_stream
Definition: AsciiOpenDlg.h:209
bool safeSequence() const
Returns whether the current sequence is 'safe'.
AsciiOpenDlg(QWidget *parent=nullptr)
Default constructor.
void autoFindBestSeparator()
Tries to guess the best separator automagically.
QString m_headerLine
Definition: AsciiOpenDlg.h:210
unsigned m_columnsCount
Definition: AsciiOpenDlg.h:217
QString m_filename
Definition: AsciiOpenDlg.h:208
void setSeparator(QChar)
Sets the current separator.
Sequence getOpenSequence() const
Returns the whole "opening" sequence as set by the user.
~AsciiOpenDlg() override
Default destructor.
void applyAll()
void onSeparatorChange(const QString &separator)
Slot called when separator changes.
void updateTable()
Forces the table to update itself.
unsigned getMaxCloudSize() const
Returns the max number of points per cloud.
ASCII open sequence item.
Definition: AsciiOpenDlg.h:124
SequenceItem()
Default constructor.
Definition: AsciiOpenDlg.h:129
CC_ASCII_OPEN_DLG_TYPES type
Definition: AsciiOpenDlg.h:125
SequenceItem(CC_ASCII_OPEN_DLG_TYPES _type, const QString &_header)
Constructor from parameters.
Definition: AsciiOpenDlg.h:132