Search in sources :

Example 6 with CurveSelectionInfo

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

the class CurveEditorTool method mouseDragged.

/**
 * This method was created in VisualAge.
 * @param event java.awt.event.MouseEvent
 */
public void mouseDragged(MouseEvent event) {
    if (!getProperlyConfigured() || !getCurveRenderer().getSelectionValid()) {
        return;
    }
    if (getTool() != TOOL_SELECT) {
        // Prevents spurious coordinate changes with other tools
        return;
    }
    CurveSelectionInfo csi = getCurveRenderer().getSelection();
    if (csi != null) {
        if (csi.getType() == CurveSelectionInfo.TYPE_SEGMENT || csi.getType() == CurveSelectionInfo.TYPE_U) {
            // extend the selection
            CurveSelectionInfo csiExtended = getCurveRenderer().extend(getWorldCoordinateValue(event.getPoint()));
            if (csiExtended != null) {
                getCurveRenderer().setSelection(csiExtended);
            }
        } else {
            // move the selection
            if (lastSnappedWorldCoord != null) {
                // getCurveRenderer().move(event.getPoint().x - lastPoint.x, event.getPoint().y - lastPoint.y);
                if (csi.getCurve() instanceof ControlPointCurve && getCurveRenderer().getRenderPropertyEditable(csi.getCurve())) {
                    Coordinate currentSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
                    if (!lastSnappedWorldCoord.compareEqual(currentSnappedWorldCoord)) {
                        double xDelta = Coordinate.convertAxisFromStandardXYZToNormal(currentSnappedWorldCoord, Coordinate.X_AXIS, getCurveRenderer().getNormalAxis()) - Coordinate.convertAxisFromStandardXYZToNormal(lastSnappedWorldCoord, Coordinate.X_AXIS, getCurveRenderer().getNormalAxis());
                        double yDelta = Coordinate.convertAxisFromStandardXYZToNormal(currentSnappedWorldCoord, Coordinate.Y_AXIS, getCurveRenderer().getNormalAxis()) - Coordinate.convertAxisFromStandardXYZToNormal(lastSnappedWorldCoord, Coordinate.Y_AXIS, getCurveRenderer().getNormalAxis());
                        if (move(xDelta, yDelta, csi, getCurveRenderer().getNormalAxis(), event.isControlDown())) {
                            lastSnappedWorldCoord = currentSnappedWorldCoord;
                        }
                    }
                } else {
                    lastSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
                }
            }
        }
        getVcellDrawable().repaint();
    }
}
Also used : Coordinate(org.vcell.util.Coordinate) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo)

Example 7 with CurveSelectionInfo

use of cbit.vcell.geometry.CurveSelectionInfo 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 8 with CurveSelectionInfo

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

the class PDEDataContextPanel method findChomboCurveSelectionInfoForPoint.

@Override
public CurveSelectionInfo findChomboCurveSelectionInfoForPoint(CoordinateIndex ci) {
    if (getPdeDataContext().getCartesianMesh().isChomboMesh()) {
        CartesianMeshChombo chomboMesh = (CartesianMeshChombo) getPdeDataContext().getCartesianMesh();
        int memIndex = chomboMesh.findMembraneIndexFromVolumeIndex(ci);
        if (memIndex >= 0) {
            for (Entry<SampledCurve, int[]> entry : membranesAndIndexes.entrySet()) {
                SampledCurve sc = entry.getKey();
                int[] memIndexes = entry.getValue();
                for (int idx = 0; idx < memIndexes.length; ++idx) {
                    if (memIndexes[idx] == memIndex) {
                        return new CurveSelectionInfo(sc, CurveSelectionInfo.TYPE_SEGMENT, idx);
                    }
                }
            }
        }
    }
    return null;
}
Also used : SampledCurve(cbit.vcell.geometry.SampledCurve) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) CartesianMeshChombo(cbit.vcell.solvers.CartesianMeshChombo) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 9 with CurveSelectionInfo

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

the class PDEDataContextPanel method isAddControlPointOK.

/**
 * Insert the method's description here.
 * Creation date: (7/4/2003 6:10:48 PM)
 */
public boolean isAddControlPointOK(int tool, Coordinate wc, Curve addedToThisCurve) {
    // 
    CurveRenderer curveR = getImagePlaneManagerPanel().getCurveRenderer();
    VariableType variableType = getPdeDataContext().getDataIdentifier().getVariableType();
    if (variableType.equals(VariableType.POSTPROCESSING) || variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION)) {
        return true;
    }
    if (variableType.equals(VariableType.MEMBRANE) || variableType.equals(VariableType.MEMBRANE_REGION)) {
        CurveSelectionInfo[] closeCSI = curveR.getCloseCurveSelectionInfos(wc);
        if (closeCSI != null && closeCSI.length > 0) {
            for (int i = 0; i < closeCSI.length; i += 1) {
                if (tool == CurveEditorTool.TOOL_POINT && addedToThisCurve instanceof SinglePoint && membranesAndIndexes != null && membranesAndIndexes.containsKey(closeCSI[i].getCurve())) {
                    return true;
                } else if (tool == CurveEditorTool.TOOL_LINE && addedToThisCurve instanceof CurveSelectionCurve) {
                    Curve sourceCurve = ((CurveSelectionCurve) (addedToThisCurve)).getSourceCurveSelectionInfo().getCurve();
                    if (sourceCurve == closeCSI[i].getCurve()) {
                        if (membranesAndIndexes != null && membranesAndIndexes.containsKey(sourceCurve)) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) VariableType(cbit.vcell.math.VariableType) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) Curve(cbit.vcell.geometry.Curve) SampledCurve(cbit.vcell.geometry.SampledCurve) CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) CurveRenderer(cbit.vcell.geometry.CurveRenderer) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 10 with CurveSelectionInfo

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

the class CurveEditorTool method mousePressed.

/**
 * This method was created in VisualAge.
 * @param event MouseEvent
 */
public void mousePressed(MouseEvent event) {
    if (!getProperlyConfigured()) {
        return;
    }
    if ((event.getModifiers() & event.BUTTON3_MASK) != 0) {
        setTool(TOOL_SELECT);
        return;
    }
    if (getTool() == TOOL_ADDCP) {
        if (getCurveRenderer().getSelection() != null && getCurveRenderer().getSelection().getCurve() instanceof ControlPointCurve && ((ControlPointCurve) getCurveRenderer().getSelection().getCurve()).isControlPointAddable()) {
            ((ControlPointCurve) (getCurveRenderer().getSelection().getCurve())).insertControlPoint(getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())), getCurveRenderer().getSelection().getControlPoint());
        }
        getVcellDrawable().repaint();
    } else if (getTool() == TOOL_LINE || getTool() == TOOL_SPLINE || getTool() == TOOL_POINT) {
        CurveSelectionInfo selectedCSI = getCurveRenderer().getSelection();
        if (selectedCSI == null || getTool() == TOOL_POINT) {
            boolean wasFromCVP = false;
            if (getCurveValueProvider() != null && getCurveValueProvider().providesInitalCurve(getTool(), getWorldCoordinateValue(event.getPoint()))) {
                // Returns null if curve shouldn't be started at this point
                selectedCSI = getCurveValueProvider().getInitalCurveSelection(getTool(), getWorldCoordinateValue(event.getPoint()));
                wasFromCVP = true;
            } else if (getTool() == TOOL_LINE) {
                selectedCSI = new CurveSelectionInfo(new PolyLine());
            } else if (getTool() == TOOL_SPLINE) {
                selectedCSI = new CurveSelectionInfo(new Spline());
            } else if (getTool() == TOOL_POINT) {
                selectedCSI = new CurveSelectionInfo(new SinglePoint());
            }
            if (selectedCSI != null) {
                if (getCurveValueProvider() != null) {
                    getCurveValueProvider().setDescription(selectedCSI.getCurve());
                }
                getCurveRenderer().addCurve(selectedCSI.getCurve());
                getCurveRenderer().renderPropertySubSelectionType(selectedCSI.getCurve(), CurveRenderer.SUBSELECTION_CONTROL_POINT);
                getCurveRenderer().renderPropertyEditable(selectedCSI.getCurve(), (!wasFromCVP ? true : false));
            }
        }
        // 
        if (selectedCSI != null && selectedCSI.getCurve() instanceof ControlPointCurve && (getCurveValueProvider() == null || !getCurveValueProvider().providesInitalCurve(getTool(), getWorldCoordinateValue(event.getPoint())) || getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateValue(event.getPoint()), selectedCSI.getCurve()))) {
            if ((!(selectedCSI.getCurve() instanceof CurveSelectionCurve)) && getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())), selectedCSI.getCurve())) {
                ((ControlPointCurve) (selectedCSI.getCurve())).appendControlPoint(getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint())));
            } else if (getCurveValueProvider().isAddControlPointOK(getTool(), getWorldCoordinateValue(event.getPoint()), selectedCSI.getCurve())) {
                try {
                    if (selectedCSI.getCurve() instanceof CurveSelectionCurve) {
                        ControlPointCurve targetCurve = (ControlPointCurve) (((CurveSelectionCurve) selectedCSI.getCurve()).getSourceCurveSelectionInfo().getCurve());
                        double dist = targetCurve.getDistanceTo(getWorldCoordinateValue(event.getPoint()));
                        int segmentIndex = targetCurve.pickSegment(getWorldCoordinateValue(event.getPoint()), dist * 1.1);
                        Coordinate[] coordArr = targetCurve.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);
                        ((ControlPointCurve) (selectedCSI.getCurve())).appendControlPoint(getWorldCoordinateCalculator().snapWorldCoordinateFace(middleCoord));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (selectedCSI != null && !selectedCSI.getCurve().isValid()) {
            int subSel = getCurveRenderer().getRenderPropertySubSelectionType(selectedCSI.getCurve());
            boolean bEdit = getCurveRenderer().getRenderPropertyEditable(selectedCSI.getCurve());
            getCurveRenderer().setSelection(null);
            getCurveRenderer().addCurve(selectedCSI.getCurve());
            getCurveRenderer().renderPropertyEditable(selectedCSI.getCurve(), bEdit);
            getCurveRenderer().renderPropertySubSelectionType(selectedCSI.getCurve(), subSel);
        }
        getCurveRenderer().setSelection(selectedCSI);
        if (getCurveValueProvider() != null && selectedCSI != null && selectedCSI.getCurve().isValid()) {
            getCurveValueProvider().curveAdded(selectedCSI.getCurve());
        }
        getVcellDrawable().repaint();
    } else if (getTool() == TOOL_SELECT) {
        CurveSelectionInfo invalidCSI = null;
        if (getCurveRenderer().getSelection() != null && !getCurveRenderer().getSelection().getCurve().isValid()) {
            invalidCSI = getCurveRenderer().getSelection();
        }
        // 
        lastSnappedWorldCoord = getWorldCoordinateCalculator().snapWorldCoordinate(getWorldCoordinateValue(event.getPoint()));
        CurveSelectionInfo csi = getCurveRenderer().pick(getWorldCoordinateValue(event.getPoint()));
        if (csi != null && getCurveRenderer().getRenderPropertySelectable(csi.getCurve())) {
            getCurveRenderer().setSelection(csi);
        } else {
            getCurveRenderer().selectNothing();
        }
        // 
        if (getCurveValueProvider() != null) {
            if (invalidCSI != null) {
                getCurveValueProvider().curveRemoved(invalidCSI.getCurve());
            } else {
                getCurveValueProvider().curveAdded(null);
            }
        }
        // 
        getVcellDrawable().repaint();
    }
// 
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) Coordinate(org.vcell.util.Coordinate) PolyLine(cbit.vcell.geometry.PolyLine) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) Spline(cbit.vcell.geometry.Spline) SinglePoint(cbit.vcell.geometry.SinglePoint)

Aggregations

CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)10 SinglePoint (cbit.vcell.geometry.SinglePoint)7 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)6 Coordinate (org.vcell.util.Coordinate)6 Curve (cbit.vcell.geometry.Curve)5 CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)5 SampledCurve (cbit.vcell.geometry.SampledCurve)5 VariableType (cbit.vcell.math.VariableType)4 CurveRenderer (cbit.vcell.geometry.CurveRenderer)2 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)2 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2 CartesianMeshChombo (cbit.vcell.solvers.CartesianMeshChombo)2 CoordinateIndex (org.vcell.util.CoordinateIndex)2 DisplayAdapterService (cbit.image.DisplayAdapterService)1 SourceDataInfo (cbit.image.SourceDataInfo)1 VCImage (cbit.image.VCImage)1 VCImageUncompressed (cbit.image.VCImageUncompressed)1 ImagePlaneManagerPanel (cbit.image.gui.ImagePlaneManagerPanel)1 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1