Search in sources :

Example 51 with Pair

use of net.imglib2.util.Pair in project vcell by virtualcell.

the class ImageStatsForPlotting method computeMean.

/**
 * Computes the mean of each XY slice along the 3rd dimension
 * TODO: Currently assumes only 3 dimensions, must handle time series of z stacks and multiple channels
 * @param data
 * @return Pair containing A) the 3rd dimension index, and B) the mean value of the XY slice
 */
private Pair<double[], double[]> computeMean(RandomAccessibleInterval<T> data, IterableInterval<BitType> mask) {
    double[] indices = new double[(int) data.dimension(2)];
    double[] means = new double[indices.length];
    for (int z = 0; z < indices.length; z++) {
        FinalInterval interval = Intervals.createMinMax(0, 0, z, data.dimension(0) - 1, data.dimension(1) - 1, z);
        double mean = 0.0;
        RandomAccessibleInterval<T> cropped = ops.transform().crop(data, interval);
        if (mask == null) {
            mean = ops.stats().mean(Views.iterable(cropped)).getRealDouble();
        } else {
            Cursor<BitType> maskCursor = mask.localizingCursor();
            RandomAccess<T> dataRA = cropped.randomAccess();
            RealSum sum = new RealSum();
            int size = 0;
            maskCursor.reset();
            while (maskCursor.hasNext()) {
                maskCursor.fwd();
                if (maskCursor.get().get()) {
                    dataRA.setPosition(maskCursor);
                    sum.add(dataRA.get().getRealDouble());
                    size++;
                }
            }
            mean = sum.getSum() / size;
        }
        indices[z] = z;
        means[z] = mean;
    }
    return new ValuePair<double[], double[]>(indices, means);
}
Also used : BitType(net.imglib2.type.logic.BitType) ValuePair(net.imglib2.util.ValuePair) FinalInterval(net.imglib2.FinalInterval) RealSum(net.imglib2.util.RealSum)

Example 52 with Pair

use of net.imglib2.util.Pair in project Shuttle by timusus.

the class BaseDetailFragment method pushDetailController.

void pushDetailController(BaseDetailFragment detailFragment, String tag, View transitionView) {
    List<Pair<View, String>> transitions = new ArrayList<>();
    String transitionName = ViewCompat.getTransitionName(transitionView);
    transitions.add(new Pair<>(transitionView, transitionName));
    transitions.add(new Pair<>(toolbar, "toolbar"));
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        Transition moveTransition = TransitionInflater.from(getContext()).inflateTransition(R.transition.image_transition);
        detailFragment.setSharedElementEnterTransition(moveTransition);
        detailFragment.setSharedElementReturnTransition(moveTransition);
    }
    getNavigationController().pushViewController(detailFragment, tag, transitions);
}
Also used : ArrayList(java.util.ArrayList) Transition(android.transition.Transition) Pair(android.support.v4.util.Pair)

Example 53 with Pair

use of net.imglib2.util.Pair in project Shuttle by timusus.

the class AestheticCoordinatorLayout method onAttachedToWindow.

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    // Find the toolbar and color view used to blend the scroll transition
    if (getChildCount() > 0 && getChildAt(0) instanceof AppBarLayout) {
        appBarLayout = (AppBarLayout) getChildAt(0);
        if (appBarLayout.getChildCount() > 0 && appBarLayout.getChildAt(0) instanceof CollapsingToolbarLayout) {
            collapsingToolbarLayout = (CollapsingToolbarLayout) appBarLayout.getChildAt(0);
            for (int i = 0; i < collapsingToolbarLayout.getChildCount(); i++) {
                if (this.toolbar != null && this.colorView != null) {
                    break;
                }
                View child = collapsingToolbarLayout.getChildAt(i);
                if (child instanceof AestheticToolbar) {
                    this.toolbar = (AestheticToolbar) child;
                } else if (child.getBackground() != null && child.getBackground() instanceof ColorDrawable) {
                    this.colorView = child;
                }
            }
        }
    }
    if (toolbar != null && colorView != null) {
        this.appBarLayout.addOnOffsetChangedListener(this);
        toolbarColorSubscription = Observable.combineLatest(toolbar.colorUpdated(), Aesthetic.get(getContext()).colorIconTitle(toolbar.colorUpdated()), new BiFunction<Integer, ActiveInactiveColors, Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public Pair<Integer, ActiveInactiveColors> apply(Integer integer, ActiveInactiveColors activeInactiveColors) {
                return Pair.create(integer, activeInactiveColors);
            }
        }).compose(Rx.<Pair<Integer, ActiveInactiveColors>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, ActiveInactiveColors>>() {

            @Override
            public void accept(@NonNull Pair<Integer, ActiveInactiveColors> result) {
                toolbarColor = result.first;
                iconTextColors = result.second;
                invalidateColors();
            }
        }, onErrorLogAndRethrow());
    }
    if (collapsingToolbarLayout != null) {
        statusBarColorSubscription = Aesthetic.get(getContext()).colorStatusBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

            @Override
            public void accept(@io.reactivex.annotations.NonNull Integer color) {
                collapsingToolbarLayout.setContentScrimColor(color);
                collapsingToolbarLayout.setStatusBarScrimColor(color);
            }
        }, onErrorLogAndRethrow());
    }
}
Also used : ActionMenuView(android.support.v7.widget.ActionMenuView) ActionMenuItemView(android.support.v7.view.menu.ActionMenuItemView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) Consumer(io.reactivex.functions.Consumer) BiFunction(io.reactivex.functions.BiFunction) NonNull(android.support.annotation.NonNull) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Pair(android.support.v4.util.Pair)

Aggregations

Pair (android.support.v4.util.Pair)39 ArrayList (java.util.ArrayList)18 View (android.view.View)17 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)13 Intent (android.content.Intent)11 Pair (org.apache.commons.math3.util.Pair)11 TextView (android.widget.TextView)8 ImageView (android.widget.ImageView)7 RecyclerView (android.support.v7.widget.RecyclerView)6 NonNull (android.support.annotation.NonNull)4 Transition (android.transition.Transition)4 IOException (java.io.IOException)4 List (java.util.List)4 Bundle (android.os.Bundle)3 Collectors (java.util.stream.Collectors)3 ArrayRealVector (org.apache.commons.math3.linear.ArrayRealVector)3 RealMatrix (org.apache.commons.math3.linear.RealMatrix)3 RealVector (org.apache.commons.math3.linear.RealVector)3 ListView (android.widget.ListView)2 Logger (chat.rocket.android.helper.Logger)2