Search in sources :

Example 1 with ControlPointCurve

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

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

the class XmlReader method getGeometry.

/**
 * This method returns a Geometry object from a XML representation.
 * Creation date: (4/26/2001 12:12:18 PM)
 * @return cbit.vcell.geometry.Geometry
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
public Geometry getGeometry(Element param) throws XmlParseException {
    // Get the Extent object
    Extent newextent = getExtent(param.getChild(XMLTags.ExtentTag, vcNamespace));
    // Get VCimage information
    VCImage newimage = null;
    if (param.getChild(XMLTags.ImageTag, vcNamespace) != null) {
        try {
            newimage = getVCImage(param.getChild(XMLTags.ImageTag, vcNamespace), newextent);
        } catch (Throwable e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Get attributes
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    int newdimension = Integer.parseInt(param.getAttributeValue(XMLTags.DimensionAttrTag));
    // Get Version
    Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
    // Try to construct the geometry upon four different cases
    Geometry newgeometry = null;
    if (version != null && newimage != null) {
        newgeometry = new Geometry(version, newimage);
    } else if (version != null) {
        newgeometry = new Geometry(version, newdimension);
    } else if (newimage != null) {
        newgeometry = new Geometry(name, newimage);
    } else {
        newgeometry = new Geometry(name, newdimension);
    }
    // set attributes
    try {
        if (!newgeometry.getName().equalsIgnoreCase(name)) {
            newgeometry.setName(name);
        }
        // String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
        // if (annotation!=null) {
        // newgeometry.setDescription( unMangle(annotation) );
        // }
        // Add annotation
        String annotation = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
        if (annotation != null && annotation.length() > 0) {
            newgeometry.setDescription(unMangle(annotation));
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException occurred when setting the name " + name + " to a Geometry object!", e);
    }
    // Add the Extent
    try {
        newgeometry.getGeometrySpec().setExtent(newextent);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException occurred while trying to set the Extent for the Geometry " + name, e);
    }
    // Add the Origin
    newgeometry.getGeometrySpec().setOrigin(getOrigin(param.getChild(XMLTags.OriginTag, vcNamespace)));
    // Add the SubVolumes
    List<Element> children = param.getChildren(XMLTags.SubVolumeTag, vcNamespace);
    SubVolume[] newsubvolumes = new SubVolume[children.size()];
    int subvolumeCounter = 0;
    for (Element child : children) {
        newsubvolumes[subvolumeCounter] = getSubVolume(child);
        subvolumeCounter++;
    }
    try {
        newgeometry.getGeometrySpec().setSubVolumes(newsubvolumes);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
    }
    if (newgeometry.getDimension() > 0) {
        // Add SurfaceClasses
        List<Element> surfaceClassChildren = param.getChildren(XMLTags.SurfaceClassTag, vcNamespace);
        SurfaceClass[] newSurfaceClassArr = new SurfaceClass[surfaceClassChildren.size()];
        int surfClassCounter = 0;
        for (Element surfClassChild : surfaceClassChildren) {
            newSurfaceClassArr[surfClassCounter] = getSurfaceClass(surfClassChild, newgeometry);
            surfClassCounter++;
        }
        try {
            newgeometry.getGeometrySurfaceDescription().setSurfaceClasses(newSurfaceClassArr);
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace();
            throw new XmlParseException("A PropertyVetoException was generated when ading the subvolumes to the Geometry " + name, e);
        }
    }
    // read Filaments (if any)
    Iterator<Element> iterator = param.getChildren(XMLTags.FilamentTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        Element tempElement = iterator.next();
        String filname = unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag));
        Iterator<Element> curveiterator = tempElement.getChildren().iterator();
        while (curveiterator.hasNext()) {
            ControlPointCurve curve = getControlPointCurve(curveiterator.next());
            newgeometry.getGeometrySpec().getFilamentGroup().addCurve(filname, curve);
        }
    }
    // read Surface description (if any)
    Element sd = param.getChild(XMLTags.SurfaceDescriptionTag, vcNamespace);
    if (sd != null) {
        GeometrySurfaceDescription dummy = getGeometrySurfaceDescription(sd, newgeometry);
    }
    try {
        newgeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT(), false, false);
    } catch (GeometryException e) {
        e.printStackTrace(System.out);
    } catch (ImageException e) {
        e.printStackTrace(System.out);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
    }
    return newgeometry;
}
Also used : ImageException(cbit.image.ImageException) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) Extent(org.vcell.util.Extent) SurfaceClass(cbit.vcell.geometry.SurfaceClass) GeometryException(cbit.vcell.geometry.GeometryException) Element(org.jdom.Element) VCImage(cbit.image.VCImage) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) ExpressionException(cbit.vcell.parser.ExpressionException) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume)

Example 3 with ControlPointCurve

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

the class Xmlproducer method getXML.

/**
 * This method returns a XML Element from a Filament object.
 * Creation date: (5/22/2001 4:03:13 PM)
 * @return Element
 * @param param cbit.vcell.geometry.Filament
 */
private Element getXML(Filament param) {
    // --- create Element
    Element filament = new Element(XMLTags.FilamentTag);
    // Add atributes
    filament.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
    // add curves
    Curve[] array = param.getCurves();
    for (int i = 0; i < array.length; i++) {
        filament.addContent(getXML((ControlPointCurve) array[i]));
    }
    return filament;
}
Also used : Element(org.jdom.Element) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve) SampledCurve(cbit.vcell.geometry.SampledCurve) Curve(cbit.vcell.geometry.Curve) ControlPointCurve(cbit.vcell.geometry.ControlPointCurve)

Example 4 with ControlPointCurve

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

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

Aggregations

ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)11 Coordinate (org.vcell.util.Coordinate)8 SinglePoint (cbit.vcell.geometry.SinglePoint)5 SampledCurve (cbit.vcell.geometry.SampledCurve)4 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)3 Element (org.jdom.Element)3 Curve (cbit.vcell.geometry.Curve)2 CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)2 PolyLine (cbit.vcell.geometry.PolyLine)2 Spline (cbit.vcell.geometry.Spline)2 Vector (java.util.Vector)2 ImageException (cbit.image.ImageException)1 VCImage (cbit.image.VCImage)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)1 Geometry (cbit.vcell.geometry.Geometry)1 GeometryException (cbit.vcell.geometry.GeometryException)1 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)1 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)1 Line (cbit.vcell.geometry.Line)1