semantic_scene/scene/
level.rs1use std::fmt;
4
5use crate::{Aabb, Vec3};
6
7use super::{SemanticObject, SemanticRegion};
8
9#[derive(Debug, Clone, PartialEq)]
14pub struct SemanticLevel<ObjectCategory, RegionCategory> {
15 index: i32,
16 label: String,
17 position: Vec3,
18 aabb: Aabb,
19 regions: Vec<SemanticRegion<ObjectCategory, RegionCategory>>,
20}
21
22impl<ObjectCategory, RegionCategory> SemanticLevel<ObjectCategory, RegionCategory> {
23 #[must_use]
27 pub const fn new(
28 index: i32,
29 label: String,
30 position: Vec3,
31 aabb: Aabb,
32 regions: Vec<SemanticRegion<ObjectCategory, RegionCategory>>,
33 ) -> Self {
34 Self {
35 index,
36 label,
37 position,
38 aabb,
39 regions,
40 }
41 }
42
43 #[must_use]
47 pub fn id(&self) -> String {
48 self.index.to_string()
49 }
50
51 #[must_use]
53 pub const fn index(&self) -> i32 {
54 self.index
55 }
56
57 #[must_use]
59 pub fn label(&self) -> &str {
60 &self.label
61 }
62
63 #[must_use]
65 pub const fn position(&self) -> Vec3 {
66 self.position
67 }
68
69 #[must_use]
71 pub const fn aabb(&self) -> &Aabb {
72 &self.aabb
73 }
74
75 #[must_use]
77 pub fn regions(&self) -> &[SemanticRegion<ObjectCategory, RegionCategory>] {
78 &self.regions
79 }
80
81 pub fn objects(&self) -> impl Iterator<Item = &SemanticObject<ObjectCategory>> {
83 self.regions.iter().flat_map(SemanticRegion::objects)
84 }
85}
86
87impl<OC, RC> fmt::Display for SemanticLevel<OC, RC> {
88 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
89 write!(
90 formatter,
91 "level {}: regions={}, objects={}, bounds=[{}]",
92 self.index,
93 self.regions.len(),
94 self.objects().count(),
95 self.aabb
96 )
97 }
98}