Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projection mode changer #73

Merged
merged 12 commits into from
Jan 21, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.numeric.ARGBType;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterService;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.concurrent.ExecutorService;

import static sc.fiji.bdvpg.bdv.projector.Projection.PROJECTION_MODE;
import static sc.fiji.bdvpg.bdv.projector.Projection.PROJECTION_MODE_SUM;

public class AccumulateMixedProjectorARGB extends AccumulateProjector< ARGBType, ARGBType >
{
public static AccumulateProjectorFactory< ARGBType > factory = new AccumulateProjectorFactory< ARGBType >()
Expand All @@ -41,7 +42,7 @@ public AccumulateMixedProjectorARGB createAccumulateProjector(
}
};

private final ArrayList< Source< ? > > sourceList;
private final String[] projectionModes;

public AccumulateMixedProjectorARGB(
final ArrayList< VolatileProjector > sourceProjectors,
Expand All @@ -52,7 +53,7 @@ public AccumulateMixedProjectorARGB(
final ExecutorService executorService )
{
super( sourceProjectors, sourceScreenImages, target, numThreads, executorService );
this.sourceList = sources;
projectionModes = getProjectionModes( sources );
}

@Override
Expand All @@ -65,8 +66,6 @@ protected void accumulate(

int sourceIndex = 0;

final Map< SourceAndConverter, Map< String, Object > > sourceAndConverterToMetadata = BdvService.getSourceAndConverterService().getSourceAndConverterToMetadata();

for ( final Cursor< ? extends ARGBType > access : accesses )
{
final int value = access.get().get();
Expand All @@ -80,16 +79,14 @@ protected void accumulate(
continue;
}

String projectionMode = getProjectionMode( sourceIndex, sourceAndConverterToMetadata );

if ( projectionMode.equals( "Sum" ) )
if ( projectionModes[sourceIndex].equals( Projection.PROJECTION_MODE_SUM ) )
NicoKiaru marked this conversation as resolved.
Show resolved Hide resolved
{
aAccu += a;
rAccu += r;
gAccu += g;
bAccu += b;
}
else if ( projectionMode.equals( "Avg" ))
else if ( projectionModes[sourceIndex].equals( Projection.PROJECTION_MODE_AVG ))
NicoKiaru marked this conversation as resolved.
Show resolved Hide resolved
{
aAvg += a;
rAvg += r;
Expand Down Expand Up @@ -127,26 +124,38 @@ else if ( projectionMode.equals( "Avg" ))

}

private String getProjectionMode( int sourceIndex, Map< SourceAndConverter, Map< String, Object > > sourceAndConverterToMetadata )
private String[] getProjectionModes( ArrayList< Source< ? > > sources )
{
Source< ? > source = sourceList.get( sourceIndex );
if ( source instanceof TransformedSource )
source = (( TransformedSource )source).getWrappedSource();
final List< SourceAndConverter > sacs = SourceAndConverterServices.getSourceAndConverterService().getSourceAndConverters();
final String[] projectionModes = new String[ sources.size() ];

String projectionMode = "Sum";
int sourceIndex = 0;

for ( SourceAndConverter sac : sourceAndConverterToMetadata.keySet() )
for ( Source<?> source : sources )
{
if ( sac.getSpimSource().equals( source ) )
{
final Set< String > metadata = sourceAndConverterToMetadata.get( sac ).keySet();
if ( metadata.contains( "ProjectionMode" ) )
{
projectionMode = (String) sourceAndConverterToMetadata.get( sac ).get( "ProjectionMode" );
}
}
if ( source instanceof TransformedSource )
tischi marked this conversation as resolved.
Show resolved Hide resolved
source = ( ( TransformedSource ) source ).getWrappedSource();

SourceAndConverter sac = SourceAndConverterServices.getSourceAndConverterService().getSourceAndConverterFromSource( source );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could fail because a Source can have different converters and thus exists in different flavors. One Source -> 2 SourceAndConverters, one with a gray LUT and one with a completely different LUT, for instance.

We have to think about that, but that's a major issue. I had to deal with this in the remove(SourceAndConverter, BdvHandle) function from the display service, you should have a look at it and then let's rediscuss this. Maybe there's no better way...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! See conversations below.


final String projectionMode = (String) SourceAndConverterServices.getSourceAndConverterService().getMetadata( sac, PROJECTION_MODE );
NicoKiaru marked this conversation as resolved.
Show resolved Hide resolved

if ( projectionMode == null )
projectionModes[sourceIndex++] = PROJECTION_MODE_SUM;
else
projectionModes[sourceIndex++] = projectionMode;

}
return projectionMode;

return projectionModes;
}

private SourceAndConverter getSourceAndConverter( List< SourceAndConverter > sacs, Source< ? > source )
{
for ( SourceAndConverter sac : sacs )
if ( sac.getSpimSource().equals( source ) )
return sac;

return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package sc.fiji.bdvpg.bdv.projector;

public class ProjectionTypes
public class Projection
{
public static final String PROJECTION_MODE = "Projection Mode";
public static final String PROJECTION_MODE_SUM = "Sum";
public static final String PROJECTION_MODE_AVG = "Avg";

public static final String MIXED_PROJECTOR = "Mixed Projector";
public static final String SUM_PROJECTOR = "Sum Projector";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cf comment above, maybe change this to int to fasten the computation

Copy link
Collaborator Author

@tischi tischi Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I could do this, but long term I think an enum would be the cleanest.
The only reason I was choosing String constants was because this is the only thing that works in Command choices. Thus, using ints not would make it more complicated because we have to implement the constants twice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll investigate the performance and report back

public static final String AVERAGE_PROJECTOR = "Average Projector";

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bdv.util.BdvHandle;
import bdv.viewer.SourceAndConverter;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;

import java.util.function.Consumer;

Expand All @@ -22,6 +22,6 @@ public void run() {

@Override
public void accept(SourceAndConverter source) {
BdvService.getSourceAndConverterDisplayService().show(bdvh, source);
SourceAndConverterServices.getSourceAndConverterDisplayService().show(bdvh, source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bdv.util.BdvHandle;
import bdv.viewer.SourceAndConverter;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;

import java.util.function.Consumer;

Expand Down Expand Up @@ -34,10 +34,10 @@ public void run() {
public void accept(SourceAndConverter source) {
if (bdvh==null) {
// Remove from all displays
BdvService.getSourceAndConverterDisplayService().removeFromAllBdvs(source);
SourceAndConverterServices.getSourceAndConverterDisplayService().removeFromAllBdvs(source);
} else {
// Remove from a specific bdvHandle
BdvService.getSourceAndConverterDisplayService().remove(bdvh, source);
SourceAndConverterServices.getSourceAndConverterDisplayService().remove(bdvh, source);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/sc/fiji/bdvpg/scijava/BdvHandleHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import bdv.util.BdvHandle;
import org.scijava.cache.CacheService;
import org.scijava.object.ObjectService;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterDisplayService;
import sc.fiji.bdvpg.scijava.services.SourceAndConverterBdvDisplayService;

import javax.swing.*;
import java.awt.event.WindowAdapter;
Expand All @@ -13,7 +13,7 @@

public class BdvHandleHelper {

public static void setBdvHandleCloseOperation(BdvHandle bdvh, CacheService cs, BdvSourceAndConverterDisplayService bdvsds, boolean putWindowOnTop) {
public static void setBdvHandleCloseOperation( BdvHandle bdvh, CacheService cs, SourceAndConverterBdvDisplayService bdvsds, boolean putWindowOnTop) {
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(bdvh.getViewerPanel());

topFrame.addWindowListener(new WindowAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.bdv.navigate.ViewerTransformAdjuster;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterDisplayService;
import sc.fiji.bdvpg.scijava.services.SourceAndConverterBdvDisplayService;
import sc.fiji.bdvpg.sourceandconverter.display.BrightnessAutoAdjuster;

@Plugin(type = Command.class, menuPath = ScijavaBdvDefaults.RootMenu+"Bdv>Show Sources")
Expand All @@ -20,7 +20,7 @@ public class BdvSourcesAdderCommand implements Command {
SourceAndConverter[] sacs;

@Parameter
BdvSourceAndConverterDisplayService bsds;
SourceAndConverterBdvDisplayService bsds;

@Parameter
boolean autoContrast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.bdv.navigate.ViewerTransformAdjuster;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterDisplayService;
import sc.fiji.bdvpg.sourceandconverter.display.BrightnessAutoAdjuster;
import sc.fiji.bdvpg.scijava.services.SourceAndConverterBdvDisplayService;

@Plugin(type = Command.class, menuPath = ScijavaBdvDefaults.RootMenu+"Bdv>Remove Sources From Bdv")
public class BdvSourcesRemoverCommand implements Command {
Expand All @@ -20,7 +18,7 @@ public class BdvSourcesRemoverCommand implements Command {
SourceAndConverter[] srcs_in;

@Parameter
BdvSourceAndConverterDisplayService bsds;
SourceAndConverterBdvDisplayService bsds;

@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sc.fiji.bdvpg.bdv.BdvCreator;
import sc.fiji.bdvpg.bdv.projector.AccumulateAverageProjectorARGB;
import sc.fiji.bdvpg.bdv.projector.AccumulateMixedProjectorARGB;
import sc.fiji.bdvpg.bdv.projector.ProjectionTypes;
import sc.fiji.bdvpg.bdv.projector.Projection;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;

@Plugin(type = Command.class, menuPath = ScijavaBdvDefaults.RootMenu+"Bdv>Create Empty BDV Frame",
Expand All @@ -30,7 +30,7 @@ public class BdvWindowCreatorCommand implements Command {
@Parameter(type = ItemIO.OUTPUT)
public BdvHandle bdvh;

@Parameter(choices = { ProjectionTypes.MIXED_PROJECTOR, ProjectionTypes.SUM_PROJECTOR, ProjectionTypes.AVERAGE_PROJECTOR})
@Parameter(choices = { Projection.MIXED_PROJECTOR, Projection.SUM_PROJECTOR, Projection.AVERAGE_PROJECTOR})
public String projector;

@Override
Expand All @@ -40,12 +40,12 @@ public void run() {
if (is2D) opts = opts.is2D();

switch (projector) {
case ProjectionTypes.MIXED_PROJECTOR:
case Projection.MIXED_PROJECTOR:
opts = opts.accumulateProjectorFactory(AccumulateMixedProjectorARGB.factory);
case ProjectionTypes.SUM_PROJECTOR:
case Projection.SUM_PROJECTOR:
// Default projector
break;
case ProjectionTypes.AVERAGE_PROJECTOR:
case Projection.AVERAGE_PROJECTOR:
opts = opts.accumulateProjectorFactory(AccumulateAverageProjectorARGB.factory);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sc.fiji.bdvpg.bdv.navigate.ViewerTransformSyncStopper;
import sc.fiji.bdvpg.scijava.BdvHandleHelper;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class ViewSynchronizerCommand implements Command {
public void run() {
// Starting synchronnization of selected bdvhandles
sync = new ViewerTransformSyncStarter(bdvhs);
sync.setBdvHandleInitialReference(BdvService.getSourceAndConverterDisplayService().getActiveBdv());
sync.setBdvHandleInitialReference( SourceAndConverterServices.getSourceAndConverterDisplayService().getActiveBdv());
sync.run();

// JFrame serving the purpose of stopping synchronization when it is being closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterDisplayService;
import sc.fiji.bdvpg.scijava.services.SourceAndConverterBdvDisplayService;
import sc.fiji.bdvpg.sourceandconverter.register.BigWarpLauncher;

import java.util.Arrays;
Expand All @@ -35,7 +35,7 @@ public class BigWarpLauncherCommand implements Command {
BdvHandle bdvhP;

@Parameter
BdvSourceAndConverterDisplayService bsds;
SourceAndConverterBdvDisplayService bsds;

public void run() {
List<SourceAndConverter> movingSacs = Arrays.stream(movingSources).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;
import sc.fiji.bdvpg.sourceandconverter.display.BrightnessAdjuster;

import java.text.DecimalFormat;
Expand Down Expand Up @@ -66,8 +66,8 @@ public void updateMessage() {

public void init() {
if (sources.length>0) {
double minSource = BdvService.getSourceAndConverterDisplayService().getConverterSetup(sources[0]).getDisplayRangeMin();
double maxSource = BdvService.getSourceAndConverterDisplayService().getConverterSetup(sources[0]).getDisplayRangeMax();
double minSource = SourceAndConverterServices.getSourceAndConverterDisplayService().getConverterSetup(sources[0]).getDisplayRangeMin();
double maxSource = SourceAndConverterServices.getSourceAndConverterDisplayService().getConverterSetup(sources[0]).getDisplayRangeMax();

if (minSource>=0) {
min = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
package sc.fiji.bdvpg.scijava.command.source;

import bdv.viewer.SourceAndConverter;
import net.imagej.display.ColorTables;
import net.imagej.lut.LUTService;
import net.imglib2.converter.Converter;
import net.imglib2.display.ColorConverter;
import net.imglib2.display.ColorTable;
import net.imglib2.type.numeric.ARGBType;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.command.DynamicCommand;
import org.scijava.convert.ConvertService;
import org.scijava.module.MutableModuleItem;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.util.ColorRGB;
import org.scijava.util.ColorRGBA;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterDisplayService;
import sc.fiji.bdvpg.sourceandconverter.SourceAndConverterUtils;
import sc.fiji.bdvpg.sourceandconverter.display.ConverterChanger;

import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;

@Plugin(type = Command.class, menuPath = ScijavaBdvDefaults.RootMenu+"Sources>Create New Source (Set Color)")
public class ColorSourceCreatorCommand implements Command {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import net.imagej.lut.LUTService;
import net.imglib2.converter.Converter;
import net.imglib2.display.ColorTable;
import org.scijava.ItemIO;
import org.scijava.command.Command;
import org.scijava.command.DynamicCommand;
import org.scijava.convert.ConvertService;
import org.scijava.module.MutableModuleItem;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import sc.fiji.bdvpg.scijava.ScijavaBdvDefaults;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterDisplayService;
import sc.fiji.bdvpg.sourceandconverter.display.ConverterChanger;

import java.net.URL;
Expand Down
Loading