5 #ifdef HAVE_POINT_CLOUD_TFS
8 #include <tbb/blocked_range.h>
9 #include <tbb/parallel_for.h>
19 __attribute__((__used__)) int32_t tf_point_cloud_metadata__cpu_(
28 Column<int32_t>& file_source_id,
29 Column<int16_t>& version_major,
30 Column<int16_t>& version_minor,
31 Column<int16_t>& creation_year,
32 Column<
bool>& is_compressed,
33 Column<int64_t>& num_points,
35 Column<int16_t>& point_len,
39 Column<
bool>& has_infrared,
40 Column<
bool>& has_14_point_format,
41 Column<int32_t>& specified_utm_zone,
42 Column<
double>& source_x_min,
43 Column<
double>& source_x_max,
44 Column<
double>& source_y_min,
45 Column<
double>& source_y_max,
46 Column<
double>& source_z_min,
47 Column<
double>& source_z_max,
48 Column<
double>& transformed_x_min,
49 Column<
double>& transformed_x_max,
50 Column<
double>& transformed_y_min,
51 Column<
double>& transformed_y_max,
52 Column<
double>& transformed_z_min,
53 Column<
double>& transformed_z_max) {
63 return mgr.ERROR_MESSAGE(
"x_min must be less than x_max");
67 return mgr.ERROR_MESSAGE(
"y_min must be less than y_max");
70 const std::string las_path(path.getString());
71 const std::vector<std::filesystem::path> file_paths =
73 for (
const auto& file_path : file_paths) {
77 }
catch (
const std::runtime_error& e) {
78 const auto error_msg{
"File path " + std::string(file_path) +
" is not whitelisted"};
79 return mgr.ERROR_MESSAGE(error_msg);
82 const std::string out_srs(
"EPSG:4326");
83 const auto& lidar_file_info = PdalLoader::get_metadata_for_files(file_paths, out_srs);
84 const auto& filtered_lidar_file_info =
85 filter_files_by_bounds(lidar_file_info.second, x_min, x_max, y_min, y_max);
86 const size_t num_filtered_files(filtered_lidar_file_info.second.size());
87 mgr.set_output_row_size(num_filtered_files);
89 for (
size_t file_idx = 0; file_idx < num_filtered_files; ++file_idx) {
90 const std::shared_ptr<PdalLoader::LidarMetadata>& lidar_metadata =
91 filtered_lidar_file_info.second[file_idx];
93 file_path.string_dict_proxy_->getOrAddTransient(lidar_metadata->filename);
95 lidar_metadata->filename.rfind(
"/", lidar_metadata->filename.size() - 1UL);
96 if (last_slash_pos == std::string::npos) {
101 file_name[file_idx] =
102 file_name.string_dict_proxy_->getOrAddTransient(lidar_metadata->filename.substr(
103 last_slash_pos, lidar_metadata->filename.size() - last_slash_pos));
104 file_source_id[file_idx] = lidar_metadata->file_source_id;
105 version_major[file_idx] = lidar_metadata->version_major;
106 version_minor[file_idx] = lidar_metadata->version_minor;
107 creation_year[file_idx] = lidar_metadata->creation_year;
108 is_compressed[file_idx] = lidar_metadata->is_compressed;
109 num_points[file_idx] = lidar_metadata->num_points;
110 num_dims[file_idx] = lidar_metadata->num_dims;
111 point_len[file_idx] = lidar_metadata->point_len;
112 has_time[file_idx] = lidar_metadata->has_time;
113 has_color[file_idx] = lidar_metadata->has_color;
114 has_wave[file_idx] = lidar_metadata->has_wave;
115 has_infrared[file_idx] = lidar_metadata->has_infrared;
116 has_14_point_format[file_idx] = lidar_metadata->has_14_point_format;
117 specified_utm_zone[file_idx] = lidar_metadata->specified_utm_zone;
118 source_x_min[file_idx] = lidar_metadata->source_x_bounds.first;
119 source_x_max[file_idx] = lidar_metadata->source_x_bounds.second;
120 source_y_min[file_idx] = lidar_metadata->source_y_bounds.first;
121 source_y_max[file_idx] = lidar_metadata->source_y_bounds.second;
122 source_z_min[file_idx] = lidar_metadata->source_z_bounds.first;
123 source_z_max[file_idx] = lidar_metadata->source_z_bounds.second;
124 transformed_x_min[file_idx] = lidar_metadata->transformed_x_bounds.first;
125 transformed_x_max[file_idx] = lidar_metadata->transformed_x_bounds.second;
126 transformed_y_min[file_idx] = lidar_metadata->transformed_y_bounds.first;
127 transformed_y_max[file_idx] = lidar_metadata->transformed_y_bounds.second;
128 transformed_z_min[file_idx] = lidar_metadata->transformed_z_bounds.first;
129 transformed_z_max[file_idx] = lidar_metadata->transformed_z_bounds.second;
131 return num_filtered_files;
135 __attribute__((__used__)) int32_t tf_point_cloud_metadata__cpu_2(
140 Column<int32_t>& file_source_id,
141 Column<int16_t>& version_major,
142 Column<int16_t>& version_minor,
143 Column<int16_t>& creation_year,
144 Column<
bool>& is_compressed,
145 Column<int64_t>& num_points,
146 Column<int16_t>& num_dims,
147 Column<int16_t>& point_len,
151 Column<
bool>& has_infrared,
152 Column<
bool>& has_14_point_format,
153 Column<int32_t>& specified_utm_zone,
154 Column<
double>& source_x_min,
155 Column<
double>& source_x_max,
156 Column<
double>& source_y_min,
157 Column<
double>& source_y_max,
158 Column<
double>& source_z_min,
159 Column<
double>& source_z_max,
160 Column<
double>& transformed_x_min,
161 Column<
double>& transformed_x_max,
162 Column<
double>& transformed_y_min,
163 Column<
double>& transformed_y_max,
164 Column<
double>& transformed_z_min,
165 Column<
double>& transformed_z_max) {
166 const double x_min = std::numeric_limits<double>::lowest();
167 const double x_max = std::numeric_limits<double>::max();
168 const double y_min = std::numeric_limits<double>::lowest();
169 const double y_max = std::numeric_limits<double>::max();
171 return tf_point_cloud_metadata__cpu_(mgr,
212 const
bool use_cache,
220 Column<int32_t>& intensity,
221 Column<int8_t>& return_num,
222 Column<int8_t>& num_returns,
223 Column<int8_t>& scan_direction_flag,
224 Column<int8_t>& edge_of_flight_line_flag,
225 Column<int16_t>& classification,
226 Column<int8_t>& scan_angle_rank) {
229 if (x_min >= x_max) {
230 return mgr.ERROR_MESSAGE(
"x_min must be less than x_max");
233 if (y_min >= y_max) {
234 return mgr.ERROR_MESSAGE(
"y_min must be less than y_max");
237 const std::string las_path(path.getString());
238 const std::string las_out_srs(out_srs.getString());
240 const std::vector<std::filesystem::path> file_paths =
242 for (
const auto& file_path : file_paths) {
246 }
catch (
const std::runtime_error& e) {
247 const auto error_msg{
"File path " + std::string(file_path) +
" is not whitelisted"};
248 return mgr.ERROR_MESSAGE(error_msg);
251 const auto& lidar_file_info =
252 PdalLoader::get_metadata_for_files(file_paths, las_out_srs);
253 const auto& filtered_lidar_file_info =
254 filter_files_by_bounds(lidar_file_info.second, x_min, x_max, y_min, y_max);
255 const size_t num_filtered_files(filtered_lidar_file_info.second.size());
256 mgr.set_output_row_size(filtered_lidar_file_info.first);
258 std::atomic<int64_t> row_offset = 0;
260 tbb::blocked_range<size_t>(0, num_filtered_files),
261 [&](
const tbb::blocked_range<size_t>& r) {
262 const size_t start_file_idx = r.begin();
263 const size_t end_file_idx = r.end();
264 for (
size_t file_idx = start_file_idx; file_idx != end_file_idx; ++file_idx) {
265 const std::shared_ptr<PdalLoader::LidarMetadata>& lidar_metadata =
266 filtered_lidar_file_info.second[file_idx];
267 const int64_t num_points = lidar_metadata->num_points;
268 const auto& las_fs_path = std::filesystem::path(lidar_metadata->filename);
269 const auto file_status = std::filesystem::status(las_fs_path);
270 if (!std::filesystem::is_regular_file(file_status)) {
274 const std::vector<std::pair<std::string, size_t>> sub_keys_and_byte_sizes = {
275 std::make_pair(
"x", 8),
276 std::make_pair(
"y", 8),
277 std::make_pair(
"z", 8),
278 std::make_pair(
"intensity", 4),
279 std::make_pair(
"return_num", 1),
280 std::make_pair(
"num_returns", 1),
281 std::make_pair(
"scan_direction_flag", 1),
282 std::make_pair(
"edge_of_flight_line_flag", 1),
283 std::make_pair(
"classification", 2),
284 std::make_pair(
"scan_angle_rank", 1)};
286 if (use_cache && PdalLoader::keys_are_cached(lidar_metadata->filename,
289 sub_keys_and_byte_sizes)) {
290 const int64_t offset =
291 row_offset.fetch_add(num_points, std::memory_order_relaxed);
292 PdalLoader::data_cache.getDataForKey(
293 PdalLoader::make_cache_key(lidar_metadata->filename, las_out_srs,
"x"),
295 PdalLoader::data_cache.getDataForKey(
296 PdalLoader::make_cache_key(lidar_metadata->filename, las_out_srs,
"y"),
298 PdalLoader::data_cache.getDataForKey(
299 PdalLoader::make_cache_key(lidar_metadata->filename, las_out_srs,
"z"),
301 PdalLoader::data_cache.getDataForKey(
302 PdalLoader::make_cache_key(
303 lidar_metadata->filename, las_out_srs,
"intensity"),
304 intensity.ptr_ + offset);
305 PdalLoader::data_cache.getDataForKey(
306 PdalLoader::make_cache_key(
307 lidar_metadata->filename, las_out_srs,
"return_num"),
308 return_num.ptr_ + offset);
309 PdalLoader::data_cache.getDataForKey(
310 PdalLoader::make_cache_key(
311 lidar_metadata->filename, las_out_srs,
"num_returns"),
312 num_returns.ptr_ + offset);
313 PdalLoader::data_cache.getDataForKey(
314 PdalLoader::make_cache_key(
315 lidar_metadata->filename, las_out_srs,
"scan_direction_flag"),
316 scan_direction_flag.ptr_ + offset);
317 PdalLoader::data_cache.getDataForKey(
318 PdalLoader::make_cache_key(
319 lidar_metadata->filename, las_out_srs,
"edge_of_flight_line_flag"),
320 edge_of_flight_line_flag.ptr_ + offset);
321 PdalLoader::data_cache.getDataForKey(
322 PdalLoader::make_cache_key(
323 lidar_metadata->filename, las_out_srs,
"classification"),
324 classification.ptr_ + offset);
325 PdalLoader::data_cache.getDataForKey(
326 PdalLoader::make_cache_key(
327 lidar_metadata->filename, las_out_srs,
"scan_angle_rank"),
328 scan_angle_rank.ptr_ + offset);
332 PdalLoader::PdalFileMgr pdal_file_mgr(lidar_metadata, las_out_srs);
333 pdal_file_mgr.openAndPrepareFile();
334 if (!pdal_file_mgr.isReady()) {
340 const int64_t offset =
341 row_offset.fetch_add(lidar_metadata->num_points, std::memory_order_relaxed);
342 pdal_file_mgr.readData(x.ptr_ + offset,
345 intensity.ptr_ + offset,
346 return_num.ptr_ + offset,
347 num_returns.ptr_ + offset,
348 scan_direction_flag.ptr_ + offset,
349 edge_of_flight_line_flag.ptr_ + offset,
350 classification.ptr_ + offset,
351 scan_angle_rank.ptr_ + offset);
355 PdalLoader::data_cache.putDataForKey(
356 PdalLoader::make_cache_key(lidar_metadata->filename, las_out_srs,
"x"),
358 lidar_metadata->num_points);
359 PdalLoader::data_cache.putDataForKey(
360 PdalLoader::make_cache_key(lidar_metadata->filename, las_out_srs,
"y"),
362 lidar_metadata->num_points);
363 PdalLoader::data_cache.putDataForKey(
364 PdalLoader::make_cache_key(lidar_metadata->filename, las_out_srs,
"z"),
366 lidar_metadata->num_points);
367 PdalLoader::data_cache.putDataForKey(
368 PdalLoader::make_cache_key(
369 lidar_metadata->filename, las_out_srs,
"intensity"),
370 intensity.ptr_ + offset,
371 lidar_metadata->num_points);
372 PdalLoader::data_cache.putDataForKey(
373 PdalLoader::make_cache_key(
374 lidar_metadata->filename, las_out_srs,
"return_num"),
375 return_num.ptr_ + offset,
376 lidar_metadata->num_points);
377 PdalLoader::data_cache.putDataForKey(
378 PdalLoader::make_cache_key(
379 lidar_metadata->filename, las_out_srs,
"num_returns"),
380 num_returns.ptr_ + offset,
381 lidar_metadata->num_points);
382 PdalLoader::data_cache.putDataForKey(
383 PdalLoader::make_cache_key(
384 lidar_metadata->filename, las_out_srs,
"scan_direction_flag"),
385 scan_direction_flag.ptr_ + offset,
386 lidar_metadata->num_points);
387 PdalLoader::data_cache.putDataForKey(
388 PdalLoader::make_cache_key(
389 lidar_metadata->filename, las_out_srs,
"edge_of_flight_line_flag"),
390 edge_of_flight_line_flag.ptr_ + offset,
391 lidar_metadata->num_points);
392 PdalLoader::data_cache.putDataForKey(
393 PdalLoader::make_cache_key(
394 lidar_metadata->filename, las_out_srs,
"classification"),
395 classification.ptr_ + offset,
396 lidar_metadata->num_points);
397 PdalLoader::data_cache.putDataForKey(
398 PdalLoader::make_cache_key(
399 lidar_metadata->filename, las_out_srs,
"scan_angle_rank"),
400 scan_angle_rank.ptr_ + offset,
401 lidar_metadata->num_points);
402 }
catch (std::runtime_error& e) {
414 __attribute__((__used__)) int32_t tf_load_point_cloud__cpu_2(
420 Column<int32_t>& intensity,
421 Column<int8_t>& return_num,
422 Column<int8_t>& num_returns,
423 Column<int8_t>& scan_direction_flag,
424 Column<int8_t>& edge_of_flight_line_flag,
425 Column<int16_t>& classification,
426 Column<int8_t>& scan_angle_rank) {
427 std::string pdal_out_srs(
"EPSG:4326");
429 out_srs.
ptr_ = pdal_out_srs.data();
430 out_srs.
size_ = pdal_out_srs.size();
431 const double x_min = std::numeric_limits<double>::lowest();
432 const double x_max = std::numeric_limits<double>::max();
433 const double y_min = std::numeric_limits<double>::lowest();
434 const double y_max = std::numeric_limits<double>::max();
435 return tf_load_point_cloud__cpu_(mgr,
450 edge_of_flight_line_flag,
456 __attribute__((__used__)) int32_t tf_load_point_cloud__cpu_3(
466 Column<int32_t>& intensity,
467 Column<int8_t>& return_num,
468 Column<int8_t>& num_returns,
469 Column<int8_t>& scan_direction_flag,
470 Column<int8_t>& edge_of_flight_line_flag,
471 Column<int16_t>& classification,
472 Column<int8_t>& scan_angle_rank) {
473 std::string pdal_out_srs(
"EPSG:4326");
475 out_srs.
ptr_ = pdal_out_srs.data();
476 out_srs.
size_ = pdal_out_srs.size();
477 return tf_load_point_cloud__cpu_(mgr,
492 edge_of_flight_line_flag,
498 __attribute__((__used__)) int32_t tf_load_point_cloud__cpu_4(
501 const
bool use_cache,
505 Column<int32_t>& intensity,
506 Column<int8_t>& return_num,
507 Column<int8_t>& num_returns,
508 Column<int8_t>& scan_direction_flag,
509 Column<int8_t>& edge_of_flight_line_flag,
510 Column<int16_t>& classification,
511 Column<int8_t>& scan_angle_rank) {
512 std::string pdal_out_srs(
"EPSG:4326");
514 out_srs.
ptr_ = pdal_out_srs.data();
515 out_srs.
size_ = pdal_out_srs.size();
516 const double x_min = std::numeric_limits<double>::lowest();
517 const double x_max = std::numeric_limits<double>::max();
518 const double y_min = std::numeric_limits<double>::lowest();
519 const double y_max = std::numeric_limits<double>::max();
520 return tf_load_point_cloud__cpu_(mgr,
535 edge_of_flight_line_flag,
541 #endif // HAVE_TF_POINT_CLOUD_TFS
std::vector< std::filesystem::path > get_fs_paths(const std::string &file_or_directory)
#define EXTENSION_NOINLINE_HOST
void validate_allowed_file_path(const std::string &file_path, const DataTransferType data_transfer_type, const bool allow_wildcards)
__attribute__((__used__)) ModelInfo get_model_info_from_file(const std
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())
std::string filename(char const *path)
#define DEBUG_TIMER(name)