Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
1.0.5

Closes #189, #190, and #188

See merge request scicomp/scidev_team/spimacquisition!2
  • Loading branch information
moon committed Mar 22, 2022
2 parents bf89a77 + 5161e97 commit bc6f528
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>org.openspim</groupId>
<artifactId>uOpenSPIM</artifactId>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
<packaging>jar</packaging>

<name>µOpenSPIM</name>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/spim/algorithm/DefaultAntiDrift.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package spim.algorithm;

import ij.ImageStack;
import ij.plugin.filter.Convolver;
import ij.plugin.filter.GaussianBlur;
import ij.plugin.filter.RankFilters;
import ij.process.*;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;

Expand All @@ -18,6 +21,14 @@ public class DefaultAntiDrift extends AbstractAntiDrift
*/
private final double sigma;
private final AntiDrift.Type type;
private final GaussianBlur gaussianBlur = new GaussianBlur();
private final Convolver convolver = new Convolver();
private final RankFilters filters = new RankFilters();
private final float[] kernel = new float[]{-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1,
-1, -1, 24, -1, -1,
-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1,};

public DefaultAntiDrift(double sigmaValue)
{
Expand Down Expand Up @@ -49,14 +60,16 @@ public void reset()
@Override public void addXYSlice( ImageProcessor ip )
{
ImageProcessor copy = ip.duplicate();
gaussianBlur.blurGaussian( copy, sigma );
convolver.convolve( copy, kernel, 5, 5 );
filters.rank( copy, 2, 2 );

switch (type) {
case CenterOfMass:
if(stack == null) stack = new ImageStack( ip.getWidth(), ip.getHeight() );
stack.addSlice( copy );
break;
case PhaseCorrelation:
copy.blurGaussian( sigma );
latest.addXYSlice( copy );
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/spim/mm/MicroManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1331,14 +1331,14 @@ public static void shutdown()

@Subscribe
public void onAcquisitionStart( AcquisitionStartedEvent ae) {
System.out.println("Acquisition started");
// System.out.println("Acquisition started");
// store_ = ae.getDatastore();
}


@Subscribe
public void onAcquisitionEnd( AcquisitionEndedEvent ae) {
System.out.println("Acquisition stopped");
// System.out.println("Acquisition stopped");
// store_ = null;
}

Expand All @@ -1349,7 +1349,7 @@ public void onSystemConfigurationLoaded(SystemConfigurationLoadedEvent event) {

@Subscribe
public void onStagePositionChanged(StagePositionChangedEvent event) {
System.out.println("Stage changed");
// System.out.println("Stage changed");
}

@Subscribe
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/spim/model/data/PositionItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package spim.model.data;

import javafx.beans.InvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

/**
* Description: PositionItem is used for position table.
*
Expand All @@ -15,19 +21,23 @@ public class PositionItem
private double zStart;
private double zEnd;
private double zStep;
private final BooleanProperty selected = new SimpleBooleanProperty();
private final StringProperty name = new SimpleStringProperty();

public PositionItem()
{
}

public PositionItem( double x, double y, double r, double zStart, double zEnd, double zStep )
public PositionItem( double x, double y, double r, double zStart, double zEnd, double zStep, InvalidationListener invalidationListener )
{
this.x = x;
this.y = y;
this.r = r;
this.zStart = zStart;
this.zEnd = zEnd;
this.zStep = zStep;
this.name.set("");
selectedProperty().addListener( observable -> invalidationListener.invalidated( observable ) );
}

public double getX()
Expand Down Expand Up @@ -74,6 +84,12 @@ public String getPosZString() {
return String.format( "%.0f", zStart );
}

public String getName() {
return name.getValue();
}

public StringProperty getNameProperty() { return name; }

public void setX( double x )
{
this.x = x;
Expand Down Expand Up @@ -105,7 +121,21 @@ public void setZStep( double zStep )
}

public int getNumberOfSlices() {
return (int) ((int) (getZEnd() - getZStart() + getZStep()) / getZStep());
return (int) ((int) (getZEnd() - getZStart() + getZStep()) / getZStep() + 1);
}

public BooleanProperty selectedProperty() { return selected; }

public boolean getSelected() {
return selected.get();
}

public void setSelected(boolean selected) {
this.selected.set( selected );
}

public void setName(String name) {
this.name.set(name);
}

@Override public String toString()
Expand Down
39 changes: 27 additions & 12 deletions src/main/java/spim/ui/view/component/AcquisitionPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public AcquisitionPanel(SPIMSetup setup, Studio studio, StagePanel stagePanel, T
{
@Override public void changed( ObservableValue< ? extends Number > observable, Number oldValue, Number newValue )
{
// System.out.println(String.format("%f / %d", newValue.doubleValue(), totalImages.getValue()));
pi.setProgress( newValue.doubleValue() / totalImages.getValue() );
}
} );
Expand Down Expand Up @@ -1207,6 +1208,13 @@ private void updateUI ( AcquisitionSetting setting ) {
positionItems = setting.getPositionItems();
positionItemTableView.getItems().setAll( positionItems );

InvalidationListener invalidationListener = observable -> computeTotalPositionImages();
for(int i = 0; i < positionItems.size(); i++) {
// positionItems.get( i ).setValue( positionItems.get(i).getValue() );
// positionItems.get( i ).setSelected( positionItems.get(i).getSelected() );
positionItems.get( i ).selectedProperty().addListener( observable -> invalidationListener.invalidated( observable ) );
}

// 3. Z-Stack panel
enabledZStacks.set( setting.getEnabledZStacks() );

Expand Down Expand Up @@ -1353,7 +1361,7 @@ public boolean startAcquisition( Button acquireButton )
if ( enabledSaveImages.get() )
{
if(null != folder.listFiles()) {
boolean found = folder.exists();
boolean found = folder.exists() && folder.listFiles().length > 1;

if(found) {
Optional< ButtonType > results = new Alert( Alert.AlertType.WARNING, "The filename already exists. All files with the same name will be replaced. Do you want to proceed?\nPress No to create another folder and keep all files.",
Expand Down Expand Up @@ -1462,7 +1470,7 @@ public boolean startAcquisition( Button acquireButton )
engine.performAcquisition( getStudio(), getSpimSetup(), stagePanel, ( java.awt.Rectangle) roiRectangle.get(), tp,
timePointItemTableView.getItems(), currentTP, waitSeconds,
arduinoSelected, finalFolder, filename.getValue(),
positionItemTableView.getItems(), channelItemList, processedImages,
positionItemTableView.getItems().filtered(p -> p.getSelected()), channelItemList, processedImages,
enabledSaveImages.get(), savingFormat.getValue(), saveMIP.getValue(), antiDrift.getValue(), experimentNote.getValue(),
antiDriftLog, antiDriftRefCh.get(), antiDriftTypeToggle, onTheFly.getValue() );

Expand Down Expand Up @@ -1515,17 +1523,19 @@ static double getUnit(String unitString) {
private Node createPositionListPane( TableView< PositionItem > positionItemTableView ) {
positionItemTableView.setEditable( true );

InvalidationListener invalidationListener = observable -> computeTotalPositionImages();

EventHandler newEventHandler = ( EventHandler< ActionEvent > ) event -> {
SPIMSetup spimSetup = getSpimSetup();
if(spimSetup != null ) {
double r = spimSetup.getThetaStage().getPosition();
double x = spimSetup.getXStage().getPosition();
double y = spimSetup.getYStage().getPosition();
double z = spimSetup.getZStage().getPosition();
positionItemTableView.getItems().add( new PositionItem( x, y, r, z, z, zStackStepSize ) );
positionItemTableView.getItems().add( new PositionItem( x, y, r, z, z, zStackStepSize, invalidationListener ) );
}
else {
positionItemTableView.getItems().add( new PositionItem( 10, 20, 30, 20, 50, 10 ) );
positionItemTableView.getItems().add( new PositionItem( 10, 20, 30, 20, 50, 10, invalidationListener ) );
}
};

Expand Down Expand Up @@ -1610,12 +1620,12 @@ public void computeTotalPositionImages() {
long totalImages = 0;
for(PositionItem item : positionItemTableView.getItems())
{
if(item.getZEnd() > item.getZStart()) {
if(item.getSelected() && item.getZEnd() > item.getZStart()) {
totalImages += item.getNumberOfSlices();
}
}

propertyMap.get("positions").setValue( positionItemTableView.getItems().size() + "" );
propertyMap.get("positions").setValue( positionItemTableView.getItems().filtered(p -> p.getSelected()).size() + "" );
propertyMap.get("slices").setValue( totalImages + "" );
}

Expand Down Expand Up @@ -1853,6 +1863,8 @@ private LabeledPane createSummaryPane() {
label.textProperty().bind( propertyMap.get("positions") );
label.textProperty().addListener( observable -> computeTotal() );

propertyMap.get("slices").addListener( observable -> computeTotal() );

Label label2 = new Label();
label2.textProperty().bind( propertyMap.get("totalImages") );
gridpane.addRow( 0, new Label("No. of positions: "), label, new Label("Total images: "), label2 );
Expand Down Expand Up @@ -2097,7 +2109,8 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
// }
// } );

Button clearButton = new Button( "New Z-stack" );
Button clearButton = new Button( "Define new Z-stack" );
clearButton.setStyle("-fx-base: #ffbec4;");
clearButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Expand Down Expand Up @@ -2134,7 +2147,7 @@ public void handle(ActionEvent event) {
}
} );

zStackGridPane.addRow( 3, new HBox( newButton, clearButton ) );
zStackGridPane.addRow( 3, new VBox( newButton, clearButton ) );

// create a group
HBox b = new HBox(new Label("Stage"));
Expand All @@ -2148,13 +2161,15 @@ public void handle(ActionEvent event) {
Button helpButton = createHelpButton();
helpButton.setOnAction( event -> new HelpWindow().show(HelpType.ZSTACK));

CheckboxPane pane = new CheckboxPane( "Define Z-stacks", zStackGroup, helpButton );
CheckboxPane pane = new CheckboxPane( "Z-stacks", zStackGroup, helpButton );
enabledZStacks = pane.selectedProperty();
return pane;
}

private void addNewPosition( int zStart, int zEnd, double zStep ) {
SPIMSetup spimSetup = getSpimSetup();
InvalidationListener invalidationListener = observable -> computeTotalPositionImages();

if(spimSetup != null ) {
double r = spimSetup.getThetaStage().getPosition();
double x = spimSetup.getXStage().getPosition();
Expand All @@ -2164,13 +2179,13 @@ private void addNewPosition( int zStart, int zEnd, double zStep ) {

if( zStart < 0 && zEnd < 0 ) {
double z = spimSetup.getZStage().getPosition();
positionItemTableView.getItems().add(new PositionItem(x, y, r, z, z, zStep));
positionItemTableView.getItems().add(new PositionItem(x, y, r, z, z, zStep, invalidationListener));
} else {
positionItemTableView.getItems().add(new PositionItem(x, y, r, zStart, zEnd, zStep));
positionItemTableView.getItems().add(new PositionItem(x, y, r, zStart, zEnd, zStep, invalidationListener));
}
}
else {
positionItemTableView.getItems().add( new PositionItem( 10, 20, 30, zStart, zEnd, zStep ) );
positionItemTableView.getItems().add( new PositionItem( 10, 20, 30, zStart, zEnd, zStep, invalidationListener ) );
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/spim/ui/view/component/MMAcquisitionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,15 @@ private void runNormalSmartImagingMMAcq(SPIMSetup setup, final Studio frame, Dat
if(toogleGroupValue.equals("Centre of mass")) {
driftCompMap.put(positionItem, new DefaultAntiDrift());
} else if(toogleGroupValue.equals("Phase correlation")) {
driftCompMap.put(positionItem, new DefaultAntiDrift(10));
driftCompMap.put(positionItem, new DefaultAntiDrift(2));
}
}
}

AcqWrapperEngine engine = new AcqWrapperEngine( setup, frame, store, currentCamera, cameras, outFolder, acqFilenamePrefix, channelItems, arduinoSelected, processedImages, driftCompMap, adReferenceChannel, onTheFly);

SystemInfo.dumpMemoryStatusToLog(core);

mainLoop:
for(TimePointItem tpItem : timePointItems ) {
if(tpItem.getType().equals( TimePointItem.Type.Acq ))
Expand All @@ -398,8 +400,6 @@ private void runNormalSmartImagingMMAcq(SPIMSetup setup, final Studio frame, Dat

int step = 0;

SystemInfo.dumpMemoryStatusToLog(core);

for ( PositionItem positionItem : positionItems )
{
final int tp = timePoints;
Expand Down Expand Up @@ -482,7 +482,7 @@ private void runNormalSmartImagingMMAcq(SPIMSetup setup, final Studio frame, Dat
}

core.logMessage("MMAcquisition started");
System.out.println("MMAcquisition started");
// System.out.println("MMAcquisition started");
engine.startAcquire( timePoints, step, positionItem );

while(engine.isAcquisitionRunning()) {
Expand All @@ -498,7 +498,7 @@ private void runNormalSmartImagingMMAcq(SPIMSetup setup, final Studio frame, Dat
}

core.logMessage("MMAcquisition finished");
System.out.println("MMAcquisition finished");
// System.out.println("MMAcquisition finished");

if(setup.getArduino1() != null)
setup.getArduino1().setSwitchState( "0" );
Expand Down Expand Up @@ -594,6 +594,8 @@ else if(tpItem.getType().equals( TimePointItem.Type.Wait ))
}
}

SystemInfo.dumpMemoryStatusToLog(core);

engine.exit();
store.freeze();
System.err.println("AcquisitionEngine exited.");
Expand Down
Loading

0 comments on commit bc6f528

Please sign in to comment.