PointCloudAndImageProcessor.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::Core
19  * @author David Gonzalez Aguirre (david dot gonzalez at kit dot edu)
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 
28 // VisionX
29 #include <VisionX/interface/core/DataTypes.h>
30 #include <VisionX/interface/core/PointCloudProcessorInterface.h>
31 
34 
36 
37 namespace visionx
38 {
39 
41  : public virtual ResultImageProvider,
42  public virtual ResultPointCloudProvider,
43  public virtual ImageAndPointCloudProviderInterface
44  {
46 
47  public:
48  std::string getDefaultName() const
49  {
51  }
52 
53  // ManagedIceObject interface
54  protected:
56  {
57  ARMARX_IMPORTANT << "ResultImageProvider::onInitComponent();";
59  ARMARX_IMPORTANT << "ResultPointCloudProvider::onInitComponent();";
61  }
62 
64  {
65  ARMARX_IMPORTANT << "ResultImageProvider::onConnectComponent();";
67  ARMARX_IMPORTANT << "ResultPointCloudProvider::onConnectComponent();";
69  }
71  {
72  ARMARX_IMPORTANT << "ResultImageProvider::onDisconnectComponent();";
74  ARMARX_IMPORTANT << "ResultPointCloudProvider::onDisconnectComponent();";
76  }
78  {
79  ARMARX_IMPORTANT << "ResultImageProvider::onExitComponent();";
81  ARMARX_IMPORTANT << "ResultPointCloudProvider::onExitComponent();";
83  }
84 
85  public:
86  bool hasSharedMemorySupport(const Ice::Current& c)
87  {
89  }
90  };
91 
92  /**
93  * The PointCloudAndImageProcessor class provides an interface for access to
94  * PointCloudProviders and ImageProviders via Ice and shared memory. The interface
95  * defines a set of convenience methods which simplify the pointcloud and image access.
96  */
98  virtual public ImageProcessor,
99  virtual public PointCloudProcessor,
100  virtual public PointCloudAndImageProcessorInterface
101  {
102  protected:
103  // ================================================================== //
104  // == Interface of PointCloudAndImageProcessor ====================== //
105  // ================================================================== //
106  /**
107  * Setup the vision component.
108  *
109  * Implement this method in your PointCloudAndImageProcessor in order to setup
110  * its parameters. Use this for the registration of adapters and
111  * subscription to topics
112  */
113  virtual void onInitPointCloudAndImageProcessor() = 0;
114 
115  /**
116  * Implement this method in your PointCloudAndImageProcessor in order execute parts
117  * when the component is fully initialized and about to run.
118  */
119  virtual void onConnectPointCloudAndImageProcessor() = 0;
120 
121  /**
122  * Implement this method in the PointCloudAndImageProcessor in order to execute parts
123  * when the component looses network connectivity.
124  */
126 
127  /**
128  * Exit the ImapeProcessor component.
129  *
130  * Implement this method in order to clean up the PointCloudAndImageProcessor
131  */
132  virtual void onExitPointCloudAndImageProcessor() = 0;
133 
134  /**
135  * Process the vision component.
136  *
137  * The main loop of the PointCloudAndImageProcessor to be implemented in the
138  * subclass. Do not block this method. One process should execute
139  * exactly one processing step.
140  */
141  void process() override { }
142 
143  // ================================================================== //
144  // == RunningComponent implementation =============================== //
145  // ================================================================== //
146  /**
147  * @see Component::onInitComponent()
148  */
149  void onInitComponent() override
150  {
153  }
154 
155  /**
156  * @see Component::onConnectComponent()
157  */
158  void onConnectComponent() override
159  {
160  // Prevent race condition by not starting the process task in the image processor
164  }
165 
166  /**
167  * @see Component::onDisconnectComponent()
168  */
169  void onDisconnectComponent() override
170  {
173  }
174 
175  /**
176  * @see Component::onExitComponent()
177  */
178  void onExitComponent() override
179  {
182  }
183 
184 
185  // those are replaced by the on*PointCloudAndImageProcessor()
186  void onInitImageProcessor() override { }
187  void onConnectImageProcessor() override { }
188  void onExitImageProcessor() override { }
189 
191  {
193  }
195  {
197  }
199  {
201  }
203  {
205  }
206 
207 
208  template<typename PointT>
209  void enableResultImagesAndPointClouds(std::string resultProviderName,
210  int numberImages, ImageDimension imageDimension, ImageType imageType)
211  {
212  if (!resultImageProvider)
213  {
214  ARMARX_VERBOSE << "Enabling ResultImageProvider with " << numberImages << " result images.";
215  IceInternal::Handle<ResultImageAndPointCloudProvider> myProvider = Component::create<ResultImageAndPointCloudProvider>();
216  myProvider->setName(resultProviderName.empty() ? getName() + "Result" : resultProviderName);
217 
218 
219  myProvider->setNumberResultImages(numberImages);
220  myProvider->setResultImageFormat(imageDimension, imageType);
221 
222 
223  resultImageProvider = myProvider;
224 
225  if (resultProviderName == "")
226  {
227  resultProviderName = getName() + "Result";
228  }
229 
230  std::unique_lock lock(resultProviderMutex);
231 
232  if (resultPointCloudProviders.count(resultProviderName))
233  {
234  ARMARX_WARNING << "result point cloud provider already exists: " << resultProviderName;
235  }
236  else
237  {
238  MetaPointCloudFormatPtr info = pointCloudProviderInfoMap.begin()->second.pointCloudFormat;
239 
240  PointContentType pointContentType = tools::getPointContentType<PointT>();
241 
242  size_t capacity = info->capacity * tools::getBytesPerPoint(pointContentType) / tools::getBytesPerPoint(info->type);
243 
244  //enableResultPointClouds(resultProviderName, capacity, pointContentType);
245 
246  //IceInternal::Handle<ResultPointCloudProvider> resultProvider = Component::create<ResultPointCloudProvider>();
247  myProvider->setName(resultProviderName);
248  myProvider->setShmCapacity(capacity);
249  myProvider->setPointContentType(pointContentType);
250 
251  //getArmarXManager()->addObject(myProvider);
252 
253  {
254  resultPointCloudProviders.emplace(myProvider->getName(), myProvider);
255  }
256  lock.unlock();
257 
258  //myProvider->getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted);
259 
260  }
261 
262  ARMARX_IMPORTANT << 7;
263  getArmarXManager()->addObject(myProvider);
264  // wait for resultImageProvider
265  ARMARX_IMPORTANT << "before waitForObjectState(armarx::eManagedIceObjectStarted);";
266  myProvider->getObjectScheduler()->waitForObjectState(armarx::eManagedIceObjectStarted);
267  ARMARX_IMPORTANT << "after waitForObjectState(armarx::eManagedIceObjectStarted);";
268 
269  }
270  }
271  };
272 }
273 
274 
visionx::PointCloudAndImageProcessor::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
Definition: PointCloudAndImageProcessor.h:202
visionx::PointCloudAndImageProcessor::onConnectComponent
void onConnectComponent() override
Definition: PointCloudAndImageProcessor.h:158
visionx::PointCloudAndImageProcessor::onConnectPointCloudAndImageProcessor
virtual void onConnectPointCloudAndImageProcessor()=0
Implement this method in your PointCloudAndImageProcessor in order execute parts when the component i...
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
visionx::PointCloudProvider::onConnectComponent
void onConnectComponent() override
Definition: PointCloudProvider.cpp:77
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
visionx::PointCloudAndImageProcessor::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: PointCloudAndImageProcessor.h:188
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ImageProcessor::onInitComponent
void onInitComponent() override
Definition: ImageProcessor.cpp:52
visionx::ResultPointCloudProvider::getDefaultName
virtual std::string getDefaultName() const override
Retrieve default name of component.
Definition: PointCloudProcessor.cpp:63
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
visionx::ImageProcessor::onExitComponent
void onExitComponent() override
Definition: ImageProcessor.cpp:89
visionx::PointCloudAndImageProcessor::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component looses net...
Definition: PointCloudAndImageProcessor.h:198
armarx::ManagedIceObject::getArmarXManager
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Definition: ManagedIceObject.cpp:348
visionx::PointCloudProcessor::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: PointCloudProcessor.cpp:217
visionx::ImageProvider::onExitComponent
void onExitComponent() override
Definition: ImageProvider.cpp:152
visionx::PointCloudAndImageProcessor::onConnectImageProcessor
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
Definition: PointCloudAndImageProcessor.h:187
visionx::PointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: PointCloudProvider.h:81
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::PointCloudAndImageProcessor::onExitComponent
void onExitComponent() override
Definition: PointCloudAndImageProcessor.h:178
visionx::PointCloudProcessor::onExitComponent
virtual void onExitComponent() override
Definition: PointCloudProcessor.cpp:223
visionx::PointCloudProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: PointCloudProvider.cpp:95
visionx::PointCloudProvider::onExitComponent
void onExitComponent() override
Definition: PointCloudProvider.cpp:106
visionx::ImageProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ImageProvider.cpp:141
IceInternal::Handle
Definition: forward_declarations.h:8
visionx::PointCloudAndImageProcessor::onExitPointCloudAndImageProcessor
virtual void onExitPointCloudAndImageProcessor()=0
Exit the ImapeProcessor component.
visionx::ResultImageAndPointCloudProvider::onDisconnectComponent
void onDisconnectComponent()
Hook for subclass.
Definition: PointCloudAndImageProcessor.h:70
visionx::ImageProcessor::onConnectComponent
void onConnectComponent() override
Definition: ImageProcessor.cpp:72
visionx::PointCloudProcessor::pointCloudProviderInfoMap
std::map< std::string, PointCloudProviderInfo > pointCloudProviderInfoMap
Definition: PointCloudProcessor.h:610
ImageProcessor.h
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:186
visionx::PointCloudAndImageProcessor::onInitComponent
void onInitComponent() override
Definition: PointCloudAndImageProcessor.h:149
visionx::ResultImageAndPointCloudProvider::onConnectComponent
void onConnectComponent()
Pure virtual hook for the subclass.
Definition: PointCloudAndImageProcessor.h:63
visionx::ResultImageAndPointCloudProvider::onExitComponent
void onExitComponent()
Hook for subclass.
Definition: PointCloudAndImageProcessor.h:77
visionx::ResultImageAndPointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c)
Definition: PointCloudAndImageProcessor.h:86
visionx::PointCloudAndImageProcessor::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
Definition: PointCloudAndImageProcessor.h:194
visionx::PointCloudProvider::onInitComponent
void onInitComponent() override
Definition: PointCloudProvider.cpp:59
ArmarXObjectScheduler.h
PointCloudProcessor.h
visionx::ResultPointCloudProvider
The ResultPointCloudProvider is used by the PointCloudProcessor to stream result PointClouds to any o...
Definition: PointCloudProcessor.h:123
visionx::ImageProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageProvider.h:93
visionx::PointCloudAndImageProcessor::process
void process() override
Process the vision component.
Definition: PointCloudAndImageProcessor.h:141
visionx::PointCloudProcessor::onConnectComponent
virtual void onConnectComponent() override
Definition: PointCloudProcessor.cpp:201
visionx::ImageProvider::onConnectComponent
void onConnectComponent() override
Definition: ImageProvider.cpp:104
visionx::ImageProvider::onInitComponent
void onInitComponent() override
Definition: ImageProvider.cpp:88
visionx::PointCloudProcessor::onInitComponent
virtual void onInitComponent() override
Definition: PointCloudProcessor.cpp:123
visionx::tools::getBytesPerPoint
size_t getBytesPerPoint(visionx::PointContentType pointContent)
Definition: PointCloudConversions.cpp:64
visionx::ResultImageProvider
The ResultImageProvider is used by the ImageProcessor to stream result images to any other processor ...
Definition: ImageProcessor.h:529
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
visionx::PointCloudAndImageProcessor::onInitPointCloudAndImageProcessor
virtual void onInitPointCloudAndImageProcessor()=0
Setup the vision component.
visionx::ImageProcessor::startProcessorTask
bool startProcessorTask
Definition: ImageProcessor.h:416
visionx::ResultImageAndPointCloudProvider::onInitComponent
void onInitComponent()
Pure virtual hook for the subclass.
Definition: PointCloudAndImageProcessor.h:55
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
visionx::PointCloudAndImageProcessor::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: PointCloudAndImageProcessor.h:186
visionx::PointCloudAndImageProcessor::onDisconnectPointCloudAndImageProcessor
virtual void onDisconnectPointCloudAndImageProcessor()
Implement this method in the PointCloudAndImageProcessor in order to execute parts when the component...
Definition: PointCloudAndImageProcessor.h:125
visionx::PointCloudAndImageProcessor::onDisconnectComponent
void onDisconnectComponent() override
Definition: PointCloudAndImageProcessor.h:169
visionx::ImageProcessor::resultImageProvider
IceInternal::Handle< ResultImageProvider > resultImageProvider
Definition: ImageProcessor.h:407
visionx::ImageProcessor::onDisconnectComponent
void onDisconnectComponent() override
Definition: ImageProcessor.cpp:83
visionx::PointCloudAndImageProcessor::enableResultImagesAndPointClouds
void enableResultImagesAndPointClouds(std::string resultProviderName, int numberImages, ImageDimension imageDimension, ImageType imageType)
Definition: PointCloudAndImageProcessor.h:209
visionx::ResultImageAndPointCloudProvider
Definition: PointCloudAndImageProcessor.h:40
visionx::PointCloudProcessor::resultProviderMutex
std::shared_mutex resultProviderMutex
Definition: PointCloudProcessor.h:615
visionx::PointCloudProcessor::resultPointCloudProviders
std::map< std::string, IceInternal::Handle< ResultPointCloudProvider > > resultPointCloudProviders
Definition: PointCloudProcessor.h:614
visionx::PointCloudAndImageProcessor
The PointCloudAndImageProcessor class provides an interface for access to PointCloudProviders and Ima...
Definition: PointCloudAndImageProcessor.h:97
visionx::ResultImageAndPointCloudProvider::getDefaultName
std::string getDefaultName() const
Retrieve default name of component.
Definition: PointCloudAndImageProcessor.h:48
visionx::PointCloudAndImageProcessor::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Setup the vision component.
Definition: PointCloudAndImageProcessor.h:190