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
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ In this repository, we collect useful additions for the [BigDataViewer](https://
## List of actions
* Read a source from disc
* Add a source to a BDV
* [Log the current mouse position](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdv/navigate/LogMousePositionDemo.java#L33)
* [Log the current viewer transform](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdv/navigate/ViewTransformSetAndLogDemo.java#L35)
* [Change the current viewer transform](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdv/navigate/ViewTransformSetAndLogDemo.java#L37-L40)
* [Take a screenshot](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdv/screenshot/ScreenshotDemo.java)
* [Log the current mouse position](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdvh/navigate/LogMousePositionDemo.java#L33)
* [Log the current viewer transform](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdvh/navigate/ViewTransformSetAndLogDemo.java#L35)
* [Change the current viewer transform](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdvh/navigate/ViewTransformSetAndLogDemo.java#L37-L40)
* [Take a screenshot](https://github.com/haesleinhuepf/bigdataviewer-playground/blob/master/src/test/src/sc/fiji/bdvh/screenshot/ScreenshotDemo.java)

## Wishlist of actions
Here we document actions we would like to have. If you know similar functionality in other repositories, feel free to contribute it here or send us a link where we can adopt code! Thanks :-)
Expand All @@ -19,7 +19,7 @@ Here we document actions we would like to have. If you know similar functionalit
## Coding guides
We tried to follow these general guide lines:
* Specific (atomic) functionality lives in a class implementing [Runnable](https://docs.oracle.com/javase/7/docs/api/java/lang/Runnable.html)
* The constructor takes a [BdvHandle](https://github.com/bigdataviewer/bigdataviewer-vistools/blob/master/src/main/java/bdv/util/BdvHandle.java) as parameter.
* The constructor takes a [BdvHandle](https://github.com/bigdataviewer/bigdataviewer-vistools/blob/master/src/main/java/bdvh/util/BdvHandle.java) as parameter.
* More mandatory parameters for the functionality are handed over as additional constructor parameters.
* Optional parameters are set with setter methods.
* The `run()` method executes the concreate action.
Expand All @@ -35,7 +35,7 @@ Pseudo code example:
}
```

* Furthermore, [Demo code](https://github.com/haesleinhuepf/bigdataviewer-playground/tree/master/src/test/src/sc/fiji/bdv) in the test sources directory should demonstrate
* Furthermore, [Demo code](https://github.com/haesleinhuepf/bigdataviewer-playground/tree/master/src/test/src/sc/fiji/bdvh) in the test sources directory should demonstrate
* the individual functionality,
* how to add it as key listeners to the BigDataViewer,
* how to add it to the right-click menu of the BigDataViewer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.ui.TransformListener;
import org.scijava.vecmath.Point3d;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;
import sc.fiji.bdvpg.sourceandconverter.transform.SourceAffineTransformer;

import java.util.ArrayList;
Expand Down Expand Up @@ -77,17 +77,17 @@ public void run() {
for (int i=0;i<sacs.length;i++) {

// Wraps into a Transformed Source, if the source was displayed originally
if (BdvService.getSourceAndConverterDisplayService().getDisplaysOf(sacs[i]).contains(bdvHandle)) {
if (SourceAndConverterServices.getSourceAndConverterDisplayService().getDisplaysOf(sacs[i]).contains(bdvHandle)) {
displayedSacsWrapped.add(new SourceAffineTransformer(sacs[i], new AffineTransform3D()).getSourceOut());
originallyDisplayedSacs.add(sacs[i]);
}
}

// Remove from display the originally dispalyed sources
BdvService.getSourceAndConverterDisplayService().remove(bdvHandle, originallyDisplayedSacs.toArray(new SourceAndConverter[originallyDisplayedSacs.size()]));
SourceAndConverterServices.getSourceAndConverterDisplayService().remove(bdvHandle, originallyDisplayedSacs.toArray(new SourceAndConverter[originallyDisplayedSacs.size()]));

// Shows the displayed wrapped Source
BdvService.getSourceAndConverterDisplayService().show(bdvHandle, displayedSacsWrapped.toArray(new SourceAndConverter[displayedSacsWrapped.size()]));
SourceAndConverterServices.getSourceAndConverterDisplayService().show(bdvHandle, displayedSacsWrapped.toArray(new SourceAndConverter[displayedSacsWrapped.size()]));

// View of the BdvHandle before starting the registration
AffineTransform3D originalViewTransform = new AffineTransform3D();
Expand Down
47 changes: 24 additions & 23 deletions src/main/java/sc/fiji/bdvpg/bdv/ManualRegistrationStopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
import mpicbg.spim.data.registration.ViewTransform;
import mpicbg.spim.data.registration.ViewTransformAffine;
import net.imglib2.realtransform.AffineTransform3D;
import sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterService;
import sc.fiji.bdvpg.services.BdvService;
import sc.fiji.bdvpg.scijava.services.SourceAndConverterBdvDisplayService;
import sc.fiji.bdvpg.scijava.services.SourceAndConverterService;
import sc.fiji.bdvpg.services.SourceAndConverterServices;
import sc.fiji.bdvpg.sourceandconverter.transform.SourceAffineTransformer;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;

import static sc.fiji.bdvpg.scijava.services.BdvSourceAndConverterService.SPIM_DATA_INFO;
import static sc.fiji.bdvpg.scijava.services.SourceAndConverterService.SPIM_DATA_INFO;

// TODO : Ensure volatile is working with source which are not AbstractSpimSource

Expand Down Expand Up @@ -95,19 +96,19 @@ public static SourceAndConverter mutateTransformedSourceAndConverter(AffineTrans
* @return
*/
public static SourceAndConverter mutateLastSpimdataTransformation(AffineTransform3D affineTransform3D, SourceAndConverter sac) {
assert BdvService
assert SourceAndConverterServices
.getSourceAndConverterService()
.getSourceAndConverterToMetadata().get(sac).containsKey(SPIM_DATA_INFO);
assert BdvService
.getSacToMetadata().get(sac).containsKey(SPIM_DATA_INFO);
assert SourceAndConverterServices
.getSourceAndConverterService()
.getSourceAndConverterToMetadata().get(sac).get(SPIM_DATA_INFO) instanceof BdvSourceAndConverterService.SpimDataInfo;
.getSacToMetadata().get(sac).get(SPIM_DATA_INFO) instanceof SourceAndConverterService.SpimDataInfo;

BdvSourceAndConverterService.SpimDataInfo sdi = ((BdvSourceAndConverterService.SpimDataInfo)
BdvService.getSourceAndConverterService()
.getSourceAndConverterToMetadata().get(sac).get(SPIM_DATA_INFO));
SourceAndConverterService.SpimDataInfo sdi = ((SourceAndConverterService.SpimDataInfo)
SourceAndConverterServices.getSourceAndConverterService()
.getSacToMetadata().get(sac).get(SPIM_DATA_INFO));

// TODO : find a way to pass the ref of starter into this function ? but static looks great...
BdvHandle bdvHandle = BdvService.getSourceAndConverterDisplayService().getActiveBdv();
BdvHandle bdvHandle = SourceAndConverterServices.getSourceAndConverterDisplayService().getActiveBdv();

int timePoint = bdvHandle.getViewerPanel().getState().getCurrentTimepoint();

Expand Down Expand Up @@ -153,19 +154,19 @@ public static SourceAndConverter mutateLastSpimdataTransformation(AffineTransfor
* @return
*/
public static SourceAndConverter appendNewSpimdataTransformation(AffineTransform3D affineTransform3D, SourceAndConverter sac) {
assert BdvService
assert SourceAndConverterServices
.getSourceAndConverterService()
.getSourceAndConverterToMetadata().get(sac).containsKey(SPIM_DATA_INFO);
assert BdvService
.getSacToMetadata().get(sac).containsKey(SPIM_DATA_INFO);
assert SourceAndConverterServices
.getSourceAndConverterService()
.getSourceAndConverterToMetadata().get(sac).get(SPIM_DATA_INFO) instanceof BdvSourceAndConverterService.SpimDataInfo;
.getSacToMetadata().get(sac).get(SPIM_DATA_INFO) instanceof SourceAndConverterService.SpimDataInfo;

BdvSourceAndConverterService.SpimDataInfo sdi = ((BdvSourceAndConverterService.SpimDataInfo)
BdvService.getSourceAndConverterService()
.getSourceAndConverterToMetadata().get(sac).get(SPIM_DATA_INFO));
SourceAndConverterService.SpimDataInfo sdi = ((SourceAndConverterService.SpimDataInfo)
SourceAndConverterServices.getSourceAndConverterService()
.getSacToMetadata().get(sac).get(SPIM_DATA_INFO));

// TODO : find a ref to starter
BdvHandle bdvHandle = BdvService.getSourceAndConverterDisplayService().getActiveBdv();
// TODO : find a way to pass the ref of starter into this function ? but static looks great...
BdvHandle bdvHandle = SourceAndConverterServices.getSourceAndConverterDisplayService().getActiveBdv();

int timePoint = bdvHandle.getViewerPanel().getState().getCurrentTimepoint();

Expand Down Expand Up @@ -253,10 +254,10 @@ public void run() {

// Removes temporary TransformedSourceAndConverter - in two times for performance issue
List<SourceAndConverter> tempSacs = starter.getTransformedSourceAndConverterDisplayed();
BdvService.getSourceAndConverterDisplayService().remove(starter.bdvHandle,tempSacs.toArray(new SourceAndConverter[tempSacs.size()]));
SourceAndConverterServices.getSourceAndConverterDisplayService().remove(starter.bdvHandle,tempSacs.toArray(new SourceAndConverter[tempSacs.size()]));

for (SourceAndConverter sac: tempSacs) {
BdvService.getSourceAndConverterService().remove(sac);
SourceAndConverterServices.getSourceAndConverterService().remove(sac);
}

int nSources = starter.getOriginalSourceAndConverter().length;
Expand All @@ -273,7 +274,7 @@ public void run() {
}

// Calls display ( array for performance issue )
BdvService.getSourceAndConverterDisplayService().show(starter.getBdvHandle(),
SourceAndConverterServices.getSourceAndConverterDisplayService().show(starter.getBdvHandle(),
transformedSacsToDisplay.toArray(new SourceAndConverter[transformedSacsToDisplay.size()]));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ protected void accumulate(
int aAvg = 0, rAvg = 0, gAvg = 0, bAvg = 0, n = 0;
int aAccu = 0, rAccu = 0, gAccu = 0, bAccu = 0;

int sourceIndex = 0;

for ( final Cursor< ? extends ARGBType > access : accesses )
{
final int value = access.get().get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sc.fiji.bdvpg.bdv.projector;

import bdv.tools.transformation.TransformedSource;
import bdv.util.BdvHandle;
import bdv.viewer.Source;
import bdv.viewer.SourceAndConverter;
import bdv.viewer.render.AccumulateProjector;
Expand All @@ -10,39 +10,23 @@
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.numeric.ARGBType;
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.Arrays;
import java.util.Collections;
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 >()
{
@Override
public AccumulateMixedProjectorARGB createAccumulateProjector(
final ArrayList< VolatileProjector > sourceProjectors,
final ArrayList< Source< ? > > sources,
final ArrayList< ? extends RandomAccessible< ? extends ARGBType > > sourceScreenImages,
final RandomAccessibleInterval< ARGBType > targetScreenImage,
final int numThreads,
final ExecutorService executorService )
{
return new AccumulateMixedProjectorARGB(
sourceProjectors,
sources,
sourceScreenImages,
targetScreenImage,
numThreads,
executorService );
}
};

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

public AccumulateMixedProjectorARGB(
BdvHandle bdvHandle,
final ArrayList< VolatileProjector > sourceProjectors,
final ArrayList< Source< ? > > sources,
final ArrayList< ? extends RandomAccessible< ? extends ARGBType > > sourceScreenImages,
Expand All @@ -51,7 +35,7 @@ public AccumulateMixedProjectorARGB(
final ExecutorService executorService )
{
super( sourceProjectors, sourceScreenImages, target, numThreads, executorService );
this.sourceList = sources;
this.projectionModes = getProjectionModes( bdvHandle, sources );
}

@Override
Expand All @@ -64,8 +48,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 @@ -79,16 +61,14 @@ protected void accumulate(
continue;
}

String projectionMode = getProjectionMode( sourceIndex, sourceAndConverterToMetadata );

if ( projectionMode.equals( Projection.PROJECTION_MODE_SUM ) )
if ( projectionModes[sourceIndex] == ( Projection.PROJECTION_MODE_SUM ) )
{
aAccu += a;
rAccu += r;
gAccu += g;
bAccu += b;
}
else if ( projectionMode.equals( Projection.PROJECTION_MODE_AVG ))
else if ( projectionModes[sourceIndex] == ( Projection.PROJECTION_MODE_AVG ))
{
aAvg += a;
rAvg += r;
Expand Down Expand Up @@ -126,26 +106,44 @@ else if ( projectionMode.equals( Projection.PROJECTION_MODE_AVG ))

}

private String getProjectionMode( int sourceIndex, Map< SourceAndConverter, Map< String, Object > > sourceAndConverterToMetadata )
private String[] getProjectionModes( BdvHandle bdvHandle, ArrayList< Source< ? > > sources )
{
Source< ? > source = sourceList.get( sourceIndex );
if ( source instanceof TransformedSource )
source = (( TransformedSource )source).getWrappedSource();
// We need to reconstitute the sequence of action that lead to the current indexes

// Getting the sources present in the BdvHandle
List<SourceAndConverter> sacsInBdvHandle = SourceAndConverterServices
.getSourceAndConverterDisplayService()
.getSourceAndConverterOf(bdvHandle);

// Fetching the indexes of visible sources in the BdvHandle
List<Integer> visibleIndexes = bdvHandle.getViewerPanel().getState().getVisibleSourceIndices();
// In ascending order
Collections.sort(visibleIndexes);

SourceAndConverter[] sacArray = new SourceAndConverter[visibleIndexes.size()];

String projectionMode = "Sum";
for (int idx = 0; idx<visibleIndexes.size(); idx++) {
sacArray[idx] = sacsInBdvHandle.get(visibleIndexes.get(idx));
}

final List< SourceAndConverter > sacs = Arrays.asList(sacArray);//SourceAndConverterServices.getSourceAndConverterService().getSourceAndConverters();
final String[] projectionModes = new String[ sources.size() ];

for ( SourceAndConverter sac : sourceAndConverterToMetadata.keySet() )
int sourceIndex = 0;

for ( SourceAndConverter<?> sac : sacs )
{
if ( sac.getSpimSource().equals( source ) )
{
final Set< String > metadata = sourceAndConverterToMetadata.get( sac ).keySet();
if ( metadata.contains( Projection.PROJECTION_MODE ) )
{
projectionMode = (String) sourceAndConverterToMetadata.get( sac ).get( Projection.PROJECTION_MODE );
}
}

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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package sc.fiji.bdvpg.bdv.projector;

import bdv.util.Bdv;
import bdv.util.BdvHandle;
import bdv.viewer.Source;
import bdv.viewer.render.AccumulateProjectorFactory;
import bdv.viewer.render.VolatileProjector;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.numeric.ARGBType;

import java.util.ArrayList;
import java.util.concurrent.ExecutorService;

public class AccumulateMixedProjectorARGBFactory implements AccumulateProjectorFactory< ARGBType >
{
private BdvHandle bdvHandle;

public AccumulateMixedProjectorARGBFactory()
{
}

public void setBdvHandle( BdvHandle bdvHandle )
{
this.bdvHandle = bdvHandle;
}

@Override
public VolatileProjector createAccumulateProjector(
ArrayList< VolatileProjector > sourceProjectors,
ArrayList< Source< ? > > sources,
ArrayList< ? extends RandomAccessible< ? extends ARGBType > > sourceScreenImages,
RandomAccessibleInterval< ARGBType > targetScreenImage,
int numThreads,
ExecutorService executorService )
{
return new AccumulateMixedProjectorARGB(
bdvHandle,
sourceProjectors,
sources,
sourceScreenImages,
targetScreenImage,
numThreads,
executorService );
}
}
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);
}
}
Loading