Skip to content

Commit

Permalink
Merge pull request #46 from fugro-oss/EVLROffsetBug
Browse files Browse the repository at this point in the history
Fix EVLR offset bug
  • Loading branch information
BenCurran98 authored Oct 31, 2024
2 parents e48d3b4 + ee73bc0 commit b3a82c1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LASDatasets"
uuid = "cc498e2a-d443-4943-8f26-2a8a0f3c7cdb"
authors = ["BenCurran98 <b.curran@fugro.com>"]
version = "0.3.1"
version = "0.3.2"

[deps]
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"
Expand All @@ -27,13 +27,15 @@ FileIO = "1"
FixedPointNumbers = "0.8"
PackedReadWrite = "0.1"
Proj = "1"
Random = "1.11.0"
StaticArrays = "1"
StructArrays = "0.6"
TypedTables = "1"
julia = "1.8"

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

[targets]
test = ["Test"]
test = ["Test", "Random"]
16 changes: 15 additions & 1 deletion src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ Get the unit factor conversion that was applied to this dataset when ingested
"""
get_unit_conversion(las::LASDataset) = las.unit_conversion

"""
$(TYPEDSIGNATURES)
Update the offset (in Bytes) to the first EVLR in a `LASDataset` `las`
"""
function update_evlr_offset!(header::LasHeader)
header.evlr_start = point_data_offset(header) + (number_of_points(header) * point_record_length(header))
end

update_evlr_offset!(las::LASDataset) = update_evlr_offset!(get_header(las))

function Base.show(io::IO, las::LASDataset)
println(io, "LAS Dataset")
println(io, "\tNum Points: $(length(get_pointcloud(las)))")
Expand Down Expand Up @@ -239,13 +250,14 @@ function add_vlr!(las::LASDataset, vlr::LasVariableLengthRecord)
push!(get_evlrs(las), vlr)
if number_of_evlrs(header) == 1
# if this is our first EVLR, need to set the EVLR offset to point to the correct location
header.evlr_start = point_data_offset(header) + (number_of_points(header) * point_record_length(header))
update_evlr_offset!(header)
end
else
set_num_vlr!(header, number_of_vlrs(header) + 1)
push!(get_vlrs(las), vlr)
# make sure to increase the point offset since we're cramming another VLR before the points
header.data_offset += sizeof(vlr)
update_evlr_offset!(header)
end
end

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

Expand Down
10 changes: 9 additions & 1 deletion test/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
@test length(evlrs) == 1
@test number_of_evlrs(header) == 1
@test evlrs[1] == long_comment
@test evlr_start(header) > 0
# make sure the offset makes sense
@test evlr_start(header) == point_data_offset(header) + (number_of_points(header) * point_record_length(header))
# we can add a new comment on top of this one
new_commment = LasVariableLengthRecord("Comment", 100, "This is a new comment", Comment(String(rand(UInt8, 2^8))), true)
add_vlr!(las, new_commment)
Expand All @@ -165,6 +166,13 @@
@test get_description(superseded_comment) == get_description(long_comment)
@test get_data(superseded_comment) == get_data(long_comment)
@test is_extended(superseded_comment) == is_extended(long_comment)
# if we add a regular VLR, we should update the offset to the first EVLR correctly
short_comment = LasVariableLengthRecord("Comment", 100, "This is a long comment", Comment(String(rand(UInt8, 10))))
add_vlr!(las, short_comment)
@test evlr_start(header) == point_data_offset(header) + (number_of_points(header) * point_record_length(header))
# and similarly if we add column data it should update properly
add_column!(las, :another_column, rand(UInt8, num_points))
@test evlr_start(header) == point_data_offset(header) + (number_of_points(header) * point_record_length(header))
# and finally we can remove it
remove_vlr!(las, superseded_comment)
@test number_of_evlrs(get_header(las)) == 1
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ using LASDatasets

using ColorTypes
using FixedPointNumbers
using Random
using StaticArrays
using Test
using TypedTables

# fix random seed to avoid random errors
Random.seed!(0)

include("util.jl")
include("spatial_info.jl")
include("vlrs.jl")
Expand Down

2 comments on commit b3a82c1

@BenCurran98
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/118414

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" b3a82c1dce2bec696f4b515824285f3356c37b6d
git push origin v0.3.2

Please # to comment.