Search in sources :

Example 6 with RegionInfo

use of cbit.vcell.geometry.RegionImage.RegionInfo in project vcell by virtualcell.

the class ROIAssistPanel method resolveCurrentROI.

private void resolveCurrentROI() {
    final String CELL_ROI = "CELL_ROI";
    AsynchClientTask keepRegionsTask = new AsynchClientTask("Pick Region", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // TODO Auto-generated method stub
            RegionInfo[] keepRegionInfos = pickKeepRegionInfoFromCurrentROI();
            if (keepRegionInfos == null) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            // dataToThreshold.getCurrentlyDisplayedROI().getPixelsXYZ();
            short[] keepPixels = new short[dataToThreshold.getCurrentlyDisplayedROI().getISize().getXYZ()];
            for (int i = 0; i < keepPixels.length; i++) {
                for (int j = 0; j < keepRegionInfos.length; j++) {
                    if (keepRegionInfos[j].isIndexInRegion(i)) {
                        keepPixels[i] = 1;
                    }
                }
            }
            UShortImage ushortImage = new UShortImage(keepPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
            ROI newCellROI = new ROI(ushortImage, originalROI.getROIName());
            hashTable.put(CELL_ROI, newCellROI);
        }
    };
    AsynchClientTask updateDisplayTask = new AsynchClientTask("Updating display", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            dataToThreshold.addReplaceRoi((ROI) hashTable.get(CELL_ROI));
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { keepRegionsTask, updateDisplayTask }, false, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 7 with RegionInfo

use of cbit.vcell.geometry.RegionImage.RegionInfo in project vcell by virtualcell.

the class ROIMultiPaintManager method generateHighlightROIInfo.

private static HighlightROIInfo generateHighlightROIInfo(byte debugValue, BufferedImage[] roiArr, RegionImage regionImage, RegionAction regionAction, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    HighlightROIInfo highlightROIInfo = new HighlightROIInfo();
    // Create lookup map to speedup highlighting operation for large dataset
    RegionImage.RegionInfo[] selectedRegionMap = new RegionImage.RegionInfo[regionAction.getAllRegionInfos().length];
    Iterator<RegionImage.RegionInfo> selectedIter = regionAction.getSelectedRegionInfos().iterator();
    while (selectedIter.hasNext()) {
        RegionImage.RegionInfo nextRegion = selectedIter.next();
        selectedRegionMap[nextRegion.getRegionIndex()] = nextRegion;
    }
    byte[] shortEncodedRegionIndexes = regionImage.getShortEncodedRegionIndexImage();
    final int XSIZE = roiArr[0].getWidth();
    if (regionAction.getAction() == RegionAction.REGION_ACTION_HIGHLIGHT) {
        highlightROIInfo.highlightROI = createEmptyROI(new ISize(roiArr[0].getWidth(), roiArr[0].getHeight(), roiArr.length));
    }
    int allIndex = 0;
    final int ZMAX = roiArr.length - 1;
    final int XMAX = roiArr[0].getWidth() - 1;
    final int YMAX = roiArr[0].getHeight() - 1;
    for (int z = 0; z < roiArr.length; z++) {
        if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
            return null;
        }
        int index = 0;
        byte[] zSlice = ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData();
        for (int y = 0; y < roiArr[0].getHeight(); y++) {
            for (int x = 0; x < XSIZE; x++) {
                int regionIndex = (shortEncodedRegionIndexes[allIndex] & 0x000000FF) | (shortEncodedRegionIndexes[allIndex + 1] & 0x000000FF) << 8;
                if (selectedRegionMap[regionIndex] != null) {
                    RegionInfo currentRegionInfo = selectedRegionMap[regionIndex];
                    if (regionAction.getAction() == RegionAction.REGION_ACTION_CHECKNEIGHBORSONLY) {
                        // Find neighbors
                        int[] neighbors = new int[6];
                        Arrays.fill(neighbors, -1);
                        if (z > 0) {
                            // top neighbor
                            neighbors[0] = 0x000000FF & ((DataBufferByte) roiArr[z - 1].getRaster().getDataBuffer()).getData()[index];
                        }
                        if (z < ZMAX) {
                            // bottom neighbor
                            neighbors[1] = 0x000000FF & ((DataBufferByte) roiArr[z + 1].getRaster().getDataBuffer()).getData()[index];
                        }
                        if (x > 0) {
                            // left neighbor
                            neighbors[2] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index - 1];
                        }
                        if (x < XMAX) {
                            // right neighbor
                            neighbors[3] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index + 1];
                        }
                        if (y > 0) {
                            // front neighbor
                            neighbors[4] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index - XSIZE];
                        }
                        if (y < YMAX) {
                            // back neighbor
                            neighbors[5] = 0x000000FF & ((DataBufferByte) roiArr[z].getRaster().getDataBuffer()).getData()[index + XSIZE];
                        }
                        if (!highlightROIInfo.neighborsForRegionsMap.containsKey(currentRegionInfo)) {
                            highlightROIInfo.neighborsForRegionsMap.put(currentRegionInfo, new TreeSet<Integer>());
                        }
                        TreeSet<Integer> neighborTreeSet = highlightROIInfo.neighborsForRegionsMap.get(currentRegionInfo);
                        for (int i = 0; i < neighbors.length; i++) {
                            if (neighbors[i] != -1 && neighbors[i] != currentRegionInfo.getPixelValue()) {
                                neighborTreeSet.add(neighbors[i]);
                            }
                        }
                        if (!highlightROIInfo.coordIndexForRegionsMap.containsKey(currentRegionInfo)) {
                            highlightROIInfo.coordIndexForRegionsMap.put(currentRegionInfo, new CoordinateIndex(x, y, z));
                        }
                    } else if (regionAction.getAction() == RegionAction.REGION_ACTION_HIGHLIGHT) {
                        highlightROIInfo.highlightROI.getRoiImages()[z].getPixels()[index] = 1;
                    } else if (regionAction.getAction() == RegionAction.REGION_ACTION_MERGESELECTEDWITHNEIGHBORS) {
                        int numNeighbors = regionAction.getNeighborsForRegionMap().get(currentRegionInfo).size();
                        if (/*!regionAction.bLeaveMultiNeighborUnchanged || */
                        numNeighbors == 1) {
                            zSlice[index] = (byte) regionAction.getNeighborsForRegionMap().get(currentRegionInfo).first().intValue();
                        } else {
                            boolean hasBG = false;
                            Integer randomNeighbor = null;
                            Iterator<Integer> pixelValIter = regionAction.getNeighborsForRegionMap().get(currentRegionInfo).iterator();
                            while (pixelValIter.hasNext()) {
                                Integer pixelValue = pixelValIter.next();
                                if (pixelValue == 0) {
                                    hasBG = true;
                                    break;
                                } else {
                                    randomNeighbor = pixelValue;
                                }
                            }
                            if (hasBG) {
                                // merge with background
                                zSlice[index] = 0;
                            } else {
                                // merge with random
                                zSlice[index] = randomNeighbor.byteValue();
                            }
                        }
                    }
                }
                index++;
                allIndex += 2;
            }
        }
    }
    return highlightROIInfo;
}
Also used : RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) ISize(org.vcell.util.ISize) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DataBufferByte(java.awt.image.DataBufferByte) CoordinateIndex(org.vcell.util.CoordinateIndex) Point(java.awt.Point) RegionImage(cbit.vcell.geometry.RegionImage)

Example 8 with RegionInfo

use of cbit.vcell.geometry.RegionImage.RegionInfo in project vcell by virtualcell.

the class ROIMultiPaintManager method pickImgROI.

private void pickImgROI(SelectImgInfo selectImgInfo) {
    int[] mapOrigToSort = new int[sortedRegionInfos.length];
    for (int i = 0; i < mapOrigToSort.length; i++) {
        mapOrigToSort[sortedRegionInfos[i].getRegionIndex()] = i;
    }
    RegionInfo[] sortedSelectedRegionInfos = Arrays.asList(selectImgInfo.getResolvedList().getSelectedValues()).toArray(new RegionInfo[0]);
    Arrays.sort(sortedSelectedRegionInfos, regionInfoComparator);
    // (B_DISPLAY_ZERO_INDEX_Z?overlayEditorPanelJAI.getZ():overlayEditorPanelJAI.getZ()-1);
    int z = overlayEditorPanelJAI.getZ();
    // RegionInfo[] regionInfoSortedByRegionIndex = regionImage.getRegionInfos();
    for (int height = 0; height <= selectImgInfo.getRectangle().height; height++) {
        // (int)(selectImgInfo.getMouseEvent().getPoint().getY()/selectImgInfo.getZoom());
        int y = selectImgInfo.getRectangle().y + height;
        for (int width = 0; width <= selectImgInfo.getRectangle().width; width++) {
            // (int)(selectImgInfo.getMouseEvent().getPoint().getX()/selectImgInfo.getZoom());
            int x = selectImgInfo.getRectangle().x + width;
            if (x < 0 || x >= roiComposite[0].getWidth() || y < 0 || y >= roiComposite[0].getHeight()) {
                return;
            }
            int currentIndex = (z * roiComposite[0].getWidth() * roiComposite[0].getHeight()) + (roiComposite[0].getWidth() * y) + x;
            RegionInfo foundRegion = regionImage.getRegionInfoFromOffset(currentIndex);
            int foundsortIndex = Arrays.binarySearch(sortedSelectedRegionInfos, foundRegion, regionInfoComparator);
            boolean isAlreadySelected = (foundsortIndex >= 0);
            if (isAlreadySelected && selectImgInfo.isIgnoreIfSelected()) {
                return;
            }
            // if(SwingUtilities.isLeftMouseButton(selectImgInfo.getMouseEvent())){
            if (selectImgInfo.getMouseEvent().isControlDown()) {
                if (isAlreadySelected) {
                    overlayEditorPanelJAI.resolvedSelectionChange(SELECT_FUNC.REMOVE, mapOrigToSort[foundRegion.getRegionIndex()]);
                } else {
                    overlayEditorPanelJAI.resolvedSelectionChange(SELECT_FUNC.ADD, mapOrigToSort[foundRegion.getRegionIndex()]);
                }
            } else {
                overlayEditorPanelJAI.resolvedSelectionChange(SELECT_FUNC.REPLACE, mapOrigToSort[foundRegion.getRegionIndex()]);
            }
        // }
        }
    }
}
Also used : RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) Point(java.awt.Point)

Example 9 with RegionInfo

use of cbit.vcell.geometry.RegionImage.RegionInfo in project vcell by virtualcell.

the class ROIMultiPaintManager method mergeResolvedSelections.

private void mergeResolvedSelections(final RegionInfo[] selectedRegionInfos) throws Exception {
    if (selectedRegionInfos == null || selectedRegionInfos.length == 0) {
        return;
    }
    // final String UNUSED_ROI_PIXVAL = "UNUSED_ROI_INDEX";
    // final String MULTI_NEIGHBOR_MERGE = "MultiNeighborMerge";
    AsynchClientTask mergeTask = new AsynchClientTask("Merging " + selectedRegionInfos.length + " regions...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // make new RegionImage with all selections converted to a single temporary ROI
            // 
            // if(isROINameUsed(overlayEditorPanelJAI.getAllCompositeROINamesAndColors(), MULTI_NEIGHBOR_MERGE)){
            // throw new Exception(MULTI_NEIGHBOR_MERGE+" exists, they must be reconciled before any new merge");
            // }
            // sort selected region index for fast lookup
            TreeSet<Integer> selectedRegionIndexesTS = new TreeSet<Integer>();
            for (int i = 0; i < selectedRegionInfos.length; i++) {
                selectedRegionIndexesTS.add(selectedRegionInfos[i].getRegionIndex());
            }
            // //find unused index we can use for temporary ROI
            // BitSet usedROIIndexes = new BitSet();
            // for (int i = 0; i < roiComposite.length; i++) {
            // byte[] sliceBytes = ((DataBufferByte)roiComposite[i].getRaster().getDataBuffer()).getData();
            // for (int j = 0; j < sliceBytes.length; j++) {
            // usedROIIndexes.set((int)(sliceBytes[j]&0x000000FF));
            // }
            // }
            int unusedROIPixelValue = getUnusedROIColorIndex(overlayEditorPanelJAI.getAllCompositeROINamesAndColors(), null);
            // if(usedROIIndexes.get(unusedROIPixelValue)){
            // throw new Exception("Error: Found unused color index but that ROI pixel value exists");
            // }
            // find image indexes of selected regions and fill new ROIImage with temporary ROI Index
            byte[] shortEncodedRegionIndexArr = regionImage.getShortEncodedRegionIndexImage();
            BufferedImage[] tempROI = new BufferedImage[roiComposite.length];
            int count = 0;
            for (int i = 0; i < tempROI.length; i++) {
                byte[] roiBytes = ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData();
                tempROI[i] = new BufferedImage(roiComposite[i].getWidth(), roiComposite[i].getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
                byte[] sliceBytes = ((DataBufferByte) tempROI[i].getRaster().getDataBuffer()).getData();
                System.arraycopy(roiBytes, 0, sliceBytes, 0, roiBytes.length);
                for (int j = 0; j < sliceBytes.length; j++) {
                    int regionIndex = (int) ((0x000000ff & shortEncodedRegionIndexArr[2 * count]) | ((0x000000ff & shortEncodedRegionIndexArr[2 * count + 1]) << 8));
                    if (selectedRegionIndexesTS.contains(regionIndex)) {
                        sliceBytes[j] = (byte) unusedROIPixelValue;
                    }
                    count++;
                }
            }
            if (getClientTaskStatusSupport() != null) {
                getClientTaskStatusSupport().setProgress(10);
            }
            // release memory
            shortEncodedRegionIndexArr = null;
            // get new regionImage and new selectedRegionInfos
            VCImage tempImage = ROIMultiPaintManager.createVCImageFromBufferedImages(ROIMultiPaintManager.DEFAULT_EXTENT, tempROI);
            RegionImage tempRegionImage = new RegionImage(tempImage, 0, /*0 means generate no surfacecollection*/
            tempImage.getExtent(), ROIMultiPaintManager.DEFAULT_ORIGIN, RegionImage.NO_SMOOTHING, null);
            // release memory
            tempImage = null;
            RegionInfo[] tempRegionInfos = tempRegionImage.getRegionInfos();
            if (tempRegionInfos.length == 1) {
                throw new Exception("No unselected neighbors to merge with.");
            }
            if (getClientTaskStatusSupport() != null) {
                getClientTaskStatusSupport().setProgress(20);
            }
            Vector<RegionImage.RegionInfo> tempSelectedRegionInfos = new Vector<RegionImage.RegionInfo>();
            HighlightROIInfo highlightROIInfo = generateHighlightROIInfo((byte) -1, tempROI, tempRegionImage, RegionAction.createCheckNeighborsOnlyRegionAction(tempRegionInfos), null);
            boolean bHasSelectionWithMoreThanOneNeighbor = false;
            for (int i = 0; i < tempRegionInfos.length; i++) {
                if (tempRegionInfos[i].getPixelValue() == unusedROIPixelValue) {
                    tempSelectedRegionInfos.add(tempRegionInfos[i]);
                // if (highlightROIInfo.neighborsForRegionsMap.get(tempRegionInfos[i]).size() > 1) {
                // hashTable.put(UNUSED_ROI_PIXVAL, new Integer(unusedROIPixelValue));
                // bHasSelectionWithMoreThanOneNeighbor = true;
                // } else {
                // tempSelectedRegionInfos.add(tempRegionInfos[i]);
                // }
                }
            }
            if (getClientTaskStatusSupport() != null) {
                getClientTaskStatusSupport().setProgress(50);
            }
            // final merge
            updateUndo(UNDO_INIT.ALLZ);
            generateHighlightROIInfo((byte) unusedROIPixelValue, tempROI, tempRegionImage, RegionAction.createMergeSelectedWithNeighborsRegionAction(tempRegionInfos, tempSelectedRegionInfos, highlightROIInfo.neighborsForRegionsMap), null);
            // copy merged bytes back to ROI
            for (int i = 0; i < tempROI.length; i++) {
                byte[] roiBytes = ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData();
                byte[] sliceBytes = ((DataBufferByte) tempROI[i].getRaster().getDataBuffer()).getData();
                // for (int j = 0; j < sliceBytes.length; j++) {
                // if(sliceBytes[j] == (byte)unusedROIPixelValue){
                // System.out.println("Bad");
                // }
                // }
                System.arraycopy(sliceBytes, 0, roiBytes, 0, roiBytes.length);
            }
            if (getClientTaskStatusSupport() != null) {
                getClientTaskStatusSupport().setProgress(90);
            }
        }
    };
    AsynchClientTask updateGUITask = new AsynchClientTask("Updating display...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Integer unusedROIIndex = (Integer)hashTable.get(UNUSED_ROI_PIXVAL);
            // if(unusedROIIndex != null){
            // overlayEditorPanelJAI.addROIName(MULTI_NEIGHBOR_MERGE, true, MULTI_NEIGHBOR_MERGE,true,/*true,true,*/OverlayEditorPanelJAI.CONTRAST_COLORS[unusedROIIndex]);
            // }
            overlayEditorPanelJAI.setHighliteInfo(null, OverlayEditorPanelJAI.FRAP_DATA_RESOLVEDMERGE_PROPERTY);
            updateUndoAfterPrivate(true, false);
        }
    };
    Vector<AsynchClientTask> asynchClientTaskV = new Vector<AsynchClientTask>();
    asynchClientTaskV.add(mergeTask);
    asynchClientTaskV.add(updateGUITask);
    asynchClientTaskV.addAll(Arrays.asList(getRefreshObjectsTasks()));
    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), asynchClientTaskV.toArray(new AsynchClientTask[0]), true, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) VCImage(cbit.image.VCImage) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) TreeSet(java.util.TreeSet) RegionImage(cbit.vcell.geometry.RegionImage) Vector(java.util.Vector)

Example 10 with RegionInfo

use of cbit.vcell.geometry.RegionImage.RegionInfo in project vcell by virtualcell.

the class ROIMultiPaintManager method highliteImageWithResolvedSelections.

private void highliteImageWithResolvedSelections(final RegionInfo[] selectedRegionInfos) {
    if (selectedRegionInfos == null || selectedRegionInfos.length == 0) {
        overlayEditorPanelJAI.setHighliteInfo(null, OverlayEditorPanelJAI.FRAP_DATA_RESOLVEDHIGHLIGHT_PROPERTY);
        return;
    }
    final String RESOLVE_HIGHLIGHT_INFO = "RESOLVE_HIGHLIGHT_INFO";
    AsynchClientTask hilightCalcTask = new AsynchClientTask("Calc highlight...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            InterruptCalc localInterruptCalc = getInterruptCalc(lastResolveHighlightInterruptCalc);
            List<RegionInfo> selectedRegionInfoList = Arrays.asList(selectedRegionInfos);
            HighlightROIInfo highlightROIInfo = generateHighlightROIInfo((byte) -1, roiComposite, regionImage, RegionAction.createHighlightRegionAction(sortedRegionInfos, selectedRegionInfoList), localInterruptCalc);
            if (localInterruptCalc.isInterrupted()) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            hashTable.put(RESOLVE_HIGHLIGHT_INFO, highlightROIInfo);
        }
    };
    AsynchClientTask udpateDisplayTask = new AsynchClientTask("Update display...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            HighlightROIInfo highlightROIInfo = (HighlightROIInfo) hashTable.get(RESOLVE_HIGHLIGHT_INFO);
            overlayEditorPanelJAI.setHighliteInfo(highlightROIInfo.highlightROI, OverlayEditorPanelJAI.FRAP_DATA_RESOLVEDHIGHLIGHT_PROPERTY);
            wantBlendSetToEnhance();
        }
    };
    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { hilightCalcTask, udpateDisplayTask });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo)

Aggregations

RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)18 Point (java.awt.Point)7 VCImage (cbit.image.VCImage)6 ISize (org.vcell.util.ISize)6 ROI (cbit.vcell.VirtualMicroscopy.ROI)5 RegionImage (cbit.vcell.geometry.RegionImage)5 SubVolume (cbit.vcell.geometry.SubVolume)5 GeometricRegion (cbit.vcell.geometry.surface.GeometricRegion)5 SurfaceGeometricRegion (cbit.vcell.geometry.surface.SurfaceGeometricRegion)5 VolumeGeometricRegion (cbit.vcell.geometry.surface.VolumeGeometricRegion)5 Vector (java.util.Vector)5 Origin (org.vcell.util.Origin)5 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)4 Geometry (cbit.vcell.geometry.Geometry)4 SurfaceClass (cbit.vcell.geometry.SurfaceClass)4 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)4 Hashtable (java.util.Hashtable)4 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)3 GeometryClass (cbit.vcell.geometry.GeometryClass)3