ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
LasVlr.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 // ##########################################################################
11 // # #
12 // # CloudViewer PLUGIN: LAS-IO Plugin #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Thomas Montaigu #
24 // # #
25 // ##########################################################################
26 
27 #include "LasDetails.h"
28 #include "LasExtraScalarField.h"
29 
30 // LASzip
31 #include <laszip/laszip_api.h>
32 // Qt
33 #include <QDataStream>
34 #include <QMetaType>
35 #include <QString>
36 
37 struct LasVlr
38 {
39  LasVlr() = default;
40  explicit LasVlr(const laszip_header& header);
41  LasVlr(const LasVlr& rhs);
42 
43  LasVlr& operator=(LasVlr rhs);
44 
45  static void Swap(LasVlr& lhs, LasVlr& rhs) noexcept;
46 
47  inline QString toString() const
48  {
49  return QString("VLRs: %1").arg(vlrs.size());
50  }
51 
52  inline laszip_U32 numVlrs() const
53  {
54  return static_cast<laszip_U32>(vlrs.size());
55  }
56 
57  friend QDataStream& operator<<(QDataStream& arch, const LasVlr& object)
58  {
59  arch << static_cast<quint64>(object.vlrs.size());
60  for (const laszip_vlr_struct& v : object.vlrs)
61  {
62  // arch << v;
63  arch << v.reserved;
64  arch.writeRawData(v.user_id, 16 * sizeof(laszip_CHAR));
65  arch << v.record_id;
66  arch << v.record_length_after_header;
67  arch.writeRawData(v.description, 32 * sizeof(laszip_CHAR));
68  arch.writeRawData((const char*)v.data, v.record_length_after_header);
69  }
70 
71  arch << static_cast<quint64>(object.extraScalarFields.size());
72  for (const LasExtraScalarField& e : object.extraScalarFields)
73  {
74  // arch << e;
75  arch.writeRawData((const char*)&e, sizeof(LasExtraScalarField));
76  }
77  return arch;
78  }
79 
80  friend QDataStream& operator>>(QDataStream& arch, LasVlr& object)
81  {
82  quint64 vlrSize = 0;
83  arch >> vlrSize;
84  object.vlrs.reserve(vlrSize);
85  for (quint64 i = 0; i < vlrSize; ++i)
86  {
88  // arch >> v;
89  arch >> v.reserved;
90  arch.readRawData((char*)v.user_id, 16 * sizeof(laszip_CHAR));
91  arch >> v.record_id;
92  arch >> v.record_length_after_header;
93  arch.readRawData((char*)v.description, 32 * sizeof(laszip_CHAR));
94  {
95  v.data = new laszip_U8[v.record_length_after_header]; // TODO: potential memory leak
96  arch.readRawData((char*)v.data, v.record_length_after_header);
97  }
98  // arch >> QByteArray((const char*)v.data, v.record_length_after_header);
99  object.vlrs.push_back(v);
100  }
101 
102  quint64 extraScalarFieldCount = 0;
103  arch >> extraScalarFieldCount;
104  object.extraScalarFields.reserve(extraScalarFieldCount);
105  for (quint64 i = 0; i < extraScalarFieldCount; ++i)
106  {
108  // arch >> e;
109  {
110  char* data = (char*)&e;
111  uint len = sizeof(LasExtraScalarField);
112  arch.readRawData(data, len);
113  }
114  object.extraScalarFields.push_back(e);
115  }
116 
117  return arch;
118  }
119 
120  std::vector<laszip_vlr_struct> vlrs;
121  std::vector<LasExtraScalarField> extraScalarFields;
122 };
123 
laszip_vlr laszip_vlr_struct
Definition: LasDetails.h:46
Q_DECLARE_METATYPE(LasVlr)
This serves the same purpose as LasScalarField but for extra bytes.
unsigned int uint
Definition: cutil_math.h:28
Definition: LasVlr.h:38
QString toString() const
Definition: LasVlr.h:47
LasVlr()=default
friend QDataStream & operator<<(QDataStream &arch, const LasVlr &object)
Definition: LasVlr.h:57
std::vector< laszip_vlr_struct > vlrs
Definition: LasVlr.h:120
std::vector< LasExtraScalarField > extraScalarFields
Definition: LasVlr.h:121
static void Swap(LasVlr &lhs, LasVlr &rhs) noexcept
Definition: LasVlr.cpp:62
laszip_U32 numVlrs() const
Definition: LasVlr.h:52
LasVlr & operator=(LasVlr rhs)
Definition: LasVlr.cpp:43
friend QDataStream & operator>>(QDataStream &arch, LasVlr &object)
Definition: LasVlr.h:80