update()

in src/engine/imgproc/Gauss.js [139:200]


  update() {
    if (this.m_needHw) {
      this.m_bilateralHw.update();
      return;
    }
    // perform slow software gauss update with portion of slices
    console.assert(this.m_z >= 0);
    console.assert(this.m_pixelsDst !== null);
    const pixelsSrc = this.m_vol.m_dataArray;

    const xDim = this.m_vol.m_xDim;
    const yDim = this.m_vol.m_yDim;
    const zDim = this.m_vol.m_zDim;
    const xyDim = xDim * yDim;

    const STEP = zDim > 16 ? 24 : 2;
    const zNext = Math.floor(((this.m_iter + 1) * zDim) / STEP);
    // console.log('Gauss update z from ' + this.m_z.toString() + ' until ' + zNext.toString());

    const arrKernel = this.m_kernel;
    const kernelSize = this.m_kernelSize;

    // update all z slices from this.m_z to zNext
    let off = this.m_z * xyDim;
    for (let z = this.m_z; z < zNext; z++) {
      for (let y = 0; y < yDim; y++) {
        for (let x = 0; x < xDim; x++) {
          // process pixel (x,y,z)
          let sum = 0.0;
          let offKer = 0;
          for (let dz = -kernelSize; dz <= +kernelSize; dz++) {
            let zz = z + dz;
            zz = zz >= 0 ? zz : 0;
            zz = zz < zDim ? zz : zDim - 1;
            const zzOff = zz * xyDim;
            for (let dy = -kernelSize; dy <= +kernelSize; dy++) {
              let yy = y + dy;
              yy = yy >= 0 ? yy : 0;
              yy = yy < yDim ? yy : yDim - 1;
              const yyOff = yy * xDim;
              for (let dx = -kernelSize; dx <= +kernelSize; dx++) {
                let xx = x + dx;
                xx = xx >= 0 ? xx : 0;
                xx = xx < xDim ? xx : xDim - 1;

                sum += arrKernel[offKer] * pixelsSrc[xx + yyOff + zzOff];
                offKer++;
              } // for dx
            } // for dy
          } // for dz
          this.m_pixelsDst[off] = sum;
          off++;
        } // for x
      } // for y
    } // for z all slices

    // console.log('max sqrt = ' + maxSqrt.toString());

    // update iteration parameters
    this.m_iter += 1;
    this.m_z = zNext;
  }