ImageSourceSelection.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package VisionX::ArmarXObjects::ImageSourceSelection
17 * @author Markus Grotz ( markus dot grotz at kit dot edu )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25
26#include <mutex>
27#include <vector>
28
29#include <SimoxUtility/algorithm/string/string_tools.h>
30
32#include <VisionX/interface/components/Calibration.h>
33#include <VisionX/interface/components/ImageSourceSelectionInterface.h>
34
35namespace armarx
36{
37
39
40 static std::vector<std::string>
41 stringToVector(std::string propertyValue)
42 {
43 std::vector<std::string> result = simox::alg::split(propertyValue, "\t ,");
44 return result;
45 }
46
47 /**
48 * @class ImageSourceSelectionPropertyDefinitions
49 * @brief
50 */
53 {
54 public:
57 {
59 "TargetDimension", visionx::ImageDimension(640, 480), "")
60 .setCaseInsensitive(true)
61 .map("320x240", visionx::ImageDimension(320, 240))
62 .map("640x480", visionx::ImageDimension(640, 480))
63 .map("800x600", visionx::ImageDimension(800, 600))
64 .map("768x576", visionx::ImageDimension(768, 576))
65 .map("1024x768", visionx::ImageDimension(1024, 768))
66 .map("1280x720", visionx::ImageDimension(1280, 960))
67 .map("1280x960", visionx::ImageDimension(1280, 960))
68 .map("1280x1024", visionx::ImageDimension(1280, 960))
69 .map("1600x1200", visionx::ImageDimension(1600, 1200))
70 .map("1920x1080", visionx::ImageDimension(1920, 1080))
71 .map("1920x1200", visionx::ImageDimension(1920, 1200));
73 "NumberOfImages",
74 0,
75 "If set to >0, this number of images will be reported. Otherwise, the number of "
76 "images of the first image provider will be used.");
77
79 "resultProviderName", "Armar3ImageProvider", "Names of the result image provider");
81 "defaultProviderName",
82 "RCImageProvider",
83 "Name of the image provider to be used when no provider is set.");
84 PropertyDefinition<std::vector<std::string>>::PropertyFactoryFunction f =
85 &stringToVector;
86 // defineOptionalProperty<std::vector<std::string>>("providerNames", {"Armar3WideImageProvider", "Armar3FovealImageProvider"}, "Names of the image providers").setFactory(f);
87 }
88 };
89
90 /**
91 * @defgroup Component-ImageSourceSelection ImageSourceSelection
92 * @ingroup VisionX-Components
93 * A description of the component ImageSourceSelection.
94 *
95 * @class ImageSourceSelection
96 * @ingroup Component-ImageSourceSelection
97 * @brief Brief description of class ImageSourceSelection.
98 *
99 * Detailed description of class ImageSourceSelection.
100 */
102 virtual public visionx::ImageProcessor,
103 virtual public ImageSourceSelectionInterface
104 {
105 public:
106 /**
107 * @see armarx::ManagedIceObject::getDefaultName()
108 */
109 std::string
110 getDefaultName() const override
111 {
112 return "ImageSourceSelection";
113 }
114
115 void setImageSource(const std::string& imageSource,
116 int relativeTimeoutMs,
117 const Ice::Current& c) override;
118
119 std::string
120 getCurrentImageSource(const Ice::Current& c = Ice::emptyCurrent) override
121 {
122 std::unique_lock lock(imageSourceMutex);
123 return providerTimeouts.empty() ? defaultProvider : providerTimeouts.begin()->first;
124 }
125
126 protected:
127 void setImageSource(const std::string& imageSource);
128 void removeImageSource(const std::string& imageSource);
129 /**
130 * enable stereo result images
131 */
132 void enableStereoResultImages(visionx::ImageDimension imageDimension,
133 visionx::ImageType imageType);
134
135 /**
136 * @see visionx::ImageProcessor::onInitImageProcessor()
137 */
138 void onInitImageProcessor() override;
139
140 /**
141 * @see visionx::ImageProcessor::onConnectImageProcessor()
142 */
143 void onConnectImageProcessor() override;
144
145 /**
146 * @see visionx::ImageProcessor::onExitImageProcessor()
147 */
148 void onExitImageProcessor() override;
149
150 /**
151 * @see visionx::ImageProcessor::process()
152 */
153 void process() override;
154
155 /**
156 * @see PropertyUser::createPropertyDefinitions()
157 */
159
160 bool
161 addImageProvider(const std::string& providerName)
162 {
163 return addImageProvider(providerName, imageDisplayType, imageProviderInfo);
164 }
165
166 bool addImageProvider(const std::string& providerName,
167 visionx::ImageType imageDisplayType,
168 visionx::ImageProviderInfo& imageProviderInfo);
169
170 private:
171 visionx::ImageDimension targetDimension;
172 float scaleFactorX, scaleFactorY;
173
174 std::recursive_mutex mutex, imageSourceMutex;
175
176 std::map<std::string, visionx::CByteImageUPtrVec> cameraImages;
177 visionx::CByteImageUPtrVec resultCameraImages;
178 int numImages;
179
180 // std::vector<std::string> providers;
181 std::string defaultProvider;
182 // std::string activeProvider;
183 visionx::ImageType imageDisplayType;
184 visionx::ImageProviderInfo imageProviderInfo;
185
186 std::vector<std::pair<std::string, IceUtil::Time>> providerTimeouts;
187 void deleteTimedOutProviders();
188 };
189
191 virtual public visionx::ResultImageProvider,
192 virtual public visionx::StereoCalibrationProviderInterface
193 {
195
196 public:
200
201 visionx::StereoCalibration
202 getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override
203 {
204 return stereoCalibration;
205 }
206
207 bool
208 getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override
209 {
210 return imagesAreUndistorted;
211 }
212
213 std::string
214 getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
215 {
216 return referenceFrame;
217 }
218
219 void
220 setStereoCalibration(visionx::StereoCalibration stereoCalibration,
221 bool imagesAreUndistorted,
222 const std::string& referenceFrame)
223 {
224 this->stereoCalibration = stereoCalibration;
225 this->imagesAreUndistorted = imagesAreUndistorted;
226 this->referenceFrame = referenceFrame;
227 calibrationPrx->reportStereoCalibrationChanged(
228 this->stereoCalibration, this->imagesAreUndistorted, this->referenceFrame);
229 }
230
231 protected:
232 void
234 {
236 offeringTopic("StereoCalibrationInterface");
237 }
238
239 void
241 {
243 calibrationPrx =
244 getTopic<StereoCalibrationUpdateInterfacePrx>("StereoCalibrationInterface");
245 }
246
247 private:
248 visionx::StereoCalibration stereoCalibration;
249 bool imagesAreUndistorted;
250 StereoCalibrationUpdateInterfacePrx calibrationPrx;
251 std::string referenceFrame;
252 };
253
255
256} // namespace armarx
constexpr T c
Brief description of class ImageSourceSelection.
bool addImageProvider(const std::string &providerName)
void enableStereoResultImages(visionx::ImageDimension imageDimension, visionx::ImageType imageType)
enable stereo result images
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void removeImageSource(const std::string &imageSource)
std::string getCurrentImageSource(const Ice::Current &c=Ice::emptyCurrent) override
void setImageSource(const std::string &imageSource, int relativeTimeoutMs, const Ice::Current &c) override
std::string getDefaultName() const override
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
PropertyDefinition defines a property that will be available within the PropertyUser.
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
void setStereoCalibration(visionx::StereoCalibration stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame)
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
void onConnectImageProvider() override
This is called when the Component::onConnectComponent() setup is called.
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
ImageProcessorPropertyDefinitions(std::string prefix)
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
virtual void onConnectImageProvider()
This is called when the Component::onConnectComponent() setup is called.
The ResultImageProvider is used by the ImageProcessor to stream result images to any other processor ...
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< StereoResultImageProvider > StereoResultImageProviderPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.
std::vector< std::unique_ptr< CByteImage > > CByteImageUPtrVec