Search in sources :

Example 1 with MovieSpecs

use of cbit.vcell.export.server.MovieSpecs in project vcell by virtualcell.

the class FRAPStudyPanel method showMovie.

private void showMovie() {
    AsynchClientTask createMovieTask = new AsynchClientTask("Buffering movie data...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            if (fStudy == null) {
                return;
            }
            if (fStudy.getMovieURLString() != null && fStudy.getMovieFileString() != null) {
                hashTable.put("FrapStudy", fStudy);
                return;
            }
            // create export specs
            Simulation sim = null;
            if (fStudy.getBioModel() == null || fStudy.getBioModel().getSimulations() == null || fStudy.getBioModel().getSimulations().length < 1) {
                return;
            } else {
                sim = fStudy.getBioModel().getSimulations()[0];
            }
            FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
            FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
            for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
                fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier());
            }
            ExternalDataIdentifier timeSeriesExtDataID = fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier();
            ExternalDataIdentifier maskExtDataID = fStudy.getRoiExternalDataInfo().getExternalDataIdentifier();
            // add sim
            int jobIndex = 0;
            SimulationJob simJob = new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs);
            VCDataIdentifier[] dataIDs = new VCDataIdentifier[] { timeSeriesExtDataID, maskExtDataID, simJob.getVCDataIdentifier() };
            VCDataIdentifier vcDataId = new MergedDataInfo(LocalWorkspace.getDefaultOwner(), dataIDs, FRAPStudy.VFRAP_DS_PREFIX);
            PDEDataManager dataManager = new PDEDataManager(null, getLocalWorkspace().getVCDataManager(), vcDataId);
            PDEDataContext pdeDataContext = new ClientPDEDataContext(dataManager);
            ExportFormat format = ExportFormat.QUICKTIME;
            String[] variableNames = new String[] { NORM_FLUOR_VAR, NORM_SIM_VAR };
            VariableSpecs variableSpecs = new VariableSpecs(variableNames, ExportConstants.VARIABLE_MULTI);
            // int endTimeIndex = (int)Math.round(sim.getSolverTaskDescription().getTimeBounds().getEndingTime()/((UniformOutputTimeSpec)sim.getSolverTaskDescription().getOutputTimeSpec()).getOutputTimeStep());
            int endTimeIndex = getFRAPSimDataViewerPanel().getOriginalDataViewer().getPdeDataContext().getTimePoints().length - 1;
            TimeSpecs timeSpecs = new TimeSpecs(0, endTimeIndex, pdeDataContext.getTimePoints(), ExportConstants.TIME_RANGE);
            int geoMode = ExportConstants.GEOMETRY_SLICE;
            GeometrySpecs geometrySpecs = new GeometrySpecs(null, Coordinate.Z_AXIS, 0, geoMode);
            // 10s
            double duration = 10000;
            DisplayPreferences pref1 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
            DisplayPreferences pref2 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
            DisplayPreferences[] displayPref = new DisplayPreferences[] { pref1, pref2 };
            int imageScale = 1;
            int membraneScale = 1;
            int scaleMode = ImagePaneModel.MESH_MODE;
            // the default setting in MediaSettingsPanel.
            int volVarMemOutlineThickness = 1;
            MovieSpecs mSpec = new MovieSpecs(duration, true, displayPref, ExportFormat.QUICKTIME, ExportConstants.NO_MIRRORING, volVarMemOutlineThickness, imageScale, membraneScale, scaleMode, FormatSpecificSpecs.CODEC_JPEG, 1.0f, /*lossless*/
            false, FormatSpecificSpecs.PARTICLE_NONE);
            // mSpec.setViewZoom(1);
            ExportSpecs exSpecs = new ExportSpecs(vcDataId, format, variableSpecs, timeSpecs, geometrySpecs, mSpec, fStudy.getName(), null);
            // pass the request
            ExportEvent exportEvt = ((VirtualFrapWindowManager) getFlourDataViewer().getDataViewerManager()).startExportMovie(exSpecs, outputContext, this.getClientTaskStatusSupport());
            hashTable.put("ExportEvt", exportEvt);
            hashTable.put("FrapStudy", fStudy);
        }
    };
    AsynchClientTask showMovieTask = new AsynchClientTask("Showing movie ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ExportEvent exportEvt = (ExportEvent) hashTable.get("ExportEvt");
            FRAPStudy fStudy = (FRAPStudy) hashTable.get("FrapStudy");
            // show movie if successfully exported
            if (exportEvt != null) {
                final String fileURLString = System.getProperty(PropertyLoader.exportBaseURLProperty) + exportEvt.getJobID() + ".mov";
                final String fileString = System.getProperty(PropertyLoader.exportBaseDirInternalProperty) + exportEvt.getJobID() + ".mov";
                fStudy.setMovieURLString(fileURLString);
                fStudy.setMovieFileString(fileString);
            }
            showMovieInDialog(fStudy.getMovieURLString(), fStudy.getMovieFileString());
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { createMovieTask, showMovieTask }, true, true, null, true);
}
Also used : ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) PDEDataContext(cbit.vcell.simdata.PDEDataContext) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ExportEvent(cbit.rmi.event.ExportEvent) GeometrySpecs(cbit.vcell.export.server.GeometrySpecs) MergedDataInfo(cbit.vcell.simdata.MergedDataInfo) DisplayPreferences(cbit.image.DisplayPreferences) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) TimeSpecs(cbit.vcell.export.server.TimeSpecs) SimulationJob(cbit.vcell.solver.SimulationJob) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) Hashtable(java.util.Hashtable) ExportFormat(cbit.vcell.export.server.ExportFormat) Range(org.vcell.util.Range) Point(java.awt.Point) VariableSpecs(cbit.vcell.export.server.VariableSpecs) MovieSpecs(cbit.vcell.export.server.MovieSpecs) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 2 with MovieSpecs

use of cbit.vcell.export.server.MovieSpecs in project vcell by virtualcell.

the class PDEExportDataPanel method startExport.

/**
 * Comment
 */
private void startExport() {
    if (getExportSettings1().getSelectedFormat() == ExportFormat.QUICKTIME && getJSlider1().getValue() == getJSlider2().getValue()) {
        DialogUtils.showWarningDialog(this, "User selected 'begin' and 'end' export times are the same.  'Movie' export format 'begin' and 'end' times must be different");
        return;
    }
    DisplayPreferences[] displayPreferences = null;
    @SuppressWarnings("deprecation") Object[] variableSelections = getJListVariables().getSelectedValues();
    boolean selectionHasVolumeVariables = false;
    boolean selectionHasMembraneVariables = false;
    switch(getExportSettings1().getSelectedFormat()) {
        case PLY:
        case QUICKTIME:
        case GIF:
        case FORMAT_JPEG:
        case ANIMATED_GIF:
            {
                displayPreferences = new DisplayPreferences[variableSelections.length];
                StringBuffer noScaleInfoNames = new StringBuffer();
                for (int i = 0; i < displayPreferences.length; i++) {
                    BitSet domainValid = null;
                    try {
                        if (dataInfoProvider != null) {
                            DataIdentifier varSelectionDataIdnetDataIdentifier = null;
                            for (int j = 0; j < dataInfoProvider.getPDEDataContext().getDataIdentifiers().length; j++) {
                                if (dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j].getName().equals(variableSelections[i])) {
                                    varSelectionDataIdnetDataIdentifier = dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j];
                                }
                            }
                            if (varSelectionDataIdnetDataIdentifier != null) {
                                selectionHasVolumeVariables = selectionHasVolumeVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.POSTPROCESSING) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME_REGION);
                                selectionHasMembraneVariables = selectionHasMembraneVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE_REGION);
                                CartesianMesh cartesianMesh = dataInfoProvider.getPDEDataContext().getCartesianMesh();
                                int dataLength = cartesianMesh.getDataLength(varSelectionDataIdnetDataIdentifier.getVariableType());
                                domainValid = new BitSet(dataLength);
                                domainValid.clear();
                                for (int j = 0; j < dataLength; j++) {
                                    if (dataInfoProvider.isDefined(varSelectionDataIdnetDataIdentifier, j)) {
                                        domainValid.set(j);
                                    }
                                }
                            } else {
                                throw new Exception("No DataIdentifer found for variable name '" + variableSelections[i] + "'");
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        DialogUtils.showErrorDialog(this, "Error during domain evaluation:\n" + e.getMessage());
                        return;
                    }
                    displayPreferences[i] = new DisplayPreferences(getDisplayAdapterService().getDisplayPreferences((String) variableSelections[i]), domainValid);
                    if (!getDisplayAdapterService().hasStateID((String) variableSelections[i])) {
                        noScaleInfoNames.append("--- " + (String) variableSelections[i] + "\n");
                    }
                }
                break;
            }
        case CSV:
            {
                // check for membrane variables... warn for 3D geometry...
                // one gets the whole nine yards by index, not generally useful... except for a few people like Boris :)
                boolean mbVars = false;
                DataIdentifier[] dataIDs = getPdeDataContext().getDataIdentifiers();
                for (int i = 0; i < variableSelections.length; i++) {
                    String varName = (String) variableSelections[i];
                    for (int j = 0; j < dataIDs.length; j++) {
                        if (dataIDs[j].getName().equals(varName) && dataIDs[j].getVariableType().equals(VariableType.MEMBRANE)) {
                            mbVars = true;
                            break;
                        }
                    }
                }
                if (mbVars && getPdeDataContext().getCartesianMesh().getGeometryDimension() == 3 && getJRadioButtonSlice().isSelected()) {
                    String choice = PopupGenerator.showWarningDialog(this, getDataViewerManager().getUserPreferences(), UserMessage.warn_exportMembraneData3D, null);
                    if (choice.equals(UserMessage.OPTION_CANCEL)) {
                        // user canceled
                        return;
                    }
                }
                getExportSettings1().setSimulationSelector(createSimulationSelector());
                getExportSettings1().setIsCSVExport(true);
                break;
            }
        case NRRD:
        case IMAGEJ:
        case UCD:
        case VTK_IMAGE:
        case VTK_UNSTRUCT:
            break;
        default:
            break;
    }
    ;
    if (getJRadioButtonROI().isSelected() && getROISelections().getSelectedIndex() == -1) {
        PopupGenerator.showErrorDialog(this, "To export selections, you must select at least one item from the ROI selection list");
    }
    getExportSettings1().setTimeSpecs(new TimeSpecs(getJSlider1().getValue(), getJSlider2().getValue(), getPdeDataContext().getTimePoints(), ExportConstants.TIME_RANGE));
    getExportSettings1().setDisplayPreferences(displayPreferences, Arrays.asList(variableSelections).toArray(new String[0]), viewZoom);
    getExportSettings1().setSliceCount(FormatSpecificSpecs.getSliceCount(getJRadioButtonFull().isSelected(), getNormalAxis(), getPdeDataContext().getCartesianMesh()));
    getExportSettings1().setImageSizeCalculationInfo(getPdeDataContext().getCartesianMesh(), getNormalAxis());
    getExportSettings1().setIsSmoldyn(isSmoldyn);
    ExportFormat format = getSelectedFormat();
    if (format.equals(ExportFormat.PLY)) {
        getExportSettings1().setFormatSpecificSpecs(new PLYSpecs(true, displayPreferences));
    }
    if (format.requiresFollowOn()) {
        Frame theFrame = JOptionPane.getFrameForComponent(this);
        boolean okToExport = getExportSettings1().showFormatSpecificDialog(theFrame, selectionHasVolumeVariables, selectionHasMembraneVariables);
        if (!okToExport) {
            return;
        }
    }
    if (format.equals(ExportFormat.IMAGEJ)) {
        // export nrrd for imagej direct, the we'll send to imagej from vcell client
        getExportSettings1().setFormatSpecificSpecs(new RasterSpecs(ExportConstants.NRRD_SINGLE, false));
    }
    // determine of sim result is from local (quick) run or on server.
    final OutputContext outputContext = ((ClientPDEDataContext) getPdeDataContext()).getDataManager().getOutputContext();
    final ExportSpecs exportSpecs = getExportSpecs();
    boolean isLocalSimResult = false;
    VCDataIdentifier vcId = exportSpecs.getVCDataIdentifier();
    if (vcId instanceof LocalVCDataIdentifier) {
        isLocalSimResult = true;
    }
    // find out if smoldyn export choice is 'particle' - not available at this time
    boolean isParticle = false;
    if (getExportSettings1().getFormatSpecificSpecs() instanceof ImageSpecs) {
        isParticle = ((ImageSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
    } else if (getExportSettings1().getFormatSpecificSpecs() instanceof MovieSpecs) {
        isParticle = ((MovieSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
    }
    if (isLocalSimResult && isParticle) {
        DialogUtils.showErrorDialog(this, "Particle export for Smoldyn particles unavailable in local data at this time.");
        return;
    }
    // pass the export request down the line; non-blocking call
    if (!isLocalSimResult) {
        // for sims that ran on server, do as before.
        getDataViewerManager().startExport(this, outputContext, exportSpecs);
    } else {
        final String SOURCE_FILE_KEY = "SOURCE_FILE_KEY";
        final String DESTINATION_FILE_KEY = "DEESTINATION_FILE_KEY";
        AsynchClientTask localExportTast = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    File primaryDir = ResourceUtil.getLocalRootDir();
                    User usr = User.tempUser;
                    File usrDir = new File(primaryDir.getAbsolutePath(), usr.getName());
                    System.setProperty(PropertyLoader.exportBaseDirInternalProperty, usrDir.getAbsolutePath() + File.separator);
                    System.setProperty(PropertyLoader.exportBaseURLProperty, usrDir.toURI().toURL().toString());
                    DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                    ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                    DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, localExportServiceImpl);
                    ExportEvent localExportEvent = dataServerImpl.makeRemoteFile(outputContext, usr, exportSpecs);
                    File sourceFile = new File(usrDir, new File((new URL(localExportEvent.getLocation()).getPath())).getName());
                    hashTable.put(SOURCE_FILE_KEY, sourceFile);
                } catch (Exception e) {
                    throw new Exception("Unable to export local sim results data : " + e.getMessage(), e);
                }
            }
        };
        AsynchClientTask localSaveTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
                JFileChooser jFileChooser = new JFileChooser();
                jFileChooser.setSelectedFile(new File(sourceFile.getName()));
                if (jFileChooser.showSaveDialog(PDEExportDataPanel.this) == JFileChooser.APPROVE_OPTION) {
                    File destinationFile = jFileChooser.getSelectedFile();
                    if (destinationFile.exists()) {
                        final String OVERWRITE = "Overwrite";
                        final String CANCEL = "Cancel";
                        String response = DialogUtils.showWarningDialog(PDEExportDataPanel.this, "OK to Overwrite " + destinationFile.getAbsolutePath() + "?", new String[] { OVERWRITE, CANCEL }, OVERWRITE);
                        if (response == null || !response.equals(OVERWRITE)) {
                            return;
                        }
                    }
                    hashTable.put(DESTINATION_FILE_KEY, destinationFile);
                }
            }
        };
        AsynchClientTask localDeleteTempTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
                File destinationFile = (File) hashTable.get(DESTINATION_FILE_KEY);
                if (sourceFile != null && sourceFile.exists()) {
                    try {
                        if (destinationFile != null) {
                            copyFile(sourceFile, destinationFile);
                        }
                    } finally {
                        sourceFile.delete();
                    }
                }
            }
        };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { localExportTast, localSaveTask, localDeleteTempTask }, false, true, null);
    }
}
Also used : DataServerImpl(cbit.vcell.simdata.DataServerImpl) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) User(org.vcell.util.document.User) RasterSpecs(cbit.vcell.export.server.RasterSpecs) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ExportEvent(cbit.rmi.event.ExportEvent) URL(java.net.URL) DisplayPreferences(cbit.image.DisplayPreferences) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) TimeSpecs(cbit.vcell.export.server.TimeSpecs) Hashtable(java.util.Hashtable) PLYSpecs(cbit.vcell.export.server.PLYSpecs) BitSet(java.util.BitSet) ExportFormat(cbit.vcell.export.server.ExportFormat) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) OutputContext(cbit.vcell.simdata.OutputContext) CartesianMesh(cbit.vcell.solvers.CartesianMesh) MovieSpecs(cbit.vcell.export.server.MovieSpecs) JFileChooser(javax.swing.JFileChooser) ImageSpecs(cbit.vcell.export.server.ImageSpecs) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File)

Aggregations

DisplayPreferences (cbit.image.DisplayPreferences)2 ExportEvent (cbit.rmi.event.ExportEvent)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 ExportFormat (cbit.vcell.export.server.ExportFormat)2 ExportSpecs (cbit.vcell.export.server.ExportSpecs)2 MovieSpecs (cbit.vcell.export.server.MovieSpecs)2 TimeSpecs (cbit.vcell.export.server.TimeSpecs)2 Hashtable (java.util.Hashtable)2 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)2 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)1 GeometrySpecs (cbit.vcell.export.server.GeometrySpecs)1 ImageSpecs (cbit.vcell.export.server.ImageSpecs)1 PLYSpecs (cbit.vcell.export.server.PLYSpecs)1 RasterSpecs (cbit.vcell.export.server.RasterSpecs)1 VariableSpecs (cbit.vcell.export.server.VariableSpecs)1 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)1 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)1 ClientPDEDataContext (cbit.vcell.simdata.ClientPDEDataContext)1 DataIdentifier (cbit.vcell.simdata.DataIdentifier)1