Search in sources :

Example 1 with GeneratorException

use of org.eclipse.scanning.api.points.GeneratorException in project gda-core by openGDA.

the class PointGeneratorPathInfoCalculator method calculatePathInfo.

@Override
public PathInfo calculatePathInfo(PathInfoRequest request) throws PathInfoCalculationException {
    IScanPointGeneratorModel scanPathModel = request.getScanPathModel();
    try {
        // Invokes ScanPointGenerator to create the points
        IPointGenerator<CompoundModel> pointGenerator = getPointGeneratorService().createGenerator(scanPathModel, request.getScanRegion());
        // Initialise with sensible starting values
        int pointCount = 0;
        double smallestXStep = Double.MAX_VALUE;
        double smallestYStep = Double.MAX_VALUE;
        double smallestAbsStep = Double.MAX_VALUE;
        List<Double> xCoordinates = new ArrayList<>();
        List<Double> yCoordinates = new ArrayList<>();
        double lastX = Double.NaN;
        double lastY = Double.NaN;
        String xAxisName = getXAxisName(scanPathModel);
        String yAxisName = getYAxisName(scanPathModel);
        // - The smallest distance between two consecutive positions in 2D space
        for (IPosition point : pointGenerator) {
            pointCount++;
            if (pointCount > 1) {
                // Updates the smallest distance tracking variables if the distance
                // between this point and the last is smaller than the smallest
                // distance we've seen so far. Do this for x, y and 2D space.
                double thisXStep = Math.abs(point.getValue(xAxisName) - lastX);
                double thisYStep = Math.abs(point.getValue(yAxisName) - lastY);
                double thisAbsStep = Math.sqrt(Math.pow(thisXStep, 2) + Math.pow(thisYStep, 2));
                if (thisXStep > 0) {
                    smallestXStep = Math.min(smallestXStep, thisXStep);
                }
                if (thisYStep > 0) {
                    smallestYStep = Math.min(smallestYStep, thisYStep);
                }
                smallestAbsStep = Math.min(smallestAbsStep, thisAbsStep);
            }
            // Ensures no more than MAX_POINTS_IN_ROI points are inserted into
            // the PathInfo. Still need to iterate through the rest of the points
            // to accurately calculate step sizes and number of points.
            lastX = point.getValue(xAxisName);
            lastY = point.getValue(yAxisName);
            if (xCoordinates.size() < request.getMaxPoints()) {
                xCoordinates.add(Double.valueOf(lastX));
                yCoordinates.add(Double.valueOf(lastY));
            }
        }
        // outerAxisMultiplier is the product of the number of points
        // in each outer axis. It defaults to 1 if there are no outer axes.
        // It is multiplied by the number of points in the mapping scan
        // e.g. if the mapping scan in x and y has 25 points and is
        // also projected back through 10 points in z then there are
        // 250 points in total.
        int outerAxisMultiplier = calculateAllOuterPoints(request.getOuterScannables());
        int totalPoints = outerAxisMultiplier * pointCount;
        return PathInfo.builder().withSourceId(request.getSourceId()).withInnerPointCount(pointCount).withTotalPointCount(totalPoints).withSmallestXStep(smallestXStep).withSmallestYStep(smallestYStep).withSmallestAbsStep(smallestAbsStep).withxCoordinateList(xCoordinates).withyCoordinateList(yCoordinates).build();
    } catch (GeneratorException e) {
        throw new PathInfoCalculationException(e);
    }
}
Also used : IPosition(org.eclipse.scanning.api.points.IPosition) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) PathInfoCalculationException(uk.ac.diamond.daq.mapping.api.PathInfoCalculationException) ArrayList(java.util.ArrayList) GeneratorException(org.eclipse.scanning.api.points.GeneratorException) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Aggregations

ArrayList (java.util.ArrayList)1 GeneratorException (org.eclipse.scanning.api.points.GeneratorException)1 IPosition (org.eclipse.scanning.api.points.IPosition)1 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)1 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)1 PathInfoCalculationException (uk.ac.diamond.daq.mapping.api.PathInfoCalculationException)1