Implemented Point Normalization (untested)

This commit is contained in:
Paul Schaller 2023-11-23 16:55:16 +01:00
parent d8531012a6
commit b77d8ba7e9
2 changed files with 47 additions and 72 deletions

View File

@ -1,13 +1,6 @@
package com.cringe_studios.christmastreescanning.scanning; package com.cringe_studios.christmastreescanning.scanning;
import java.awt.Color;
import java.awt.Point;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import com.cringe_studios.christmastreescanning.Point3D;
public class PointNormalizer { public class PointNormalizer {
Point2D[] points; Point2D[] points;
@ -15,78 +8,57 @@ public class PointNormalizer {
public PointNormalizer(Point2D[] newPoints) { public PointNormalizer(Point2D[] newPoints) {
this.points = newPoints; this.points = newPoints;
} }
/**
// This method normalizes the Point coordinates, * This method normalizes the Point coordinates,
// Optionally flips them horizontally * Adjusts the height (y-coordinate) to make the virtual points not squished (puts them into a rectangle)
// Adjusts the height (y-coordinate) to make the virtual points not squished (puts them into a rectangle) *
// Returns the Points as Point2D * To get the normalized Points call .getPoints();
*
*/
public void normalizePoints() { public void normalizePoints() {
if(points == null) return; if(points == null) return;
Point2D normalizedPoints[] = new Point2D.Double[points.length]; double smallestXValue = Double.POSITIVE_INFINITY;
for(int i = 0; i < normalizedPoints.length; i++) { double biggestXValue = Double.NEGATIVE_INFINITY;
double smallestYValue = Double.POSITIVE_INFINITY;
double biggestYValue = Double.NEGATIVE_INFINITY;
for(int i = 0; i < points.length; i++) {
if(points[i].getX() < smallestXValue) {
smallestXValue = points[i].getX();
}
if(points[i].getX() > biggestXValue) {
biggestXValue = points[i].getX();
}
if(points[i].getY() < smallestYValue) {
smallestYValue = points[i].getY();
}
if(points[i].getY() > biggestYValue) {
biggestYValue = points[i].getY();
}
} }
//TODO is this still needed? // x between -1 and 1
// y between 0 and 1
Point2D normalizedPoints[] = new Point2D.Double[points.length];
for(int i = 0; i < normalizedPoints.length; i++) {
double normalizedX = (points[i].getX() - smallestXValue) / (biggestXValue - smallestXValue);
double normalizedY = (points[i].getY() - smallestYValue) / (biggestYValue - smallestYValue);;
normalizedX = normalizedX * 2.0 - 1.0;
normalizedPoints[i] = new Point2D.Double(normalizedX, normalizedY);
}
this.points = normalizedPoints;
} }
public Point2D[] getPoints() { public Point2D[] getPoints() {
return points; return points;
} }
// /**
// * Normalizes 3D points with the given parameters and returns a NEW array with the normalized points. To see which coordinate dimension represents what direction, view Point3D class
// * @param points
// * @param baseline for z coordinates. Can be different to the lowest LED
// * @param minX minimal X value of LED box
// * @param minY minimal Y value of LED box
// * @param maxX maximal X value of LED box
// * @param maxY maximal Y value of LED box
// * @return new Array with normalized Points
// */
// public Point3D[] normalizePoints(Point3D[] points, double baseline, double minX, double minY, double maxX, double maxY) {
// Point3D normalizedPoints[] = new Point3D[points.length];
// for(int i = 0; i < normalizedPoints.length; i++) {
// double normalizedX = (points[i].x - minX) / (maxX - minX);
// double normalizedY = (points[i].y - minY) / (maxY - minY);
// double normalizedZ = ((baseline - points[i].z) - minX) / (maxX - minX);
//
// normalizedX = normalizedX * 2.0 - 1.0;
// normalizedY = normalizedY * 2.0 - 1.0;
//
// normalizedPoints[i] = new Point3D(normalizedX, normalizedY, normalizedZ);
// }
//
// return normalizedPoints;
// }
//
// public Point3D[] normalizePoints(Point3D[] points, double baseline) {
// double lowestX = Double.POSITIVE_INFINITY;
// double highestX = Double.NEGATIVE_INFINITY;
//
// for(int i = 0; i < points.length; i++) {
// if(lowestX > points[i].x) {
// lowestX = points[i].x;
// }
//
// if(highestX < points[i].x) {
// highestX = points[i].x;
// }
// }
//
// return normalizePoints(points, baseline, lowestX, highestX, lowestX, highestX);
// }
//
// public Point3D[] normalizePoints(Point3D[] points) {
// double lowestZ = Double.POSITIVE_INFINITY;
//
// for(int i = 0; i < points.length; i++) {
// if(lowestZ > points[i].z) {
// lowestZ = points[i].z;
// }
// }
//
// return normalizePoints(points, lowestZ);
// }
} }

View File

@ -90,8 +90,11 @@ public abstract class SideScanner {
// } // }
public void normalizePoints() { public void normalizePoints() {
if(foundPoints == null); //TODO error if(foundPoints == null) return;
//TODO
PointNormalizer pointNormalizer = new PointNormalizer(foundPoints);
pointNormalizer.normalizePoints();
foundPoints = pointNormalizer.getPoints();
} }
} }