Search in sources :

Example 1 with SinglePoint

use of cbit.vcell.geometry.SinglePoint in project vcell by virtualcell.

the class PDEDataViewer method getFillROI.

private BitSet getFillROI(SpatialSelectionVolume spatialSelectionVolume) {
    if (spatialSelectionVolume.getCurveSelectionInfo().getCurve() instanceof SinglePoint) {
        return null;
    }
    BitSet fillROI = null;
    SSHelper ssHelper = spatialSelectionVolume.getIndexSamples(0, 1);
    if (ssHelper != null && ssHelper.getSampledIndexes()[0] == ssHelper.getSampledIndexes()[ssHelper.getSampledIndexes().length - 1]) {
        Point projMin = null;
        Point projMax = null;
        Point[] projVolCI = new Point[ssHelper.getSampledIndexes().length];
        for (int i = 0; i < ssHelper.getSampledIndexes().length; i++) {
            CoordinateIndex vCI = getPdeDataContext().getCartesianMesh().getCoordinateIndexFromVolumeIndex(ssHelper.getSampledIndexes()[i]);
            int normalAxis = getPDEDataContextPanel1().getNormalAxis();
            projVolCI[i] = new Point((int) Coordinate.convertAxisFromStandardXYZToNormal(vCI.x, vCI.y, vCI.z, Coordinate.X_AXIS, normalAxis), (int) Coordinate.convertAxisFromStandardXYZToNormal(vCI.x, vCI.y, vCI.z, Coordinate.Y_AXIS, normalAxis));
            if (i == 0) {
                projMin = new Point(projVolCI[i]);
                projMax = new Point(projMin);
            } else {
                if (projVolCI[i].x < projMin.x) {
                    projMin.x = projVolCI[i].x;
                }
                if (projVolCI[i].y < projMin.y) {
                    projMin.y = projVolCI[i].y;
                }
                if (projVolCI[i].x > projMax.x) {
                    projMax.x = projVolCI[i].x;
                }
                if (projVolCI[i].y > projMax.y) {
                    projMax.y = projVolCI[i].y;
                }
            }
        }
        // System.out.println(projMin+" "+projMax);
        int UNMARKED = 0;
        int BOUNDARY_MARK = 1;
        // Create work area
        int[][] markers = new int[projMax.y - projMin.y + 1][projMax.x - projMin.x + 1];
        Vector<Vector<Point>> allSeedsV = new Vector<Vector<Point>>();
        allSeedsV.add(null);
        allSeedsV.add(null);
        // Mark boundary
        for (int i = 0; i < projVolCI.length; i++) {
            markers[projVolCI[i].y - projMin.y][projVolCI[i].x - projMin.x] = BOUNDARY_MARK;
        }
        // Create seeds around boundary
        for (int i = 0; i < projVolCI.length; i++) {
            if (projVolCI[i].x - 1 >= projMin.x) {
                int currentMark = markers[projVolCI[i].y - projMin.y][projVolCI[i].x - projMin.x - 1];
                if (currentMark == UNMARKED) {
                    Vector<Point> newSeedV = new Vector<Point>();
                    newSeedV.add(new Point(projVolCI[i].x - 1, projVolCI[i].y));
                    markers[projVolCI[i].y - projMin.y][projVolCI[i].x - projMin.x - 1] = allSeedsV.size();
                    allSeedsV.add(newSeedV);
                }
            }
            if (projVolCI[i].x + 1 <= projMax.x) {
                int currentMark = markers[projVolCI[i].y - projMin.y][projVolCI[i].x - projMin.x + 1];
                if (currentMark == UNMARKED) {
                    Vector<Point> newSeedV = new Vector<Point>();
                    newSeedV.add(new Point(projVolCI[i].x + 1, projVolCI[i].y));
                    markers[projVolCI[i].y - projMin.y][projVolCI[i].x - projMin.x + 1] = allSeedsV.size();
                    allSeedsV.add(newSeedV);
                }
            }
            if (projVolCI[i].y - 1 >= projMin.y) {
                int currentMark = markers[projVolCI[i].y - projMin.y - 1][projVolCI[i].x - projMin.x];
                if (currentMark == UNMARKED) {
                    Vector<Point> newSeedV = new Vector<Point>();
                    newSeedV.add(new Point(projVolCI[i].x, projVolCI[i].y - 1));
                    markers[projVolCI[i].y - projMin.y - 1][projVolCI[i].x - projMin.x] = allSeedsV.size();
                    allSeedsV.add(newSeedV);
                }
            }
            if (projVolCI[i].y + 1 <= projMax.y) {
                int currentMark = markers[projVolCI[i].y - projMin.y + 1][projVolCI[i].x - projMin.x];
                if (currentMark == UNMARKED) {
                    Vector<Point> newSeedV = new Vector<Point>();
                    newSeedV.add(new Point(projVolCI[i].x, projVolCI[i].y + 1));
                    markers[projVolCI[i].y - projMin.y + 1][projVolCI[i].x - projMin.x] = allSeedsV.size();
                    allSeedsV.add(newSeedV);
                }
            }
        }
        // Grow seeds
        for (int i = 2; i < allSeedsV.size(); i++) {
            while (allSeedsV.elementAt(i) != null && allSeedsV.elementAt(i).size() > 0) {
                Point currentPoint = allSeedsV.elementAt(i).remove(0);
                if (currentPoint.x - 1 >= projMin.x) {
                    int currentMark = markers[currentPoint.y - projMin.y][currentPoint.x - projMin.x - 1];
                    if (currentMark == UNMARKED) {
                        allSeedsV.elementAt(i).add(new Point(currentPoint.x - 1, currentPoint.y));
                        markers[currentPoint.y - projMin.y][currentPoint.x - projMin.x - 1] = i;
                    } else if (currentMark != BOUNDARY_MARK && currentMark != i) {
                        for (int j = 0; j < allSeedsV.elementAt(currentMark).size(); j++) {
                            if (!allSeedsV.elementAt(i).contains(allSeedsV.elementAt(currentMark).elementAt(j))) {
                                allSeedsV.elementAt(i).add(allSeedsV.elementAt(currentMark).elementAt(j));
                                markers[allSeedsV.elementAt(currentMark).elementAt(j).y - projMin.y][allSeedsV.elementAt(currentMark).elementAt(j).x - projMin.x] = i;
                            }
                        }
                        allSeedsV.setElementAt(null, currentMark);
                    }
                }
                if (currentPoint.x + 1 <= projMax.x) {
                    int currentMark = markers[currentPoint.y - projMin.y][currentPoint.x - projMin.x + 1];
                    if (currentMark == UNMARKED) {
                        allSeedsV.elementAt(i).add(new Point(currentPoint.x + 1, currentPoint.y));
                        markers[currentPoint.y - projMin.y][currentPoint.x - projMin.x + 1] = i;
                    } else if (currentMark != BOUNDARY_MARK && currentMark != i) {
                        for (int j = 0; j < allSeedsV.elementAt(currentMark).size(); j++) {
                            if (!allSeedsV.elementAt(i).contains(allSeedsV.elementAt(currentMark).elementAt(j))) {
                                allSeedsV.elementAt(i).add(allSeedsV.elementAt(currentMark).elementAt(j));
                                markers[allSeedsV.elementAt(currentMark).elementAt(j).y - projMin.y][allSeedsV.elementAt(currentMark).elementAt(j).x - projMin.x] = i;
                            }
                        }
                        allSeedsV.setElementAt(null, currentMark);
                    }
                }
                if (currentPoint.y - 1 >= projMin.y) {
                    int currentMark = markers[currentPoint.y - projMin.y - 1][currentPoint.x - projMin.x];
                    if (currentMark == UNMARKED) {
                        allSeedsV.elementAt(i).add(new Point(currentPoint.x, currentPoint.y - 1));
                        markers[currentPoint.y - projMin.y - 1][currentPoint.x - projMin.x] = i;
                    } else if (currentMark != BOUNDARY_MARK && currentMark != i) {
                        for (int j = 0; j < allSeedsV.elementAt(currentMark).size(); j++) {
                            if (!allSeedsV.elementAt(i).contains(allSeedsV.elementAt(currentMark).elementAt(j))) {
                                allSeedsV.elementAt(i).add(allSeedsV.elementAt(currentMark).elementAt(j));
                                markers[allSeedsV.elementAt(currentMark).elementAt(j).y - projMin.y][allSeedsV.elementAt(currentMark).elementAt(j).x - projMin.x] = i;
                            }
                        }
                        allSeedsV.setElementAt(null, currentMark);
                    }
                }
                if (currentPoint.y + 1 <= projMax.y) {
                    int currentMark = markers[currentPoint.y - projMin.y + 1][currentPoint.x - projMin.x];
                    if (currentMark == UNMARKED) {
                        allSeedsV.elementAt(i).add(new Point(currentPoint.x, currentPoint.y + 1));
                        markers[currentPoint.y - projMin.y + 1][currentPoint.x - projMin.x] = i;
                    } else if (currentMark != BOUNDARY_MARK && currentMark != i) {
                        for (int j = 0; j < allSeedsV.elementAt(currentMark).size(); j++) {
                            if (!allSeedsV.elementAt(i).contains(allSeedsV.elementAt(currentMark).elementAt(j))) {
                                allSeedsV.elementAt(i).add(allSeedsV.elementAt(currentMark).elementAt(j));
                                markers[allSeedsV.elementAt(currentMark).elementAt(j).y - projMin.y][allSeedsV.elementAt(currentMark).elementAt(j).x - projMin.x] = i;
                            }
                        }
                        allSeedsV.setElementAt(null, currentMark);
                    }
                }
            }
            allSeedsV.setElementAt(null, i);
        }
        int[] encodeEdge = new int[allSeedsV.size()];
        for (int i = 0; i < encodeEdge.length; i++) {
            encodeEdge[i] = i;
        }
        int c = 0;
        while (true) {
            if (c < markers.length) {
                encodeEdge[markers[c][0]] = UNMARKED;
                encodeEdge[markers[c][markers[0].length - 1]] = UNMARKED;
            }
            if (c < markers[0].length) {
                encodeEdge[markers[0][c]] = UNMARKED;
                encodeEdge[markers[markers.length - 1][c]] = UNMARKED;
            }
            c++;
            if (c >= markers.length && c >= markers[0].length) {
                break;
            }
        }
        // boundary
        encodeEdge[1] = 1;
        // System.out.println("Distinct Areas");
        // for (int i = 0; i < markers.length; i++) {
        // for (int j = 0; j < markers[i].length; j++) {
        // System.out.print((encodeEdge[markers[i][j]] < 10?"0":"")+encodeEdge[markers[i][j]]+" ");
        // }
        // System.out.println();
        // }
        // Make BitSet
        fillROI = new BitSet(getPdeDataContext().getDataValues().length);
        CoordinateIndex coordinateIndex = new CoordinateIndex();
        for (int y = 0; y < markers.length; y++) {
            for (int x = 0; x < markers[y].length; x++) {
                if (encodeEdge[markers[y][x]] != UNMARKED) {
                    coordinateIndex.x = projMin.x + x;
                    coordinateIndex.y = projMin.y + y;
                    coordinateIndex.z = getPDEDataContextPanel1().getSlice();
                    Coordinate.convertCoordinateIndexFromNormalToStandardXYZ(coordinateIndex, getPDEDataContextPanel1().getNormalAxis());
                    // System.out.println(coordinateIndex);
                    int volIndex = getPdeDataContext().getCartesianMesh().getVolumeIndex(coordinateIndex);
                    fillROI.set(volIndex);
                }
            }
        }
    }
    return fillROI;
}
Also used : SinglePoint(cbit.vcell.geometry.SinglePoint) BitSet(java.util.BitSet) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) CoordinateIndex(org.vcell.util.CoordinateIndex) Vector(java.util.Vector) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 2 with SinglePoint

use of cbit.vcell.geometry.SinglePoint in project vcell by virtualcell.

the class PDEDataViewer method roiAction.

private void roiAction() {
    BeanUtils.setCursorThroughout(this, Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try {
        final String[] ROI_COLUMN_NAMES = new String[] { "ROI source", "ROI source name", "ROI Description" };
        final Vector<Object> auxInfoV = new Vector<Object>();
        final DataIdentifier dataIdentifier = getPdeDataContext().getDataIdentifier();
        VariableType variableType = dataIdentifier.getVariableType();
        final boolean isVolume = variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION);
        DefaultTableModel tableModel = new DefaultTableModel() {

            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        for (int i = 0; i < ROI_COLUMN_NAMES.length; i++) {
            tableModel.addColumn(ROI_COLUMN_NAMES[i]);
        }
        // Add Snapshot ROI
        if ((isVolume ? volumeSnapshotROI : membraneSnapshotROI) != null) {
            tableModel.addRow(new Object[] { (isVolume ? "Volume" : "Membrane") + " Variables and Functions", "Snapshot", (isVolume ? volumeSnapshotROIDescription : membraneSnapshotROIDescription) + ", (values = 1.0)" });
            auxInfoV.add((isVolume ? volumeSnapshotROI : membraneSnapshotROI));
        }
        // Add user ROIs
        SpatialSelection[] userROIArr = getPDEDataContextPanel1().fetchSpatialSelections(true, false);
        for (int i = 0; userROIArr != null && i < userROIArr.length; i += 1) {
            String descr = null;
            boolean bPoint = false;
            if (isVolume) {
                if (userROIArr[i] instanceof SpatialSelectionVolume) {
                    Curve curve = ((SpatialSelectionVolume) userROIArr[i]).getCurveSelectionInfo().getCurve();
                    descr = curve.getDescription();
                    if (curve instanceof SinglePoint) {
                        bPoint = true;
                    }
                }
            } else {
                if (userROIArr[i] instanceof SpatialSelectionMembrane) {
                    SampledCurve selectionSource = ((SpatialSelectionMembrane) userROIArr[i]).getSelectionSource();
                    descr = selectionSource.getDescription();
                    if (selectionSource instanceof SinglePoint) {
                        bPoint = true;
                    }
                }
            }
            // Add Area User ROI
            BitSet fillBitSet = null;
            if (userROIArr[i] instanceof SpatialSelectionVolume) {
                fillBitSet = getFillROI((SpatialSelectionVolume) userROIArr[i]);
                if (fillBitSet != null) {
                    tableModel.addRow(new Object[] { "User Defined", descr, "Area Enclosed Volume ROI" });
                    auxInfoV.add(fillBitSet);
                }
            }
            // Add Point and Line User ROI
            if (fillBitSet == null) {
                tableModel.addRow(new Object[] { "User Defined", descr, (bPoint ? "Point" : "Line") + (isVolume ? " Volume" : " Membrane") + " ROI " });
                auxInfoV.add(userROIArr[i]);
            }
        }
        // Add sorted Geometry ROI
        final CartesianMesh cartesianMesh = getPdeDataContext().getCartesianMesh();
        HashMap<Integer, ?> regionMapSubvolumesHashMap = (isVolume ? cartesianMesh.getVolumeRegionMapSubvolume() : cartesianMesh.getMembraneRegionMapSubvolumesInOut());
        Set<?> regionMapSubvolumesEntrySet = regionMapSubvolumesHashMap.entrySet();
        Iterator<?> regionMapSubvolumesEntryIter = regionMapSubvolumesEntrySet.iterator();
        TreeSet<Object[]> sortedGeomROITreeSet = new TreeSet<Object[]>(new Comparator<Object[]>() {

            public int compare(Object[] o1, Object[] o2) {
                int result = ((String) ((Object[]) o1[0])[1]).compareToIgnoreCase((String) ((Object[]) o2[0])[1]);
                if (result == 0) {
                    result = (((Entry<Integer, ?>) o1[1]).getKey()).compareTo(((Entry<Integer, ?>) o2[1]).getKey());
                }
                return result;
            }
        });
        while (regionMapSubvolumesEntryIter.hasNext()) {
            Entry<Integer, ?> regionMapSubvolumesEntry = (Entry<Integer, ?>) regionMapSubvolumesEntryIter.next();
            sortedGeomROITreeSet.add(new Object[] { new Object[] { "Geometry", (isVolume ? getSimulationModelInfo().getVolumeNamePhysiology(((Integer) regionMapSubvolumesEntry.getValue())) : getSimulationModelInfo().getMembraneName(((int[]) regionMapSubvolumesEntry.getValue())[0], ((int[]) regionMapSubvolumesEntry.getValue())[1], false)), (isVolume ? "(svID=" + regionMapSubvolumesEntry.getValue() + " " : "(") + "vrID=" + regionMapSubvolumesEntry.getKey() + ") Predefined " + (isVolume ? "volume" : "membrane") + " region" }, regionMapSubvolumesEntry });
        }
        Iterator<Object[]> sortedGeomROIIter = sortedGeomROITreeSet.iterator();
        while (sortedGeomROIIter.hasNext()) {
            Object[] sortedGeomROIObjArr = (Object[]) sortedGeomROIIter.next();
            tableModel.addRow((Object[]) sortedGeomROIObjArr[0]);
            auxInfoV.add(sortedGeomROIObjArr[1]);
        }
        final ScrollTable roiTable = new ScrollTable();
        roiTable.setModel(tableModel);
        roiTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        roiTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
        final JPanel mainJPanel = new JPanel();
        BoxLayout mainBL = new BoxLayout(mainJPanel, BoxLayout.Y_AXIS);
        mainJPanel.setLayout(mainBL);
        MiniTimePanel timeJPanel = new MiniTimePanel();
        ActionListener okAction = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (((Double) timeJPanel.jcb_time_begin.getSelectedItem()).compareTo((Double) timeJPanel.jcb_time_end.getSelectedItem()) > 0) {
                    PopupGenerator.showErrorDialog(PDEDataViewer.this, "Selected 'Begin Time' must be less than or equal to 'End Time'");
                    return;
                }
                int[] selectedRows = roiTable.getSelectedRows();
                if (selectedRows != null) {
                    try {
                        BitSet dataBitSet = new BitSet(getPdeDataContext().getDataValues().length);
                        for (int i = 0; i < selectedRows.length; i++) {
                            Object auxInfo = auxInfoV.elementAt(selectedRows[i]);
                            if (auxInfo instanceof BitSet) {
                                dataBitSet.or((BitSet) auxInfo);
                            } else if (auxInfo instanceof SpatialSelectionMembrane) {
                                int[] roiIndexes = ((SpatialSelectionMembrane) auxInfo).getIndexSamples().getSampledIndexes();
                                for (int j = 0; j < roiIndexes.length; j += 1) {
                                    dataBitSet.set(roiIndexes[j], true);
                                }
                            } else if (auxInfo instanceof SpatialSelectionVolume) {
                                int[] roiIndexes = ((SpatialSelectionVolume) auxInfo).getIndexSamples(0, 1).getSampledIndexes();
                                for (int j = 0; j < roiIndexes.length; j += 1) {
                                    dataBitSet.set(roiIndexes[j], true);
                                }
                            } else if (auxInfo instanceof Entry) {
                                Entry<Integer, Integer> entry = (Entry<Integer, Integer>) auxInfo;
                                if (isVolume) {
                                    int volumeRegionID = entry.getKey();
                                    dataBitSet.or(cartesianMesh.getVolumeROIFromVolumeRegionID(volumeRegionID));
                                } else {
                                    int membraneRegionID = entry.getKey();
                                    dataBitSet.or(cartesianMesh.getMembraneROIFromMembraneRegionID(membraneRegionID));
                                }
                            } else if (auxInfo instanceof BitSet) {
                                dataBitSet.or((BitSet) auxInfo);
                            } else {
                                throw new Exception("ROI table, Unknown data type: " + auxInfo.getClass().getName());
                            }
                        }
                        TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { dataIdentifier.getName() }, new BitSet[] { dataBitSet }, ((Double) timeJPanel.jcb_time_begin.getSelectedItem()).doubleValue(), 1, ((Double) timeJPanel.jcb_time_end.getSelectedItem()).doubleValue(), true, false, VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
                        Hashtable<String, Object> hash = new Hashtable<String, Object>();
                        hash.put(StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
                        AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieve data for '" + dataIdentifier + "'", PDEDataViewer.this, getPdeDataContext());
                        AsynchClientTask task2 = new AsynchClientTask("Showing stat for '" + dataIdentifier + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                            @Override
                            public void run(Hashtable<String, Object> hashTable) throws Exception {
                                TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) hashTable.get(StringKey_timeSeriesJobResults);
                                plotSpaceStats(tsJobResultsSpaceStats);
                            }
                        };
                        ClientTaskDispatcher.dispatch(PDEDataViewer.this, hash, new AsynchClientTask[] { task1, task2 }, true, true, null);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                        PopupGenerator.showErrorDialog(PDEDataViewer.this, "ROI Error.\n" + e1.getMessage(), e1);
                    }
                }
                BeanUtils.disposeParentWindow(mainJPanel);
            }
        };
        ActionListener cancelAction = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                BeanUtils.disposeParentWindow(mainJPanel);
            }
        };
        OkCancelSubPanel okCancelJPanel = new OkCancelSubPanel(okAction, cancelAction);
        roiTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                if (roiTable.getSelectedRows() != null && roiTable.getSelectedRows().length > 0) {
                    okCancelJPanel.okButton.setEnabled(true);
                } else {
                    okCancelJPanel.okButton.setEnabled(false);
                }
            }
        });
        mainJPanel.add(timeJPanel);
        mainJPanel.add(roiTable.getEnclosingScrollPane());
        mainJPanel.add(okCancelJPanel);
        // showComponentInFrame(mainJPanel,
        // "Calculate "+(isVolume?"volume":"membrane")+" statistics for '"+getPdeDataContext().getVariableName()+"'."+
        // "  Choose times and 1 or more ROI(s).");
        Frame dialogOwner = JOptionPane.getFrameForComponent(this);
        JOptionPane inputDialog = new JOptionPane(mainJPanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[0]);
        final JDialog d = inputDialog.createDialog(dialogOwner, "Calculate " + (isVolume ? "volume" : "membrane") + " statistics for '" + getPdeDataContext().getVariableName() + "'." + "  Choose times and 1 or more ROI(s).");
        d.setResizable(true);
        try {
            DialogUtils.showModalJDialogOnTop(d, PDEDataViewer.this);
        } finally {
            d.dispose();
        }
    } finally {
        BeanUtils.setCursorThroughout(this, Cursor.getDefaultCursor());
    }
}
Also used : JPanel(javax.swing.JPanel) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ScrollTable(org.vcell.util.gui.ScrollTable) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ActionEvent(java.awt.event.ActionEvent) TreeSet(java.util.TreeSet) Vector(java.util.Vector) SampledCurve(cbit.vcell.geometry.SampledCurve) Curve(cbit.vcell.geometry.Curve) BitSet(java.util.BitSet) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) JOptionPane(javax.swing.JOptionPane) ListSelectionListener(javax.swing.event.ListSelectionListener) CartesianMesh(cbit.vcell.solvers.CartesianMesh) ActionListener(java.awt.event.ActionListener) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) JDialog(javax.swing.JDialog) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Frame(java.awt.Frame) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) DefaultTableModel(javax.swing.table.DefaultTableModel) BoxLayout(javax.swing.BoxLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Entry(java.util.Map.Entry) UserDataEntry(cbit.vcell.export.gloworm.atoms.UserDataEntry) SinglePoint(cbit.vcell.geometry.SinglePoint) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SampledCurve(cbit.vcell.geometry.SampledCurve) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) Dimension(java.awt.Dimension) 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)

Example 3 with SinglePoint

use of cbit.vcell.geometry.SinglePoint 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 4 with SinglePoint

use of cbit.vcell.geometry.SinglePoint 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 5 with SinglePoint

use of cbit.vcell.geometry.SinglePoint 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)

Aggregations

SinglePoint (cbit.vcell.geometry.SinglePoint)15 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)6 CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)6 SampledCurve (cbit.vcell.geometry.SampledCurve)6 VariableType (cbit.vcell.math.VariableType)6 Vector (java.util.Vector)6 Curve (cbit.vcell.geometry.Curve)5 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)5 SpatialSelection (cbit.vcell.simdata.SpatialSelection)5 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)5 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)5 Coordinate (org.vcell.util.Coordinate)5 PolyLine (cbit.vcell.geometry.PolyLine)3 Point (java.awt.Point)3 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)3 ImageException (cbit.image.ImageException)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 CurveRenderer (cbit.vcell.geometry.CurveRenderer)2 Spline (cbit.vcell.geometry.Spline)2 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2