AsciiOpenDlg.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_ASCII_OPEN_DIALOG_HEADER
  18. #define CC_ASCII_OPEN_DIALOG_HEADER
  19. //local
  20. #include "qCC_io.h"
  21. //Qt
  22. #include <QDialog>
  23. #include <QString>
  24. //system
  25. #include <vector>
  26. enum CC_ASCII_OPEN_DLG_TYPES { ASCII_OPEN_DLG_None = 0,
  27. ASCII_OPEN_DLG_X = 1,
  28. ASCII_OPEN_DLG_Y = 2,
  29. ASCII_OPEN_DLG_Z = 3,
  30. ASCII_OPEN_DLG_NX = 4,
  31. ASCII_OPEN_DLG_NY = 5,
  32. ASCII_OPEN_DLG_NZ = 6,
  33. ASCII_OPEN_DLG_R = 7,
  34. ASCII_OPEN_DLG_G = 8,
  35. ASCII_OPEN_DLG_B = 9,
  36. ASCII_OPEN_DLG_A = 10,
  37. ASCII_OPEN_DLG_Rf = 11,
  38. ASCII_OPEN_DLG_Gf = 12,
  39. ASCII_OPEN_DLG_Bf = 13,
  40. ASCII_OPEN_DLG_Af = 14,
  41. ASCII_OPEN_DLG_Grey = 15,
  42. ASCII_OPEN_DLG_RGB32i = 16, //RGBA as a single 32 bits integer (PCL style)
  43. ASCII_OPEN_DLG_RGB32f = 17, //RGBA as a single 32 bits float (PCL style)
  44. ASCII_OPEN_DLG_Label = 18,
  45. ASCII_OPEN_DLG_QuatW = 19,
  46. ASCII_OPEN_DLG_QuatX = 20,
  47. ASCII_OPEN_DLG_QuatY = 21,
  48. ASCII_OPEN_DLG_QuatZ = 22,
  49. ASCII_OPEN_DLG_Scalar = 23, //should always be the last one! (see AsciiOpenDlg::CheckOpenSequence)
  50. };
  51. constexpr const unsigned ASCII_OPEN_DLG_TYPES_COUNT = ASCII_OPEN_DLG_Scalar + 1;
  52. //! Default ASCII header columns
  53. class AsciiHeaderColumns
  54. {
  55. public:
  56. static QString X() { return "X"; }
  57. static QString Y() { return "Y"; }
  58. static QString Z() { return "Z"; }
  59. static QString Nx() { return "Nx"; }
  60. static QString Ny() { return "Ny"; }
  61. static QString Nz() { return "Nz"; }
  62. static QString R() { return "R"; }
  63. static QString G() { return "G"; }
  64. static QString B() { return "B"; }
  65. static QString A() { return "A"; }
  66. static QString Rf() { return "Rf"; }
  67. static QString Gf() { return "Gf"; }
  68. static QString Bf() { return "Bf"; }
  69. static QString Af() { return "Af"; }
  70. static QString Grey() { return "Grey"; }
  71. static QString Scalar() { return "SF"; }
  72. static QString RGB32i() { return "RGB32i"; }
  73. static QString RGB32f() { return "RGB32f"; }
  74. static QString Label() { return "Label"; }
  75. static QString QuatW() { return "QuatW"; }
  76. static QString QuatX() { return "QuatX"; }
  77. static QString QuatY() { return "QuatY"; }
  78. static QString QuatZ() { return "QuatZ"; }
  79. };
  80. const char ASCII_OPEN_DLG_TYPES_NAMES[ASCII_OPEN_DLG_TYPES_COUNT][20] = { "Ignore",
  81. "coord. X",
  82. "coord. Y",
  83. "coord. Z",
  84. "Nx",
  85. "Ny",
  86. "Nz",
  87. "Red (0-255)",
  88. "Green (0-255)",
  89. "Blue (0-255)",
  90. "Alpha (0-255)",
  91. "Red.float (0-1)",
  92. "Green.float (0-1)",
  93. "Blue.float (0-1)",
  94. "Alpha.float (0-1)",
  95. "Grey",
  96. "RGBAi",
  97. "RGBAf",
  98. "Label",
  99. "Quaternion W",
  100. "Quaternion X",
  101. "Quaternion Y",
  102. "Quaternion Z",
  103. "Scalar"
  104. };
  105. class QComboBox;
  106. class QPushButton;
  107. class QTextStream;
  108. class Ui_AsciiOpenDialog;
  109. //! Dialog for configuration of ASCII files opening sequence
  110. class QCC_IO_LIB_API AsciiOpenDlg : public QDialog
  111. {
  112. Q_OBJECT
  113. public:
  114. //! Default constructor
  115. /** \param parent parent widget
  116. **/
  117. explicit AsciiOpenDlg(QWidget* parent = nullptr);
  118. //! Default destructor
  119. ~AsciiOpenDlg() override;
  120. //! Sets the input filename or text stream
  121. /** \param filename filename
  122. \param stream text stream
  123. \return whether a previous context was saved or not and it can be safely applied again to this file
  124. **/
  125. bool setInput(const QString &filename, QTextStream* stream = nullptr);
  126. //! ASCII open sequence item
  127. struct SequenceItem
  128. {
  129. CC_ASCII_OPEN_DLG_TYPES type;
  130. QString header;
  131. //! Default constructor
  132. SequenceItem()
  133. : type(ASCII_OPEN_DLG_None)
  134. , header()
  135. {}
  136. //! Constructor from parameters
  137. SequenceItem(CC_ASCII_OPEN_DLG_TYPES _type, const QString& _header)
  138. : type(_type)
  139. , header(_header)
  140. {}
  141. };
  142. //! ASCII open sequence
  143. using Sequence = std::vector<SequenceItem>;
  144. //! Returns the whole "opening" sequence as set by the user
  145. Sequence getOpenSequence() const;
  146. //! Returns number of lines to skip
  147. unsigned getSkippedLinesCount() const;
  148. //! Returns user selected separator
  149. unsigned char getSeparator() const { return m_separator.cell(); }
  150. //! Returns whether comma should be used as decimal point
  151. bool useCommaAsDecimal() const;
  152. //! Returns roughly estimated average line size (in bytes)
  153. double getAverageLineSize() const { return m_averageLineSize; }
  154. //! Returns columns count per line
  155. unsigned getColumnsCount() const { return m_columnsCount; }
  156. //! Returns the max number of points per cloud
  157. unsigned getMaxCloudSize() const;
  158. //! Whether labels should be visible in 2D
  159. bool showLabelsIn2D() const;
  160. //! Returns whether the current sequence is 'safe'
  161. /** A safe sequence is safe if it matches the header (if any)
  162. or if the file has less than 6 columns.
  163. **/
  164. bool safeSequence() const;
  165. //! Checks the "opening" sequence as set by the user
  166. /** \return validity (+ error message if not)
  167. **/
  168. static bool CheckOpenSequence(const Sequence& sequence, QString& errorMessage);
  169. //! Resets the "apply all" flag (if set)
  170. static void ResetApplyAll();
  171. //! Returns the quaternion scale
  172. double getQuaternionScale() const;
  173. public:
  174. //! Slot called when separator changes
  175. void onSeparatorChange(const QString& separator);
  176. //! Forces the table to update itself
  177. void updateTable();
  178. //! Slot called when the number of lines to skip is changed
  179. void onSkippedLinesChanged(int);
  180. //! Slot called when the 'comma as decimal' checkbox is toggled
  181. void commaDecimalCheckBoxToggled(bool);
  182. protected:
  183. bool apply();
  184. void applyAll();
  185. void columnsTypeHasChanged(int index);
  186. void shortcutButtonPressed();
  187. void checkSelectedColumnsValidity();
  188. protected:
  189. //! Restores the previous context ('Apply all' button)
  190. /** \return whether a previous context was saved or not and it can be safely applied again to this file
  191. **/
  192. bool restorePreviousContext();
  193. //! Tries to guess the best separator automagically
  194. void autoFindBestSeparator();
  195. //! Sets the current separator
  196. void setSeparator(QChar);
  197. //! Sets the number of lines to skip
  198. void setSkippedLines(int lineCount, bool blockSignal = true);
  199. //! Resest all column roles
  200. void resetColumnRoles();
  201. //associated UI
  202. Ui_AsciiOpenDialog* m_ui;
  203. QChar m_separator;
  204. double m_averageLineSize;
  205. QString m_filename;
  206. QTextStream* m_stream;
  207. QString m_headerLine;
  208. enum ColumnType { TEXT = 0, UNKNOWN = 1, IGNORED = 2, VALID = 3 };
  209. //! Identifies columns with numbers only [mandatory]
  210. std::vector<ColumnType> m_columnType;
  211. unsigned m_columnsCount;
  212. };
  213. #endif //CC_ASCII_OPEN_DIALOG_HEADER