Skip to content

Commit

Permalink
fix: error in surface area calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
william-silversmith committed Apr 3, 2024
1 parent 93b4f6f commit 53ab5f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
8 changes: 7 additions & 1 deletion automated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,13 @@ def test_contacts_surface_area():
assert res[(1,3)] == 1
assert res[(1,4)] == 1
assert res[(1,5)] == 1


data = np.ones((3,3,3))
data[1,1,1] = 2
labels_out = cc3d.connected_components(data, connectivity=6)
res = cc3d.contacts(labels_out, connectivity=6, surface_area=True)
assert res[(1,2)] == 6

def test_contacts_26():
labels = np.zeros( (10, 10, 10), dtype=np.uint32 )

Expand Down
19 changes: 6 additions & 13 deletions cc3d_graphs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ extract_region_graph(

T cur = 0;
T label = 0;
T last_label = 0;

std::unordered_map<std::pair<T,T>, float, pair_hash> edges;

Expand All @@ -332,25 +331,19 @@ extract_region_graph(
}

compute_neighborhood(neighborhood, x, y, z, sx, sy, sz, connectivity);

last_label = cur;

for (int i = 0; i < connectivity / 2; i++) {
int64_t neighboridx = loc + neighborhood[i];
label = labels[neighboridx];

if (label == 0 || label == last_label) {
if (label == 0) {
continue;
}
else if (label != cur) {
if (cur > label) {
edges[std::pair<T,T>(label, cur)] += areas[i];
}
else {
edges[std::pair<T,T>(cur, label)] += areas[i];
}

last_label = label;
else if (cur > label) {
edges[std::pair<T,T>(label, cur)] += areas[i];
}
else if (cur < label) {
edges[std::pair<T,T>(cur, label)] += areas[i];
}
}
}
Expand Down

0 comments on commit 53ab5f8

Please sign in to comment.