Plugin.cpp
Go to the documentation of this file.
1 #include "Plugin.h"
2 
5 
9 #include <VisionX/libraries/armem/vision/images/core/aron/ImageDepth.aron.generated.h>
10 #include <VisionX/libraries/armem/vision/images/core/aron/ImageRGB.aron.generated.h>
12 
13 
14 namespace armem = armarx::armem;
15 namespace wm = armem::server::wm;
16 
18 {
19 
20  Plugin::Plugin(armarx::ManagedIceObject& parent, std::string prefix) :
21  armarx::ComponentPlugin(parent, prefix)
22  // , workingMemory(std::make_unique<wm::Memory>())
23  // , iceAdapter(std::make_unique<armem::server::MemoryToIceAdapter>(workingMemory.get()))
24  ,
25  properties(std::make_unique<Properties>()),
26  imageToArMem(std::make_unique<visionx::armem_images::ImageToArMem>())
27  {
28  addPlugin(serverPlugin);
29  addPluginDependency(serverPlugin);
30  ARMARX_CHECK_NOT_NULL(serverPlugin);
31  }
32 
34  {
35  }
36 
38  {
39  std::vector<size_t> rgbIndices{0};
40  std::vector<size_t> depthIndices{1};
41 
43  void read(armarx::PropertyUser& properties);
44  };
45 
46  void
48  {
49  defs.defineOptionalProperty("img.rgb.ImageIndices",
50  simox::alg::join(simox::alg::multi_to_string(rgbIndices)),
51  "Indices of RGB images in provided images");
52  defs.defineOptionalProperty("img.depth.ImageIndices",
53  simox::alg::join(simox::alg::multi_to_string(depthIndices)),
54  "Indices of RGB images in provided images");
55  }
56 
57  void
59  {
60  rgbIndices = ImagesProperties::getIndices(properties, "img.rgb.ImageIndices");
61  depthIndices = ImagesProperties::getIndices(properties, "img.depth.ImageIndices");
62  }
63 
64  void
66  {
67  properties->define(*defs);
68  }
69 
70  void
72  {
73  armarx::Component& parent = this->parent<armarx::Component>();
74  serverPlugin->workingMemory.name() = parent.getName();
75  properties->read(parent);
76  }
77 
78  void
80  {
81  addRgbImagesEntity(properties->rgbIndices);
82  addDepthImagesEntity(properties->depthIndices);
83  ARMARX_INFO << "Memory image structure: \n" << imageToArMem->summarizeStructure();
84  }
85 
86  void
88  {
89  ImageProvider& imageProvider = this->parent<ImageProvider>();
90  imageToArMem->initImages(imageProvider.getImageFormat());
91  }
92 
93  wm::Entity&
94  Plugin::addRgbImagesEntity(const std::vector<size_t>& imageIndices)
95  {
96  wm::CoreSegment& cs = serverPlugin->workingMemory.addCoreSegment(
98  visionx::armem_images::arondto::ImageRGB::ToAronType());
99  cs.setMaxHistorySize(128);
100 
101  wm::ProviderSegment& ps = cs.addProviderSegment(parent().getName());
102  wm::Entity& entity = ps.addEntity("image");
103  imageToArMem->addImagesRGB(entity.id(), imageIndices);
104  return entity;
105  }
106 
107  wm::Entity&
108  Plugin::addDepthImagesEntity(const std::vector<size_t>& imageIndices)
109  {
110  wm::CoreSegment& cs = serverPlugin->workingMemory.addCoreSegment(
112  visionx::armem_images::arondto::ImageDepth::ToAronType());
113  cs.setMaxHistorySize(128);
114 
115  wm::ProviderSegment& ps = cs.addProviderSegment(parent().getName());
116  wm::Entity& entity = ps.addEntity("image");
117  imageToArMem->addImagesDepth(entity.id(), imageIndices);
118  return entity;
119  }
120 
121  void
122  Plugin::useImageBuffers(CByteImage** inputImages, armarx::armem::Time timeProvided)
123  {
124  imageToArMem->useImageBuffers(inputImages, timeProvided);
125  }
126 
127  void
128  Plugin::usePixelBuffers(void** inputPixelBuffers, armarx::armem::Time timeProvided)
129  {
130  // inputImageBuffer is not a CByteImage**, but directly points to the pixel data
131  imageToArMem->usePixelBuffers(inputPixelBuffers, timeProvided);
132  }
133 
134  void
136  {
137  armem::Commit commit = imageToArMem->makeCommit();
138  serverPlugin->iceAdapter.commitLocking(commit);
139  }
140 
141  void
142  Plugin::commitImages(CByteImage** inputImages, armarx::armem::Time timeProvided)
143  {
144  useImageBuffers(inputImages, timeProvided);
145  commitImages();
146  }
147 
148  void
149  Plugin::commitImages(void** inputPixelBuffers, armarx::armem::Time timeProvided)
150  {
151  usePixelBuffers(inputPixelBuffers, timeProvided);
152  commitImages();
153  }
154 
155 } // namespace visionx::armem_images::server::plugins
visionx::armem_images::server::plugins::Plugin::addDepthImagesEntity
armarx::armem::server::wm::Entity & addDepthImagesEntity(const std::vector< size_t > &imageIndices)
Definition: Plugin.cpp:108
visionx::armem_images::server::plugins::Plugin::Plugin
Plugin(armarx::ManagedIceObject &parent, std::string prefix)
Definition: Plugin.cpp:20
visionx::armem_images::server::plugins::Plugin::usePixelBuffers
void usePixelBuffers(void **inputPixelBuffers, armarx::armem::Time timeProvided)
Definition: Plugin.cpp:128
visionx::armem_images::server::plugins::Plugin::postOnInitComponent
virtual void postOnInitComponent() override
Definition: Plugin.cpp:79
plugins::Plugin::Properties::rgbIndices
std::vector< size_t > rgbIndices
Definition: Plugin.cpp:39
armarx::armem::server::plugins::Plugin::iceAdapter
MemoryToIceAdapter iceAdapter
Helps connecting memory to ice. Used to handle Ice callbacks.
Definition: Plugin.h:66
armarx::ManagedIceObjectPlugin::addPluginDependency
void addPluginDependency(ManagedIceObjectPlugin *dependedOn)
Definition: ManagedIceObjectPlugin.cpp:42
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
Plugin.h
armarx::PropertyDefinitionContainer::defineOptionalProperty
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Definition: PropertyDefinitionContainer.h:533
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
plugins::Plugin::Properties::read
void read(armarx::PropertyUser &properties)
Definition: Plugin.cpp:58
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
visionx::armem_images::server::plugins::Plugin::commitImages
void commitImages()
Definition: Plugin.cpp:135
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
ImagesProperties.h
visionx::armem_images::ImagesProperties::getIndices
static std::vector< size_t > getIndices(armarx::PropertyUser &properties, const std::string &propertyName)
Definition: ImagesProperties.cpp:49
visionx::armem_images::depthImagesCoreSegmentID
const armarx::armem::MemoryID depthImagesCoreSegmentID
Definition: constants.cpp:32
visionx::armem_images::rgbImagesCoreSegmentID
const armarx::armem::MemoryID rgbImagesCoreSegmentID
Definition: constants.cpp:31
armarx::armem::base::MemoryBase::name
std::string & name()
Definition: MemoryBase.h:92
visionx::armem_images::server::plugins::Plugin::~Plugin
virtual ~Plugin() override
Definition: Plugin.cpp:33
visionx::ImageProvider::getImageFormat
ImageFormatInfo getImageFormat(const Ice::Current &c=Ice::emptyCurrent) override
Returns the entire image format info struct via Ice.
Definition: ImageProvider.cpp:75
armarx::ManagedIceObjectPlugin::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObjectPlugin.h:104
memory_definitions.h
visionx::armem_images::server::plugins::Plugin::useImageBuffers
void useImageBuffers(CByteImage **inputImages, armarx::armem::Time timeProvided)
Definition: Plugin.cpp:122
plugins::Plugin::Properties::depthIndices
std::vector< size_t > depthIndices
Definition: Plugin.cpp:40
plugins::Plugin::Properties::define
void define(armarx::PropertyDefinitionContainer &defs)
Definition: Plugin.cpp:47
armarx::armem::base::MemoryBase::addCoreSegment
CoreSegmentT & addCoreSegment(const std::string &name, aron::type::ObjectPtr coreSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty core segment with the given name, type and prediction engines.
Definition: MemoryBase.h:259
armarx::PropertyDefinitionContainer
PropertyDefinitionContainer.
Definition: PropertyDefinitionContainer.h:53
MemoryToIceAdapter.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
plugins::Plugin::Properties
Definition: Plugin.cpp:37
visionx::armem_images::server::plugins::Plugin::addRgbImagesEntity
armarx::armem::server::wm::Entity & addRgbImagesEntity(const std::vector< size_t > &imageIndices)
Definition: Plugin.cpp:94
visionx::armem_images::server::plugins::Plugin::postCreatePropertyDefinitions
virtual void postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr &properties) override
Definition: Plugin.cpp:65
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
visionx::ImageProvider
ImageProvider abstract class defines a component which provide images via ice or shared memory.
Definition: ImageProvider.h:66
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
std
Definition: Application.h:66
visionx::armem_images::server::plugins::Plugin::postOnConnectComponent
virtual void postOnConnectComponent() override
Definition: Plugin.cpp:87
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::armem_images::server::plugins
Definition: Plugin.cpp:17
visionx::armem_images::ImageToArMem
Allows to convert multiple CByteImages to Aron images and memory commits.
Definition: ImageToArMem.h:23
constants.h
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::armem::server::plugins::Plugin::workingMemory
server::wm::Memory workingMemory
The actual memory.
Definition: Plugin.h:63
armarx::PropertyUser
Abstract PropertyUser class.
Definition: PropertyUser.h:62
ImageProvider.h
armarx::armem::server::MemoryToIceAdapter::commitLocking
data::CommitResult commitLocking(const data::Commit &commitIce, Time timeArrived)
Definition: MemoryToIceAdapter.cpp:166
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
visionx::armem_images::server::plugins::Plugin::preOnInitComponent
virtual void preOnInitComponent() override
Definition: Plugin.cpp:71
ImageToArMem.h