cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
kitti_types_impl.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <algorithm>
5#include <set>
6
7namespace toolbox::io {
8
9// ==================== semantic_kitti_frame_t Implementation ====================
10
11template<typename DataType>
12std::unique_ptr<point_cloud_t<DataType>>
14 auto result = std::make_unique<point_cloud_t<DataType>>();
15
16 if (!cloud || labels.size() != cloud->size()) {
17 return result;
18 }
19
20 result->points.reserve(cloud->size() / 10); // Rough estimate
21
22 for (std::size_t i = 0; i < cloud->size(); ++i) {
23 if (get_kitti_label_id(labels[i]) == label) {
24 result->points.push_back(cloud->points[i]);
25 }
26 }
27
28 result->points.shrink_to_fit();
29 return result;
30}
31
32template<typename DataType>
33std::unique_ptr<point_cloud_t<DataType>>
35 const std::vector<uint16_t>& label_ids) const {
36
37 auto result = std::make_unique<point_cloud_t<DataType>>();
38
39 if (!cloud || labels.size() != cloud->size()) {
40 return result;
41 }
42
43 // Convert to set for faster lookup
44 std::set<uint16_t> label_set(label_ids.begin(), label_ids.end());
45
46 result->points.reserve(cloud->size() / 2); // Rough estimate
47
48 for (std::size_t i = 0; i < cloud->size(); ++i) {
49 if (label_set.count(get_kitti_label_id(labels[i])) > 0) {
50 result->points.push_back(cloud->points[i]);
51 }
52 }
53
54 result->points.shrink_to_fit();
55 return result;
56}
57
58template<typename DataType>
60 std::set<uint16_t> unique_labels;
61
62 for (const auto& label : labels) {
63 unique_labels.insert(get_kitti_label_id(label));
64 }
65
66 return std::vector<uint16_t>(unique_labels.begin(), unique_labels.end());
67}
68
69template<typename DataType>
70std::map<uint16_t, std::size_t>
72 std::map<uint16_t, std::size_t> stats;
73
74 for (const auto& label : labels) {
75 stats[get_kitti_label_id(label)]++;
76 }
77
78 return stats;
79}
80
81// ==================== semantic_kitti_frame_pair_t Implementation ====================
82
83template<typename DataType>
84std::pair<std::unique_ptr<point_cloud_t<DataType>>,
85 std::unique_ptr<point_cloud_t<DataType>>>
87
88 auto source_static = std::make_unique<point_cloud_t<DataType>>();
89 auto target_static = std::make_unique<point_cloud_t<DataType>>();
90
91 // Extract static points from source
92 if (source_cloud && source_labels.size() == source_cloud->size()) {
93 for (std::size_t i = 0; i < source_cloud->size(); ++i) {
94 uint16_t label_id = get_kitti_label_id(source_labels[i]);
96 source_static->points.push_back(source_cloud->points[i]);
97 }
98 }
99 }
100
101 // Extract static points from target
102 if (target_cloud && target_labels.size() == target_cloud->size()) {
103 for (std::size_t i = 0; i < target_cloud->size(); ++i) {
104 uint16_t label_id = get_kitti_label_id(target_labels[i]);
105 if (kitti_semantic_labels::is_static(label_id)) {
106 target_static->points.push_back(target_cloud->points[i]);
107 }
108 }
109 }
110
111 return std::make_pair(std::move(source_static), std::move(target_static));
112}
113
114template<typename DataType>
115std::pair<std::unique_ptr<point_cloud_t<DataType>>,
116 std::unique_ptr<point_cloud_t<DataType>>>
118
119 auto source_dynamic = std::make_unique<point_cloud_t<DataType>>();
120 auto target_dynamic = std::make_unique<point_cloud_t<DataType>>();
121
122 // Extract dynamic points from source
123 if (source_cloud && source_labels.size() == source_cloud->size()) {
124 for (std::size_t i = 0; i < source_cloud->size(); ++i) {
125 uint16_t label_id = get_kitti_label_id(source_labels[i]);
126 if (kitti_semantic_labels::is_dynamic(label_id)) {
127 source_dynamic->points.push_back(source_cloud->points[i]);
128 }
129 }
130 }
131
132 // Extract dynamic points from target
133 if (target_cloud && target_labels.size() == target_cloud->size()) {
134 for (std::size_t i = 0; i < target_cloud->size(); ++i) {
135 uint16_t label_id = get_kitti_label_id(target_labels[i]);
136 if (kitti_semantic_labels::is_dynamic(label_id)) {
137 target_dynamic->points.push_back(target_cloud->points[i]);
138 }
139 }
140 }
141
142 return std::make_pair(std::move(source_dynamic), std::move(target_dynamic));
143}
144
145} // namespace toolbox::io
bool is_dynamic(uint16_t label)
Check if a label is dynamic (moving)
Definition kitti_extended.hpp:269
bool is_static(uint16_t label)
Check if a label is static (non-moving)
Definition kitti_extended.hpp:259
< 用于列出目录下的文件/For listing files in a directory
Definition dataloader.hpp:15
uint16_t get_kitti_label_id(uint32_t full_label)
Extract label ID from full label (ignoring instance ID)
Definition kitti_extended.hpp:289
std::pair< std::unique_ptr< point_cloud_t< DataType > >, std::unique_ptr< point_cloud_t< DataType > > > extract_static_points() const
Extract static points from both clouds (buildings, road, etc.)
Definition kitti_types_impl.hpp:86
std::pair< std::unique_ptr< point_cloud_t< DataType > >, std::unique_ptr< point_cloud_t< DataType > > > extract_dynamic_points() const
Extract dynamic points from both clouds (cars, people, etc.)
Definition kitti_types_impl.hpp:117
std::map< uint16_t, std::size_t > get_label_statistics() const
Count points for each label.
Definition kitti_types_impl.hpp:71
std::unique_ptr< point_cloud_t< DataType > > get_labeled_cloud(uint16_t label) const
Extract point cloud containing only specified label.
Definition kitti_types_impl.hpp:13
std::vector< uint16_t > get_unique_labels() const
Get unique label IDs in this frame.
Definition kitti_types_impl.hpp:59