Skip to main content

qualia_vision/
kitti_taxonomy.rs

1//! KITTI 3D Autonomous Driving Taxonomy & Semantic Resolver.
2//!
3//! Provides zero-allocation FNV-1a IRI hashing, class index mapping (0..7),
4//! and display name resolution for all 8 KITTI 3D object detection classes.
5
6use crate::semantic::q_hash;
7
8/// KITTI 3D object classes (Display Name, Class Index 0..7).
9pub const KITTI_8_CLASSES: &[(&str, u32)] = &[
10    ("Car", 0),
11    ("Van", 1),
12    ("Truck", 2),
13    ("Pedestrian", 3),
14    ("Person_sitting", 4),
15    ("Cyclist", 5),
16    ("Tram", 6),
17    ("Misc", 7),
18];
19
20/// Resolve a KITTI class display name by numeric class index (0..7).
21pub fn lookup_kitti_class_by_id(id: u32) -> Option<&'static str> {
22    KITTI_8_CLASSES
23        .iter()
24        .find(|(_, idx)| *idx == id)
25        .map(|(name, _)| *name)
26}
27
28/// Resolve a KITTI class display name by its deterministic FNV-1a class hash.
29pub fn lookup_kitti_class_by_hash(class_hash: u64) -> Option<&'static str> {
30    KITTI_8_CLASSES
31        .iter()
32        .find(|(name, _)| q_hash(name) == class_hash)
33        .map(|(name, _)| *name)
34}
35
36/// Compute the deterministic 64-bit FNV-1a class hash for a KITTI display name.
37pub fn q_hash_kitti_class(display_name: &str) -> u64 {
38    q_hash(display_name)
39}
40
41/// Total count of registered KITTI 3D object categories.
42pub fn kitti_category_count() -> usize {
43    KITTI_8_CLASSES.len()
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_kitti_taxonomy_lookups() {
52        assert_eq!(lookup_kitti_class_by_id(0), Some("Car"));
53        assert_eq!(lookup_kitti_class_by_id(3), Some("Pedestrian"));
54        assert_eq!(lookup_kitti_class_by_id(5), Some("Cyclist"));
55
56        let car_hash = q_hash("Car");
57        assert_eq!(lookup_kitti_class_by_hash(car_hash), Some("Car"));
58
59        assert_eq!(kitti_category_count(), 8);
60    }
61}