27 #include <unordered_map>
33 #include <pdal/PointTable.hpp>
34 #include <pdal/PointView.hpp>
35 #include <pdal/SpatialReference.hpp>
36 #include <pdal/io/LasReader.hpp>
37 namespace PdalLoader {
39 static std::mutex print_mutex;
41 struct LidarMetadata {
43 int32_t file_source_id;
44 int16_t version_major;
45 int16_t version_minor;
46 int16_t creation_year;
55 bool has_14_point_format;
56 int32_t specified_utm_zone;
58 pdal::SpatialReference source_spatial_reference;
59 std::pair<double, double> source_x_bounds;
60 std::pair<double, double> source_y_bounds;
61 std::pair<double, double> source_z_bounds;
62 pdal::SpatialReference transformed_spatial_reference;
63 std::pair<double, double> transformed_x_bounds;
64 std::pair<double, double> transformed_y_bounds;
65 std::pair<double, double> transformed_z_bounds;
67 LidarMetadata() : num_points(0) {}
69 inline void updateBounds(
const double x,
const double y,
const double z) {
70 transformed_x_bounds.first = std::min(transformed_x_bounds.first, x);
71 transformed_x_bounds.second = std::max(transformed_x_bounds.second, x);
72 transformed_y_bounds.first = std::min(transformed_y_bounds.first, y);
73 transformed_y_bounds.second = std::max(transformed_y_bounds.second, y);
74 transformed_z_bounds.first = std::min(transformed_z_bounds.first, z);
75 transformed_z_bounds.second = std::max(transformed_z_bounds.second, z);
79 std::unique_lock<std::mutex> print_lock(print_mutex);
80 std::cout << std::endl <<
"-----Lidar Metadata-------" << std::endl;
81 std::cout <<
"# Points: " << num_points << std::endl;
82 std::cout <<
"X bounds: (" << transformed_x_bounds.first <<
", "
83 << transformed_x_bounds.second <<
")" << std::endl;
84 std::cout <<
"Y bounds: (" << transformed_y_bounds.first <<
", "
85 << transformed_y_bounds.second <<
")" << std::endl;
86 std::cout <<
"Z bounds: (" << transformed_z_bounds.first <<
", "
87 << transformed_z_bounds.second <<
")" << std::endl;
99 int8_t* scan_direction_flag;
100 int8_t* edge_of_flight_line;
101 int16_t* classification;
102 int8_t* scan_angle_rank;
108 inline std::string make_cache_key(
const std::string&
filename,
109 const std::string& out_srs,
110 const std::string& attribute) {
111 return filename +
" || " + out_srs +
"|| " + attribute;
114 std::shared_ptr<LidarMetadata> get_metadata_for_file(
const std::string&
filename,
115 const std::string& out_srs);
117 std::pair<int64_t, std::vector<std::shared_ptr<LidarMetadata>>> get_metadata_for_files(
118 const std::vector<std::filesystem::path>& file_paths,
119 const std::string& out_srs);
121 std::pair<int64_t, std::vector<std::shared_ptr<LidarMetadata>>> filter_files_by_bounds(
122 const std::vector<std::shared_ptr<LidarMetadata>>& lidar_metadata_vec,
128 bool keys_are_cached(
130 const std::string& out_srs,
131 const size_t num_records,
132 const std::vector<std::pair<std::string, size_t>>& sub_keys_and_byte_sizes);
136 PdalFileMgr(
const std::shared_ptr<LidarMetadata>& lidar_metadata,
137 const std::string& out_srs)
138 : lidar_metadata_(lidar_metadata), out_srs_(out_srs) {}
140 void openAndPrepareFile();
142 inline bool isReady()
const {
return is_ready_; }
144 void readData(
double* x,
150 int8_t* scan_direction_flag,
151 int8_t* edge_of_flight_line_flag,
152 int16_t* classification,
153 int8_t* scan_angle_rank) {
161 edge_of_flight_line_flag,
164 lidar_metadata_->num_points);
167 void readData(
double* x,
173 int8_t* scan_direction_flag,
174 int8_t* edge_of_flight_line_flag,
175 int16_t* classification,
176 int8_t* scan_angle_rank,
177 const int64_t num_points);
180 pdal::LasReader las_reader_;
181 pdal::PointTable point_table_;
182 pdal::PointViewSet point_view_set_;
183 pdal::PointViewPtr point_view_;
185 const std::shared_ptr<LidarMetadata> lidar_metadata_;
186 const std::string out_srs_;
187 bool is_ready_{
false};
std::string filename(char const *path)