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
30 
33 #include <VisionX/interface/core/DataTypes.h>
34 #include <VisionX/interface/core/PointCloudProcessorInterface.h>
35 
36 namespace visionx
37 {
38 
40  public virtual ResultImageProvider,
41  public virtual ResultPointCloudProvider,
42  public virtual ImageAndPointCloudProviderInterface
43  {
45 
46  public:
47  std::string
49  {
51  }
52 
53  // ManagedIceObject interface
54  protected:
55  void
57  {
58  ARMARX_IMPORTANT << "ResultImageProvider::onInitComponent();";
60  ARMARX_IMPORTANT << "ResultPointCloudProvider::onInitComponent();";
62  }
63 
64  void
66  {
67  ARMARX_IMPORTANT << "ResultImageProvider::onConnectComponent();";
69  ARMARX_IMPORTANT << "ResultPointCloudProvider::onConnectComponent();";
71  }
72 
73  void
75  {
76  ARMARX_IMPORTANT << "ResultImageProvider::onDisconnectComponent();";
78  ARMARX_IMPORTANT << "ResultPointCloudProvider::onDisconnectComponent();";
80  }
81 
82  void
84  {
85  ARMARX_IMPORTANT << "ResultImageProvider::onExitComponent();";
87  ARMARX_IMPORTANT << "ResultPointCloudProvider::onExitComponent();";
89  }
90 
91  public:
92  bool
93  hasSharedMemorySupport(const Ice::Current& c)
94  {
97  }
98  };
99 
100  /**
101  * The PointCloudAndImageProcessor class provides an interface for access to
102  * PointCloudProviders and ImageProviders via Ice and shared memory. The interface
103  * defines a set of convenience methods which simplify the pointcloud and image access.
104  */
106  virtual public ImageProcessor,
107  virtual public PointCloudProcessor,
108  virtual public PointCloudAndImageProcessorInterface
109  {
110  protected:
111  // ================================================================== //
112  // == Interface of PointCloudAndImageProcessor ====================== //
113  // ================================================================== //
114  /**
115  * Setup the vision component.
116  *
117  * Implement this method in your PointCloudAndImageProcessor in order to setup
118  * its parameters. Use this for the registration of adapters and
119  * subscription to topics
120  */
121  virtual void onInitPointCloudAndImageProcessor() = 0;
122 
123  /**
124  * Implement this method in your PointCloudAndImageProcessor in order execute parts
125  * when the component is fully initialized and about to run.
126  */
127  virtual void onConnectPointCloudAndImageProcessor() = 0;
128 
129  /**
130  * Implement this method in the PointCloudAndImageProcessor in order to execute parts
131  * when the component looses network connectivity.
132  */
133  virtual void
135  {
136  }
137 
138  /**
139  * Exit the ImapeProcessor component.
140  *
141  * Implement this method in order to clean up the PointCloudAndImageProcessor
142  */
143  virtual void onExitPointCloudAndImageProcessor() = 0;
144 
145  /**
146  * Process the vision component.
147  *
148  * The main loop of the PointCloudAndImageProcessor to be implemented in the
149  * subclass. Do not block this method. One process should execute
150  * exactly one processing step.
151  */
152  void
153  process() override
154  {
155  }
156 
157  // ================================================================== //
158  // == RunningComponent implementation =============================== //
159  // ================================================================== //
160  /**
161  * @see Component::onInitComponent()
162  */
163  void
164  onInitComponent() override
165  {
168  }
169 
170  /**
171  * @see Component::onConnectComponent()
172  */
173  void
175  {
176  // Prevent race condition by not starting the process task in the image processor
180  }
181 
182  /**
183  * @see Component::onDisconnectComponent()
184  */
185  void
187  {
190  }
191 
192  /**
193  * @see Component::onExitComponent()
194  */
195  void
196  onExitComponent() override
197  {
200  }
201 
202  // those are replaced by the on*PointCloudAndImageProcessor()
203  void
205  {
206  }
207 
208  void
210  {
211  }
212 
213  void
215  {
216  }
217 
218  void
220  {
222  }
223 
224  void
226  {
228  }
229 
230  void
232  {
234  }
235 
236  void
238  {
240  }
241 
242  template <typename PointT>
243  void
244  enableResultImagesAndPointClouds(std::string resultProviderName,
245  int numberImages,
246  ImageDimension imageDimension,
247  ImageType imageType)
248  {
249  if (!resultImageProvider)
250  {
251  ARMARX_VERBOSE << "Enabling ResultImageProvider with " << numberImages
252  << " result images.";
254  Component::create<ResultImageAndPointCloudProvider>();
255  myProvider->setName(resultProviderName.empty() ? getName() + "Result"
256  : resultProviderName);
257 
258 
259  myProvider->setNumberResultImages(numberImages);
260  myProvider->setResultImageFormat(imageDimension, imageType);
261 
262 
263  resultImageProvider = myProvider;
264 
265  if (resultProviderName == "")
266  {
267  resultProviderName = getName() + "Result";
268  }
269 
270  std::unique_lock lock(resultProviderMutex);
271 
272  if (resultPointCloudProviders.count(resultProviderName))
273  {
274  ARMARX_WARNING << "result point cloud provider already exists: "
275  << resultProviderName;
276  }
277  else
278  {
279  MetaPointCloudFormatPtr info =
280  pointCloudProviderInfoMap.begin()->second.pointCloudFormat;
281 
282  PointContentType pointContentType = tools::getPointContentType<PointT>();
283 
284  size_t capacity = info->capacity * tools::getBytesPerPoint(pointContentType) /
285  tools::getBytesPerPoint(info->type);
286 
287  //enableResultPointClouds(resultProviderName, capacity, pointContentType);
288 
289  //IceInternal::Handle<ResultPointCloudProvider> resultProvider = Component::create<ResultPointCloudProvider>();
290  myProvider->setName(resultProviderName);
291  myProvider->setShmCapacity(capacity);
292  myProvider->setPointContentType(pointContentType);
293 
294  //getArmarXManager()->addObject(myProvider);
295 
296  {
297  resultPointCloudProviders.emplace(myProvider->getName(), myProvider);
298  }
299  lock.unlock();
300 
301  //myProvider->getObjectScheduler()->waitForObjectState(eManagedIceObjectStarted);
302  }
303 
304  ARMARX_IMPORTANT << 7;
305  getArmarXManager()->addObject(myProvider);
306  // wait for resultImageProvider
307  ARMARX_IMPORTANT << "before waitForObjectState(armarx::eManagedIceObjectStarted);";
308  myProvider->getObjectScheduler()->waitForObjectState(
309  armarx::eManagedIceObjectStarted);
310  ARMARX_IMPORTANT << "after waitForObjectState(armarx::eManagedIceObjectStarted);";
311  }
312  }
313  };
314 } // namespace visionx
visionx::PointCloudAndImageProcessor::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
Definition: PointCloudAndImageProcessor.h:237
visionx::PointCloudAndImageProcessor::onConnectComponent
void onConnectComponent() override
Definition: PointCloudAndImageProcessor.h:174
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:187
visionx::PointCloudProvider::onConnectComponent
void onConnectComponent() override
Definition: PointCloudProvider.cpp:80
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
visionx::PointCloudAndImageProcessor::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: PointCloudAndImageProcessor.h:214
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::ImageProcessor::onInitComponent
void onInitComponent() override
Definition: ImageProcessor.cpp:55
visionx::ResultPointCloudProvider::getDefaultName
virtual std::string getDefaultName() const override
Retrieve default name of component.
Definition: PointCloudProcessor.cpp:65
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:98
visionx::ImageProcessor::onExitComponent
void onExitComponent() override
Definition: ImageProcessor.cpp:97
visionx::PointCloudAndImageProcessor::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component looses net...
Definition: PointCloudAndImageProcessor.h:231
armarx::ManagedIceObject::getArmarXManager
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Definition: ManagedIceObject.cpp:360
visionx::PointCloudProcessor::onDisconnectComponent
virtual void onDisconnectComponent() override
Definition: PointCloudProcessor.cpp:234
visionx::ImageProvider::onExitComponent
void onExitComponent() override
Definition: ImageProvider.cpp:161
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:209
visionx::PointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: PointCloudProvider.h:81
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::PointCloudAndImageProcessor::onExitComponent
void onExitComponent() override
Definition: PointCloudAndImageProcessor.h:196
visionx::PointCloudProcessor::onExitComponent
virtual void onExitComponent() override
Definition: PointCloudProcessor.cpp:241
visionx::PointCloudProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: PointCloudProvider.cpp:101
visionx::PointCloudProvider::onExitComponent
void onExitComponent() override
Definition: PointCloudProvider.cpp:112
visionx::ImageProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ImageProvider.cpp:149
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:74
visionx::ImageProcessor::onConnectComponent
void onConnectComponent() override
Definition: ImageProcessor.cpp:78
visionx::PointCloudProcessor::pointCloudProviderInfoMap
std::map< std::string, PointCloudProviderInfo > pointCloudProviderInfoMap
Definition: PointCloudProcessor.h:637
ImageProcessor.h
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:177
visionx::PointCloudAndImageProcessor::onInitComponent
void onInitComponent() override
Definition: PointCloudAndImageProcessor.h:164
visionx::ResultImageAndPointCloudProvider::onConnectComponent
void onConnectComponent()
Pure virtual hook for the subclass.
Definition: PointCloudAndImageProcessor.h:65
visionx::ResultImageAndPointCloudProvider::onExitComponent
void onExitComponent()
Hook for subclass.
Definition: PointCloudAndImageProcessor.h:83
visionx::ResultImageAndPointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c)
Definition: PointCloudAndImageProcessor.h:93
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:225
visionx::PointCloudProvider::onInitComponent
void onInitComponent() override
Definition: PointCloudProvider.cpp:61
ArmarXObjectScheduler.h
PointCloudProcessor.h
visionx::ResultPointCloudProvider
The ResultPointCloudProvider is used by the PointCloudProcessor to stream result PointClouds to any o...
Definition: PointCloudProcessor.h:119
visionx::ImageProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageProvider.h:94
visionx::PointCloudAndImageProcessor::process
void process() override
Process the vision component.
Definition: PointCloudAndImageProcessor.h:153
visionx::PointCloudProcessor::onConnectComponent
virtual void onConnectComponent() override
Definition: PointCloudProcessor.cpp:216
visionx::ImageProvider::onConnectComponent
void onConnectComponent() override
Definition: ImageProvider.cpp:107
visionx::ImageProvider::onInitComponent
void onInitComponent() override
Definition: ImageProvider.cpp:91
visionx::PointCloudProcessor::onInitComponent
virtual void onInitComponent() override
Definition: PointCloudProcessor.cpp:136
visionx::tools::getBytesPerPoint
size_t getBytesPerPoint(visionx::PointContentType pointContent)
Definition: PointCloudConversions.cpp:85
visionx::ResultImageProvider
The ResultImageProvider is used by the ImageProcessor to stream result images to any other processor ...
Definition: ImageProcessor.h:541
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
visionx::PointCloudAndImageProcessor::onInitPointCloudAndImageProcessor
virtual void onInitPointCloudAndImageProcessor()=0
Setup the vision component.
visionx::ImageProcessor::startProcessorTask
bool startProcessorTask
Definition: ImageProcessor.h:433
visionx::ResultImageAndPointCloudProvider::onInitComponent
void onInitComponent()
Pure virtual hook for the subclass.
Definition: PointCloudAndImageProcessor.h:56
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
visionx::PointCloudAndImageProcessor::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: PointCloudAndImageProcessor.h:204
visionx::PointCloudAndImageProcessor::onDisconnectPointCloudAndImageProcessor
virtual void onDisconnectPointCloudAndImageProcessor()
Implement this method in the PointCloudAndImageProcessor in order to execute parts when the component...
Definition: PointCloudAndImageProcessor.h:134
visionx::PointCloudAndImageProcessor::onDisconnectComponent
void onDisconnectComponent() override
Definition: PointCloudAndImageProcessor.h:186
visionx::ImageProcessor::resultImageProvider
IceInternal::Handle< ResultImageProvider > resultImageProvider
Definition: ImageProcessor.h:424
visionx::ImageProcessor::onDisconnectComponent
void onDisconnectComponent() override
Definition: ImageProcessor.cpp:90
visionx::PointCloudAndImageProcessor::enableResultImagesAndPointClouds
void enableResultImagesAndPointClouds(std::string resultProviderName, int numberImages, ImageDimension imageDimension, ImageType imageType)
Definition: PointCloudAndImageProcessor.h:244
visionx::ResultImageAndPointCloudProvider
Definition: PointCloudAndImageProcessor.h:39
visionx::PointCloudProcessor::resultProviderMutex
std::shared_mutex resultProviderMutex
Definition: PointCloudProcessor.h:643
visionx::PointCloudProcessor::resultPointCloudProviders
std::map< std::string, IceInternal::Handle< ResultPointCloudProvider > > resultPointCloudProviders
Definition: PointCloudProcessor.h:642
visionx::PointCloudAndImageProcessor
The PointCloudAndImageProcessor class provides an interface for access to PointCloudProviders and Ima...
Definition: PointCloudAndImageProcessor.h:105
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:219