Search in sources :

Example 11 with ImageException

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();
    }
}
Also used : ImageException(cbit.image.ImageException) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) ExportEvent(cbit.rmi.event.ExportEvent) ExportSpecs(cbit.vcell.export.server.ExportSpecs) DataSetControllerProvider(cbit.vcell.server.DataSetControllerProvider) RequestManager(cbit.vcell.client.RequestManager) JFrame(javax.swing.JFrame) Component(java.awt.Component) VCDataManager(cbit.vcell.simdata.VCDataManager) IOException(java.io.IOException) OutputContext(cbit.vcell.simdata.OutputContext) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyVetoException(java.beans.PropertyVetoException) RequestManagerAdapter(cbit.vcell.client.RequestManagerAdapter) DataViewerManager(cbit.vcell.client.DataViewerManager) DataJobEvent(cbit.rmi.event.DataJobEvent) PDEDataManager(cbit.vcell.simdata.PDEDataManager) SimStatusEvent(cbit.vcell.client.server.SimStatusEvent) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) DataListener(cbit.vcell.simdata.DataListener) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Example 12 with ImageException

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();
            }
        }
    }
}
Also used : DataOutput(org.vcell.workflow.DataOutput) DisplayProfileLikelihoodPlotsOp(org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp) WindowListener(java.awt.event.WindowListener) ImageException(cbit.image.ImageException) WindowAdapter(java.awt.event.WindowAdapter) ProfileData(org.vcell.optimization.ProfileData) IOException(java.io.IOException) Image(cbit.vcell.VirtualMicroscopy.Image) ROI(cbit.vcell.VirtualMicroscopy.ROI) WorkflowDataSource(org.vcell.workflow.WorkflowDataSource) ExpressionException(cbit.vcell.parser.ExpressionException) DataInput(org.vcell.workflow.DataInput) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) WorkflowObject(org.vcell.workflow.WorkflowObject) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 13 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 14 with ImageException

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);
            }
    }
}
Also used : Extent(org.vcell.util.Extent) VCImageUncompressed(cbit.image.VCImageUncompressed) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) DependencyException(org.vcell.util.DependencyException) GifParsingException(cbit.image.GifParsingException) RecordChangedException(cbit.sql.RecordChangedException) ImageException(cbit.image.ImageException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 15 with ImageException

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;
}
Also used : VCPixelClass(cbit.image.VCPixelClass) ImageException(cbit.image.ImageException) Element(org.jdom.Element) VCImageCompressed(cbit.image.VCImageCompressed) PropertyVetoException(java.beans.PropertyVetoException) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion)

Aggregations

ImageException (cbit.image.ImageException)34 IOException (java.io.IOException)11 Extent (org.vcell.util.Extent)11 VCImage (cbit.image.VCImage)10 SubVolume (cbit.vcell.geometry.SubVolume)9 SurfaceClass (cbit.vcell.geometry.SurfaceClass)9 PropertyVetoException (java.beans.PropertyVetoException)9 DataAccessException (org.vcell.util.DataAccessException)9 Geometry (cbit.vcell.geometry.Geometry)8 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)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 ExpressionException (cbit.vcell.parser.ExpressionException)7 Origin (org.vcell.util.Origin)7 UserCancelException (org.vcell.util.UserCancelException)7 KeyValue (org.vcell.util.document.KeyValue)7