Search in sources :

Example 11 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class Image method crop.

static Image crop(Image origImage, Rectangle rect) throws ImageException {
    Object inArray = origImage.getPixelArray();
    Object outArray = Array.newInstance(inArray.getClass().getComponentType(), rect.width * rect.height * origImage.getNumZ());
    for (int k = 0; k < origImage.getNumZ(); k++) {
        for (int j = 0; j < rect.height; j++) {
            for (int i = 0; i < rect.width; i++) {
                int inIndex = rect.x + i + (j + rect.y) * origImage.getNumX() + k * origImage.getNumX() * origImage.getNumY();
                int outIndex = i + j * rect.width + (k * rect.width * rect.height);
                Array.set(outArray, outIndex, Array.get(inArray, inIndex));
            }
        }
    }
    Extent croppedExtent = null;
    if (origImage.getExtent() != null) {
        croppedExtent = new Extent(origImage.getExtent().getX() * rect.width / origImage.getNumX(), origImage.getExtent().getY() * rect.height / origImage.getNumY(), origImage.getExtent().getZ());
    }
    Origin croppedOrigin = null;
    if (origImage.getOrigin() != null) {
        croppedOrigin = new Origin(calcOriginPosition(origImage.getOrigin().getX(), rect.x, origImage.getExtent().getX(), origImage.getNumX()), calcOriginPosition(origImage.getOrigin().getY(), rect.y, origImage.getExtent().getY(), origImage.getNumY()), // origImage.getOrigin().getY()+(rect.y*(origImage.getExtent().getY()/origImage.getNumY())),
        origImage.getExtent().getZ());
    }
    if (origImage instanceof UShortImage) {
        return new UShortImage((short[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    } else if (origImage instanceof ByteImage) {
        return new ByteImage((byte[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    } else if (origImage instanceof FloatImage) {
        return new FloatImage((float[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    }
    throw new ImageException("Crop if Image type " + origImage.getClass().getName() + " not implemented.");
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent)

Example 12 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class ImageDataset method createZStack.

/**
 * FRAPData constructor comment.
 */
public static ImageDataset createZStack(ImageDataset[] argImageDatasets) {
    // Error checking
    if (argImageDatasets.length == 0) {
        throw new RuntimeException("Cannot perform FRAP analysis on null image.");
    }
    int tempNumX = argImageDatasets[0].getImage(0, 0, 0).getNumX();
    int tempNumY = argImageDatasets[0].getImage(0, 0, 0).getNumY();
    int tempNumZ = argImageDatasets[0].getSizeZ();
    int tempNumC = argImageDatasets[0].getSizeC();
    int tempNumT = argImageDatasets[0].getSizeT();
    if (tempNumZ != 1 || tempNumC != 1 || tempNumT != 1) {
        throw new RuntimeException("each ImageDataset in z-stack must be 2D, single channel, and one time");
    }
    UShortImage[] ushortImages = new UShortImage[argImageDatasets.length];
    ushortImages[0] = argImageDatasets[0].getImage(0, 0, 0);
    for (int i = 1; i < argImageDatasets.length; i++) {
        UShortImage img = argImageDatasets[i].getImage(0, 0, 0);
        if (img.getNumX() != tempNumX || img.getNumY() != tempNumY || img.getNumZ() != tempNumZ) {
            throw new RuntimeException("ImageDataset sub-images not same dimension");
        }
        ushortImages[i] = img;
        ushortImages[i].setExtent(new Extent(img.getExtent().getX(), img.getExtent().getY(), img.getExtent().getZ() * argImageDatasets.length));
    }
    return new ImageDataset(ushortImages, null, ushortImages.length);
}
Also used : Extent(org.vcell.util.Extent)

Example 13 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class ImageFile method getVCImage.

/**
 * This method was created in VisualAge.
 * @return cbit.image.VCImage
 */
public VCImage getVCImage() throws ImageException {
    if (originalRGB == null && originalDouble == null) {
        throw new ImageException("data is not loaded");
    }
    byte[] bytepix = null;
    if (originalRGB != null) {
        int[] uniquePixelValues = getUniquePixelValues();
        if (uniquePixelValues.length > 256) {
            throw new ImageException("VCImage can't have more than 256 pixel values");
        }
        bytepix = new byte[originalRGB.length];
        for (int i = 0; i < originalRGB.length; i++) {
            int oRGBIndex = -1;
            for (int j = 0; j < uniquePixelValues.length; j += 1) {
                if (uniquePixelValues[j] == originalRGB[i]) {
                    oRGBIndex = j;
                    break;
                }
            }
            if (oRGBIndex >= 0) {
                bytepix[i] = ((byte) oRGBIndex);
            } else {
                throw new ImageException("Unique Pixel value missing in originalRGB array");
            }
        // int intPix = 0xffffff&originalRGB[i];
        // int red = intPix&0xff;
        // int green = (intPix>>8)&0xff;
        // int blue = (intPix>>16)&0xff;
        // byte pix = (byte)Math.max(red,Math.max(green,blue));
        // bytepix[i] = pix;
        }
    } else {
        bytepix = new byte[originalDouble.length];
        for (int i = 0; i < originalDouble.length; i++) {
            bytepix[i] = (byte) (0xff & (int) originalDouble[i]);
        }
    }
    VCImageUncompressed vci = new VCImageUncompressed(null, bytepix, new Extent(getSizeX(), getSizeY(), getSizeZ()), getSizeX(), getSizeY(), getSizeZ());
    return vci;
}
Also used : Extent(org.vcell.util.Extent)

Example 14 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class ImagePlaneManager method updateImagePlaneData.

/**
 * Insert the method's description here.
 * Creation date: (10/11/00 1:35:27 PM)
 */
private void updateImagePlaneData() {
    if (getSourceDataInfo() == null) {
        setImagePlaneData(null);
        return;
    }
    if (lastImagePlaneDataNormalAxis == getNormalAxis()) {
        return;
    }
    if (lastImagePlaneDataSlice == getSlice()) {
        return;
    }
    int type = getSourceDataInfo().getType();
    Serializable data = getSourceDataInfo().getData();
    int startIndex = getSourceDataInfo().getStartIndex();
    SourceDataInfo sdiSource = getSourceDataInfo();
    // 
    org.vcell.util.Origin org = sdiSource.getOrigin();
    Extent ext = sdiSource.getExtent();
    // 
    int startDelta = worldSlice() * (int) Coordinate.convertAxisFromStandardXYZToNormal(sdiSource.getXIncrement(), sdiSource.getYIncrement(), sdiSource.getZIncrement(), Coordinate.Z_AXIS, getNormalAxis());
    int xSize = (int) Coordinate.convertAxisFromStandardXYZToNormal(sdiSource.getXSize(), sdiSource.getYSize(), sdiSource.getZSize(), Coordinate.X_AXIS, getNormalAxis());
    int xIncrement = (int) Coordinate.convertAxisFromStandardXYZToNormal(sdiSource.getXIncrement(), sdiSource.getYIncrement(), sdiSource.getZIncrement(), Coordinate.X_AXIS, getNormalAxis());
    double xOrigin = Coordinate.convertAxisFromStandardXYZToNormal(org.getX(), org.getY(), org.getZ(), Coordinate.X_AXIS, getNormalAxis());
    double xExtent = Coordinate.convertAxisFromStandardXYZToNormal(ext.getX(), ext.getY(), ext.getZ(), Coordinate.X_AXIS, getNormalAxis());
    int ySize = (int) Coordinate.convertAxisFromStandardXYZToNormal(sdiSource.getXSize(), sdiSource.getYSize(), sdiSource.getZSize(), Coordinate.Y_AXIS, getNormalAxis());
    int yIncrement = (int) Coordinate.convertAxisFromStandardXYZToNormal(sdiSource.getXIncrement(), sdiSource.getYIncrement(), sdiSource.getZIncrement(), Coordinate.Y_AXIS, getNormalAxis());
    double yOrigin = Coordinate.convertAxisFromStandardXYZToNormal(org.getX(), org.getY(), org.getZ(), Coordinate.Y_AXIS, getNormalAxis());
    double yExtent = Coordinate.convertAxisFromStandardXYZToNormal(ext.getX(), ext.getY(), ext.getZ(), Coordinate.Y_AXIS, getNormalAxis());
    // 
    SourceDataInfo sdi = new SourceDataInfo(type, data, null, startIndex + startDelta, xSize, xIncrement, xOrigin, xExtent, ySize, yIncrement, yOrigin, yExtent);
    sdi.setIsChombo(sdiSource.isChombo());
    sdi.setSolverDataType(sdiSource.getSolverDataType());
    setImagePlaneData(sdi);
}
Also used : Serializable(java.io.Serializable) Extent(org.vcell.util.Extent)

Example 15 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class GeometrySpec method vetoableChange.

/**
 * Insert the method's description here.
 * Creation date: (6/3/00 9:58:08 AM)
 * @param event java.beans.PropertyChangeEvent
 */
public void vetoableChange(java.beans.PropertyChangeEvent event) throws PropertyVetoException {
    if (event.getSource() == this && event.getPropertyName().equals("image")) {
        if (event.getNewValue() != null) {
            VCImage newVCImage = (VCImage) event.getNewValue();
            if (newVCImage.getNumXYZ() > IMAGE_SIZE_LIMIT) {
                // throw new PropertyVetoException("image size "+newVCImage.getNumXYZ()+" pixels exceeded limit of "+IMAGE_SIZE_LIMIT,event);
                if (lg.isEnabledFor(Level.WARN)) {
                    lg.warn("WARNING: image size " + newVCImage.getNumXYZ() + " pixels exceeded limit of " + IMAGE_SIZE_LIMIT);
                }
            }
        }
    }
    if (event.getSource() == this && event.getPropertyName().equals("subVolumes")) {
        SubVolume[] subVolumes = (SubVolume[]) event.getNewValue();
        // 
        // add subvolumes
        // (handles must be unique and non-negative, and analytic subvolumes must be first in array)
        // 
        boolean bFoundImageSubVolume = false;
        for (int i = 0; i < subVolumes.length; i++) {
            SubVolume sv = subVolumes[i];
            // 
            if (sv.getHandle() < 0) {
                throw new PropertyVetoException("subdomain handle=" + sv.getHandle() + " must be non-negative", event);
            }
            if (sv.getName() == null || sv.getName().length() < 1) {
                throw new PropertyVetoException("Subdomain name cannot be null or blank : ", event);
            }
            // 
            for (int j = i + 1; j < subVolumes.length; j++) {
                if (subVolumes[j].getHandle() == subVolumes[i].getHandle()) {
                    throw new PropertyVetoException("subdomain handle=" + sv.getHandle() + " has already been used in geometry", event);
                }
                if (subVolumes[j].getName().equals(subVolumes[i].getName())) {
                    throw new PropertyVetoException("subdomain name=" + sv.getName() + " has already been used in geometry", event);
                }
            }
            // 
            if (sv instanceof ImageSubVolume) {
                bFoundImageSubVolume = true;
            } else if (sv instanceof AnalyticSubVolume) {
                if (bFoundImageSubVolume) {
                    throw new PropertyVetoException("subdomains are out of order, all analytic subdomains must preceed all image subdomains", event);
                }
            }
        }
        // 
        for (int i = 0; i < subVolumes.length; i++) {
            if (subVolumes[i] instanceof ImageSubVolume) {
                if (vcImage == null) {
                    throw new PropertyVetoException("adding image subdomain, an image must be set first", event);
                }
            }
        }
    // 
    // check for uniqueness of name and handles
    // check for handle values of (0..N-1)
    // 
    } else if (event.getSource() == this && event.getPropertyName().equals("extent")) {
        Extent newExtent = (Extent) event.getNewValue();
        if (newExtent == null) {
            throw new PropertyVetoException("extent cannot be null", event);
        }
        if (newExtent.getX() <= 0 || newExtent.getY() <= 0.0 || newExtent.getZ() <= 0) {
            throw new PropertyVetoException("extent must be positive in X,Y,Z", event);
        }
    } else if (event.getSource() instanceof SubVolume && event.getPropertyName().equals("name")) {
        String newName = (String) event.getNewValue();
        if (newName == null || newName.length() < 1) {
            throw new PropertyVetoException("subdomain name must be at least one character", event);
        }
        // 
        // check if name already used
        // 
        SubVolume sv = getSubVolume(newName);
        if (sv != null && sv != event.getSource()) {
            throw new PropertyVetoException("A subdomain with name '" + newName + "' already exists.", event);
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Extent(org.vcell.util.Extent) VCImage(cbit.image.VCImage)

Aggregations

Extent (org.vcell.util.Extent)96 Origin (org.vcell.util.Origin)58 ISize (org.vcell.util.ISize)52 VCImageUncompressed (cbit.image.VCImageUncompressed)23 ImageException (cbit.image.ImageException)19 VCImage (cbit.image.VCImage)19 CartesianMesh (cbit.vcell.solvers.CartesianMesh)19 RegionImage (cbit.vcell.geometry.RegionImage)17 Geometry (cbit.vcell.geometry.Geometry)16 Expression (cbit.vcell.parser.Expression)16 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)15 IOException (java.io.IOException)15 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)13 BioModel (cbit.vcell.biomodel.BioModel)13 SubVolume (cbit.vcell.geometry.SubVolume)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 UserCancelException (org.vcell.util.UserCancelException)12 ExpressionException (cbit.vcell.parser.ExpressionException)10 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)9