Skip to content

Commit

Permalink
Fix knn optimization for las 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Romain committed May 9, 2024
1 parent 620aa2e commit a17b14a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/LASRcore/LAS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool LAS::add_point(const LASpoint& p)
size_t required_capacity = npoints*point.total_point_size;
if (required_capacity == capacity)
{
size_t capacity_max = MAX(header->number_of_point_records, header->extended_number_of_point_records)*point.total_point_size;
size_t capacity_max = get_true_number_of_points()*point.total_point_size;

// This may happens if the header is not properly populated
if (required_capacity >= capacity_max)
Expand Down Expand Up @@ -377,7 +377,7 @@ bool LAS::knn(const double* xyz, int k, double radius_max, std::vector<PointLAS>
p.init(point.quantizer, point.num_items, point.items, point.attributer);

double area = (header->max_x-header->min_x)*(header->max_y-header->min_y);
double density = header->number_of_point_records / area;
double density = get_true_number_of_points() / area;
double radius = std::sqrt((double)k / (density * 3.14)) * 1.5;

int n = 0;
Expand Down Expand Up @@ -821,3 +821,10 @@ int LAS::get_point_data_record_length(int point_data_format, int num_extrabytes)
default: return 0; break;
}
}

int LAS::get_true_number_of_points() const
{
int n = (int)MAX(header->number_of_point_records, header->extended_number_of_point_records);
return n;
}

1 change: 1 addition & 0 deletions src/LASRcore/LAS.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LAS
void clean_query();
bool alloc_buffer();
bool realloc_buffer();
int get_true_number_of_points() const;

public:
LASpoint point;
Expand Down

0 comments on commit a17b14a

Please sign in to comment.