From 5c6f5118bb4b1eaf5e3ea0949a2ef1fd6b9fd76c Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 26 Oct 2026 15:52:20 -0700 Subject: [PATCH] move the stage scan math into StageScanUtils --- .../lightsheetmanager/model/PLogicScape.java | 47 ++----------------- .../acquisitions/AcquisitionEngineScape.java | 9 ++-- .../model/utils/StageScanUtils.java | 46 ++++++++++++++++++ 3 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 src/main/java/org/micromanager/lightsheetmanager/model/utils/StageScanUtils.java diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/PLogicScape.java b/src/main/java/org/micromanager/lightsheetmanager/model/PLogicScape.java index c5eed468..35721571 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/PLogicScape.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/PLogicScape.java @@ -19,6 +19,7 @@ import org.micromanager.lightsheetmanager.model.devices.vendor.SingleAxis; import org.micromanager.lightsheetmanager.model.utils.GeometryUtils; import org.micromanager.lightsheetmanager.model.utils.NumberUtils; +import org.micromanager.lightsheetmanager.model.utils.StageScanUtils; import java.awt.geom.Point2D; import java.util.Objects; @@ -201,7 +202,7 @@ public boolean prepareControllerForAcquisition( final double actualMotorSpeed = xyStage_.getSpeedXUm() / 1000; // set the acceleration to a reasonable value for the (usually very slow) scan speed - xyStage_.setAccelerationX(computeScanAcceleration(actualMotorSpeed, + xyStage_.setAccelerationX(StageScanUtils.computeScanAcceleration(actualMotorSpeed, xyStage_.getMaxSpeedX(), settings.stageScan().accelerationFactor())); // set the scan pattern and number of scans appropriately @@ -210,7 +211,7 @@ public boolean prepareControllerForAcquisition( numLines = 1; // assure in acquisition code that we can't have single-sided interleaved } if (settings.channels().enabled()) { - numLines = numLines * (settings.channels().count() / computeScanChannelsPerPass(settings)); + numLines = numLines * (settings.channels().count() / StageScanUtils.computeScanChannelsPerPass(settings)); } xyStage_.setScanNumLines(numLines); @@ -264,47 +265,7 @@ public boolean prepareControllerForAcquisition( // Compute appropriate motor speed in mm/s for the given stage scanning settings public double computeScanSpeed(final ScapeAcquisitionSettings settings) { - double sliceDurationMs = settings.timing().sliceDurationMs(); - if (settings.acquisitionMode() == AcquisitionMode.STAGE_SCAN_INTERLEAVED) { - // pretend like our slice takes twice as long so that we move the correct speed - // this has the effect of halving the motor speed, but keeping the scan distance the same - sliceDurationMs *= 2; - } - final int channelsPerPass = computeScanChannelsPerPass(settings); - final double speedFactor = GeometryUtils.getStageGeometricSpeedFactor( - settings.stageScan().firstViewAngle(), settings.volume().firstView() == 1); - return settings.volume().sliceStepSize() * speedFactor / sliceDurationMs / channelsPerPass; - } - - // compute how many channels we do in each one-way scan, at least 1 so the speed and the scan - // line count never divide by 0 when channels are enabled but none is used - private int computeScanChannelsPerPass(ScapeAcquisitionSettings settings) { - return settings.channels().mode() == ChannelMode.SLICE_HW - ? Math.max(1, settings.channels().count()) : 1; - } - - /** - * Compute appropriate acceleration time in ms for the specified motor speed. - * Set to be 10ms + 0-100ms depending on relative speed to max, all scaled by factor specified on the settings panel - * @param motorSpeed - * @return - */ - public double computeScanAcceleration(final double motorSpeed, final ScapeAcquisitionSettings settings) { - return (10 + 100 * (motorSpeed / xyStage_.getMaxSpeedX())) * settings.stageScan().accelerationFactor(); - } - - /** - * Compute appropriate acceleration time in ms for the specified motor speed. - * Set to be 10ms + 0-100ms depending on relative speed to max, all scaled by factor specified on the settings panel - * - * @param motorSpeed - * @return - */ - public double computeScanAcceleration(final double motorSpeed, final double maxMotorSpeed, final double stageScanAccelFactor) { -// final double maxMotorSpeed = props_.getPropValueFloat(Devices.Keys.XYSTAGE, Properties.Keys.STAGESCAN_MAX_MOTOR_SPEED_X); -// final double accelFactor = props_.getPropValueFloat(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_STAGESCAN_ACCEL_FACTOR); -// return (10 + 100 * (motorSpeed / maxMotorSpeed) ) * accelFactor; - return (10 + 100 * (motorSpeed / maxMotorSpeed)) * stageScanAccelFactor; + return StageScanUtils.computeScanSpeed(settings); } public boolean prepareStageScanForAcquisition(final double x, final double y, ScapeAcquisitionSettings settings) { diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineScape.java b/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineScape.java index 2dd8b3ad..15357851 100644 --- a/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineScape.java +++ b/src/main/java/org/micromanager/lightsheetmanager/model/acquisitions/AcquisitionEngineScape.java @@ -47,6 +47,7 @@ import org.micromanager.lightsheetmanager.model.utils.FileUtils; import org.micromanager.lightsheetmanager.model.utils.GeometryUtils; import org.micromanager.lightsheetmanager.model.utils.NumberUtils; +import org.micromanager.lightsheetmanager.model.utils.StageScanUtils; import javax.swing.JLabel; import javax.swing.SwingUtilities; @@ -2230,12 +2231,10 @@ private double getStageRampDuration(final ScapeAcquisitionSettings settings) { } private double getScanStageAcceleration(final ScapeAcquisitionSettings settings) { - // TODO: remove this and find a better way - if (controller_ == null) { - controller_ = new PLogicScape(model_); - } + final ASIXYStage stage = model_.devices().device("SampleXY"); // extra 1 for rounding up that often happens in controller - return controller_.computeScanAcceleration(controller_.computeScanSpeed(settings), settings) + 1; + return StageScanUtils.computeScanAcceleration(StageScanUtils.computeScanSpeed(settings), + stage.getMaxSpeedX(), settings.stageScan().accelerationFactor()) + 1; } private double getStageRetraceDuration(final ScapeAcquisitionSettings settings) { diff --git a/src/main/java/org/micromanager/lightsheetmanager/model/utils/StageScanUtils.java b/src/main/java/org/micromanager/lightsheetmanager/model/utils/StageScanUtils.java new file mode 100644 index 00000000..580f3bef --- /dev/null +++ b/src/main/java/org/micromanager/lightsheetmanager/model/utils/StageScanUtils.java @@ -0,0 +1,46 @@ +package org.micromanager.lightsheetmanager.model.utils; + +import org.micromanager.lightsheetmanager.api.data.AcquisitionMode; +import org.micromanager.lightsheetmanager.api.data.ChannelMode; +import org.micromanager.lightsheetmanager.api.internal.ScapeAcquisitionSettings; + +public final class StageScanUtils { + + /** This class should not be instantiated. */ + private StageScanUtils() { + throw new AssertionError("Utility class; do not instantiate."); + } + + // Compute appropriate motor speed in mm/s for the given stage scanning settings + public static double computeScanSpeed(final ScapeAcquisitionSettings settings) { + double sliceDurationMs = settings.timing().sliceDurationMs(); + if (settings.acquisitionMode() == AcquisitionMode.STAGE_SCAN_INTERLEAVED) { + // pretend like our slice takes twice as long so that we move the correct speed + // this has the effect of halving the motor speed, but keeping the scan distance the same + sliceDurationMs *= 2; + } + final int channelsPerPass = computeScanChannelsPerPass(settings); + final double speedFactor = GeometryUtils.getStageGeometricSpeedFactor( + settings.stageScan().firstViewAngle(), settings.volume().firstView() == 1); + return settings.volume().sliceStepSize() * speedFactor / sliceDurationMs / channelsPerPass; + } + + // compute how many channels we do in each one-way scan, at least 1 so the speed and the scan + // line count never divide by 0 when channels are enabled but none is used + public static int computeScanChannelsPerPass(final ScapeAcquisitionSettings settings) { + return settings.channels().mode() == ChannelMode.SLICE_HW + ? Math.max(1, settings.channels().count()) : 1; + } + + /** + * Compute appropriate acceleration time in ms for the specified motor speed. + * Set to be 10ms + 0-100ms depending on relative speed to max, all scaled by factor specified on the settings panel + * + * @param motorSpeed + * @return + */ + public static double computeScanAcceleration(final double motorSpeed, final double maxMotorSpeed, final double stageScanAccelFactor) { + return (10 + 100 * (motorSpeed / maxMotorSpeed)) * stageScanAccelFactor; + } + +}