bigdataviewer / bigdataviewer-playground

BSD 2-Clause "Simplified" License
19 stars 5 forks source link

Add SourceAndConverter to Bdv #29

Closed tischi closed 4 years ago

tischi commented 4 years ago

@NicoKiaru

Wow.....

https://github.com/haesleinhuepf/bigdataviewer-playground/blob/cdcad0549f9284b2e76f2f86fdd385e4116c5dac/src/main/java/sc/fiji/bdv/sourceAndConverter/add/AddSourceAndConverterToBdv.java#L22

I did not know this function existed for a SourceAndConverter!

  1. What is the difference to BdvFunctions.show( ... , BdvOptions.options.addTo( ... ) )
  2. Does it also add the DisplaySettings for this Source to the Bdv UI?
NicoKiaru commented 4 years ago

Not available in BdvFunctions but in ViewerPanel, yes. So, it's accessible from BdvHandle. That's want I wanted to tell you but I wasn't clear enough when I told you to use SourceAndConverter instead of Source

That's the trick, this function allows to add a SourceAndConverter:

NicoKiaru commented 4 years ago

But wait for it : here's the magic of Functional interface:

NicoKiaru commented 4 years ago

Let's say you want to affine transform a SourceAndConverter: This means you need to apply an affineTransform on both the concrete and Volatile source, if present. So one way is to create an affinetransform action for SourceAndConverter.

Then if you want to warp a Source, it's the same, you write an action for Source objects but also for SourceAndConverterobjects.

Then if you have an action which applies a Gaussian Blur it's the same.

At the end you have many duplicated Actions, where you do the same things.

But ahah! All these actions on sources (affine, warp, gaussian, whatever) all implement Function<Source,Source> so what you need to do is just to call an action which will take any of these functions and apply it on a SourceAndConverter object.

And it's already done: look at:

https://github.com/haesleinhuepf/bigdataviewer-playground/blob/cdcad0549f9284b2e76f2f86fdd385e4116c5dac/src/main/java/sc/fiji/bdv/sourceAndConverter/SourceAndConverterApplySourceFunction.java

So -> no duplicated code. Write once for Source, and apply it easily on SourceAndConverter.

tischi commented 4 years ago

All very cool! I like it :-)

One concern about the naming: SourceAndConverterApplySourceFunction Maybe more correct: ApplySourceFunctionToSourceAndConverter

?

NicoKiaru commented 4 years ago

Indeed, still complex but a bit more understandable

NicoKiaru commented 4 years ago

Or Applier, since class names are supposed to be nouns

tischi commented 4 years ago

Yes!

tischi commented 4 years ago

@NicoKiaru Below are the code changes of the PR where I am adding a SourceAndConverter and getting back a bdvStackSource. We could see whether we could get the same code running without getting the PR to Bdv-Vistools accepted. https://github.com/bigdataviewer/bigdataviewer-vistools/pull/40/commits/e1aa24a4f6c2dda9dd81a04c725f4a60446da96c#

NicoKiaru commented 4 years ago

Not relevant anymore. See PR https://github.com/bigdataviewer/bigdataviewer-playground/pull/53