floodFill3d()

in src/engine/actvolume/floodfill.js [120:216]


  floodFill3d(xDim, yDim, zDim, pixels, vSeed) {
    const xyDim = xDim * yDim;
    const okCreate = this.createStack3d(xDim * yDim * zDim);
    if (okCreate !== 1) {
      return okCreate;
    }

    const VIS = 255;
    this.m_numFilled3d = 0;

    this.stack3dPush(vSeed);
    while (!this.stack3dEIsEmpty()) {
      let x;

      const vTaken = this.stack3dPop();
      const y = vTaken.y;
      const z = vTaken.z;

      const yOff = y * xDim;
      const zOff = z * xyDim;

      // get leftmost
      for (x = vTaken.x; x >= 0 && pixels[x + yOff + zOff] === 0; ) {
        x--;
      }
      const xL = x + 1;
      // get rightmost
      for (x = vTaken.x; x < xDim && pixels[x + yOff + zOff] === 0; ) {
        x++;
      }
      const xR = x - 1;

      let setYLess = VIS;
      let setYMore = VIS;
      let setZLess = VIS;
      let setZMore = VIS;
      for (x = xL; x <= xR; x++) {
        // set point visible
        pixels[x + yOff + zOff] = VIS;
        this.m_numFilled3d++;

        // check line y less
        if (y > 0 && pixels[x + yOff - xDim + zOff] !== setYLess) {
          setYLess = VIS - setYLess;
          if (setYLess === 0) {
            // V3d vPu(x, y - 1, z);
            const vPu = new THREE.Vector3(x, y - 1, z);
            const okPush = this.stack3dPush(vPu);
            if (okPush !== 1) {
              return okPush;
            }
          } // if need to push
        } // if (y less pint has another vis state

        // check line above
        if (y < yDim - 1 && pixels[x + yOff + xDim + zOff] !== setYMore) {
          setYMore = VIS - setYMore;
          if (setYMore === 0) {
            // V3d vPu(x, y + 1, z);
            const vPu = new THREE.Vector3(x, y + 1, z);
            const okPush = this.stack3dPush(vPu);
            if (okPush !== 1) {
              return okPush;
            }
          } // if need to push
        } // if (y more point has another vis state

        // check line z less
        if (z > 0 && pixels[x + yOff + zOff - xyDim] !== setZLess) {
          setZLess = VIS - setZLess;
          if (setZLess === 0) {
            // V3d vPu(x, y, z - 1);
            const vPu = new THREE.Vector3(x, y, z - 1);
            const okPush = this.stack3dPush(vPu);
            if (okPush !== 1) {
              return okPush;
            }
          } // if need to push
        } // if (z less pint has another vis state

        // check line z more
        if (z < zDim - 1 && pixels[x + yOff + zOff + xyDim] !== setZMore) {
          setZMore = VIS - setZMore;
          if (setZMore === 0) {
            // V3d vPu(x, y, z + 1);
            const vPu = new THREE.Vector3(x, y, z + 1);
            const okPush = this.stack3dPush(vPu);
            if (okPush !== 1) {
              return okPush;
            }
          } // if need to push
        } // if (z more)
      } // for (x) scanned hor line
    } // while stack is not empty
    this.destroyStack3d();
    return 1;
  }