Search in sources :

Example 46 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method updateUndo.

private void updateUndo(UNDO_INIT initType) {
    // Caller of this method is going to do something that CAN be undone so save undo info
    if (initType == UNDO_INIT.ALLZ) {
        undoROIComposite = new BufferedImage[roiComposite.length];
        for (int i = 0; i < roiComposite.length; i++) {
            undoROIComposite[i] = new BufferedImage(roiComposite[0].getWidth(), roiComposite[0].getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
            System.arraycopy((byte[]) ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData(), 0, (byte[]) ((DataBufferByte) undoROIComposite[i].getRaster().getDataBuffer()).getData(), 0, roiComposite[0].getWidth() * roiComposite[0].getHeight());
        }
    }
    if (initType == UNDO_INIT.ONEZ) {
        // Some operations (paint,erase,fill) only need 1 zslice saved for undo
        if (undoROIComposite == null || undoROIComposite[overlayEditorPanelJAI.getZ()] == null) {
            undoROIComposite = new BufferedImage[roiComposite.length];
            undoROIComposite[overlayEditorPanelJAI.getZ()] = new BufferedImage(roiComposite[0].getWidth(), roiComposite[0].getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
        }
        System.arraycopy((byte[]) ((DataBufferByte) roiComposite[overlayEditorPanelJAI.getZ()].getRaster().getDataBuffer()).getData(), 0, (byte[]) ((DataBufferByte) undoROIComposite[overlayEditorPanelJAI.getZ()].getRaster().getDataBuffer()).getData(), 0, roiComposite[0].getWidth() * roiComposite[0].getHeight());
    }
}
Also used : DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage)

Example 47 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method getNonZeroBoundingBox.

private ROIMultiPaintManager.Crop3D getNonZeroBoundingBox(boolean bUseROI) {
    Rectangle bounding2D = null;
    int lowZ = Integer.MAX_VALUE;
    int highZ = -1;
    if (bUseROI) {
        int lowX = Integer.MAX_VALUE;
        int lowY = Integer.MAX_VALUE;
        int highX = -1;
        int highY = -1;
        for (int z = 0; z < roiComposite.length; z++) {
            int xyIndex = 0;
            byte[] zSectData = ((DataBufferByte) roiComposite[z].getRaster().getDataBuffer()).getData();
            for (int y = 0; y < roiComposite[0].getHeight(); y++) {
                for (int x = 0; x < roiComposite[0].getWidth(); x++) {
                    if (zSectData[xyIndex] != 0) {
                        lowX = Math.min(lowX, x);
                        lowY = Math.min(lowY, y);
                        highX = Math.max(highX, x);
                        highY = Math.max(highY, y);
                        lowZ = Math.min(lowZ, z);
                        ;
                        highZ = Math.max(highZ, z);
                    }
                    xyIndex++;
                }
            }
        }
        if (lowX != Integer.MAX_VALUE) {
            bounding2D = new Rectangle(lowX, lowY, highX - lowX + 1, highY - lowY + 1);
        }
    } else {
        UShortImage[] images = getImageDataSetChannel().getAllImages();
        for (int z = 0; z < images.length; z++) {
            Rectangle boundingRect = images[z].getNonzeroBoundingBox();
            if (boundingRect != null) {
                lowZ = Math.min(lowZ, z);
                ;
                highZ = Math.max(highZ, z);
                if (bounding2D == null) {
                    bounding2D = boundingRect;
                } else {
                    bounding2D = bounding2D.union(boundingRect);
                }
            }
        }
    }
    if (bounding2D == null) {
        return null;
    }
    ROIMultiPaintManager.Crop3D bounding3D = new ROIMultiPaintManager.Crop3D();
    bounding3D.setBounds(bounding2D.x, bounding2D.y, lowZ, bounding2D.width, bounding2D.height, highZ - lowZ + 1);
    return bounding3D;
}
Also used : Rectangle(java.awt.Rectangle) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 48 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method recoverUndo.

private void recoverUndo() {
    try {
        if (roiComposite == null || undoROIComposite == null || roiComposite.length != undoROIComposite.length) {
            throw new Exception("Undo operation has wrong undo information");
        } else {
            // Reset to last undo
            for (int i = 0; i < roiComposite.length; i++) {
                if (undoROIComposite[i] != null) {
                    if (roiComposite[i].getWidth() != undoROIComposite[i].getWidth() || roiComposite[i].getHeight() != undoROIComposite[i].getHeight()) {
                        throw new Exception("Undo operation z-slice size not match");
                    }
                    System.arraycopy((byte[]) ((DataBufferByte) undoROIComposite[i].getRaster().getDataBuffer()).getData(), 0, (byte[]) ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData(), 0, roiComposite[0].getWidth() * roiComposite[0].getHeight());
                }
            }
            undoROIComposite = null;
            overlayEditorPanelJAI.setAllROICompositeImage(roiComposite, OverlayEditorPanelJAI.FRAP_DATA_FILL_PROPERTY);
            overlayEditorPanelJAI.setHighliteInfo(null, OverlayEditorPanelJAI.FRAP_DATA_FILL_PROPERTY);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // Something is wrong, throw out undo
        undoROIComposite = null;
        System.out.println("Error: undoROIComposite inconsistent state.\n" + e.getMessage());
    }
    updateUndoAfter(false);
}
Also used : DataBufferByte(java.awt.image.DataBufferByte) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) Point(java.awt.Point)

Example 49 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method applyPixelClasses.

private void applyPixelClasses(VCPixelClass[] vcPixelClasses, Component parentComponent) {
    if (vcPixelClasses != null) {
        int backgroundIndex = -1;
        int[] pixelValMapPixelClassIndex = new int[256];
        Arrays.fill(pixelValMapPixelClassIndex, -1);
        String[][] rowData = new String[vcPixelClasses.length][1];
        for (int i = 0; i < vcPixelClasses.length; i++) {
            pixelValMapPixelClassIndex[vcPixelClasses[i].getPixel()] = i;
            rowData[i][0] = vcPixelClasses[i].getPixelClassName();
            if (vcPixelClasses[i].getPixel() == 0 && vcPixelClasses[i].getPixelClassName().equals(RESERVED_NAME_BACKGROUND)) {
                // choose background automatically
                backgroundIndex = i;
            }
        }
        // Create ROIs from VCPixelclasses
        // start 1 after background index color
        int roiCount = 1;
        int[] pixelClassIndexMaproiIndex = new int[vcPixelClasses.length];
        for (int i = 0; i < vcPixelClasses.length; i++) {
            if (i == backgroundIndex) {
                // background
                pixelClassIndexMaproiIndex[i] = 0;
                continue;
            }
            overlayEditorPanelJAI.addROIName(vcPixelClasses[i].getPixelClassName(), true, vcPixelClasses[0].getPixelClassName(), true, /*true,true,*/
            roiCount);
            pixelClassIndexMaproiIndex[i] = roiCount;
            roiCount++;
        }
        // fill in rois using pixel value and VCPixelClass mappings
        for (int zindex = 0; zindex < roiComposite.length; zindex++) {
            byte[] zdata = ((DataBufferByte) roiComposite[zindex].getRaster().getDataBuffer()).getData();
            UShortImage uShortImage = initImageDataSetChannels[0].getImage(zindex, 0, 0);
            for (int xyindex = 0; xyindex < zdata.length; xyindex++) {
                // unsigned short
                int pixelval = uShortImage.getPixels()[xyindex] & 0x000000FF;
                zdata[xyindex] = (byte) pixelClassIndexMaproiIndex[pixelValMapPixelClassIndex[pixelval]];
            }
        }
    }
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 50 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method askApplyHighlightToROI.

private boolean askApplyHighlightToROI() {
    UShortImage[] roiZ = overlayEditorPanelJAI.getHighliteInfo().getRoiImages();
    boolean bOverWrite = true;
    // Check for existing ROI
    final String OVERWRITE_ALL = "Overwrite any existing Domain Regionss";
    final String KEEP_EXISTING = "Keep existing Domain Regions when overlapping";
    final String CANCEL_ROI_UPDATE = "Cancel";
    // boolean bHadAny = false;
    for (int i = 0; i < roiZ.length; i++) {
        boolean bDone = false;
        short[] pixels = roiZ[i].getPixels();
        byte[] compositePixels = ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData();
        for (int j = 0; j < compositePixels.length; j++) {
            // bHadAny|= pixels[j] != 0;
            if (compositePixels[j] != 0 && pixels[j] != 0) /* && compositePixels[j] != (byte)roiColorIndex*/
            {
                bDone = true;
                String result = DialogUtils.showWarningDialog(overlayEditorPanelJAI, "Some areas of the new Domain Regions overlap with existing Domain Regions.", new String[] { OVERWRITE_ALL, KEEP_EXISTING, CANCEL_ROI_UPDATE }, OVERWRITE_ALL);
                if (result.equals(KEEP_EXISTING)) {
                    bOverWrite = false;
                } else if (result.equals(CANCEL_ROI_UPDATE)) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
                break;
            }
        }
        if (bDone) {
            break;
        }
    }
    return bOverWrite;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Aggregations

DataBufferByte (java.awt.image.DataBufferByte)64 BufferedImage (java.awt.image.BufferedImage)38 Point (java.awt.Point)36 WritableRaster (java.awt.image.WritableRaster)18 DataBufferInt (java.awt.image.DataBufferInt)14 DataBuffer (java.awt.image.DataBuffer)13 DataBufferShort (java.awt.image.DataBufferShort)10 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)8 Rectangle (java.awt.Rectangle)8 SampleModel (java.awt.image.SampleModel)8 DataBufferUShort (java.awt.image.DataBufferUShort)7 IndexColorModel (java.awt.image.IndexColorModel)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 Graphics2D (java.awt.Graphics2D)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 UserCancelException (org.vcell.util.UserCancelException)6 UtilCancelException (org.vcell.util.UtilCancelException)6 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)5 Hashtable (java.util.Hashtable)5 VCImage (cbit.image.VCImage)4