-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLasLoader.h
150 lines (134 loc) · 3.93 KB
/
LasLoader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#pragma once
#include <string>
#include <vector>
#include <cassert>
#include <iostream>
#include "glm/glm.hpp"
namespace LAS {
#define LOG(msg) std::cout << msg
#ifndef NDEBUG
#define ASSERT(expr) assert(expr)
#else
#define ASSERT(expr)
#endif // !NDEBUG
struct MeshVertex {
glm::vec3 Pos{};
glm::vec3 Normal{};
glm::vec2 UV{};
};
struct ColorVertex {
glm::vec3 Pos{};
glm::vec3 Color{};
};
struct ColorNormalVertex {
glm::vec3 Pos{};
glm::vec3 Color{};
glm::vec3 Normal{};
};
struct Triangle {
glm::vec3 A;
glm::vec3 B;
glm::vec3 C;
glm::vec3 N;
};
class LasLoader {
public:
LasLoader(const std::string& path);
std::vector<ColorVertex> GetPointData();
std::pair<std::vector<MeshVertex>, std::vector<uint32_t>> GetIndexedData();
std::vector<MeshVertex> GetVertexData();
std::pair<std::vector<ColorNormalVertex>, std::vector<uint32_t>> GetIndexedColorNormalVertexData();
std::vector<std::vector<std::pair<Triangle, Triangle>>> GetTerrainData();
float GetMinY() { return -max.y; }
private:
std::vector<ColorVertex> PointData;
std::vector<MeshVertex> VertexData;
std::vector<ColorNormalVertex> ColorNormalVertexData;
std::vector<uint32_t> IndexData;
std::vector<MeshVertex> TriangulatedVertexData;
std::vector<Triangle> triangles;
void ReadTxt(const std::string& path);
void ReadBin(const std::string& path);
void ReadLas(const std::string& path);
void CalcCenter();
void FindMinMax();
void UpdatePoints();
void Triangulate();
glm::vec3 min{ 0.f };
glm::vec3 max{ 0.f };
glm::vec3 middle{ 0.f };
glm::vec3 offset{ 0.f };
int xSquares{ 0 };
int zSquares{ 0 };
};
struct HeightAndColor {
int count{ 0 };
float sum{ 0.f };
glm::vec3 color{ 0.f };
};
// Can't use struct directly because of padding of the size of the struct
struct lasHeader {
char fileSignature[4];
uint16_t sourceID;
uint16_t globalEncoding;
uint32_t GUID1;
uint16_t GUID2;
uint16_t GUID3;
uint8_t GUID4[8];
uint8_t versionMajor;
uint8_t versionMinor;
char systemIdentifier[32];
char generatingSoftware[32];
uint16_t creationDay;
uint16_t creationYear;
uint16_t headerSize;
uint32_t offsetToPointData;
uint32_t numberVariableLengthRecords;
uint8_t pointDataRecordFormat;
uint16_t pointDataRecordLength;
int32_t legacyNumberPointsRecords;
int32_t legacyNumberPointReturn[5];
double xScaleFactor, yScaleFactor, zScaleFactor;
double xOffset, yOffset, zOffset;
double maxX, minX;
double maxY, minY;
double maxZ, minZ;
};
// Not needed
struct lasVariableLengthRecords {
// Variable Length Records
uint16_t lasReserved;
char UserID[16];
uint16_t recordID;
uint16_t recordLengthAfterHeader;
char lasDescription[32];
};
// Can't use struct directly because of padding of the size of the struct
struct lasPointData1 {
int32_t xPos;
int32_t yPos;
int32_t zPos;
uint16_t intensity;
int8_t flags;
uint8_t classificaton;
int8_t scanAngle;
uint8_t userData;
uint16_t pointSourceID;
double GPSTime;
};
// Can't use struct directly because of padding of the size of the struct
struct lasPointData2 {
int32_t xPos;
int32_t yPos;
int32_t zPos;
uint16_t intensity;
int8_t flags;
uint8_t classificaton;
int8_t scanAngle;
uint8_t userData;
uint16_t pointSourceID;
uint16_t red;
uint16_t green;
uint16_t blue;
};
}