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

"Stack" RealRandomAccessibles as Composite #318

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

bogovicj
Copy link
Contributor

see #317

@bogovicj
Copy link
Contributor Author

bogovicj commented Aug 15, 2022

I called this a RealStackCompositeView, but don't like that name.
maybe RealListCompositeView?

@bogovicj
Copy link
Contributor Author

I won't keep working on this until there is a more urgent use case but will leave this open in case we'd like to revisit in the future.

This needs a better name for the class, and probably would benefit from a view that does the "inverse" operation, something like:
RealRandomAccessible<T> unstackRealComposite( RealRandomAccessible<Composite<T>> stack, int component )
but also with a better name

@bogovicj
Copy link
Contributor Author

bogovicj commented Sep 21, 2023

I'd like to revist this.

There are at least two specific applications for the code provided by this PR. One I describe below, the other is in paintera - @cmhulbert can point it one if it's of interest.

When I initially started this, I thought it might be useful for building DisplacementFieldTransforms, and I believe they still could be because somehow needs to build a RealRandomAccessible<RealLocalizable> to create a DisplacementFieldTransform.

We left this PR for a year because one (common) way to create the RealRandomAccessible<RealLocalizable> is by collapsing then interpolating. That works because some interpolators (specifically NLinearInterpolators can work on Composites, because Composites are NumericTypes

Other interpolators will not work today, for example:

because they use RealTypes. and even RealComposite types are not RealTypes.

We might choose to make some composite types RealTypes, but that would sacrifice some nice behavior, for example clipping. Clipping requires a min and max value, and there's no ordering of vectors. There are at least three clipping interpolators: Lanczos Bspline and ClampingNLinearInterpolator

A straightfoward solution to interpolate each component of the vector independently, then "stack" them. Given a list of vector componets:

final RealRandomAccessible<T>[] components 

It is possible to do this now with BiConverters, but it's very verbose:

final BiConverter<T, T, RealComposite<DoubleType>> conv0 = new BiConverter<T,T,RealComposite<DoubleType>>()
{
    @Override
    public void convert( T x, T y, RealComposite<DoubleType> output ) {
        output.get(0).set(x.getRealDouble());
        output.get(1).set(y.getRealDouble());
    }
};

final int N = 3;
final RealComposite<DoubleType> v = DoubleType.createVector(N);
final RealRandomAccessible<RealComposite<DoubleType>> img = Converters.convert( components[0], components[1], conv0, v);
RealRandomAccessible<RealComposite<DoubleType>> total = img;
for( int i = 2; i < N; i++ )
{
    final int j = i;
    total = Converters.convert(
            total,
            components[i],
            new BiConverter<RealComposite<DoubleType>,T,RealComposite<DoubleType>>()
            {
                @Override
                public void convert( RealComposite<DoubleType> part, T x, RealComposite<DoubleType> whole ) {

                    for( int d = 0; d < j; d++ )
                        whole.get(d).set(part.get(d));

                    whole.get(j).set(x.getRealDouble());
                }
            },
            v.copy());
}

This PR would

RealRandomAccessible<Composite<T>> total2 = Views.realComposite(components);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant