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 static std::string
111 {
112 return "ImageSourceSelection";
113 }
114
115 std::string
116 getDefaultName() const override
117 {
118 return GetDefaultName();
119 }
120
121 void setImageSource(const std::string& imageSource,
122 int relativeTimeoutMs,
123 const Ice::Current& c) override;
124
125 std::string
126 getCurrentImageSource(const Ice::Current& c = Ice::emptyCurrent) override
127 {
128 std::unique_lock lock(imageSourceMutex);
129 return providerTimeouts.empty() ? defaultProvider : providerTimeouts.begin()->first;
130 }
131
132 protected:
133 void setImageSource(const std::string& imageSource);
134 void removeImageSource(const std::string& imageSource);
135 /**
136 * enable stereo result images
137 */
138 void enableStereoResultImages(visionx::ImageDimension imageDimension,
139 visionx::ImageType imageType);
140
141 /**
142 * @see visionx::ImageProcessor::onInitImageProcessor()
143 */
144 void onInitImageProcessor() override;
145
146 /**
147 * @see visionx::ImageProcessor::onConnectImageProcessor()
148 */
149 void onConnectImageProcessor() override;
150
151 /**
152 * @see visionx::ImageProcessor::onExitImageProcessor()
153 */
154 void onExitImageProcessor() override;
155
156 /**
157 * @see visionx::ImageProcessor::process()
158 */
159 void process() override;
160
161 /**
162 * @see PropertyUser::createPropertyDefinitions()
163 */
165
166 bool
167 addImageProvider(const std::string& providerName)
168 {
169 return addImageProvider(providerName, imageDisplayType, imageProviderInfo);
170 }
171
172 bool addImageProvider(const std::string& providerName,
173 visionx::ImageType imageDisplayType,
174 visionx::ImageProviderInfo& imageProviderInfo);
175
176 private:
177 visionx::ImageDimension targetDimension;
178 float scaleFactorX, scaleFactorY;
179
180 std::recursive_mutex mutex, imageSourceMutex;
181
182 std::map<std::string, visionx::CByteImageUPtrVec> cameraImages;
183 visionx::CByteImageUPtrVec resultCameraImages;
184 int numImages;
185
186 // std::vector<std::string> providers;
187 std::string defaultProvider;
188 // std::string activeProvider;
189 visionx::ImageType imageDisplayType;
190 visionx::ImageProviderInfo imageProviderInfo;
191
192 std::vector<std::pair<std::string, IceUtil::Time>> providerTimeouts;
193 void deleteTimedOutProviders();
194 };
195
197 virtual public visionx::ResultImageProvider,
198 virtual public visionx::StereoCalibrationProviderInterface
199 {
201
202 public:
206
207 visionx::StereoCalibration
208 getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override
209 {
210 return stereoCalibration;
211 }
212
213 bool
214 getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override
215 {
216 return imagesAreUndistorted;
217 }
218
219 std::string
220 getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
221 {
222 return referenceFrame;
223 }
224
225 void
226 setStereoCalibration(visionx::StereoCalibration stereoCalibration,
227 bool imagesAreUndistorted,
228 const std::string& referenceFrame)
229 {
230 this->stereoCalibration = stereoCalibration;
231 this->imagesAreUndistorted = imagesAreUndistorted;
232 this->referenceFrame = referenceFrame;
233 calibrationPrx->reportStereoCalibrationChanged(
234 this->stereoCalibration, this->imagesAreUndistorted, this->referenceFrame);
235 }
236
237 protected:
238 void
240 {
242 offeringTopic("StereoCalibrationInterface");
243 }
244
245 void
247 {
249 calibrationPrx =
250 getTopic<StereoCalibrationUpdateInterfacePrx>("StereoCalibrationInterface");
251 }
252
253 private:
254 visionx::StereoCalibration stereoCalibration;
255 bool imagesAreUndistorted;
256 StereoCalibrationUpdateInterfacePrx calibrationPrx;
257 std::string referenceFrame;
258 };
259
261
262} // 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
Retrieve default name of component.
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