diff --git a/src/main/java/sc/fiji/bdvpg/bdv/BdvUtils.java b/src/main/java/sc/fiji/bdvpg/bdv/BdvUtils.java index 4ab0738d..c699f35c 100644 --- a/src/main/java/sc/fiji/bdvpg/bdv/BdvUtils.java +++ b/src/main/java/sc/fiji/bdvpg/bdv/BdvUtils.java @@ -1,6 +1,7 @@ package sc.fiji.bdvpg.bdv; import bdv.tools.brightness.MinMaxGroup; +import bdv.tools.transformation.TransformedSource; import bdv.util.Bdv; import bdv.util.BdvHandle; import bdv.viewer.Source; @@ -229,6 +230,15 @@ public static MinMaxGroup getMinMaxGroup( BdvHandle bdvHandle, Source< ? > sourc return minmax; } + + /** + * TODO: remove the print statements or make them some debug mode. + * + * + * @param bdv + * @param source + * @return + */ public static int getSourceIndex( Bdv bdv, Source< ? > source ) { final List< SourceState< ? > > sources = @@ -237,10 +247,22 @@ public static int getSourceIndex( Bdv bdv, Source< ? > source ) System.out.println("look for : "+ source); for ( int i = 0; i < sources.size(); ++i ) { - System.out.println("c:"+sources.get(i).getSpimSource()); + final Source< ? > bdvSource = sources.get( i ).getSpimSource(); + + System.out.println("c:"+ bdvSource ); + + if ( bdvSource instanceof TransformedSource ) + { + final Source wrappedSource = ( ( TransformedSource ) bdvSource ).getWrappedSource(); - if (sources.get(i).getSpimSource().equals(source)) - return i; + if ( wrappedSource.equals( source ) ) + return i; + } + else + { + if ( bdvSource.equals( source ) ) + return i; + } } return -1; diff --git a/src/main/java/sc/fiji/bdvpg/bdv/source/displayopts/BrightnessAdjuster.java b/src/main/java/sc/fiji/bdvpg/bdv/source/display/BrightnessAutoAdjuster.java similarity index 85% rename from src/main/java/sc/fiji/bdvpg/bdv/source/displayopts/BrightnessAdjuster.java rename to src/main/java/sc/fiji/bdvpg/bdv/source/display/BrightnessAutoAdjuster.java index c8a0d051..fd4a9695 100644 --- a/src/main/java/sc/fiji/bdvpg/bdv/source/displayopts/BrightnessAdjuster.java +++ b/src/main/java/sc/fiji/bdvpg/bdv/source/display/BrightnessAutoAdjuster.java @@ -1,4 +1,4 @@ -package sc.fiji.bdvpg.bdv.source.displayopts; +package sc.fiji.bdvpg.bdv.source.display; import bdv.tools.brightness.MinMaxGroup; import bdv.util.BdvHandle; @@ -12,14 +12,20 @@ import net.imglib2.view.Views; import sc.fiji.bdvpg.bdv.BdvUtils; -public class BrightnessAdjuster implements Runnable +public class BrightnessAutoAdjuster implements Runnable { private final BdvHandle bdvHandle; private final Source< ? > source; private final double cumulativeMinCutoff; private final double cumulativeMaxCutoff; - public BrightnessAdjuster( final BdvHandle bdvHandle, final Source< ? > source, final double cumulativeMinCutoff, final double cumulativeMaxCutoff ) + + public BrightnessAutoAdjuster( final BdvHandle bdvHandle, final Source< ? > source ) + { + this( bdvHandle, source, 0.01, 0.99 ); + } + + public BrightnessAutoAdjuster( final BdvHandle bdvHandle, final Source< ? > source, final double cumulativeMinCutoff, final double cumulativeMaxCutoff ) { this.bdvHandle = bdvHandle; this.source = source; diff --git a/src/main/java/sc/fiji/bdvpg/command/BdvAppendSampleCommand.java b/src/main/java/sc/fiji/bdvpg/command/BdvAppendSampleCommand.java index 20925ce0..1f594e23 100644 --- a/src/main/java/sc/fiji/bdvpg/command/BdvAppendSampleCommand.java +++ b/src/main/java/sc/fiji/bdvpg/command/BdvAppendSampleCommand.java @@ -7,7 +7,7 @@ import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; import sc.fiji.bdvpg.bdv.source.append.AddSourceToBdv; -import sc.fiji.bdvpg.bdv.source.displayopts.BrightnessAdjuster; +import sc.fiji.bdvpg.bdv.source.display.BrightnessAutoAdjuster; import sc.fiji.bdvpg.log.SystemLogger; import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults; import sc.fiji.bdvpg.source.importer.samples.MandelbrotSourceGetter; @@ -18,10 +18,10 @@ public class BdvAppendSampleCommand implements Command { @Parameter(type = ItemIO.BOTH) - BdvHandle bdvh; + public BdvHandle bdvh; @Parameter(choices = {"Mandelbrot", "Wave3D", "Voronoi", "Big Voronoi"}) - String sampleName; + public String sampleName; @Override public void run() { @@ -50,7 +50,6 @@ public void run() { } new AddSourceToBdv(bdvh, src).run(); - // DO NOT WORK - //new BrightnessAdjuster(bdvh, src, 0.01, 0.99).run(); + new BrightnessAutoAdjuster(bdvh, src, 0.01, 0.99).run(); } } diff --git a/src/main/java/sc/fiji/bdvpg/command/SingleSourceLoaderCommand.java b/src/main/java/sc/fiji/bdvpg/command/SingleSourceLoaderCommand.java index c2532cb2..6d16ad7a 100644 --- a/src/main/java/sc/fiji/bdvpg/command/SingleSourceLoaderCommand.java +++ b/src/main/java/sc/fiji/bdvpg/command/SingleSourceLoaderCommand.java @@ -8,7 +8,7 @@ import org.scijava.plugin.Plugin; import sc.fiji.bdvpg.bdv.navigate.ViewerTransformAdjuster; import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults; -import sc.fiji.bdvpg.bdv.source.displayopts.BrightnessAdjuster; +import sc.fiji.bdvpg.bdv.source.display.BrightnessAutoAdjuster; import sc.fiji.bdvpg.bdv.source.append.SourceAdder; import sc.fiji.bdvpg.source.importer.SourceLoader; @@ -47,7 +47,7 @@ public void adjustViewerTransform() public void adjustBrightness() { - new BrightnessAdjuster( bdvHandle, source, 0.01, 0.99 ).run(); + new BrightnessAutoAdjuster( bdvHandle, source, 0.01, 0.99 ).run(); } public void addSource() diff --git a/src/main/java/sc/fiji/bdvpg/scijava/ScijavaBdvDefaults.java b/src/main/java/sc/fiji/bdvpg/scijava/ScijavaBdvDefaults.java index 9a459569..74792180 100644 --- a/src/main/java/sc/fiji/bdvpg/scijava/ScijavaBdvDefaults.java +++ b/src/main/java/sc/fiji/bdvpg/scijava/ScijavaBdvDefaults.java @@ -2,5 +2,5 @@ public class ScijavaBdvDefaults { - final public static String RootMenu = "Bdv_Scijava>";//Plugins>BigDataViewer>"; + final public static String RootMenu = "Bdv_Scijava>"; } diff --git a/src/main/java/sc/fiji/bdvpg/source/importer/samples/Wave3DSourceGetter.java b/src/main/java/sc/fiji/bdvpg/source/importer/samples/Wave3DSourceGetter.java index 6cd554fa..a5a8f4f0 100644 --- a/src/main/java/sc/fiji/bdvpg/source/importer/samples/Wave3DSourceGetter.java +++ b/src/main/java/sc/fiji/bdvpg/source/importer/samples/Wave3DSourceGetter.java @@ -1,6 +1,7 @@ package sc.fiji.bdvpg.source.importer.samples; import bdv.viewer.Source; +import net.imglib2.FinalInterval; import java.util.function.Supplier; @@ -15,6 +16,6 @@ public void run() { public Source get() { return new Procedural3DImageShort( p -> (int) ((Math.sin(p[0]/20)*Math.sin(p[1]/40)*Math.sin(p[2]/5)+1)*100) - ).getSource("Wave 3D"); + ).getSource(new FinalInterval(new long[]{0,0,0}, new long[]{512,512,512}),"Wave 3D"); } } diff --git a/src/test/src/sc/fiji/bdvpg/bdv/source/display/BrightnessAutoAdjusterDemo.java b/src/test/src/sc/fiji/bdvpg/bdv/source/display/BrightnessAutoAdjusterDemo.java new file mode 100644 index 00000000..ba35d7d9 --- /dev/null +++ b/src/test/src/sc/fiji/bdvpg/bdv/source/display/BrightnessAutoAdjusterDemo.java @@ -0,0 +1,44 @@ +package sc.fiji.bdvpg.bdv.source.display; + +import bdv.util.BdvFunctions; +import bdv.util.BdvHandle; +import bdv.util.BdvOptions; +import bdv.viewer.Source; +import bdv.viewer.SourceAndConverter; +import mpicbg.spim.data.SpimData; +import sc.fiji.bdvpg.bdv.BDVSingleton; +import sc.fiji.bdvpg.bdv.navigate.ViewerTransformAdjuster; +import sc.fiji.bdvpg.bdv.source.append.SourceAdder; +import sc.fiji.bdvpg.source.importer.SourceLoader; +import sc.fiji.bdvpg.source.importer.samples.VoronoiSourceGetter; + +public class BrightnessAutoAdjusterDemo +{ + public static void main( String[] args ) + { + // Mri stack + BdvHandle bdvHandle = BDVSingleton.getInstance(); + + final Source source = getMriSource(); + addSource( bdvHandle, source ); + + // Voronoi + final Source voronoiSource = new VoronoiSourceGetter( new long[]{ 512, 512, 1 }, 256, true ).get(); + addSource( bdvHandle, voronoiSource ); + } + + public static Source getMriSource() + { + final String filePath = "src/test/resources/mri-stack.xml"; + final SourceLoader sourceLoader = new SourceLoader( filePath ); + sourceLoader.run(); + return sourceLoader.getSource( 0 ); + } + + public static void addSource( BdvHandle bdvHandle, Source source ) + { + new SourceAdder( bdvHandle, source ).run(); + new ViewerTransformAdjuster( bdvHandle, source ).run(); + new BrightnessAutoAdjuster( bdvHandle, source ).run(); + } +}