diff --git a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp index 1db77c2f32c4a2b2278abcd9fbdfe860ca081f95..d8b6e4f89038a42fc137a78316cfa3fbd7bc7eb0 100644 --- a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.cpp @@ -22,13 +22,9 @@ #include "ExampleMemoryClient.h" -#include <random> - -#include <SimoxUtility/color/cmaps.h> - -#include <ArmarXCore/core/exceptions/local/ExpressionException.h> -#include <ArmarXCore/core/time/CycleUtil.h> +#include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h> +#include <RobotAPI/libraries/armem/client/MemoryNameSystem.h> #include <RobotAPI/libraries/armem/server/MemoryRemoteGui.h> #include <RobotAPI/libraries/armem/client/query/Builder.h> #include <RobotAPI/libraries/armem/client/query/query_fns.h> @@ -37,7 +33,16 @@ #include <RobotAPI/libraries/armem/core/operations.h> #include <RobotAPI/libraries/armem/core/wm/ice_conversions.h> -#include <RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.aron.generated.h> +#include <ArmarXCore/core/exceptions/local/ExpressionException.h> +#include <ArmarXCore/core/time/CycleUtil.h> + +#include <SimoxUtility/color/cmaps.h> +#include <SimoxUtility/math/pose/pose.h> + +#include <Eigen/Geometry> + +#include <random> + #define STORE_IMAGES 0 @@ -130,7 +135,6 @@ namespace armarx { ARMARX_IMPORTANT << "Running example."; run_started = IceUtil::Time::now(); - std::srand(std::time(nullptr)); armem::MemoryID snapshotID = commitSingleSnapshot(exampleEntityID); if (true) @@ -185,6 +189,9 @@ namespace armarx armem::MemoryID ExampleMemoryClient::commitSingleSnapshot(const armem::MemoryID& entityID) { + std::default_random_engine gen(std::random_device{}()); + std::uniform_int_distribution<int> distrib(-20, 20); + // Prepare the update with some empty instances. armem::EntityUpdate update; update.entityID = entityID; @@ -200,7 +207,7 @@ namespace armarx auto sqrt = std::make_shared<aron::datanavigator::DoubleNavigator>(std::sqrt(diff)); auto lin = std::make_shared<aron::datanavigator::LongNavigator>(static_cast<long>(diff * 1000)); - auto rand = std::make_shared<aron::datanavigator::IntNavigator>(std::rand()); + auto rand = std::make_shared<aron::datanavigator::IntNavigator>(distrib(gen)); dict1->addElement("sin", sin); dict1->addElement("cos", cos); @@ -386,34 +393,24 @@ namespace armarx { "three", 3 }, }; + data.the_position = { 42, 24, 4224 }; + data.the_orientation = Eigen::AngleAxisf(1.57f, Eigen::Vector3f(1, 1, 1).normalized()); + data.the_pose = simox::math::pose(data.the_position, data.the_orientation); + + data.the_3x1_vector = { 24, 42, 2442 }; + data.the_4x4_matrix = 42 * Eigen::Matrix4f::Identity(); + toAron(data.memoryLink, armem::MemoryID()); simox::ColorMap cmap = simox::color::cmaps::plasma(); - { - data.the_ivt_image = std::make_shared<CByteImage>(); - CByteImage& image = *data.the_ivt_image; - image.Set(15, 35, CByteImage::ImageType::eRGB24); - cmap.set_vlimits(0, float(image.width + image.height)); - for (int row = 0; row < image.height; ++row) - { - for (int col = 0; col < image.width; ++col) - { - simox::Color color = cmap(float(row + col)); - unsigned char* p = &image.pixels[(row * image.width + col) * image.bytesPerPixel]; - p[0] = color.r; - p[1] = color.g; - p[2] = color.b; - } - } - } { cv::Mat& image = data.the_rgb24_image; image.create(10, 20, image.type()); cmap.set_vlimits(0, float(image.cols + image.rows)); using Pixel = cv::Point3_<uint8_t>; - image.forEach<Pixel>([&cmap](Pixel& pixel, const int position[]) -> void + image.forEach<Pixel>([&cmap](Pixel& pixel, const int index[]) -> void { - simox::Color color = cmap(float(position[0] + position[1])); + simox::Color color = cmap(float(index[0] + index[1])); pixel.x = color.r; pixel.y = color.g; pixel.z = color.b; @@ -428,18 +425,18 @@ namespace armarx { cv::Mat& image = data.the_depth32_image; image.create(20, 10, image.type()); - image.forEach<float>([&image](float& pixel, const int position[]) -> void + image.forEach<float>([&image](float& pixel, const int index[]) -> void { - pixel = 100 * float(position[0] + position[1]) / float(image.rows + image.cols); + pixel = 100 * float(index[0] + index[1]) / float(image.rows + image.cols); }); #if STORE_IMAGES cmap.set_vlimits(0, 100); cv::Mat rgb(image.rows, image.cols, CV_8UC3); using Pixel = cv::Point3_<uint8_t>; - rgb.forEach<Pixel>([&image, &cmap](Pixel& pixel, const int position[]) -> void + rgb.forEach<Pixel>([&image, &cmap](Pixel& pixel, const int index[]) -> void { - simox::Color color = cmap(image.at<float>(position)); + simox::Color color = cmap(image.at<float>(index)); pixel.x = color.r; pixel.y = color.g; pixel.z = color.b; diff --git a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h index 40aa30326633f0afb3f97e36ada659918f5dafa1..40eb57625848ba442e7be2abb10ed1c832ee8440 100644 --- a/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h +++ b/source/RobotAPI/components/armem/client/ExampleMemoryClient/ExampleMemoryClient.h @@ -23,20 +23,17 @@ #pragma once +#include <RobotAPI/libraries/armem/client/plugins/ListeningPluginUser.h> +#include <RobotAPI/libraries/armem/client/Reader.h> +#include <RobotAPI/libraries/armem/client/Writer.h> +#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> +#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> + +#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> -// ArmarX #include <ArmarXCore/core/Component.h> #include <ArmarXCore/interface/observers/ObserverInterface.h> #include <ArmarXCore/util/tasks.h> -#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h> - -// RobotAPI -#include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> -#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h> -#include <RobotAPI/libraries/armem/client/plugins.h> -#include <RobotAPI/interface/armem/server/MemoryInterface.h> -#include <RobotAPI/libraries/armem/client/Reader.h> -#include <RobotAPI/libraries/armem/client/Writer.h> namespace armarx @@ -56,8 +53,8 @@ namespace armarx */ class ExampleMemoryClient : virtual public armarx::Component, - virtual public armarx::armem::client::ComponentPluginUser, - virtual public LightweightRemoteGuiComponentPluginUser + virtual public armarx::armem::ListeningClientPluginUser, + virtual public armarx::LightweightRemoteGuiComponentPluginUser { public: diff --git a/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml index 5c49bef1660bbb3eb2fa336c83ad865bb7bf2e9e..6347fef0adf48e84d1104985481b05732db7b11f 100644 --- a/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml +++ b/source/RobotAPI/components/armem/server/ExampleMemory/aron/ExampleData.xml @@ -1,104 +1,114 @@ -<!--Some fancy comment --> +<!-- +An example data containing different native ARON types. +--> <?xml version="1.0" encoding="UTF-8" ?> <AronTypeDefinition> - <CodeIncludes> - <Include include="<Eigen/Core>" /> - <Include include="<Image/ByteImage.h>" /> - <Include include="<opencv2/core/core.hpp>" /> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /> - </CodeIncludes> + <CodeIncludes> + <!-- These should not be necessary in the future: --> + <Include include="<Eigen/Core>" /> <!-- For Position, Pose and Matrix. --> + <Include include="<Eigen/Geometry>" /> <!-- For Orientation. --> + <Include include="<opencv2/core/core.hpp>" /> <!-- For Image. --> + <!--Include include="<RobotAPI/libraries/armem/aron/MemoryID.aron.generated.h>" /--> + </CodeIncludes> - <AronIncludes> - <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" /> - </AronIncludes> + <AronIncludes> + <Include include="<RobotAPI/libraries/armem/aron/MemoryID.xml>" autoinclude="true" /> + </AronIncludes> - <GenerateTypes> - <Object name='armarx::armem::example::ExampleData'> + <GenerateTypes> + <Object name='armarx::armem::example::ExampleData'> - <ObjectChild key='the_int'> - <Int /> - </ObjectChild> - <ObjectChild key='the_long'> - <Long /> - </ObjectChild> - <ObjectChild key='the_float'> - <Float /> - </ObjectChild> - <ObjectChild key='the_double'> - <Double /> - </ObjectChild> - <ObjectChild key='the_string'> + <ObjectChild key='the_int'> + <Int /> + </ObjectChild> + <ObjectChild key='the_long'> + <Long /> + </ObjectChild> + <ObjectChild key='the_float'> + <Float /> + </ObjectChild> + <ObjectChild key='the_double'> + <Double /> + </ObjectChild> + <ObjectChild key='the_string'> <String /> - </ObjectChild> - <ObjectChild key='the_bool'> - <Bool /> - </ObjectChild> + </ObjectChild> + <ObjectChild key='the_bool'> + <Bool /> + </ObjectChild> - <ObjectChild key='the_eigen_position'> - <EigenMatrix rows="3" cols="1" type="float" /> - </ObjectChild> - <ObjectChild key='the_eigen_pose'> - <EigenMatrix rows="4" cols="4" type="float" /> - </ObjectChild> - <ObjectChild key='the_ivt_image'> - <IVTCByteImage type="GrayScale" shared_ptr="true"/> - </ObjectChild> - <ObjectChild key='the_rgb24_image'> - <Image pixelType="rgb24"/> - </ObjectChild> - <ObjectChild key='the_depth32_image'> - <Image pixelType="depth32"/> - </ObjectChild> + <ObjectChild key='the_position'> + <Position /> + </ObjectChild> + <ObjectChild key='the_orientation'> + <Orientation /> + </ObjectChild> + <ObjectChild key='the_pose'> + <Pose /> + </ObjectChild> - <ObjectChild key='the_float_list'> - <List> - <Float /> - </List> - </ObjectChild> - <ObjectChild key='the_int_list'> - <List> - <Int /> - </List> - </ObjectChild> - <ObjectChild key='the_string_list'> - <List> - <String /> - </List> - </ObjectChild> + <ObjectChild key='the_3x1_vector'> + <EigenMatrix rows="3" cols="1" type="float" /> + </ObjectChild> + <ObjectChild key='the_4x4_matrix'> + <EigenMatrix rows="4" cols="4" type="float" /> + </ObjectChild> + <ObjectChild key='the_rgb24_image'> + <Image pixelType="rgb24"/> + </ObjectChild> + <ObjectChild key='the_depth32_image'> + <Image pixelType="depth32"/> + </ObjectChild> - <ObjectChild key='the_object_list'> - <List> - <Object name='ListClass'> - <ObjectChild key='element_int'> - <Int /> - </ObjectChild> - <ObjectChild key='element_float'> - <Float /> - </ObjectChild> - <ObjectChild key='element_string'> + <ObjectChild key='the_float_list'> + <List> + <Float /> + </List> + </ObjectChild> + <ObjectChild key='the_int_list'> + <List> + <Int /> + </List> + </ObjectChild> + <ObjectChild key='the_string_list'> + <List> <String /> - </ObjectChild> - </Object> - </List> - </ObjectChild> + </List> + </ObjectChild> + + <ObjectChild key='the_object_list'> + <List> + <Object name='InnerClass'> + <ObjectChild key='element_int'> + <Int /> + </ObjectChild> + <ObjectChild key='element_float'> + <Float /> + </ObjectChild> + <ObjectChild key='element_string'> + <String /> + </ObjectChild> + </Object> + </List> + </ObjectChild> - <ObjectChild key='the_float_dict'> - <Dict> - <Float /> - </Dict> - </ObjectChild> - <ObjectChild key='the_int_dict'> - <Dict> - <Int /> - </Dict> - </ObjectChild> + <ObjectChild key='the_float_dict'> + <Dict> + <Float /> + </Dict> + </ObjectChild> + <ObjectChild key='the_int_dict'> + <Dict> + <Int /> + </Dict> + </ObjectChild> - <ObjectChild key="memoryLink"> - <armarx::armem::arondto::MemoryID /> - </ObjectChild> + <ObjectChild key="memoryLink"> + <armarx::armem::arondto::MemoryID /> + </ObjectChild> - </Object> - </GenerateTypes> + </Object> + </GenerateTypes> </AronTypeDefinition>