Search in sources :

Example 11 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class MathModelEditor method setMathModelWindowManager.

/**
 * Insert the method's description here.
 * Creation date: (5/7/2004 5:40:13 PM)
 * @param newBioModelWindowManager cbit.vcell.client.desktop.BioModelWindowManager
 */
public void setMathModelWindowManager(MathModelWindowManager newValue) {
    if (this.mathModelWindowManager == newValue) {
        return;
    }
    this.mathModelWindowManager = newValue;
    geometryViewer.addActionListener(mathModelWindowManager);
    mathModelPropertiesPanel.setMathModelWindowManager(mathModelWindowManager);
    simulationListPanel.setSimulationWorkspace(mathModelWindowManager.getSimulationWorkspace());
    DatabaseWindowManager dbWindowManager = new DatabaseWindowManager(databaseWindowPanel, mathModelWindowManager.getRequestManager());
    databaseWindowPanel.setDatabaseWindowManager(dbWindowManager);
    DocumentManager documentManager = mathModelWindowManager.getRequestManager().getDocumentManager();
    databaseWindowPanel.setDocumentManager(documentManager);
    geometryMetaDataPanel.setDocumentManager(documentManager);
    updateGeometryViewerOwner();
}
Also used : DocumentManager(cbit.vcell.clientdb.DocumentManager) DatabaseWindowManager(cbit.vcell.client.DatabaseWindowManager)

Example 12 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class PointSpreadFunctionManagement method importPointSpreadFunction.

public void importPointSpreadFunction() {
    AsynchClientTask[] taskArray = new AsynchClientTask[3];
    // select the desired PSF file
    taskArray[0] = new AsynchClientTask("Select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ChoosePSFFile(hashTable);
        }
    };
    // create and save the field data object
    taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Component requesterComponent = parentWindow;
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
            DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (documentManager == null) {
                throw new RuntimeException("Not connected to server.");
            }
            // the following line of code may modify initialFieldDataName
            // normal file name
            checkNameAvailability(hashTable, false, documentManager, requesterComponent);
            File filePSF = (File) hashTable.get("filePSF");
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            ImageDataset imageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(filePSF.getAbsolutePath(), null);
            Extent extent = imageDataset.getExtent();
            ISize isize = imageDataset.getISize();
            Origin origin = new Origin(0, 0, 0);
            CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
            // save field data
            int NumTimePoints = imageDataset.getImageTimeStamps().length;
            int NumChannels = 1;
            double[][][] pixData = new double[NumTimePoints][NumChannels][];
            for (int i = 0; i < NumTimePoints; i++) {
                // images according to zIndex at specific time points(tIndex)
                short[] originalData = imageDataset.getPixelsZ(0, i);
                double[] doubleData = new double[originalData.length];
                for (int j = 0; j < originalData.length; j++) {
                    doubleData[j] = 0x0000ffff & originalData[j];
                }
                pixData[i][NumChannels - 1] = doubleData;
            }
            FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
            // try {
            // fdos = ClientRequestManager.createFDOSFromImageFile(filePSF, false, null);
            // } catch (DataFormatException ex) {
            // throw new Exception("Cannot read image " + filePSF.getAbsolutePath()+"\n"+ex.getMessage());
            // }
            fdos.owner = documentManager.getUser();
            fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
            fdos.cartesianMesh = cartesianMesh;
            fdos.doubleSpecData = pixData;
            fdos.specEDI = null;
            fdos.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
            fdos.times = imageDataset.getImageTimeStamps();
            fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
            fdos.origin = origin;
            fdos.extent = extent;
            fdos.isize = isize;
            ExternalDataIdentifier pSFImageEDI = documentManager.saveFieldData(fdos, initialFieldDataName);
            hashTable.put("pSFImageEDI", pSFImageEDI);
        }
    };
    // create a data symbol for the PSF image saved above as field data
    taskArray[2] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // --- create the data symbols associated with the time series
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            ExternalDataIdentifier pSFImageEDI = (ExternalDataIdentifier) hashTable.get("pSFImageEDI");
            String fluorName = "psf_" + initialFieldDataName;
            DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.POINT_SPREAD_FUNCTION, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), pSFImageEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), 0D);
            simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
        }
    };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    ClientTaskDispatcher.dispatch(parentWindow, hash, taskArray, false, true, null);
}
Also used : Origin(org.vcell.util.Origin) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) VariableType(cbit.vcell.math.VariableType) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) VCImageUncompressed(cbit.image.VCImageUncompressed) ImageException(cbit.image.ImageException) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol) DataSymbol(cbit.vcell.data.DataSymbol) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Component(java.awt.Component) ImageFile(cbit.image.ImageFile) File(java.io.File) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol)

Example 13 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class DataSymbolsPanel method addVFrapOriginalImages.

private void addVFrapOriginalImages() {
    // add dataset (normal images) from vFrap
    AsynchClientTask[] taskArray = new AsynchClientTask[5];
    // select the desired vfrap file
    taskArray[0] = ChooseVFrapFile();
    taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            File vFrapFile = (File) hashTable.get("vFrapFile");
            Component requesterComponent = DataSymbolsPanel.this;
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
            DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (documentManager == null) {
                throw new RuntimeException("Not connected to server.");
            }
            // ex  ccc8.vfrap
            String vFrapFileNameExtended = vFrapFile.getName();
            {
                // we want to make sure to reload these strings from the hash later on
                String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
                // we'll save here the "special" vFrap images (prebleach_avg, ...)
                String mixedFieldDataName = initialFieldDataName + "Mx";
                hashTable.put("initialFieldDataName", initialFieldDataName);
                hashTable.put("mixedFieldDataName", mixedFieldDataName);
            }
            if (vFrapFileNameExtended.indexOf(".vfrap") <= -1) {
                throw new RuntimeException("File extension must be .vfrap");
            }
            // normal images
            checkNameAvailability(hashTable, false, documentManager, requesterComponent);
            // ----- read needed info from Virtual FRAP xml file
            System.out.println("Loading " + vFrapFileNameExtended + " ...");
            String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
            MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
            Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
            // loading frap images
            AnnotatedImageDataset annotatedImages = xmlReader.getAnnotatedImageDataset(vFrapRoot, null);
            hashTable.put("annotatedImages", annotatedImages);
            // loading ROIs for display purposes only (see next task)
            ROI[] rois = xmlReader.getPrimaryROIs(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
            LoadVFrapDisplayRoi(hashTable, annotatedImages, rois);
        // Calendar cal = Calendar.getInstance();
        // SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
        // DocumentWindow documentWindow = (DocumentWindow)BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
        // DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
        // VFrapXmlHelper vFrapXmlHelper = new VFrapXmlHelper();
        // if(vFrapXmlHelper.isAlreadyImported(vFrapFileName, documentManager)) {
        // throw new RuntimeException("FieldData name already in use.");
        // }
        // //				bioModel.setName(vFrapFileName + "-" + sdf.format(cal.getTime()));
        // bioModel.setName(vFrapFileName);
        // BioModel feedbackModel =  documentManager.save(bioModel, null);
        // BioModelChildSummary  childSummary = BioModelChildSummary.fromDatabaseSerialization(xmlString);
        // BioModelInfo biomodelInfo = new BioModelInfo(feedbackModel.getVersion(), feedbackModel.getVersion().getVersionKey(), childSummary );
        // documentWindow.getTopLevelWindowManager().getRequestManager().openDocument(biomodelInfo, documentWindow.getTopLevelWindowManager(), true);
        }
    };
    // show the images from the vfrap file in an OverlayEditorPanelJAI dialog
    taskArray[2] = new AsynchClientTask("Display images", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            if (initialFieldDataName.equals("")) {
                JOptionPane.showMessageDialog(DataSymbolsPanel.this, "Field Data name " + initialFieldDataName + " already in use.");
                // prevents the rest of tasks below from running
                throw UserCancelException.CANCEL_GENERIC;
            }
            AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
            BufferedImage[] displayROI = (BufferedImage[]) hashTable.get("displayROI");
            if (annotatedImages == null || displayROI == null) {
                return;
            }
            // display the images
            OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI();
            overlayPanel.setAllowAddROI(false);
            ImageDataset imageDataset = annotatedImages.getImageDataset();
            overlayPanel.setImages(imageDataset, 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200));
            overlayPanel.setAllROICompositeImage(displayROI, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
            int choice = DialogUtils.showComponentOKCancelDialog(DataSymbolsPanel.this, overlayPanel, "vFrap Field Data");
            if (choice != JOptionPane.OK_OPTION) {
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
    };
    // save the timepoints from memory to the database as field data
    taskArray[3] = new AsynchClientTask("Saving time series data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
            DocumentManager dm = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (dm == null) {
                throw new RuntimeException("Not connected to server.");
            }
            User owner = null;
            Version version = simulationContext.getVersion();
            if (version == null) {
                // new document, so the owner is the user
                owner = dm.getUser();
            } else {
                owner = simulationContext.getVersion().getOwner();
            }
            // mesh
            ImageDataset imageDataset = annotatedImages.getImageDataset();
            Extent extent = imageDataset.getExtent();
            ISize isize = imageDataset.getISize();
            Origin origin = new Origin(0, 0, 0);
            CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
            // save field data
            int NumTimePoints = imageDataset.getImageTimeStamps().length;
            int NumChannels = 1;
            double[][][] pixData = new double[NumTimePoints][NumChannels][];
            for (int i = 0; i < NumTimePoints; i++) {
                // images according to zIndex at specific time points(tIndex)
                short[] originalData = imageDataset.getPixelsZ(0, i);
                double[] doubleData = new double[originalData.length];
                for (int j = 0; j < originalData.length; j++) {
                    doubleData[j] = 0x0000ffff & originalData[j];
                }
                pixData[i][NumChannels - 1] = doubleData;
            }
            FieldDataFileOperationSpec timeSeriesFieldDataOpSpec = new FieldDataFileOperationSpec();
            timeSeriesFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
            timeSeriesFieldDataOpSpec.cartesianMesh = cartesianMesh;
            timeSeriesFieldDataOpSpec.doubleSpecData = pixData;
            timeSeriesFieldDataOpSpec.specEDI = null;
            timeSeriesFieldDataOpSpec.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
            timeSeriesFieldDataOpSpec.owner = owner;
            timeSeriesFieldDataOpSpec.times = imageDataset.getImageTimeStamps();
            timeSeriesFieldDataOpSpec.variableTypes = new VariableType[] { VariableType.VOLUME };
            timeSeriesFieldDataOpSpec.origin = origin;
            timeSeriesFieldDataOpSpec.extent = extent;
            timeSeriesFieldDataOpSpec.isize = isize;
            // realignment for the case when first timepoint is not zero
            if (timeSeriesFieldDataOpSpec.times[0] != 0) {
                double shift = timeSeriesFieldDataOpSpec.times[0];
                for (int i = 0; i < NumTimePoints; i++) {
                    timeSeriesFieldDataOpSpec.times[i] -= shift;
                }
            }
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyMMMdd_hhmmss");
            String formattedDate = sdf.format(cal.getTime());
            hashTable.put("formattedDate", formattedDate);
            // ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec,
            // initialFieldDataName + "_" + formattedDate);
            ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec, initialFieldDataName);
            hashTable.put("imageDataset", imageDataset);
            hashTable.put("timeSeriesEDI", timeSeriesEDI);
        }
    };
    // create the data symbols for the images saved above and display them in the tree/table
    taskArray[4] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // --- create the data symbols associated with the time series
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            ImageDataset imageDataset = (ImageDataset) hashTable.get("imageDataset");
            ExternalDataIdentifier timeSeriesEDI = (ExternalDataIdentifier) hashTable.get("timeSeriesEDI");
            for (double time : imageDataset.getImageTimeStamps()) {
                // String fluorName = TokenMangler.fixTokenStrict("fluor_"+time+"_");
                // while (simulationContext.getDataContext().getDataSymbol(fluorName)!=null){
                // fluorName = TokenMangler.getNextEnumeratedToken(fluorName);
                // }
                // max time interval we can display is about 11 days
                DecimalFormat df = new DecimalFormat("###000.00");
                // String fluorName = "fluor_" + df.format(time) + "_" + formattedDate;
                String fluorName = "fluor_" + df.format(time).substring(0, df.format(time).indexOf(".")) + "s" + df.format(time).substring(1 + df.format(time).indexOf(".")) + "_" + initialFieldDataName;
                // FieldFunctionArguments fluorFFArgs = new FieldFunctionArguments(timeSeriesEDI.getName(), fluorName, new Expression(time), VariableType.VOLUME);
                DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.VFRAP_TIMEPOINT, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), timeSeriesEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), time);
                simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
            }
        }
    };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    ClientTaskDispatcher.dispatch(this, hash, taskArray, false, true, null);
// String name = null;
// try {
// getNewDataSymbolPanel().setSymbolName("");
// getNewDataSymbolPanel().setSymbolExpression("vcField(dataset1,var1,0.0,Volume)");
// int newSettings = org.vcell.util.gui.DialogUtils.showComponentOKCancelDialog(this, getNewDataSymbolPanel(), "New DataSymbol");
// if (newSettings == JOptionPane.OK_OPTION) {
// name = getNewDataSymbolPanel().getSymbolName();
// String expression = getNewDataSymbolPanel().getSymbolExpression();
// Expression exp = new Expression(expression);
// FunctionInvocation[] functionInvocations = exp.getFunctionInvocations(null);
// //			DataSymbol ds = new FieldDataSymbol(DataSymbolType.GENERIC_SYMBOL, name, "",
// //					simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD,
// //					new FieldFunctionArguments(functionInvocations[0]));
// DataSymbol ds = new FieldDataSymbol(name, DataSymbolType.GENERIC_SYMBOL,
// simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD);
// simulationContext.getDataContext().addDataSymbol(ds);
// }
// } catch (java.lang.Throwable ivjExc) {
// DialogUtils.showErrorDialog(this, "Data symbol " + name + " already exists");
// }
}
Also used : Origin(org.vcell.util.Origin) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) User(org.vcell.util.document.User) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) Element(org.jdom.Element) DecimalFormat(java.text.DecimalFormat) BufferedImage(java.awt.image.BufferedImage) Version(org.vcell.util.document.Version) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Component(java.awt.Component) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) Calendar(java.util.Calendar) DocumentManager(cbit.vcell.clientdb.DocumentManager) VCImageUncompressed(cbit.image.VCImageUncompressed) UserCancelException(org.vcell.util.UserCancelException) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) MicroscopyXmlReader(cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol) DataSymbol(cbit.vcell.data.DataSymbol) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage) File(java.io.File) OverlayEditorPanelJAI(cbit.vcell.geometry.gui.OverlayEditorPanelJAI) SimpleDateFormat(java.text.SimpleDateFormat) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol)

Example 14 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class DataSymbolsPanel method addVFrapDerivedImages.

private void addVFrapDerivedImages() {
    // add special (computed) images from vFrap
    AsynchClientTask[] taskArray = new AsynchClientTask[5];
    // select the desired vfrap file
    taskArray[0] = ChooseVFrapFile();
    // load the images from the vfrap file, compute derived images, store them all in memory
    taskArray[1] = new AsynchClientTask("Import images", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            File vFrapFile = (File) hashTable.get("vFrapFile");
            Component requesterComponent = DataSymbolsPanel.this;
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
            DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (documentManager == null) {
                throw new RuntimeException("Not connected to server.");
            }
            // ex  ccc8.vfrap
            String vFrapFileNameExtended = vFrapFile.getName();
            {
                // we want to make sure to reload these strings from the hash later on
                String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
                // we'll save here the "special" vFrap images (prebleach_avg, ...)
                String mixedFieldDataName = initialFieldDataName + "Mx";
                hashTable.put("initialFieldDataName", initialFieldDataName);
                hashTable.put("mixedFieldDataName", mixedFieldDataName);
            }
            if (vFrapFileNameExtended.indexOf(".vfrap") <= -1) {
                throw new RuntimeException("File extension must be .vfrap");
            }
            // for derived images and ROIs
            checkNameAvailability(hashTable, true, documentManager, requesterComponent);
            // ----- read needed info from Virtual FRAP xml file
            System.out.println("Loading " + vFrapFileNameExtended + " ...");
            String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
            MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
            Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
            // loading frap images and a ROIs subset for display purposes only (see next task)
            AnnotatedImageDataset annotatedImages = xmlReader.getAnnotatedImageDataset(vFrapRoot, null);
            hashTable.put("annotatedImages", annotatedImages);
            ROI[] rois = xmlReader.getPrimaryROIs(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
            LoadVFrapDisplayRoi(hashTable, annotatedImages, rois);
            // ------ locate the special images within the vFrap files and load them in memory
            if (!LoadVFrapSpecialImages(hashTable, vFrapRoot)) {
                throw new RuntimeException("Unable to recover derived images from vFrap.");
            }
        // int startingIndexRecovery = xmlReader.getStartindIndexForRecovery(XmlUtil.stringToXML(xmlString, null).getRootElement());
        // vFrapXmlHelper.LoadVFrapSpecialImages(annotatedImages, startingIndexRecovery);	// prebleach average and first postbleach
        // vFrapXmlHelper.LoadVFrapRoiCompositeImages(annotatedImages, rois);
        }
    };
    // show the images from the vfrap file in an OverlayEditorPanelJAI dialog
    taskArray[2] = new AsynchClientTask("Display images", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            String mixedFieldDataName = (String) hashTable.get("mixedFieldDataName");
            if (mixedFieldDataName.equals("")) {
                JOptionPane.showMessageDialog(DataSymbolsPanel.this, "Field Data name " + mixedFieldDataName + " already in use.");
                // prevents the rest of tasks below from running
                throw UserCancelException.CANCEL_GENERIC;
            }
            AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
            BufferedImage[] displayROI = (BufferedImage[]) hashTable.get("displayROI");
            if (annotatedImages == null || displayROI == null) {
                return;
            }
            // display the images
            OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI();
            overlayPanel.setAllowAddROI(false);
            ImageDataset imageDataset = annotatedImages.getImageDataset();
            overlayPanel.setImages(imageDataset, 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200));
            overlayPanel.setAllROICompositeImage(displayROI, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
            int choice = DialogUtils.showComponentOKCancelDialog(DataSymbolsPanel.this, overlayPanel, "vFrap Field Data");
            if (choice != JOptionPane.OK_OPTION) {
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
    };
    // save the ROIs, prebleach average and the first postbleach frame from memory to the database as field data
    taskArray[3] = new AsynchClientTask("Saving roi masks, pre-bleach average and first post-bleach", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Component requesterComponent = DataSymbolsPanel.this;
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
            DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (documentManager == null) {
                throw new RuntimeException("Not connected to server.");
            }
            ExternalDataIdentifier derivedEDI = SaveVFrapSpecialImagesAsFieldData(hashTable, documentManager);
            hashTable.put("derivedEDI", derivedEDI);
        }
    };
    // create the data symbols for the images saved above and display them in the tree/table
    taskArray[4] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ExternalDataIdentifier derivedEDI = (ExternalDataIdentifier) hashTable.get("derivedEDI");
            BioModel bioModel = simulationContext.getBioModel();
            CreateSaveVFrapDataSymbols(hashTable, bioModel, derivedEDI);
        }
    };
    // save the ROIs, prebleach average and the first postbleach frame from memory to the database as field data
    // taskArray[4] = new AsynchClientTask("Saving roi masks, pre-bleach average and first post-bleach", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
    // public void run(Hashtable<String, Object> hashTable) throws Exception {
    // File vFrapFile = (File)hashTable.get("vFrapFile");
    // if(vFrapFile == null) {
    // return;
    // }
    // AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset)hashTable.get("annotatedImages");
    // String initialFieldDataName = (String)hashTable.get("initialFieldDataName");
    // 
    // DocumentWindow documentWindow = (DocumentWindow)BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
    // DocumentManager dm = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
    // if(dm == null){
    // throw new RuntimeException("not connected to server");
    // }
    // 
    // // mesh
    // ImageDataset imageDataset = annotatedImages.getImageDataset();
    // Extent extent = imageDataset.getExtent();
    // ISize isize = imageDataset.getISize();
    // Origin origin = new Origin(0,0,0);
    // CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent,isize,
    // new RegionImage( new VCImageUncompressed(null, new byte[isize.getXYZ()], extent,
    // isize.getX(),isize.getY(),isize.getZ()),0,null,null,RegionImage.NO_SMOOTHING));
    // double[] firstPostBleach = (double[])hashTable.get("firstPostBleach");
    // double[] prebleachAvg = (double[])hashTable.get("prebleachAverage");
    // ROI[] rois = (ROI[])hashTable.get("rois");
    // 
    // int NumTimePoints = 1;
    // int NumChannels = 2+rois.length;  // prebleach, postbleach, roi1, roi2 ... roiN
    // String[] channelNames = new String[NumChannels];
    // VariableType[] channelTypes = new VariableType[NumChannels];
    // DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
    // double[][][] pixData = new double[NumTimePoints][NumChannels][];
    // pixData[0][0] = firstPostBleach;
    // channelNames[0] = "firstPostBleach";
    // channelTypes[0] = VariableType.VOLUME;
    // channelVFrapImageType[0] = DataSymbolType.VFRAP_FIRST_POSTBLEACH;
    // pixData[0][1] = prebleachAvg;
    // channelNames[1] = "prebleachAverage";
    // channelTypes[1] = VariableType.VOLUME;
    // channelVFrapImageType[1] = DataSymbolType.VFRAP_PREBLEACH_AVG;
    // int index = 0;
    // for (ROI roi : rois){
    // short[] ushortPixels = roi.getPixelsXYZ();
    // double[] doublePixels = new double[ushortPixels.length];
    // for (int i = 0; i < ushortPixels.length; i++) {
    // doublePixels[i] = ((int)ushortPixels[i])&0xffff;
    // }
    // pixData[0][index+2] = doublePixels;
    // channelNames[index+2] = "roi_"+index;
    // channelTypes[index+2] = VariableType.VOLUME;
    // channelVFrapImageType[index+2] = DataSymbolType.VFRAP_ROI;
    // index++;
    // }
    // double[] times = new double[] { 0.0 };
    // 
    // FieldDataFileOperationSpec vfrapMiscFieldDataOpSpec = new FieldDataFileOperationSpec();
    // vfrapMiscFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
    // vfrapMiscFieldDataOpSpec.cartesianMesh = cartesianMesh;
    // vfrapMiscFieldDataOpSpec.doubleSpecData =  pixData;
    // vfrapMiscFieldDataOpSpec.specEDI = null;
    // vfrapMiscFieldDataOpSpec.varNames = channelNames;
    // vfrapMiscFieldDataOpSpec.owner = dm.getUser();
    // vfrapMiscFieldDataOpSpec.times = times;
    // vfrapMiscFieldDataOpSpec.variableTypes = channelTypes;
    // vfrapMiscFieldDataOpSpec.origin = origin;
    // vfrapMiscFieldDataOpSpec.extent = extent;
    // vfrapMiscFieldDataOpSpec.isize = isize;
    // //  localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
    // 
    // //			String formattedDate = (String)hashTable.get("formattedDate");
    // //			String fieldDataName = initialFieldDataName + "_vfrapMisc_" + formattedDate;
    // String mixedFieldDataName = (String)hashTable.get("mixedFieldDataName");
    // ExternalDataIdentifier vfrapMisc = dm.saveFieldData(vfrapMiscFieldDataOpSpec, mixedFieldDataName);
    // 
    // hashTable.put("channelNames", channelNames);
    // hashTable.put("channelVFrapImageType", channelVFrapImageType);
    // hashTable.put("vfrapMisc", vfrapMisc);
    // }
    // };
    // create the data symbols for the images saved above and display them in the tree/table
    // taskArray[5] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
    // public void run(Hashtable<String, Object> hashTable) throws Exception {
    // 
    // // --- create the data symbols associated with the time series
    // String initialFieldDataName = (String)hashTable.get("initialFieldDataName");
    // String mixedFieldDataName = (String)hashTable.get("mixedFieldDataName");
    // String formattedDate = (String)hashTable.get("formattedDate");
    // ImageDataset imageDataset = (ImageDataset)hashTable.get("imageDataset");
    // ExternalDataIdentifier timeSeriesEDI = (ExternalDataIdentifier)hashTable.get("timeSeriesEDI");
    // 
    // for (double time : imageDataset.getImageTimeStamps()){
    // //	   			String fluorName = TokenMangler.fixTokenStrict("fluor_"+time+"_");
    // //				while (simulationContext.getDataContext().getDataSymbol(fluorName)!=null){
    // //					fluorName = TokenMangler.getNextEnumeratedToken(fluorName);
    // //	   			}
    // DecimalFormat df = new  DecimalFormat("0.##");
    // //	   			String fluorName = "fluor_" + df.format(time) + "_" + formattedDate;
    // String fluorName = "fluor_" + df.format(time) + "_" + initialFieldDataName;
    // //				FieldFunctionArguments fluorFFArgs = new FieldFunctionArguments(timeSeriesEDI.getName(), fluorName, new Expression(time), VariableType.VOLUME);
    // DataSymbol fluorDataSymbol = new FieldDataSymbol( fluorName, DataSymbolType.VFRAP_TIMEPOINT,
    // simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD,
    // timeSeriesEDI, fluorName, VariableType.VOLUME.getTypeName(), time);
    // simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
    // }
    // // --- create the vFrap-specific symbols (ROIs, first postbleach, prebleach average)
    // String[] channelNames = (String[])hashTable.get("channelNames");
    // DataSymbolType[] channelVFrapImageType = (DataSymbolType[])hashTable.get("channelVFrapImageType");
    // ExternalDataIdentifier vfrapMisc = (ExternalDataIdentifier)hashTable.get("vfrapMisc");
    // 
    // for (int i=0; i<channelNames.length; i++) {
    // String dataSymbolID = channelNames[i] + "_" + mixedFieldDataName;
    // //				while (simulationContext.getDataContext().getDataSymbol(dataSymbolID)!=null){
    // //					dataSymbolID = TokenMangler.getNextEnumeratedToken(dataSymbolID);
    // //				}
    // //				FieldFunctionArguments prebleachFFArgs = new FieldFunctionArguments(vfrapMisc.getName(), channelNames[i], new Expression(0.0), VariableType.VOLUME);
    // //				DataSymbol dataSymbol = new FieldDataSymbol(channelNames[i], channelVFrapImageType[i],
    // //				DataSymbol dataSymbol = new FieldDataSymbol(dataSymbolID + "_" + formattedDate, channelVFrapImageType[i],
    // DataSymbol dataSymbol = new FieldDataSymbol(dataSymbolID, channelVFrapImageType[i],
    // simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD,
    // vfrapMisc, channelNames[i], VariableType.VOLUME.getTypeName(), 0D);
    // simulationContext.getDataContext().addDataSymbol(dataSymbol);
    // }
    // }
    // };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    ClientTaskDispatcher.dispatch(this, hash, taskArray, false, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Hashtable(java.util.Hashtable) Element(org.jdom.Element) DocumentManager(cbit.vcell.clientdb.DocumentManager) UserCancelException(org.vcell.util.UserCancelException) BufferedImage(java.awt.image.BufferedImage) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) MicroscopyXmlReader(cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader) BioModel(cbit.vcell.biomodel.BioModel) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Component(java.awt.Component) File(java.io.File) OverlayEditorPanelJAI(cbit.vcell.geometry.gui.OverlayEditorPanelJAI) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset)

Example 15 with DocumentManager

use of cbit.vcell.clientdb.DocumentManager in project vcell by virtualcell.

the class DBReactionWizardPanel method setDocumentManager.

/**
 * Sets the documentManager property (cbit.vcell.clientdb.DocumentManager) value.
 * @param documentManager The new value for the property.
 * @see #getDocumentManager
 */
public void setDocumentManager(DocumentManager documentManager) {
    DocumentManager oldValue = fieldDocumentManager;
    fieldDocumentManager = documentManager;
    firePropertyChange(CommonTask.DOCUMENT_MANAGER.name, oldValue, documentManager);
}
Also used : DocumentManager(cbit.vcell.clientdb.DocumentManager)

Aggregations

DocumentManager (cbit.vcell.clientdb.DocumentManager)30 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)10 Hashtable (java.util.Hashtable)10 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)6 VCDocument (org.vcell.util.document.VCDocument)6 UserCancelException (org.vcell.util.UserCancelException)5 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)5 BioModel (cbit.vcell.biomodel.BioModel)4 Component (java.awt.Component)4 File (java.io.File)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 DatabaseWindowManager (cbit.vcell.client.DatabaseWindowManager)3 DocumentWindow (cbit.vcell.client.desktop.DocumentWindow)3 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)3 GeometryInfo (cbit.vcell.geometry.GeometryInfo)3 RegionImage (cbit.vcell.geometry.RegionImage)3 DataAccessException (org.vcell.util.DataAccessException)3 VCImageUncompressed (cbit.image.VCImageUncompressed)2 AnnotatedImageDataset (cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset)2 MicroscopyXmlReader (cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader)2