From a686fa00a1c93f340bf01033247b60791a022cf3 Mon Sep 17 00:00:00 2001 From: Joseph Eng Date: Wed, 31 Jan 2024 15:27:59 -0800 Subject: [PATCH] Add AprilTagFieldLayout.loadStandardField() Also change AprilTagFields.loadFromResource() to use the new method --- .../wpi/first/apriltag/AprilTagFieldLayout.java | 17 +++++++++++++++++ .../edu/wpi/first/apriltag/AprilTagFields.java | 8 +------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java index 5d0e4248878..d073660161b 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UncheckedIOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; @@ -221,6 +222,22 @@ public void serialize(Path path) throws IOException { new ObjectMapper().writeValue(path.toFile(), this); } + /** + * Get a standard {@link AprilTagFieldLayout}. + * + * @param field The loadable AprilTag field layout. + * @return AprilTagFieldLayout of the field. + * @throws UncheckedIOException If the layout does not exist. + */ + public static AprilTagFieldLayout loadStandardField(AprilTagFields field) { + try { + return loadFromResource(field.m_resourceFile); + } catch (IOException e) { + throw new UncheckedIOException( + "Could not load AprilTagFieldLayout from " + field.m_resourceFile, e); + } + } + /** * Deserializes a field layout from a resource within a internal jar file. * diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java index 653151e6266..1b50c5ae972 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java @@ -4,7 +4,6 @@ package edu.wpi.first.apriltag; -import java.io.IOException; import java.io.UncheckedIOException; /** Loadable AprilTag field layouts. */ @@ -36,11 +35,6 @@ public enum AprilTagFields { * @throws UncheckedIOException If the layout does not exist */ public AprilTagFieldLayout loadAprilTagLayoutField() { - try { - return AprilTagFieldLayout.loadFromResource(m_resourceFile); - } catch (IOException e) { - throw new UncheckedIOException( - "Could not load AprilTagFieldLayout from " + m_resourceFile, e); - } + return AprilTagFieldLayout.loadStandardField(this); } }