ResultImageFuser.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::ArmarXObjects::ResultImageFuser
19  * @author Markus Grotz ( markus dot grotz at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
31 
33 #include <VisionX/interface/core/ImageProviderInterface.h>
35 
36 #include <Eigen/Core>
37 
38 #include <mutex>
39 
40 
41 namespace armarx
42 {
43 
44  inline std::vector<std::string> splitter(std::string const& propertyValue)
45  {
46  std::vector<std::string> result = Split(propertyValue, ",");
47  return result;
48  }
49 
50  inline Eigen::Vector3i extractColorValue(std::string propertyValue)
51  {
52  int number = (int) strtol(&propertyValue.c_str()[1], NULL, 16);
53 
54  int r = number >> 16;
55  int g = number >> 8 & 0xFF;
56  int b = number & 0xFF;
57 
58  return Eigen::Vector3i(r, g, b);
59  }
60 
61 
62 
63  /**
64  * @class ResultImageFuserPropertyDefinitions
65  * @brief
66  */
69  {
70  public:
73  {
74  defineOptionalProperty<int>("width", 640, "image width");
75  defineOptionalProperty<int>("height", 480, "image height");
76  defineOptionalProperty<int>("numImages", 1, "number of images");
78  defineOptionalProperty<Eigen::Vector3i>("colorMask", extractColorValue("#FFFFFF"),
79  "image color that should be used as alpha channel").setFactory(f);
80  PropertyDefinition<std::vector<std::string>>::PropertyFactoryFunction g = &splitter;
81  defineOptionalProperty<std::vector<std::string>>("imageProviders", splitter("TestImageProvider"),
82  "comma separated list of image providers").setFactory(g);
83  }
84  };
85 
86  /**
87  * @class ResultImageFuser
88  *
89  * @ingroup VisionX-Components
90  * @brief A brief description
91  *
92  *
93  * Detailed Description
94  */
96  virtual public visionx::CapturingImageProvider
97  {
98  public:
99  /**
100  * @see armarx::ManagedIceObject::getDefaultName()
101  */
102  std::string getDefaultName() const override
103  {
104  return "ResultImageFuser";
105  }
106 
107 
108  // void setResultImageProviders(std::string imageProviders, const Ice::Current& c = Ice::emptyCurrent);
109 
110  protected:
111 
112  /**
113  * @see visionx::ImageProviderBase::onInitImageProvider()
114  */
115  void onInitCapturingImageProvider() override;
116 
117  /**
118  * @see visionx::ImageProviderBase::onExitImageProvider()
119  */
120  void onExitCapturingImageProvider() override;
121 
122  /**
123  * @see visionx::ImageProviderBase::onStartCapture(float frameRate)
124  */
125  void onStartCapture(float frameRate) override;
126 
127  /**
128  * @see visionx::ImageProviderBase::onStopCapture()
129  */
130  void onStopCapture() override;
131 
132  /**
133  * @see visionx::ImageProviderBase::capture()
134  */
135  bool capture(void** ppImages) override;
136 
137  /**
138  * @see PropertyUser::createPropertyDefinitions()
139  */
141 
142  private:
143 
144 
145  void setResultImageProviders(std::vector<std::string> imageProviders);
146 
147  void pollImageProviders();
148 
149  int bytesPerPixel;
150  int width;
151  int height;
152  int numImages;
153  std::mutex imageMutex;
154 
155  Eigen::Vector3i colorMask;
156  std::map<std::string, CByteImage**> imageSources;
157  std::map<std::string, bool> imageAvailable;
158 
159 
161 
162  };
163 }
164 
armarx::ResultImageFuser::onStartCapture
void onStartCapture(float frameRate) override
Definition: ResultImageFuser.cpp:58
armarx::ResultImageFuser::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
Definition: ResultImageFuser.cpp:51
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::ResultImageFuser
A brief description.
Definition: ResultImageFuser.h:95
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:198
armarx::splitter
std::vector< std::string > splitter(std::string const &propertyValue)
Definition: ResultImageFuser.h:44
armarx::ResultImageFuser::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
Definition: ResultImageFuser.cpp:33
armarx::ResultImageFuserPropertyDefinitions
Definition: ResultImageFuser.h:67
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:35
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
StringHelpers.h
armarx::ResultImageFuser::onStopCapture
void onStopCapture() override
Definition: ResultImageFuser.cpp:69
armarx::extractColorValue
Eigen::Vector3i extractColorValue(std::string propertyValue)
Definition: ResultImageFuser.h:50
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:106
armarx::ResultImageFuserPropertyDefinitions::ResultImageFuserPropertyDefinitions
ResultImageFuserPropertyDefinitions(std::string prefix)
Definition: ResultImageFuser.h:71
visionx::CapturingImageProvider
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
Definition: CapturingImageProvider.h:52
Component.h
CapturingImageProvider.h
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::CapturingImageProviderPropertyDefinitions
Definition: CapturingImageProvider.h:37
ImageUtil.h
armarx::ResultImageFuser::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ResultImageFuser.cpp:231
armarx::PropertyDefinition
PropertyDefinition defines a property that will be available within the PropertyUser.
Definition: PropertyDefinition.h:107
armarx::ResultImageFuser::getDefaultName
std::string getDefaultName() const override
Definition: ResultImageFuser.h:102
armarx::PropertyDefinition::PropertyFactoryFunction
std::function< PropertyType(std::string)> PropertyFactoryFunction
Definition: PropertyDefinition.h:114
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
PropertyDefinition.h
visionx::CapturingImageProviderPropertyDefinitions::CapturingImageProviderPropertyDefinitions
CapturingImageProviderPropertyDefinitions(std::string prefix)
Definition: CapturingImageProvider.h:40