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 
27 #include <mutex>
28 
29 #include <Eigen/Core>
30 
35 
37 #include <VisionX/interface/core/ImageProviderInterface.h>
39 
40 namespace armarx
41 {
42 
43  inline std::vector<std::string>
44  splitter(std::string const& propertyValue)
45  {
46  std::vector<std::string> result = Split(propertyValue, ",");
47  return result;
48  }
49 
50  inline Eigen::Vector3i
51  extractColorValue(std::string propertyValue)
52  {
53  int number = (int)strtol(&propertyValue.c_str()[1], NULL, 16);
54 
55  int r = number >> 16;
56  int g = number >> 8 & 0xFF;
57  int b = number & 0xFF;
58 
59  return Eigen::Vector3i(r, g, b);
60  }
61 
62  /**
63  * @class ResultImageFuserPropertyDefinitions
64  * @brief
65  */
68  {
69  public:
72  {
73  defineOptionalProperty<int>("width", 640, "image width");
74  defineOptionalProperty<int>("height", 480, "image height");
75  defineOptionalProperty<int>("numImages", 1, "number of images");
77  defineOptionalProperty<Eigen::Vector3i>(
78  "colorMask",
79  extractColorValue("#FFFFFF"),
80  "image color that should be used as alpha channel")
81  .setFactory(f);
82  PropertyDefinition<std::vector<std::string>>::PropertyFactoryFunction g = &splitter;
83  defineOptionalProperty<std::vector<std::string>>(
84  "imageProviders",
85  splitter("TestImageProvider"),
86  "comma separated list of image providers")
87  .setFactory(g);
88  }
89  };
90 
91  /**
92  * @class ResultImageFuser
93  *
94  * @ingroup VisionX-Components
95  * @brief A brief description
96  *
97  *
98  * Detailed Description
99  */
101  {
102  public:
103  /**
104  * @see armarx::ManagedIceObject::getDefaultName()
105  */
106  std::string
107  getDefaultName() const override
108  {
109  return "ResultImageFuser";
110  }
111 
112  // void setResultImageProviders(std::string imageProviders, const Ice::Current& c = Ice::emptyCurrent);
113 
114  protected:
115  /**
116  * @see visionx::ImageProviderBase::onInitImageProvider()
117  */
118  void onInitCapturingImageProvider() override;
119 
120  /**
121  * @see visionx::ImageProviderBase::onExitImageProvider()
122  */
123  void onExitCapturingImageProvider() override;
124 
125  /**
126  * @see visionx::ImageProviderBase::onStartCapture(float frameRate)
127  */
128  void onStartCapture(float frameRate) override;
129 
130  /**
131  * @see visionx::ImageProviderBase::onStopCapture()
132  */
133  void onStopCapture() override;
134 
135  /**
136  * @see visionx::ImageProviderBase::capture()
137  */
138  bool capture(void** ppImages) override;
139 
140  /**
141  * @see PropertyUser::createPropertyDefinitions()
142  */
144 
145  private:
146  void setResultImageProviders(std::vector<std::string> imageProviders);
147 
148  void pollImageProviders();
149 
150  int bytesPerPixel;
151  int width;
152  int height;
153  int numImages;
154  std::mutex imageMutex;
155 
156  Eigen::Vector3i colorMask;
157  std::map<std::string, CByteImage**> imageSources;
158  std::map<std::string, bool> imageAvailable;
159 
160 
162  };
163 } // namespace armarx
armarx::ResultImageFuser::onStartCapture
void onStartCapture(float frameRate) override
Definition: ResultImageFuser.cpp:58
armarx::ResultImageFuser::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
Definition: ResultImageFuser.cpp:53
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::ResultImageFuser
A brief description.
Definition: ResultImageFuser.h:100
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:201
armarx::splitter
std::vector< std::string > splitter(std::string const &propertyValue)
Definition: ResultImageFuser.h:44
armarx::ResultImageFuser::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
Definition: ResultImageFuser.cpp:32
armarx::ResultImageFuserPropertyDefinitions
Definition: ResultImageFuser.h:66
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:36
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
PeriodicTask.h
StringHelpers.h
armarx::ResultImageFuser::onStopCapture
void onStopCapture() override
Definition: ResultImageFuser.cpp:71
armarx::extractColorValue
Eigen::Vector3i extractColorValue(std::string propertyValue)
Definition: ResultImageFuser.h:51
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:109
armarx::ResultImageFuserPropertyDefinitions::ResultImageFuserPropertyDefinitions
ResultImageFuserPropertyDefinitions(std::string prefix)
Definition: ResultImageFuser.h:70
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:232
armarx::PropertyDefinition
PropertyDefinition defines a property that will be available within the PropertyUser.
Definition: PropertyDefinition.h:117
armarx::ResultImageFuser::getDefaultName
std::string getDefaultName() const override
Definition: ResultImageFuser.h:107
armarx::PropertyDefinition::PropertyFactoryFunction
std::function< PropertyType(std::string)> PropertyFactoryFunction
Definition: PropertyDefinition.h:123
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
PropertyDefinition.h
visionx::CapturingImageProviderPropertyDefinitions::CapturingImageProviderPropertyDefinitions
CapturingImageProviderPropertyDefinitions(std::string prefix)
Definition: CapturingImageProvider.h:40