Search in sources :

Example 1 with ImageException

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

the class ClientRequestManager method createMathModel.

/**
 * Insert the method's description here. Creation date: (5/24/2004 12:22:11 PM)
 *
 * @param windowID java.lang.String
 */
private MathModel createMathModel(String name, Geometry geometry) {
    MathModel mathModel = new MathModel(null);
    MathDescription mathDesc = mathModel.getMathDescription();
    try {
        mathDesc.setGeometry(geometry);
        if (geometry.getDimension() == 0) {
            mathDesc.addSubDomain(new CompartmentSubDomain("Compartment", CompartmentSubDomain.NON_SPATIAL_PRIORITY));
        } else {
            try {
                if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                    geometry.getGeometrySurfaceDescription().updateAll();
                }
            } catch (ImageException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Geometric surface generation error: \n" + e.getMessage());
            } catch (GeometryException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Geometric surface generation error: \n" + e.getMessage());
            }
            SubVolume[] subVolumes = geometry.getGeometrySpec().getSubVolumes();
            for (int i = 0; i < subVolumes.length; i++) {
                mathDesc.addSubDomain(new CompartmentSubDomain(subVolumes[i].getName(), subVolumes[i].getHandle()));
            }
            // 
            // add only those MembraneSubDomains corresponding to surfaces that acutally
            // exist in geometry.
            // 
            GeometricRegion[] regions = geometry.getGeometrySurfaceDescription().getGeometricRegions();
            for (int i = 0; i < regions.length; i++) {
                if (regions[i] instanceof SurfaceGeometricRegion) {
                    SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) regions[i];
                    SubVolume subVolume1 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[0]).getSubVolume();
                    SubVolume subVolume2 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[1]).getSubVolume();
                    CompartmentSubDomain compartment1 = mathDesc.getCompartmentSubDomain(subVolume1.getName());
                    CompartmentSubDomain compartment2 = mathDesc.getCompartmentSubDomain(subVolume2.getName());
                    MembraneSubDomain membraneSubDomain = mathDesc.getMembraneSubDomain(compartment1, compartment2);
                    if (membraneSubDomain == null) {
                        SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(subVolume1, subVolume2);
                        membraneSubDomain = new MembraneSubDomain(compartment1, compartment2, surfaceClass.getName());
                        mathDesc.addSubDomain(membraneSubDomain);
                    }
                }
            }
        }
        mathDesc.isValid();
        mathModel.setName(name);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
    return mathModel;
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ImageException(cbit.image.ImageException) SetMathDescription(cbit.vcell.client.task.SetMathDescription) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) GeometryException(cbit.vcell.geometry.GeometryException) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) ProgrammingException(org.vcell.util.ProgrammingException) MatrixException(cbit.vcell.matrix.MatrixException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) ModelException(cbit.vcell.model.ModelException) DataFormatException(java.util.zip.DataFormatException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) UserCancelException(org.vcell.util.UserCancelException) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 2 with ImageException

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

the class MicroscopyXmlReader method getUShortImage.

/**
 * This method returns a VCIMage object from a XML representation.
 * Creation date: (3/16/2001 3:41:24 PM)
 * @param param org.jdom.Element
 * @return VCImage
 * @throws XmlParseException
 */
private UShortImage getUShortImage(Element param) throws XmlParseException {
    // get the attributes
    Element tempelement = param.getChild(XMLTags.ImageDataTag);
    int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
    int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
    int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
    int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
    final int BYTES_PER_SHORT = 2;
    int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
    // getpixels
    String hexEncodedBytes = tempelement.getText();
    byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
    ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
    InputStream rawInputStream = rawByteArrayInputStream;
    if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
        rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
    }
    byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
    int readCount = 0;
    try {
        while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image pixels: ", e);
    } finally {
        if (rawInputStream != null) {
            try {
                rawInputStream.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
    short[] shortPixels = new short[aNumX * aNumY * aNumZ];
    for (int i = 0; i < shortPixels.length; i++) {
        shortPixels[i] = byteBuffer.getShort();
    }
    Element extentElement = param.getChild(XMLTags.ExtentTag);
    Extent extent = null;
    if (extentElement != null) {
        extent = vcellXMLReader.getExtent(extentElement);
    }
    Element originElement = param.getChild(XMLTags.OriginTag);
    Origin origin = null;
    if (originElement != null) {
        origin = vcellXMLReader.getOrigin(originElement);
    }
    // //set attributes
    // String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
    // String annotation = param.getChildText(XMLTags.AnnotationTag);
    UShortImage newimage;
    try {
        newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image: ", e);
    }
    return newimage;
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) XmlParseException(cbit.vcell.xml.XmlParseException) ByteBuffer(java.nio.ByteBuffer) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with ImageException

use of cbit.image.ImageException 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 4 with ImageException

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

the class ByteImage method getPixelsCompressed.

/**
 * This method was created in VisualAge.
 * @return byte[]
 */
public byte[] getPixelsCompressed() throws ImageException {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DeflaterOutputStream dos = new DeflaterOutputStream(bos);
        // DeflaterOutputStream dos = new DeflaterOutputStream(bos,new Deflater(5,false));
        dos.write(pixels, 0, pixels.length);
        dos.close();
        return bos.toByteArray();
    } catch (IOException e) {
        e.printStackTrace(System.out);
        throw new ImageException(e.getMessage());
    }
}
Also used : ImageException(cbit.image.ImageException) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with ImageException

use of cbit.image.ImageException 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)

Aggregations

ImageException (cbit.image.ImageException)34 IOException (java.io.IOException)11 Extent (org.vcell.util.Extent)11 VCImage (cbit.image.VCImage)10 PropertyVetoException (java.beans.PropertyVetoException)10 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)9 SubVolume (cbit.vcell.geometry.SubVolume)9 SurfaceClass (cbit.vcell.geometry.SurfaceClass)9 ExpressionException (cbit.vcell.parser.ExpressionException)9 DataAccessException (org.vcell.util.DataAccessException)9 Geometry (cbit.vcell.geometry.Geometry)8 Expression (cbit.vcell.parser.Expression)8 VCImageUncompressed (cbit.image.VCImageUncompressed)7 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)7 BioModel (cbit.vcell.biomodel.BioModel)7 GeometryException (cbit.vcell.geometry.GeometryException)7 MathDescription (cbit.vcell.math.MathDescription)7 Origin (org.vcell.util.Origin)7 UserCancelException (org.vcell.util.UserCancelException)7 KeyValue (org.vcell.util.document.KeyValue)7