Search in sources :

Example 16 with SinglePoint

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

the class SpatialSelectionVolume method getIndexSamples.

/**
 * Insert the method's description here.
 * Creation date: (2/26/2001 6:17:10 PM)
 * @return int[]
 * @param numSamples int
 */
public SSHelper getIndexSamples(double begin, double end) {
    if (getCurveSelectionInfo().getCurve() instanceof SinglePoint) {
        return new SSHelper(new Coordinate[] { getCurveSelectionInfo().getCurve().getCoordinate(0) }, new int[] { getConvertedIndexFromWC(getCurveSelectionInfo().getCurve().getCoordinate(0)) }, getVariableType(), new int[] { -1 });
    }
    // Try simple sampling
    SSHelper ssvHelper = null;
    if (begin == 0.0 && end == 1.0) {
        try {
            ssvHelper = sampleSymmetric();
        } catch (Throwable e) {
        // Do nothing, we'll try sampling below
        }
    }
    if (ssvHelper != null) {
        return ssvHelper;
    }
    // 
    // Find continuous mesh elements along the curve
    // 
    final int SAMPLE_MULT = 10;
    // Determine reasonable sample size
    double smallestMeshCellDimension = getSmallestMeshCellDimensionLength();
    double uSpatialLength = getCurveSelectionInfo().getCurve().getSpatialLength() * (Math.abs(end - begin));
    int SSV_NUM_SAMPLES = (int) (Math.ceil(uSpatialLength / smallestMeshCellDimension) * (double) SAMPLE_MULT);
    if (SSV_NUM_SAMPLES < 2) {
        SSV_NUM_SAMPLES = 2;
    }
    // 
    double delta = (end - begin) / (double) SSV_NUM_SAMPLES;
    int[] uniquePoints = new int[SSV_NUM_SAMPLES];
    int uniquePointCount = 0;
    Vector<Coordinate> wcV = new Vector<Coordinate>();
    // Vector ciV = new Vector();
    // double[] cellStepArr = new double[SAMPLE_MULT*10];//big enough
    // big enough
    double[] cellStepArr = new double[SSV_NUM_SAMPLES];
    int cellStepCounter = 0;
    int lastISample = -1;
    int currISample;
    double currentU = begin;
    for (int index = 0; index < SSV_NUM_SAMPLES; index += 1) {
        boolean isLastLoop = index == (SSV_NUM_SAMPLES - 1);
        if (isLastLoop) {
            currISample = getMeshIndexFromU(end);
            currentU = end;
        } else {
            currISample = getMeshIndexFromU(currentU);
        }
        if ((index == 0) || (lastISample != currISample)) {
            uniquePoints[uniquePointCount] = getIndex(currentU);
            double midU = midpoint(cellStepArr, cellStepCounter);
            if (index == 0) {
                midU = begin;
            }
            if (isLastLoop) {
                midU = end;
            }
            Coordinate wc = getSamplingWorldCoordinate(midU);
            if (index == 0 || isLastLoop || (uniquePointCount > 1)) {
                wcV.add(wc);
            }
            // CoordinateIndex ci = getCoordinateIndexFromWC(wc);
            // ciV.add(ci);
            uniquePointCount += 1;
            // if(ciV.size() > 1 &&!areTouching(((CoordinateIndex)ciV.elementAt(ciV.size()-1)),((CoordinateIndex)ciV.elementAt(ciV.size()-2)))){
            // //this shouldn't happen if our sampling is fine enough
            // //all sampled mesh elements should be "touching"
            // }
            cellStepCounter = 0;
        } else if (isLastLoop && (wcV.size() != uniquePointCount)) {
            wcV.add(getSamplingWorldCoordinate(end));
        }
        cellStepArr[cellStepCounter] = currentU;
        cellStepCounter += 1;
        currentU += delta;
        lastISample = currISample;
    }
    if (uniquePointCount > 0) {
        return makeSSHelper(uniquePoints, uniquePointCount, wcV, true);
    }
    // This shouldn't happen
    throw new RuntimeException(this.getClass().getName() + " couldn't generate sampling");
}
Also used : SinglePoint(cbit.vcell.geometry.SinglePoint) Coordinate(org.vcell.util.Coordinate) Vector(java.util.Vector) SinglePoint(cbit.vcell.geometry.SinglePoint)

Aggregations

SinglePoint (cbit.vcell.geometry.SinglePoint)16 ControlPointCurve (cbit.vcell.geometry.ControlPointCurve)6 CurveSelectionCurve (cbit.vcell.geometry.CurveSelectionCurve)6 SampledCurve (cbit.vcell.geometry.SampledCurve)6 VariableType (cbit.vcell.math.VariableType)6 SpatialSelection (cbit.vcell.simdata.SpatialSelection)6 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)6 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)6 Vector (java.util.Vector)6 Coordinate (org.vcell.util.Coordinate)6 Curve (cbit.vcell.geometry.Curve)5 CurveSelectionInfo (cbit.vcell.geometry.CurveSelectionInfo)5 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)4 PolyLine (cbit.vcell.geometry.PolyLine)3 Point (java.awt.Point)3 DataAccessException (org.vcell.util.DataAccessException)3 TSJobResultsNoStats (org.vcell.util.document.TSJobResultsNoStats)3 ImageException (cbit.image.ImageException)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 FileDataContainerID (cbit.vcell.export.server.FileDataContainerManager.FileDataContainerID)2