Search in sources :

Example 11 with VCImageUncompressed

use of cbit.image.VCImageUncompressed in project vcell by virtualcell.

the class RunRefSimulationOp method saveExternalData.

private static void saveExternalData(Image image, String varName, ExternalDataIdentifier newROIExtDataID, LocalWorkspace localWorkspace) throws ObjectNotFoundException, ImageException, IOException {
    Extent extent = image.getExtent();
    Origin origin = image.getOrigin();
    ISize isize = image.getISize();
    VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
    RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
    CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
    int NumTimePoints = 1;
    int NumChannels = 1;
    // dimensions: time points, channels, whole image ordered by z slices.
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    pixData[0][0] = image.getDoublePixels();
    FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
    fdos.cartesianMesh = simpleCartesianMesh;
    fdos.doubleSpecData = pixData;
    fdos.specEDI = newROIExtDataID;
    fdos.varNames = new String[] { varName };
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = new double[] { 0.0 };
    fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) RegionImage(cbit.vcell.geometry.RegionImage) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Example 12 with VCImageUncompressed

use of cbit.image.VCImageUncompressed in project vcell by virtualcell.

the class DisplayImageOp method displayImage.

public void displayImage(final Image image, String title, WindowListener listener) {
    final ImagePlaneManagerPanel imagePanel = new ImagePlaneManagerPanel();
    double[] doublePixels = image.getDoublePixels();
    double minPixel = Double.MAX_VALUE;
    double maxPixel = -Double.MAX_VALUE;
    for (int i = 0; i < doublePixels.length; i++) {
        double pixel = doublePixels[i];
        doublePixels[i] = pixel;
        minPixel = Math.min(minPixel, pixel);
        maxPixel = Math.max(maxPixel, pixel);
    }
    Range newRange = new Range(minPixel, maxPixel);
    SourceDataInfo source = new SourceDataInfo(SourceDataInfo.RAW_VALUE_TYPE, doublePixels, image.getExtent(), image.getOrigin(), newRange, 0, image.getNumX(), 1, image.getNumY(), image.getNumX(), image.getNumZ(), image.getNumX() * image.getNumY());
    imagePanel.setDisplayAdapterServicePanelVisible(true);
    imagePanel.setCurveValueProvider(new CurveValueProvider() {

        @Override
        public void curveAdded(Curve curve) {
            System.out.println("called curveAdded(" + curve + "), do nothing for now");
        }

        @Override
        public void curveRemoved(Curve curve) {
            System.out.println("called curveRemoved(" + curve + ")");
        }

        @Override
        public String getCurveValue(CurveSelectionInfo csi) {
            System.out.println("called getCurveValue(CurveSelectionInfo " + csi);
            return null;
        }

        @Override
        public CurveSelectionInfo getInitalCurveSelection(int tool, Coordinate wc) {
            System.out.println("called getInitialCurveSelection(tool=" + tool + ", coord=" + wc + ")");
            return null;
        }

        @Override
        public boolean isAddControlPointOK(int tool, Coordinate wc, Curve addedToThisCurve) {
            System.out.println("called isAddControlPointOK");
            return true;
        }

        @Override
        public boolean providesInitalCurve(int tool, Coordinate wc) {
            System.out.println("called providesInitialCurve(tool=" + tool + " (TOOL_LINE=" + CurveEditorTool.TOOL_LINE + "), coord=" + wc);
            return false;
        }

        @Override
        public void setDescription(Curve curve) {
            System.out.println("called setDescription(" + curve + ")");
            curve.setDescription(CurveValueProvider.DESCRIPTION_VOLUME);
        }

        @Override
        public CurveSelectionInfo findChomboCurveSelectionInfoForPoint(CoordinateIndex ci) {
            System.out.println("called find ChomboCurveSelectionInfoForPoint(coord=" + ci + ")");
            return null;
        }
    });
    DisplayAdapterService das = imagePanel.getDisplayAdapterServicePanel().getDisplayAdapterService();
    das.setValueDomain(null);
    das.addColorModelForValues(DisplayAdapterService.createGrayColorModel(), DisplayAdapterService.createGraySpecialColors(), DisplayAdapterService.GRAY);
    das.addColorModelForValues(DisplayAdapterService.createBlueRedColorModel(), DisplayAdapterService.createBlueRedSpecialColors(), DisplayAdapterService.BLUERED);
    das.setActiveColorModelID(DisplayAdapterService.BLUERED);
    final JFrame jframe = new JFrame();
    jframe.setTitle(title);
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints imageConstraints = new GridBagConstraints();
    imageConstraints.gridx = 0;
    imageConstraints.gridy = 0;
    imageConstraints.weightx = 1.0;
    imageConstraints.weighty = 1.0;
    imageConstraints.fill = GridBagConstraints.BOTH;
    panel.add(imagePanel, imageConstraints);
    JButton plotButton = new JButton("plot");
    plotButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Curve curve = imagePanel.getCurveRenderer().getSelection().getCurve();
                VariableType variableType = VariableType.VOLUME;
                Curve samplerCurve = curve.getSampledCurve();
                samplerCurve.setDescription(curve.getDescription());
                VCImage vcImage = new VCImageUncompressed(null, new byte[image.getISize().getXYZ()], image.getExtent(), image.getISize().getX(), image.getISize().getY(), image.getISize().getZ());
                int dimension = 1 + (image.getISize().getY() > 0 ? 1 : 0) + (image.getISize().getZ() > 0 ? 1 : 0);
                RegionImage regionImage = new RegionImage(vcImage, dimension, image.getExtent(), image.getOrigin(), RegionImage.NO_SMOOTHING);
                CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(image.getOrigin(), image.getExtent(), image.getISize(), regionImage);
                SpatialSelectionVolume ssVolume = new SpatialSelectionVolume(new CurveSelectionInfo(samplerCurve), variableType, mesh);
                String varName = "var";
                SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[] { new VolVariable(varName, null) };
                PlotData plotData = getLineScan(ssVolume, image, mesh);
                PlotPane plotPane = new PlotPane();
                DataSymbolMetadataResolver resolver = null;
                Plot2D plot2D = new Plot2D(symbolTableEntries, resolver, new String[] { varName }, new PlotData[] { plotData }, new String[] { "Values along curve", "Distance (\u00b5m)", "[" + varName + "]" });
                plotPane.setPlot2D(plot2D);
                DialogUtils.showComponentCloseDialog(jframe, plotPane, "plot");
            } catch (ImageException | IOException | DataAccessException | MathException e1) {
                e1.printStackTrace();
            }
        }
    });
    GridBagConstraints plotButtonConstraints = new GridBagConstraints();
    plotButtonConstraints.gridx = 0;
    plotButtonConstraints.gridy = 1;
    panel.add(plotButton, plotButtonConstraints);
    jframe.getContentPane().add(panel);
    jframe.setSize(500, 500);
    jframe.addWindowListener(listener);
    jframe.setVisible(true);
    imagePanel.setSourceDataInfo(source);
}
Also used : DisplayAdapterService(cbit.image.DisplayAdapterService) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ImagePlaneManagerPanel(cbit.image.gui.ImagePlaneManagerPanel) JButton(javax.swing.JButton) VCImage(cbit.image.VCImage) SourceDataInfo(cbit.image.SourceDataInfo) CoordinateIndex(org.vcell.util.CoordinateIndex) JFrame(javax.swing.JFrame) PlotData(cbit.plot.PlotData) DataSymbolMetadataResolver(cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) Curve(cbit.vcell.geometry.Curve) VCImageUncompressed(cbit.image.VCImageUncompressed) Range(org.vcell.util.Range) CartesianMesh(cbit.vcell.solvers.CartesianMesh) CurveValueProvider(cbit.vcell.simdata.gui.CurveValueProvider) ActionListener(java.awt.event.ActionListener) Coordinate(org.vcell.util.Coordinate) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) RegionImage(cbit.vcell.geometry.RegionImage) PlotPane(cbit.plot.gui.PlotPane) Plot2D(cbit.plot.Plot2D) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo)

Example 13 with VCImageUncompressed

use of cbit.image.VCImageUncompressed in project vcell by virtualcell.

the class DisplayTimeSeriesOp method getDataSetControllerProvider.

private DataSetControllerProvider getDataSetControllerProvider(final ImageTimeSeries<? extends Image> imageTimeSeries, final PDEDataViewer pdeDataViewer) throws ImageException, IOException {
    ISize size = imageTimeSeries.getISize();
    int dimension = (size.getZ() > 0) ? (3) : (2);
    Extent extent = imageTimeSeries.getExtent();
    Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
    // don't care ... no surfaces
    double filterCutoffFrequency = 0.5;
    VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
    RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
    final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
    final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
    final DataSetController dataSetController = new DataSetController() {

        @Override
        public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
            pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_START, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
            if (!timeSeriesJobSpec.isCalcSpaceStats() && !timeSeriesJobSpec.isCalcTimeStats()) {
                int[][] indices = timeSeriesJobSpec.getIndices();
                double[] timeStamps = imageTimeSeries.getImageTimeStamps();
                // [var][dataindex+1][timeindex]
                double[][][] dataValues = new double[1][indices[0].length + 1][timeStamps.length];
                for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
                    // index 0 is time
                    dataValues[0][0][timeIndex] = timeStamps[timeIndex];
                }
                for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
                    float[] pixelValues = imageTimeSeries.getAllImages()[timeIndex].getFloatPixels();
                    for (int samplePointIndex = 0; samplePointIndex < indices[0].length; samplePointIndex++) {
                        int pixelIndex = indices[0][samplePointIndex];
                        dataValues[0][samplePointIndex + 1][timeIndex] = pixelValues[pixelIndex];
                    }
                }
                TSJobResultsNoStats timeSeriesJobResults = new TSJobResultsNoStats(new String[] { "var" }, indices, timeStamps, dataValues);
                pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_COMPLETE, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
                return timeSeriesJobResults;
            }
            return null;
        }

        @Override
        public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
            double timePoint = time;
            double[] timePoints = getDataSetTimes(vcdataID);
            int index = -1;
            for (int i = 0; i < timePoints.length; i++) {
                if (timePoint == timePoints[i]) {
                    index = i;
                    break;
                }
            }
            double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
            PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
            VariableType varType = VariableType.VOLUME;
            return new SimDataBlock(pdeDataInfo, data, varType);
        }

        @Override
        public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return false;
        }

        @Override
        public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return mesh;
        }

        @Override
        public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return new AnnotatedFunction[0];
        }

        @Override
        public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return imageTimeSeries.getImageTimeStamps();
        }

        @Override
        public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return new DataIdentifier[] { dataIdentifier };
        }

        @Override
        public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }
    };
    DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {

        @Override
        public DataSetController getDataSetController() throws DataAccessException {
            return dataSetController;
        }
    };
    return dataSetControllerProvider;
}
Also used : Origin(org.vcell.util.Origin) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ExportSpecs(cbit.vcell.export.server.ExportSpecs) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImage(cbit.image.VCImage) PDEDataInfo(cbit.vcell.simdata.PDEDataInfo) DataSetControllerProvider(cbit.vcell.server.DataSetControllerProvider) SimDataBlock(cbit.vcell.simdata.SimDataBlock) SpatialSelection(cbit.vcell.simdata.SpatialSelection) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) DataOperation(cbit.vcell.simdata.DataOperation) VariableType(cbit.vcell.math.VariableType) DataSetController(cbit.vcell.server.DataSetController) VCImageUncompressed(cbit.image.VCImageUncompressed) OutputContext(cbit.vcell.simdata.OutputContext) DataJobEvent(cbit.rmi.event.DataJobEvent) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage) Domain(cbit.vcell.math.Variable.Domain) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 14 with VCImageUncompressed

use of cbit.image.VCImageUncompressed in project vcell by virtualcell.

the class VFrapXmlHelper method LoadVFrapSpecialImages.

// // load and compute prebleach average and first postbleach images
// public void LoadVFrapSpecialImages(AnnotatedImageDataset annotatedImages, int startingIndexRecovery)
// {
// // unnormalized prebleach average
// prebleachAvg = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// for(int j = 0; j < prebleachAvg.length; j++)
// {
// double pixelTotal = 0;
// for(int i = 0 ; i < startingIndexRecovery; i++)
// {
// pixelTotal = pixelTotal + (annotatedImages.getImageDataset().getImage(0, 0, i).getPixels()[j] & 0x0000FFFF);
// }
// prebleachAvg[j] = pixelTotal/startingIndexRecovery;
// }
// 
// // unnormalized first post bleach
// firstPostBleach = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// short[] pixels = annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getPixels();
// for(int i = 0; i< pixels.length; i++)
// {
// firstPostBleach[i] = pixels[i] & 0x0000FFFF;
// }
// }
// 
// Locate the special images within the vFrap files and load them in memory
// 
public static boolean LoadVFrapSpecialImages(Hashtable<String, Object> hashTable, Element vFrapRoot) throws IOException, DataAccessException, MathException, ImageException {
    // ------ parse the vfrap file and the log/zip files referred within -----
    // many channels of 1 timepoint each
    int NumTimePoints = 1;
    // the channels: prebleach, postbleach, roi1, roi2 ... roiN
    int NumChannels = tokenNames.length;
    String[] channelNames = new String[NumChannels];
    VariableType[] channelTypes = new VariableType[NumChannels];
    DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    // get the path of the file tagged with "ROIExternalDataInfoTag" and open it
    Element roiExternalDataInfoElement = vFrapRoot.getChild(MicroscopyXMLTags.ROIExternalDataInfoTag);
    if (roiExternalDataInfoElement == null) {
        // can't load FieldData for some reason, fall back to importing the biomodel only
        return false;
    }
    // <ROIExternalDataInfo Filename="c:\vFrap\VirtualMicroscopy\SimulationData\SimID_1282941232246_0_.log">
    // <ExternalDataIdentifier Name="timeData" KeyValue="1282941232246" OwnerName="SimulationData" OwnerKey="0" />
    // </ImageDatasetExternalDataInfo>
    // c:\VirtualMicroscopy\SimulationData\SimID_1284149203811_0_.log
    String filename = (roiExternalDataInfoElement).getAttributeValue("Filename");
    Element childElement = (roiExternalDataInfoElement).getChild("ExternalDataIdentifier");
    if (childElement == null) {
        // can't load FieldData for some reason, fall back to importing the biomodel only
        return false;
    }
    StringTokenizer tokens = new StringTokenizer(filename, "/\\.");
    final ArrayList<String> tokenArray = new ArrayList<String>();
    while (tokens.hasMoreElements()) {
        tokenArray.add(tokens.nextToken());
    }
    final String dataID = tokenArray.get(tokenArray.size() - 2);
    final String userName = tokenArray.get(tokenArray.size() - 3);
    VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

        public String getID() {
            return dataID;
        }

        public KeyValue getDataKey() {
            return null;
        }

        public User getOwner() {
            return new User(userName, new KeyValue("123345432334"));
        }
    };
    // ------- recover simulation data for this user name, load the images in memory ------------
    // ex  c:\\VirtualMicroscopy\\SimulationData
    String userDirName = filename.substring(0, filename.indexOf(dataID) - 1);
    File userDir = new File(userDirName);
    SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
    SimulationData simData = new SimulationData(vcDataIdentifier, userDir, null, simDataAmplistorInfo);
    // build a valid mesh in 2 steps, what we have in simData is incomplete
    CartesianMesh incompleteMesh = simData.getMesh();
    Extent extent = incompleteMesh.getExtent();
    ISize isize = new ISize(incompleteMesh.getSizeX(), incompleteMesh.getSizeY(), incompleteMesh.getSizeZ());
    Origin origin = new Origin(0, 0, 0);
    CartesianMesh mesh = 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));
    DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
    double[] times = simData.getDataTimes();
    for (int i = 0; i < dataIdentifiers.length; i++) {
        // ex: prebleach_avg, postbleach_first, postbleach_last, bleached_mask, cell_mask, ring1_mask,... ring8_mask
        System.out.println(dataIdentifiers[i].getName());
        for (double time : times) {
            // this loops only once, we have just 1 timepoint for each "special" image
            SimDataBlock simDataBlock = simData.getSimDataBlock(null, dataIdentifiers[i].getName(), time);
            channelNames[i] = dataIdentifiers[i].getName();
            channelTypes[i] = VariableType.VOLUME;
            channelVFrapImageType[i] = SymbolEquivalence.typeFromToken(dataIdentifiers[i].getName());
            pixData[0][i] = simDataBlock.getData();
            // var = prebleach_avg, time = 0.0, data = { 1.0832530361887216 1.0832530361887216 1.0832530361887216 1.0 .... }
            System.out.print("var = " + dataIdentifiers[i].getName() + ", time = " + time + ", data = { ");
            // show a few
            for (int j = 0; j < 5; j++) {
                System.out.print(pixData[0][i][j] + " ");
            }
            // show a few
            ;
            // show a few
            System.out.println(" ... ");
        }
    }
    hashTable.put("mesh", mesh);
    hashTable.put("pixData", pixData);
    hashTable.put("channelNames", channelNames);
    hashTable.put("channelTypes", channelTypes);
    hashTable.put("channelVFrapImageType", channelVFrapImageType);
    return true;
}
Also used : Origin(org.vcell.util.Origin) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) Element(org.jdom.Element) ArrayList(java.util.ArrayList) SimDataBlock(cbit.vcell.simdata.SimDataBlock) VariableType(cbit.vcell.math.VariableType) VCImageUncompressed(cbit.image.VCImageUncompressed) StringTokenizer(java.util.StringTokenizer) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SimulationData(cbit.vcell.simdata.SimulationData) DataSymbolType(cbit.vcell.data.DataSymbol.DataSymbolType) RegionImage(cbit.vcell.geometry.RegionImage) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File)

Example 15 with VCImageUncompressed

use of cbit.image.VCImageUncompressed 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)

Aggregations

VCImageUncompressed (cbit.image.VCImageUncompressed)34 Extent (org.vcell.util.Extent)23 ISize (org.vcell.util.ISize)19 VCImage (cbit.image.VCImage)18 RegionImage (cbit.vcell.geometry.RegionImage)18 Origin (org.vcell.util.Origin)17 CartesianMesh (cbit.vcell.solvers.CartesianMesh)15 Expression (cbit.vcell.parser.Expression)11 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)10 Geometry (cbit.vcell.geometry.Geometry)10 ImageException (cbit.image.ImageException)9 SubVolume (cbit.vcell.geometry.SubVolume)9 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)8 UserCancelException (org.vcell.util.UserCancelException)8 BioModel (cbit.vcell.biomodel.BioModel)6 SurfaceClass (cbit.vcell.geometry.SurfaceClass)6 FeatureMapping (cbit.vcell.mapping.FeatureMapping)6 SimulationContext (cbit.vcell.mapping.SimulationContext)6 VariableType (cbit.vcell.math.VariableType)6 Feature (cbit.vcell.model.Feature)6