applyPartGaussSmooth()

in src/engine/actvolume/actvol.js [591:658]


  applyPartGaussSmooth(zStart, zEnd, rad, sigma) {
    const TWICE = 2;
    const dia = 1 + TWICE * rad;
    // fill gauss matrix
    const THREE_DIMS = 3.0;
    const koef = 1.0 / (THREE_DIMS * sigma * sigma);
    let dx, dy, dz;
    let j = 0;
    if (zStart === 0) {
      const GAUSS_MAX_RAD = 9;
      const GAUSS_MAX_DIA = 1 + TWICE * GAUSS_MAX_RAD;
      this.m_gaussMatrix = new Float32Array(GAUSS_MAX_DIA * GAUSS_MAX_DIA * GAUSS_MAX_DIA);
      let wSum = 0.0;
      for (dz = -rad; dz <= +rad; dz++) {
        const fz = dz / rad;
        for (dy = -rad; dy <= +rad; dy++) {
          const fy = dy / rad;
          for (dx = -rad; dx <= +rad; dx++) {
            const fx = dx / rad;
            const dist2 = fx * fx + fy * fy + fz * fz;
            const weight = Math.exp(-1.0 * dist2 * koef);
            this.m_gaussMatrix[j++] = weight;
            wSum += weight;
          }
        }
      } // for (dz)
      // normalize weights
      const numGaussElems = dia * dia * dia;
      const gScale = 1.0 / wSum;
      for (j = 0; j < numGaussElems; j++) {
        this.m_gaussMatrix[j] *= gScale;
      }
      const numPixels = this.m_xDim * this.m_yDim * this.m_zDim;
      for (j = 0; j < numPixels; j++) {
        this.m_imageGauss[j] = this.m_imageSrc[j];
      }
    }
    // apply gauss matrix to source image
    const zs = zStart > rad ? zStart : rad;
    const ze = zEnd < this.m_zDim - rad ? zEnd : this.m_zDim - rad;
    let cx, cy, cz;
    for (cz = zs; cz < ze; cz++) {
      const czOff = cz * this.m_xDim * this.m_yDim;
      for (cy = rad; cy < this.m_yDim - rad; cy++) {
        const cyOff = cy * this.m_xDim;
        for (cx = rad; cx < this.m_xDim - rad; cx++) {
          let sum = 0.0;
          j = 0;
          for (dz = -rad; dz <= +rad; dz++) {
            const z = cz + dz;
            const zOff = z * this.m_xDim * this.m_yDim;
            for (dy = -rad; dy <= +rad; dy++) {
              const y = cy + dy;
              const yOff = y * this.m_xDim;
              for (dx = -rad; dx <= +rad; dx++) {
                const x = cx + dx;
                const weight = this.m_gaussMatrix[j++];
                const val = this.m_imageSrc[x + yOff + zOff];
                sum += val * weight;
              } // for (dx)
            } // for (dy)
          } // for (dz)
          this.m_imageGauss[cx + cyOff + czOff] = sum;
          // this.m_imageGauss[cx + cyOff + czOff] = 0.0;
        } // for (cx)
      } // for (cy)
    } // for (cz)
  }