Search in sources :

Example 1 with PolyLine

use of cbit.vcell.geometry.PolyLine 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 2 with PolyLine

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

the class PDEDataContextPanel method setDescription.

public void setDescription(Curve curve) {
    VariableType variableType = getPdeDataContext().getDataIdentifier().getVariableType();
    boolean isVolume = variableType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME) || variableType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_POSTPROCESSING);
    curve.setDescription((isVolume ? CurveValueProvider.DESCRIPTION_VOLUME : CurveValueProvider.DESCRIPTION_MEMBRANE) + (curve instanceof SinglePoint ? "p" : (curve instanceof PolyLine ? "l" : (curve instanceof Spline ? "s" : (curve instanceof CurveSelectionCurve ? "l" : "?")))) + uniquCurveID++);
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) VariableType(cbit.vcell.math.VariableType) PolyLine(cbit.vcell.geometry.PolyLine) Spline(cbit.vcell.geometry.Spline)

Example 3 with PolyLine

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

PolyLine (cbit.vcell.geometry.PolyLine)3 SinglePoint (cbit.vcell.geometry.SinglePoint)3 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)2 CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)2 Spline (cbit.vcell.geometry.Spline)2 Coordinate (org.vcell.util.Coordinate)2 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)1 SampledCurve (cbit.vcell.geometry.SampledCurve)1 VariableType (cbit.vcell.math.VariableType)1 Vector (java.util.Vector)1