Search in sources :

Example 41 with Coordinate

use of org.vcell.util.Coordinate 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 42 with Coordinate

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

the class CurveTable method decodeCurve.

/**
 * Insert the method's description here.
 * Creation date: (7/28/00 6:02:38 PM)
 * @return java.awt.Shape
 * @param pathIterator byte[]
 */
public static cbit.vcell.geometry.Curve decodeCurve(String encodedShape) throws Exception {
    cbit.vcell.geometry.Curve rCurve = null;
    try {
        org.vcell.util.CommentStringTokenizer st = new org.vcell.util.CommentStringTokenizer(encodedShape);
        String curveType = st.nextToken();
        Class classType = Class.forName(curveType);
        Object oCurve = classType.newInstance();
        String curveClosed = st.nextToken();
        if (oCurve instanceof ControlPointCurve) {
            cbit.vcell.geometry.ControlPointCurve cpc = (cbit.vcell.geometry.ControlPointCurve) oCurve;
            int cpCount = new Integer(st.nextToken()).intValue();
            for (int c = 0; c < cpCount; c += 1) {
                double x = new Double(st.nextToken()).doubleValue();
                double y = new Double(st.nextToken()).doubleValue();
                double z = new Double(st.nextToken()).doubleValue();
                cpc.appendControlPoint(new Coordinate(x, y, z));
            }
            rCurve = cpc;
        }
        if (rCurve == null) {
            throw new RuntimeException("Couldn't decode curve " + curveType);
        }
        rCurve.setClosed(curveClosed.equals("Closed"));
    } catch (Throwable e) {
        throw new Exception(e.toString());
    }
    return rCurve;
}
Also used : ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) DataAccessException(org.vcell.util.DataAccessException) Coordinate(org.vcell.util.Coordinate) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve)

Example 43 with Coordinate

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

the class ROIMultiPaintManager method sampleAnalyticIntoImage.

private void sampleAnalyticIntoImage(OverlayEditorPanelJAI.ImgSubVolHelper imgSubVolHelper) {
    try {
        Extent extent = (editedGeometryAttributes == null ? originalExtent : editedGeometryAttributes.extent);
        Origin orig = (editedGeometryAttributes == null ? originalOrigin : editedGeometryAttributes.origin);
        int numX = roiComposite[0].getWidth();
        int numY = roiComposite[0].getHeight();
        int numZ = roiComposite.length;
        int dim = (roiComposite.length > 1 ? 1 : 0) + (roiComposite[0].getHeight() > 1 ? 1 : 0) + 1;
        double cX = calcCoord(imgSubVolHelper.getMousePoint().x, numX, orig.getX(), extent.getX());
        double cY = calcCoord(imgSubVolHelper.getMousePoint().y, numY, orig.getY(), extent.getY());
        double cZ = calcCoord(imgSubVolHelper.getZCenter(), numZ, orig.getZ(), extent.getZ());
        Coordinate center = new Coordinate(cX, cY, cZ);
        AnalyticSubVolume tempSV = GeometrySubVolumePanel.createAnalyticSubVolume(overlayEditorPanelJAI, dim, center, "tempSV");
        tempSV.rebind();
        for (int k = 0; k < numZ; k++) {
            double coordZ = calcCoord(k, numZ, orig.getZ(), extent.getZ());
            for (int j = 0; j < numY; j++) {
                double coordY = calcCoord(j, numY, orig.getY(), extent.getY());
                for (int i = 0; i < numX; i++) {
                    double coordX = calcCoord(i, numX, orig.getX(), extent.getX());
                    if (tempSV.isInside(coordX, coordY, coordZ, null)) {
                        ((DataBufferByte) roiComposite[k].getRaster().getDataBuffer()).getData()[j * numX + i] = (byte) (imgSubVolHelper.getCurrentSubVolHandle().getContrastColorIndex());
                    }
                }
            }
        }
    } catch (UserCancelException uce) {
    // ignore
    } catch (Exception e) {
        DialogUtils.showErrorDialog(overlayEditorPanelJAI, e.getClass().getName() + " " + e.getMessage());
    }
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) Coordinate(org.vcell.util.Coordinate) UserCancelException(org.vcell.util.UserCancelException) DataBufferByte(java.awt.image.DataBufferByte) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException)

Example 44 with Coordinate

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

the class MeshSpecificationPanel method updateTotalSizeAndSpatialStep.

private void updateTotalSizeAndSpatialStep() {
    if (getMeshSpecification() == null) {
        return;
    }
    if (getMeshSpecification().getGeometry() == null || getMeshSpecification().getGeometry().getExtent() == null) {
        return;
    }
    ISize samplingSize = getMeshSpecification().getSamplingSize();
    if (samplingSize == null) {
        return;
    }
    try {
        int dim = getMeshSpecification().getGeometry().getDimension();
        String xtext = getXTextField().getText();
        int numX = Integer.parseInt(xtext);
        int numY = 1;
        int numZ = 1;
        String totalSizeText = "";
        long totalSizeValue = numX;
        if (dim > 1) {
            String ytext = getYTextField().getText();
            numY = Integer.parseInt(ytext);
            totalSizeText += numX + " x " + numY;
            totalSizeValue *= numY;
            if (dim > 2) {
                String ztext = getZTextField().getText();
                numZ = Integer.parseInt(ztext);
                totalSizeText += " x " + numZ;
                totalSizeValue *= numZ;
            }
        }
        totalSizeTextField.setText(totalSizeText + (totalSizeText.length() == 0 ? "" : " = ") + totalSizeValue);
        Coordinate h = computeDxDyDz(numX, numY, numZ);
        ivjDxTextField.setText(h.getX() + "");
        ivjDyTextField.setText(h.getY() + "");
        ivjDzTextField.setText(h.getZ() + "");
    } catch (NumberFormatException ex) {
        clearTotalSizeAndSpatialStep();
    }
}
Also used : Coordinate(org.vcell.util.Coordinate) ISize(org.vcell.util.ISize)

Example 45 with Coordinate

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

the class ElectricalStimulusPanel method newStimulus.

/**
 * Comment
 */
private void newStimulus() {
    try {
        SimulationContext simContext = getSimulationContext();
        if (simContext == null) {
            return;
        }
        // 
        // When the voltage and current clamp radio buttons is deselected within the same simulation context (application),
        // display a warning saying that the present clamp settings will be lost (not applicable when the 'no clamp'
        // radiobutton is deselected.
        // 
        ElectricalStimulus currElectricalStimulus = null;
        if (simContext.getElectricalStimuli() != null && simContext.getElectricalStimuli().length > 0) {
            currElectricalStimulus = simContext.getElectricalStimuli()[0];
        }
        // 
        // ignore selection if already selected
        // warn upon deselect if about to loose edits
        // 
        Clamp selectedClamp = (Clamp) clampComboBox.getSelectedItem();
        if (currElectricalStimulus instanceof VoltageClampStimulus) {
            if (selectedClamp == Clamp.Voltage_Clamp) {
                return;
            }
            String response = PopupGenerator.showWarningDialog(this, "warning: the present voltage clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
            if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
                // revert back to Voltage Clamp
                clampComboBox.setSelectedItem(Clamp.Voltage_Clamp);
                return;
            }
        }
        if (currElectricalStimulus instanceof TotalCurrentClampStimulus) {
            if (selectedClamp == Clamp.Total_Current_Clamp) {
                return;
            }
            String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
            if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
                // revert back to Current Clamp
                clampComboBox.setSelectedItem(Clamp.Total_Current_Clamp);
                return;
            }
        }
        if (currElectricalStimulus instanceof CurrentDensityClampStimulus) {
            if (selectedClamp == Clamp.Current_Density_Clamp) {
                return;
            }
            String response = PopupGenerator.showWarningDialog(this, "warning: the present current clamp settings will be lost", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CONTINUE);
            if (response == null || response.equals(UserMessage.OPTION_CANCEL)) {
                // revert back to Current Clamp
                clampComboBox.setSelectedItem(Clamp.Current_Density_Clamp);
                return;
            }
        }
        if (currElectricalStimulus == null && selectedClamp == Clamp.No_Clamp) {
            return;
        }
        StructureTopology structTopology = getSimulationContext().getModel().getStructureTopology();
        Structure[] structures = getSimulationContext().getModel().getStructures();
        ArrayList<Feature> features = new ArrayList<Feature>();
        for (Structure structure : structures) {
            if (structure instanceof Feature) {
                features.add((Feature) structure);
            }
        }
        if (features.size() < 2) {
            PopupGenerator.showErrorDialog(this, "error: electrodes must be placed in distinct volumetric structures, found " + features.size() + " volumetric structures in model");
            return;
        }
        Feature groundFeature = features.get(0);
        Feature clampedFeature = features.get(1);
        // 
        if (selectedClamp == Clamp.Total_Current_Clamp) {
            if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof TotalCurrentClampStimulus)) {
                Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
                TotalCurrentClampStimulus ccStimulus = new TotalCurrentClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
                System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
                simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
                simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
            }
        }
        // 
        if (selectedClamp == Clamp.Current_Density_Clamp) {
            if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof CurrentDensityClampStimulus)) {
                Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
                CurrentDensityClampStimulus ccStimulus = new CurrentDensityClampStimulus(probeElectrode, "ccElectrode", new Expression(0.0), simContext);
                System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
                simContext.setElectricalStimuli(new ElectricalStimulus[] { ccStimulus });
                simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
            }
        }
        // 
        if (selectedClamp == Clamp.No_Clamp) {
            if (simContext.getElectricalStimuli().length > 0) {
                simContext.setElectricalStimuli(new ElectricalStimulus[0]);
            }
        }
        // 
        if (selectedClamp == Clamp.Voltage_Clamp) {
            if (simContext.getElectricalStimuli().length == 0 || !(simContext.getElectricalStimuli()[0] instanceof VoltageClampStimulus)) {
                Electrode probeElectrode = new Electrode(clampedFeature, new Coordinate(0, 0, 0));
                VoltageClampStimulus vcStimulus = new VoltageClampStimulus(probeElectrode, "vcElectrode", new Expression(0.0), simContext);
                System.out.println(" Geo's dim = " + simContext.getGeometry().getDimension());
                simContext.setElectricalStimuli(new ElectricalStimulus[] { vcStimulus });
                simContext.setGroundElectrode(new Electrode(groundFeature, new Coordinate(0, 0, 0)));
            }
        }
    } catch (java.beans.PropertyVetoException e) {
        PopupGenerator.showErrorDialog(this, "Error setting electrical stimulus: " + e.getMessage());
    }
}
Also used : Electrode(cbit.vcell.mapping.Electrode) StructureTopology(cbit.vcell.model.Model.StructureTopology) ArrayList(java.util.ArrayList) CurrentDensityClampStimulus(cbit.vcell.mapping.CurrentDensityClampStimulus) SimulationContext(cbit.vcell.mapping.SimulationContext) TotalCurrentClampStimulus(cbit.vcell.mapping.TotalCurrentClampStimulus) Feature(cbit.vcell.model.Feature) ElectricalStimulus(cbit.vcell.mapping.ElectricalStimulus) Coordinate(org.vcell.util.Coordinate) Expression(cbit.vcell.parser.Expression) VoltageClampStimulus(cbit.vcell.mapping.VoltageClampStimulus) Structure(cbit.vcell.model.Structure)

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