bigdataviewer / bigdataviewer-playground

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

ViewerTransformAdjuster for multiple sources #246

Closed tischi closed 2 years ago

tischi commented 2 years ago

@NicoKiaru

you have there code like this:

        RealInterval maxInterval = intervalList.stream()
                .reduce((i1,i2) -> new FinalRealInterval(
                        new double[]{Math.min(i1.realMin(0), i2.realMin(0)), Math.min(i1.realMin(1), i2.realMin(1)), Math.min(i1.realMin(2), i2.realMin(2))},
                        new double[]{Math.max(i1.realMax(0), i2.realMax(0)), Math.max(i1.realMax(1), i2.realMax(1)), Math.max(i1.realMax(2), i2.realMax(2))}
                        )).get();

Is that maybe rather the union interval?

If so, could one just use the inbuilt Intervals.union for this?

NicoKiaru commented 2 years ago

Ah nice! I didn't know it exists. But is union really union ?

Because [1..3] union [5..7] is not supposed to be [1..7], but [1..3]U[5..7].

I guess it's just a naming problem. With Intervals we always get bounds and not a 'real' union.

tischi commented 2 years ago

Good point. Javadoc says: "Compute the smallest interval that contains both input intervals."

I have a TransformHelpers class with such code:

public static RealInterval unionRealInterval( List< ? extends Source< ? > > sources )
    {
        RealInterval union = null;

        for ( Source< ? > source : sources )
        {
            final FinalRealInterval bounds = estimateBounds( source );

            if ( union == null )
                union = bounds; // init with first source
            else
                union = Intervals.union( bounds, union );
        }

        return union;
    }

public static FinalRealInterval estimateBounds( Source< ? > source )
    {
        final AffineTransform3D affineTransform3D = new AffineTransform3D();
        source.getSourceTransform( 0, 0, affineTransform3D );
        final FinalRealInterval bounds = affineTransform3D.estimateBounds( source.getSource( 0, 0 ) );
        return bounds;
    }

What do you think?

NicoKiaru commented 2 years ago

Looks good! I would add a timepoint parameter though

NicoKiaru commented 2 years ago

Done in https://github.com/bigdataviewer/bigdataviewer-playground/commit/b701f4a104434c2ba63090b38da1936bfa2a6f9c. I still need to reduce since union takes only two arguments.