Search in sources :

Example 16 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class GeometrySummaryPanel method initGeometry.

/**
 * Comment
 */
private void initGeometry(Geometry arg1) {
    final boolean bSpatial = getGeometry() != null && getGeometry().getDimension() > 0;
    getImagePlaneManagerPanel1().setVisible(bSpatial);
    getJPanelOrigin().setVisible(bSpatial);
    getJPanelSize().setVisible(bSpatial);
    if (getGeometry() != null) {
        try {
            if (getGeometry().getGeometrySpec().getSampledImage().isDirty()) {
                return;
            }
            VCImage vcImage = getGeometry().getGeometrySpec().getSampledImage().getCurrentValue();
            byte[] pixels = vcImage.getPixels();
            DisplayAdapterService das = new DisplayAdapterService();
            das.setActiveScaleRange(new org.vcell.util.Range(0, 255));
            das.setValueDomain(new org.vcell.util.Range(0, 255));
            das.addColorModelForValues(DisplayAdapterService.createContrastColorModel(), DisplayAdapterService.createGraySpecialColors(), "Contrast");
            das.setActiveColorModelID("Contrast");
            int[] rgb = new int[pixels.length];
            for (int i = 0; i < rgb.length; i += 1) {
                rgb[i] = das.getColorFromIndex(pixels[i]);
            }
            SourceDataInfo sdi = new SourceDataInfo(SourceDataInfo.INT_RGB_TYPE, rgb, getGeometry().getExtent(), getGeometry().getOrigin(), new org.vcell.util.Range(0, 255), 0, vcImage.getNumX(), 1, vcImage.getNumY(), vcImage.getNumX(), vcImage.getNumZ(), vcImage.getNumX() * vcImage.getNumY());
            getImagePlaneManagerPanel1().setSourceDataInfo(sdi);
        } catch (Exception e) {
            PopupGenerator.showErrorDialog(GeometrySummaryPanel.this, e.getMessage(), e);
        }
    } else {
        getImagePlaneManagerPanel1().setSourceDataInfo(null);
    }
}
Also used : DisplayAdapterService(cbit.image.DisplayAdapterService) VCImage(cbit.image.VCImage) SourceDataInfo(cbit.image.SourceDataInfo) ImageException(cbit.image.ImageException)

Example 17 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class GeometryViewer method refreshSourceDataInfo.

/**
 * connEtoM2:  (Geometry.this --> ImagePlaneManagerPanel1.sourceDataInfo)
 * @param value cbit.vcell.geometry.Geometry
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void refreshSourceDataInfo() {
    if (getGeometry() == null) {
        return;
    }
    GeometrySpec geometrySpec = getGeometry().getGeometrySpec();
    if (geometrySpec.getSampledImage().isDirty()) {
        return;
    }
    VCImage sampledImage = geometrySpec.getSampledImage().getCurrentValue();
    try {
        SourceDataInfo sdi = new SourceDataInfo(SourceDataInfo.INDEX_TYPE, sampledImage.getPixels(), geometrySpec.getExtent(), geometrySpec.getOrigin(), null, 0, sampledImage.getNumX(), 1, sampledImage.getNumY(), sampledImage.getNumX(), sampledImage.getNumZ(), sampledImage.getNumX() * sampledImage.getNumY());
        getImagePlaneManagerPanel1().setSourceDataInfo(sdi);
    } catch (ImageException e) {
        e.printStackTrace();
        DialogUtils.showErrorDialog(this, e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        DialogUtils.showErrorDialog(this, e.getMessage(), e);
    }
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) ImageException(cbit.image.ImageException) VCImage(cbit.image.VCImage) SourceDataInfo(cbit.image.SourceDataInfo) ImageException(cbit.image.ImageException)

Example 18 with VCImage

use of cbit.image.VCImage 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 19 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class RunRefSimulationFastOp method saveROIsAsExternalData.

private void saveROIsAsExternalData(ROI[] rois, LocalWorkspace localWorkspace, ExternalDataIdentifier newROIExtDataID) throws ObjectNotFoundException, ImageException, IOException {
    ISize isize = rois[0].getISize();
    Origin origin = rois[0].getRoiImages()[0].getOrigin();
    Extent extent = rois[0].getRoiImages()[0].getExtent();
    VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
    RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
    CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
    int NumTimePoints = 1;
    int NumChannels = rois.length;
    // dimensions: time points, channels, whole image ordered by z slices.
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    int index = 0;
    for (ROI roi : rois) {
        pixData[0][index++] = createDoubleArray(roi.getBinaryPixelsXYZ(1));
    }
    // Origin origin = new Origin(0,0,0);
    FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
    fdos.cartesianMesh = cartesianMesh;
    fdos.doubleSpecData = pixData;
    fdos.specEDI = newROIExtDataID;
    ArrayList<String> varNames = new ArrayList<String>();
    ArrayList<VariableType> varTypes = new ArrayList<VariableType>();
    for (ROI roi : rois) {
        varNames.add(ROI_MASK_NAME_PREFIX + roi.getROIName());
        varTypes.add(VariableType.VOLUME);
    }
    fdos.varNames = varNames.toArray(new String[0]);
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = new double[] { 0.0 };
    fdos.variableTypes = varTypes.toArray(new VariableType[0]);
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) VariableType(cbit.vcell.math.VariableType) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) ArrayList(java.util.ArrayList) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed) ROI(cbit.vcell.VirtualMicroscopy.ROI) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage)

Example 20 with VCImage

use of cbit.image.VCImage in project vcell by virtualcell.

the class RunRefSimulationOp method saveExternalData.

private static void saveExternalData(Image image, String varName, ExternalDataIdentifier newROIExtDataID, LocalWorkspace localWorkspace) throws ObjectNotFoundException, ImageException, IOException {
    Extent extent = image.getExtent();
    Origin origin = image.getOrigin();
    ISize isize = image.getISize();
    VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
    RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
    CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
    int NumTimePoints = 1;
    int NumChannels = 1;
    // dimensions: time points, channels, whole image ordered by z slices.
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    pixData[0][0] = image.getDoublePixels();
    FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
    fdos.cartesianMesh = simpleCartesianMesh;
    fdos.doubleSpecData = pixData;
    fdos.specEDI = newROIExtDataID;
    fdos.varNames = new String[] { varName };
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = new double[] { 0.0 };
    fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) RegionImage(cbit.vcell.geometry.RegionImage) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Aggregations

VCImage (cbit.image.VCImage)54 Geometry (cbit.vcell.geometry.Geometry)22 Extent (org.vcell.util.Extent)20 ISize (org.vcell.util.ISize)19 VCImageUncompressed (cbit.image.VCImageUncompressed)18 ImageException (cbit.image.ImageException)16 PropertyVetoException (java.beans.PropertyVetoException)15 DataAccessException (org.vcell.util.DataAccessException)15 KeyValue (org.vcell.util.document.KeyValue)15 SubVolume (cbit.vcell.geometry.SubVolume)14 Origin (org.vcell.util.Origin)13 RegionImage (cbit.vcell.geometry.RegionImage)11 SurfaceClass (cbit.vcell.geometry.SurfaceClass)11 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)11 UserCancelException (org.vcell.util.UserCancelException)11 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)10 Expression (cbit.vcell.parser.Expression)10 VCPixelClass (cbit.image.VCPixelClass)9 BioModel (cbit.vcell.biomodel.BioModel)8 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)8