Skip to content
Snippets Groups Projects
Commit b2a1867c authored by Fabian Tërnava's avatar Fabian Tërnava
Browse files

add objclass reader and writer in armem_objects

parent 00e6e554
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,8 @@ armarx_add_library(
server/attachments/Segment.h
client/class/ClassReader.h
client/class/ClassWriter.h
client/articulated_object/Reader.h
client/articulated_object/Writer.h
client/articulated_object/ArticulatedObjectReader.h
......@@ -55,6 +57,8 @@ armarx_add_library(
types.cpp
utils.cpp
client/class/ClassReader.cpp
client/class/ClassWriter.cpp
client/articulated_object/Reader.cpp
client/articulated_object/Writer.cpp
client/articulated_object/ArticulatedObjectReader.cpp
......
#include "ClassReader.h"
namespace armarx::armem::obj::clazz
{
std::optional<armem::clazz::ObjectClass>
ClassReader::getObjectClass(const std::string& providerName, const ObjectID& id)
{
auto mid = armarx::armem::MemoryID();
mid.memoryName = properties().memoryName;
mid.coreSegmentName = properties().coreSegmentName;
mid.providerSegmentName = providerName;
mid.entityName = id.str();
auto i = this->memoryReader().getLatestSnapshotIn(mid);
if (i.has_value() && i->size() == 1)
{
auto& instance = i->getInstance(0);
auto aron = instance.dataAs<armarx::armem::arondto::ObjectClass>();
armem::clazz::ObjectClass objClass;
armarx::armem::clazz::fromAron(aron, objClass);
return objClass;
}
return std::nullopt;
}
std::string
ClassReader::propertyPrefix() const
{
return "classReader.";
}
client::util::SimpleReaderBase::Properties
ClassReader::defaultProperties() const
{
client::util::SimpleReaderBase::Properties p;
p.memoryName = "Object";
p.coreSegmentName = "Class";
return p;
}
} // namespace armarx::armem::obj::clazz
/*
* 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/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <mutex>
#include <optional>
#include <RobotAPI/libraries/armem/client/util/SimpleReaderBase.h>
#include <RobotAPI/libraries/armem_objects/aron_conversions.h>
#include <RobotAPI/libraries/armem_objects/types.h>
namespace armarx::armem::obj::clazz
{
class ClassReader : public armem::client::util::SimpleReaderBase
{
public:
ClassReader() = default;
std::optional<armem::clazz::ObjectClass> getObjectClass(const std::string& providerName,
const armarx::ObjectID& id);
protected:
std::string propertyPrefix() const final;
Properties defaultProperties() const final;
private:
};
} // namespace armarx::armem::obj::clazz
#include "ClassWriter.h"
namespace armarx::armem::obj::clazz
{
bool
ClassWriter::commitObjectClass(const armarx::armem::clazz::ObjectClass& c,
const armarx::core::time::DateTime& referenceTime)
{
armarx::armem::arondto::ObjectClass objClassAron;
armarx::armem::clazz::toAron(objClassAron, c);
armarx::armem::MemoryID mid;
mid.memoryName = properties().memoryName;
mid.coreSegmentName = properties().coreSegmentName;
mid.providerSegmentName = properties().providerName;
mid.entityName = c.id.str();
auto commit = armarx::armem::Commit();
auto& update = commit.add();
update.confidence = 1.0f;
update.referencedTime = referenceTime;
update.sentTime = armarx::core::time::DateTime::Now();
update.entityID = mid;
update.instancesData = {objClassAron.toAron()};
auto res = this->memoryWriter().commit(commit);
return res.allSuccess();
}
std::string
ClassWriter::propertyPrefix() const
{
return "classWriter.";
}
client::util::SimpleWriterBase::Properties
ClassWriter::defaultProperties() const
{
client::util::SimpleWriterBase::Properties p;
p.memoryName = "Object";
p.coreSegmentName = "Class";
p.providerName = providerName;
return p;
}
} // namespace armarx::armem::obj::clazz
/*
* 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/>.
*
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#pragma once
#include <mutex>
#include <optional>
#include <RobotAPI/libraries/armem/client/util/SimpleWriterBase.h>
#include <RobotAPI/libraries/armem_objects/aron_conversions.h>
#include <RobotAPI/libraries/armem_objects/types.h>
namespace armarx::armem::obj::clazz
{
class ClassWriter : public armem::client::util::SimpleWriterBase
{
public:
ClassWriter(const std::string& p) : providerName(p){};
bool commitObjectClass(const armarx::armem::clazz::ObjectClass& c,
const armarx::core::time::DateTime& referenceTime);
protected:
std::string propertyPrefix() const final;
Properties defaultProperties() const final;
private:
const std::string providerName;
};
} // namespace armarx::armem::obj::clazz
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