[apriltag] Cache layout loaded from AprilTagFields resource json (#6385)

This commit is contained in:
Ryan Blue
2024-04-22 01:36:22 -04:00
committed by GitHub
parent d7dfa63ae9
commit b620b6a4dd
2 changed files with 14 additions and 5 deletions

View File

@@ -230,12 +230,19 @@ public class AprilTagFieldLayout {
* @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());
}
/**

View File

@@ -24,6 +24,8 @@ public enum AprilTagFields {
/** Resource filename. */
public final String m_resourceFile;
AprilTagFieldLayout m_fieldLayout;
AprilTagFields(String resourceFile) {
m_resourceFile = kBaseResourceDir + resourceFile;
}