Search in sources :

Example 11 with Coordinate

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

the class ImagePlaneManager method snapWorldCoordinateFace.

/**
 * Insert the method's description here.
 * Creation date: (7/13/2004 4:27:15 PM)
 */
public Coordinate snapWorldCoordinateFace(Coordinate targetC) {
    if (getSourceDataInfo().isCellCentered()) {
        return targetC;
    }
    org.vcell.util.CoordinateIndex centerCI = getSourceDataInfo().getDataIndexFromWorldCoordinate(targetC);
    Coordinate centerCoord = getSourceDataInfo().getWorldCoordinateFromIndex(centerCI);
    double diffX = centerCoord.getX() - targetC.getX();
    double diffY = centerCoord.getY() - targetC.getY();
    double diffZ = centerCoord.getZ() - targetC.getZ();
    if (Math.abs(diffX) >= Math.abs(diffY) && Math.abs(diffX) >= Math.abs(diffZ)) {
        diffY = 0;
        diffZ = 0;
    } else if (Math.abs(diffY) >= Math.abs(diffX) && Math.abs(diffY) >= Math.abs(diffZ)) {
        diffX = 0;
        diffZ = 0;
    } else {
        diffX = 0;
        diffY = 0;
    }
    CoordinateIndex offsetCI = new CoordinateIndex(centerCI.x - (new java.math.BigDecimal(diffX).signum()), centerCI.y - (new java.math.BigDecimal(diffY).signum()), centerCI.z - (new java.math.BigDecimal(diffZ).signum()));
    Coordinate offsetCoord = getSourceDataInfo().getWorldCoordinateFromIndex(offsetCI);
    Coordinate faceCoord = new Coordinate((centerCoord.getX() + offsetCoord.getX()) / 2.0, (centerCoord.getY() + offsetCoord.getY()) / 2.0, (centerCoord.getZ() + offsetCoord.getZ()) / 2.0);
    return faceCoord;
}
Also used : CoordinateIndex(org.vcell.util.CoordinateIndex) Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 12 with Coordinate

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

the class RegionImage method sortSurfaceCollection.

public static void sortSurfaceCollection(SurfaceCollection surfCollection) {
    // Sort nodes
    Object[] nodeObjArr = new Object[surfCollection.getNodes().length];
    for (int i = 0; i < nodeObjArr.length; i++) {
        Object[] temp = new Object[2];
        temp[0] = new Integer(i);
        temp[1] = surfCollection.getNodes()[i];
        nodeObjArr[i] = temp;
    }
    Arrays.sort(nodeObjArr, new Comparator<Object>() {

        public int compare(Object obj1, Object obj2) {
            cbit.vcell.geometry.surface.Node o1 = (cbit.vcell.geometry.surface.Node) ((Object[]) obj1)[1];
            cbit.vcell.geometry.surface.Node o2 = (cbit.vcell.geometry.surface.Node) ((Object[]) obj2)[1];
            double xdiff = o1.getX() - o2.getX();
            double xmin = Math.min(Math.abs(o1.getX()), Math.abs(o2.getX()));
            double xlimit = (1e-12 * (xmin >= 1.0 ? (Math.pow(10, (int) Math.log10(xmin) + 1)) : 1));
            double ydiff = o1.getY() - o2.getY();
            double ymin = Math.min(Math.abs(o1.getY()), Math.abs(o2.getY()));
            double ylimit = (1e-12 * (ymin >= 1.0 ? (Math.pow(10, (int) Math.log10(ymin) + 1)) : 1));
            double zdiff = o1.getZ() - o2.getZ();
            double zmin = Math.min(Math.abs(o1.getZ()), Math.abs(o2.getZ()));
            double zlimit = (1e-12 * (zmin >= 1.0 ? (Math.pow(10, (int) Math.log10(zmin) + 1)) : 1));
            if (Math.abs(zdiff) < zlimit) {
                if (Math.abs(ydiff) < ylimit) {
                    return (int) Math.signum((Math.abs(xdiff) < xlimit ? 0 : xdiff));
                }
                return (int) Math.signum((Math.abs(ydiff) < ylimit ? 0 : ydiff));
            }
            return (int) Math.signum((Math.abs(zdiff) < zlimit ? 0 : zdiff));
        }
    });
    int[] remap = new int[nodeObjArr.length];
    Arrays.fill(remap, -1);
    cbit.vcell.geometry.surface.Node[] sortedNodes = new cbit.vcell.geometry.surface.Node[nodeObjArr.length];
    for (int i = 0; i < nodeObjArr.length; i++) {
        sortedNodes[i] = (cbit.vcell.geometry.surface.Node) ((Object[]) nodeObjArr[i])[1];
        if (remap[sortedNodes[i].getGlobalIndex()] == -1) {
            remap[sortedNodes[i].getGlobalIndex()] = i;
        } else {
            throw new RuntimeException("SORT error: duplicate nodes");
        }
    }
    // surfCollection.setNodes(sortedNodes);
    System.arraycopy(sortedNodes, 0, surfCollection.getNodes(), 0, sortedNodes.length);
    HashSet<cbit.vcell.geometry.surface.Node> remapHashSet = new HashSet<cbit.vcell.geometry.surface.Node>();
    for (int i = 0; i < surfCollection.getSurfaceCount(); i++) {
        Surface surf = surfCollection.getSurfaces(i);
        Polygon[] sortedPolygonArr = new Polygon[surf.getPolygonCount()];
        for (int j = 0; j < surf.getPolygonCount(); j++) {
            Polygon poly = surf.getPolygons(j);
            for (int k = 0; k < poly.getNodes().length; k++) {
                cbit.vcell.geometry.surface.Node node = poly.getNodes(k);
                if (!remapHashSet.contains(node)) {
                    node.setGlobalIndex(remap[node.getGlobalIndex()]);
                    remapHashSet.add(node);
                }
            }
            sortedPolygonArr[j] = poly;
        }
        Arrays.sort(sortedPolygonArr, new Comparator<Polygon>() {

            public int compare(Polygon obj1, Polygon obj2) {
                Coordinate o1 = ((Quadrilateral) obj1).calculateCentroid();
                Coordinate o2 = ((Quadrilateral) obj2).calculateCentroid();
                double xdiff = o1.getX() - o2.getX();
                double xmin = Math.min(Math.abs(o1.getX()), Math.abs(o2.getX()));
                double xlimit = (1e-12 * (xmin >= 1.0 ? (Math.pow(10, (int) Math.log10(xmin) + 1)) : 1));
                double ydiff = o1.getY() - o2.getY();
                double ymin = Math.min(Math.abs(o1.getY()), Math.abs(o2.getY()));
                double ylimit = (1e-12 * (ymin >= 1.0 ? (Math.pow(10, (int) Math.log10(ymin) + 1)) : 1));
                double zdiff = o1.getZ() - o2.getZ();
                double zmin = Math.min(Math.abs(o1.getZ()), Math.abs(o2.getZ()));
                double zlimit = (1e-12 * (zmin >= 1.0 ? (Math.pow(10, (int) Math.log10(zmin) + 1)) : 1));
                if (Math.abs(zdiff) < zlimit) {
                    if (Math.abs(ydiff) < ylimit) {
                        return (int) Math.signum((Math.abs(xdiff) < xlimit ? 0 : xdiff));
                    }
                    return (int) Math.signum((Math.abs(ydiff) < ylimit ? 0 : ydiff));
                }
                return (int) Math.signum((Math.abs(zdiff) < zlimit ? 0 : zdiff));
            }
        });
        OrigSurface sortedSurface = new OrigSurface(surf.getInteriorRegionIndex(), surf.getExteriorRegionIndex());
        for (int k = 0; k < sortedPolygonArr.length; k++) {
            int minGlobalIndex = sortedPolygonArr[k].getNodes(0).getGlobalIndex();
            // System.out.print("Surf "+i+" poly "+k+" nodeGI - ");
            for (int j = 0; j < sortedPolygonArr[k].getNodeCount(); j++) {
                if (sortedPolygonArr[k].getNodes(j).getGlobalIndex() < minGlobalIndex) {
                    minGlobalIndex = sortedPolygonArr[k].getNodes(j).getGlobalIndex();
                }
            // System.out.print(sortedPolygonArr[k].getNodes(j).getGlobalIndex()+" ");
            }
            while (sortedPolygonArr[k].getNodes(0).getGlobalIndex() != minGlobalIndex) {
                cbit.vcell.geometry.surface.Node lastNode = sortedPolygonArr[k].getNodes(sortedPolygonArr[k].getNodeCount() - 1);
                System.arraycopy(sortedPolygonArr[k].getNodes(), 0, sortedPolygonArr[k].getNodes(), 1, sortedPolygonArr[k].getNodeCount() - 1);
                sortedPolygonArr[k].getNodes()[0] = lastNode;
            }
            // System.out.println();
            sortedSurface.addPolygon(sortedPolygonArr[k]);
        }
        surfCollection.setSurfaces(i, sortedSurface);
    }
}
Also used : Node(cbit.util.graph.Node) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Surface(cbit.vcell.geometry.surface.Surface) Coordinate(org.vcell.util.Coordinate) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Polygon(cbit.vcell.geometry.surface.Polygon) HashSet(java.util.HashSet)

Example 13 with Coordinate

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

the class SampledCurve method isSampledCurveInside.

/**
 * Insert the method's description here.
 * Creation date: (10/9/00 7:00:19 PM)
 */
protected boolean isSampledCurveInside(org.vcell.util.Origin origin, org.vcell.util.Extent extent, Coordinate delta) {
    // 
    // This util. checks sample of this curve that are straight line segments and that if their endpoints
    // are inside the the whole thing is inside.
    // 
    int controlPointCount = getControlPointCount();
    java.util.Vector controlPointsV = getControlPointsVector();
    for (int c = 0; c < controlPointCount; c += 1) {
        Coordinate curveCoord = (Coordinate) controlPointsV.elementAt(c);
        if (!Coordinate.isCoordinateInBounds(curveCoord, origin, extent, delta)) {
            return false;
        }
    }
    return true;
}
Also used : Coordinate(org.vcell.util.Coordinate)

Example 14 with Coordinate

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

the class SampledCurve method pickSegment.

/**
 * Insert the method's description here.
 * Creation date: (10/10/00 12:54:48 PM)
 */
public int pickSegment(Coordinate pickCoord, double minPickDistance) {
    int segmentCount = getSegmentCount();
    int controlPointCount = getControlPointCount();
    double shortestDistance = Double.MAX_VALUE;
    int closestSegment = Curve.NONE_SELECTED;
    Coordinate p0 = null;
    Coordinate p1 = null;
    for (int i = 0; i < segmentCount; i += 1) {
        p0 = getControlPoint(i);
        p1 = getControlPoint((i + 1) % controlPointCount);
        double distance = getDistanceToLine(p0, p1, pickCoord);
        if (distance <= minPickDistance && distance < shortestDistance) {
            shortestDistance = distance;
            closestSegment = i;
        }
    }
    return closestSegment;
}
Also used : Coordinate(org.vcell.util.Coordinate)

Example 15 with Coordinate

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

the class SampledCurve method pickUSampledCurve.

/**
 * Insert the method's description here.
 * Creation date: (10/10/00 4:23:11 PM)
 */
protected double pickUSampledCurve(Coordinate pickCoord, double minPickDistance) {
    int segmentCount = getSegmentCount();
    int controlPointCount = getControlPointCount();
    double shortestDistance = Double.MAX_VALUE;
    int closestSegment = Curve.NONE_SELECTED;
    double closestSegmentU = Curve.NONE_SELECTED;
    Coordinate p0 = null;
    Coordinate p1 = null;
    for (int i = 0; i < segmentCount; i += 1) {
        p0 = getControlPoint(i);
        p1 = getControlPoint((i + 1) % controlPointCount);
        double u = calculateUOfV1AlongV2(p0, pickCoord, p1);
        if (u >= 0.0 && u <= 1.0) {
            double uX = p0.getX() + ((p1.getX() - p0.getX()) * u);
            double uY = p0.getY() + ((p1.getY() - p0.getY()) * u);
            double uZ = p0.getZ() + ((p1.getZ() - p0.getZ()) * u);
            double distance = pickCoord.distanceTo(uX, uY, uZ);
            if (distance <= minPickDistance && distance < shortestDistance) {
                shortestDistance = distance;
                closestSegment = i;
                closestSegmentU = u;
            }
        }
    }
    if (closestSegment != Curve.NONE_SELECTED) {
        // Calculate Non-LengthNormalized U
        double finalU = (closestSegment + closestSegmentU) / getSegmentCount();
        return finalU;
    } else {
        return Curve.NONE_SELECTED;
    }
}
Also used : Coordinate(org.vcell.util.Coordinate)

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