Skip to content

Commit b3a82c1

Browse files
authored
Merge pull request #46 from fugro-oss/EVLROffsetBug
Fix EVLR offset bug
2 parents e48d3b4 + ee73bc0 commit b3a82c1

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LASDatasets"
22
uuid = "cc498e2a-d443-4943-8f26-2a8a0f3c7cdb"
33
authors = ["BenCurran98 <b.curran@fugro.com>"]
4-
version = "0.3.1"
4+
version = "0.3.2"
55

66
[deps]
77
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"
@@ -27,13 +27,15 @@ FileIO = "1"
2727
FixedPointNumbers = "0.8"
2828
PackedReadWrite = "0.1"
2929
Proj = "1"
30+
Random = "1.11.0"
3031
StaticArrays = "1"
3132
StructArrays = "0.6"
3233
TypedTables = "1"
3334
julia = "1.8"
3435

3536
[extras]
3637
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
38+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
3739

3840
[targets]
39-
test = ["Test"]
41+
test = ["Test", "Random"]

src/dataset.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ Get the unit factor conversion that was applied to this dataset when ingested
174174
"""
175175
get_unit_conversion(las::LASDataset) = las.unit_conversion
176176

177+
"""
178+
$(TYPEDSIGNATURES)
179+
180+
Update the offset (in Bytes) to the first EVLR in a `LASDataset` `las`
181+
"""
182+
function update_evlr_offset!(header::LasHeader)
183+
header.evlr_start = point_data_offset(header) + (number_of_points(header) * point_record_length(header))
184+
end
185+
186+
update_evlr_offset!(las::LASDataset) = update_evlr_offset!(get_header(las))
187+
177188
function Base.show(io::IO, las::LASDataset)
178189
println(io, "LAS Dataset")
179190
println(io, "\tNum Points: $(length(get_pointcloud(las)))")
@@ -239,13 +250,14 @@ function add_vlr!(las::LASDataset, vlr::LasVariableLengthRecord)
239250
push!(get_evlrs(las), vlr)
240251
if number_of_evlrs(header) == 1
241252
# if this is our first EVLR, need to set the EVLR offset to point to the correct location
242-
header.evlr_start = point_data_offset(header) + (number_of_points(header) * point_record_length(header))
253+
update_evlr_offset!(header)
243254
end
244255
else
245256
set_num_vlr!(header, number_of_vlrs(header) + 1)
246257
push!(get_vlrs(las), vlr)
247258
# make sure to increase the point offset since we're cramming another VLR before the points
248259
header.data_offset += sizeof(vlr)
260+
update_evlr_offset!(header)
249261
end
250262
end
251263

@@ -326,6 +338,8 @@ function add_column!(las::LASDataset, column::Symbol, values::AbstractVector{T})
326338
else
327339
add_extra_bytes!(las, column, T, extra_bytes_vlr)
328340
end
341+
# make sure we keep our offset to our first EVLR consistent now we've crammed more data in
342+
update_evlr_offset!(las)
329343
nothing
330344
end
331345

test/dataset.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
@test length(evlrs) == 1
150150
@test number_of_evlrs(header) == 1
151151
@test evlrs[1] == long_comment
152-
@test evlr_start(header) > 0
152+
# make sure the offset makes sense
153+
@test evlr_start(header) == point_data_offset(header) + (number_of_points(header) * point_record_length(header))
153154
# we can add a new comment on top of this one
154155
new_commment = LasVariableLengthRecord("Comment", 100, "This is a new comment", Comment(String(rand(UInt8, 2^8))), true)
155156
add_vlr!(las, new_commment)
@@ -165,6 +166,13 @@
165166
@test get_description(superseded_comment) == get_description(long_comment)
166167
@test get_data(superseded_comment) == get_data(long_comment)
167168
@test is_extended(superseded_comment) == is_extended(long_comment)
169+
# if we add a regular VLR, we should update the offset to the first EVLR correctly
170+
short_comment = LasVariableLengthRecord("Comment", 100, "This is a long comment", Comment(String(rand(UInt8, 10))))
171+
add_vlr!(las, short_comment)
172+
@test evlr_start(header) == point_data_offset(header) + (number_of_points(header) * point_record_length(header))
173+
# and similarly if we add column data it should update properly
174+
add_column!(las, :another_column, rand(UInt8, num_points))
175+
@test evlr_start(header) == point_data_offset(header) + (number_of_points(header) * point_record_length(header))
168176
# and finally we can remove it
169177
remove_vlr!(las, superseded_comment)
170178
@test number_of_evlrs(get_header(las)) == 1

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ using LASDatasets
22

33
using ColorTypes
44
using FixedPointNumbers
5+
using Random
56
using StaticArrays
67
using Test
78
using TypedTables
89

10+
# fix random seed to avoid random errors
11+
Random.seed!(0)
12+
913
include("util.jl")
1014
include("spatial_info.jl")
1115
include("vlrs.jl")

0 commit comments

Comments
 (0)