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");
}
Aggregations