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
36namespace visionx
37{
38
40 public virtual ResultImageProvider,
41 public virtual ResultPointCloudProvider,
42 public virtual ImageAndPointCloudProviderInterface
43 {
45
46 public:
47 std::string
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
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 */
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 */
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
137
138 /**
139 * Exit the ImapeProcessor component.
140 *
141 * Implement this method in order to clean up the PointCloudAndImageProcessor
142 */
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
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
191
192 /**
193 * @see Component::onExitComponent()
194 */
195 void
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
223
224 void
229
230 void
235
236 void
241
242 template <typename PointT>
243 void
244 enableResultImagesAndPointClouds(std::string resultProviderName,
245 int numberImages,
246 ImageDimension imageDimension,
247 ImageType imageType)
248 {
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
constexpr T c
virtual void onExitComponent()
Hook for subclass.
virtual void onDisconnectComponent()
Hook for subclass.
virtual void onConnectComponent()=0
Pure virtual hook for the subclass.
std::string getName() const
Retrieve name of object.
virtual void onInitComponent()=0
Pure virtual hook for the subclass.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
void onInitComponent() override
IceInternal::Handle< ResultImageProvider > resultImageProvider
void onDisconnectComponent() override
void onConnectComponent() override
void onExitComponent() override
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
The PointCloudAndImageProcessor class provides an interface for access to PointCloudProviders and Ima...
virtual void onConnectPointCloudAndImageProcessor()=0
Implement this method in your PointCloudAndImageProcessor in order execute parts when the component i...
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void onExitImageProcessor() override
Exit the ImapeProcessor component.
virtual void onDisconnectPointCloudAndImageProcessor()
Implement this method in the PointCloudAndImageProcessor in order to execute parts when the component...
void process() override
Process the vision component.
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
void enableResultImagesAndPointClouds(std::string resultProviderName, int numberImages, ImageDimension imageDimension, ImageType imageType)
void onInitImageProcessor() override
Setup the vision component.
void onConnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
virtual void onExitPointCloudAndImageProcessor()=0
Exit the ImapeProcessor component.
void onDisconnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component looses net...
virtual void onInitPointCloudAndImageProcessor()=0
Setup the vision component.
void onInitPointCloudProcessor() override
Setup the vision component.
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
virtual void onInitComponent() override
std::map< std::string, IceInternal::Handle< ResultPointCloudProvider > > resultPointCloudProviders
virtual void onDisconnectComponent() override
virtual void onConnectComponent() override
virtual void onExitComponent() override
std::map< std::string, PointCloudProviderInfo > pointCloudProviderInfoMap
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const
Retrieve default name of component.
virtual std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
visionx::PointContentType getPointContentType()
size_t getBytesPerPoint(visionx::PointContentType pointContent)
ArmarX headers.