in octree/octree/contour.cpp [89:143]
bool Contour::check_subdividion(const uintk node_key, const int depth) {
// get cooridinates
int xyz[3] = {0};
octree_->key2xyz(xyz, node_key, depth);
int depth_ = octree_->info().depth();
const int scale = 1 << (depth_ - depth);
for (int c = 0; c < 3; ++c) {
xyz[c] *= scale;
}
// check 8 cornors
const uintk mask[8] = {1, 2, 4, 8, 16, 32, 64, 128};
uintk cube_case = 0, weight_case = 0;
for (int i = 0; i < 8; ++i) {
int x = xyz[0] + MarchingCube::corner_[i][0] * scale;
int y = xyz[1] + MarchingCube::corner_[i][2] * scale;
int z = xyz[2] + MarchingCube::corner_[i][2] * scale;
auto fvalue = fval(x, y, z); // pair<value, weight>
if (fvalue.first < 0) cube_case |= mask[i];
if (fvalue.second != 0) weight_case |= mask[i];
}
if (cube_case != 0 && cube_case != 255 && weight_case == 255) return true;
// check 6 faces
const int coord[6][3] = {
{xyz[0], xyz[1], xyz[2]}, {xyz[0] + scale, xyz[1], xyz[2]},
{xyz[0], xyz[1], xyz[2]}, {xyz[0], xyz[1] + scale, xyz[2]},
{xyz[0], xyz[1], xyz[2]}, {xyz[0], xyz[1], xyz[2] + scale}};
const int axis1[6][3] = {{0, 1, 0}, {0, 1, 0}, {1, 0, 0},
{1, 0, 0}, {1, 0, 0}, {1, 0, 0}};
const int axis2[6][3] = {{0, 0, 1}, {0, 0, 1}, {0, 0, 1},
{0, 0, 1}, {0, 1, 0}, {0, 1, 0}};
for (int i = 0; i < 6; ++i) {
for (int m = 0; m < scale; ++m) {
for (int n = 0; n < scale; ++n) {
uintk face_case = 0, wt_case = 0;
for (int k = 0; k < 4; ++k) {
int m1 = (k & 1) ? m + 1 : m;
int n1 = (k & 2) ? n + 1 : n;
int x = coord[i][0] + m1 * axis1[i][0] + n1 * axis2[i][0];
int y = coord[i][1] + m1 * axis1[i][1] + n1 * axis2[i][1];
int z = coord[i][2] + m1 * axis1[i][2] + n1 * axis2[i][2];
auto fvalue = fval(x, y, z); // pair<value, weight>
if (fvalue.first < 0) face_case |= mask[k];
if (fvalue.second != 0) wt_case |= mask[k];
}
if (face_case != 0 && face_case != 15 && wt_case == 15) return true;
}
}
}
return false;
}