Search in sources :

Example 6 with SpatialSelectionVolume

use of cbit.vcell.simdata.SpatialSelectionVolume in project vcell by virtualcell.

the class PDEDataContextPanel method fetchSpatialSelections0.

/**
 * Insert the method's description here.
 * Creation date: (6/28/2003 4:57:18 PM)
 * @return cbit.vcell.simdata.gui.SpatialSelection[]
 */
private SpatialSelection[] fetchSpatialSelections0(Curve curveOfInterest, boolean bFetchOnlyVisible, VariableType vt) {
    // 
    java.util.Vector<SpatialSelection> spatialSelection = new java.util.Vector<SpatialSelection>();
    // 
    if (getPdeDataContext() != null && getPdeDataContext().getCartesianMesh() != null && getImagePlaneManagerPanel() != null && getImagePlaneManagerPanel().getCurveRenderer() != null) {
        // 
        CartesianMesh cm = getPdeDataContext().getCartesianMesh();
        Curve[] curves = getImagePlaneManagerPanel().getCurveRenderer().getAllCurves();
        // 
        if (curves != null && curves.length > 0) {
            for (int i = 0; i < curves.length; i += 1) {
                boolean bIsVisible = getImagePlaneManagerPanel().getCurveRenderer().getRenderPropertyVisible(curves[i]);
                if ((bFetchOnlyVisible && !bIsVisible) || (curveOfInterest != null && curves[i] != curveOfInterest)) {
                    continue;
                }
                // 
                if ((vt.equals(VariableType.POSTPROCESSING) || vt.equals(VariableType.VOLUME) || vt.equals(VariableType.VOLUME_REGION)) && curves[i] instanceof ControlPointCurve && !(curves[i] instanceof CurveSelectionCurve) && (curves[i].getDescription() == null || curves[i].getDescription().startsWith(CurveValueProvider.DESCRIPTION_VOLUME)) && (membranesAndIndexes == null || !membranesAndIndexes.containsKey(curves[i]))) {
                    // Volume
                    // 
                    Curve samplerCurve = null;
                    // if(isSpatial2D){
                    samplerCurve = projectCurveOntoSlice(curves[i].getSampledCurve());
                    // }
                    if (samplerCurve != null) {
                        samplerCurve.setDescription(curves[i].getDescription());
                        spatialSelection.add(new SpatialSelectionVolume(new CurveSelectionInfo(samplerCurve), vt, cm));
                    }
                } else if ((vt.equals(VariableType.MEMBRANE) || vt.equals(VariableType.MEMBRANE_REGION)) && membranesAndIndexes != null) {
                    // 
                    if (curves[i] instanceof CurveSelectionCurve) {
                        CurveSelectionCurve csCurve = (CurveSelectionCurve) curves[i];
                        if (csCurve.getSourceCurveSelectionInfo().getCurve() instanceof ControlPointCurve) {
                            int[] csisegsel = csCurve.getSourceCurveSelectionInfo().getSegmentsInSelectionOrder();
                            if (csisegsel != null) {
                                ControlPointCurve cscpcCurve = (ControlPointCurve) (csCurve.getSourceCurveSelectionInfo().getCurve());
                                Curve[] membraneCurves = (Curve[]) (membranesAndIndexes.keySet().toArray(new Curve[membranesAndIndexes.size()]));
                                // See if CurveSelectionCurve matches controlpoints in space of a membrane we have
                                for (int j = 0; j < membraneCurves.length; j += 1) {
                                    if (membraneCurves[j] instanceof ControlPointCurve) {
                                        // They should all be
                                        ControlPointCurve cpc = (ControlPointCurve) membraneCurves[j];
                                        boolean bSame = true;
                                        for (int k = 0; k < csisegsel.length; k += 1) {
                                            if (csisegsel[k] >= cpc.getControlPointCount() || csisegsel[k] >= cscpcCurve.getControlPointCount() || !Coordinate.get2DProjection(cpc.getControlPoint(csisegsel[k]), getNormalAxis()).equals(Coordinate.get2DProjection(cscpcCurve.getControlPoint(csisegsel[k]), getNormalAxis()))) {
                                                // 
                                                bSame = false;
                                                break;
                                            }
                                        }
                                        if (bSame) {
                                            int[] mi = (int[]) membranesAndIndexes.get(membraneCurves[j]);
                                            spatialSelection.add(new SpatialSelectionMembrane(new CurveSelectionInfo(membraneCurves[j], csisegsel[0], csisegsel[csisegsel.length - 1], csCurve.getSourceCurveSelectionInfo().getDirectionNegative()), vt, cm, mi, csCurve));
                                        }
                                    }
                                }
                            }
                        }
                    } else if (curves[i] instanceof SinglePoint && (curves[i].getDescription() == null || curves[i].getDescription().startsWith(CurveValueProvider.DESCRIPTION_MEMBRANE))) {
                        CurveSelectionInfo[] csiArr = getImagePlaneManagerPanel().getCurveRenderer().getCloseCurveSelectionInfos(curves[i].getBeginningCoordinate());
                        if (csiArr != null && csiArr.length > 0) {
                            for (int j = 0; j < csiArr.length; j += 1) {
                                if (membranesAndIndexes.containsKey(csiArr[j].getCurve())) {
                                    CurveSelectionInfo closestCSI = getImagePlaneManagerPanel().getCurveRenderer().getClosestSegmentSelectionInfo(curves[i].getBeginningCoordinate(), csiArr[j].getCurve());
                                    int[] mi = (int[]) membranesAndIndexes.get(csiArr[j].getCurve());
                                    spatialSelection.add(new SpatialSelectionMembrane(closestCSI, vt, cm, mi, (SinglePoint) curves[i]));
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // 
    if (spatialSelection.size() > 0) {
        SpatialSelection[] ss = new SpatialSelection[spatialSelection.size()];
        spatialSelection.copyInto(ss);
        return ss;
    }
    return null;
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) Curve(cbit.vcell.geometry.Curve) SampledCurve(cbit.vcell.geometry.SampledCurve) CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SinglePoint(cbit.vcell.geometry.SinglePoint) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) Vector(java.util.Vector)

Example 7 with SpatialSelectionVolume

use of cbit.vcell.simdata.SpatialSelectionVolume in project vcell by virtualcell.

the class ASCIIExporter method getallSampleIndexes.

private int[] getallSampleIndexes(GeometrySpecs geometrySpecs, CartesianMesh mesh) throws DataAccessException {
    ArrayList<Integer> sampleIndexes = new ArrayList<>();
    SpatialSelection[] spatialSelections = geometrySpecs.getSelections();
    for (int i = 0; i < spatialSelections.length; i++) {
        spatialSelections[i].setMesh(mesh);
    }
    // Add points
    if (geometrySpecs.getPointIndexes().length > 0) {
        for (int i = 0; i < geometrySpecs.getPointIndexes().length; i++) {
            sampleIndexes.add(geometrySpecs.getPointIndexes()[i]);
        }
    }
    // Add curves
    if (geometrySpecs.getCurves().length != 0) {
        for (int i = 0; i < geometrySpecs.getCurves().length; i++) {
            SpatialSelection curve = geometrySpecs.getCurves()[i];
            curve.setMesh(mesh);
            if (curve instanceof SpatialSelectionVolume) {
                SpatialSelection.SSHelper ssh = ((SpatialSelectionVolume) curve).getIndexSamples(0.0, 1.0);
                for (int j = 0; j < ssh.getSampledIndexes().length; j++) {
                    sampleIndexes.add(ssh.getSampledIndexes()[j]);
                }
            // numSamplePoints+= ssh.getSampledIndexes().length;
            // pointIndexes = ssh.getSampledIndexes();
            // distances = ssh.getWorldCoordinateLengths();
            // crossingMembraneIndexes = ssh.getMembraneIndexesInOut();
            } else if (curve instanceof SpatialSelectionMembrane) {
                SpatialSelection.SSHelper ssh = ((SpatialSelectionMembrane) curve).getIndexSamples();
                if (((SpatialSelectionMembrane) curve).getSelectionSource() instanceof SinglePoint) {
                    sampleIndexes.add(ssh.getSampledIndexes()[0]);
                // numSamplePoints++;
                // pointIndexes = new int[] {ssh.getSampledIndexes()[0]};
                // distances = new double[] {0};
                } else {
                    for (int j = 0; j < ssh.getSampledIndexes().length; j++) {
                        sampleIndexes.add(ssh.getSampledIndexes()[j]);
                    }
                // numSamplePoints+= ssh.getSampledIndexes().length;
                // pointIndexes = ssh.getSampledIndexes();
                // distances = ssh.getWorldCoordinateLengths();
                }
            }
        }
    }
    if (sampleIndexes.size() > 0) {
        int[] allSampleIndexes = new int[sampleIndexes.size()];
        for (int i = 0; i < allSampleIndexes.length; i++) {
            allSampleIndexes[i] = sampleIndexes.get(i);
        }
        return allSampleIndexes;
    }
    return null;
}
Also used : SinglePoint(cbit.vcell.geometry.SinglePoint) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) ArrayList(java.util.ArrayList) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 8 with SpatialSelectionVolume

use of cbit.vcell.simdata.SpatialSelectionVolume in project vcell by virtualcell.

the class ASCIIExporter method getCurveTimeSeries.

/**
 * This method was created in VisualAge.
 * @return java.lang.String
 * @throws IOException
 */
private FileDataContainerID getCurveTimeSeries(int hdf5GroupVarID, PointsCurvesSlices pointsCurvesSlices, OutputContext outputContext, User user, DataServerImpl dataServerImpl, VCDataIdentifier vcdID, String variableName, SpatialSelection curve, double[] allTimes, int beginIndex, int endIndex, boolean switchRowsColumns, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
    int[] pointIndexes = null;
    double[] distances = null;
    int[] crossingMembraneIndexes = null;
    if (curve instanceof SpatialSelectionVolume) {
        SpatialSelection.SSHelper ssh = ((SpatialSelectionVolume) curve).getIndexSamples(0.0, 1.0);
        pointIndexes = ssh.getSampledIndexes();
        distances = ssh.getWorldCoordinateLengths();
        crossingMembraneIndexes = ssh.getMembraneIndexesInOut();
    } else if (curve instanceof SpatialSelectionMembrane) {
        SpatialSelection.SSHelper ssh = ((SpatialSelectionMembrane) curve).getIndexSamples();
        if (((SpatialSelectionMembrane) curve).getSelectionSource() instanceof SinglePoint) {
            pointIndexes = new int[] { ssh.getSampledIndexes()[0] };
            distances = new double[] { 0 };
        } else {
            pointIndexes = ssh.getSampledIndexes();
            distances = ssh.getWorldCoordinateLengths();
        }
    }
    pointsCurvesSlices.data.put(PCS.TIMES, new ArrayList<Double>());
    pointsCurvesSlices.data.put(PCS.TIMEBOUNDS, new int[] { beginIndex, endIndex });
    final TreeMap<PCS, Object> treePCS = new TreeMap<PCS, Object>();
    ((TreeMap<String, TreeMap<PCS, Object>>) pointsCurvesSlices.data.get(PCS.CURVES)).put(getSpatialSelectionDescription(curve), treePCS);
    treePCS.put(PCS.CURVEINDEXES, pointIndexes);
    treePCS.put(PCS.CURVEDISTANCES, distances);
    if (crossingMembraneIndexes != null) {
        treePCS.put(PCS.CURVECROSSMEMBRINDEX, crossingMembraneIndexes);
    }
    treePCS.put(PCS.CURVEVALS, new ArrayList<Double>());
    org.vcell.util.document.TimeSeriesJobSpec timeSeriesJobSpec = new org.vcell.util.document.TimeSeriesJobSpec(new String[] { variableName }, new int[][] { pointIndexes }, new int[][] { crossingMembraneIndexes }, allTimes[beginIndex], 1, allTimes[endIndex], VCDataJobID.createVCDataJobID(user, false));
    org.vcell.util.document.TSJobResultsNoStats timeSeriesJobResults = (org.vcell.util.document.TSJobResultsNoStats) dataServerImpl.getTimeSeriesValues(outputContext, user, vcdID, timeSeriesJobSpec);
    // variableValues[0] is time array
    // variableValues[1] is values for 1st spatial point.
    // variableValues[2] is values for 2nd spatial point.
    // variableValues[n] (n>=1) is values for nth spatial point.
    // the length of variableValues should always be 1 + pointIndexes.length
    // the length of variableValues[n] is allTimes.length
    final double[][] variableValues = timeSeriesJobResults.getTimesAndValuesForVariable(variableName);
    // 
    // put data in csv format
    // 
    FileDataContainerID fileDataContainerID = fileDataContainerManager.getNewFileDataContainerID();
    fileDataContainerManager.append(fileDataContainerID, "\"variable ('" + variableName + "') times (" + allTimes[beginIndex] + " " + allTimes[endIndex] + ") " + getSpatialSelectionDescription(curve) + "\"\n");
    if (switchRowsColumns) {
        fileDataContainerManager.append(fileDataContainerID, ",Distances\n");
        fileDataContainerManager.append(fileDataContainerID, "Times,");
        for (int i = beginIndex; i <= endIndex; i++) {
            fileDataContainerManager.append(fileDataContainerID, "," + allTimes[i]);
            ((ArrayList<Double>) pointsCurvesSlices.data.get(PCS.TIMES)).add(allTimes[i]);
        }
        fileDataContainerManager.append(fileDataContainerID, "\n");
        for (int j = 0; j < distances.length; j++) {
            fileDataContainerManager.append(fileDataContainerID, "," + distances[j]);
            for (int i = beginIndex; i <= endIndex; i++) {
                fileDataContainerManager.append(fileDataContainerID, "," + variableValues[j + 1][i - beginIndex]);
                ((ArrayList<Double>) treePCS.get(PCS.CURVEVALS)).add(variableValues[j + 1][i - beginIndex]);
            }
            fileDataContainerManager.append(fileDataContainerID, "\n");
        }
    } else {
        fileDataContainerManager.append(fileDataContainerID, ",Times\n");
        fileDataContainerManager.append(fileDataContainerID, "Distances,");
        for (int i = 0; i < distances.length; i++) {
            fileDataContainerManager.append(fileDataContainerID, "," + distances[i]);
        }
        fileDataContainerManager.append(fileDataContainerID, "\n");
        for (int i = beginIndex; i <= endIndex; i++) {
            fileDataContainerManager.append(fileDataContainerID, "," + allTimes[i]);
            ((ArrayList<Double>) pointsCurvesSlices.data.get(PCS.TIMES)).add(allTimes[i]);
            for (int j = 0; j < distances.length; j++) {
                fileDataContainerManager.append(fileDataContainerID, "," + variableValues[j + 1][i - beginIndex]);
                ((ArrayList<Double>) treePCS.get(PCS.CURVEVALS)).add(variableValues[j + 1][i - beginIndex]);
            }
            fileDataContainerManager.append(fileDataContainerID, "\n");
        }
    }
    if (curve instanceof SpatialSelectionMembrane) {
        fileDataContainerManager.append(fileDataContainerID, "\n");
        fileDataContainerManager.append(fileDataContainerID, "\"Centroid(XYZ):Times:Values[Times,Centroid]\",X,Y,Z,distance");
        for (int i = 0; i < variableValues[0].length; i++) {
            fileDataContainerManager.append(fileDataContainerID, "," + variableValues[0][i]);
            ((ArrayList<Double>) pointsCurvesSlices.data.get(PCS.TIMES)).add(variableValues[0][i]);
        }
        fileDataContainerManager.append(fileDataContainerID, "\n");
        double distance = 0;
        for (int i = 0; i < pointIndexes.length; i++) {
            if (pointIndexes.length > 1 && (i == (pointIndexes.length - 1)) && pointIndexes[i] == pointIndexes[i - 1]) {
                continue;
            }
            Coordinate coord = curve.getMesh().getCoordinateFromMembraneIndex(pointIndexes[i]);
            // double value = variableValues[i+1][0];
            fileDataContainerManager.append(fileDataContainerID, "," + coord.getX() + "," + coord.getY() + "," + coord.getZ());
            if (i > 0) {
                Coordinate prevCoord = curve.getMesh().getCoordinateFromMembraneIndex(pointIndexes[i - 1]);
                distance += coord.distanceTo(prevCoord);
            }
            fileDataContainerManager.append(fileDataContainerID, "," + distance);
            for (int t = 0; t < variableValues[t].length; t++) {
                fileDataContainerManager.append(fileDataContainerID, "," + variableValues[i + 1][t]);
                ((ArrayList<Double>) treePCS.get(PCS.CURVEVALS)).add(variableValues[i + 1][t]);
            }
            fileDataContainerManager.append(fileDataContainerID, "\n");
        }
    }
    if (hdf5GroupVarID != -1) {
        try {
            int hdf5GroupCurveID = H5.H5Gcreate(hdf5GroupVarID, getSpatialSelectionDescription(curve), HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
            // Hdf5Utils.writeHDF5Dataset(hdf5GroupCurveID, PCS.CURVEINDEXES.name(), new long[] {((int[])treePCS.get(PCS.CURVEINDEXES)).length}, (int[])treePCS.get(PCS.CURVEINDEXES),false);
            Hdf5Utils.insertInts(hdf5GroupCurveID, PCS.CURVEINDEXES.name(), new long[] { ((int[]) treePCS.get(PCS.CURVEINDEXES)).length }, (int[]) treePCS.get(PCS.CURVEINDEXES));
            // Hdf5Utils.writeHDF5Dataset(hdf5GroupCurveID, PCS.CURVEDISTANCES.name(), new long[] {((double[])treePCS.get(PCS.CURVEDISTANCES)).length}, (double[])treePCS.get(PCS.CURVEDISTANCES),false);
            Hdf5Utils.insertDoubles(hdf5GroupCurveID, PCS.CURVEDISTANCES.name(), new long[] { ((double[]) treePCS.get(PCS.CURVEDISTANCES)).length }, (double[]) treePCS.get(PCS.CURVEDISTANCES));
            if (treePCS.get(PCS.CURVECROSSMEMBRINDEX) != null) {
                // Hdf5Utils.writeHDF5Dataset(hdf5GroupCurveID, PCS.CURVECROSSMEMBRINDEX.name(), new long[] {((int[])treePCS.get(PCS.CURVECROSSMEMBRINDEX)).length}, (int[])treePCS.get(PCS.CURVECROSSMEMBRINDEX),false);
                Hdf5Utils.insertInts(hdf5GroupCurveID, PCS.CURVECROSSMEMBRINDEX.name(), new long[] { ((int[]) treePCS.get(PCS.CURVECROSSMEMBRINDEX)).length }, (int[]) treePCS.get(PCS.CURVECROSSMEMBRINDEX));
                ArrayList<Integer> crossPoints = new ArrayList<Integer>();
                for (int i = 0; i < crossingMembraneIndexes.length; i++) {
                    if (crossingMembraneIndexes[i] != -1) {
                        crossPoints.add(i);
                    }
                }
                String attrText = PCS.CURVEVALS.name() + " columns " + crossPoints.get(0) + " and " + crossPoints.get(1) + " are added points of interpolation near membrane";
                // Hdf5Utils.writeHDF5Dataset(hdf5GroupCurveID, PCS.CURVECROSSMEMBRINDEX.name()+" Info", null, attrText,true);
                Hdf5Utils.insertAttribute(hdf5GroupCurveID, PCS.CURVECROSSMEMBRINDEX.name() + " Info", attrText);
            }
            // Hdf5Utils.writeHDF5Dataset(hdf5GroupCurveID, PCS.CURVEVALS.name(), new long[] {endIndex-beginIndex+1,((int[])treePCS.get(PCS.CURVEINDEXES)).length}, (ArrayList<Double>)treePCS.get(PCS.CURVEVALS),false);
            Hdf5Utils.insertDoubles(hdf5GroupCurveID, PCS.CURVEVALS.name(), new long[] { endIndex - beginIndex + 1, ((int[]) treePCS.get(PCS.CURVEINDEXES)).length }, (ArrayList<Double>) treePCS.get(PCS.CURVEVALS));
            H5.H5Gclose(hdf5GroupCurveID);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAccessException(e.getMessage(), e);
        }
    }
    return fileDataContainerID;
}
Also used : TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) ArrayList(java.util.ArrayList) SinglePoint(cbit.vcell.geometry.SinglePoint) SpatialSelection(cbit.vcell.simdata.SpatialSelection) DataAccessException(org.vcell.util.DataAccessException) TreeMap(java.util.TreeMap) SinglePoint(cbit.vcell.geometry.SinglePoint) HDF5LibraryException(ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException) HDF5Exception(ncsa.hdf.hdf5lib.exceptions.HDF5Exception) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats) Coordinate(org.vcell.util.Coordinate) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) FileDataContainerID(cbit.vcell.export.server.FileDataContainerManager.FileDataContainerID) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 9 with SpatialSelectionVolume

use of cbit.vcell.simdata.SpatialSelectionVolume 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 10 with SpatialSelectionVolume

use of cbit.vcell.simdata.SpatialSelectionVolume in project vcell by virtualcell.

the class PDEDataViewer method showKymograph.

private void showKymograph() {
    String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Kymograph: ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
    final String INDICES_KEY = "INDICES_KEY";
    final String CROSSING_KEY = "CROSSING_KEY";
    final String ACCUM_KEY = "ACCUM_KEY";
    AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("multiTimePlotHelperTask...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Collect all sample curves created by user
            SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
            final Vector<SpatialSelection> lineSSOnly = new Vector<SpatialSelection>();
            if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
                // 
                for (int i = 0; i < spatialSelectionArr.length; i++) {
                    if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof cbit.vcell.geometry.SinglePoint)) {
                    } else {
                        lineSSOnly.add(spatialSelectionArr[i]);
                    }
                }
            }
            // 
            if (lineSSOnly.size() == 0) {
                throw new Exception("No line samples match DataType=" + getPdeDataContext().getDataIdentifier().getVariableType());
            }
            VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
            int[] indices = null;
            int[] crossingMembraneIndices = null;
            double[] accumDistances = null;
            for (int i = 0; i < lineSSOnly.size(); i++) {
                if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
                    SpatialSelectionVolume ssv = (SpatialSelectionVolume) lineSSOnly.get(i);
                    SpatialSelection.SSHelper ssh = ssv.getIndexSamples(0.0, 1.0);
                    indices = ssh.getSampledIndexes();
                    crossingMembraneIndices = ssh.getMembraneIndexesInOut();
                    accumDistances = ssh.getWorldCoordinateLengths();
                } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
                    SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) lineSSOnly.get(i);
                    SpatialSelection.SSHelper ssh = ssm.getIndexSamples();
                    indices = ssh.getSampledIndexes();
                    accumDistances = ssh.getWorldCoordinateLengths();
                }
            }
            if (indices != null) {
                hashTable.put(INDICES_KEY, indices);
            }
            if (crossingMembraneIndices != null) {
                hashTable.put(CROSSING_KEY, crossingMembraneIndices);
            }
            if (accumDistances != null) {
                hashTable.put(ACCUM_KEY, accumDistances);
            }
            MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) getPdeDataContext(), getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
            hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
        }
    };
    AsynchClientTask kymographTask = new AsynchClientTask("Kymograph showing...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            KymographPanel kymographPanel = new KymographPanel(PDEDataViewer.this, title, (MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY));
            SymbolTable symbolTable;
            if (getSimulation() != null && getSimulation().getMathDescription() != null) {
                symbolTable = getSimulation().getMathDescription();
            } else {
                symbolTable = new SimpleSymbolTable(new String[] { getPdeDataContext().getDataIdentifier().getName() });
            }
            ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
            ChildWindow childWindow = childWindowManager.addChildWindow(kymographPanel, kymographPanel, title);
            childWindow.setSize(new Dimension(700, 500));
            childWindow.show();
            kymographPanel.initDataManager(getPdeDataContext().getDataIdentifier(), getPdeDataContext().getTimePoints()[0], 1, getPdeDataContext().getTimePoints()[getPdeDataContext().getTimePoints().length - 1], (int[]) hashTable.get(INDICES_KEY), (int[]) hashTable.get(CROSSING_KEY), (double[]) hashTable.get(ACCUM_KEY), true, getPdeDataContext().getTimePoint(), symbolTable);
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { multiTimePlotHelperTask, kymographTask }, null, false, false, true, null, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SinglePoint(cbit.vcell.geometry.SinglePoint) Vector(java.util.Vector) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) ChildWindowManager(cbit.vcell.client.ChildWindowManager) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume)

Aggregations

SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)12 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)10 SinglePoint (cbit.vcell.geometry.SinglePoint)8 SpatialSelection (cbit.vcell.simdata.SpatialSelection)8 VariableType (cbit.vcell.math.VariableType)6 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)5 Hashtable (java.util.Hashtable)5 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)5 Plot2D (cbit.plot.Plot2D)4 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)4 Vector (java.util.Vector)4 DataAccessException (org.vcell.util.DataAccessException)4 TSJobResultsNoStats (org.vcell.util.document.TSJobResultsNoStats)4 ImageException (cbit.image.ImageException)3 SingleXPlot2D (cbit.plot.SingleXPlot2D)3 PlotPane (cbit.plot.gui.PlotPane)3 ChildWindowManager (cbit.vcell.client.ChildWindowManager)3 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)3 Curve (cbit.vcell.geometry.Curve)3 SampledCurve (cbit.vcell.geometry.SampledCurve)3