Added Testcode for the four sided scanner and fixed a small typo

This commit is contained in:
Paul Schaller 2023-12-14 12:53:03 +01:00
parent 6807ee4a25
commit e7f1aa9b3c
8 changed files with 108 additions and 1 deletions

View File

@ -15,16 +15,31 @@ public class Homograph4 implements Homograph{
Point2D[] flippedBehindSide = new Point2D[frontSidePoints.length]; Point2D[] flippedBehindSide = new Point2D[frontSidePoints.length];
Point2D[] flippedLeftSide = new Point2D[frontSidePoints.length]; Point2D[] flippedLeftSide = new Point2D[frontSidePoints.length];
System.out.println("Homograph:");
for(int i = 0; i < frontSidePoints.length; i++) { for(int i = 0; i < frontSidePoints.length; i++) {
// the x coordinate goes from -1 to 1 after normalization // the x coordinate goes from -1 to 1 after normalization
System.out.println("f " + frontSidePoints[i].toString());
System.out.println("r " + rightSidePoints[i].toString());
flippedBehindSide[i] = new Point2D.Double(behindSidePoints[i].getX() * -1.0, behindSidePoints[i].getY()); flippedBehindSide[i] = new Point2D.Double(behindSidePoints[i].getX() * -1.0, behindSidePoints[i].getY());
System.out.println("b " + behindSidePoints[i].toString() + " to " + flippedBehindSide[i].toString());
flippedLeftSide[i] = new Point2D.Double(leftSidePoints[i].getX() * -1.0, leftSidePoints[i].getY()); flippedLeftSide[i] = new Point2D.Double(leftSidePoints[i].getX() * -1.0, leftSidePoints[i].getY());
System.out.println("l " + leftSidePoints[i].toString() + " to " + flippedLeftSide[i].toString());
} }
for(int i = 0; i < frontSidePoints.length; i++) { for(int i = 0; i < frontSidePoints.length; i++) {
Point2D interpolatedFrontBehind = new PointInterpolator(frontSidePoints[i], flippedBehindSide[i]).getCenter(); Point2D interpolatedFrontBehind = new PointInterpolator(frontSidePoints[i], flippedBehindSide[i]).getCenter();
Point2D interpolatedRightLeft = new PointInterpolator(rightSidePoints[i], leftSidePoints[i]).getCenter(); Point2D interpolatedRightLeft = new PointInterpolator(rightSidePoints[i], flippedLeftSide[i]).getCenter();
System.out.println("fb " + frontSidePoints[i].toString() + " + " + flippedBehindSide[i].toString() + " to " + interpolatedFrontBehind.toString());
System.out.println("rl " + rightSidePoints[i].toString() + " + " + leftSidePoints[i].toString() + " to " + interpolatedRightLeft.toString());
mergedFrontBack[i] = interpolatedFrontBehind; mergedFrontBack[i] = interpolatedFrontBehind;
mergedRightLeft[i] = interpolatedRightLeft; mergedRightLeft[i] = interpolatedRightLeft;

View File

@ -16,6 +16,7 @@ import javax.imageio.ImageIO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import com.cringe_studios.christmastreescanning.FourSidedScanner;
import com.cringe_studios.christmastreescanning.Homograph; import com.cringe_studios.christmastreescanning.Homograph;
import com.cringe_studios.christmastreescanning.Point3D; import com.cringe_studios.christmastreescanning.Point3D;
import com.cringe_studios.christmastreescanning.Scanner; import com.cringe_studios.christmastreescanning.Scanner;
@ -32,6 +33,7 @@ public class ExampleTest {
@Test @Test
public void scannerTest() { public void scannerTest() {
System.out.println("ScannerTest1:");
try { try {
BufferedImage LED1Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED1_front.png")); BufferedImage LED1Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED1_front.png"));
BufferedImage LED2Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED2_front.png")); BufferedImage LED2Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED2_front.png"));
@ -102,6 +104,96 @@ public class ExampleTest {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("-----EndOf ScannerTest1");
System.out.println();
}
@Test
public void scannerTest2() {
System.out.println("ScannerTest2:");
try {
BufferedImage LED1Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED1_front.png"));
BufferedImage LED2Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED2_front.png"));
BufferedImage LED3Front = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED3_front.png"));
BufferedImage LED1Right = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED1_right.png"));
BufferedImage LED2Right = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED2_right.png"));
BufferedImage LED3Right = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest1_LED3_right.png"));
BufferedImage LED1Behind= ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest2_LED1_back.png"));
BufferedImage LED2Behind= ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest2_LED2_back.png"));
BufferedImage LED3Behind= ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest2_LED3_back.png"));
BufferedImage LED1Left = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest2_LED1_left.png"));
BufferedImage LED2Left = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest2_LED2_left.png"));
BufferedImage LED3Left = ImageIO.read(ExampleTest.class.getResourceAsStream("/ScannerTest2_LED3_left.png"));
Scanner scanner = new FourSidedScanner(new BufferedImage[] {LED1Front, LED2Front, LED3Front},
new BufferedImage[] {LED1Right, LED2Right, LED3Right},
new BufferedImage[] {LED1Behind, LED2Behind, LED3Behind},
new BufferedImage[] {LED1Left, LED2Left, LED3Left});
scanner.setGammaDelta((byte)(0.1 * 255));
Homograph homo = scanner.scan();
homo.merge();
homo.renormalize();
Point3D points[] = homo.getPoints();
System.out.println(Arrays.toString(points));
boolean foundXMin = false; // -1
boolean foundXMax = false; // 1
boolean foundYMin = false; // -1
boolean foundYMax = false; // 1
boolean foundZMin = false; // 0
boolean foundZMax = false; // 1
for(int i = 0; i < points.length; i++) {
if(Math.abs(points[i].x - (-1.0)) < 0.001) {
foundXMin = true;
}
if(Math.abs(points[i].x - (1.0)) < 0.001) {
foundXMax = true;
}
if(Math.abs(points[i].y - (-1.0)) < 0.001) {
foundYMin = true;
}
if(Math.abs(points[i].y - (1.0)) < 0.001) {
foundYMax = true;
}
if(Math.abs(points[i].z - (1.0)) < 0.001) {
foundZMax = true;
}
if(Math.abs(points[i].z - (0.0)) < 0.001) {
foundZMin = true;
}
}
if(foundXMin && foundXMax && foundYMin && foundYMax && foundZMin && foundZMax) {
assertTrue(true);
}else {
System.out.println(foundXMin );
System.out.println(foundXMax );
System.out.println(foundYMin );
System.out.println(foundYMax );
System.out.println(foundZMin );
System.out.println(foundZMax );
assertTrue(false);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("-----EndOf ScannerTest2");
System.out.println();
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB