-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implement SourceChanger?! #224
Comments
I played with it and it is working. Here is an improved version of the class: public class SourceChanger< T > implements Function< SourceAndConverter< ? >, SourceAndConverter< ? > >
{
private final Function< Source< ? >, Source< ? > > sourceConverter;
public SourceChanger( Function< Source< ? >, Source< ? > > sourceConverter )
{
this.sourceConverter = sourceConverter;
}
@Override
public SourceAndConverter< ? > apply( SourceAndConverter< ? > inputSourceAndConverter )
{
Source< ? > outputSource = sourceConverter.apply( inputSourceAndConverter.getSpimSource() );
if ( inputSourceAndConverter.asVolatile() != null )
{
final Source< ? > volatileOutputSource = sourceConverter.apply( inputSourceAndConverter.asVolatile().getSpimSource() );
final SourceAndConverter< ? > volatileOutputSourceAndConverter = new SourceAndConverter( volatileOutputSource, inputSourceAndConverter.asVolatile().getConverter() );
final SourceAndConverter< ? > outputSourceAndConverter = new SourceAndConverter( outputSource, inputSourceAndConverter.getConverter(), volatileOutputSourceAndConverter );
return outputSourceAndConverter;
}
else
{
return new SourceAndConverter( outputSource, inputSourceAndConverter.getConverter() );
}
}
} One can use this now even with a lambda, for example like this: final SourceAndConverter< T > croppedSourceAndConverter = new SourceChanger( ( Function< Source< ? >, Source< ? > > ) source -> new CroppedSource( source, "someName", new FinalRealInterval( min, max ), shiftToOrigin ) ).apply( sourceAndConverter ); That means one only has to implement the class the converts the source and the rest can be done by the |
Looks good! Do you think it's better as an action or it could fit as a static function in sourceandconverter helper. Also : regarding the converter, I uses the clone converter function instead of reusing the same converter. Do you have a good reason not to clone it ? Should we make this optional (clone or reuse?) |
I think it should be a class, because otherwise we cannot implement the
Yes, should be optional, one needs both I think. I can amend the code to enable cloning. |
go for it, with optional converter cloning ! 👍 |
But in which package should I put it? |
Here https://github.com/bigdataviewer/bigdataviewer-playground/tree/master/src/main/java/sc/fiji/bdvpg ? Within a new source package ? |
I'll be on holidays from tomorrow for one week 🌴 ⛰️ |
@NicoKiaru
Do you think this could be useful? If it works I think it could avoid quite some code duplication:
The
Function< Source< ? >, Source< ? > > sourceConverter
would for example return aTransformedSource
or aWarpedSource
, given an inputSource
.For this one needs to create a
SourceTransformer implements Function< Source< ? >, Source< ? > >
and aSourceWarper implements Function< Source< ? >, Source< ? > >
. But we needed this anyway (see e.g.SourceResampler
). The advantage would be that with above code theSourceResampler
does not need to deal with the generic is of creating also the Volatile versions.The text was updated successfully, but these errors were encountered: