From 0f77f2bfaf3012cbe12ccf7b6e3dd01f8ab4e0a4 Mon Sep 17 00:00:00 2001 From: Peter Abeles Date: Wed, 22 Apr 2026 20:12:27 -0700 Subject: [PATCH] format - Started adding support for format to several structures --- build.gradle | 2 +- .../boofcv/struct/calib/CameraDivision.java | 24 ++-- .../struct/calib/CameraKannalaBrandt.java | 43 +++----- .../java/boofcv/struct/calib/CameraModel.java | 5 +- .../boofcv/struct/calib/CameraPinhole.java | 33 ++++-- .../struct/calib/CameraPinholeBrown.java | 30 ++--- .../struct/calib/CameraUniversalOmni.java | 33 ++---- .../boofcv/struct/geo/AssociatedPair.java | 104 +++++++----------- .../boofcv/struct/geo/AssociatedTriple.java | 30 +++-- .../boofcv/struct/geo/AssociatedTuple.java | 14 +-- .../boofcv/struct/geo/AssociatedTupleDN.java | 35 +++++- .../boofcv/struct/geo/AssociatedTupleN.java | 34 +++++- .../java/boofcv/struct/geo/GeoLL_F64.java | 65 ++++++----- .../java/boofcv/struct/geo/PairLineNorm.java | 66 ++++++----- .../java/boofcv/struct/geo/Point2D3D.java | 33 +++--- .../java/boofcv/struct/geo/Point2D4D.java | 33 +++--- .../java/boofcv/struct/geo/PointIndex.java | 15 ++- .../boofcv/struct/geo/PointIndex2D_F64.java | 9 +- .../boofcv/struct/geo/PointIndex3D_F64.java | 2 +- .../boofcv/struct/geo/PointIndex4D_F64.java | 2 +- .../boofcv/struct/geo/ScaleTranslate2D.java | 31 ++++-- .../struct/geo/ScaleTranslateRotate2D.java | 38 ++++--- .../boofcv/struct/geo/TrifocalTensor.java | 38 ++++--- .../TestDistanceScaleTranslateRotate2DSq.java | 8 +- .../TestGenerateScaleTranslateRotate2D.java | 4 +- ...estModelManagerScaleTranslateRotate2D.java | 4 +- .../struct/calib/TestCameraKannalaBrandt.java | 20 +++- .../struct/calib/TestCameraPinhole.java | 13 ++- .../struct/calib/TestCameraPinholeBrown.java | 29 +++-- .../boofcv/struct/geo/TestAssociatedPair.java | 16 ++- .../struct/geo/TestAssociatedTriple.java | 9 +- .../struct/geo/TestAssociatedTupleDN.java | 55 +++++++++ .../struct/geo/TestAssociatedTupleN.java | 53 +++++++++ .../java/boofcv/struct/geo/TestGeoLL_F64.java | 33 ++++++ .../boofcv/struct/geo/TestPairLineNorm.java | 6 +- .../struct/geo/TestPointIndex2D_F64.java | 33 ++++++ .../struct/geo/TestPointIndex3D_F64.java | 33 ++++++ .../struct/geo/TestPointIndex4D_F64.java | 33 ++++++ .../struct/geo/TestScaleTranslate2D.java | 16 ++- .../geo/TestScaleTranslateRotate2D.java | 16 ++- .../boofcv/struct/geo/TestTrifocalTensor.java | 37 +++++-- .../boofcv/testing/BoofStandardJUnit.java | 16 ++- 42 files changed, 771 insertions(+), 382 deletions(-) create mode 100644 main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleDN.java create mode 100644 main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleN.java create mode 100644 main/boofcv-geo/src/test/java/boofcv/struct/geo/TestGeoLL_F64.java create mode 100644 main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex2D_F64.java create mode 100644 main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex3D_F64.java create mode 100644 main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex4D_F64.java diff --git a/build.gradle b/build.gradle index 412bfba735..d587ef050a 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ project.ext.args4j_version = '2.33' project.ext.junit_version = '5.11.4' project.ext.errorprone_version = '2.41.0' project.ext.nullaway_version = '0.12.10' -project.ext.auto64to32_version = '3.3.0-SNAPSHOT' +project.ext.auto64to32_version = '3.3.0' project.ext.snakeyaml_version = '2.3' project.ext.jmh_version = '1.36' project.ext.jetnull_version = '23.0.0' diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraDivision.java b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraDivision.java index 79079904b4..7fcdcc6b4e 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraDivision.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraDivision.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,7 +19,7 @@ package boofcv.struct.calib; import lombok.Getter; -import org.ejml.FancyPrint; +import org.ejml.MapPrintFormat; import java.io.Serializable; @@ -81,18 +81,12 @@ public boolean isDistorted() { System.out.printf("radial=%6.2e%n\n", radial); } - @Override public String toString() { - FancyPrint fp = new FancyPrint(); - String txt = "CameraDivision{" + - "fx=" + fx + - ", fy=" + fy + - ", skew=" + skew + - ", cx=" + cx + - ", cy=" + cy + - ", width=" + width + - ", height=" + height + - ", radial="+fp.s(radial); - txt += '}'; - return txt; + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.itemPrefix); + formatPinhole(format, builder, true); + format.pair(builder, "radial", radial, true); + builder.append(format.itemSuffix); + return builder.toString(); } } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraKannalaBrandt.java b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraKannalaBrandt.java index e21d38feed..46a728b764 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraKannalaBrandt.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraKannalaBrandt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -21,9 +21,7 @@ import boofcv.misc.BoofMiscOps; import lombok.Getter; import lombok.Setter; -import org.ejml.FancyPrint; - -import static boofcv.struct.calib.CameraPinholeBrown.toStringArray; +import org.ejml.MapPrintFormat; /** * A camera model for pinhole, wide angle, and fisheye cameras. The full camera model @@ -75,7 +73,7 @@ public class CameraKannalaBrandt extends CameraPinhole { * Constructor which allows the order of all distortion coefficients to be specified * * @param numSymmetric Number of radially symmetric terms. Standard is 5. - * @param numAsymmetric Number of non symmetric terms. If not zero then trig coefficients will be 4. + * @param numAsymmetric Number of non-symmetric terms. If not zero then trig coefficients will be 4. * Standard is 4 */ public CameraKannalaBrandt( int numSymmetric, int numAsymmetric ) { @@ -100,7 +98,7 @@ public CameraKannalaBrandt() { * Configures the number of coefficients for each distortion term. * * @param numSymmetric Number of radially symmetric terms. Standard is 5. - * @param numAsymmetric Number of non symmetric terms. If not zero then trig coefficients will be 4. + * @param numAsymmetric Number of non-symmetric terms. If not zero then trig coefficients will be 4. * Standard is 4 */ public void configureCoefficients( int numSymmetric, int numAsymmetric ) { @@ -114,8 +112,8 @@ public void configureCoefficients( int numSymmetric, int numAsymmetric ) { } @Override public CameraKannalaBrandt fsetK( double fx, double fy, - double skew, - double cx, double cy ) { + double skew, + double cx, double cy ) { super.fsetK(fx, fy, skew, cx, cy); return this; } @@ -241,24 +239,17 @@ public T createLike() { return (T)new CameraKannalaBrandt(symmetric.length, radial.length); } - @Override - public String toString() { - FancyPrint fp = new FancyPrint(); - String txt = "CameraKannalaBrandt{" + - "fx=" + fx + - ", fy=" + fy + - ", skew=" + skew + - ", cx=" + cx + - ", cy=" + cy + - ", width=" + width + - ", height=" + height; - txt += toStringArray(fp, "s", symmetric); - txt += toStringArray(fp, "r", radial); - txt += toStringArray(fp, "rt", radialTrig); - txt += toStringArray(fp, "t", tangent); - txt += toStringArray(fp, "tt", tangentTrig); - txt += '}'; - return txt; + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.itemPrefix); + formatPinhole(format, builder, true); + format.pair(builder, "symmetric", symmetric, true); + format.pair(builder, "radial", radial, true); + format.pair(builder, "radialTrig", radialTrig, true); + format.pair(builder, "tangent", tangent, true); + format.pair(builder, "tangentTrig", tangentTrig, false); + builder.append(format.itemSuffix); + return builder.toString(); } @Override diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraModel.java b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraModel.java index 62e563570d..0e775b6904 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraModel.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,6 +20,7 @@ import boofcv.struct.image.ImageBase; import boofcv.struct.image.ImageDimension; +import org.ejml.MapFormattable; import org.jetbrains.annotations.Nullable; import java.io.Serializable; @@ -29,7 +30,7 @@ * * @author Peter Abeles */ -public abstract class CameraModel implements Serializable { +public abstract class CameraModel implements Serializable, MapFormattable { /** image shape (units: pixels) */ public int width, height; diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinhole.java b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinhole.java index a77257a4f9..5865648ab7 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinhole.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinhole.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -21,6 +21,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; +import org.ejml.MapPrintFormat; import org.ejml.data.DMatrixRMaj; /** @@ -161,19 +162,27 @@ public T createLike() { return (T)new CameraPinhole(); } - @Override - public String toString() { - return "CameraPinhole{" + - "fx=" + fx + - ", fy=" + fy + - ", skew=" + skew + - ", cx=" + cx + - ", cy=" + cy + - ", width=" + width + - ", height=" + height + - '}'; + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.itemPrefix); + formatPinhole(format, builder, false); + builder.append(format.itemSuffix); + return builder.toString(); + } + + /// Adds parameters which define a pinhole camera to the serialization + protected void formatPinhole( MapPrintFormat format, StringBuilder builder, boolean isMore ) { + format.pair(builder, "fx", fx, true); + format.pair(builder, "fy", fy, true); + format.pair(builder, "skew", skew, true); + format.pair(builder, "cx", cx, true); + format.pair(builder, "cy", cy, true); + format.pair(builder, "width", width, true); + format.pair(builder, "height", height, isMore); } + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} + public boolean isEquals( CameraPinhole param, double tol ) { if (Math.abs(fx - param.fx) > tol) return false; diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinholeBrown.java b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinholeBrown.java index a07775c912..40645bfcc6 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinholeBrown.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraPinholeBrown.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -21,6 +21,7 @@ import lombok.Getter; import lombok.Setter; import org.ejml.FancyPrint; +import org.ejml.MapPrintFormat; import org.jetbrains.annotations.Nullable; import java.io.Serializable; @@ -182,24 +183,15 @@ public void print() { } } - @Override - public String toString() { - var fp = new FancyPrint(); - String txt = "CameraPinholeRadial{" + - "fx=" + fx + - ", fy=" + fy + - ", skew=" + skew + - ", cx=" + cx + - ", cy=" + cy + - ", width=" + width + - ", height=" + height; - txt += toStringArray(fp, "r", radial); - - if (t1 != 0 || t2 != 0) { - txt += ", t1=" + fp.s(t1) + " t2=" + fp.s(t2); - } - txt += '}'; - return txt; + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.itemPrefix); + formatPinhole(format, builder, true); + format.pair(builder, "radial", radial, true); + format.pair(builder, "t1", t1, true); + format.pair(builder, "t2", t2, false); + builder.append(format.itemSuffix); + return builder.toString(); } public static String toStringArray( FancyPrint fp, String name, @Nullable double[] param ) { diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraUniversalOmni.java b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraUniversalOmni.java index a8c8a138cd..a6cc1bdbe5 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraUniversalOmni.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/calib/CameraUniversalOmni.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -18,9 +18,7 @@ package boofcv.struct.calib; -import org.ejml.FancyPrint; - -import static boofcv.struct.calib.CameraPinholeBrown.toStringArray; +import org.ejml.MapPrintFormat; /** *

Camera model for omnidirectional single viewpoint sensors [1]. Designed to work with parabolic, @@ -165,23 +163,16 @@ public void setMirrorOffset( double mirrorOffset ) { this.mirrorOffset = mirrorOffset; } - @Override public String toString() { - FancyPrint fp = new FancyPrint(); - String txt = "CameraUniversalOmni{" + - "width=" + width + - ", height=" + height + - ", fx=" + fx + - ", fy=" + fy + - ", skew=" + skew + - ", cx=" + cx + - ", cy=" + cy + - ", mirrorOffset=" + fp.s(mirrorOffset); - txt += toStringArray(fp, "r", radial); - if (t1 != 0 || t2 != 0) { - txt += ", t1=" + fp.s(t1) + " t2=" + fp.s(t2); - } - txt += '}'; - return txt; + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.itemPrefix); + formatPinhole(format, builder, true); + format.pair(builder, "radial", radial, true); + format.pair(builder, "t1", t1, true); + format.pair(builder, "t2", t2, true); + format.pair(builder, "mirrorOffset", mirrorOffset, false); + builder.append(format.itemSuffix); + return builder.toString(); } @Override diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedPair.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedPair.java index d47b1770dd..50b19bf623 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedPair.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedPair.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,23 +20,16 @@ import georegression.struct.point.Point2D_F64; import lombok.Getter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - *

- * The observed location of a point feature in two camera views. Can be in pixels or normalized image coordinates. - *

- * - * @author Peter Abeles - */ -public class AssociatedPair { +/// The observed location of a point feature in two camera views. Can be in pixels or normalized image coordinates. +/// +public class AssociatedPair implements MapFormattable { - /** - * Location of the feature in the first image - */ + /// Location of the feature in the first image @Getter public Point2D_F64 p1; - /** - * Location of the feature in the second image. - */ + /// Location of the feature in the second image. @Getter public Point2D_F64 p2; public AssociatedPair() { @@ -44,37 +37,31 @@ public AssociatedPair() { p2 = new Point2D_F64(); } - /** - * Creates a new associated point from the two provided points. - * - * @param x1 image 1 location x-axis. - * @param y1 image 1 location y-axis. - * @param x2 image 2 location x-axis. - * @param y2 image 2 location y-axis. - */ + /// Creates a new associated point from the two provided points. + /// + /// @param x1 image 1 location x-axis. + /// @param y1 image 1 location y-axis. + /// @param x2 image 2 location x-axis. + /// @param y2 image 2 location y-axis. public AssociatedPair( double x1, double y1, - double x2, double y2 ) { + double x2, double y2 ) { p1 = new Point2D_F64(x1, y1); p2 = new Point2D_F64(x2, y2); } - /** - * Assigns the value to the two passed in features. A copy of the features is made. - * - * @param p1 image 1 location - * @param p2 image 2 location - */ + /// Assigns the value to the two passed in features. A copy of the features is made. + /// + /// @param p1 image 1 location + /// @param p2 image 2 location public AssociatedPair( Point2D_F64 p1, Point2D_F64 p2 ) { this(p1, p2, true); } - /** - * Allows features to either be copied or saved as references. - * - * @param p1 image 1 location - * @param p2 image 2 location - * @param newInstance Should it create new points or save a reference to these instances. - */ + /// Allows features to either be copied or saved as references. + /// + /// @param p1 image 1 location + /// @param p2 image 2 location + /// @param newInstance Should it create new points or save a reference to these instances. public AssociatedPair( Point2D_F64 p1, Point2D_F64 p2, boolean newInstance ) { if (newInstance) { this.p1 = new Point2D_F64(p1); @@ -91,51 +78,41 @@ public AssociatedPair setTo( AssociatedPair original ) { return this; } - /** - * Assigns this object to be equal to the passed in values. - */ + /// Assigns this object to be equal to the passed in values. public AssociatedPair setTo( Point2D_F64 p1, Point2D_F64 p2 ) { this.p1.setTo(p1); this.p2.setTo(p2); return this; } - /** - * Assigns this object to be equal to the passed in values. - */ + /// Assigns this object to be equal to the passed in values. public AssociatedPair setTo( Point2D_F64 p1, double p2_x, double p2_y ) { this.p1.setTo(p1); this.p2.setTo(p2_x, p2_y); return this; } - /** - * Assigns this object to be equal to the passed in values. - */ + /// Assigns this object to be equal to the passed in values. public AssociatedPair setTo( double p1_x, double p1_y, Point2D_F64 p2 ) { this.p1.setTo(p1_x, p1_y); this.p2.setTo(p2); return this; } - /** - * Assigns this object to be equal to the passed in values. - */ + /// Assigns this object to be equal to the passed in values. public AssociatedPair setTo( double p1_x, double p1_y, double p2_x, double p2_y ) { this.p1.setTo(p1_x, p1_y); this.p2.setTo(p2_x, p2_y); return this; } - /** - * Changes the references to the passed in objects. - */ + /// Changes the references to the passed in objects. public void assign( Point2D_F64 p1, Point2D_F64 p2 ) { this.p1 = p1; this.p2 = p2; } - /** Sets internal points to zero */ + /// Sets internal points to zero public void zero() { this.p1.zero(); this.p2.zero(); @@ -145,25 +122,22 @@ public AssociatedPair copy() { return new AssociatedPair().setTo(p1, p2); } - /** - * Euclidean distance from p1 to p2 - */ + /// Euclidean distance from p1 to p2 public double distance() { return p1.distance(p2); } - /** - * Euclidean distance squared from p1 to p2 - */ + /// Euclidean distance squared from p1 to p2 public double distance2() { return p1.distance2(p2); } - @Override - public String toString() { - return "AssociatedPair{" + - "p1=(" + p1.x + ", " + p1.y + ")" + - ", p2=(" + p2.x + ", " + p2.y + ")" + - '}'; + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("p1", p1.formatMap(format), true) + + format.pair("p2", p2.formatMap(format), false) + + format.itemSuffix; } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTriple.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTriple.java index 74662b8385..3f03455660 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTriple.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTriple.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,18 +19,16 @@ package boofcv.struct.geo; import georegression.struct.point.Point2D_F64; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - * Contains a set of three observations of the same point feature in three different views. - * - * @author Peter Abeles - */ -public class AssociatedTriple { - /** Observation in View 1 */ +/// Contains a set of three observations of the same point feature in three different views. +public class AssociatedTriple implements MapFormattable { + /// Observation in View 1 public Point2D_F64 p1; - /** Observation in View 2 */ + /// Observation in View 2 public Point2D_F64 p2; - /** Observation in View 3 */ + /// Observation in View 3 public Point2D_F64 p3; public AssociatedTriple( Point2D_F64 p1, Point2D_F64 p2, Point2D_F64 p3 ) { @@ -114,7 +112,17 @@ public boolean isIdentical( AssociatedTriple o, double tol ) { return tol >= o.p3.distance(p3); } + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("p1", p1.formatMap(format), true) + + format.pair("p2", p2.formatMap(format), true) + + format.pair("p3", p3.formatMap(format), false) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} + public void print() { - System.out.println("AssociatedTriple( " + p1 + " , " + p2 + " , " + p3 + " )"); + System.out.println(this); } } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTuple.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTuple.java index f197abd754..6af6ab39ea 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTuple.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTuple.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,13 +19,11 @@ package boofcv.struct.geo; import georegression.struct.point.Point2D_F64; +import org.ejml.MapFormattable; +import org.ejml.MatrixFormattable; -/** - * Interface for arbitrary number of matched 2D features - * - * @author Peter Abeles - */ -public interface AssociatedTuple { +/// Interface for arbitrary number of matched 2D features +public interface AssociatedTuple extends MapFormattable, MatrixFormattable { double getX( int index ); double getY( int index ); @@ -38,7 +36,7 @@ public interface AssociatedTuple { int size(); - void setTo( AssociatedTuple src ); + AssociatedTuple setTo( AssociatedTuple src ); void zero(); } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleDN.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleDN.java index a82aa8be3f..7650c8d62b 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleDN.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleDN.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,6 +20,8 @@ import georegression.struct.point.Point2D_F64; import org.ddogleg.struct.DogArray; +import org.ejml.MapPrintFormat; +import org.ejml.MatrixPrintFormat; /** * Associated set of {@link Point2D_F64} for an arbitrary number of views which can be changed. @@ -32,6 +34,7 @@ public class AssociatedTupleDN implements AssociatedTuple { public AssociatedTupleDN( int num ) { p = new DogArray<>(num, Point2D_F64::new); + p.resize(num); } public AssociatedTupleDN() { @@ -68,12 +71,14 @@ public void resize( int newSize ) { p.resize(newSize); } - @Override public void setTo( AssociatedTuple src ) { + @Override public AssociatedTuple setTo( AssociatedTuple src ) { p.resize(src.size()); for (int i = 0; i < p.size; i++) { p.data[i].setTo(src.get(i)); } + + return this; } @Override public void zero() { @@ -81,4 +86,30 @@ public void resize( int newSize ) { p.data[i].zero(); } } + + @Override public String format( MatrixPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.prefix); + for (int i = 0; i < p.size(); i++) { + builder.append(p.get(i).format(format)); + if (i < p.size() - 1) + builder.append(format.rowSeparator); + } + builder.append(format.suffix); + return builder.toString(); + } + + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.listPrefix); + for (int i = 0; i < p.size(); i++) { + builder.append(p.get(i).formatMap(format)); + if (i < p.size() - 1) + builder.append(format.itemSeparator); + } + builder.append(format.listSuffix); + return builder.toString(); + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleN.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleN.java index f05d81c888..f67ead53b8 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleN.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/AssociatedTupleN.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,6 +20,8 @@ import boofcv.misc.BoofMiscOps; import georegression.struct.point.Point2D_F64; +import org.ejml.MapPrintFormat; +import org.ejml.MatrixPrintFormat; /** * Associated set of {@link Point2D_F64} for an arbitrary number of views that is fixed. @@ -68,12 +70,14 @@ public AssociatedTupleN( final Point2D_F64... src ) { return p.length; } - @Override public void setTo( AssociatedTuple src ) { + @Override public AssociatedTuple setTo( AssociatedTuple src ) { BoofMiscOps.checkTrue(src.size() == size()); for (int i = 0; i < p.length; i++) { p[i].setTo(src.get(i)); } + + return this; } @Override public void zero() { @@ -81,4 +85,30 @@ public AssociatedTupleN( final Point2D_F64... src ) { p[i].zero(); } } + + @Override public String format( MatrixPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.prefix); + for (int i = 0; i < p.length; i++) { + builder.append(p[i].format(format)); + if (i < p.length - 1) + builder.append(format.rowSeparator); + } + builder.append(format.suffix); + return builder.toString(); + } + + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.listPrefix); + for (int i = 0; i < p.length; i++) { + builder.append(p[i].formatMap(format)); + if (i < p.length - 1) + builder.append(format.itemSeparator); + } + builder.append(format.listSuffix); + return builder.toString(); + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/GeoLL_F64.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/GeoLL_F64.java index 39e8f892ac..30598ee8bb 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/GeoLL_F64.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/GeoLL_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -18,41 +18,48 @@ package boofcv.struct.geo; -/** - * Geographic coordinate consisting of latitude (north-south coordinate) and longitude (west-east) . - * - *
- * - *
- */ -public class GeoLL_F64 { - /** - * latitude - */ - public double lat; - /** - * longitude - */ - public double lon; - - public void setTo( GeoLL_F64 src ) { - this.lat = src.lat; - this.lon = src.lon; - } +import lombok.Getter; +import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; - public double getLat() { - return lat; - } +/// Geographic coordinate consisting of latitude (north-south coordinate) and longitude (west-east) . +///
+/// +///
+public class GeoLL_F64 implements MapFormattable { + /// latitude + @Getter @Setter public double lat; + /// longitude + @Getter @Setter public double lon; - public void setLat( double lat ) { + public GeoLL_F64( double lat, double lon ) { this.lat = lat; + this.lon = lon; } - public double getLon() { - return lon; + public GeoLL_F64() {} + + public GeoLL_F64 setTo( GeoLL_F64 src ) { + this.lat = src.lat; + this.lon = src.lon; + return this; } - public void setLon( double lon ) { + public GeoLL_F64 setTo( double lat, double lon ) { + this.lat = lat; this.lon = lon; + return this; } + + @Override public String formatMap( MapPrintFormat format ) { + var builder = new StringBuilder(); + builder.append(format.itemPrefix); + format.pair(builder, "lat", lat, true); + format.pair(builder, "lon", lon, false); + builder.append(format.itemSuffix); + return builder.toString(); + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PairLineNorm.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PairLineNorm.java index 1aeba64f3f..3dc3c4e0dd 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PairLineNorm.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PairLineNorm.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -21,22 +21,16 @@ import georegression.struct.point.Vector3D_F64; import lombok.Getter; import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - * A pair of line observations found in two different images. The line is described by a vector, which is the normal - * of the plane defined by the line on the image plane and the camera's origin. The cross product of the two end - * points (in homogeneous pixels) would define a line in this manor. - * - * @author Peter Abeles - */ -public class PairLineNorm { - /** - * Location of the feature in the first image - */ +/// A pair of line observations found in two different images. The line is described by a vector, which is the normal +/// of the plane defined by the line on the image plane and the camera's origin. The cross product of the two end +/// points (in homogeneous pixels) would define a line in this manor. +public class PairLineNorm implements MapFormattable { + /// Location of the feature in the first image @Getter @Setter public Vector3D_F64 l1; - /** - * Location of the feature in the second image. - */ + /// Location of the feature in the second image. @Getter @Setter public Vector3D_F64 l2; public PairLineNorm() { @@ -44,23 +38,19 @@ public PairLineNorm() { l2 = new Vector3D_F64(); } - /** - * Creates a new instance by copying the values of the two lines. - * - * @param l1 image 1 location - * @param l2 image 2 location - */ + /// Creates a new instance by copying the values of the two lines. + /// + /// @param l1 image 1 location + /// @param l2 image 2 location public PairLineNorm( Vector3D_F64 l1, Vector3D_F64 l2 ) { this(l1, l2, true); } - /** - * Creates a new instance by either copying or saving a reference to the two lines - * - * @param l1 image 1 location - * @param l2 image 2 location - * @param newInstance Should it create new lines or save a reference to these instances. - */ + /// Creates a new instance by either copying or saving a reference to the two lines + /// + /// @param l1 image 1 location + /// @param l2 image 2 location + /// @param newInstance Should it create new lines or save a reference to these instances. public PairLineNorm( Vector3D_F64 l1, Vector3D_F64 l2, boolean newInstance ) { if (newInstance) { this.l1 = l1.copy(); @@ -71,12 +61,11 @@ public PairLineNorm( Vector3D_F64 l1, Vector3D_F64 l2, boolean newInstance ) { } } - /** - * Sets the value of p1 and p2 to be equal to the values of the passed in objects - */ - public void setTo( Vector3D_F64 l1, Vector3D_F64 l2 ) { + /// Sets the value of p1 and p2 to be equal to the values of the passed in objects + public PairLineNorm setTo( Vector3D_F64 l1, Vector3D_F64 l2 ) { this.l1.setTo(l1); this.l2.setTo(l2); + return this; } public PairLineNorm setTo( PairLineNorm src ) { @@ -90,11 +79,18 @@ public void zero() { this.l2.zero(); } - /** - * Sets p1 and p2 to reference the passed in objects. - */ + /// Sets p1 and p2 to reference the passed in objects. public void assign( Vector3D_F64 l1, Vector3D_F64 l2 ) { this.l1 = l1; this.l2 = l2; } + + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("l1", l1.formatMap(format), true) + + format.pair("l2", l2.formatMap(format), false) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D3D.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D3D.java index 53ef124439..343c9fa2ac 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D3D.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D3D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -22,20 +22,14 @@ import georegression.struct.point.Point3D_F64; import lombok.Getter; import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - * Observed point feature location on the image plane and its 3D position. - * - * @author Peter Abeles - */ -public class Point2D3D { - /** - * Observed location of the feature on the image plane - */ +/// Observed point feature location on the image plane and its 3D position. +public class Point2D3D implements MapFormattable { + /// Observed location of the feature on the image plane public @Getter @Setter Point2D_F64 observation; - /** - * 3D location of the feature in world coordinates - */ + /// 3D location of the feature in world coordinates public @Getter @Setter Point3D_F64 location; public Point2D3D() { @@ -48,9 +42,7 @@ public Point2D3D( Point2D_F64 observation, Point3D_F64 location ) { this.location = location; } - /** - * Sets 'this' to be identical to 'src'. - */ + /// Sets 'this' to be identical to 'src'. public Point2D3D setTo( Point2D3D src ) { this.observation.setTo(src.observation); this.location.setTo(src.location); @@ -77,4 +69,13 @@ public void zero() { public Point2D3D copy() { return new Point2D3D(observation.copy(), location.copy()); } + + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("observation", observation.formatMap(format), true) + + format.pair("location", location.formatMap(format), true) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D4D.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D4D.java index 427e46ba9d..5a9ceb5943 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D4D.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/Point2D4D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -22,20 +22,14 @@ import georegression.struct.point.Point4D_F64; import lombok.Getter; import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - * Observed point feature location on the image plane and its 3D homogeneous position. - * - * @author Peter Abeles - */ -public class Point2D4D { - /** - * Observed location of the feature on the image plane - */ +/// Observed point feature location on the image plane and its 3D homogeneous position. +public class Point2D4D implements MapFormattable { + /// Observed location of the feature on the image plane @Getter @Setter public Point2D_F64 observation; - /** - * 3D location of the feature in homogeneous world coordinates - */ + /// 3D location of the feature in homogeneous world coordinates @Getter @Setter public Point4D_F64 location; public Point2D4D() { @@ -48,9 +42,7 @@ public Point2D4D( Point2D_F64 observation, Point4D_F64 location ) { this.location = location; } - /** - * Sets 'this' to be identical to 'src'. - */ + /// Sets 'this' to be identical to 'src'. public Point2D4D setTo( Point2D4D src ) { observation.setTo(src.observation); location.setTo(src.location); @@ -65,4 +57,13 @@ public void zero() { public Point2D4D copy() { return new Point2D4D(observation.copy(), location.copy()); } + + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("observation", observation.formatMap(format), true) + + format.pair("location", location.formatMap(format), true) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex.java index dd5a3424ef..08dde38348 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -21,13 +21,15 @@ import georegression.struct.GeoTuple; import lombok.Getter; import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; /** * Base class for all PointIndex implementations. * * @author Peter Abeles */ -public abstract class PointIndex, P extends GeoTuple

> { +public abstract class PointIndex, P extends GeoTuple

> implements MapFormattable { public @Getter final P p; public @Getter @Setter int index; @@ -52,4 +54,13 @@ public void zero() { } public abstract T copy(); + + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("p", p.formatMap(format), true) + + format.pair("index", index, false) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex2D_F64.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex2D_F64.java index 579da091d1..ba13ab05ea 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex2D_F64.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex2D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -82,11 +82,4 @@ public boolean isIdentical( PointIndex2D_F64 o, double tol ) { public PointIndex2D_F64 copy() { return new PointIndex2D_F64(p, index); } - - @Override public String toString() { - return "PointIndex2D_F64{" + - "index=" + index + - ", p={ " + p.x + " , " + p.y + " }" + - '}'; - } } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex3D_F64.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex3D_F64.java index 08fae940d6..07e2152ef9 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex3D_F64.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex3D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex4D_F64.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex4D_F64.java index 6af9098e96..d7227532b7 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex4D_F64.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/PointIndex4D_F64.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslate2D.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslate2D.java index 89d28491f9..422fa4642c 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslate2D.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslate2D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,18 +20,17 @@ import lombok.Getter; import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - * Motion model for scale and translation: - * - * (x',y') = (x,y)*scale + (tranX , tranY) - * - * @author Peter Abeles - */ -public class ScaleTranslate2D { - /** Scaling */ +/// Motion model for scale and translation: +/// {@code (x',y') = (x,y)*scale + (tranX , tranY)} +/// +/// @author Peter Abeles +public class ScaleTranslate2D implements MapFormattable { + /// Scaling public @Getter @Setter double scale; - /** Translation along x and y axis */ + /// Translation along x and y axis public @Getter @Setter double transX, transY; public ScaleTranslate2D( double scale, double transX, double transY ) { @@ -53,4 +52,14 @@ public ScaleTranslate2D setTo( ScaleTranslate2D src ) { this.transY = src.transY; return this; } + + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("scale", scale, true) + + format.pair("transX", transX, true) + + format.pair("transY", transY, false) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslateRotate2D.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslateRotate2D.java index 76a39f6009..b631bff99d 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslateRotate2D.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/ScaleTranslateRotate2D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,25 +20,22 @@ import lombok.Getter; import lombok.Setter; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; -/** - * Motion model for scale, translation, and rotation: - * - * (x',y') = (x,y)*R*scale + (tranX , tranY) - * - * R is rotation matrix. - * - * @author Peter Abeles - */ -public class ScaleTranslateRotate2D { - /** Scaling */ +/// Motion model for scale, translation, and rotation: +/// +/// {@code (x',y') = (x,y)\*R\*scale + (tranX , tranY)} +/// R is rotation matrix. +public class ScaleTranslateRotate2D implements MapFormattable { + /// Scaling public @Getter @Setter double scale; - /** Translation along x and y axis */ + /// Translation along x and y axis public @Getter @Setter double transX, transY; - /** Angle of rotation */ + /// Angle of rotation public @Getter @Setter double theta; - public ScaleTranslateRotate2D( double theta, double scale, double transX, double transY ) { + public ScaleTranslateRotate2D( double scale, double transX, double transY, double theta ) { this.theta = theta; this.scale = scale; this.transX = transX; @@ -58,4 +55,15 @@ public ScaleTranslateRotate2D setTo( ScaleTranslateRotate2D src ) { this.transY = src.transY; return this; } + + @Override public String formatMap( MapPrintFormat format ) { + return format.itemPrefix + + format.pair("scale", scale, true) + + format.pair("transX", transX, true) + + format.pair("transY", transY, true) + + format.pair("theta", theta, false) + + format.itemSuffix; + } + + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} } diff --git a/main/boofcv-geo/src/main/java/boofcv/struct/geo/TrifocalTensor.java b/main/boofcv-geo/src/main/java/boofcv/struct/geo/TrifocalTensor.java index 2c08c98fd5..5565754f30 100644 --- a/main/boofcv-geo/src/main/java/boofcv/struct/geo/TrifocalTensor.java +++ b/main/boofcv-geo/src/main/java/boofcv/struct/geo/TrifocalTensor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -18,6 +18,9 @@ package boofcv.struct.geo; +import org.ejml.MapFormattable; +import org.ejml.MapPrintFormat; +import org.ejml.MatrixPrintFormat; import org.ejml.data.DMatrixRMaj; import org.ejml.dense.row.CommonOps_DDRM; import org.ejml.dense.row.SpecializedOps_DDRM; @@ -29,24 +32,18 @@ * * @author Peter Abeles */ -public class TrifocalTensor { +public class TrifocalTensor implements MapFormattable { public DMatrixRMaj T1 = new DMatrixRMaj(3, 3); public DMatrixRMaj T2 = new DMatrixRMaj(3, 3); public DMatrixRMaj T3 = new DMatrixRMaj(3, 3); public DMatrixRMaj getT( int index ) { - switch (index) { - case 0: - return T1; - - case 1: - return T2; - - case 2: - return T3; - } - - throw new IllegalArgumentException("Invalid index"); + return switch (index) { + case 0 -> T1; + case 1 -> T2; + case 2 -> T3; + default -> throw new IllegalArgumentException("Invalid index"); + }; } public void setTo( TrifocalTensor a ) { @@ -131,11 +128,18 @@ public void normalizeScale() { CommonOps_DDRM.scale(1.0/n, T3); } - @Override - public String toString() { - return "TrifocalTensor {\nT1:\n" + T1 + "\nT2:\n" + T2 + "\nT3:\n" + T3 + "}"; + @Override public String formatMap( MapPrintFormat format ) { + MatrixPrintFormat matrixFormat = format.convertToMatrix(); + + return format.itemPrefix + + format.pair("T1", T1.format(matrixFormat), true) + + format.pair("T2", T2.format(matrixFormat), true) + + format.pair("T3", T3.format(matrixFormat), false) + + format.itemSuffix; } + @Override public String toString() {return MapPrintFormat.DEFAULT.toString(this);} + public void print() { System.out.println(this); } diff --git a/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestDistanceScaleTranslateRotate2DSq.java b/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestDistanceScaleTranslateRotate2DSq.java index 7af576f7ee..91268d6a27 100644 --- a/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestDistanceScaleTranslateRotate2DSq.java +++ b/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestDistanceScaleTranslateRotate2DSq.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -30,7 +30,7 @@ public class TestDistanceScaleTranslateRotate2DSq extends BoofStandardJUnit { @Test void perfect() { - var model = new ScaleTranslateRotate2D(0.2, 1.5, -2, 3); + var model = new ScaleTranslateRotate2D(1.5, -2, 3, 0.2); AssociatedPair a = apply(-5, 4, model); @@ -41,7 +41,7 @@ public class TestDistanceScaleTranslateRotate2DSq extends BoofStandardJUnit { } @Test void noisy() { - var model = new ScaleTranslateRotate2D(0.2, 1.5, -2, 3); + var model = new ScaleTranslateRotate2D(1.5, -2, 3, 0.2); AssociatedPair a = apply(-5, 4, model); a.p2.x += 3.5; @@ -53,7 +53,7 @@ public class TestDistanceScaleTranslateRotate2DSq extends BoofStandardJUnit { } @Test void multiple() { - var model = new ScaleTranslateRotate2D(0.2, 1.5, -2, 3); + var model = new ScaleTranslateRotate2D(1.5, -2, 3, 0.2); AssociatedPair a = apply(-5, 4, model); a.p2.x += 3.5; diff --git a/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestGenerateScaleTranslateRotate2D.java b/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestGenerateScaleTranslateRotate2D.java index 18e6af0926..8164b01683 100644 --- a/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestGenerateScaleTranslateRotate2D.java +++ b/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestGenerateScaleTranslateRotate2D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -36,7 +36,7 @@ public class TestGenerateScaleTranslateRotate2D extends BoofStandardJUnit { double theta = rand.nextDouble()*Math.PI*2 - Math.PI; double scale = rand.nextDouble()*5 + 0.1; - ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(theta, scale, -2, 3); + ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(scale, -2, 3, theta); AssociatedPair a = TestDistanceScaleTranslateRotate2DSq.apply(-5, 4, model); AssociatedPair b = TestDistanceScaleTranslateRotate2DSq.apply(2, 3, model); diff --git a/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestModelManagerScaleTranslateRotate2D.java b/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestModelManagerScaleTranslateRotate2D.java index 1f77d77016..a3b1d54ada 100644 --- a/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestModelManagerScaleTranslateRotate2D.java +++ b/main/boofcv-geo/src/test/java/boofcv/alg/geo/robust/TestModelManagerScaleTranslateRotate2D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -36,7 +36,7 @@ public class TestModelManagerScaleTranslateRotate2D extends BoofStandardJUnit { @Test void copyModel() { ModelManagerScaleTranslateRotate2D alg = new ModelManagerScaleTranslateRotate2D(); - ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(1, 2, 3, 4); + ScaleTranslateRotate2D model = new ScaleTranslateRotate2D(2, 3, 4, 1); ScaleTranslateRotate2D found = new ScaleTranslateRotate2D(); alg.copyModel(model, found); diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraKannalaBrandt.java b/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraKannalaBrandt.java index 6556221068..d18aff2a16 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraKannalaBrandt.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraKannalaBrandt.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -18,24 +18,36 @@ package boofcv.struct.calib; +import org.ejml.MapPrintFormat; import org.ejml.UtilEjml; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; class TestCameraKannalaBrandt extends CommonCameraChecks { @Test void fsetSymmetric() { - CameraKannalaBrandt cam = new CameraKannalaBrandt().fsetSymmetric(0.1, 0.2); + var cam = new CameraKannalaBrandt().fsetSymmetric(0.1, 0.2); assertArrayEquals(new double[]{0.1, 0.2}, cam.symmetric, UtilEjml.TEST_F64); } @Test void fsetDistRadial() { - CameraKannalaBrandt cam = new CameraKannalaBrandt().fsetRadial(0.1, 0.2); + var cam = new CameraKannalaBrandt().fsetRadial(0.1, 0.2); assertArrayEquals(new double[]{0.1, 0.2}, cam.radial, UtilEjml.TEST_F64); } @Test void fsetDistTangent() { - CameraKannalaBrandt cam = new CameraKannalaBrandt().fsetTangent(0.1, 0.2); + var cam = new CameraKannalaBrandt().fsetTangent(0.1, 0.2); assertArrayEquals(new double[]{0.1, 0.2}, cam.tangent, UtilEjml.TEST_F64); } + + @Test void formatMap() { + var a = new CameraKannalaBrandt().fsetTangent(0.1, 0.2).fsetRadial(-0.1, -0.2).fsetSymmetric(3,4); + a.fsetK(1.1234,2,3,4,5,100,200); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{fx: 1.12, fy: 2, skew: 3, cx: 4, cy: 5, width: 100, height: 200, " + + "symmetric: {3, 4}, " + + "radial: {-0.1, -0.2}, radialTrig: {}, " + + "tangent: {0.1, 0.2}, tangentTrig: {}}", found); + } } diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinhole.java b/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinhole.java index 47267f466e..63ce8e3055 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinhole.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinhole.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -18,6 +18,7 @@ package boofcv.struct.calib; +import org.ejml.MapPrintFormat; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -25,7 +26,7 @@ public class TestCameraPinhole extends CommonCameraChecks { @Test void constructor_K() { - CameraPinhole p = new CameraPinhole(200,210,1,320,240,640,380); + var p = new CameraPinhole(200,210,1,320,240,640,380); assertEquals(200,p.fx,1e-8); assertEquals(210,p.fy,1e-8); @@ -37,7 +38,7 @@ public class TestCameraPinhole extends CommonCameraChecks { } @Test void fsetK() { - CameraPinhole p = new CameraPinhole(200,210,1,320,240,640,380); + var p = new CameraPinhole(200,210,1,320,240,640,380); assertSame(p, p.fsetK(201, 211, 2, 321, 241, 641, 381)); @@ -49,4 +50,10 @@ public class TestCameraPinhole extends CommonCameraChecks { assertEquals(641,p.width,1e-8); assertEquals(381,p.height,1e-8); } + + @Test void formatMap() { + var p = new CameraPinhole(200,210,1.1234,320,240,640,380); + String found = p.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{fx: 200, fy: 210, skew: 1.12, cx: 320, cy: 240, width: 640, height: 380}", found); + } } diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinholeBrown.java b/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinholeBrown.java index 3b42b06195..b50626827b 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinholeBrown.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/calib/TestCameraPinholeBrown.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -18,6 +18,7 @@ package boofcv.struct.calib; +import org.ejml.MapPrintFormat; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -25,20 +26,20 @@ public class TestCameraPinholeBrown extends CommonCameraChecks { @Test void set_radial() { - CameraPinholeBrown p = new CameraPinholeBrown(200,210,1,320,240,640,380); + var p = new CameraPinholeBrown(200,210,1,320,240,640,380); p.fsetRadial(1,2); p.fsetTangential(2,3); - CameraPinholeBrown f = new CameraPinholeBrown(); + var f = new CameraPinholeBrown(); f.setTo(p); equalsR(p,f); } @Test void set_pinhole() { - CameraPinhole p = new CameraPinhole(2020,2210,2,2,56,5,234); + var p = new CameraPinhole(2020,2210,2,2,56,5,234); - CameraPinholeBrown f = new CameraPinholeBrown(200,210,1,320,240,640,380); + var f = new CameraPinholeBrown(200,210,1,320,240,640,380); f.fsetRadial(1,2); f.fsetTangential(2,3); @@ -73,7 +74,7 @@ private void equalsR(CameraPinholeBrown expected, CameraPinholeBrown found ) { } @Test void fsetRadial() { - CameraPinholeBrown p = new CameraPinholeBrown(200,210,1,320,240,640,380); + var p = new CameraPinholeBrown(200,210,1,320,240,640,380); assertSame(p, p.fsetRadial(1.1, 2.2, 3.3)); @@ -94,7 +95,7 @@ private void equalsR(CameraPinholeBrown expected, CameraPinholeBrown found ) { } @Test void fsetTangential() { - CameraPinholeBrown p = new CameraPinholeBrown(200,210,1,320,240,640,380); + var p = new CameraPinholeBrown(200,210,1,320,240,640,380); assertSame(p, p.fsetTangential(1.1, 2.2)); @@ -112,7 +113,7 @@ private void equalsR(CameraPinholeBrown expected, CameraPinholeBrown found ) { } @Test void isDistorted() { - CameraPinholeBrown p = new CameraPinholeBrown(200,210,0,320,240,640,380); + var p = new CameraPinholeBrown(200,210,0,320,240,640,380); assertFalse(p.isDistorted()); assertFalse(p.fsetRadial(0,0).isDistorted()); @@ -120,4 +121,16 @@ private void equalsR(CameraPinholeBrown expected, CameraPinholeBrown found ) { assertFalse(p.fsetRadial(0,0).isDistorted()); assertTrue(p.fsetTangential(0, 0.1).isDistorted()); } + + @Test void formatMap() { + var p = new CameraPinholeBrown(200,210,1.1234,320,240,640,380). + fsetRadial(0.123, 4).fsetTangential(0.3, 0.4); + String found = p.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{fx: 200, fy: 210, skew: 1.12, cx: 320, cy: 240, width: 640, height: 380, radial: {0.12, 4}, t1: 0.3, t2: 0.4}", found); + + // Now will null radial + p.radial = null; + found = p.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{fx: 200, fy: 210, skew: 1.12, cx: 320, cy: 240, width: 640, height: 380, radial: {}, t1: 0.3, t2: 0.4}", found); + } } diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedPair.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedPair.java index 04974b1f3c..e437bf45b2 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedPair.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedPair.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,5 +19,17 @@ package boofcv.struct.geo; import boofcv.struct.StandardStructChecks; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; -public class TestAssociatedPair extends StandardStructChecks {{this.resetName = "zero";}} +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestAssociatedPair extends StandardStructChecks { + {this.resetName = "zero";} + + @Test void formatMap() { + var a = new AssociatedPair(2, -1, 1.2345, 3); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{p1: {x: 2, y: -1}, p2: {x: 1.23, y: 3}}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTriple.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTriple.java index f15c8861bd..03d24aab1e 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTriple.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTriple.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,6 +20,7 @@ import boofcv.struct.StandardStructChecks; import georegression.struct.point.Point2D_F64; +import org.ejml.MapPrintFormat; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -125,4 +126,10 @@ public class TestAssociatedTriple extends StandardStructChecks { assertTrue(b.p2.isIdentical(a.p2,1e-8)); assertTrue(b.p3.isIdentical(a.p3,1e-8)); } + + @Test void formatMap() { + var a = new AssociatedTriple().setTo(2, -1, 1.2345, 3, 4, 5); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{p1: {x: 2, y: -1}, p2: {x: 1.23, y: 3}, p3: {x: 4, y: 5}}", found); + } } diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleDN.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleDN.java new file mode 100644 index 0000000000..8de23c1abb --- /dev/null +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleDN.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.geo; + +import boofcv.struct.StandardStructChecks; +import org.ejml.MapPrintFormat; +import org.ejml.MatrixPrintFormat; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.InvocationTargetException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestAssociatedTupleDN extends StandardStructChecks { + // Need to override since the default constructor results in an empty list + @Override + protected Object createNew( Class type ) + throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { + if (type == AssociatedTupleDN.class) + return new AssociatedTupleDN(3); + return super.createNew(type); + } + + @Test void format_Matrix() { + var p = new AssociatedTupleDN(2); + p.set(0, 1.234, 2); + p.set(1, 3, 4); + String found = p.format(new MatrixPrintFormat().withPrecision(2)); + assertEquals("[{1.23, 2},\n{3, 4}]", found); + } + + @Test void formatMap() { + var p = new AssociatedTupleDN(2); + p.set(0, 1.234, 2); + p.set(1, 3, 4); + String found = p.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("[{x: 1.23, y: 2},\n{x: 3, y: 4}]", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleN.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleN.java new file mode 100644 index 0000000000..092cf45323 --- /dev/null +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestAssociatedTupleN.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.geo; + +import boofcv.struct.StandardStructChecks; +import georegression.struct.point.Point2D_F64; +import org.ejml.MapPrintFormat; +import org.ejml.MatrixPrintFormat; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.InvocationTargetException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestAssociatedTupleN extends StandardStructChecks { + + // Need to override since there is no default constructor + @Override + protected Object createNew( Class type ) + throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { + if (type == AssociatedTupleN.class) + return new AssociatedTupleN(3); + return super.createNew(type); + } + + @Test void format_Matrix() { + var p = new AssociatedTupleN(new Point2D_F64(1.234, 2), new Point2D_F64(3, 4)); + String found = p.format(new MatrixPrintFormat().withPrecision(2)); + assertEquals("[{1.23, 2},\n{3, 4}]", found); + } + + @Test void formatMap() { + var p = new AssociatedTupleN(new Point2D_F64(1.234, 2), new Point2D_F64(3, 4)); + String found = p.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("[{x: 1.23, y: 2},\n{x: 3, y: 4}]", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestGeoLL_F64.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestGeoLL_F64.java new file mode 100644 index 0000000000..732a229804 --- /dev/null +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestGeoLL_F64.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.geo; + +import boofcv.testing.BoofStandardJUnit; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestGeoLL_F64 extends BoofStandardJUnit { + @Test void formatMap() { + var a = new GeoLL_F64(1.2345, 2); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{lat: 1.23, lon: 2}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPairLineNorm.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPairLineNorm.java index 310a260f3f..15a97315e9 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPairLineNorm.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPairLineNorm.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -20,4 +20,6 @@ import boofcv.struct.StandardStructChecks; -public class TestPairLineNorm extends StandardStructChecks {{this.resetName = "zero";}} +public class TestPairLineNorm extends StandardStructChecks { + {this.resetName = "zero";} +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex2D_F64.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex2D_F64.java new file mode 100644 index 0000000000..1528328136 --- /dev/null +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex2D_F64.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.geo; + +import boofcv.testing.BoofStandardJUnit; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestPointIndex2D_F64 extends BoofStandardJUnit { + @Test void formatMap() { + var a = new PointIndex2D_F64(1.2345, 2, 34); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{p: {x: 1.23, y: 2}, index: 34}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex3D_F64.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex3D_F64.java new file mode 100644 index 0000000000..cb318f93db --- /dev/null +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex3D_F64.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.geo; + +import boofcv.testing.BoofStandardJUnit; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestPointIndex3D_F64 extends BoofStandardJUnit { + @Test void formatMap() { + var a = new PointIndex3D_F64(1.2345, 2, 34, 120); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{p: {x: 1.23, y: 2, z: 34}, index: 120}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex4D_F64.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex4D_F64.java new file mode 100644 index 0000000000..2ce9033182 --- /dev/null +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestPointIndex4D_F64.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. + * + * This file is part of BoofCV (http://boofcv.org). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package boofcv.struct.geo; + +import boofcv.testing.BoofStandardJUnit; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestPointIndex4D_F64 extends BoofStandardJUnit { + @Test void formatMap() { + var a = new PointIndex4D_F64(1.2345, 2, 34, 200, 120); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{p: {x: 1.23, y: 2, z: 34, w: 200}, index: 120}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslate2D.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslate2D.java index 1cc3ef75ab..e182c4e457 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslate2D.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslate2D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,5 +19,17 @@ package boofcv.struct.geo; import boofcv.struct.StandardStructChecks; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; -public class TestScaleTranslate2D extends StandardStructChecks {{this.resetName = "zero";}} +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestScaleTranslate2D extends StandardStructChecks { + {this.resetName = "zero";} + + @Test void formatMap() { + var a = new ScaleTranslate2D(1.2345, 2, 34); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{scale: 1.23, transX: 2, transY: 34}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslateRotate2D.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslateRotate2D.java index 92f6c7c63d..baf23cf6c4 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslateRotate2D.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestScaleTranslateRotate2D.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,5 +19,17 @@ package boofcv.struct.geo; import boofcv.struct.StandardStructChecks; +import org.ejml.MapPrintFormat; +import org.junit.jupiter.api.Test; -public class TestScaleTranslateRotate2D extends StandardStructChecks {{this.resetName = "zero";}} +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TestScaleTranslateRotate2D extends StandardStructChecks { + {this.resetName = "zero";} + + @Test void formatMap() { + var a = new ScaleTranslateRotate2D(2, 34, 0.9832, 1.2345); + String found = a.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{scale: 2, transX: 34, transY: 0.98, theta: 1.23}", found); + } +} diff --git a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestTrifocalTensor.java b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestTrifocalTensor.java index aac5791fb8..f61cea0515 100644 --- a/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestTrifocalTensor.java +++ b/main/boofcv-geo/src/test/java/boofcv/struct/geo/TestTrifocalTensor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -19,6 +19,7 @@ package boofcv.struct.geo; import boofcv.testing.BoofStandardJUnit; +import org.ejml.MapPrintFormat; import org.ejml.data.DMatrixRMaj; import org.ejml.dense.row.NormOps_DDRM; import org.junit.jupiter.api.Test; @@ -29,19 +30,19 @@ public class TestTrifocalTensor extends BoofStandardJUnit { @Test void getT() { - TrifocalTensor t = new TrifocalTensor(); + var t = new TrifocalTensor(); assertSame(t.T1, t.getT(0)); assertSame(t.T2, t.getT(1)); assertSame(t.T3, t.getT(2)); } @Test void set() { - TrifocalTensor t = new TrifocalTensor(); + var t = new TrifocalTensor(); t.T1.set(0,0,1); t.T2.set(0,0,2); t.T3.set(0,0,3); - TrifocalTensor a = new TrifocalTensor(); + var a = new TrifocalTensor(); a.setTo(t); assertEquals(a.T1.get(0, 0), 1); @@ -50,11 +51,11 @@ public class TestTrifocalTensor extends BoofStandardJUnit { } @Test void convertFrom() { - DMatrixRMaj A = new DMatrixRMaj(27,1); + var A = new DMatrixRMaj(27,1); for( int i = 0; i < 27; i++ ) A.set(i,i); - TrifocalTensor t = new TrifocalTensor(); + var t = new TrifocalTensor(); t.convertFrom(A); for( int i = 0; i < 27; i++ ) @@ -62,12 +63,12 @@ public class TestTrifocalTensor extends BoofStandardJUnit { } @Test void convertTo() { - TrifocalTensor t = new TrifocalTensor(); + var t = new TrifocalTensor(); for( int i = 0; i < 27; i++ ) t.getT( i/9 ).set(i % 9, i); - DMatrixRMaj A = new DMatrixRMaj(27,1); + var A = new DMatrixRMaj(27,1); t.convertTo(A); for( int i = 0; i < 27; i++ ) assertEquals(A.get(i), i); @@ -75,12 +76,12 @@ public class TestTrifocalTensor extends BoofStandardJUnit { } @Test void normalizeScale() { - TrifocalTensor t = new TrifocalTensor(); + var t = new TrifocalTensor(); for( int i = 0; i < 27; i++ ) t.getT( i/9 ).set(i%9,i); - DMatrixRMaj A = new DMatrixRMaj(27,1); + var A = new DMatrixRMaj(27,1); t.convertTo(A); double N = NormOps_DDRM.normF(A); @@ -89,4 +90,20 @@ public class TestTrifocalTensor extends BoofStandardJUnit { for( int i = 0; i < 27; i++ ) assertEquals(A.get(i)/N,t.getT( i/9 ).get(i%9),1e-8); } + + @Test void formatMap() { + var t = new TrifocalTensor(); + + for( int i = 0; i < 27; i++ ) + t.getT( i/9 ).set(i%9,i); + + String found = t.formatMap(new MapPrintFormat().withPrecision(2)); + assertEquals("{T1: [{0, 1, 2},\n" + + "{3, 4, 5},\n" + + "{6, 7, 8}], T2: [{9, 10, 11},\n" + + "{12, 13, 14},\n" + + "{15, 16, 17}], T3: [{18, 19, 20},\n" + + "{21, 22, 23},\n" + + "{24, 25, 26}]}", found); + } } diff --git a/main/boofcv-types/src/test/java/boofcv/testing/BoofStandardJUnit.java b/main/boofcv-types/src/test/java/boofcv/testing/BoofStandardJUnit.java index ac11dfec00..fe2467a66c 100644 --- a/main/boofcv-types/src/test/java/boofcv/testing/BoofStandardJUnit.java +++ b/main/boofcv-types/src/test/java/boofcv/testing/BoofStandardJUnit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Peter Abeles. All Rights Reserved. + * Copyright (c) 2026, Peter Abeles. All Rights Reserved. * * This file is part of BoofCV (http://boofcv.org). * @@ -69,12 +69,18 @@ public void revertStreams() { System.setErr(systemErr); } + /// Override to create a new instance that doesn't use the default constructor + protected Object createNew(Class type ) throws + NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { + return type.getConstructor().newInstance(); + } + /** - * Creates an instance of the class where all fields are assigned a random valuen + * Creates an instance of the class where all fields are assigned a random value */ - public static Object createNotDefault( Class type, Random rand ) { + public Object createNotDefault( Class type, Random rand ) { try { - Object config = type.getConstructor().newInstance(); + Object config = createNew(type); Field[] fields = type.getFields(); for (Field f : fields) { if (Modifier.isStatic(f.getModifiers())) @@ -259,7 +265,7 @@ protected void checkSetTo( Class type, boolean returnThis ) { try { m = findCompatibleSetTo(type); - Object dst = type.getConstructor().newInstance(); + Object dst = createNew(type); Object src = createNotDefault(type, rand); Field[] fields = type.getFields();