40 return "ArMemToImageProvider";
48 defs->topic(debugObserver);
50 defs->optional(p.providerSegmentName,
"img.ProviderSegmentName",
51 "Name of the provider segment(s).");
52 defs->optional(p.resultImagesName,
"img.ResultImagesName",
53 "Name of the resulting (provided) images.\n"
54 "If '(auto)', the provider segment name is used.");
56 defs->defineOptionalPropertyVector(
"img.FallbackDimensions", p.fallbackDims,
57 "Image dimensions to use when they cannot be fetched from memory.",
'x');
59 p.images.define(*defs);
68 getProperty(p.fallbackDims,
"img.FallbackDimensions");
69 if (p.resultImagesName ==
"(auto)")
71 p.resultImagesName = p.providerSegmentName;
73 p.images.read(*
this, p.providerSegmentName);
76 armemToImage.
addImagesRGB(p.images.rgbEntityID, p.images.rgbIndices);
77 armemToImage.
addImagesDepth(p.images.depthEntityID, p.images.depthIndices);
81 auto callback = [
this](
const armarx::armem::MemoryID & entityID,
const std::vector<armarx::armem::MemoryID>& updatedSnapshotIDs)
83 this->fetchUpdates(entityID, updatedSnapshotIDs);
104 Eigen::Vector2i dimensions = p.fallbackDims;
113 enableResultImages(armemToImage.
images.size(), { dimensions(0), dimensions(1) }, eRgb, p.resultImagesName);
118 if (resultImageProvider)
121 resultImageProvider =
nullptr;
139 void ArMemToImageProvider::enableResultImages(
size_t numberImages, ImageDimension imageDimension, ImageType imageType,
const std::string& name)
141 if (!resultImageProvider)
143 ARMARX_VERBOSE <<
"Enabling ImageProvider with " << numberImages <<
" result images of size "
144 << imageDimension.width <<
"x" << imageDimension.height <<
".";
147 provider->setName(name);
148 provider->setNumberResultImages(
static_cast<int>(numberImages));
149 provider->setResultImageFormat(imageDimension, imageType);
155 catch (
const Ice::AlreadyRegisteredException& e)
157 ARMARX_ERROR <<
"The name '" << name <<
"' is already used. Please choose another one.\n"
158 <<
"Reason: " << e.what();
161 provider->getObjectScheduler()->waitForObjectState(armarx::ManagedIceObjectState::eManagedIceObjectStarted);
164 this->resultImageProvider = provider;
169 void ArMemToImageProvider::fetchUpdates(
const armarx::armem::MemoryID& entityID,
const std::vector<armarx::armem::MemoryID>& updatedSnapshotIDs)
171 std::scoped_lock lock(armemToImageMutex);
172 armemToImage.
fetchUpdates(entityID, updatedSnapshotIDs);
174 if (resultImageProvider && armemToImage.
updated)
176 std::vector<CByteImage> ivtImages;
177 std::vector<CByteImage*> ivtImagesBuffer;
178 ivtImages.reserve(armemToImage.
images.size());
179 ivtImagesBuffer.reserve(armemToImage.
images.size());
180 for (
auto& image : armemToImage.
images)
182 CByteImage& ivt = ivtImages.emplace_back(image->toCByteImage());
183 ivtImagesBuffer.emplace_back(&ivt);
192 debugObserver->setDebugChannel(
getName(),
194 {
"Provide [us]",
new armarx::Variant(Provide.toMicroSecondsDouble()) },