so siehts schon besser aus :D
This commit is contained in:
parent
a37c690000
commit
a3d2d97dcf
|
@ -103,5 +103,13 @@ public class Line {
|
|||
this.y2 = y2;
|
||||
}
|
||||
|
||||
public boolean equals(Line other){
|
||||
if (other.getM() == this.getM() && other.getB() == this.getB()){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,12 @@ public class LineModel {
|
|||
public LineModel() {
|
||||
nodes = new ArrayList<>();
|
||||
lines = new LinkedList<>();
|
||||
|
||||
xMinimum = Double.MAX_VALUE;
|
||||
xMaximum = Double.MIN_VALUE;
|
||||
yMinimum = Double.MAX_VALUE;
|
||||
yMaximum = Double.MIN_VALUE;
|
||||
|
||||
}
|
||||
|
||||
public void setXbounds() {
|
||||
|
@ -50,6 +56,11 @@ public class LineModel {
|
|||
|
||||
public void addNode(Point node) {
|
||||
this.nodes.add(node);
|
||||
xMaximum = (node.getX() > xMaximum) ? node.getX() : xMinimum;
|
||||
xMinimum = (node.getX() <= xMinimum) ? node.getX() : xMinimum;
|
||||
yMaximum = (node.getY() > yMaximum) ? node.getY() : yMaximum;
|
||||
yMaximum = (node.getY() <= yMaximum) ? node.getY() : yMaximum;
|
||||
|
||||
}
|
||||
|
||||
public void addLine(Line line) {
|
||||
|
@ -103,4 +114,11 @@ public class LineModel {
|
|||
public void setyMaximum(Double yMaximum) {
|
||||
this.yMaximum = yMaximum;
|
||||
}
|
||||
|
||||
public void resetRanges(){
|
||||
xMinimum = Double.MAX_VALUE;
|
||||
xMaximum = Double.MIN_VALUE;
|
||||
yMinimum = Double.MAX_VALUE;
|
||||
yMaximum = Double.MIN_VALUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,4 +32,5 @@ public class Pair {
|
|||
public void setP2(Integer p2) {
|
||||
this.p2 = p2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,6 +55,14 @@ public class Point implements Comparable<Point> {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean equals(Point other){
|
||||
if (other.getX() == this.getX() && other.getY() == this.getY()){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package presenter;
|
|||
|
||||
import model.Interval;
|
||||
import model.LineModel;
|
||||
import presenter.algorithms.util.IntersectionComputer;
|
||||
import presenter.algorithms.util.IntersectionCounter;
|
||||
import presenter.evaluation.EvaluateAlgorithms;
|
||||
import view.MainFrame;
|
||||
|
@ -95,12 +96,6 @@ public abstract class AbstractPresenter implements Observer {
|
|||
Integer progress = (int) (100 * (current / max));
|
||||
//100% erreicht
|
||||
if (progress == 100) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
getView().enableFunctionality();
|
||||
getView().getProgressDialog().dispose();
|
||||
});
|
||||
setup();
|
||||
Thread t = new Thread(() -> {
|
||||
calculateIntersections();
|
||||
});
|
||||
|
@ -110,6 +105,16 @@ public abstract class AbstractPresenter implements Observer {
|
|||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
getView().enableFunctionality();
|
||||
getView().getProgressDialog().dispose();
|
||||
getView().logHeading("Import aus Datei");
|
||||
getView().log("Anzahl der Geraden: "+ getModel().getLines().size() + ".");
|
||||
getView().log("Anzahl der Schnittpunkte: "+getModel().getNodes().size()+".");
|
||||
getView().logSuccess("Import war Erfolgreich! <hr>");
|
||||
});
|
||||
} else {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().showImportProgress(progress);
|
||||
|
@ -118,16 +123,16 @@ public abstract class AbstractPresenter implements Observer {
|
|||
}
|
||||
if (result[0] == "export") {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().logSuccess("Export Erfolgreich");
|
||||
getView().logHeading("Export der Daten als CSV");
|
||||
getView().logSuccess("Export war Erfolgreich");
|
||||
getView().log(result[1] + "<hr>");
|
||||
});
|
||||
}
|
||||
|
||||
if (result[0] == "generator") {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().logSuccess("Generierung Erfolgreich");
|
||||
getView().logSuccess("Generierung war Erfolgreich");
|
||||
getView().log(result[1] + "<hr>");
|
||||
setup();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -135,8 +140,12 @@ public abstract class AbstractPresenter implements Observer {
|
|||
//100% erreicht
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().enableFunctionality();
|
||||
getView().logHeading("Import eines Bildes");
|
||||
getView().log("Anzahl der Geraden: "+ getModel().getLines().size() + ".");
|
||||
getView().log("Anzahl der Schnittpunkte: "+getModel().getNodes().size()+".");
|
||||
getView().logSuccess("Der Import war Erfolgreich! <hr>");
|
||||
});
|
||||
setup();
|
||||
|
||||
Thread t = new Thread(() -> {
|
||||
calculateIntersections();
|
||||
});
|
||||
|
@ -150,25 +159,20 @@ public abstract class AbstractPresenter implements Observer {
|
|||
}
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
//Darstellung der Schnittpunkte in einer Tabelle
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
getView().logSuccess("Der Import der Daten war Erfolgreich!");
|
||||
getView().log("<hr>");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void calculateIntersections() {
|
||||
try {
|
||||
Thread thread = new Thread(() -> {
|
||||
IntersectionCounter counter = new IntersectionCounter();
|
||||
counter.run(getModel().getLines(), new Interval(-99999, 99999));
|
||||
counter.calculateIntersectionAbscissas(getModel());
|
||||
getModel().setXbounds();
|
||||
getModel().setYbounds();
|
||||
getModel().resetRanges();
|
||||
IntersectionComputer intersectionComputer = new IntersectionComputer(getModel().getLines());
|
||||
getModel().setNodes(intersectionComputer.compute());
|
||||
|
||||
getModel().setxMaximum(intersectionComputer.getxMaximum());
|
||||
getModel().setxMinimum(intersectionComputer.getxMinimum());
|
||||
getModel().setyMaximum(intersectionComputer.getyMaximum());
|
||||
getModel().setyMinimum(intersectionComputer.getyMinimum());
|
||||
});
|
||||
thread.start();
|
||||
thread.join();
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
package presenter.algorithms.util;
|
||||
|
||||
import model.Interval;
|
||||
import model.Line;
|
||||
import model.Point;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
||||
*
|
||||
* @Author: Armin Wolf
|
||||
* @Email: a_wolf28@uni-muenster.de
|
||||
* @Date: 18.09.2017.
|
||||
*/
|
||||
public class IntersectionComputer {
|
||||
|
||||
private LinkedList<Line> lines;
|
||||
private List<Line>[] subList;
|
||||
private TreeSet<Point> intersections;
|
||||
|
||||
private Double xMinimum;
|
||||
private Double xMaximum;
|
||||
private Double yMinimum;
|
||||
private Double yMaximum;
|
||||
|
||||
private Thread[] worker;
|
||||
|
||||
public IntersectionComputer(LinkedList<Line> lines) {
|
||||
this.lines = lines;
|
||||
this.worker = new Thread[4];
|
||||
this.subList = new LinkedList[4];
|
||||
this.intersections = new TreeSet<>();
|
||||
|
||||
xMinimum = Double.MAX_VALUE;
|
||||
xMaximum = Double.MIN_VALUE;
|
||||
yMinimum = Double.MAX_VALUE;
|
||||
yMaximum = Double.MIN_VALUE;
|
||||
}
|
||||
|
||||
public ArrayList<Point> compute(){
|
||||
|
||||
if (lines.size() >= 12) {
|
||||
worker[0] = new Thread(() -> {
|
||||
work(lines.subList(0, (lines.size() / 4)));
|
||||
});
|
||||
worker[0].start();
|
||||
worker[1] = new Thread(() -> {
|
||||
work(lines.subList((lines.size() / 4) + 1, (lines.size() / 2)));
|
||||
});
|
||||
worker[1].start();
|
||||
worker[2] = new Thread(() -> {
|
||||
work(lines.subList((lines.size() / 2) + 1, 3 * (lines.size() / 4)));
|
||||
});
|
||||
worker[2].start();
|
||||
worker[3] = new Thread(() -> {
|
||||
work(lines.subList(3 * (lines.size() / 4) + 1, (lines.size())));
|
||||
});
|
||||
worker[3].start();
|
||||
|
||||
|
||||
for (Thread t : worker) {
|
||||
try {
|
||||
t.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
work(lines);
|
||||
}
|
||||
|
||||
return new ArrayList<>(intersections);
|
||||
|
||||
}
|
||||
|
||||
private synchronized void work(List<Line> lines){
|
||||
IntersectionCounter counter = new IntersectionCounter();
|
||||
counter.run(lines, new Interval(-99999, 99999));
|
||||
ArrayList<Point> points = counter.calculateIntersectionAbscissas();
|
||||
for (Point p :points){
|
||||
if (!isFound(p)){
|
||||
addIntersection(p);
|
||||
setRanges(p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized LinkedList<Line> getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public synchronized void addIntersection(Point p){
|
||||
this.intersections.add(p);
|
||||
}
|
||||
|
||||
public synchronized boolean isFound(Point p){
|
||||
if (intersections.contains(p)){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void setRanges(Point point){
|
||||
xMaximum = (point.getX() > xMaximum) ? point.getX() : xMaximum;
|
||||
xMinimum = (point.getX() < xMinimum) ? point.getX() : xMinimum;
|
||||
yMaximum = (point.getY() > yMaximum) ? point.getY() : yMaximum;
|
||||
yMinimum = (point.getY() < yMinimum) ? point.getY() : yMinimum;
|
||||
}
|
||||
|
||||
public Double getxMinimum() {
|
||||
return xMinimum;
|
||||
}
|
||||
|
||||
public Double getxMaximum() {
|
||||
return xMaximum;
|
||||
}
|
||||
|
||||
public Double getyMinimum() {
|
||||
return yMinimum;
|
||||
}
|
||||
|
||||
public Double getyMaximum() {
|
||||
return yMaximum;
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ public class IntersectionCounter {
|
|||
private HashMap<Integer, Line> secondaryDictionaryBACK;
|
||||
private ArrayList<Line> umin;
|
||||
|
||||
|
||||
/**
|
||||
* Berechnet die Inversionen zwischen zwei Listen mit Integer Werten. Diese Methode dient als
|
||||
* Wrapper Methode. Die Logik steht in der <code>countInversions</code> Funktion.
|
||||
|
@ -242,6 +243,34 @@ public class IntersectionCounter {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Diese Methode liefert nur nach dem Ausführen der <code>run</code> Funktion Sinnvolle Werte.
|
||||
*/
|
||||
public ArrayList<Point> calculateIntersectionAbscissas() {
|
||||
ArrayList<Pair> result = new ArrayList<>();
|
||||
|
||||
ArrayList<Point> points = new ArrayList<>();
|
||||
for (int i = 0; i < inversions.size(); i++) {
|
||||
result.add(new Pair(dictionaryBACK.get(inversions.get(i).getP1()),
|
||||
dictionaryBACK.get(inversions.get(i).getP2())));
|
||||
}
|
||||
|
||||
for (Pair p : result) {
|
||||
Line line = secondaryDictionaryBACK.get(p.getP1());
|
||||
Line sampledLine = secondaryDictionaryBACK.get(p.getP2());
|
||||
if (!line.equals(sampledLine)) {
|
||||
double intersection = (line.getB() - sampledLine.getB()) / (sampledLine.getM() - line.getM());
|
||||
double yintercept = sampledLine.getM() * intersection + sampledLine.getB();
|
||||
Point point = new Point(intersection, yintercept);
|
||||
points.add(point);
|
||||
}
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die Schnittpunkte zwischen einer gegebenen Gerade und einer Menge an Geraden.
|
||||
*
|
||||
|
|
|
@ -51,10 +51,8 @@ public class PictureProcessor extends Observable{
|
|||
Imgproc.findContours(source, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0,0));
|
||||
Mat viscont = new Mat(source.size(), source.type());
|
||||
for (int i=0;i<contours.size();i++) {
|
||||
if (Imgproc.contourArea(contours.get(i)) > 20) {
|
||||
Imgproc.drawContours(viscont, contours, i, new Scalar(255, 255, 255), -1);
|
||||
} else {
|
||||
contours.remove(i);
|
||||
if (Imgproc.contourArea(contours.get(i)) > 100) {
|
||||
Imgproc.drawContours(viscont, contours, i, new Scalar(255, 255, 100), -1);
|
||||
}
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
@ -87,12 +85,13 @@ public class PictureProcessor extends Observable{
|
|||
int id = 0;
|
||||
for (int j=0;j<contours.size();j++){
|
||||
Point[] p = contours.get(j).toArray();
|
||||
for (int i=0;i<p.length;i++) {
|
||||
if (p.length > 200) {
|
||||
for (int i = 0; i < p.length; i++) {
|
||||
Line line = new Line(-1 * (500 - p[i].x), p[i].y);
|
||||
line.setId("" + id++);
|
||||
presenter.getModel().getLines().add(line);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
setChanged();
|
||||
|
|
|
@ -57,7 +57,9 @@ public class DataImporter extends Observable {
|
|||
Double y = Double.parseDouble(nextLine[2]) * (-1);
|
||||
Line line = new Line(x, y);
|
||||
line.setId(counter + "");
|
||||
this.presenter.getModel().addLine(line);
|
||||
if (!this.presenter.getModel().getLines().contains(line)) {
|
||||
this.presenter.getModel().addLine(line);
|
||||
}
|
||||
//System.out.format("|\t\t\t\t\t %-11d \t|\t\t\t\t\t %-11f \t|\t\t\t\t\t %-11f \t\t\t\t\t|\n", id,x,y);
|
||||
setChanged();
|
||||
counter++;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
1,18,18
|
||||
2,24,26
|
||||
3,30,30
|
||||
4,34,40
|
||||
5,38,70
|
||||
0,18,18
|
||||
1,24,26
|
||||
2,30,30
|
||||
3,34,40
|
||||
4,38,70
|
||||
|
|
|
Loading…
Reference in New Issue