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 <VisionX/interface/components/ImageSourceSelectionInterface.h>
27 #include <VisionX/interface/components/Calibration.h>
28 
29 
31 
32 #include <SimoxUtility/algorithm/string/string_tools.h>
33 
34 #include <vector>
35 #include <mutex>
36 
37 namespace armarx
38 {
39 
40  class StereoResultImageProvider;
41 
42  static std::vector<std::string> stringToVector(std::string propertyValue)
43  {
44  std::vector<std::string> result = simox::alg::split(propertyValue, "\t ,");
45  return result;
46  }
47 
48 
49 
50  /**
51  * @class ImageSourceSelectionPropertyDefinitions
52  * @brief
53  */
56  {
57  public:
60  {
61  defineOptionalProperty<visionx::ImageDimension>("TargetDimension", visionx::ImageDimension(640, 480), "")
62  .setCaseInsensitive(true)
63  .map("320x240", visionx::ImageDimension(320, 240))
64  .map("640x480", visionx::ImageDimension(640, 480))
65  .map("800x600", visionx::ImageDimension(800, 600))
66  .map("768x576", visionx::ImageDimension(768, 576))
67  .map("1024x768", visionx::ImageDimension(1024, 768))
68  .map("1280x720", visionx::ImageDimension(1280, 960))
69  .map("1280x960", visionx::ImageDimension(1280, 960))
70  .map("1280x1024", visionx::ImageDimension(1280, 960))
71  .map("1600x1200", visionx::ImageDimension(1600, 1200))
72  .map("1920x1080", visionx::ImageDimension(1920, 1080))
73  .map("1920x1200", visionx::ImageDimension(1920, 1200));
74  defineOptionalProperty<int>("NumberOfImages", 0, "If set to >0, this number of images will be reported. Otherwise, the number of images of the first image provider will be used.");
75 
76  defineOptionalProperty<std::string>("resultProviderName", "Armar3ImageProvider", "Names of the result image provider");
77  defineOptionalProperty<std::string>("defaultProviderName", "RCImageProvider", "Name of the image provider to be used when no provider is set.");
78  PropertyDefinition<std::vector<std::string>>::PropertyFactoryFunction f = &stringToVector;
79  // defineOptionalProperty<std::vector<std::string>>("providerNames", {"Armar3WideImageProvider", "Armar3FovealImageProvider"}, "Names of the image providers").setFactory(f);
80 
81  }
82  };
83 
84  /**
85  * @defgroup Component-ImageSourceSelection ImageSourceSelection
86  * @ingroup VisionX-Components
87  * A description of the component ImageSourceSelection.
88  *
89  * @class ImageSourceSelection
90  * @ingroup Component-ImageSourceSelection
91  * @brief Brief description of class ImageSourceSelection.
92  *
93  * Detailed description of class ImageSourceSelection.
94  */
96  virtual public visionx::ImageProcessor,
97  virtual public ImageSourceSelectionInterface
98  {
99  public:
100  /**
101  * @see armarx::ManagedIceObject::getDefaultName()
102  */
103  std::string getDefaultName() const override
104  {
105  return "ImageSourceSelection";
106  }
107 
108  void setImageSource(const std::string& imageSource, int relativeTimeoutMs, const Ice::Current& c) override;
109 
110  std::string getCurrentImageSource(const Ice::Current& c = Ice::emptyCurrent) override
111  {
112  std::unique_lock lock(imageSourceMutex);
113  return providerTimeouts.empty() ? defaultProvider : providerTimeouts.begin()->first;
114  }
115 
116  protected:
117  void setImageSource(const std::string& imageSource);
118  void removeImageSource(const std::string& imageSource);
119  /**
120  * enable stereo result images
121  */
122  void enableStereoResultImages(visionx::ImageDimension imageDimension, visionx::ImageType imageType);
123 
124  /**
125  * @see visionx::ImageProcessor::onInitImageProcessor()
126  */
127  void onInitImageProcessor() override;
128 
129  /**
130  * @see visionx::ImageProcessor::onConnectImageProcessor()
131  */
132  void onConnectImageProcessor() override;
133 
134  /**
135  * @see visionx::ImageProcessor::onExitImageProcessor()
136  */
137  void onExitImageProcessor() override;
138 
139  /**
140  * @see visionx::ImageProcessor::process()
141  */
142  void process() override;
143 
144  /**
145  * @see PropertyUser::createPropertyDefinitions()
146  */
148 
149  bool addImageProvider(const std::string& providerName)
150  {
151  return addImageProvider(providerName, imageDisplayType, imageProviderInfo);
152  }
153  bool addImageProvider(const std::string& providerName, visionx::ImageType imageDisplayType, visionx::ImageProviderInfo& imageProviderInfo);
154  private:
155 
156  visionx::ImageDimension targetDimension;
157  float scaleFactorX, scaleFactorY;
158 
159  std::recursive_mutex mutex, imageSourceMutex;
160 
161  std::map<std::string, visionx::CByteImageUPtrVec > cameraImages;
162  visionx::CByteImageUPtrVec resultCameraImages;
163  int numImages;
164 
165  // std::vector<std::string> providers;
166  std::string defaultProvider;
167  // std::string activeProvider;
168  visionx::ImageType imageDisplayType;
169  visionx::ImageProviderInfo imageProviderInfo;
170 
171  std::vector<std::pair<std::string, IceUtil::Time>> providerTimeouts;
172  void deleteTimedOutProviders();
173  };
174 
175 
176 
178  virtual public visionx::ResultImageProvider,
179  virtual public visionx::StereoCalibrationProviderInterface
180  {
181  friend class ImageSourceSelection;
182 
183  public:
184 
187  {
188 
189  }
190 
191  visionx::StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override
192  {
193  return stereoCalibration;
194  }
195 
196  bool getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override
197  {
198  return imagesAreUndistorted;
199  }
200 
201  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
202  {
203  return referenceFrame;
204  }
205 
206  void setStereoCalibration(visionx::StereoCalibration stereoCalibration, bool imagesAreUndistorted, const std::string& referenceFrame)
207  {
208  this->stereoCalibration = stereoCalibration;
209  this->imagesAreUndistorted = imagesAreUndistorted;
210  this->referenceFrame = referenceFrame;
211  calibrationPrx->reportStereoCalibrationChanged(this->stereoCalibration, this->imagesAreUndistorted, this->referenceFrame);
212  }
213 
214  protected:
215 
216  void onInitImageProvider() override
217  {
219  offeringTopic("StereoCalibrationInterface");
220  }
221 
222  void onConnectImageProvider() override
223  {
225  calibrationPrx = getTopic<StereoCalibrationUpdateInterfacePrx>("StereoCalibrationInterface");
226  }
227 
228  private:
229  visionx::StereoCalibration stereoCalibration;
230  bool imagesAreUndistorted;
231  StereoCalibrationUpdateInterfacePrx calibrationPrx;
232  std::string referenceFrame;
233  };
234 
235 
237 
238 }
239 
armarx::ImageSourceSelection::process
void process() override
Definition: ImageSourceSelection.cpp:141
armarx::ImageSourceSelection::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ImageSourceSelection.cpp:334
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::ImageSourceSelection::removeImageSource
void removeImageSource(const std::string &imageSource)
Definition: ImageSourceSelection.cpp:299
visionx::ResultImageProvider::ResultImageProvider
ResultImageProvider()
Definition: ImageProcessor.h:536
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
armarx::StereoResultImageProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:196
armarx::ImageSourceSelection::onInitImageProcessor
void onInitImageProcessor() override
Definition: ImageSourceSelection.cpp:38
armarx::StereoResultImageProvider::onConnectImageProvider
void onConnectImageProvider() override
This is called when the Component::onConnectComponent() setup is called.
Definition: ImageSourceSelection.h:222
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::CByteImageUPtrVec
std::vector< std::unique_ptr< CByteImage > > CByteImageUPtrVec
Definition: ImageProvider.h:58
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::ImageProcessorPropertyDefinitions::ImageProcessorPropertyDefinitions
ImageProcessorPropertyDefinitions(std::string prefix)
Definition: ImageProcessor.h:65
armarx::ImageSourceSelection
Brief description of class ImageSourceSelection.
Definition: ImageSourceSelection.h:95
armarx::ImageSourceSelection::setImageSource
void setImageSource(const std::string &imageSource, int relativeTimeoutMs, const Ice::Current &c) override
Definition: ImageSourceSelection.cpp:219
visionx::ImageProviderInfo
Definition: ImageProcessor.h:466
armarx::StereoResultImageProvider
Definition: ImageSourceSelection.h:177
armarx::ImageSourceSelection::getCurrentImageSource
std::string getCurrentImageSource(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:110
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::StereoResultImageProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:191
armarx::StereoResultImageProvider::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: ImageSourceSelection.h:216
visionx::ResultImageProvider::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: ImageProcessor.h:576
ImageProcessor.h
armarx::ImageSourceSelection::onConnectImageProcessor
void onConnectImageProcessor() override
Definition: ImageSourceSelection.cpp:46
armarx::ImageSourceSelection::enableStereoResultImages
void enableStereoResultImages(visionx::ImageDimension imageDimension, visionx::ImageType imageType)
enable stereo result images
Definition: ImageSourceSelection.cpp:313
armarx::ImageSourceSelection::onExitImageProcessor
void onExitImageProcessor() override
Definition: ImageSourceSelection.cpp:83
visionx::ImageProvider::onConnectImageProvider
virtual void onConnectImageProvider()
This is called when the Component::onConnectComponent() setup is called.
Definition: ImageProvider.h:113
armarx::StereoResultImageProvider::setStereoCalibration
void setStereoCalibration(visionx::StereoCalibration stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame)
Definition: ImageSourceSelection.h:206
armarx::StereoResultImageProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:201
armarx::ImageSourceSelectionPropertyDefinitions
Definition: ImageSourceSelection.h:54
armarx::StereoResultImageProvider::StereoResultImageProvider
StereoResultImageProvider()
Definition: ImageSourceSelection.h:185
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
armarx::ImageSourceSelection::getDefaultName
std::string getDefaultName() const override
Definition: ImageSourceSelection.h:103
armarx::ImageSourceSelection::addImageProvider
bool addImageProvider(const std::string &providerName)
Definition: ImageSourceSelection.h:149
visionx::ResultImageProvider
The ResultImageProvider is used by the ImageProcessor to stream result images to any other processor ...
Definition: ImageProcessor.h:529
armarx::PropertyDefinition
PropertyDefinition defines a property that will be available within the PropertyUser.
Definition: PropertyDefinition.h:107
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ImageSourceSelectionPropertyDefinitions::ImageSourceSelectionPropertyDefinitions
ImageSourceSelectionPropertyDefinitions(std::string prefix)
Definition: ImageSourceSelection.h:58
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36