Search in sources :

Example 31 with VCImage

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

the class ROIMultiPaintManager method checkBorders.

private VCImage checkBorders(VCImage checkThisVCImage) throws Exception {
    boolean bAddBorder = false;
    BorderInfo borderInfo = checkBorderInfo(checkThisVCImage);
    if (borderInfo.bXYTouch || borderInfo.bZTouch) {
        boolean b3DTouch = borderInfo.bXYTouch && borderInfo.bZTouch;
        String edgeDescrFrag = "on the " + (b3DTouch ? "XY and Z" : (borderInfo.bXYTouch ? "XY" : "Z")) + " border.";
        final String addBorder = "Add empty border";
        final String keep = "Keep as is";
        final String cancel = "Cancel";
        String result = DialogUtils.showWarningDialog(overlayEditorPanelJAI, "One or more Domain Regions touches the outer boundary " + edgeDescrFrag + "\n" + "Choose an option:\n" + "1. Keep as is, do not change.\n" + "2. Add empty 'background' border around outer boundary so no Domain Region touches an outer edge.", new String[] { keep, addBorder, cancel }, keep);
        if (result.equals(cancel)) {
            throw UserCancelException.CANCEL_GENERIC;
        } else if (result.equals(addBorder)) {
            bAddBorder = true;
            ;
        }
    }
    if (!bAddBorder) {
        return null;
    }
    ISize checkThisVCImageISize = new ISize(checkThisVCImage.getNumX(), checkThisVCImage.getNumY(), checkThisVCImage.getNumZ());
    boolean bxy = borderInfo.bXYTouch;
    boolean bz = borderInfo.bZTouch;
    ROIMultiPaintManager.PaddedInfo paddedInfo = copyToPadded(checkThisVCImage.getPixels(), checkThisVCImageISize, null, checkThisVCImage.getExtent(), new ISize((bxy ? 1 : 0), (bxy ? 1 : 0), (bz ? 1 : 0)), new ISize((bxy ? 1 : 0), (bxy ? 1 : 0), (bz ? 1 : 0)));
    VCImage newVCImage = new VCImageUncompressed(null, (byte[]) paddedInfo.paddedArray, DEFAULT_EXTENT, /*paddedInfo.paddedExtent*/
    paddedInfo.paddedISize.getX(), paddedInfo.paddedISize.getY(), paddedInfo.paddedISize.getZ());
    return newVCImage;
}
Also used : ISize(org.vcell.util.ISize) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Example 32 with VCImage

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

the class ROIMultiPaintManager method fillVoids.

private boolean fillVoids(BufferedImage[] roiPixels, boolean bCheckOnly) throws Exception {
    if (true) {
        throw new IllegalArgumentException("Not yet implemented fully");
    }
    boolean bHadAnyInternalVoids = false;
    int xSize = roiPixels[0].getWidth();
    int ySize = roiPixels[0].getHeight();
    int zSize = roiPixels.length;
    int XYSIZE = xSize * ySize;
    boolean bUseZ = roiPixels.length > 1;
    VCImage checkImage = ROIMultiPaintManager.createVCImageFromBufferedImages(getImageDataSetChannel().getExtent(), roiComposite);
    RegionImage regionImage = new RegionImage(checkImage, 0, /*0 means generate no surfacecollection*/
    checkImage.getExtent(), getImageDataSetChannel().getAllImages()[0].getOrigin(), RegionImage.NO_SMOOTHING, progressWaitPopup);
    RegionInfo[] newRegionInfos = regionImage.getRegionInfos();
    for (int i = 0; i < newRegionInfos.length; i++) {
        if (newRegionInfos[i].getPixelValue() == 0) {
            boolean bInternalVoid = true;
            for (int z = 0; z < zSize; z++) {
                int zOffset = z * XYSIZE;
                for (int y = 0; y < ySize; y++) {
                    int yoffset = y * xSize;
                    int zyOffset = zOffset + yoffset;
                    for (int x = 0; x < xSize; x++) {
                        if (newRegionInfos[i].isIndexInRegion(zyOffset + x)) {
                            if (x == 0 || y == 0 | (bUseZ && z == 0) | x == (xSize - 1) || y == (ySize - 1) || (bUseZ && z == (zSize - 1))) {
                                bInternalVoid = false;
                                break;
                            }
                        }
                    }
                    if (!bInternalVoid) {
                        break;
                    }
                }
                if (!bInternalVoid) {
                    break;
                }
            }
            if (bInternalVoid) {
                bHadAnyInternalVoids = true;
                if (bCheckOnly) {
                    return bHadAnyInternalVoids;
                }
                for (int z = 0; z < zSize; z++) {
                    byte[] roiPixelsBytes = ((DataBufferByte) roiPixels[z].getRaster().getDataBuffer()).getData();
                    for (int xy = 0; xy < XYSIZE; xy++) {
                    // if(newRegionInfos[i].isIndexInRegion(j)){
                    // fillvoidPixels[j]|= 0xFFFF;
                    // }
                    }
                }
            }
        }
    }
    return bHadAnyInternalVoids;
}
Also used : RegionImage(cbit.vcell.geometry.RegionImage) VCImage(cbit.image.VCImage) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 33 with VCImage

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

the class ClientDocumentManager method save.

/**
 * Insert the method's description here.
 * Creation date: (2/5/01 4:58:40 PM)
 */
public VCImage save(VCImage vcImage) throws DataAccessException {
    try {
        String vcImageXML = null;
        try {
            vcImageXML = XmlHelper.imageToXML(vcImage);
        } catch (XmlParseException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
        String savedVCImageXML = sessionManager.getUserMetaDbServer().saveVCImage(new BigString(vcImageXML)).toString();
        VCImage savedVCImage = null;
        try {
            savedVCImage = XmlHelper.XMLToImage(savedVCImageXML);
        } catch (XmlParseException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException(e.getMessage());
        }
        savedVCImage.refreshDependencies();
        KeyValue savedKey = savedVCImage.getVersion().getVersionKey();
        if (xmlHash.get(savedKey) == null) {
            xmlHash.put(savedKey, savedVCImageXML);
        }
        try {
            ISize size = new ISize(savedVCImage.getNumX(), savedVCImage.getNumY(), savedVCImage.getNumZ());
            GIFImage browseData = BrowseImage.makeBrowseGIFImage(savedVCImage);
            VCImageInfo savedVCImageInfo = new VCImageInfo(savedVCImage.getVersion(), size, savedVCImage.getExtent(), browseData, VCellSoftwareVersion.fromSystemProperty());
            imgInfoHash.put(savedKey, savedVCImageInfo);
            fireDatabaseInsert(new DatabaseEvent(this, DatabaseEvent.INSERT, null, savedVCImageInfo));
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
        return savedVCImage;
    } catch (RemoteProxyException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(VCellErrorMessages.FAIL_SAVE_MESSAGE + "\n\n" + e.getMessage());
    }
}
Also used : GIFImage(cbit.image.GIFImage) KeyValue(org.vcell.util.document.KeyValue) ISize(org.vcell.util.ISize) VCImage(cbit.image.VCImage) BigString(org.vcell.util.BigString) XmlParseException(cbit.vcell.xml.XmlParseException) BigString(org.vcell.util.BigString) DataAccessException(org.vcell.util.DataAccessException) VCImageInfo(cbit.image.VCImageInfo) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)

Example 34 with VCImage

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

the class RayCaster method resampleGeometry.

public static Geometry resampleGeometry(GeometryThumbnailImageFactory geometryThumbnailImageFactory, Geometry origGeometry, ISize sampleSize) throws ImageException, PropertyVetoException, GeometryException, ExpressionException {
    if (origGeometry.getDimension() < 3) {
        throw new GeometryException("Presently, the Raycaster resampling works only for 3d geometries.");
    }
    GeometrySpec origGeometrySpec = origGeometry.getGeometrySpec();
    VCImage origSubvolumeImage = origGeometrySpec.getSampledImage().getCurrentValue();
    if (origSubvolumeImage == null) {
        throw new GeometryException("original geometry does not have a sampled image");
    }
    VCImage resampledSubvolumeImage = RayCaster.sampleGeometry(origGeometry, sampleSize, false);
    // 
    // Check if resampling failed:
    // if not the same number of pixelClasses (between original geometry and resampled)
    // if the subvolume handles are the same
    // 
    boolean bSameSubvolumes = true;
    if (origSubvolumeImage.getNumPixelClasses() != resampledSubvolumeImage.getNumPixelClasses()) {
        bSameSubvolumes = false;
    }
    // 
    for (VCPixelClass origPixelClass : origSubvolumeImage.getPixelClasses()) {
        VCPixelClass resampledPixelClass = resampledSubvolumeImage.getPixelClassFromPixelValue(origPixelClass.getPixel());
        if (resampledPixelClass == null) {
            bSameSubvolumes = false;
            break;
        }
    }
    // 
    if (!bSameSubvolumes) {
        StringBuffer message = new StringBuffer();
        message.append("\n\nexisting geometry:\n");
        for (SubVolume oldSubvolume : origGeometrySpec.getSubVolumes()) {
            long count = origSubvolumeImage.countPixelsByValue((byte) oldSubvolume.getHandle());
            message.append("subvolume('" + oldSubvolume.getName() + "',handle=" + oldSubvolume.getHandle() + ",numPixels=" + count + " of " + origSubvolumeImage.getNumXYZ() + "\n");
        }
        message.append("\n\nnew resampled handle VCImage:\n");
        for (VCPixelClass newPixelClass : resampledSubvolumeImage.getPixelClasses()) {
            long count = resampledSubvolumeImage.countPixelsByValue((byte) newPixelClass.getPixel());
            message.append("pixelClass('" + newPixelClass.getPixelClassName() + "',pixelValue=" + newPixelClass.getPixel() + ",numPixels=" + count + " of " + resampledSubvolumeImage.getNumXYZ() + ")\n");
        }
        throw new GeometryException("original Geometry had " + origSubvolumeImage.getNumPixelClasses() + " subvolumes, resampled Geometry found " + resampledSubvolumeImage.getNumPixelClasses() + " subvolumes " + message.toString());
    }
    // 
    // Create new VCImage that will form the basis for a new image-based geometry.
    // 
    VCImage newVCImage = null;
    if (origGeometrySpec.getImage() != null) {
        // 
        // was an image-based geometry - try to make new VCImage similar to the original (same pixelClass names and pixel values).
        // the goal is to make identical geometries if the sample size is same as the original image size.
        // 
        // create a new VCImage with same image pixel values (not subvolume handles) and pixel class names as original image.
        // 
        byte[] newVCImagePixels = new byte[sampleSize.getXYZ()];
        byte[] resampledSubvolumePixels = resampledSubvolumeImage.getPixels();
        for (int i = 0; i < sampleSize.getXYZ(); i++) {
            int subvolumeHandle = resampledSubvolumePixels[i];
            ImageSubVolume imageSubvolume = (ImageSubVolume) origGeometrySpec.getSubVolume(subvolumeHandle);
            newVCImagePixels[i] = (byte) imageSubvolume.getPixelValue();
        }
        newVCImage = new VCImageUncompressed(null, newVCImagePixels, origGeometry.getExtent(), sampleSize.getX(), sampleSize.getY(), sampleSize.getZ());
        newVCImage.setName(origGeometrySpec.getImage().getName());
        ArrayList<VCPixelClass> newPixelClasses = new ArrayList<VCPixelClass>();
        for (VCPixelClass origPixelClass : origGeometrySpec.getImage().getPixelClasses()) {
            SubVolume origSubvolume = origGeometrySpec.getImageSubVolumeFromPixelValue(origPixelClass.getPixel());
            newPixelClasses.add(new VCPixelClass(null, origSubvolume.getName(), origPixelClass.getPixel()));
        }
        newVCImage.setPixelClasses(newPixelClasses.toArray(new VCPixelClass[newPixelClasses.size()]));
    } else {
        // 
        // was an analytic geometry - create a new image-based geometry
        // 
        // create a new VCImage with image pixel values and pixelClass names equal to corresponding subvolumes from original geometry
        // make new subvolume names equal to old subvolume names.
        // 
        byte[] newVCImageSubvolumePixels = resampledSubvolumeImage.getPixels().clone();
        newVCImage = new VCImageUncompressed(null, newVCImageSubvolumePixels, origGeometry.getExtent(), sampleSize.getX(), sampleSize.getY(), sampleSize.getZ());
        ArrayList<VCPixelClass> newPixelClasses = new ArrayList<VCPixelClass>();
        for (SubVolume origSubvolume : origGeometrySpec.getSubVolumes()) {
            // note: newVCImage already has subvolume handle pixels.
            newPixelClasses.add(new VCPixelClass(null, origSubvolume.getName(), origSubvolume.getHandle()));
        }
        newVCImage.setPixelClasses(newPixelClasses.toArray(new VCPixelClass[newPixelClasses.size()]));
    }
    // 
    // construct the new geometry with the sampled VCImage.
    // 
    Geometry newGeometry = new Geometry(origGeometry.getName(), newVCImage);
    newGeometry.getGeometrySpec().setExtent(origGeometry.getExtent());
    newGeometry.getGeometrySpec().setOrigin(origGeometry.getOrigin());
    newGeometry.setDescription(origGeometry.getDescription());
    newGeometry.getGeometrySurfaceDescription().setFilterCutoffFrequency(origGeometry.getGeometrySurfaceDescription().getFilterCutoffFrequency());
    newGeometry.precomputeAll(geometryThumbnailImageFactory, true, true);
    return newGeometry;
}
Also used : VCPixelClass(cbit.image.VCPixelClass) GeometryException(cbit.vcell.geometry.GeometryException) ArrayList(java.util.ArrayList) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed) GeometrySpec(cbit.vcell.geometry.GeometrySpec) Geometry(cbit.vcell.geometry.Geometry) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume)

Example 35 with VCImage

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

the class GeometryThumbnailImageFactoryAWT method getThumbnailImage.

public ThumbnailImage getThumbnailImage(GeometrySpec geometrySpec) throws ImageException {
    int REAL_SAMPLE_X = 0;
    int REAL_SAMPLE_Y = 0;
    if (geometrySpec.getDimension() > 0) {
        // Calc Scaling parameters
        double srcScaleX = SAMPLED_GEOM_SIZE_MAX / geometrySpec.getExtent().getX();
        double srcScaleY = SAMPLED_GEOM_SIZE_MAX / geometrySpec.getExtent().getY();
        if (srcScaleX < srcScaleY) {
            REAL_SAMPLE_X = SAMPLED_GEOM_SIZE_MAX;
            REAL_SAMPLE_Y = Math.max((int) (srcScaleX * geometrySpec.getExtent().getY()), 1);
        } else {
            REAL_SAMPLE_Y = SAMPLED_GEOM_SIZE_MAX;
            REAL_SAMPLE_X = Math.max((int) (srcScaleY * geometrySpec.getExtent().getX()), 1);
        }
    }
    if (geometrySpec.getDimension() > 0) {
        BufferedImage brightImage = new BufferedImage(REAL_SAMPLE_X, REAL_SAMPLE_Y, BufferedImage.TYPE_INT_RGB);
        Graphics2D brightG2D = brightImage.createGraphics();
        brightG2D.setColor(java.awt.Color.white);
        brightG2D.fillRect(0, 0, REAL_SAMPLE_X, REAL_SAMPLE_Y);
        VCImage currSampledImage = geometrySpec.getSampledImage().getCurrentValue();
        java.awt.image.IndexColorModel handleColorMap = DisplayAdapterService.getHandleColorMap();
        byte[] reds = new byte[256];
        handleColorMap.getReds(reds);
        byte[] greens = new byte[256];
        handleColorMap.getGreens(greens);
        byte[] blues = new byte[256];
        handleColorMap.getBlues(blues);
        // Create projections of each subvolume handle
        VCPixelClass[] pixClassHandles = currSampledImage.getPixelClasses();
        byte[] pixels = currSampledImage.getPixels();
        for (int i = 0; i < pixClassHandles.length; i += 1) {
            byte[] zBuf = new byte[currSampledImage.getNumX() * currSampledImage.getNumY()];
            java.util.Arrays.fill(zBuf, (byte) 0);
            // Project z
            for (int j = 0; j < pixels.length; j += 1) {
                if (pixels[j] == pixClassHandles[i].getPixel()) {
                    zBuf[j % zBuf.length] = (byte) 1;
                }
            }
            // Scale X-Y
            int cmapIndex = (pixClassHandles[i].getPixel() & 0xff);
            byte ired = reds[cmapIndex];
            byte igrn = greens[cmapIndex];
            byte iblu = blues[cmapIndex];
            IndexColorModel colorModel = new IndexColorModel(8, 2, new byte[] { 0, ired }, new byte[] { 0, igrn }, new byte[] { 0, iblu }, new byte[] { 0, (byte) (200) });
            int width = currSampledImage.getNumX();
            int height = currSampledImage.getNumY();
            BufferedImage bufferedImage = getImage(colorModel, zBuf, width, height);
            ImageIcon theImageIcon = new ImageIcon(bufferedImage.getScaledInstance(REAL_SAMPLE_X, REAL_SAMPLE_Y, Image.SCALE_AREA_AVERAGING));
            brightG2D.drawImage(theImageIcon.getImage(), 0, 0, theImageIcon.getImageObserver());
        }
        int[] rgb = brightImage.getRGB(0, 0, REAL_SAMPLE_X, REAL_SAMPLE_Y, null, 0, REAL_SAMPLE_X);
        return new ThumbnailImage(rgb, REAL_SAMPLE_X, REAL_SAMPLE_Y, brightImage);
    }
    return null;
}
Also used : ImageIcon(javax.swing.ImageIcon) VCPixelClass(cbit.image.VCPixelClass) VCImage(cbit.image.VCImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ThumbnailImage(cbit.image.ThumbnailImage) IndexColorModel(java.awt.image.IndexColorModel) IndexColorModel(java.awt.image.IndexColorModel)

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