diff --git a/source/RobotAPI/libraries/armem/server/ltm/base/detail/EntityBase.h b/source/RobotAPI/libraries/armem/server/ltm/base/detail/EntityBase.h index 9dedb572fdc8b4ff31c6018f238009d45fde6763..15ebde328ec72b9f189f542087fd7753c2a3faf0 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/base/detail/EntityBase.h +++ b/source/RobotAPI/libraries/armem/server/ltm/base/detail/EntityBase.h @@ -59,11 +59,11 @@ namespace armarx::armem::server::ltm } /// iterate over all entity snapshots of this ltm - virtual bool forEachSnapshot(std::function<void(EntitySnapshotT&)>&& func) const = 0; - virtual bool forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshotT&)>&& func) const = 0; - virtual bool forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshotT&)>&& func) const = 0; - virtual bool forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshotT&)>&& func) const = 0; - virtual bool forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshotT&)>&& func) const = 0; + virtual bool forEachSnapshot(std::function<void(EntitySnapshotT&)> func) const = 0; + virtual bool forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshotT&)> func) const = 0; + virtual bool forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshotT&)> func) const = 0; + virtual bool forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshotT&)> func) const = 0; + virtual bool forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshotT&)> func) const = 0; /// find entity snapshot segment virtual std::shared_ptr<EntitySnapshotT> findSnapshot(const Time&) const = 0; diff --git a/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h b/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h index bec7576234c8f6bbc9064745f2d0cdc0f8ef333b..c0973aa90b7d54a3efde6f331e8ddaab65e0393b 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/server/ltm/base/detail/MemoryBase.h @@ -126,7 +126,7 @@ namespace armarx::armem::server::ltm virtual bool forEachCoreSegment(std::function<void(CoreSegmentT&)>&& func) const = 0; /// find core segment - virtual std::shared_ptr<CoreSegmentT> findCoreSegment(const std::string&) const = 0; + virtual std::shared_ptr<CoreSegmentT> findCoreSegment(const std::string&) const = 0; // TODO make unique!! /// default parameters. Implementation should use the configuration to configure virtual void createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix) diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp b/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp index 6c87da45e576c10c18c6680141e00ed8c19aa3ba..8b00d8d39b8fa49de6c31d8b617549d97e6a45cb 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.cpp @@ -21,7 +21,7 @@ namespace armarx::armem::server::ltm::disk { } - bool Entity::forEachSnapshot(std::function<void(EntitySnapshot&)>&& func) const + bool Entity::forEachSnapshot(std::function<void(EntitySnapshot&)> func) const { auto mPath = getMemoryBasePathForMode(currentMode, currentExport); auto relPath = getRelativePathForMode(currentMode); @@ -75,7 +75,7 @@ namespace armarx::armem::server::ltm::disk return true; } - bool Entity::forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshot&)>&& func) const + bool Entity::forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshot&)> func) const { ARMARX_WARNING << "PLEASE NOTE THAT QUERYING THE LTM INDEX WISE MAY BE BUGGY BECAUSE THE FILESYSTEM ITERATOR IS UNSORTED!"; @@ -106,7 +106,7 @@ namespace armarx::armem::server::ltm::disk return forEachSnapshot(std::move(f)); } - bool Entity::forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshot&)>&& func) const + bool Entity::forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshot&)> func) const { auto f = [&](EntitySnapshot& e) { @@ -120,7 +120,7 @@ namespace armarx::armem::server::ltm::disk return forEachSnapshot(std::move(f)); } - bool Entity::forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshot&)>&& func) const + bool Entity::forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshot&)> func) const { auto f = [&](EntitySnapshot& e) { @@ -134,7 +134,7 @@ namespace armarx::armem::server::ltm::disk return forEachSnapshot(std::move(f)); } - bool Entity::forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshot&)>&& func) const + bool Entity::forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshot&)> func) const { auto f = [&](EntitySnapshot& e) { diff --git a/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.h b/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.h index 759b22733612c700ec0461541976cf3872d9df07..3d98ef1bf8abe315e005a110ad6fa807f373d7ba 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.h +++ b/source/RobotAPI/libraries/armem/server/ltm/disk/Entity.h @@ -18,11 +18,11 @@ namespace armarx::armem::server::ltm::disk public: Entity(const std::filesystem::path& parentPath, const MemoryID& id, const std::shared_ptr<Processors>& p, const DiskMemoryItem::MemoryEncodingMode mode, const unsigned long e); - bool forEachSnapshot(std::function<void(EntitySnapshot&)>&& func) const override; - bool forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshot&)>&& func) const override; - bool forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshot&)>&& func) const override; - bool forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshot&)>&& func) const override; - bool forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshot&)>&& func) const override; + bool forEachSnapshot(std::function<void(EntitySnapshot&)> func) const override; + bool forEachSnapshotInIndexRange(long first, long last, std::function<void(EntitySnapshot&)> func) const override; + bool forEachSnapshotInTimeRange(const Time& min, const Time& max, std::function<void(EntitySnapshot&)> func) const override; + bool forEachSnapshotBeforeOrAt(const Time& time, std::function<void(EntitySnapshot&)> func) const override; + bool forEachSnapshotBefore(const Time& time, std::function<void(EntitySnapshot&)> func) const override; std::shared_ptr<EntitySnapshot> findSnapshot(const Time&) const override; std::shared_ptr<EntitySnapshot> findLatestSnapshot() const override; diff --git a/source/RobotAPI/libraries/aron/converter/binary/CMakeLists.txt b/source/RobotAPI/libraries/aron/converter/binary/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7fa2684a23d3ef1e887a5f11b1c5aa83cbbe4b8f --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/binary/CMakeLists.txt @@ -0,0 +1,34 @@ +set(LIB_NAME aronivtconverter) + +armarx_component_set_name("${LIB_NAME}") +armarx_set_target("Library: ${LIB_NAME}") + +armarx_build_if(IVT_FOUND "IVT not available") +armarx_build_if(OpenCV_FOUND "OpenCV not available") + +set(LIBS + aron + ivt + ivtopencv + + ${IVT_LIBRARIES} +) + +set(LIB_FILES + IVTConverter.cpp +) + +set(LIB_HEADERS + IVTConverter.h +) + +armarx_add_library("${LIB_NAME}" "${LIB_FILES}" "${LIB_HEADERS}" "${LIBS}") + +if(IVT_FOUND) + target_include_directories(aronivtconverter + SYSTEM PUBLIC + ${IVT_INCLUDE_DIRS} + ) +endif() + +add_library(RobotAPI::aron::converter::ivt ALIAS aronivtconverter) diff --git a/source/RobotAPI/libraries/aron/converter/binary/LTMVectorRepresentationConverter.cpp b/source/RobotAPI/libraries/aron/converter/binary/LTMVectorRepresentationConverter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..999359d6b79ef56bbe7352263556ad71316e7384 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/binary/LTMVectorRepresentationConverter.cpp @@ -0,0 +1,53 @@ +/* + * This file is part of ArmarX. + * + * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), + * Karlsruhe Institute of Technology (KIT), all rights reserved. + * + * 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 Peller-Konrad (fabian dot peller-konrad at kit dot edu) + * @copyright http://www.gnu.org/licenses/gpl-2.0.txt + * GNU General Public License + */ + +// STD/STL +#include <numeric> + +// Header +#include "IVTConverter.h" + +namespace armarx::aron::converter +{ + std::shared_ptr<CByteImage> AronIVTConverter::ConvertToCByteImage(const data::NDArrayPtr& nav) + { + ARMARX_CHECK_NOT_NULL(nav); + + if (nav->getShape().size() != 3) // +1 for bytes per pixel + { + throw error::AronException(__PRETTY_FUNCTION__, "The size of an NDArray does not match.", nav->getPath()); + } + auto dims = nav->getShape(); + + auto ret = std::make_shared<CByteImage>(); + ret->Set(dims[0], dims[1], static_cast<CByteImage::ImageType>(std::stoi(nav->getType()))); + memcpy(reinterpret_cast<unsigned char*>(ret->pixels), nav->getData(), std::accumulate(std::begin(dims), std::end(dims), 1, std::multiplies<int>())); + return ret; + } + + data::NDArrayPtr ConvertFromCByteImage(const std::shared_ptr<CByteImage>& img) + { + // TODO: + return nullptr; + } +} diff --git a/source/RobotAPI/libraries/aron/converter/binary/LTMVectorRepresentationConverter.h b/source/RobotAPI/libraries/aron/converter/binary/LTMVectorRepresentationConverter.h new file mode 100644 index 0000000000000000000000000000000000000000..6d0c23d3b598c7dc55334c7181fa39885ee15ce4 --- /dev/null +++ b/source/RobotAPI/libraries/aron/converter/binary/LTMVectorRepresentationConverter.h @@ -0,0 +1,45 @@ +/* +* 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 Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#pragma once + +// STD/STL +#include <memory> +#include <string> + +// IVT +#include <Image/ByteImage.h> + +// ArmarX +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/core/data/variant/complex/NDArray.h> + + +namespace armarx::aron::converter +{ + class AronIVTConverter + { + AronIVTConverter() = delete; + public: + static std::shared_ptr<CByteImage> ConvertToCByteImage(const data::NDArrayPtr&); + static data::NDArrayPtr ConvertFromCByteImage(const std::shared_ptr<CByteImage>&); + }; +}