Plugin.cpp
Go to the documentation of this file.
1#include "Plugin.h"
2
3#include <SimoxUtility/algorithm/string/string_tools.h>
4
7
11#include <VisionX/libraries/armem/vision/images/core/aron/ImageDepth.aron.generated.h>
12#include <VisionX/libraries/armem/vision/images/core/aron/ImageRGB.aron.generated.h>
14
15
16namespace armem = armarx::armem;
17namespace wm = armem::server::wm;
18
20{
21
23 armarx::ComponentPlugin(parent, prefix)
24 // , workingMemory(std::make_unique<wm::Memory>())
25 // , iceAdapter(std::make_unique<armem::server::MemoryToIceAdapter>(workingMemory.get()))
26 ,
27 properties(std::make_unique<Properties>()),
28 imageToArMem(std::make_unique<visionx::armem_images::ImageToArMem>())
29 {
30 addPlugin(serverPlugin);
31 addPluginDependency(serverPlugin);
32 ARMARX_CHECK_NOT_NULL(serverPlugin);
33 }
34
36 {
37 }
38
40 {
41 std::vector<size_t> rgbIndices{0};
42 std::vector<size_t> depthIndices{1};
43
44 void define(armarx::PropertyDefinitionContainer& defs);
45 void read(armarx::PropertyUser& properties);
46 };
47
48 void
50 {
51 defs.defineOptionalProperty("img.rgb.ImageIndices",
52 simox::alg::join(simox::alg::multi_to_string(rgbIndices)),
53 "Indices of RGB images in provided images");
54 defs.defineOptionalProperty("img.depth.ImageIndices",
55 simox::alg::join(simox::alg::multi_to_string(depthIndices)),
56 "Indices of RGB images in provided images");
57 }
58
59 void
61 {
62 rgbIndices = ImagesProperties::getIndices(properties, "img.rgb.ImageIndices");
63 depthIndices = ImagesProperties::getIndices(properties, "img.depth.ImageIndices");
64 }
65
66 void
68 {
69 properties->define(*defs);
70 }
71
72 void
74 {
76 serverPlugin->workingMemory.name() = parent.getName();
77 properties->read(parent);
78 }
79
80 void
82 {
83 addRgbImagesEntity(properties->rgbIndices);
84 addDepthImagesEntity(properties->depthIndices);
85 ARMARX_INFO << "Memory image structure: \n" << imageToArMem->summarizeStructure();
86 }
87
88 void
90 {
91 ImageProvider& imageProvider = this->parent<ImageProvider>();
92 imageToArMem->initImages(imageProvider.getImageFormat());
93 }
94
96 Plugin::addRgbImagesEntity(const std::vector<size_t>& imageIndices)
97 {
98 wm::CoreSegment& cs = serverPlugin->workingMemory.addCoreSegment(
100 visionx::armem_images::arondto::ImageRGB::ToAronType());
101 cs.setMaxHistorySize(128);
102
103 wm::ProviderSegment& ps = cs.addProviderSegment(parent().getName());
104 wm::Entity& entity = ps.addEntity("image");
105 imageToArMem->addImagesRGB(entity.id(), imageIndices);
106 return entity;
107 }
108
110 Plugin::addDepthImagesEntity(const std::vector<size_t>& imageIndices)
111 {
112 wm::CoreSegment& cs = serverPlugin->workingMemory.addCoreSegment(
114 visionx::armem_images::arondto::ImageDepth::ToAronType());
115 cs.setMaxHistorySize(128);
116
117 wm::ProviderSegment& ps = cs.addProviderSegment(parent().getName());
118 wm::Entity& entity = ps.addEntity("image");
119 imageToArMem->addImagesDepth(entity.id(), imageIndices);
120 return entity;
121 }
122
123 void
124 Plugin::useImageBuffers(CByteImage** inputImages, armarx::armem::Time timeProvided)
125 {
126 imageToArMem->useImageBuffers(inputImages, timeProvided);
127 }
128
129 void
130 Plugin::usePixelBuffers(void** inputPixelBuffers, armarx::armem::Time timeProvided)
131 {
132 // inputImageBuffer is not a CByteImage**, but directly points to the pixel data
133 imageToArMem->usePixelBuffers(inputPixelBuffers, timeProvided);
134 }
135
136 void
138 {
139 armem::Commit commit = imageToArMem->makeCommit();
140 serverPlugin->iceAdapter.commitLocking(commit);
141 }
142
143 void
144 Plugin::commitImages(CByteImage** inputImages, armarx::armem::Time timeProvided)
145 {
146 useImageBuffers(inputImages, timeProvided);
147 commitImages();
148 }
149
150 void
151 Plugin::commitImages(void** inputPixelBuffers, armarx::armem::Time timeProvided)
152 {
153 usePixelBuffers(inputPixelBuffers, timeProvided);
154 commitImages();
155 }
156
157} // namespace visionx::armem_images::server::plugins
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
void addPluginDependency(ManagedIceObjectPlugin *dependedOn)
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
const std::string & prefix() const
The ManagedIceObject is the base class for all ArmarX objects.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Abstract PropertyUser class.
ProviderSegment & addProviderSegment(const std::string &name, Args... args)
Entity & addEntity(const std::string &name, Args... args)
void setMaxHistorySize(long maxSize)
Sets the maximum history size of entities in this container.
ImageProvider abstract class defines a component which provide images via ice or shared memory.
ImageFormatInfo getImageFormat(const Ice::Current &c=Ice::emptyCurrent) override
Returns the entire image format info struct via Ice.
Allows to convert multiple CByteImages to Aron images and memory commits.
virtual void postOnInitComponent() override
Definition Plugin.cpp:81
virtual void preOnInitComponent() override
Definition Plugin.cpp:73
virtual void postOnConnectComponent() override
Definition Plugin.cpp:89
armarx::armem::server::wm::Entity & addDepthImagesEntity(const std::vector< size_t > &imageIndices)
Definition Plugin.cpp:110
void useImageBuffers(CByteImage **inputImages, armarx::armem::Time timeProvided)
Definition Plugin.cpp:124
armarx::armem::server::wm::Entity & addRgbImagesEntity(const std::vector< size_t > &imageIndices)
Definition Plugin.cpp:96
Plugin(armarx::ManagedIceObject &parent, std::string prefix)
Definition Plugin.cpp:22
void usePixelBuffers(void **inputPixelBuffers, armarx::armem::Time timeProvided)
Definition Plugin.cpp:130
virtual void postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr &properties) override
Definition Plugin.cpp:67
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
armarx::core::time::DateTime Time
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const armarx::armem::MemoryID rgbImagesCoreSegmentID
Definition constants.cpp:30
const armarx::armem::MemoryID depthImagesCoreSegmentID
Definition constants.cpp:31
ArmarX headers.
A bundle of updates to be sent to the memory.
Definition Commit.h:90
static std::vector< size_t > getIndices(armarx::PropertyUser &properties, const std::string &propertyName)
std::vector< size_t > rgbIndices
Definition Plugin.cpp:41
void define(armarx::PropertyDefinitionContainer &defs)
Definition Plugin.cpp:49
void read(armarx::PropertyUser &properties)
Definition Plugin.cpp:60
std::vector< size_t > depthIndices
Definition Plugin.cpp:42