function mapCanvasToData() {
    for (let i = ijkBBox[0]; i < ijkBBox[1] + 1; i++) {
      for (let j = ijkBBox[2]; j < ijkBBox[3] + 1; j++) {
        for (let k = ijkBBox[4]; k < ijkBBox[5] + 1; k++) {
          // ijk to world
          // center of voxel
          let worldCoordinate = new THREE.Vector3(i, j, k).applyMatrix4(stack2._ijk2LPS);
          // world to screen coordinate
          let screenCoordinates = worldCoordinate.clone();
          screenCoordinates.project(camera);

          screenCoordinates.x = Math.round(((screenCoordinates.x + 1) * canvas.offsetWidth) / 2);
          screenCoordinates.y = Math.round(((-screenCoordinates.y + 1) * canvas.offsetHeight) / 2);
          screenCoordinates.z = 0;

          let pixel = context.getImageData(screenCoordinates.x, screenCoordinates.y, 1, 1).data;
          if (pixel[3] > 0 && i >= 0 && j >= 0 && k >= 0) {
            // find index and texture
            let voxelIndex = i + j * stack2._columns + k * stack2._rows * stack2._columns;

            let textureSize = 4096;
            let textureDimension = textureSize * textureSize;

            let rawDataIndex = ~~(voxelIndex / textureDimension);
            let inRawDataIndex = voxelIndex % textureDimension;

            // update value...
            let oldValue = stack2.rawData[rawDataIndex][inRawDataIndex];
            let newValue = cursor.value;

            if (oldValue != newValue) {
              // update raw data
              stack2.rawData[rawDataIndex][inRawDataIndex] = newValue;

              // update texture that is passed to shader
              textures2[rawDataIndex].image.data = stack2.rawData[rawDataIndex]; // tex;
              textures2[rawDataIndex].needsUpdate = true;

              // update stats
              editorStats[oldValue] -= 1;
              editorStats[newValue] += 1;
            }
          }
        }
      }
    }
  }
function mapCanvasToData() {
    for (let i = ijkBBox[0]; i < ijkBBox[1] + 1; i++) {
      for (let j = ijkBBox[2]; j < ijkBBox[3] + 1; j++) {
        for (let k = ijkBBox[4]; k < ijkBBox[5] + 1; k++) {
          
          
          let worldCoordinate = new THREE.Vector3(i, j, k).applyMatrix4(stack2._ijk2LPS);
          
          let screenCoordinates = worldCoordinate.clone();
          screenCoordinates.project(camera);

          screenCoordinates.x = Math.round(((screenCoordinates.x + 1) * canvas.offsetWidth) / 2);
          screenCoordinates.y = Math.round(((-screenCoordinates.y + 1) * canvas.offsetHeight) / 2);
          screenCoordinates.z = 0;

          let pixel = context.getImageData(screenCoordinates.x, screenCoordinates.y, 1, 1).data;
          if (pixel[3] > 0 && i >= 0 && j >= 0 && k >= 0) {
            
            let voxelIndex = i + j * stack2._columns + k * stack2._rows * stack2._columns;

            let textureSize = 4096;
            let textureDimension = textureSize * textureSize;

            let rawDataIndex = ~~(voxelIndex / textureDimension);
            let inRawDataIndex = voxelIndex % textureDimension;

            
            let oldValue = stack2.rawData[rawDataIndex][inRawDataIndex];
            let newValue = cursor.value;

            if (oldValue != newValue) {
              
              stack2.rawData[rawDataIndex][inRawDataIndex] = newValue;

              
              textures2[rawDataIndex].image.data = stack2.rawData[rawDataIndex]; 
              textures2[rawDataIndex].needsUpdate = true;

              
              editorStats[oldValue] -= 1;
              editorStats[newValue] += 1;
            }
          }
        }
      }
    }
  }
function mapCanvasToData ( ) { for ( let i = ijkBBox [ 0 ] ; i < ijkBBox [ 1 ] + 1 ; i ++ ) { for ( let j = ijkBBox [ 2 ] ; j < ijkBBox [ 3 ] + 1 ; j ++ ) { for ( let k = ijkBBox [ 4 ] ; k < ijkBBox [ 5 ] + 1 ; k ++ ) { // ijk to world // center of voxel let worldCoordinate = new THREE . Vector3 ( i , j , k ) . applyMatrix4 ( stack2 . _ijk2LPS ) ; // world to screen coordinate let screenCoordinates = worldCoordinate . clone ( ) ; screenCoordinates . project ( camera ) ; screenCoordinates . x = Math . round ( ( ( screenCoordinates . x + 1 ) * canvas . offsetWidth ) / 2 ) ; screenCoordinates . y = Math . round ( ( ( - screenCoordinates . y + 1 ) * canvas . offsetHeight ) / 2 ) ; screenCoordinates . z = 0 ; let pixel = context . getImageData ( screenCoordinates . x , screenCoordinates . y , 1 , 1 ) . data ; if ( pixel [ 3 ] > 0 && i >= 0 && j >= 0 && k >= 0 ) { // find index and texture let voxelIndex = i + j * stack2 . _columns + k * stack2 . _rows * stack2 . _columns ; let textureSize = 4096 ; let textureDimension = textureSize * textureSize ; let rawDataIndex = ~ ~ ( voxelIndex / textureDimension ) ; let inRawDataIndex = voxelIndex % textureDimension ; // update value... let oldValue = stack2 . rawData [ rawDataIndex ] [ inRawDataIndex ] ; let newValue = cursor . value ; if ( oldValue != newValue ) { // update raw data stack2 . rawData [ rawDataIndex ] [ inRawDataIndex ] = newValue ; // update texture that is passed to shader textures2 [ rawDataIndex ] . image . data = stack2 . rawData [ rawDataIndex ] ; // tex; textures2 [ rawDataIndex ] . needsUpdate = true ; // update stats editorStats [ oldValue ] -= 1 ; editorStats [ newValue ] += 1 ; } } } } } }
Loop through IJK BBox and see if voxel can be mapped to screen
Loop through IJK BBox and see if voxel can be mapped to screen