ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
LasExtraScalarField.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 <cstdint>
28 #include <string>
29 #include <vector>
30 
31 class QDataStream;
32 
33 class ccPointCloud;
34 class ccScalarField;
35 
36 struct laszip_header;
37 struct laszip_vlr;
38 typedef laszip_vlr laszip_vlr_struct;
39 
42 {
43  public:
50  static constexpr unsigned MAX_DIM_SIZE = 3;
51  static constexpr unsigned MAX_NAME_SIZE = 32;
52  static constexpr unsigned MAX_DESCRIPTION_SIZE = 32;
53 
54  enum class DimensionSize
55  {
56  One = 1,
57  Two = 2,
58  Three = 3,
59  };
60 
62  enum DataType
63  {
65  u8 = 1,
66  i8,
67  u16,
68  i16,
69  u32,
70  i32,
71  u64,
72  i64,
73  f32,
74  f64,
75  Invalid
76  };
77 
78  enum Kind
79  {
82  Floating
83  };
84 
85  public:
86  LasExtraScalarField() = default;
87 
88  friend QDataStream& operator>>(QDataStream& dataStream, LasExtraScalarField& extraScalarField);
89  friend QDataStream& operator<<(QDataStream& dataStream, const LasExtraScalarField& extraScalarField);
90 
91  public: // Static Helper functions that works on collection of LasExtraScalarFields
92  static std::vector<LasExtraScalarField> ParseExtraScalarFields(const laszip_header& laszipHeader);
93  static std::vector<LasExtraScalarField> ParseExtraScalarFields(const laszip_vlr_struct& extraBytesVlr);
94  static void InitExtraBytesVlr(laszip_vlr_struct& vlr,
95  const std::vector<LasExtraScalarField>& extraFields);
96  static void UpdateByteOffsets(std::vector<LasExtraScalarField>& extraFields);
97  static unsigned TotalExtraBytesSize(const std::vector<LasExtraScalarField>& extraScalarFields);
98  static void MatchExtraBytesToScalarFields(std::vector<LasExtraScalarField>& extraScalarFields,
99  const ccPointCloud& pointCloud);
100 
101  public: // methods
102  // LAS Spec integer value for the type
103  uint8_t typeCode() const;
104 
105  // Properties we can derive from the type attribute
106  unsigned elementSize() const;
107  unsigned numElements() const;
108  unsigned byteSize() const;
109  Kind kind() const;
110  const char* typeName() const;
111 
112  // Properties we can derive from the type options attribute
113  bool noDataIsRelevant() const;
114  bool minIsRelevant() const;
115  bool maxIsRelevant() const;
116  bool scaleIsRelevant() const;
117  bool offsetIsRelevant() const;
118 
119  void setOffsetIsRelevant(bool isRelevant);
120  void setScaleIsRelevant(bool isRelevant);
121 
123 
124  static std::tuple<DataType, DimensionSize> DataTypeFromValue(uint8_t value);
125 
126  public: // Data members
129  // These fields are from the vlr itself
130  uint8_t options{0};
131  char name[MAX_NAME_SIZE] = "";
133  uint8_t noData[MAX_DIM_SIZE][8] = {0};
134  uint8_t mins[MAX_DIM_SIZE][8] = {0};
135  uint8_t maxs[MAX_DIM_SIZE][8] = {0};
136  double scales[MAX_DIM_SIZE] = {0.0};
137  double offsets[MAX_DIM_SIZE] = {0.0};
138 
139  // These are added by us
140  unsigned byteOffset{0};
142  // TODO explain better
143  // This strings store the name of the field in CC,
144  // Extra fields name may clash with existing scalar fields name
145  // (eg: the user calls one of his extra field "Intensity")
146  // we have to alter the real name
147  char ccName[MAX_NAME_SIZE + 8] = {0};
148 };
laszip_vlr laszip_vlr_struct
Definition: LasDetails.h:46
laszip_vlr laszip_vlr_struct
This serves the same purpose as LasScalarField but for extra bytes.
static constexpr unsigned MAX_NAME_SIZE
char name[MAX_NAME_SIZE]
char ccName[MAX_NAME_SIZE+8]
static constexpr unsigned MAX_DIM_SIZE
static void UpdateByteOffsets(std::vector< LasExtraScalarField > &extraFields)
friend QDataStream & operator>>(QDataStream &dataStream, LasExtraScalarField &extraScalarField)
static constexpr unsigned MAX_DESCRIPTION_SIZE
unsigned elementSize() const
char description[MAX_DESCRIPTION_SIZE]
double scales[MAX_DIM_SIZE]
uint8_t noData[MAX_DIM_SIZE][8]
uint8_t mins[MAX_DIM_SIZE][8]
DataType
Data types available LAS Extra Field.
const char * typeName() const
unsigned numElements() const
LasExtraScalarField()=default
friend QDataStream & operator<<(QDataStream &dataStream, const LasExtraScalarField &extraScalarField)
void setScaleIsRelevant(bool isRelevant)
uint8_t maxs[MAX_DIM_SIZE][8]
static void InitExtraBytesVlr(laszip_vlr_struct &vlr, const std::vector< LasExtraScalarField > &extraFields)
static void MatchExtraBytesToScalarFields(std::vector< LasExtraScalarField > &extraScalarFields, const ccPointCloud &pointCloud)
void setOffsetIsRelevant(bool isRelevant)
static unsigned TotalExtraBytesSize(const std::vector< LasExtraScalarField > &extraScalarFields)
double offsets[MAX_DIM_SIZE]
static std::tuple< DataType, DimensionSize > DataTypeFromValue(uint8_t value)
ccScalarField * scalarFields[MAX_DIM_SIZE]
static std::vector< LasExtraScalarField > ParseExtraScalarFields(const laszip_header &laszipHeader)
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
A scalar field associated to display-related parameters.
unsigned char u8
Definition: shell.c:92