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
32using namespace armarx;
33
34namespace 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
51 {
52 // armarx::SharedMemoryScopedWriteLockPtr lock(sharedMemoryProvider->getScopedWriteLock());
53
54 return sharedMemoryProvider->getMetaInfo();
55 }
56
57 // ================================================================== //
58 // == Component implementation ====================================== //
59 // ================================================================== //
60 void
62 {
64 // init members
65 exiting = false;
66
67 // call setup of derived poitcloud provider implementation to setup Point Clouds type and size
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
81 {
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
97 fps.reset();
98 }
99
100 void
102 {
104 if (sharedMemoryProvider)
105 {
106 sharedMemoryProvider->stop();
107 sharedMemoryProvider = nullptr;
108 }
109 }
110
111 void
113 {
115 if (sharedMemoryProvider)
116 {
117 sharedMemoryProvider->stop();
118 sharedMemoryProvider = nullptr;
119 }
120 exiting = true;
122 }
123
124 void
125 PointCloudProvider::updateComponentMetaInfo(const MetaPointCloudFormatPtr& info)
126 {
127 fps.update();
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
140 {
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
constexpr T c
The IceSharedMemoryProvider provides data via Ice or shared memory.
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
std::string getName() const
Retrieve name of object.
void setMetaInfo(const std::string &id, const VariantBasePtr &value)
Allows to set meta information that can be queried live via Ice interface on the ArmarXManager.
The Variant class is described here: Variants.
Definition Variant.h:224
virtual void onInitPointCloudProvider()=0
This is called when the Component::onInitComponent() is called.
void onDisconnectComponent() override
Hook for subclass.
void updateComponentMetaInfo(const MetaPointCloudFormatPtr &info)
MetaPointCloudFormatPtr getPointCloudFormat(const Ice::Current &c=Ice::emptyCurrent) override
Returns the point cloud format info struct via Ice.
virtual void onConnectPointCloudProvider()
This is called when the Component::onConnectComponent() setup is called.
virtual MetaPointCloudFormatPtr getDefaultPointCloudFormat()
default point cloud format used to initialize shared memory
virtual void onExitPointCloudProvider()=0
This is called when the Component::onExitComponent() setup is called.
PointCloudProcessorInterfacePrx pointCloudProcessorProxy
Ice proxy of the point cloud processor interface.
armarx::Blob getPointCloud(MetaPointCloudFormatPtr &info, const Ice::Current &c=Ice::emptyCurrent) override
Retrieve point clouds via Ice.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
ArmarX headers.
#define ARMARX_TRACE
Definition trace.h:77