aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--src/analysis.rs76
-rw-r--r--src/lib.rs3
4 files changed, 89 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 51bd3e4..670a762 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,5 +3,13 @@
version = 4
[[package]]
+name = "avl_tree"
+version = "0.2.1"
+source = "git+https://git.ccrl.dev/avl_tree.git/#5c9746dccf6a77bf4a921a4420b663e05af6247c"
+
+[[package]]
name = "label_toolkit"
-version = "0.0.3"
+version = "0.1.0"
+dependencies = [
+ "avl_tree",
+]
diff --git a/Cargo.toml b/Cargo.toml
index 41caf08..3e06d25 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2024"
[dependencies]
+avl_tree = { git = "https://git.ccrl.dev/avl_tree.git/" }
diff --git a/src/analysis.rs b/src/analysis.rs
new file mode 100644
index 0000000..9cf0b6a
--- /dev/null
+++ b/src/analysis.rs
@@ -0,0 +1,76 @@
+use crate::{LabelFormat,LabelU16};
+
+use avl_tree::*;
+
+#[derive(Debug)]
+struct Data {
+ label: u16,
+ area: usize,
+ perimeter: usize,
+ cell_cell: usize,
+ cell_tissue: usize,
+}
+
+impl Data {
+ const fn new(label: u16, area: usize, perimeter: usize, cell_cell: usize, cell_tissue: usize) -> Self {
+ Self {
+ label,
+ area,
+ perimeter,
+ cell_cell,
+ cell_tissue,
+ }
+ }
+}
+
+
+impl LabelFormat<u16> {
+ fn get_tree(&self) -> AVLTree<u16, Data> {
+ let mut avt = avl_tree::AVLTree::<u16, Data>::new();
+ for y in 0..self.height {
+ for x in 0..self.width {
+ let index = x + y * self.width;
+ let key = self.buffer[index];
+ if key.is_zero() {
+ continue;
+ }
+ if let Some(data) = avt.get(key) {
+ let mut new_data = Data::new(
+ data.label,
+ data.area,
+ data.perimeter,
+ data.cell_cell,
+ data.cell_tissue,
+ );
+ new_data.area += 1;
+ avt.insert(key, new_data);
+ } else {
+ avt.insert(key, Data::new(key, 1, 0, 0, 0));
+ }
+ }
+ }
+ avt
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn get_areas_test() {
+ const DIM: usize = 6;
+ let mut test_data = LabelFormat::<u16> {
+ buffer: vec![0u16; DIM*DIM],
+ width: DIM,
+ height: DIM,
+ };
+ test_data.buffer[2+3*DIM] = 1;
+ test_data.buffer[3+3*DIM] = 1;
+ test_data.buffer[4+3*DIM] = 2;
+
+ for (key,val) in test_data.get_tree().iter() {
+ println!("{} -> {:?}",key,val)
+ }
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index ace2fb7..c479f76 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,8 @@
+extern crate avl_tree;
+
mod label_format;
pub mod binfile;
+pub mod analysis;
pub use crate::label_format::{LabelFormat,LabelU16};