Skip to content

Commit

Permalink
Merge pull request #31 from automated-ultramicrotomy/dev
Browse files Browse the repository at this point in the history
Merge changes from dev
  • Loading branch information
K-Meech authored Jun 25, 2024
2 parents fd92a0a + 8fefd92 commit 45aabe9
Show file tree
Hide file tree
Showing 48 changed files with 1,358 additions and 590 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

# - name: Install blosc
# run: sudo apt install libblosc-dev
# - name: Install xvfb
# run: sudo apt-get install xvfb
- name: Install xvfb
run: sudo apt-get install xvfb
- name: Build with maven
run: mvn -B package --file pom.xml # for testing with graphics prepend: xvfb-run --auto-servernum
run: xvfb-run --auto-servernum mvn -B package --file pom.xml
16 changes: 13 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</parent>
<artifactId>crosshair</artifactId>
<url>https://github.com/K-Meech/crosshair</url>
<version>1.0.3</version>
<version>1.0.4</version>
<name>Crosshair</name>
<description>Assisted 3D targeting via an ultramicrotome</description>
<inceptionYear>2020</inceptionYear>
Expand Down Expand Up @@ -80,7 +80,7 @@

<!-- <bigdataviewer-core.version>10.2.0</bigdataviewer-core.version>-->
<!-- <bigdataviewer-vistools.version>1.0.0-beta-28</bigdataviewer-vistools.version>-->
<imagej-utils.version>0.6.4-SNAPSHOT</imagej-utils.version>
<imagej-utils.version>0.6.4</imagej-utils.version>
</properties>

<repositories>
Expand Down Expand Up @@ -111,6 +111,16 @@
<groupId>sc.fiji</groupId>
<artifactId>3D_Viewer</artifactId>
</dependency>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt</artifactId>
<classifier>${scijava.natives.classifier.gluegen}</classifier>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all</artifactId>
<classifier>${scijava.natives.classifier.jogl}</classifier>
</dependency>
<dependency>
<groupId>de.embl.cba</groupId>
<artifactId>imagej-utils</artifactId>
Expand All @@ -119,7 +129,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
104 changes: 99 additions & 5 deletions src/main/java/de/embl/schwab/crosshair/Crosshair.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package de.embl.schwab.crosshair;

import bdv.util.*;
import bdv.viewer.Source;
import de.embl.schwab.crosshair.bdv.BdvBehaviours;
import de.embl.schwab.crosshair.microtome.MicrotomeManager;
import de.embl.schwab.crosshair.plane.Plane;
import de.embl.schwab.crosshair.plane.PlaneManager;
import de.embl.schwab.crosshair.ui.swing.CrosshairFrame;
import ij3d.Content;
import ij3d.Image3DUniverse;
import net.imglib2.img.Img;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.type.numeric.ARGBType;
import ij.ImagePlus;

import static de.embl.cba.tables.ij3d.UniverseUtils.addSourceToUniverse;
import static de.embl.schwab.crosshair.utils.Utils.spaceOutWindows;

// TODO - neaten up code structure, possibly clearer labelling of which coordinate system & units are being used
Expand All @@ -33,9 +40,72 @@ public class Crosshair {
public static final String block = "block";
public static final String image = "image";

public Crosshair (BdvStackSource bdvStackSource, Image3DUniverse universe, Content imageContent, String unit) {
// TODO - make generic? Not just 8 bit
private final int min = 0;
private final int max = 255;
private final float transparency = 0.7f;

private BdvHandle bdvHandle; // bdvHandle of the BigDataViewer window
private Image3DUniverse universe; // universe of the 3D viewer
private Content imageContent; // image content displayed in 3D viewer
private PlaneManager planeManager;
private MicrotomeManager microtomeManager;
private String unit; // pixel size unit e.g. mm

/**
* Open Crosshair from a Source (normally from a bdv style file e.g. hdf5 / n5)
* @param imageSource image source
*/
public Crosshair(Source<Object> imageSource) {

BdvStackSource bdvStackSource = BdvFunctions.show(imageSource, 1);
Image3DUniverse universe = new Image3DUniverse();
universe.show();

String unit = imageSource.getVoxelDimensions().unit();

// Set to arbitrary colour
ARGBType colour = new ARGBType( ARGBType.rgba( 0, 0, 0, 0 ) );
Content imageContent = addSourceToUniverse(universe, imageSource, 300 * 300 * 300,
Content.VOLUME, colour, transparency, min, max );
// Reset colour to default for 3D viewer
imageContent.setColor(null);

initialiseCrosshair(bdvStackSource, universe, imageContent, unit);
}

/**
* Open Crosshair from an ImagePlus (normally by pulling current image from ImageJ)
* @param imagePlus image
*/
public Crosshair(ImagePlus imagePlus) {

Image3DUniverse universe = new Image3DUniverse();
Content imageContent = universe.addContent(imagePlus, Content.VOLUME);
imageContent.setTransparency(transparency);
universe.show();

final double pw = imagePlus.getCalibration().pixelWidth;
final double ph = imagePlus.getCalibration().pixelHeight;
final double pd = imagePlus.getCalibration().pixelDepth;
final String unit = imagePlus.getCalibration().getUnit();

final Img wrap = ImageJFunctions.wrap(imagePlus);
BdvStackSource bdvStackSource = BdvFunctions.show(wrap, "raw", Bdv.options()
.sourceTransform(pw, ph, pd));

initialiseCrosshair(bdvStackSource, universe, imageContent, unit);
}

private void initialiseCrosshair(BdvStackSource bdvStackSource, Image3DUniverse universe, Content imageContent, String unit) {

bdvStackSource.setDisplayRange(min, max);

this.bdvHandle = bdvStackSource.getBdvHandle();
this.imageContent = imageContent;
this.universe = universe;
this.unit = unit;

BdvHandle bdvHandle = bdvStackSource.getBdvHandle();
imageContent.setLocked(true);
imageContent.showPointList(true);
universe.getPointListDialog().setVisible(false);
Expand All @@ -45,13 +115,37 @@ public Crosshair (BdvStackSource bdvStackSource, Image3DUniverse universe, Conte
// Still places so (0,0) of image == (0,0) in global coordinate system, just bounding box is wrapped tight to
// only regions of the image > 0

PlaneManager planeManager = new PlaneManager(bdvStackSource, universe, imageContent);
planeManager = new PlaneManager(bdvStackSource, universe, imageContent);

MicrotomeManager microtomeManager = new MicrotomeManager(planeManager, universe, imageContent, bdvStackSource, unit);
microtomeManager = new MicrotomeManager(planeManager, universe, imageContent, bdvStackSource, unit);
new BdvBehaviours(bdvHandle, planeManager, microtomeManager);

CrosshairFrame crosshairFrame = new CrosshairFrame(universe, imageContent, planeManager, microtomeManager, bdvHandle, unit);
CrosshairFrame crosshairFrame = new CrosshairFrame(this);

spaceOutWindows( bdvHandle, crosshairFrame, universe );
}

public BdvHandle getBdvHandle() {
return bdvHandle;
}

public Content getImageContent() {
return imageContent;
}

public Image3DUniverse getUniverse() {
return universe;
}

public MicrotomeManager getMicrotomeManager() {
return microtomeManager;
}

public PlaneManager getPlaneManager() {
return planeManager;
}

public String getUnit() {
return unit;
}
}
10 changes: 10 additions & 0 deletions src/main/java/de/embl/schwab/crosshair/bdv/BdvBehaviours.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@

import javax.swing.*;

/**
* Class to control custom interactions with the BigDataViewer window
* For example, clicking to add points or fitting a plane to points
*/
public class BdvBehaviours {

private BdvHandle bdvHandle;
private PlaneManager planeManager;
private MicrotomeManager microtomeManager;

/**
* Adds custom behaviours to the BigDataViewer window referenced by bdvHandle
* @param bdvHandle bdvHandle of the BigDataViewer window
* @param planeManager Crosshair plane manager
* @param microtomeManager Crosshair microtome manager
*/
public BdvBehaviours (BdvHandle bdvHandle, PlaneManager planeManager, MicrotomeManager microtomeManager) {
this.bdvHandle = bdvHandle;
this.planeManager = planeManager;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/de/embl/schwab/crosshair/bdv/ModeOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@

import java.awt.*;

/**
* Class to display the current Crosshair mode as an overlay on the BigDataViewer window
*/
public class ModeOverlay extends BdvOverlay {

private PlaneManager planeManager;
private Color colModeText = new Color(255, 255, 255);

/**
* Create a BigDataViewer overlay for the Crosshair mode text
* @param planeManager Crosshair plane manager
*/
public ModeOverlay( PlaneManager planeManager ) {
this.planeManager = planeManager;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/embl/schwab/crosshair/io/IoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;

/**
* Class with IO utility functions
*/
public class IoHelper {

private static String lastDirPath;

/**
* Opens a file chooser to select a json file
* @return filepath of the chosen file
*/
public static String chooseOpenFilePath() {
String filePath = null;
JFileChooser chooser = new JFileChooser(lastDirPath);
Expand All @@ -21,6 +28,10 @@ public static String chooseOpenFilePath() {
return filePath;
}

/**
* Opens a file chooser to select where to save a json file
* @return filepath to save json
*/
public static String chooseSaveFilePath() {
String filePath = null;
JFileChooser chooser = new JFileChooser(lastDirPath);
Expand Down
Loading

0 comments on commit 45aabe9

Please sign in to comment.