Search in sources :

Example 21 with CoordinateIndex

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

the class HybridSolverTester method calcSimLocs.

public static SimLocHelper calcSimLocs(String csSimLocs, CartesianMesh mesh) {
    // ArrayList<Integer> simLocs = new ArrayList<Integer>();
    HashMap<Integer, ArrayList<Integer>> boxToLocs = new HashMap<>();
    HashMap<Integer, Integer> indexToBoxMap = new HashMap<>();
    HashMap<Integer, Integer> boxToSizeMap = new HashMap<>();
    HashMap<Integer, String> boxToID = new HashMap<>();
    StringTokenizer st = new StringTokenizer(csSimLocs, ":");
    int boxCount = 0;
    while (st.hasMoreTokens()) {
        boxToSizeMap.put(boxCount, 0);
        boxToLocs.put(boxCount, new ArrayList<Integer>());
        String token = st.nextToken();
        boxToID.put(boxCount, token);
        if (token.contains("-")) {
            // box
            CoordinateIndex coord0, coord1;
            StringTokenizer st2 = new StringTokenizer(token, "-");
            int volIndex = Integer.parseInt(st2.nextToken());
            coord0 = mesh.getCoordinateIndexFromVolumeIndex(volIndex);
            volIndex = Integer.parseInt(st2.nextToken());
            coord1 = mesh.getCoordinateIndexFromVolumeIndex(volIndex);
            for (int z = coord0.z; (coord0.z < coord1.z ? z <= coord1.z : z >= coord1.z); z += (Integer.signum(coord1.z - coord0.z) == 0 ? -1 : Integer.signum(coord1.z - coord0.z))) {
                for (int y = coord0.y; (coord0.y < coord1.y ? y <= coord1.y : y >= coord1.y); y += (Integer.signum(coord1.y - coord0.y) == 0 ? -1 : Integer.signum(coord1.y - coord0.y))) {
                    for (int x = coord0.x; (coord0.x < coord1.x ? x <= coord1.x : x >= coord1.x); x += (Integer.signum(coord1.x - coord0.x) == 0 ? -1 : Integer.signum(coord1.x - coord0.x))) {
                        int location = mesh.getVolumeIndex(new CoordinateIndex(x, y, z));
                        // simLocs.add(location);
                        boxToLocs.get(boxCount).add(location);
                        indexToBoxMap.put(location, boxCount);
                        boxToSizeMap.put(boxCount, boxToSizeMap.get(boxCount) + 1);
                    }
                }
            }
            boxCount++;
        } else {
            // points, considered to be a box with 1 element
            int location = Integer.parseInt(token);
            // simLocs.add(location);
            boxToLocs.get(boxCount).add(location);
            indexToBoxMap.put(location, boxCount);
            boxCount++;
        }
    }
    return new SimLocHelper(boxToLocs, indexToBoxMap, boxToID);
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigString(org.vcell.util.BigString) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 22 with CoordinateIndex

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

the class MathTestingUtilities method resample1DSpatial.

/**
 * Insert the method's description here.
 * Creation date: (10/27/2003 5:07:42 PM)
 * @return double[]
 * @param data double[]
 * @param sourceMesh cbit.vcell.solvers.CartesianMesh
 * @param targetMesh cbit.vcell.solvers.CartesianMesh
 */
public static double[] resample1DSpatial(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
    if (sourceData.length != sourceMesh.getNumVolumeElements()) {
        throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
    }
    // for volume samples:
    // 
    // loop through volumeIndexes from refMesh
    // Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
    // Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
    // ....interpolate in z
    // start with integer portion of fractionIndex
    double[] resampledData = new double[refMesh.getSizeX()];
    for (int i = 0; i < resampledData.length; i++) {
        Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
        Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
        int ceil_x;
        int floor_x;
        if (fractionalIndex.getX() < 0) {
            floor_x = 0;
            ceil_x = 1;
        } else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
            floor_x = sourceMesh.getSizeX() - 2;
            ceil_x = sourceMesh.getSizeX() - 1;
        } else {
            ceil_x = (int) Math.ceil(fractionalIndex.getX());
            floor_x = (int) Math.floor(fractionalIndex.getX());
        }
        double fract_x = fractionalIndex.getX() - floor_x;
        // ***** SHOULD Y,Z BE 0 OR 1 ???? *****
        CoordinateIndex coord_1 = new CoordinateIndex(floor_x, 0, 0);
        CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, 0, 0);
        int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
        int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
        boolean bBoth1_2 = false;
        boolean bNoneOf1_2 = false;
        boolean bOne = false;
        boolean bTwo = false;
        boolean bOneOf1_2 = false;
        // use it to compute a, b, 	 ** Interpolation in X **
        if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) == refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
            bOneOf1_2 = true;
            bOne = true;
            volIndx2 = volIndx1;
        } else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) == refMesh.getSubVolumeFromVolumeIndex(i)) {
            bOneOf1_2 = true;
            bTwo = true;
            volIndx1 = volIndx2;
        } else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
            // throw new RuntimeException("Either subvolume in sourceMesh not equal to refMesh subVol cannot be handled at this time!");
            bNoneOf1_2 = true;
        } else {
            bBoth1_2 = true;
        }
        // Interpolate in X - final resampledSourceData value
        if (bBoth1_2) {
            resampledData[i] = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
        }
        if (bOneOf1_2) {
            if (bOne) {
                resampledData[i] = sourceData[volIndx1];
            } else if (bTwo) {
                resampledData[i] = sourceData[volIndx2];
            }
        }
        // 
        if (bNoneOf1_2) {
            // resampledData[i] = BLAH_BLAH;
            throw new RuntimeException("Cannot handle the case where both points are not in ref subvolume");
        }
    }
    return resampledData;
}
Also used : Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 23 with CoordinateIndex

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

the class MathTestingUtilities method resample2DSpatialSimple.

/**
 * Insert the method's description here.
 * Creation date: (10/27/2003 5:07:42 PM)
 * @return double[]
 * @param data double[]
 * @param sourceMesh cbit.vcell.solvers.CartesianMesh
 * @param targetMesh cbit.vcell.solvers.CartesianMesh
 */
public static double[] resample2DSpatialSimple(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
    if (sourceData.length != sourceMesh.getNumVolumeElements()) {
        throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
    }
    // for volume samples:
    // 
    // loop through volumeIndexes from refMesh
    // Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
    // Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
    // ....interpolate in y
    // start with integer portion of fractionIndex
    double[] resampledData = new double[refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ()];
    for (int i = 0; i < resampledData.length; i++) {
        Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
        Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
        int ceil_x;
        int floor_x;
        int ceil_y;
        int floor_y;
        if (fractionalIndex.getX() < 0) {
            floor_x = 0;
            ceil_x = 1;
        } else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
            floor_x = sourceMesh.getSizeX() - 2;
            ceil_x = sourceMesh.getSizeX() - 1;
        } else {
            ceil_x = (int) Math.ceil(fractionalIndex.getX());
            floor_x = (int) Math.floor(fractionalIndex.getX());
        }
        if (fractionalIndex.getY() < 0) {
            floor_y = 0;
            ceil_y = 1;
        } else if (fractionalIndex.getY() > sourceMesh.getSizeY() - 1) {
            floor_y = sourceMesh.getSizeY() - 2;
            ceil_y = sourceMesh.getSizeY() - 1;
        } else {
            ceil_y = (int) Math.ceil(fractionalIndex.getY());
            floor_y = (int) Math.floor(fractionalIndex.getY());
        }
        double fract_x = fractionalIndex.getX() - floor_x;
        double fract_y = fractionalIndex.getY() - floor_y;
        // ***** SHOULD THIS BE 0 OR 1 ???? *****
        CoordinateIndex coord_1 = new CoordinateIndex(floor_x, floor_y, 0);
        CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, floor_y, 0);
        CoordinateIndex coord_3 = new CoordinateIndex(floor_x, ceil_y, 0);
        CoordinateIndex coord_4 = new CoordinateIndex(ceil_x, ceil_y, 0);
        int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
        int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
        int volIndx3 = sourceMesh.getVolumeIndex(coord_3);
        int volIndx4 = sourceMesh.getVolumeIndex(coord_4);
        // Interpolate in X (first order)
        double val_a = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
        double val_b = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
        // Interpolate in Y - final resampledSourceData value
        resampledData[i] = val_a + fract_y * (val_b - val_a);
    }
    return resampledData;
}
Also used : Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 24 with CoordinateIndex

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

the class MathTestingUtilities method resample2DSpatial.

/**
 * Insert the method's description here.
 * Creation date: (10/27/2003 5:07:42 PM)
 * @return double[]
 * @param data double[]
 * @param sourceMesh cbit.vcell.solvers.CartesianMesh
 * @param targetMesh cbit.vcell.solvers.CartesianMesh
 */
public static double[] resample2DSpatial(double[] sourceData, CartesianMesh sourceMesh, CartesianMesh refMesh) {
    if (sourceData.length != sourceMesh.getNumVolumeElements()) {
        throw new RuntimeException("must be volume data, data length doesn't match number of volume elements");
    }
    // for volume samples:
    // 
    // loop through volumeIndexes from refMesh
    // Coordinate refCoordinate = refMesh.getCoordinate(volumeIndex);
    // Coordinate fractionalIndex = sourceMesh.getFractionCoordinateIndex(Coordinate refCoordinate);
    // ....interpolate in y
    // start with integer portion of fractionIndex
    double[] resampledData = new double[refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ()];
    for (int i = 0; i < resampledData.length; i++) {
        Coordinate refCoordinate = refMesh.getCoordinateFromVolumeIndex(i);
        Coordinate fractionalIndex = sourceMesh.getFractionalCoordinateIndex(refCoordinate);
        int ceil_x;
        int floor_x;
        int ceil_y;
        int floor_y;
        if (fractionalIndex.getX() < 0) {
            floor_x = 0;
            ceil_x = 1;
        } else if (fractionalIndex.getX() > sourceMesh.getSizeX() - 1) {
            floor_x = sourceMesh.getSizeX() - 2;
            ceil_x = sourceMesh.getSizeX() - 1;
        } else {
            ceil_x = (int) Math.ceil(fractionalIndex.getX());
            floor_x = (int) Math.floor(fractionalIndex.getX());
        }
        if (fractionalIndex.getY() < 0) {
            floor_y = 0;
            ceil_y = 1;
        } else if (fractionalIndex.getY() > sourceMesh.getSizeY() - 1) {
            floor_y = sourceMesh.getSizeY() - 2;
            ceil_y = sourceMesh.getSizeY() - 1;
        } else {
            ceil_y = (int) Math.ceil(fractionalIndex.getY());
            floor_y = (int) Math.floor(fractionalIndex.getY());
        }
        double fract_x = fractionalIndex.getX() - floor_x;
        double fract_y = fractionalIndex.getY() - floor_y;
        // ***** SHOULD THIS BE 0 OR 1 ???? *****
        CoordinateIndex coord_1 = new CoordinateIndex(floor_x, floor_y, 0);
        CoordinateIndex coord_2 = new CoordinateIndex(ceil_x, floor_y, 0);
        CoordinateIndex coord_3 = new CoordinateIndex(floor_x, ceil_y, 0);
        CoordinateIndex coord_4 = new CoordinateIndex(ceil_x, ceil_y, 0);
        int volIndx1 = sourceMesh.getVolumeIndex(coord_1);
        int volIndx2 = sourceMesh.getVolumeIndex(coord_2);
        int volIndx3 = sourceMesh.getVolumeIndex(coord_3);
        int volIndx4 = sourceMesh.getVolumeIndex(coord_4);
        boolean bBoth1_2 = false;
        boolean bNoneOf1_2 = false;
        boolean bOne = false;
        boolean bTwo = false;
        boolean bOneOf1_2 = false;
        boolean bBoth3_4 = false;
        boolean bNoneOf3_4 = false;
        boolean bThree = false;
        boolean bFour = false;
        boolean bOneOf3_4 = false;
        // use it to compute a, b, 	 ** Interpolation in X **
        if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) == refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
            bOneOf1_2 = true;
            bOne = true;
            volIndx2 = volIndx1;
        } else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) == refMesh.getSubVolumeFromVolumeIndex(i)) {
            bOneOf1_2 = true;
            bTwo = true;
            volIndx1 = volIndx2;
        } else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx1) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx2) != refMesh.getSubVolumeFromVolumeIndex(i)) {
            // throw new RuntimeException("Either subvolume in sourceMesh not equal to refMesh subVol cannot be handled at this time!");
            bNoneOf1_2 = true;
        } else {
            bBoth1_2 = true;
        }
        if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx3) == refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx4) != refMesh.getSubVolumeFromVolumeIndex(i)) {
            bOneOf3_4 = true;
            bThree = true;
            volIndx4 = volIndx3;
        } else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx3) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx4) == refMesh.getSubVolumeFromVolumeIndex(i)) {
            bOneOf3_4 = true;
            bFour = true;
            volIndx3 = volIndx4;
        } else if (sourceMesh.getSubVolumeFromVolumeIndex(volIndx3) != refMesh.getSubVolumeFromVolumeIndex(i) && sourceMesh.getSubVolumeFromVolumeIndex(volIndx4) != refMesh.getSubVolumeFromVolumeIndex(i)) {
            // throw new RuntimeException("Either subvolume in sourceMesh not equal to refMesh subVol cannot be handled at this time!");
            bNoneOf3_4 = true;
        } else {
            bBoth3_4 = true;
        }
        // First order interpolation if 4, 3, 2 points are within the ref subVolume.
        if ((bBoth1_2 && bBoth3_4) || (bBoth1_2 && bOneOf3_4) || (bOneOf1_2 && bBoth3_4) || (bOneOf1_2 && bOneOf3_4)) {
            // Interpolate in X (first order)
            double val_a = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
            double val_b = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
            // Interpolate in Y - final resampledSourceData value
            resampledData[i] = val_a + fract_y * (val_b - val_a);
        }
        // 0th order interpolation if only one point is in ref subVol.
        if ((bBoth1_2 && bNoneOf3_4)) {
            resampledData[i] = sourceData[volIndx1] + fract_x * (sourceData[volIndx2] - sourceData[volIndx1]);
        }
        if ((bNoneOf1_2 && bBoth3_4)) {
            resampledData[i] = sourceData[volIndx3] + fract_x * (sourceData[volIndx4] - sourceData[volIndx3]);
        }
        if ((bOneOf1_2 && bNoneOf3_4)) {
            if (bOne) {
                resampledData[i] = sourceData[volIndx1];
            } else if (bTwo) {
                resampledData[i] = sourceData[volIndx2];
            }
        }
        if ((bNoneOf1_2 && bOneOf3_4)) {
            if (bThree) {
                resampledData[i] = sourceData[volIndx3];
            } else if (bFour) {
                resampledData[i] = sourceData[volIndx4];
            }
        }
        // 
        if (bNoneOf1_2 && bNoneOf3_4) {
            // resampledData[i] = BLAH_BLAH;
            throw new RuntimeException("Cannot handle the case where all 4 points are not in ref subvolume1");
        }
    }
    return resampledData;
}
Also used : Coordinate(org.vcell.util.Coordinate) CoordinateIndex(org.vcell.util.CoordinateIndex)

Example 25 with CoordinateIndex

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

the class ImageContainer method getLineScan.

/**
 * This method was created in VisualAge.
 * @return cbit.plot.PlotData
 * @param displayBeginPoint java.awt.Point
 * @param displayEndPoint java.awt.Point
 */
public cbit.plot.PlotData getLineScan(Point displayBeginPoint, Point displayEndPoint) throws Exception {
    // 
    // go from screen space to image space
    // 
    CoordinateIndex begin = getCoordinateIndexFromDisplay(displayBeginPoint.x, displayBeginPoint.y);
    CoordinateIndex end = getCoordinateIndexFromDisplay(displayEndPoint.x, displayEndPoint.y);
    // 
    // get length of span
    // 
    double lengthScan = Math.sqrt((begin.x - end.x) * (begin.x - end.x) + (begin.y - end.y) * (begin.y - end.y) + (begin.z - end.z) * (begin.z - end.z));
    if (lengthScan <= 0) {
        return null;
    }
    int sizeScan = Math.min(200, 4 * ((int) lengthScan));
    double[] lineScan = new double[sizeScan];
    double[] line = new double[sizeScan];
    for (int i = 0; i < sizeScan; i++) {
        // operate on normalized length (parametric line)
        line[i] = ((double) i) / (sizeScan - 1);
        double coordX = begin.x + line[i] * (end.x - begin.x);
        double coordY = begin.y + line[i] * (end.y - begin.y);
        double coordZ = begin.z + line[i] * (end.z - begin.z);
        int pointX = (int) (coordX + 0.5);
        int pointY = (int) (coordY + 0.5);
        int pointZ = (int) (coordZ + 0.5);
        lineScan[i] = getValue(pointX, pointY, pointZ);
        // restore scale to
        line[i] *= lengthScan;
    }
    try {
        return new cbit.plot.PlotData(line, lineScan);
    } catch (Exception e) {
        return null;
    }
}
Also used : CoordinateIndex(org.vcell.util.CoordinateIndex) Point(java.awt.Point)

Aggregations

CoordinateIndex (org.vcell.util.CoordinateIndex)30 Coordinate (org.vcell.util.Coordinate)15 Point (java.awt.Point)7 SinglePoint (cbit.vcell.geometry.SinglePoint)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 Hashtable (java.util.Hashtable)3 Vector (java.util.Vector)3 ISize (org.vcell.util.ISize)3 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)2 RegionImage (cbit.vcell.geometry.RegionImage)2 SampledCurve (cbit.vcell.geometry.SampledCurve)2 DataBufferByte (java.awt.image.DataBufferByte)2 StringTokenizer (java.util.StringTokenizer)2 DisplayAdapterService (cbit.image.DisplayAdapterService)1 SourceDataInfo (cbit.image.SourceDataInfo)1 VCImage (cbit.image.VCImage)1 VCImageUncompressed (cbit.image.VCImageUncompressed)1 ImagePlaneManagerPanel (cbit.image.gui.ImagePlaneManagerPanel)1 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1