use of cbit.image.ImageException in project vcell by virtualcell.
the class DisplayTimeSeriesOp method displayImageTimeSeries.
public void displayImageTimeSeries(final ImageTimeSeries<? extends Image> imageTimeSeries, final String title, final WindowListener windowListener) throws ImageException, IOException {
try {
System.out.println("starting to prepare data for time series viewing");
final PDEDataViewer pdeDataViewer = new PDEDataViewer();
DataSetControllerProvider dataSetControllerProvider;
try {
dataSetControllerProvider = getDataSetControllerProvider(imageTimeSeries, pdeDataViewer);
} catch (ImageException | IOException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
}
VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
final VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public User getOwner() {
return new User("nouser", null);
}
public KeyValue getDataKey() {
return null;
}
public String getID() {
return "mydata";
}
};
PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
final ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
final RequestManager requestManager = new RequestManagerAdapter() {
};
final DataViewerManager dataViewerManager = new DataViewerManager() {
public void dataJobMessage(DataJobEvent event) {
}
public void exportMessage(ExportEvent event) {
}
public void addDataListener(DataListener newListener) {
}
public UserPreferences getUserPreferences() {
// getRequestManager().getUserPreferences();
return null;
}
public void removeDataListener(DataListener newListener) {
}
public void startExport(Component requester, OutputContext outputContext, ExportSpecs exportSpecs) {
// getLocalRequestManager().startExport(outputContext, FieldDataWindowManager.this, exportSpecs);
}
public void simStatusChanged(SimStatusEvent simStatusEvent) {
}
public User getUser() {
return new User("dummy", new KeyValue("123"));
// return getRequestManager().getDocumentManager().getUser();
}
public RequestManager getRequestManager() {
return requestManager;
}
};
System.out.println("ready to display time series");
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
JFrame jframe = new TopLevelFrame();
jframe.setTitle(title);
jframe.getContentPane().add(pdeDataViewer);
jframe.setSize(1000, 600);
jframe.setVisible(true);
if (windowListener != null) {
jframe.addWindowListener(windowListener);
}
try {
pdeDataViewer.setDataViewerManager(dataViewerManager);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
});
} catch (InvocationTargetException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of cbit.image.ImageException in project vcell by virtualcell.
the class WorkflowObjectsPanel method displayData.
private void displayData(TaskContext taskContext, WorkflowObject workflowObject) {
if (workflowObject instanceof DataInput || workflowObject instanceof DataOutput) {
String title = parametersFunctionsTableModel.getName(workflowObject);
WindowListener listener = new WindowAdapter() {
};
Object data = null;
if (workflowObject instanceof WorkflowDataSource) {
WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
data = taskContext.getRepository().getData(dataHolder);
} else if (workflowObject instanceof DataInput) {
DataInput dataInput = (DataInput) workflowObject;
data = taskContext.getData(dataInput);
}
if (data instanceof RowColumnResultSet) {
RowColumnResultSet rc = (RowColumnResultSet) data;
try {
new DisplayPlotOp().displayPlot(rc, title, listener);
} catch (ExpressionException e) {
e.printStackTrace();
}
} else if (data instanceof ROI) {
ROI roi = (ROI) data;
Image image = roi.getRoiImages()[0];
new DisplayImageOp().displayImage(image, title, listener);
} else if (data instanceof ProfileData[]) {
ProfileData[] profileData = (ProfileData[]) data;
new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(profileData, title, listener);
} else if (data instanceof Image) {
Image image = (Image) data;
new DisplayImageOp().displayImage(image, title, listener);
} else if (data instanceof ImageTimeSeries) {
ImageTimeSeries imageTimeSeries = (ImageTimeSeries) data;
try {
DisplayTimeSeries.displayImageTimeSeries(imageTimeSeries, title, listener);
} catch (ImageException | IOException e) {
e.printStackTrace();
}
}
}
}
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 GeomDbDriver method insertBrowseImageDataSQL.
/**
* This method was created in VisualAge.
* @param vcimage cbit.image.VCImage
* @param userid java.lang.String
* @exception java.rmi.RemoteException The exception description.
*/
private void insertBrowseImageDataSQL(Connection con, KeyValue key, KeyValue imageKey, VCImage image) throws SQLException, DataAccessException, ImageException, GifParsingException {
String sql;
sql = "INSERT INTO " + browseImageDataTable.getTableName() + " " + browseImageDataTable.getSQLColumnList() + " VALUES " + browseImageDataTable.getSQLValueList(key, imageKey, dbSyntax);
// System.out.println(sql);
byte[] gifEncodedImage = null;
try {
if (image != null) {
if (image.getNumZ() > 1) {
byte[] sliceBytes = new byte[image.getNumX() * image.getNumY()];
System.arraycopy(image.getPixels(), 0, sliceBytes, 0, sliceBytes.length);
gifEncodedImage = BrowseImage.makeBrowseGIFImage(new VCImageUncompressed(null, sliceBytes, new Extent(1, 1, 1), image.getNumX(), image.getNumY(), 1)).getGifEncodedData();
} else {
gifEncodedImage = BrowseImage.makeBrowseGIFImage(image).getGifEncodedData();
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (gifEncodedImage == null) {
gifEncodedImage = BrowseImage.makeBrowseGIFImage(new VCImageUncompressed(null, new byte[BrowseImage.BROWSE_XSIZE * BrowseImage.BROWSE_YSIZE], new Extent(1, 1, 1), BrowseImage.BROWSE_XSIZE, BrowseImage.BROWSE_YSIZE, 1)).getGifEncodedData();
}
switch(dbSyntax) {
case ORACLE:
{
updateCleanSQL(con, sql);
updateCleanLOB(con, browseImageDataTable.id.toString(), key, browseImageDataTable.tableName, browseImageDataTable.data, gifEncodedImage, dbSyntax);
break;
}
case POSTGRES:
{
updatePreparedCleanSQL(con, sql, gifEncodedImage);
break;
}
default:
{
throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
}
}
}
use of cbit.image.ImageException in project vcell by virtualcell.
the class XmlReader method getVCImage.
/**
* This method returns a VCIMage object from a XML representation.
* Creation date: (3/16/2001 3:41:24 PM)
* @return VCImage
* @param param org.jdom.Element
*/
VCImage getVCImage(Element param, Extent extent) throws XmlParseException {
// try to get metadata(version)
Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// get the attributes
Element tempelement = param.getChild(XMLTags.ImageDataTag, vcNamespace);
int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
// getpixels
String temp = tempelement.getText();
// decode
byte[] data = Hex.toBytes(temp);
// create the VCImage object
VCImageCompressed newimage = null;
try {
newimage = new VCImageCompressed(version, data, extent, aNumX, aNumY, aNumZ);
} catch (ImageException e) {
e.printStackTrace();
throw new XmlParseException("An imageException occurred while trying to create a VCImage!", e);
}
// set attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
try {
newimage.setName(name);
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// newimage.setDescription(unMangle(annotation));
// }
// read the annotation
String annotation = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotation != null && annotation.length() > 0) {
newimage.setDescription(unMangle(annotation));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
// get PixelClasses
List<Element> pixelClassList = param.getChildren(XMLTags.PixelClassTag, vcNamespace);
if (pixelClassList.size() != 0) {
VCPixelClass[] pixelClassArray = new VCPixelClass[pixelClassList.size()];
int pixelClassCounter = 0;
for (Element pcElement : pixelClassList) {
pixelClassArray[pixelClassCounter] = getPixelClass(pcElement);
pixelClassCounter++;
}
try {
newimage.setPixelClasses(pixelClassArray);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
} else {
// Invalid format
System.out.println("Format Error! No <PixelClass> references found inside <Image name=\"" + name + "\">!");
System.out.println("Valid format for images is:");
System.out.println("<Image Name=\"??\">");
System.out.println(" <ImageData Z=\"?\" Y=\"?\" Z=\"?\" CompressedSize=\"?\">");
System.out.println(" ......Image content...");
System.out.println(" </ImageData>");
System.out.println(" <PixelClass Name=\"?\" ImagePixelValue=\"?\"/>");
System.out.println(" ...");
System.out.println(" <PixelClass Name=\"?\" ImagePixelValue=\"?\"/>");
System.out.println(" <Version Name=\"?\"/>");
System.out.println("</Image>");
throw new XmlParseException("Invalid VCML format error!\nNo <PixelClass> references found inside <Image name=\"" + name + "\">!");
}
return newimage;
}
Aggregations