parent
6e15d25210
commit
d6cd29f2fc
@ -0,0 +1,61 @@
|
||||
package edu.thi.phga.aparapi_test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class Rauschfilter extends javafx.application.Application {
|
||||
private static Rectangle2D bounds = Screen.getPrimary().getBounds();
|
||||
|
||||
private static final int BREITE = (int) (bounds.getWidth() * 0.8);
|
||||
private static final int HOEHE = BREITE * 9 / 16;
|
||||
|
||||
private static final double OMEGA = 8 * Math.PI / BREITE;
|
||||
private static final int FILTERLAENGE = 15;
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
float[] noisy = new float[BREITE];
|
||||
// float[] clean = new float[BREITE];
|
||||
|
||||
for (int i = 0; i < BREITE; i++) {
|
||||
noisy[i] = (float) (5 * Math.sin(i * OMEGA) + Math.random() - 0.5);
|
||||
}
|
||||
|
||||
// Kernel k = new FilterKernel(noisy, clean)
|
||||
|
||||
Canvas oben = getCanvas(noisy);
|
||||
|
||||
VBox vbox = new VBox(oben);
|
||||
|
||||
vbox.setStyle("-fx-background-color: whitesmoke");
|
||||
|
||||
stage.setScene(new Scene(vbox));
|
||||
stage.setTitle("KAO: Mittelwertfilter der Ordnung " + (FILTERLAENGE - 1));
|
||||
stage.setResizable(false);
|
||||
stage.sizeToScene();
|
||||
stage.show();
|
||||
}
|
||||
|
||||
private Canvas getCanvas(float[] curve) {
|
||||
Canvas canvas = new Canvas(BREITE, HOEHE / 2);
|
||||
var statistics = IntStream.range(0, curve.length)
|
||||
.mapToDouble(i -> curve[i])
|
||||
.summaryStatistics();
|
||||
double max = statistics.getMax(), min = statistics.getMin();
|
||||
double scale = HOEHE / 2 / (max - min) * 0.9;
|
||||
double[] x = new double[BREITE], y = new double[BREITE];
|
||||
Arrays.parallelSetAll(x, i -> i);
|
||||
Arrays.parallelSetAll(y, i -> curve[i] * scale + HOEHE / 4);
|
||||
GraphicsContext g = canvas.getGraphicsContext2D();
|
||||
g.setLineWidth(2); g.strokePolyline(x, y, BREITE);
|
||||
return canvas;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
open module edu.thi.phga.aparapi_test {
|
||||
requires javafx.controls;
|
||||
requires aparapi;
|
||||
}
|
Loading…
Reference in new issue