From d5571c13800d239c72eb7271ea3a4efaad06959b Mon Sep 17 00:00:00 2001
From: Oleg Alexandrov <oleg.alexandrov@gmail.com>
Date: Tue, 7 Nov 2023 14:20:44 -0800
Subject: [PATCH] Add radtan distortion (#575)

---
 include/ale/Distortion.h |  3 ++-
 src/Util.cpp             | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/include/ale/Distortion.h b/include/ale/Distortion.h
index 4372766..dd2aa4a 100644
--- a/include/ale/Distortion.h
+++ b/include/ale/Distortion.h
@@ -9,7 +9,8 @@ namespace ale {
     DAWNFC,
     LROLROCNAC,
     CAHVOR,
-    LUNARORBITER
+    LUNARORBITER,
+    RADTAN
   };
 }
 
diff --git a/src/Util.cpp b/src/Util.cpp
index 52e0800..8afcfa1 100644
--- a/src/Util.cpp
+++ b/src/Util.cpp
@@ -342,9 +342,9 @@ double getSemiMinorRadius(json isd) {
 // type. Defaults to transverse
 DistortionType getDistortionModel(json isd) {
   try {
-    json distoriton_subset = isd.at("optical_distortion");
+    json distortion_subset = isd.at("optical_distortion");
 
-    json::iterator it = distoriton_subset.begin();
+    json::iterator it = distortion_subset.begin();
 
     std::string distortion = (std::string)it.key();
 
@@ -362,6 +362,8 @@ DistortionType getDistortionModel(json isd) {
       return DistortionType::CAHVOR;
     } else if (distortion.compare("lunarorbiter") == 0) {
       return DistortionType::LUNARORBITER;
+    } else if (distortion.compare("radtan") == 0) {
+      return DistortionType::RADTAN;
     }
   } catch (...) {
     throw std::runtime_error("Could not parse the distortion model.");
@@ -528,6 +530,20 @@ std::vector<double> getDistortionCoeffs(json isd) {
         coefficients = std::vector<double>(4, 0.0);
       }
     } break;
+    case DistortionType::RADTAN: {
+      try {
+        coefficients = isd.at("optical_distortion")
+                          .at("radtan")
+                          .at("coefficients")
+                          .get<std::vector<double>>();
+
+        return coefficients;
+      } catch (...) {
+        throw std::runtime_error(
+            "Could not parse the radtan distortion model coefficients.");
+        coefficients = std::vector<double>(5, 0.0);
+      }
+    } break;
   }
   throw std::runtime_error(
       "Could not parse the distortion model coefficients.");
-- 
GitLab