PointCloudProvider.cpp
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 #include "PointCloudProvider.h"
26 
27 #include <string>
28 
31 
32 using namespace armarx;
33 
34 namespace visionx
35 {
36  // ================================================================== //
37  // == PointCloudProvider ice interface ============================== //
38  // ================================================================== //
39  armarx::Blob
40  PointCloudProvider::getPointCloud(MetaPointCloudFormatPtr& info, const Ice::Current& c)
41  {
42  MetaInfoSizeBasePtr infoBase;
43  armarx::Blob result = sharedMemoryProvider->getData(infoBase);
44  // info is an output parameter and must be set explicitly
45  info = MetaPointCloudFormatPtr::dynamicCast(infoBase);
46  return result;
47  }
48 
49  MetaPointCloudFormatPtr
50  PointCloudProvider::getPointCloudFormat(const Ice::Current& c)
51  {
52  // armarx::SharedMemoryScopedWriteLockPtr lock(sharedMemoryProvider->getScopedWriteLock());
53 
54  return sharedMemoryProvider->getMetaInfo();
55  }
56 
57  // ================================================================== //
58  // == Component implementation ====================================== //
59  // ================================================================== //
60  void
61  PointCloudProvider::onInitComponent()
62  {
64  // init members
65  exiting = false;
66 
67  // call setup of derived poitcloud provider implementation to setup Point Clouds type and size
68  onInitPointCloudProvider();
69 
70  MetaPointCloudFormatPtr info = getDefaultPointCloudFormat();
71  intermediateBuffer.resize(info->capacity);
73  this, info, "PointCloudProvider");
74 
75  // Offer topic for point cloud events
76  offeringTopic(getName() + ".PointCloudListener");
77  }
78 
79  void
80  PointCloudProvider::onConnectComponent()
81  {
83  pointCloudProcessorProxy =
84  getTopic<PointCloudProcessorInterfacePrx>(getName() + ".PointCloudListener");
85 
86  if (!sharedMemoryProvider)
87  {
88  // Ensure that the shared memory provider is created
89  ARMARX_INFO << "Shared memory provider is null: Recreating it";
90  MetaPointCloudFormatPtr info = getDefaultPointCloudFormat();
92  this, info, "PointCloudProvider");
93  }
94  sharedMemoryProvider->start();
95 
96  onConnectPointCloudProvider();
97  fps.reset();
98  }
99 
100  void
101  PointCloudProvider::onDisconnectComponent()
102  {
103  ARMARX_TRACE;
104  if (sharedMemoryProvider)
105  {
106  sharedMemoryProvider->stop();
107  sharedMemoryProvider = nullptr;
108  }
109  }
110 
111  void
112  PointCloudProvider::onExitComponent()
113  {
114  ARMARX_TRACE;
115  if (sharedMemoryProvider)
116  {
117  sharedMemoryProvider->stop();
118  sharedMemoryProvider = nullptr;
119  }
120  exiting = true;
121  onExitPointCloudProvider();
122  }
123 
124  void
125  PointCloudProvider::updateComponentMetaInfo(const MetaPointCloudFormatPtr& info)
126  {
127  fps.update();
128  setMetaInfo(
129  "PointCloudTimestamp",
130  new armarx::Variant(IceUtil::Time::microSeconds(info->timeProvided).toDateTime()));
131  setMetaInfo("FPS", new armarx::Variant(fps.getFPS()));
132  setMetaInfo("MaxCycleTimeMS", new armarx::Variant(fps.getMaxCycleTimeMS()));
133  setMetaInfo("MeanCycleTimeMS", new armarx::Variant(fps.getMeanCycleTimeMS()));
134  setMetaInfo("MinCycleTimeMS", new armarx::Variant(fps.getMinCycleTimeMS()));
135  setMetaInfo("PointCloudSize", new armarx::Variant(info->size));
136  }
137 
138  MetaPointCloudFormatPtr
139  PointCloudProvider::getDefaultPointCloudFormat()
140  {
141  ARMARX_TRACE;
142  MetaPointCloudFormatPtr info = new MetaPointCloudFormat();
143  //info->frameId = getProperty<std::string>("frameId").getValue();
144  info->type = PointContentType::eColoredPoints;
145  info->capacity = 640 * 480 * sizeof(ColoredPoint3D); // + info->frameId.size();
146  info->size = info->capacity;
147  return info;
148  }
149 } // namespace visionx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
trace.h
PointCloudProvider.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::IceSharedMemoryProvider< unsigned char, MetaPointCloudFormat >
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
Variant.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27