use of org.apache.commons.math3.util.Pair in project vcell by virtualcell.
the class PlotImageStats method run.
@Override
public void run() {
Plot plot = new ColorPlot("Frame mean intensity", "Time", "Mean intensity");
StringBuilder legendLabels = new StringBuilder();
for (int i = 0; i < datasets.size(); i++) {
RandomAccessibleInterval<T> data = datasets.get(i);
if (data instanceof Dataset) {
legendLabels.append(((Dataset) data).getName());
legendLabels.append(": ");
}
Pair<double[], double[]> xyPair = (Pair<double[], double[]>) ops.run("imageStatsForPlotting", ImageStatsForPlotting.MEAN, data, mask);
plot.addPoints(xyPair.getA(), xyPair.getB(), Plot.LINE);
legendLabels.append("ROI ");
legendLabels.append(i + 1);
legendLabels.append("\n");
}
plot.addLegend(legendLabels.toString());
plot.show();
}
use of org.apache.commons.math3.util.Pair in project vcell by virtualcell.
the class PlotROIStats method run.
@Override
public void run() {
Plot plot = new ColorPlot("ROI Mean Intensity", "Time", "Mean Intensity");
StringBuilder legendLabels = new StringBuilder();
for (RandomAccessibleInterval<T> data : datasetROIsMap.keySet()) {
if (data instanceof Dataset) {
legendLabels.append(((Dataset) data).getName());
legendLabels.append(": ");
}
List<Overlay> overlays = datasetROIsMap.get(data);
for (int i = 0; i < overlays.size(); i++) {
Overlay overlay = overlays.get(i);
RandomAccessibleInterval<T> cropped = crop(data, overlay);
Pair<double[], double[]> xyPair = (Pair<double[], double[]>) ops.run("imageStatsForPlotting", ImageStatsForPlotting.MEAN, cropped);
plot.addPoints(xyPair.getA(), xyPair.getB(), Plot.LINE);
legendLabels.append("ROI ");
legendLabels.append(i + 1);
legendLabels.append("\n");
}
}
plot.addLegend(legendLabels.toString());
plot.show();
}
use of org.apache.commons.math3.util.Pair in project Shuttle by timusus.
the class Aesthetic method resume.
/**
* Should be called in onResume() of each Activity.
*/
public void resume(@NonNull final AppCompatActivity activity) {
if (instance == null) {
return;
}
instance.context = activity;
if (instance.subs != null) {
instance.subs.clear();
}
instance.subs = new CompositeDisposable();
instance.subs.add(instance.colorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
Util.setTaskDescriptionColor(activity, color);
}
}, onErrorLogAndRethrow()));
instance.subs.add(instance.activityTheme().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer themeId) {
if (getLastActivityTheme(activity) == themeId) {
return;
}
instance.lastActivityThemes.put(activity.getClass().getName(), themeId);
activity.recreate();
}
}, onErrorLogAndRethrow()));
instance.subs.add(Observable.combineLatest(instance.colorStatusBar(), instance.lightStatusBarMode(), new BiFunction<Integer, Integer, Pair<Integer, Integer>>() {
@Override
public Pair<Integer, Integer> apply(Integer integer, Integer integer2) {
return Pair.create(integer, integer2);
}
}).compose(Rx.<Pair<Integer, Integer>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, Integer>>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Pair<Integer, Integer> result) {
instance.invalidateStatusBar(activity);
}
}, onErrorLogAndRethrow()));
instance.subs.add(instance.colorNavigationBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
setNavBarColorCompat(activity, color);
}
}, onErrorLogAndRethrow()));
instance.subs.add(instance.colorWindowBackground().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Integer color) {
activity.getWindow().setBackgroundDrawable(new ColorDrawable(color));
}
}, onErrorLogAndRethrow()));
if (MaterialDialogsUtil.shouldSupport()) {
instance.subs.add(MaterialDialogsUtil.observe(instance));
}
}
use of org.apache.commons.math3.util.Pair in project Shuttle by timusus.
the class BitmapPaletteProcessor method processBitmap.
/**
* Processes a builder of a media notification and calculates the appropriate colors that should
* be used.
*
* @param bitmap
*
* returns a {@link Pair} of integers. The first is the background colour, second is foreground colour.
*/
public Pair<Integer, Integer> processBitmap(Bitmap bitmap) {
int backgroundColor = 0;
// we want all colors, red / white / black ones too!;
Palette.Builder paletteBuilder = Palette.from(bitmap).clearFilters();
Palette palette = paletteBuilder.generate();
backgroundColor = findBackgroundColorAndFilter(palette);
if (mFilteredBackgroundHsl != null) {
paletteBuilder.addFilter((rgb, hsl) -> {
// at least 10 degrees hue difference
float diff = Math.abs(hsl[0] - mFilteredBackgroundHsl[0]);
return diff > 10 && diff < 350;
});
}
paletteBuilder.addFilter(mBlackWhiteFilter);
palette = paletteBuilder.generate();
int foregroundColor = selectForegroundColor(backgroundColor, palette);
return new Pair<>(backgroundColor, foregroundColor);
}
use of org.apache.commons.math3.util.Pair in project drools by kiegroup.
the class GroupByTest method testDecomposedGroupByKeyAnd2Accumulates.
@Test
public void testDecomposedGroupByKeyAnd2Accumulates() throws Exception {
// DROOLS-6031
final Global<List> var_results = D.globalOf(List.class, "defaultpkg", "results");
final Variable<Pair<String, String>> var_$key = (Variable) D.declarationOf(Pair.class);
final Variable<Pair> var_$accumulate = D.declarationOf(Pair.class);
final Variable<Person> var_$p = D.declarationOf(Person.class);
final Variable<Person> var_$p2 = D.declarationOf(Person.class);
final Variable<String> var_$subkeyA = D.declarationOf(String.class);
final Variable<String> var_$subkeyB = D.declarationOf(String.class);
final Variable<List> var_$accresult = D.declarationOf(List.class);
final Variable<List> var_$accresult2 = D.declarationOf(List.class);
final Rule rule1 = PatternDSL.rule("R1").build(D.groupBy(// Patterns
D.and(D.pattern(var_$p), D.pattern(var_$p2).bind(var_$accumulate, var_$p, Pair::create)), // Grouping Function
var_$p, var_$key, person -> Pair.create(person.getName().substring(0, 1), person.getName().substring(1, 2)), D.accFunction(CollectListAccumulateFunction::new, var_$accumulate).as(var_$accresult), D.accFunction(CollectListAccumulateFunction::new, var_$accumulate).as(var_$accresult2)), // Bindings
D.pattern(var_$key).bind(var_$subkeyA, Pair::getKey).bind(var_$subkeyB, Pair::getValue), D.pattern(var_$accresult), // Consequence
D.on(var_$subkeyA, var_$subkeyB, var_$accresult, var_results).execute(($a, $b, $accresult, results) -> {
results.add($a);
results.add($b);
results.add($accresult);
}));
final Model model = new ModelImpl().addRule(rule1).addGlobal(var_results);
final KieSession ksession = KieBaseBuilder.createKieBaseFromModel(model).newKieSession();
final List<Object> results = new ArrayList<>();
ksession.setGlobal("results", results);
ksession.insert("A");
ksession.insert("test");
ksession.insert(new Person("Mark", 42));
assertThat(ksession.fireAllRules()).isEqualTo(1);
Assertions.assertThat(results.size()).isEqualTo(3);
Assertions.assertThat(results.get(0)).isEqualTo("M");
Assertions.assertThat(results.get(1)).isEqualTo("a");
}
Aggregations