From 6dfd04d2229496b6bea7dbfba01832193e83f738 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Thu, 24 Jun 2021 18:39:17 +0200
Subject: [PATCH] Add SceneSnapshot class with JSON serialization

---
 .../libraries/armem_objects/CMakeLists.txt    |  4 ++
 .../libraries/armem_objects/SceneSnapshot.cpp | 39 ++++++++++++++
 .../libraries/armem_objects/SceneSnapshot.h   | 53 +++++++++++++++++++
 3 files changed, 96 insertions(+)
 create mode 100644 source/RobotAPI/libraries/armem_objects/SceneSnapshot.cpp
 create mode 100644 source/RobotAPI/libraries/armem_objects/SceneSnapshot.h

diff --git a/source/RobotAPI/libraries/armem_objects/CMakeLists.txt b/source/RobotAPI/libraries/armem_objects/CMakeLists.txt
index 8c0f625f0..51296814f 100644
--- a/source/RobotAPI/libraries/armem_objects/CMakeLists.txt
+++ b/source/RobotAPI/libraries/armem_objects/CMakeLists.txt
@@ -20,6 +20,8 @@ armarx_add_library(
         aron_conversions.h
         aron_forward_declarations.h
 
+        SceneSnapshot.h
+
         server/class/FloorVis.h
         server/class/Segment.h
 
@@ -46,6 +48,8 @@ armarx_add_library(
     SOURCES
         aron_conversions.cpp
 
+        SceneSnapshot.cpp
+
         server/class/FloorVis.cpp
         server/class/Segment.cpp
 
diff --git a/source/RobotAPI/libraries/armem_objects/SceneSnapshot.cpp b/source/RobotAPI/libraries/armem_objects/SceneSnapshot.cpp
new file mode 100644
index 000000000..8c9297558
--- /dev/null
+++ b/source/RobotAPI/libraries/armem_objects/SceneSnapshot.cpp
@@ -0,0 +1,39 @@
+#include "SceneSnapshot.h"
+
+#include <SimoxUtility/json.h>
+
+
+namespace armarx::armem::obj
+{
+}
+
+
+void armarx::armem::obj::to_json(nlohmann::json& j, const SceneSnapshot::Object& rhs)
+{
+    j["class"] = rhs.classID.str();
+    j["collection"] = rhs.collection;
+    j["postion"] = rhs.postion;
+    j["orientation"] = rhs.orientation;
+}
+
+
+void armarx::armem::obj::from_json(const nlohmann::json& j, SceneSnapshot::Object& rhs)
+{
+    rhs.classID = ObjectID(j.at("class").get<std::string>());
+    rhs.collection = j.at("collection");
+    j.at("postion").get_to(rhs.postion);
+    j.at("orientation").get_to(rhs.orientation);
+}
+
+
+
+void armarx::armem::obj::to_json(nlohmann::json& j, const SceneSnapshot& rhs)
+{
+    j["objects"] = rhs.objects;
+}
+
+
+void armarx::armem::obj::from_json(const nlohmann::json& j, SceneSnapshot& rhs)
+{
+    j.at("objects").get_to(rhs.objects);
+}
diff --git a/source/RobotAPI/libraries/armem_objects/SceneSnapshot.h b/source/RobotAPI/libraries/armem_objects/SceneSnapshot.h
new file mode 100644
index 000000000..5fe5192a4
--- /dev/null
+++ b/source/RobotAPI/libraries/armem_objects/SceneSnapshot.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::ArmarXObjects::ObjectMemory
+ * @author     Rainer Kartmann ( rainer dot kartmann at kit dot edu )
+ * @date       2021
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+#pragma once
+
+#include <SimoxUtility/json/json.hpp>
+
+#include <Eigen/Geometry>
+
+#include <RobotAPI/libraries/ArmarXObjects/ObjectID.h>
+
+
+namespace armarx::armem::obj
+{
+
+    struct SceneSnapshot
+    {
+        struct Object
+        {
+            ObjectID classID;
+            std::string collection;
+
+            Eigen::Vector3f postion = Eigen::Vector3f::Zero();
+            Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity();
+        };
+        std::vector<Object> objects;
+    };
+
+    void to_json(nlohmann::json& j, const SceneSnapshot::Object& rhs);
+    void from_json(const nlohmann::json& j, SceneSnapshot::Object& rhs);
+
+    void to_json(nlohmann::json& j, const SceneSnapshot& rhs);
+    void from_json(const nlohmann::json& j, SceneSnapshot& rhs);
+
+}
-- 
GitLab