feat: javafx dependency added, Rauschfilter (partially working)

master
qhga 3 years ago
parent 6e15d25210
commit d6cd29f2fc
Signed by: phga
GPG Key ID: 5249548AA705F019

@ -14,6 +14,7 @@ DEVICE=1
# 21 - 25 = Reduce1 - Reduce5 respectively # 21 - 25 = Reduce1 - Reduce5 respectively
# 30 = All Prefix related implementations at once # 30 = All Prefix related implementations at once
# 31 - 32 = Prefix1 - Prefix2 respectively # 31 - 32 = Prefix1 - Prefix2 respectively
# 40 = Rauschfilter (Spawns a javafx window)
# DEFAULT = 0 # DEFAULT = 0
TARGET=31 TARGET=31

@ -18,6 +18,10 @@
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
</properties> </properties>
<!-- <modules>
<module>aparapi_test</module>
</modules>
-->
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/com.aparapi/aparapi --> <!-- https://mvnrepository.com/artifact/com.aparapi/aparapi -->
<dependency> <dependency>
@ -26,6 +30,13 @@
<version>3.0.0</version> <version>3.0.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.1</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

@ -2,6 +2,8 @@ package edu.thi.phga.aparapi_test;
import com.aparapi.device.OpenCLDevice; import com.aparapi.device.OpenCLDevice;
import javafx.application.Application;
public class App { public class App {
public static int choice; public static int choice;
public static OpenCLDevice device; public static OpenCLDevice device;
@ -95,6 +97,9 @@ public class App {
java.util.Arrays.fill(b, 1); java.util.Arrays.fill(b, 1);
OpenCLPrefix2.start(b); OpenCLPrefix2.start(b);
break; break;
case 40:
Application.launch(Rauschfilter.class);
break;
} }
} }
} }

@ -1,3 +1,4 @@
// Author: Prof. Dr. Schmidt <Ulrich.Schmidt@thi.de>
package edu.thi.phga.aparapi_test; package edu.thi.phga.aparapi_test;
import java.io.IOException; import java.io.IOException;

@ -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…
Cancel
Save