Page MenuHome
Paste P2275

(An Untitled Masterwork)
ActivePublic

Authored by Erik Abrahamsson (erik85) on Thu, Jul 22, 6:14 PM.
void extrapolateLsSimple(Grid<Real> &phi, int distance = 4, bool inside = false)
{
Grid<int> tmp(phi.getParent());
tmp.clear();
const int dim = (phi.is3D() ? 3 : 2);
// by default, march outside
Real direction = 1.;
if (!inside) {
// mark all inside
FOR_IJK_BND(phi, 1)
{
if (phi(i, j, k) < 0.) {
tmp(i, j, k) = 1;
}
}
}
else {
direction = -1.;
FOR_IJK_BND(phi, 1)
{
if (phi(i, j, k) > 0.) {
tmp(i, j, k) = 1;
}
}
}
const int k_start = (phi.is3D() ? 1 : 0);
const int __kmax = (phi.is3D() ? (phi.getSizeZ() - 1) : 1);
// + first layer around
tbb::parallel_for(tbb::blocked_range<IndexInt>(k_start, __kmax), [&](const tbb::blocked_range<IndexInt>& r) {
for (int k=r.begin(); k<r.end(); ++k) {
for (int j = 1; j < phi.getSizeY() - 1; j++) {
for (int i = 1; i < phi.getSizeX() - 1; i++)
{
Vec3i p(i, j, k);
if (tmp(p))
continue;
for (int n = 0; n < 2 * dim; ++n) {
if (tmp(p + nb[n]) == 1) {
tmp(i, j, k) = 2;
n = 2 * dim;
}
}
}
}
}
});
// extrapolate for distance
for (int d = 2; d < 1 + distance; ++d) {
knExtrapolateLsSimple<Real>(phi, distance, tmp, d, direction);
}
// set all remaining cells to max
knSetRemaining<Real>(phi, tmp, Real(direction * (distance + 2)));
}

Event Timeline

Erik Abrahamsson (erik85) updated the paste's language from autodetect to cpp.Thu, Jul 22, 6:30 PM
Erik Abrahamsson (erik85) edited the content of this paste. (Show Details)