Search in sources :

Example 6 with Coordinate

use of org.vcell.util.Coordinate in project vcell by virtualcell.

the class PdeTimePlotMultipleVariablesPanel method initialize.

private void initialize() {
    VariableType varType = multiTimePlotHelper.getPdeDatacontext().getDataIdentifier().getVariableType();
    String varName = multiTimePlotHelper.getPdeDatacontext().getVariableName();
    String[] plotNames = new String[pointVector.size()];
    final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotNames.length];
    DefaultListModel<String> pointListModel = new DefaultListModel<String>();
    for (int i = 0; i < pointVector.size(); i++) {
        Coordinate tp = null;
        if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
            SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector.get(i);
            tp = ssv.getCurveSelectionInfo().getCurve().getBeginningCoordinate();
        } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
            SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector.get(i);
            double midU = ssm.getCurveSelectionInfo().getCurveUfromSelectionU(.5);
            tp = ((SampledCurve) ssm.getCurveSelectionInfo().getCurve()).coordinateFromNormalizedU(midU);
        }
        plotNames[i] = varName + " at P[" + i + "]";
        String point = "P[" + i + "]  (" + niceCoordinateString(tp) + ")";
        pointListModel.addElement(point);
        if (multiTimePlotHelper.getsimulation() != null) {
            symbolTableEntries[0] = multiTimePlotHelper.getsimulation().getMathDescription().getEntry(varName);
        } else {
            System.out.println("PdeTimePlotMultipleVariablesPanel.initialize() adding artificial symbol table entries for field data");
            SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(new String[] { varName });
            symbolTableEntries[0] = simpleSymbolTable.getEntry(varName);
        }
    }
    pointJList.setModel(pointListModel);
    pointJList.setForeground(variableJList.getForeground());
    pointJList.setVisibleRowCount(3);
    pointJList.setBackground(getBackground());
    pointJList.setSelectionBackground(getBackground());
    pointJList.setSelectionForeground(Color.black);
    plotPane = new PlotPane();
    double[][] plotDatas = tsJobResultsNoStats.getTimesAndValuesForVariable(varName);
    Plot2D plot2D = new SingleXPlot2D(symbolTableEntries, multiTimePlotHelper.getDataSymbolMetadataResolver(), ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
    plotPane.setPlot2D(plot2D);
    DataIdentifier[] dis = (multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() != null ? multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() : DataIdentifier.collectSortedSimilarDataTypes(multiTimePlotHelper.getVariableType(), multiTimePlotHelper.getPdeDatacontext().getDataIdentifiers()));
    Arrays.sort(dis, new Comparator<DataIdentifier>() {

        public int compare(DataIdentifier o1, DataIdentifier o2) {
            int bEqualIgnoreCase = o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
            if (bEqualIgnoreCase == 0) {
                return o1.getDisplayName().compareTo(o2.getDisplayName());
            }
            return bEqualIgnoreCase;
        }
    });
    variableJList.setListData(dis);
    initVariableListSelected(variableJList, multiTimePlotHelper.getPdeDatacontext().getDataIdentifier());
    variableJList.setCellRenderer(multiTimePlotHelper.getListCellRenderer());
    setLayout(new GridBagLayout());
    JLabel label = new JLabel("Selected Points");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new java.awt.Insets(15, 10, 4, 4);
    add(label, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.gridheight = 4;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new java.awt.Insets(0, 4, 0, 0);
    add(plotPane, gbc);
    JScrollPane sp = new JScrollPane(pointJList);
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weighty = 0.5;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.insets = new java.awt.Insets(4, 10, 4, 4);
    add(sp, gbc);
    label = new JLabel("Y Axis");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new java.awt.Insets(4, 10, 4, 4);
    add(label, gbc);
    sp = new JScrollPane(variableJList);
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.weightx = 0.2;
    gbc.weighty = 1;
    gbc.insets = new java.awt.Insets(4, 10, 50, 4);
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    add(sp, gbc);
    variableJList.addListSelectionListener(eventHandler);
    multiTimePlotHelper.addPropertyChangeListener(eventHandler);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) DataIdentifier(cbit.vcell.simdata.DataIdentifier) GridBagLayout(java.awt.GridBagLayout) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) DefaultListModel(javax.swing.DefaultListModel) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) JScrollPane(javax.swing.JScrollPane) SampledCurve(cbit.vcell.geometry.SampledCurve) VariableType(cbit.vcell.math.VariableType) JLabel(javax.swing.JLabel) SingleXPlot2D(cbit.plot.SingleXPlot2D) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Coordinate(org.vcell.util.Coordinate) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) PlotPane(cbit.plot.gui.PlotPane) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D)

Example 7 with Coordinate

use of org.vcell.util.Coordinate in project vcell by virtualcell.

the class PDEDataContextPanel method findChomboSinglePointSelectionInfoForPoint.

public CurveSelectionInfo findChomboSinglePointSelectionInfoForPoint(Coordinate wc) {
    if (getPdeDataContext().getCartesianMesh().isChomboMesh()) {
        CartesianMeshChombo chomboMesh = (CartesianMeshChombo) getPdeDataContext().getCartesianMesh();
        int memIndex = chomboMesh.findMembraneIndexFromVolumeCoordinate(wc);
        if (memIndex >= 0) {
            Coordinate coord = chomboMesh.getMembraneElements()[memIndex].getCentroid();
            return new CurveSelectionInfo(new SinglePoint(coord));
        }
    }
    return null;
}
Also used : SinglePoint(cbit.vcell.geometry.SinglePoint) Coordinate(org.vcell.util.Coordinate) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) CartesianMeshChombo(cbit.vcell.solvers.CartesianMeshChombo) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 8 with Coordinate

use of org.vcell.util.Coordinate in project vcell by virtualcell.

the class PDEDataContextPanel method projectCurveOntoSlice.

/**
 * Insert the method's description here.
 * Creation date: (7/16/2003 1:05:56 PM)
 * @return cbit.vcell.geometry.ControlPointCurve
 * @param curve cbit.vcell.geometry.ControlPointCurve
 */
private ControlPointCurve projectCurveOntoSlice(ControlPointCurve curve) {
    // for SinglePoint(timepoint) and PolyLine(spatial) samplers(always stored in world coordinates),
    // convert the curve coordinates into view coordinates from the sliceviewer
    ControlPointCurve cpCurve = null;
    java.util.Vector<Coordinate> cpV = new java.util.Vector<Coordinate>();
    int normalAxis = getimagePlaneManager1().getNormalAxis();
    for (int i = 0; i < curve.getControlPointCount(); i += 1) {
        // convert curves that are always stored in world coordinates into coordinates that
        // represent how user sees them in the slice viewer
        double xCoord = Coordinate.convertAxisFromStandardXYZToNormal(curve.getControlPoint(i), Coordinate.X_AXIS, normalAxis);
        double yCoord = Coordinate.convertAxisFromStandardXYZToNormal(curve.getControlPoint(i), Coordinate.Y_AXIS, normalAxis);
        // Get z from slice
        double zCoord = Coordinate.convertAxisFromStandardXYZToNormal(getimagePlaneManager1().getWorldCoordinateFromUnitized2D(0, 0), Coordinate.Z_AXIS, normalAxis);
        // These are now the real coordinates as they are viewed in the slice viewer
        // Coordinate newCoord = new Coordinate(xCoord,yCoord,zCoord);
        Coordinate newCoord = Coordinate.convertCoordinateFromNormalToStandardXYZ(xCoord, yCoord, zCoord, normalAxis);
        cpV.add(newCoord);
    }
    if (cpV.size() > 0) {
        Coordinate[] cpArr = new Coordinate[cpV.size()];
        cpV.copyInto(cpArr);
        // Determine if curve has been projected down to a single point
        boolean bSinglePoint = true;
        for (int i = 0; i < cpArr.length; i += 1) {
            if (i > 0 && !cpArr[i].equals(cpArr[i - 1])) {
                bSinglePoint = false;
                break;
            }
        }
        // if(curve instanceof SinglePoint){
        if (bSinglePoint) {
            cpCurve = new SinglePoint(cpArr[0]);
        } else if (curve instanceof SampledCurve) {
            cpCurve = new PolyLine(cpArr);
        }
    }
    return cpCurve;
}
Also used : SampledCurve(cbit.vcell.geometry.SampledCurve) PolyLine(cbit.vcell.geometry.PolyLine) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) SinglePoint(cbit.vcell.geometry.SinglePoint) Coordinate(org.vcell.util.Coordinate) Vector(java.util.Vector)

Example 9 with Coordinate

use of org.vcell.util.Coordinate in project vcell by virtualcell.

the class PDEDataContextPanel method getInitalCurveSelection.

/**
 * Insert the method's description here.
 * Creation date: (7/4/2003 6:10:48 PM)
 */
public CurveSelectionInfo getInitalCurveSelection(int tool, Coordinate wc) {
    // 
    CurveSelectionInfo newCurveSelection = null;
    VariableType variableType = getPdeDataContext().getDataIdentifier().getVariableType();
    if (variableType.equals(VariableType.MEMBRANE) || variableType.equals(VariableType.MEMBRANE_REGION)) {
        if (getPdeDataContext().getCartesianMesh().isChomboMesh() && tool == CurveEditorTool.TOOL_POINT) {
            newCurveSelection = findChomboSinglePointSelectionInfoForPoint(wc);
        } else {
            CurveSelectionInfo[] closeCSI = getImagePlaneManagerPanel().getCurveRenderer().getCloseCurveSelectionInfos(wc);
            if (closeCSI != null) {
                for (int i = 0; i < closeCSI.length; i += 1) {
                    if (membranesAndIndexes != null && membranesAndIndexes.containsKey(closeCSI[i].getCurve())) {
                        if (tool == CurveEditorTool.TOOL_LINE) {
                            newCurveSelection = new CurveSelectionInfo(new CurveSelectionCurve((SampledCurve) (closeCSI[i].getCurve())));
                        } else if (tool == CurveEditorTool.TOOL_POINT) {
                            newCurveSelection = new CurveSelectionInfo(new CurveSelectionCurve((SampledCurve) (closeCSI[i].getCurve())));
                            double dist = closeCSI[i].getCurve().getDistanceTo(wc);
                            int segmentIndex = closeCSI[i].getCurve().pickSegment(wc, dist * 1.1);
                            Coordinate[] coordArr = closeCSI[i].getCurve().getSampledCurve().getControlPointsForSegment(segmentIndex);
                            Coordinate middleCoord = new Coordinate((coordArr[0].getX() + coordArr[1].getX()) / 2, (coordArr[0].getY() + coordArr[1].getY()) / 2, (coordArr[0].getZ() + coordArr[1].getZ()) / 2);
                            newCurveSelection = new CurveSelectionInfo(new SinglePoint(middleCoord));
                        }
                        break;
                    }
                }
            }
        }
    }
    if (newCurveSelection != null) {
        if (membraneSamplerCurves == null) {
            membraneSamplerCurves = new java.util.Vector<Curve>();
        }
        membraneSamplerCurves.add(newCurveSelection.getCurve());
    }
    return newCurveSelection;
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SampledCurve(cbit.vcell.geometry.SampledCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) VariableType(cbit.vcell.math.VariableType) Coordinate(org.vcell.util.Coordinate) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) Curve(cbit.vcell.geometry.Curve) SampledCurve(cbit.vcell.geometry.SampledCurve) CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 10 with Coordinate

use of org.vcell.util.Coordinate in project vcell by virtualcell.

the class ASCIIExporter method exportParticleData.

/**
 * Insert the method's description here.
 * Creation date: (1/12/00 5:00:28 PM)
 * @return cbit.vcell.export.server.ExportOutput[]
 * @param dsc cbit.vcell.server.DataSetController
 * @param timeSpecs cbit.vcell.export.server.TimeSpecs
 * @throws IOException
 */
private List<ExportOutput> exportParticleData(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs, ASCIISpecs asciiSpecs, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
    VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
    TimeSpecs timeSpecs = exportSpecs.getTimeSpecs();
    String simID = vcdID.getID();
    String dataType = ".csv";
    // in switched format, how many rows for each particle
    final int N_PARTICLE_PIECES = 1;
    // get parameters
    boolean switchRowsColumns = asciiSpecs.getSwitchRowsColumns();
    double[] allTimes = timeSpecs.getAllTimes();
    int beginIndex = timeSpecs.getBeginTimeIndex();
    int endIndex = timeSpecs.getEndTimeIndex();
    ParticleDataBlock particleDataBlk = dataServerImpl.getParticleDataBlock(user, vcdID, allTimes[beginIndex]);
    VariableSpecs vs = exportSpecs.getVariableSpecs();
    VCAssert.assertValid(vs);
    String[] vnames = vs.getVariableNames();
    if (vnames.length == 0) {
        throw new IllegalArgumentException("No variables selected");
    }
    // need array for SimulationDescription, later
    final String[] currentVariableName = new String[1];
    ArrayList<ExportOutput> rval = new ArrayList<>(vnames.length);
    Set<String> species = particleDataBlk.getSpecies();
    ParticleProgress particleProgress = null;
    for (String vcellName : vnames) {
        String smoldynSpecies = null;
        for (int i = 0; smoldynSpecies == null && i < SMOLDYN_KEYWORDS_USED.length; i++) {
            SmoldynKeyword kw = SMOLDYN_KEYWORDS_USED[i];
            String smoldynName = SmoldynVCellMapper.vcellToSmoldyn(vcellName, kw);
            if (species.contains(smoldynName)) {
                smoldynSpecies = smoldynName;
            }
        }
        if (smoldynSpecies == null) {
            throw new DataAccessException("Unable to find match for variable name " + vcellName + " in " + StringUtils.join(species, ", "));
        }
        List<Coordinate> particles = particleDataBlk.getCoordinates(smoldynSpecies);
        int numberOfParticles = particles.size();
        int numberOfTimes = endIndex - beginIndex + 1;
        if (particleProgress != null) {
            particleProgress.nextName();
        } else {
            particleProgress = new ParticleProgress(jobID, vcdID, vnames.length, numberOfTimes, numberOfParticles);
        }
        // now make csv formatted data
        StringBuilder header = new StringBuilder();
        StringBuilder[] dataLines = null;
        final int NUMBER_HEADING_LINES = SwitchedRowsHeading.DATA.ordinal();
        if (switchRowsColumns) {
            dataLines = stringBuilderArray(numberOfParticles * N_PARTICLE_PIECES + NUMBER_HEADING_LINES);
            dataLines[SwitchedRowsHeading.TIME.ordinal()].append("Time,");
            final String particleLine = "Particle" + StringUtils.repeat(",x,y,z", numberOfTimes);
            dataLines[SwitchedRowsHeading.PARTICLE.ordinal()].append(particleLine);
            dataLines[SwitchedRowsHeading.XYZ.ordinal()].append("#,");
            // "first data line"
            final int FDL = SwitchedRowsHeading.DATA.ordinal();
            for (int i = 0; i < numberOfParticles; i++) {
                dataLines[FDL + N_PARTICLE_PIECES * i].append(i);
                dataLines[FDL + N_PARTICLE_PIECES * i].append(',');
            }
        } else {
            dataLines = stringBuilderArray(numberOfTimes);
        }
        currentVariableName[0] = vcellName;
        SimulationDescription simulationDescription = new SimulationDescription(outputContext, user, dataServerImpl, vcdID, false, currentVariableName);
        header.append(simulationDescription.getHeader(dataType));
        if (switchRowsColumns) {
        // implemented using first few data lines
        } else {
            header.append(",Time\n");
            header.append("Particle #,,");
            for (int k = 0; k < numberOfParticles; k++) {
                header.append(k + StringUtils.repeat(',', N_PARTICLE_PIECES));
            }
            header.append("\n,,");
            for (int k = 0; k < numberOfParticles; k++) {
                header.append("x,y,z,");
            }
        }
        final char COMMA = ',';
        int nextTimeIndex = particleProgress.nextTimeIndex(0, false);
        for (int i = beginIndex; i <= endIndex; i++) {
            particleDataBlk = dataServerImpl.getParticleDataBlock(user, vcdID, allTimes[i]);
            particles = particleDataBlk.getCoordinates(smoldynSpecies);
            if (i >= nextTimeIndex) {
                nextTimeIndex = particleProgress.nextTimeIndex(i, true);
            }
            if (switchRowsColumns) {
                // "first data line"
                final int FDL = SwitchedRowsHeading.DATA.ordinal();
                StringBuilder timeSb = dataLines[SwitchedRowsHeading.TIME.ordinal()];
                timeSb.append(allTimes[i]);
                timeSb.append(",,,");
                for (int j = 0; j < numberOfParticles; j++) {
                    StringBuilder sb = dataLines[FDL + N_PARTICLE_PIECES * j];
                    Coordinate coordinate = particles.get(j);
                    sb.append(coordinate.getX());
                    sb.append(COMMA);
                    sb.append(coordinate.getY());
                    sb.append(COMMA);
                    sb.append(coordinate.getZ());
                    sb.append(COMMA);
                }
            } else {
                StringBuilder particleSb = dataLines[i - beginIndex];
                particleSb.append(COMMA);
                particleSb.append(allTimes[i]);
                particleSb.append(COMMA);
                for (int j = 0; j < numberOfParticles; j++) {
                    Coordinate coordinate = particles.get(j);
                    particleSb.append(coordinate.getX());
                    particleSb.append(COMMA);
                    particleSb.append(coordinate.getY());
                    particleSb.append(COMMA);
                    particleSb.append(coordinate.getZ());
                }
            }
        }
        particleProgress.endOfTimes();
        final String dataID = vcellName + "_Particles";
        ExportOutput exportOutputCSV = new ExportOutput(true, dataType, simID, dataID, fileDataContainerManager);
        fileDataContainerManager.append(exportOutputCSV.getFileDataContainerID(), header.toString());
        int nextDataIndex = particleProgress.nextDataIndex(0, false);
        StringBuilder all = new StringBuilder();
        for (int i = 0; i < dataLines.length; i++) {
            final char NEWLINE = '\n';
            all.append(dataLines[i]);
            // kill reference to allow garbage collection
            dataLines[i] = null;
            all.append(NEWLINE);
            if (i >= nextDataIndex) {
                nextDataIndex = particleProgress.nextDataIndex(i, true);
            }
        }
        fileDataContainerManager.append(exportOutputCSV.getFileDataContainerID(), all.toString());
        rval.add(exportOutputCSV);
    }
    return rval;
}
Also used : ArrayList(java.util.ArrayList) SmoldynKeyword(org.vcell.solver.smoldyn.SmoldynVCellMapper.SmoldynKeyword) SinglePoint(cbit.vcell.geometry.SinglePoint) Coordinate(org.vcell.util.Coordinate) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataAccessException(org.vcell.util.DataAccessException) ParticleDataBlock(cbit.vcell.simdata.ParticleDataBlock)

Aggregations

Coordinate (org.vcell.util.Coordinate)81 CoordinateIndex (org.vcell.util.CoordinateIndex)16 SampledCurve (cbit.vcell.geometry.SampledCurve)11 SinglePoint (cbit.vcell.geometry.SinglePoint)11 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)10 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)6 Expression (cbit.vcell.parser.Expression)6 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 Vector (java.util.Vector)6 Extent (org.vcell.util.Extent)6 VariableType (cbit.vcell.math.VariableType)5 ISize (org.vcell.util.ISize)5 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)4 Curve (cbit.vcell.geometry.Curve)4 SubVolume (cbit.vcell.geometry.SubVolume)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Origin (org.vcell.util.Origin)4 VCImageUncompressed (cbit.image.VCImageUncompressed)3 Line (cbit.vcell.geometry.Line)3