int octsect_active(const Region R, const MathTree* tree, Region* const out) { out[0] = R; uint8_t bits = 1; const uint8_t active = active_axes(tree); if (R.nk > 1 && (active & 1)) { bisect_z(out[0], out, out+1); bits |= (bits << 1); } if (R.nj > 1 && (active & 2)) { if (bits & (1 << 0)) bisect_y(out[0], out, out+2); if (bits & (1 << 1)) bisect_y(out[1], out+1, out+3); bits |= (bits << 2); } if (R.ni > 1 && (active & 4)) { if (bits & (1 << 0)) bisect_x(out[0], out, out+4); if (bits & (1 << 1)) bisect_x(out[1], out+1, out+5); if (bits & (1 << 2)) bisect_x(out[2], out+2, out+6); if (bits & (1 << 3)) bisect_x(out[3], out+3, out+7); bits |= (bits << 4); } return bits; }
// Splits a region into up to 8 sections, returning // a bitfield with bits set where a region was stored. uint8_t octsect(const Region R, Region* const out) { out[0] = R; uint8_t bits = 1; if (R.nk > 1) { bisect_z(out[0], out, out+1); bits |= (bits << 1); } if (R.nj > 1) { if (bits & (1 << 0)) bisect_y(out[0], out, out+2); if (bits & (1 << 1)) bisect_y(out[1], out+1, out+3); bits |= (bits << 2); } if (R.ni > 1) { if (bits & (1 << 0)) bisect_x(out[0], out, out+4); if (bits & (1 << 1)) bisect_x(out[1], out+1, out+5); if (bits & (1 << 2)) bisect_x(out[2], out+2, out+6); if (bits & (1 << 3)) bisect_x(out[3], out+3, out+7); bits |= (bits << 4); } return bits; }
// Splits a region into up to 8 sections, returning // a bitfield with bits set where a region was stored. uint8_t octsect_merged(const Region R, const ASDF* const asdf, Region* const out) { out[0] = R; uint8_t bits = 1; if (asdf->branches[1] && R.nk > 1) { bisect_z(out[0], out, out+1); bits |= (bits << 1); } if (asdf->branches[2] && R.nj > 1) { if (bits & (1 << 0)) bisect_y(out[0], out, out+2); if (bits & (1 << 1)) bisect_y(out[1], out+1, out+3); bits |= (bits << 2); } if (asdf->branches[4] && R.ni > 1) { if (bits & (1 << 0)) bisect_x(out[0], out, out+4); if (bits & (1 << 1)) bisect_x(out[1], out+1, out+5); if (bits & (1 << 2)) bisect_x(out[2], out+2, out+6); if (bits & (1 << 3)) bisect_x(out[3], out+3, out+7); bits |= (bits << 4); } return bits; }
// Splits a region in two along either the x or y axis int bisect_xy(const Region r, Region* const A, Region* const B) { if (r.ni * r.nj * r.nk == 1) { *A = r; return 1; } if (r.ni >= r.nj && r.ni >= r.nk) bisect_x(r, A, B); else bisect_y(r, A, B); return 0; }