aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcc <cc@localhost>2025-08-28 02:36:30 -0700
committercc <cc@localhost>2025-08-28 03:02:18 -0700
commit82d392112f71a8ad99ddebbbd00b13d7972535bc (patch)
tree40c27a2c4729c0f7e6fa1bde203040eb5cd6e4d0
parent38efd731dd77a2eb78268525c5affe56ac96316c (diff)
Logic for determining data fields
-rw-r--r--src/analysis.rs74
1 files changed, 62 insertions, 12 deletions
diff --git a/src/analysis.rs b/src/analysis.rs
index 9cf0b6a..e22408b 100644
--- a/src/analysis.rs
+++ b/src/analysis.rs
@@ -23,6 +23,14 @@ impl Data {
}
}
+fn any(a: &[bool]) -> bool {
+ for value in a.iter() {
+ if *value {
+ return true;
+ }
+ }
+ false
+}
impl LabelFormat<u16> {
fn get_tree(&self) -> AVLTree<u16, Data> {
@@ -34,19 +42,59 @@ impl LabelFormat<u16> {
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));
+ let mut new_data = Data::new(
+ key,
+ 0,
+ 0,
+ 0,
+ 0);
+ match avt.get(key) {
+ Some(data) => {
+ new_data.area = data.area;
+ new_data.perimeter = data.perimeter;
+ new_data.cell_cell = data.cell_cell;
+ new_data.cell_tissue = data.cell_tissue;
+ },
+ None => {
+ },
+ }
+ let neighbors: [Option<u16>;4] = [
+ self.get_up(x,y),
+ self.get_right(x,y),
+ self.get_down(x,y),
+ self.get_left(x,y),
+ ];
+ let perimeter_slice = neighbors.map(|x|
+ match x {
+ Some(y) => (y.is_zero()) || (y != new_data.label),
+ None => false,
+ });
+ let add_perimeter = any(&perimeter_slice);
+ let cell_cell_slice = neighbors.map(|x|
+ match x {
+ Some(y) => (y != new_data.label) && (!y.is_zero()),
+ None => false,
+ });
+ let add_cell_cell = any(&cell_cell_slice);
+ let cell_tissue_slice = neighbors.map(|x|
+ match x {
+ Some(y) => y.is_zero(),
+ None => false,
+ });
+ let add_cell_tissue = any(&cell_tissue_slice);
+ // Always increase area
+ new_data.area += 1;
+ // Increase perimeter if there is a neighbor that is not the same cell
+ if add_perimeter {
+ new_data.perimeter += 1;
+ }
+ if add_cell_tissue {
+ new_data.cell_tissue += 1;
+ }
+ if add_cell_cell {
+ new_data.cell_cell += 1;
}
+ avt.insert(key, new_data);
}
}
avt
@@ -68,7 +116,9 @@ mod tests {
test_data.buffer[2+3*DIM] = 1;
test_data.buffer[3+3*DIM] = 1;
test_data.buffer[4+3*DIM] = 2;
+ test_data.idilate();
+ test_data.display();
for (key,val) in test_data.get_tree().iter() {
println!("{} -> {:?}",key,val)
}