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 
35 namespace armarx
36 {
37 
38  class StereoResultImageProvider;
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  {
58  defineOptionalProperty<visionx::ImageDimension>(
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));
72  defineOptionalProperty<int>(
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 
78  defineOptionalProperty<std::string>(
79  "resultProviderName", "Armar3ImageProvider", "Names of the result image provider");
80  defineOptionalProperty<std::string>(
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  {
194  friend class ImageSourceSelection;
195 
196  public:
198  {
199  }
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
armarx::ImageSourceSelection::process
void process() override
Definition: ImageSourceSelection.cpp:152
armarx::ImageSourceSelection::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ImageSourceSelection.cpp:377
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::ImageSourceSelection::removeImageSource
void removeImageSource(const std::string &imageSource)
Definition: ImageSourceSelection.cpp:340
visionx::ResultImageProvider::ResultImageProvider
ResultImageProvider()
Definition: ImageProcessor.h:546
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:98
armarx::StereoResultImageProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:208
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:240
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::CByteImageUPtrVec
std::vector< std::unique_ptr< CByteImage > > CByteImageUPtrVec
Definition: ImageProvider.h:57
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::ImageProcessorPropertyDefinitions::ImageProcessorPropertyDefinitions
ImageProcessorPropertyDefinitions(std::string prefix)
Definition: ImageProcessor.h:64
armarx::ImageSourceSelection
Brief description of class ImageSourceSelection.
Definition: ImageSourceSelection.h:101
armarx::ImageSourceSelection::setImageSource
void setImageSource(const std::string &imageSource, int relativeTimeoutMs, const Ice::Current &c) override
Definition: ImageSourceSelection.cpp:244
visionx::ImageProviderInfo
Definition: ImageProcessor.h:479
armarx::StereoResultImageProvider
Definition: ImageSourceSelection.h:190
armarx::ImageSourceSelection::getCurrentImageSource
std::string getCurrentImageSource(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:120
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::StereoResultImageProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:202
armarx::StereoResultImageProvider::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: ImageSourceSelection.h:233
visionx::ResultImageProvider::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: ImageProcessor.h:592
ImageProcessor.h
armarx::ImageSourceSelection::onConnectImageProcessor
void onConnectImageProcessor() override
Definition: ImageSourceSelection.cpp:47
armarx::ImageSourceSelection::enableStereoResultImages
void enableStereoResultImages(visionx::ImageDimension imageDimension, visionx::ImageType imageType)
enable stereo result images
Definition: ImageSourceSelection.cpp:353
armarx::ImageSourceSelection::onExitImageProcessor
void onExitImageProcessor() override
Definition: ImageSourceSelection.cpp:94
visionx::ImageProvider::onConnectImageProvider
virtual void onConnectImageProvider()
This is called when the Component::onConnectComponent() setup is called.
Definition: ImageProvider.h:115
armarx::StereoResultImageProvider::setStereoCalibration
void setStereoCalibration(visionx::StereoCalibration stereoCalibration, bool imagesAreUndistorted, const std::string &referenceFrame)
Definition: ImageSourceSelection.h:220
armarx::StereoResultImageProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSourceSelection.h:214
armarx::ImageSourceSelectionPropertyDefinitions
Definition: ImageSourceSelection.h:51
armarx::StereoResultImageProvider::StereoResultImageProvider
StereoResultImageProvider()
Definition: ImageSourceSelection.h:197
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::ImageProcessorPropertyDefinitions
Definition: ImageProcessor.h:61
armarx::ImageSourceSelection::getDefaultName
std::string getDefaultName() const override
Definition: ImageSourceSelection.h:110
armarx::ImageSourceSelection::addImageProvider
bool addImageProvider(const std::string &providerName)
Definition: ImageSourceSelection.h:161
visionx::ResultImageProvider
The ResultImageProvider is used by the ImageProcessor to stream result images to any other processor ...
Definition: ImageProcessor.h:541
armarx::PropertyDefinition
PropertyDefinition defines a property that will be available within the PropertyUser.
Definition: PropertyDefinition.h:117
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ImageSourceSelectionPropertyDefinitions::ImageSourceSelectionPropertyDefinitions
ImageSourceSelectionPropertyDefinitions(std::string prefix)
Definition: ImageSourceSelection.h:55
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:38