ImagesProperties.cpp
Go to the documentation of this file.
1#include "ImagesProperties.h"
2
3#include <SimoxUtility/algorithm/string.h>
4
7
9{
10
11 void
13 {
15 "img.rgb.EntityID",
16 rgbEntityID.str(),
17 "The RGB image(s) entity ID. Provider segment name can be set via 'img.ProviderName'.");
18 defs.defineOptionalProperty("img.rgb.ImageIndices",
19 simox::alg::join(simox::alg::multi_to_string(rgbIndices)),
20 "Indices of RGB images in provided images");
21
22 defs.defineOptionalProperty("img.depth.EntityID",
23 depthEntityID.str(),
24 "The depth image(s) entity ID. Provider segment name can be "
25 "set via 'img.ProviderName'.");
26 defs.defineOptionalProperty("img.depth.ImageIndices",
27 simox::alg::join(simox::alg::multi_to_string(depthIndices)),
28 "Indices of Depth images in provided images.");
29 }
30
31 void
33 const std::string& defaultProviderSegmentName)
34 {
35 // Parse properties.
36 rgbEntityID = getEntityID(properties, "img.rgb.EntityID", defaultProviderSegmentName);
37 depthEntityID = getEntityID(properties, "img.depth.EntityID", defaultProviderSegmentName);
38
39 rgbIndices = getIndices(properties, "img.rgb.ImageIndices");
40 depthIndices = getIndices(properties, "img.depth.ImageIndices");
41 }
42
45 const std::string& propertyName,
46 const std::string& defaultProviderSegmentName)
47 {
48 armarx::armem::MemoryID id(properties.getProperty<std::string>(propertyName));
49 if (!id.hasProviderSegmentName())
50 {
51 id.providerSegmentName = defaultProviderSegmentName;
52 }
53 return id;
54 }
55
56 std::vector<size_t>
57 ImagesProperties::getIndices(armarx::PropertyUser& properties, const std::string& propertyName)
58 {
59 std::string prop = properties.getProperty<std::string>(propertyName);
60 std::vector<size_t> indices;
61 if (prop.empty())
62 {
63 return indices;
64 }
65
66 std::vector<std::string> indicesStr = simox::alg::split(prop, ",", true, true);
67 std::transform(indicesStr.begin(),
68 indicesStr.end(),
69 std::back_inserter(indices),
70 [](const std::string& s)
71 {
72 long l = std::stol(s);
73 ARMARX_CHECK_NONNEGATIVE(l) << "Image indices must be non-negative.";
74 return static_cast<size_t>(l);
75 });
76 return indices;
77 }
78} // namespace visionx::armem_images
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Abstract PropertyUser class.
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
static armarx::armem::MemoryID getEntityID(armarx::PropertyUser &properties, const std::string &propertyName, const std::string &defaultProviderSegmentName)
static std::vector< size_t > getIndices(armarx::PropertyUser &properties, const std::string &propertyName)
void define(armarx::PropertyDefinitionContainer &defs)
void read(armarx::PropertyUser &properties, const std::string &defaultProviderSegmentName)