@@ -192,7 +192,17 @@ OUT* connected_components3d_26_binary(
192192 }
193193 else if (y < sy - 1 && z > 0 && in_labels[loc + H]) {
194194 out_labels[loc] = out_labels[loc + H];
195- unify2d_ac<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
195+
196+ if (x > 0 && y > 0 && in_labels[loc - 1 - sx]) {
197+ equivalences.unify (out_labels[loc], out_labels[loc - 1 - sx]);
198+
199+ if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx] && !(y > 1 && in_labels[loc - sx - sx])) {
200+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
201+ }
202+ }
203+ else if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx]) {
204+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
205+ }
196206
197207 if (x > 0 && y > 0 && z > 0 && in_labels[loc + A]) {
198208 equivalences.unify (out_labels[loc], out_labels[loc + A]);
@@ -203,7 +213,13 @@ OUT* connected_components3d_26_binary(
203213 }
204214 else if (x < sx - 1 && z > 0 && in_labels[loc + F]) {
205215 out_labels[loc] = out_labels[loc + F];
206- unify2d_lt<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
216+
217+ if (x > 0 && in_labels[loc - 1 ]) {
218+ equivalences.unify (out_labels[loc], out_labels[loc - 1 ]);
219+ }
220+ else if (x > 0 && y > 0 && in_labels[loc - 1 - sx]) {
221+ equivalences.unify (out_labels[loc], out_labels[loc - 1 - sx]);
222+ }
207223
208224 if (x > 0 && y > 0 && z > 0 && in_labels[loc + A]) {
209225 equivalences.unify (out_labels[loc], out_labels[loc + A]);
@@ -214,7 +230,10 @@ OUT* connected_components3d_26_binary(
214230 }
215231 else if (x > 0 && y > 0 && z > 0 && in_labels[loc + A]) {
216232 out_labels[loc] = out_labels[loc + A];
217- unify2d_rt<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
233+
234+ if (x < sx - 1 && y > 0 && in_labels[loc + L]) {
235+ equivalences.unify (out_labels[loc], out_labels[loc + L]);
236+ }
218237
219238 if (x < sx - 1 && y > 0 && z > 0 && in_labels[loc + C]) {
220239 equivalences.unify (out_labels[loc], out_labels[loc + C]);
@@ -228,7 +247,14 @@ OUT* connected_components3d_26_binary(
228247 }
229248 else if (x < sx - 1 && y > 0 && z > 0 && in_labels[loc + C]) {
230249 out_labels[loc] = out_labels[loc + C];
231- unify2d_lt<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
250+
251+ if (x > 0 && in_labels[loc - 1 ]) {
252+ equivalences.unify (out_labels[loc], out_labels[loc - 1 ]);
253+ }
254+ else if (x > 0 && y > 0 && in_labels[loc - 1 - sx]) {
255+ equivalences.unify (out_labels[loc], out_labels[loc - 1 - sx]);
256+ }
257+
232258
233259 if (x > 0 && y < sy - 1 && z > 0 && in_labels[loc + G]) {
234260 equivalences.unify (out_labels[loc], out_labels[loc + G]);
@@ -239,15 +265,35 @@ OUT* connected_components3d_26_binary(
239265 }
240266 else if (x > 0 && y < sy - 1 && z > 0 && in_labels[loc + G]) {
241267 out_labels[loc] = out_labels[loc + G];
242- unify2d_ac<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
268+
269+ if (x > 0 && y > 0 && in_labels[loc - 1 - sx]) {
270+ equivalences.unify (out_labels[loc], out_labels[loc - 1 - sx]);
271+
272+ if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx] && !(y > 1 && in_labels[loc - sx - sx])) {
273+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
274+ }
275+ }
276+ else if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx]) {
277+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
278+ }
243279
244280 if (x < sx - 1 && y < sy - 1 && z > 0 && in_labels[loc + I]) {
245281 equivalences.unify (out_labels[loc], out_labels[loc + I]);
246282 }
247283 }
248284 else if (x < sx - 1 && y < sy - 1 && z > 0 && in_labels[loc + I]) {
249285 out_labels[loc] = out_labels[loc + I];
250- unify2d_ac<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
286+
287+ if (x > 0 && y > 0 && in_labels[loc - 1 - sx]) {
288+ equivalences.unify (out_labels[loc], out_labels[loc - 1 - sx]);
289+
290+ if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx] && !(y > 1 && in_labels[loc - sx - sx])) {
291+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
292+ }
293+ }
294+ else if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx]) {
295+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
296+ }
251297 }
252298 // It's the original 2D problem now
253299 else if (y > 0 && in_labels[loc + K]) {
@@ -407,7 +453,28 @@ OUT* connected_components3d_18_binary(
407453 }
408454 else if (y < sy - 1 && z > 0 && in_labels[loc + H]) {
409455 out_labels[loc] = out_labels[loc + H];
410- unify2d<T>(loc, cur, x, y, sx, sy, in_labels, out_labels, equivalences);
456+
457+ if (y > 0 && in_labels[loc - sx]) {
458+ equivalences.unify (out_labels[loc], out_labels[loc - sx]);
459+ }
460+ else if (x > 0 && in_labels[loc - 1 ]) {
461+ equivalences.unify (out_labels[loc], out_labels[loc - 1 ]);
462+
463+ if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx]) {
464+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
465+ }
466+ }
467+ else if (x > 0 && y > 0 && in_labels[loc - 1 - sx]) {
468+ equivalences.unify (out_labels[loc], out_labels[loc - 1 - sx]);
469+
470+ if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx]) {
471+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
472+ }
473+ }
474+ else if (x < sx - 1 && y > 0 && in_labels[loc + 1 - sx]) {
475+ equivalences.unify (out_labels[loc], out_labels[loc + 1 - sx]);
476+ }
477+
411478 }
412479 // It's the original 2D problem now
413480 else if (y > 0 && in_labels[loc + K]) {
0 commit comments