static extract2dSliceFrom3dTexture()

in src/engine/loaders/voltools.js [576:656]


  static extract2dSliceFrom3dTexture(xDim, yDim, zDim, pixelsSrc, sliceType, sliceIndex, pixelsDst) {
    const BYTES_IN_DWORD = 4;
    const numPixVol = xDim * yDim * zDim;
    if (numPixVol * BYTES_IN_DWORD !== pixelsSrc.length) {
      console.log(`!!! wrong volume texture size: ${numPixVol}`);
    }
    const X_SLICE = 0;
    const Y_SLICE = 1;
    const Z_SLICE = 2;
    const OFF_0 = 0;
    const OFF_1 = 1;
    const OFF_2 = 2;
    const OFF_3 = 3;
    const VAL255 = 255;
    if (sliceType === X_SLICE) {
      const x = sliceIndex;
      console.log(`x slice is: ${x} from ${xDim}*${yDim}*${zDim} volume`);
      const w = yDim;
      const h = zDim;
      let cx, cy;
      let j = 0;
      for (cy = 0; cy < h; cy++) {
        const zOff = cy * xDim * yDim;
        for (cx = 0; cx < w; cx++) {
          const yOff = cx * xDim;
          const off = zOff + yOff + x;
          const off4 = off * BYTES_IN_DWORD;
          pixelsDst[j + OFF_0] = pixelsSrc[off4 + OFF_0];
          pixelsDst[j + OFF_1] = pixelsSrc[off4 + OFF_1];
          pixelsDst[j + OFF_2] = pixelsSrc[off4 + OFF_2];
          pixelsDst[j + OFF_3] = VAL255;
          j += BYTES_IN_DWORD;
        } // for (x)
      } // for (y)
    } // if x slice

    if (sliceType === Y_SLICE) {
      const y = sliceIndex;
      const yOff = y * xDim;
      console.log(`y slice is: ${y} from ${xDim}*${yDim}*${zDim} volume`);
      const w = xDim;
      const h = zDim;
      let cx, cy;
      let j = 0;
      for (cy = 0; cy < h; cy++) {
        const zOff = cy * xDim * yDim;
        for (cx = 0; cx < w; cx++) {
          const xOff = cx;
          const off = zOff + yOff + xOff;
          const off4 = off * BYTES_IN_DWORD;
          pixelsDst[j + OFF_0] = pixelsSrc[off4 + OFF_0];
          pixelsDst[j + OFF_1] = pixelsSrc[off4 + OFF_1];
          pixelsDst[j + OFF_2] = pixelsSrc[off4 + OFF_2];
          pixelsDst[j + OFF_3] = VAL255;
          j += BYTES_IN_DWORD;
        } // for (x)
      } // for (y)
    } // if x slice

    if (sliceType === Z_SLICE) {
      const z = sliceIndex;
      console.log(`z slice is: ${z} from ${xDim}*${yDim}*${zDim} volume`);
      const zOff = z * xDim * yDim;
      const w = xDim;
      const h = yDim;
      let x, y;
      let j = 0;
      for (y = 0; y < h; y++) {
        const yOff = y * xDim;
        for (x = 0; x < w; x++) {
          const off = zOff + yOff + x;
          const off4 = off * BYTES_IN_DWORD;
          pixelsDst[j + OFF_0] = pixelsSrc[off4 + OFF_0];
          pixelsDst[j + OFF_1] = pixelsSrc[off4 + OFF_1];
          pixelsDst[j + OFF_2] = pixelsSrc[off4 + OFF_2];
          pixelsDst[j + OFF_3] = VAL255;
          j += BYTES_IN_DWORD;
        } // for (x)
      } // for (y)
    } // if z slice
  } // end of extract2dSliceFrom3dTexture