Search in sources :

Example 1 with CurveSelectionCurve

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

Example 2 with CurveSelectionCurve

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

the class PDEDataContextPanel method getInitalCurveSelection.

/**
 * Insert the method's description here.
 * Creation date: (7/4/2003 6:10:48 PM)
 */
public CurveSelectionInfo getInitalCurveSelection(int tool, Coordinate wc) {
    // 
    CurveSelectionInfo newCurveSelection = null;
    VariableType variableType = getPdeDataContext().getDataIdentifier().getVariableType();
    if (variableType.equals(VariableType.MEMBRANE) || variableType.equals(VariableType.MEMBRANE_REGION)) {
        if (getPdeDataContext().getCartesianMesh().isChomboMesh() && tool == CurveEditorTool.TOOL_POINT) {
            newCurveSelection = findChomboSinglePointSelectionInfoForPoint(wc);
        } else {
            CurveSelectionInfo[] closeCSI = getImagePlaneManagerPanel().getCurveRenderer().getCloseCurveSelectionInfos(wc);
            if (closeCSI != null) {
                for (int i = 0; i < closeCSI.length; i += 1) {
                    if (membranesAndIndexes != null && membranesAndIndexes.containsKey(closeCSI[i].getCurve())) {
                        if (tool == CurveEditorTool.TOOL_LINE) {
                            newCurveSelection = new CurveSelectionInfo(new CurveSelectionCurve((SampledCurve) (closeCSI[i].getCurve())));
                        } else if (tool == CurveEditorTool.TOOL_POINT) {
                            newCurveSelection = new CurveSelectionInfo(new CurveSelectionCurve((SampledCurve) (closeCSI[i].getCurve())));
                            double dist = closeCSI[i].getCurve().getDistanceTo(wc);
                            int segmentIndex = closeCSI[i].getCurve().pickSegment(wc, dist * 1.1);
                            Coordinate[] coordArr = closeCSI[i].getCurve().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);
                            newCurveSelection = new CurveSelectionInfo(new SinglePoint(middleCoord));
                        }
                        break;
                    }
                }
            }
        }
    }
    if (newCurveSelection != null) {
        if (membraneSamplerCurves == null) {
            membraneSamplerCurves = new java.util.Vector<Curve>();
        }
        membraneSamplerCurves.add(newCurveSelection.getCurve());
    }
    return newCurveSelection;
}
Also used : CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) SampledCurve(cbit.vcell.geometry.SampledCurve) SinglePoint(cbit.vcell.geometry.SinglePoint) VariableType(cbit.vcell.math.VariableType) Coordinate(org.vcell.util.Coordinate) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) Curve(cbit.vcell.geometry.Curve) SampledCurve(cbit.vcell.geometry.SampledCurve) CurveSelectionCurve(cbit.vcell.geometry.CurveSelectionCurve) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 3 with CurveSelectionCurve

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

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

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

CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)5 SinglePoint (cbit.vcell.geometry.SinglePoint)5 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)4 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)4 Curve (cbit.vcell.geometry.Curve)3 SampledCurve (cbit.vcell.geometry.SampledCurve)3 VariableType (cbit.vcell.math.VariableType)3 PolyLine (cbit.vcell.geometry.PolyLine)2 Spline (cbit.vcell.geometry.Spline)2 Coordinate (org.vcell.util.Coordinate)2 CurveRenderer (cbit.vcell.geometry.CurveRenderer)1 SpatialSelection (cbit.vcell.simdata.SpatialSelection)1 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)1 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)1 CartesianMesh (cbit.vcell.solvers.CartesianMesh)1 Vector (java.util.Vector)1