Skip to content
Snippets Groups Projects
Commit aa6f304d authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Merge branch 'object-pose-json-serialization' into 'master'

Object pose JSON serialization

See merge request ArmarX/RobotAPI!77
parents 55e93590 1d473e1a
Loading
......@@ -16,6 +16,7 @@ set(SOURCES
plugins/ObjectPoseClientPlugin.cpp
ice_conversions.cpp
json_conversions.cpp
ObjectPose.cpp
)
set(HEADERS
......@@ -25,6 +26,7 @@ set(HEADERS
plugins/ObjectPoseClientPlugin.h
ice_conversions.h
json_conversions.h
ObjectPose.h
)
......
#include "json_conversions.h"
#include <SimoxUtility/json/eigen_conversion.h>
#include <SimoxUtility/shapes/json_conversions.h>
#include <RobotAPI/libraries/ArmarXObjects/json_conversions.h>
#include "ice_conversions.h"
void armarx::objpose::to_json(nlohmann::json& j, const ObjectPose& op)
{
j["providerName"] = op.providerName;
j["objectType"] = ObjectTypeEnumNames.to_name(op.objectType);
j["objectID"] = op.objectID;
j["objectPoseRobot"] = op.objectPoseRobot;
j["objectPoseGlobal"] = op.objectPoseGlobal;
j["objectPoseOriginal"] = op.objectPoseOriginal;
j["objectPoseOriginalFrame"] = op.objectPoseOriginalFrame;
j["robotConfig"] = op.robotConfig;
j["robotPose"] = op.robotPose;
j["confidence"] = op.confidence;
j["timestampMicroSeconds"] = op.timestamp.toMicroSeconds();
if (op.localOOBB)
{
j["localOOBB"] = *op.localOOBB;
}
}
void armarx::objpose::from_json(const nlohmann::json& j, ObjectPose& op)
{
op.providerName = j.at("providerName");
op.objectType = ObjectTypeEnumNames.from_name(j.at("objectType"));
op.objectID = j.at("objectID");
op.objectPoseRobot = j.at("objectPoseRobot");
op.objectPoseGlobal = j.at("objectPoseGlobal");
op.objectPoseOriginal = j.at("objectPoseOriginal");
op.objectPoseOriginalFrame = j.at("objectPoseOriginalFrame");
op.robotConfig = j.at("robotConfig").get<std::map<std::string, float>>();
op.robotPose = j.at("robotPose");
op.confidence = j.at("confidence");
op.timestamp = IceUtil::Time::microSeconds(j.at("timestampMicroSeconds"));
if (j.count("localOOBB"))
{
op.localOOBB = j.at("localOOBB").get<simox::OrientedBoxf>();
}
}
#pragma once
#include <SimoxUtility/json/json.hpp>
#include "ObjectPose.h"
namespace armarx::objpose
{
void to_json(nlohmann::json& j, const ObjectPose& op);
void from_json(const nlohmann::json& j, ObjectPose& op);
}
/*
* 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::ArmarXObjects
* @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
* @date 2020
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include "ArmarXObjects.h"
namespace armarx
{
}
......@@ -8,11 +8,11 @@ set(LIBS
)
set(LIB_FILES
ArmarXObjects.cpp
ObjectID.cpp
ObjectInfo.cpp
ObjectFinder.cpp
json_conversions.cpp
)
set(LIB_HEADERS
ArmarXObjects.h
......@@ -20,6 +20,8 @@ set(LIB_HEADERS
ObjectID.h
ObjectInfo.h
ObjectFinder.h
json_conversions.h
)
......
......@@ -30,6 +30,10 @@ namespace armarx
{
return _instanceName;
}
inline void setInstanceName(const std::string& instanceName)
{
this->_instanceName = instanceName;
}
/// Return "dataset/className" or "dataset/className/instanceName".
std::string str() const;
......
#include "json_conversions.h"
void armarx::to_json(nlohmann::json& j, const ObjectID& id)
{
j["dataset"] = id.dataset();
j["className"] = id.className();
j["instanceName"] = id.instanceName();
j["str"] = id.str();
}
void armarx::from_json(const nlohmann::json& j, ObjectID& id)
{
id =
{
j.at("dataset").get<std::string>(),
j.at("className").get<std::string>(),
j.at("instanceName").get<std::string>()
};
}
#pragma once
#include <SimoxUtility/json/json.hpp>
#include "ObjectID.h"
namespace armarx
{
void to_json(nlohmann::json& j, const ObjectID& value);
void from_json(const nlohmann::json& j, ObjectID& value);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment