Search in sources :

Example 6 with FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec in project vcell by virtualcell.

the class ROIMultiPaintManager method loadFD.

private void loadFD(Hashtable<String, Object> hashTable) throws Exception {
    final Exception[] excHolder = new Exception[] { null };
    final JDialog jDialog = new JDialog(JOptionPane.getFrameForComponent(this.overlayEditorPanelJAI));
    jDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    jDialog.setTitle("Import Type");
    jDialog.setModal(true);
    final JPanel okCancelJPanel = new JPanel(new FlowLayout());
    JButton okJButton = new JButton("from File...");
    okJButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                fdDelta = new double[] { 0, 0, 0 };
                fdDeltaLast = new double[] { 0, 0, 0 };
                currScale = 1.0;
                currScaleLast = 1.0;
                VCDocument.DocumentCreationInfo documentCreationInfo = new VCDocument.DocumentCreationInfo(VCDocumentType.GEOMETRY_DOC, VCDocument.GEOM_OPTION_FILE);
                final AsynchClientTask selectImageFile = ClientRequestManager.getSelectImageFileTask(overlayEditorPanelJAI, null);
                final AsynchClientTask parseImageTask = ClientRequestManager.getParseImageTask(overlayEditorPanelJAI, documentCreationInfo, null);
                final AsynchClientTask importFileImage = ClientRequestManager.getImportFileImageTask(documentCreationInfo);
                // final AsynchClientTask resizeImageTask = ClientRequestManager.getResizeImageTask(documentCreationInfo);
                hashTable.put(ClientRequestManager.GUI_PARENT, ROIMultiPaintManager.this.overlayEditorPanelJAI);
                selectImageFile.run(hashTable);
                parseImageTask.run(hashTable);
                hashTable.put(ClientRequestManager.NEW_IMAGE_SIZE_INFO, hashTable.get(ClientRequestManager.ORIG_IMAGE_SIZE_INFO));
                importFileImage.run(hashTable);
                // resizeImageTask.run(hashTable);
                saveFDUnderlay(hashTable);
            } catch (Exception e1) {
                excHolder[0] = e1;
            // e1.printStackTrace();
            // DialogUtils.showErrorDialog(ROIMultiPaintManager.this.overlayEditorPanelJAI, e1.getMessage());
            } finally {
                jDialog.dispose();
            }
        }
    });
    JButton fdJButton = new JButton("from FieldData...");
    fdJButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                ArrayList<Object[]> allRows = new ArrayList<Object[]>();
                ArrayList<ISize> iSizes = new ArrayList<ISize>();
                ArrayList<CartesianMesh> meshes = new ArrayList<CartesianMesh>();
                // DocumentManager documentManager = documentManager.getSessionManager()..getRequestManager().getDocumentManager();
                FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
                FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
                ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
                Arrays.sort(externalDataIdentifierArr, new Comparator<ExternalDataIdentifier>() {

                    @Override
                    public int compare(ExternalDataIdentifier o1, ExternalDataIdentifier o2) {
                        // TODO Auto-generated method stub
                        return o1.getName().compareToIgnoreCase(o2.getName());
                    }
                });
                ArrayList<ExternalDataIdentifier> okEDI = new ArrayList<ExternalDataIdentifier>();
                for (int i = 0; externalDataIdentifierArr != null && i < externalDataIdentifierArr.length; i++) {
                    try {
                        FieldDataFileOperationSpec fieldDataFileOperationSpec = FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(externalDataIdentifierArr[i].getSimulationKey(), externalDataIdentifierArr[i].getOwner(), externalDataIdentifierArr[i].getJobIndex());
                        FieldDataFileOperationResults fieldDataFileOperationResults = documentManager.fieldDataFileOperation(fieldDataFileOperationSpec);
                        // System.out.println(externalDataIdentifierArr[i].getName()+" "+fieldDataFileOperationResults.iSize);
                        ISize iSize = fieldDataFileOperationResults.iSize;
                        iSizes.add(iSize);
                        // isizes.add(iSize);
                        okEDI.add(externalDataIdentifierArr[i]);
                        allRows.add(new Object[] { iSize.getX(), iSize.getY(), iSize.getZ(), "FieldData='" + externalDataIdentifierArr[i].getName() + "'" });
                        VCImageUncompressed vcImageUnc = new VCImageUncompressed(null, new byte[iSize.getXYZ()], fieldDataFileOperationResults.extent, iSize.getX(), iSize.getY(), iSize.getZ());
                        int dimension = 1 + (iSize.getY() > 1 ? 1 : 0) + (iSize.getZ() > 1 ? 1 : 0);
                        CartesianMesh simpleMesh = CartesianMesh.createSimpleCartesianMesh(fieldDataFileOperationResults.origin, fieldDataFileOperationResults.extent, iSize, new RegionImage(vcImageUnc, dimension, fieldDataFileOperationResults.extent, fieldDataFileOperationResults.origin, RegionImage.NO_SMOOTHING));
                        meshes.add(simpleMesh);
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
                if (allRows.size() > 0) {
                    Object[][] rowData = allRows.toArray(new Object[0][]);
                    int[] selections = DialogUtils.showComponentOKCancelTableList(ROIMultiPaintManager.this.overlayEditorPanelJAI, "Select Simulation for Geom Size", new String[] { "X", "Y", "Z", "Name" }, rowData, ListSelectionModel.SINGLE_SELECTION);
                    if (selections != null && selections.length == 1) {
                        FieldDataFileOperationResults fdfor = documentManager.fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(okEDI.get(selections[0]).getSimulationKey(), okEDI.get(selections[0]).getOwner(), okEDI.get(selections[0]).getJobIndex()));
                        SimDataBlock simDataBlock = VCellClientTest.getVCellClient().getClientServerManager().getDataSetController().getSimDataBlock(null, okEDI.get(selections[0]), fdfor.dataIdentifierArr[0].getName(), 0.0);
                        FieldDataFileOperationSpec fieldDataFileOperationSpec = new FieldDataFileOperationSpec();
                        fieldDataFileOperationSpec.isize = meshes.get(selections[0]).getISize();
                        fieldDataFileOperationSpec.shortSpecData = new short[][][] { { new short[fieldDataFileOperationSpec.isize.getXYZ()] } };
                        for (int i = 0; i < simDataBlock.getData().length; i++) {
                            fieldDataFileOperationSpec.shortSpecData[0][0][i] = (short) simDataBlock.getData()[i];
                        // if(simDataBlock.getData()[i] != 0) {
                        // System.out.println(simDataBlock.getData()[i]);
                        // }
                        }
                        hashTable.put(ClientRequestManager.FDFOS, fieldDataFileOperationSpec);
                        hashTable.put(ClientRequestManager.IMPORT_SOURCE_NAME, "FieldData=" + okEDI.get(selections[0]).getName());
                        saveFDUnderlay(hashTable);
                    // ROIMultiPaintManager.this.fdShort = (FieldDataFileOperationSpec)hashTable.get(ClientRequestManager.FDFOS);
                    // ROIMultiPaintManager.this.importSourceName = (String)hashTable.get(ClientRequestManager.IMPORT_SOURCE_NAME);
                    // (outMax-outMin)(inVal - inMin)
                    // ------------------------------ + outMin
                    // inMax - inMin
                    // externalDataIdentifierArr[selections[0]].
                    // //						ImageSizeInfo imagesizeInfo = new ImageSizeInfo("internal",meshes.get(selections[0]).getISize(),1,new double[] {0},0);
                    // ImageSizeInfo imagesizeInfo = new ImageSizeInfo("internal",iSizes.get(selections[0]),1,new double[] {0},0);
                    // hashTable.put(ClientRequestManager.NEW_IMAGE_SIZE_INFO, imagesizeInfo);
                    // 
                    // VCImage image = sourceGeom.getGeometrySpec().getImage();
                    // ISize samplingSize = new ISize(image.getNumX(),image.getNumY(),image.getNumZ());//
                    // VCImageUncompressed vcImageUnc = new VCImageUncompressed(null, new byte[samplingSize.getXYZ()], sourceGeom.getExtent(), samplingSize.getX(), samplingSize.getY(), samplingSize.getZ());
                    // CartesianMesh sourceMesh = CartesianMesh.createSimpleCartesianMesh(
                    // sourceGeom.getOrigin(),
                    // sourceGeom.getExtent(),
                    // samplingSize,
                    // new RegionImage(vcImageUnc, sourceGeom.getDimension(), sourceGeom.getExtent(), sourceGeom.getOrigin(), RegionImage.NO_SMOOTHING));
                    // 
                    // hashTable.put("newMesh", meshes.get(selections[0]));
                    // hashTable.put("sourceMesh", sourceMesh);
                    }
                }
            } catch (Exception e1) {
                excHolder[0] = e1;
            // e1.printStackTrace();
            // DialogUtils.showErrorDialog(ROIMultiPaintManager.this.overlayEditorPanelJAI, e1.getMessage());
            } finally {
                jDialog.dispose();
            }
        }
    });
    JButton clipbboardJButton = new JButton("from Clipboard");
    clipbboardJButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
            try {
                Object transferData = contents.getTransferData(DataFlavor.stringFlavor);
                if (transferData instanceof String) {
                    StringTokenizer st = new StringTokenizer(((String) transferData).toString(), ",");
                    String varName = st.nextToken();
                    String vcDataIdentifer = st.nextToken();
                    double timePoint = Double.parseDouble(st.nextToken());
                    ISize isize = new ISize(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
                    Range inRange = new Range(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
                    String simDataFile = st.nextToken();
                    DataInputStream dis = new DataInputStream(new FileInputStream(simDataFile));
                    FieldDataFileOperationSpec fieldDataFileOperationSpec = new FieldDataFileOperationSpec();
                    fieldDataFileOperationSpec.isize = isize;
                    fieldDataFileOperationSpec.shortSpecData = new short[][][] { { new short[fieldDataFileOperationSpec.isize.getXYZ()] } };
                    double outMax = 65535;
                    double outMin = 0;
                    double scale = (outMax - outMin) / (inRange.getMax() - inRange.getMin());
                    for (int i = 0; i < isize.getXYZ(); i++) {
                        double val = dis.readDouble();
                        fieldDataFileOperationSpec.shortSpecData[0][0][i] = (short) (scale * (val - inRange.getMin()) + outMin);
                    }
                    hashTable.put(ClientRequestManager.FDFOS, fieldDataFileOperationSpec);
                    hashTable.put(ClientRequestManager.IMPORT_SOURCE_NAME, "SimData=" + vcDataIdentifer + " varName=" + varName + " time=" + timePoint);
                    saveFDUnderlay(hashTable);
                    ROIMultiPaintManager.this.overlayEditorPanelJAI.setFDScale(new double[] { scale, inRange.getMin(), outMin });
                }
            } catch (Exception e1) {
                excHolder[0] = e1;
            // e1.printStackTrace();
            // DialogUtils.showErrorDialog(ROIMultiPaintManager.this.overlayEditorPanelJAI, e1.getMessage());
            } finally {
                jDialog.dispose();
            }
        }
    });
    final boolean[] bCanelHolder = new boolean[] { false };
    JButton cancelJButton = new JButton("Cancel");
    cancelJButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jDialog.dispose();
            bCanelHolder[0] = true;
        }
    });
    okCancelJPanel.add(okJButton);
    okCancelJPanel.add(fdJButton);
    okCancelJPanel.add(clipbboardJButton);
    okCancelJPanel.add(cancelJButton);
    jDialog.getContentPane().add(okCancelJPanel, BorderLayout.SOUTH);
    jDialog.pack();
    // jDialog.setSize(300,250);
    DialogUtils.showModalJDialogOnTop(jDialog, overlayEditorPanelJAI);
    if (bCanelHolder[0]) {
        throw UserCancelException.CANCEL_GENERIC;
    }
    if (excHolder[0] != null) {
        throw excHolder[0];
    }
}
Also used : JPanel(javax.swing.JPanel) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) SimDataBlock(cbit.vcell.simdata.SimDataBlock) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec) FieldDataFileOperationResults(cbit.vcell.field.io.FieldDataFileOperationResults) VCDocument(org.vcell.util.document.VCDocument) Transferable(java.awt.datatransfer.Transferable) VCImageUncompressed(cbit.image.VCImageUncompressed) Range(org.vcell.util.Range) DataInputStream(java.io.DataInputStream) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) FileInputStream(java.io.FileInputStream) CartesianMesh(cbit.vcell.solvers.CartesianMesh) StringTokenizer(java.util.StringTokenizer) ActionListener(java.awt.event.ActionListener) RegionImage(cbit.vcell.geometry.RegionImage) JDialog(javax.swing.JDialog)

Example 7 with FieldDataDBOperationSpec

use of cbit.vcell.field.FieldDataDBOperationSpec in project vcell by virtualcell.

the class VFrapXmlHelper method isAlreadyImported.

// double[] firstPostBleach = null;
// double[] prebleachAvg = null;
// BufferedImage[] roiComposite = null;
// 
// public double[] getFirstPostBleach() {
// if(firstPostBleach == null) {
// throw new RuntimeException("Missing vFrap FirstPostbleach Image");
// } else {
// return firstPostBleach;
// }
// }
// public double[] getPrebleachAvg() {
// if(prebleachAvg == null) {
// throw new RuntimeException("Missing vFrap PrebleachAverage Image");
// } else {
// return prebleachAvg;
// }
// }
// public BufferedImage[] getRoiComposite() {
// if(roiComposite == null) {
// throw new RuntimeException("Missing vFrap RoiComposite Image");
// } else {
// return roiComposite;
// }
// }
public static boolean isAlreadyImported(String candidateName, DocumentManager documentManager) throws DataAccessException {
    FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
    FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
    ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
    for (ExternalDataIdentifier edi : externalDataIdentifierArr) {
        if (candidateName.equals(edi.getName())) {
            return true;
        }
    }
    return false;
}
Also used : ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec)

Aggregations

FieldDataDBOperationSpec (cbit.vcell.field.FieldDataDBOperationSpec)7 FieldDataDBOperationResults (cbit.vcell.field.FieldDataDBOperationResults)6 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)5 UserCancelException (org.vcell.util.UserCancelException)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)3 RegionImage (cbit.vcell.geometry.RegionImage)3 ImageException (cbit.image.ImageException)2 DocumentManager (cbit.vcell.clientdb.DocumentManager)2 FieldDataFileOperationResults (cbit.vcell.field.io.FieldDataFileOperationResults)2 XmlParseException (cbit.vcell.xml.XmlParseException)2 Hashtable (java.util.Hashtable)2 DataFormatException (java.util.zip.DataFormatException)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 DataAccessException (org.vcell.util.DataAccessException)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 UtilCancelException (org.vcell.util.UtilCancelException)2 VCImageUncompressed (cbit.image.VCImageUncompressed)1 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)1