Skip to content

Instantly share code, notes, and snippets.

@lacan
Last active October 28, 2019 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacan/82f88b67693ce22bbb61788cf585e11a to your computer and use it in GitHub Desktop.
Save lacan/82f88b67693ce22bbb61788cf585e11a to your computer and use it in GitHub Desktop.
[BigStitcher Flip Axes] Implements the Flip Axes Command from BigStitcher in a Macro Recordable Way #SPIM #BigStitcher #Fiji #Groovy
/**
* Implements the Flip Axes Command from BigStitcher
*
* Recommendation is to place this file in
* [FIJI Folder]/plugins/Scripts/Plugins/BigStitcher/Custom Scripts
*
* By Olivier Burri for Kai Schleicher,
* https://forum.image.sc/t/bigstitcher-flip-axes-in-headless-mode/30557?u=oburri
* BSD 3 License
*
*/
import net.preibisch.mvrecon.fiji.plugin.queryXML.LoadParseQueryXML
import ij.gui.GenericDialog
import net.preibisch.stitcher.arrangement.FlipAxes
import net.preibisch.mvrecon.fiji.spimdata.SpimData2
def result = new LoadParseQueryXML()
if ( !result.queryXML( "for Axes Flipping", true, true, true, true, true ) ) return
// Get the data
def spimData = result.getData();
def dims = new HashMap<>()
def views = spimData.getSequenceDescription().getViewDescriptions().keySet().collect()
views.each{ v -> dims.put( v, spimData.getSequenceDescription().getViewDescriptions().get( v ).getViewSetup().getSize()) }
def flipAxes = new boolean[3]
GenericDialog gd = new GenericDialog( "Flip Parameters" )
gd.addCheckbox( "Flip X", true )
gd.addCheckbox( "Flip Y", false )
gd.addCheckbox( "Flip Z", false )
gd.showDialog();
if (gd.wasCanceled())
return;
flipAxes[0] = gd.getNextBoolean()
flipAxes[1] = gd.getNextBoolean()
flipAxes[2] = gd.getNextBoolean()
// Finally do the flip
FlipAxes.applyFlipToData( spimData.getViewRegistrations(), dims, views, flipAxes )
// Save the XML file
SpimData2.saveXML( spimData, result.getXMLFileName(), result.getClusterExtension() )
@imagejan
Copy link

imagejan commented Oct 25, 2019

Lines 28 to 39 can be simplified by using script parameters:

#@ Boolean (label="Flip X", value=true ) flipX
#@ Boolean (label="Flip Y", value=false) flipY
#@ Boolean (label="Flip Z", value=false) flipZ
flipAxes[0] = flipX
flipAxes[1] = flipY
flipAxes[2] = flipZ

Is there a specific reason why you prefer using GenericDialog?

@lacan
Copy link
Author

lacan commented Oct 28, 2019

Hi @imagejan,
The reason was to keep the order of the operations the same as running any other BigStitcher batch command.

  1. Get the xml
  2. Show GenericDialogs specific to the batch task

I simply copied from:
https://github.com/PreibischLab/BigStitcher/blob/acb0ee1c68bc124e805a5e3a4c39d723965d520b/src/main/java/net/preibisch/stitcher/gui/popup/FlipAxesPopup.java#L54

If I used script parameters, it would first ask about the flipping axes and then request the XML file. Though I agree with you that Script Parameters would be the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment