Search in sources :

Example 1 with Spline

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

the class XmlReader method getControlPointCurve.

/**
 * This method returns a ControlPointcurve object from a XML element.
 * Creation date: (5/22/2001 5:20:39 PM)
 * @return cbit.vcell.geometry.ControlPointCurve
 * @param param org.jdom.Element
 */
private ControlPointCurve getControlPointCurve(Element param) {
    ControlPointCurve curve = null;
    // get Attributes
    String type = param.getAttributeValue(XMLTags.TypeAttrTag);
    boolean closed = Boolean.valueOf(param.getAttributeValue(XMLTags.ClosedAttrTag)).booleanValue();
    List<Element> coordList = param.getChildren();
    // Upon de type, decide which Curve type to create
    if (type.equalsIgnoreCase(XMLTags.PolyLineTypeTag)) {
        if (coordList.size() == 2) {
            // I have a Line
            Coordinate begin = getCoordinate(coordList.get(0));
            Coordinate end = getCoordinate(coordList.get(1));
            // ****create new Line ****
            curve = new Line(begin, end);
        } else {
            // If it it is not a Line, then it is a SampledCurve
            Coordinate[] coords = new Coordinate[coordList.size()];
            for (int i = 0; i < coordList.size(); i++) {
                coords[i] = getCoordinate(coordList.get(i));
            }
            // ****create new SampledCurve ****
            curve = new SampledCurve(coords);
        }
    } else if (type.equalsIgnoreCase(XMLTags.SplineTypeTag)) {
        Coordinate[] coords = new Coordinate[coordList.size()];
        for (int i = 0; i < coordList.size(); i++) {
            coords[i] = getCoordinate(coordList.get(i));
        }
        // ****create new Spline ****
        curve = new Spline(coords);
    }
    // set Atributes
    curve.setClosed(closed);
    return curve;
}
Also used : Line(cbit.vcell.geometry.Line) SampledCurve(cbit.vcell.geometry.SampledCurve) Coordinate(org.vcell.util.Coordinate) Element(org.jdom.Element) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) Spline(cbit.vcell.geometry.Spline)

Example 2 with Spline

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

the class Xmlproducer method getXML.

/**
 * This method retruns a XML ELement from a ControlPointCurve object.
 * Creation date: (5/22/2001 4:11:37 PM)
 * @return Element
 * @param param cbit.vcell.geometry.ControlPointCurve
 */
private Element getXML(ControlPointCurve param) {
    Element curve = new Element(XMLTags.CurveTag);
    // Add attributes
    String type = null;
    if (param instanceof Spline) {
        type = XMLTags.SplineTypeTag;
    } else if (param instanceof Line || param instanceof SampledCurve) {
        type = XMLTags.PolyLineTypeTag;
    }
    curve.setAttribute(XMLTags.TypeAttrTag, type);
    curve.setAttribute(XMLTags.ClosedAttrTag, String.valueOf(param.isClosed()));
    // Add coordinates
    Vector<Coordinate> vector = param.getControlPointsVector();
    Iterator<Coordinate> iterator = vector.iterator();
    while (iterator.hasNext()) {
        curve.addContent(getXML(iterator.next()));
    }
    return curve;
}
Also used : Line(cbit.vcell.geometry.Line) SampledCurve(cbit.vcell.geometry.SampledCurve) Coordinate(org.vcell.util.Coordinate) Element(org.jdom.Element) Spline(cbit.vcell.geometry.Spline)

Example 3 with Spline

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

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

Spline (cbit.vcell.geometry.Spline)4 Coordinate (org.vcell.util.Coordinate)3 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)2 CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)2 Line (cbit.vcell.geometry.Line)2 PolyLine (cbit.vcell.geometry.PolyLine)2 SampledCurve (cbit.vcell.geometry.SampledCurve)2 SinglePoint (cbit.vcell.geometry.SinglePoint)2 Element (org.jdom.Element)2 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)1 VariableType (cbit.vcell.math.VariableType)1