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;
}
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;
}
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);
}
}
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());
}
}
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.");
}
Aggregations