ArMemToImage.cpp
Go to the documentation of this file.
1#include "ArMemToImage.h"
2
3#include <sstream>
4
7
11
12#include <Image/ByteImage.h>
13
15{
16
18 {
19 }
20
21 template <class AronImageT>
22 void
23 ArMemToImage::addImages(const armarx::armem::MemoryID& entityID,
24 const std::vector<size_t>& imageIndices)
25 {
26 for (size_t i = 0; i < imageIndices.size(); ++i)
27 {
28 armarx::armem::MemoryID instanceID = entityID;
29 instanceID.instanceIndex = static_cast<int>(i);
30
31 size_t index = imageIndices[i];
32 if (index >= images.size())
33 {
34 images.resize(index + 1);
35 }
36 images[index].reset(new Image<AronImageT>(instanceID, index));
37 }
38 }
39
40 void
42 const std::vector<size_t>& imageIndices)
43 {
44 addImages<arondto::ImageRGB>(entityID, imageIndices);
45 }
46
47 void
49 const std::vector<size_t>& imageIndices)
50 {
51 addImages<arondto::ImageDepth>(entityID, imageIndices);
52 }
53
56 {
57 armarx::armem::MemoryID id = images.front()->instanceID.getMemoryID();
58 for (size_t i = 0; i < images.size(); ++i)
59 {
60 ARMARX_CHECK_EQUAL(images[i]->instanceID.memoryName, id.memoryName)
61 << "Currently, all images must be from the same memory.";
62 }
63 return id;
64 }
65
66 Eigen::Vector2i
68 {
69 Eigen::Vector2i dims = dims.Zero();
70 for (const auto& image : images)
71 {
72 const cv::Mat& img = image->getImage();
73 dims(0) = std::max(dims(0), img.cols);
74 dims(1) = std::max(dims(1), img.rows);
75 }
76 return dims;
77 }
78
79 void
81 const std::vector<armarx::armem::MemoryID>& updatedSnapshotIDs)
82 {
83 (void)entityID;
84 auto it = std::find_if(updatedSnapshotIDs.begin(),
85 updatedSnapshotIDs.end(),
86 [this](const armarx::armem::MemoryID& id)
87 { return id.timestamp > timestamp; });
88 if (it != updatedSnapshotIDs.end())
89 {
90 TIMING_START(Fetch);
93
94 if (debugObserver)
95 {
96 debugObserver->setDebugChannel(
98 {
99 {"Fetch [us]", new armarx::Variant(Fetch.toMicroSecondsDouble())},
100 {"Timestamp [ms]",
101 new armarx::Variant(
102 timestamp.toDurationSinceEpoch().toMilliSecondsDouble())},
103 });
104 }
105 }
106 }
107
108 std::string
110 {
111 std::stringstream ss;
112 for (size_t i = 0; i < images.size(); ++i)
113 {
114 ss << "- [" << images[i]->imageIndex << "] id=" << images[i]->instanceID << "\n";
115 }
116 return ss.str();
117 }
118
121 {
122 if (!memoryReader)
123 {
125 r.success = false;
126 r.errorMessage = "No memory reader.";
127 return r;
128 }
129
131 for (const auto& image : images)
132 {
133 image->addQuery(qb);
134 }
135
137 if (result.success)
138 {
139 updateAronImages(result.memory);
140 }
141 return result;
142 }
143
144 void
145 ArMemToImage::updateAronImages(const armarx::armem::wm::Memory& memory)
146 {
147 for (const auto& image : images)
148 {
149 updated |= image->updateAronImage(memory);
150 timestamp = std::max(timestamp, image->instanceID.timestamp);
151 }
152 }
153
154 std::string
156 {
157 std::stringstream ss;
158 for (const auto& image : images)
159 {
160 ss << "- " << image->printFormat() << "\n";
161 }
162 return ss.str();
163 }
164
165} // namespace visionx::armem_images
std::string timestamp()
uint8_t index
The Variant class is described here: Variants.
Definition Variant.h:224
std::string memoryName
Definition MemoryID.h:50
Client-side working memory.
std::vector< std::unique_ptr< ImageBase > > images
armarx::armem::client::QueryResult fetchLatest()
armarx::armem::client::Reader memoryReader
void fetchUpdates(const armarx::armem::MemoryID &entityID, const std::vector< armarx::armem::MemoryID > &updatedSnapshotIDs)
std::string summarizeStructure() const override
armarx::armem::MemoryID getMemoryID() const override
Eigen::Vector2i getImageDimensions() const
void addImagesDepth(const armarx::armem::MemoryID &entityID, const std::vector< size_t > &imageIndices) override
void addImagesRGB(const armarx::armem::MemoryID &entityID, const std::vector< size_t > &imageIndices) override
armarx::DebugObserverInterfacePrx debugObserver
ImageAdapter(const std::string &debugObserverChannelName="ImageAdapter")
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
#define TIMING_START(name)
Helper macro to do timing tests.
Definition TimeUtil.h:289
#define TIMING_END_STREAM(name, os)
Prints duration.
Definition TimeUtil.h:310
client::QueryResult ClientQueryResult
Definition client.h:18
client::query::Builder ClientQueryBuilder
Definition client.h:19
Result of a QueryInput.
Definition Query.h:51
wm::Memory memory
The slice of the memory that matched the query.
Definition Query.h:58