Skip to content

Commit a0639b1

Browse files
authored
Merge pull request #54 from fugro-oss/FixSynthFlagHandling
Fix synth flag handling
2 parents efefb58 + 143407d commit a0639b1

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
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.4.2"
4+
version = "0.4.3"
55

66
[deps]
77
BufferedStreams = "e1450e63-4bb3-523b-b2a4-4ffa8c0fd77d"

src/header.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ function make_consistent_header!(header::LasHeader,
853853

854854
set_point_data_offset!(header, point_data_offset)
855855

856-
_consolidate_point_header_info!(header, pointcloud)
856+
_consolidate_point_header_info!(header, pointcloud)
857857

858858
if !isempty(vlrs)
859859
set_num_vlr!(header, length(vlrs))
@@ -891,8 +891,13 @@ function _consolidate_point_header_info!(header::LasHeader, pointcloud::Abstract
891891
returns = (:returnnumber columnnames(pointcloud)) ? pointcloud.returnnumber : ones(Int, length(pointcloud))
892892
points_per_return = ntuple(r -> count(returns .== r), num_return_channels(header))
893893
set_number_of_points_by_return!(header, points_per_return)
894+
# check if we have any synthetic points and update the global encoding bit accordingly
894895
if :synthetic columnnames(pointcloud)
895-
set_synthetic_return_numbers_bit!(header)
896+
if any(pointcloud.synthetic)
897+
set_synthetic_return_numbers_bit!(header)
898+
else
899+
unset_synthetic_return_numbers_bit!(header)
900+
end
896901
else
897902
unset_synthetic_return_numbers_bit!(header)
898903
end

test/dataset.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@
5050
LASDatasets.make_consistent_header!(h, pc, LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
5151
las = LASDataset(h, pc, LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
5252
@test las == LASDataset(deepcopy(pc))
53+
54+
# check how we're modifying the synthetic flag - if we have no synthetics, it shouldn't be set
55+
just_synth_flag(global_encoding::UInt16) = global_encoding & 0x0008
56+
@test just_synth_flag(h.global_encoding) == 0x00
57+
# but if we set some, our flag should be adjusted
58+
pc = Table(pc, synthetic = trues(num_points))
59+
h = LasHeader(; las_version = v"1.1", data_format_id = UInt8(1), data_record_length = UInt16(28))
60+
LASDatasets.make_consistent_header!(h, pc, LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
61+
@test just_synth_flag(h.global_encoding) > 0
62+
# if we set all these to false, though, then we shouldn't set the flag either
63+
pc.synthetic .= false
64+
LASDatasets.make_consistent_header!(h, pc, LasVariableLengthRecord[], LasVariableLengthRecord[], UInt8[])
65+
@test just_synth_flag(h.global_encoding) == 0x00
66+
5367

5468
# now try incorporating some user fields
5569
spicy_pc = Table(pc, thing = rand(num_points), other_thing = rand(Int16, num_points))
@@ -58,7 +72,7 @@
5872
this_header = get_header(las)
5973
@test point_record_length(this_header) == LASDatasets.byte_size(LasPoint1) + 10
6074
# our user fields should be populated in the dataset
61-
@test sort(collect(columnnames(las.pointcloud))) == [:classification, :gps_time, :id, :other_thing, :position, :thing]
75+
@test sort(collect(columnnames(las.pointcloud))) == [:classification, :gps_time, :id, :other_thing, :position, :synthetic, :thing]
6276
this_pc = get_pointcloud(las)
6377
@test this_pc.thing == spicy_pc.thing
6478
@test this_pc.other_thing == spicy_pc.other_thing

0 commit comments

Comments
 (0)