Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support arbitrary labels #11

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 7 additions & 33 deletions cc3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <unordered_map>

#include "libdivide.h"

Expand All @@ -47,35 +48,13 @@ namespace cc3d {
template <typename T>
class DisjointSet {
public:
T *ids;
size_t *size;
size_t length;
DisjointSet () {
length = 65536;
ids = new T[length]();
size = new size_t[length]();
}

DisjointSet (size_t len) {
length = len;
ids = new T[length]();
size = new size_t[length]();
}
std::unordered_map<T,T> ids;
std::unordered_map<T,size_t> size;
DisjointSet () {}

DisjointSet (const DisjointSet &cpy) {
length = cpy.length;
ids = new T[length]();
size = new size_t[length]();

for (int i = 0; i < length; i++) {
ids[i] = cpy.ids[i];
size[i] = cpy.size[i];
}
}

~DisjointSet () {
delete []ids;
delete []size;
ids = cpy.ids;
size = cpy.size;
}

T root (T n) {
Expand All @@ -93,11 +72,6 @@ class DisjointSet {
}

void add(T p) {
if (p >= length) {
printf("Connected Components Error: Label %d cannot be mapped to union-find array of length %lu.\n", p, length);
throw "maximum length exception";
}

if (ids[p] == 0) {
ids[p] = p;
size[p] = 1;
Expand Down Expand Up @@ -240,7 +214,7 @@ uint32_t* connected_components3d(

max_labels = std::max(std::min(max_labels, voxels), static_cast<int64_t>(1L)); // can't allocate 0 arrays

DisjointSet<uint32_t> equivalences(max_labels);
DisjointSet<uint32_t> equivalences;

uint32_t* out_labels = new uint32_t[voxels]();
uint32_t next_label = 0;
Expand Down