Skip to content
Snippets Groups Projects
Commit b6bcf710 authored by Roman Belousov's avatar Roman Belousov
Browse files

Three-planes connectiviity check

parent 9e942945
No related branches found
No related tags found
No related merge requests found
......@@ -252,31 +252,24 @@ impl Kernel {
result
}
/// Check whether local connectivity of a voxel allows a move
pub(crate) fn check_change(&self, voxel: &Voxel, voxel_value: usize) -> bool {
// First screen planar index
let index = self.planar_index(voxel, voxel_value);
match index {
[0, 0, 0] | [0, 2, 2] | [2, 2, 4] | [4, 4, 4] => return false,
[0, 1, 1] => return true,
[1, 1, 2] | [1, 2, 3] | [2, 2, 2] | [2, 3, 3] | [3, 3, 4] => (),
_ => panic!("Unexpected planar index ({}, {}, {})", index[0], index[1], index[2])
}
/// Check whether local connectivity of a voxel in an adjacency plane
pub(crate) fn check_plane(&self, voxel: &Voxel, voxel_value: usize, adjacency: &AdjacencyPlane) -> bool {
// The implementation relies on a graph connectivity check
let mut graph_nodes = Vec::<[i64; DIM]>::with_capacity(5);
for triplet in &TARGET_NEIGHBORHOOD {
let mut graph_nodes = Vec::<[i64; DIM]>::with_capacity(4);
for triplet in adjacency {
if voxel_value == self.get_index_value(
voxel.index[0] + triplet[0],
voxel.index[1] + triplet[1],
voxel.index[2] + triplet[2]
) { graph_nodes.push(*triplet) }
}
// Trivial situtations
let sz = graph_nodes.len();
if sz == 0 || sz == 6 { return false }
if sz == 1 { return true }
match sz {
1 => return true,
2 | 3 | 4 => (),
_ => panic!("Unexpected plane index {}", sz)
}
// Find edges
let mut graph_edges = vec![Vec::<usize>::new(); sz];
......@@ -315,6 +308,23 @@ impl Kernel {
visited.iter().all(|v| *v)
}
/// Check whether local connectivity of a voxel allows a move
pub(crate) fn check_change(&self, voxel: &Voxel, voxel_value: usize) -> bool {
// First screen planar index
let index = self.planar_index(voxel, voxel_value);
match index {
[0, 0, 0] | [0, 2, 2] | [2, 2, 4] | [4, 4, 4] => return false,
[0, 1, 1] => return true,
[1, 1, 2] | [1, 2, 3] | [2, 2, 2] | [2, 3, 3] | [3, 3, 4] => (),
_ => panic!("Unexpected planar index ({}, {}, {})", index[0], index[1], index[2])
}
for adjacency in [&ADJACENCY_X, &ADJACENCY_Y, &ADJACENCY_Z] {
if !self.check_plane(voxel, voxel_value, &adjacency) { return false }
}
true
}
/// Modulation of voxel-voxel interactions by distance
pub(crate) fn modulate(&self, triplet: &[i64; DIM]) -> f64 {
match triplet[0].abs() + triplet[1].abs() + triplet[2].abs() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment