Skip to content

Commit

Permalink
[apriltag] Cache layout loaded from AprilTagFields resource json (wpi…
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue authored and chauser committed May 30, 2024
1 parent 0038caf commit 2eadedb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,19 @@ public void serialize(Path path) throws IOException {
* @throws UncheckedIOException If the layout does not exist.
*/
public static AprilTagFieldLayout loadField(AprilTagFields field) {
try {
return loadFromResource(field.m_resourceFile);
} catch (IOException e) {
throw new UncheckedIOException(
"Could not load AprilTagFieldLayout from " + field.m_resourceFile, e);
if (field.m_fieldLayout == null) {
try {
field.m_fieldLayout = loadFromResource(field.m_resourceFile);
} catch (IOException e) {
throw new UncheckedIOException(
"Could not load AprilTagFieldLayout from " + field.m_resourceFile, e);
}
}
// Copy layout because the layout's origin is mutable
return new AprilTagFieldLayout(
field.m_fieldLayout.getTags(),
field.m_fieldLayout.getFieldLength(),
field.m_fieldLayout.getFieldWidth());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public enum AprilTagFields {
/** Resource filename. */
public final String m_resourceFile;

AprilTagFieldLayout m_fieldLayout;

AprilTagFields(String resourceFile) {
m_resourceFile = kBaseResourceDir + resourceFile;
}
Expand Down

0 comments on commit 2eadedb

Please sign in to comment.