UserAssistedSegmenter.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package SceneUnderstanding::ArmarXObjects::UserAssistedSegmenter
17 * @author Rainer Kartmann ( rainer dot kartmann at student dot kit dot edu )
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
27namespace visionx
28{
29
31 std::string prefix) :
33 {
34 // POINT CLOUDS
35
36 defineOptionalProperty<std::string>("ResultPointCloudName",
37 "UserAssistedSegmenterResult",
38 "Name of the output segmented point cloud.");
39
40
41 // TOPICS
42
43 defineOptionalProperty<std::string>("UserAssistedSegmenterTopicName",
44 "UserAssistedSegmenterUpdates",
45 "Topic where received point clouds are reported.");
46
47
48 // PARAMETERS
49
50 defineOptionalProperty<float>("PublishFrequency",
51 1.0f,
52 "Rate [1/s] the result point cloud will be published at."
53 "If zero, the point cloud will be published exactly once.");
54 }
55
56 std::string
58 {
59 return "UserAssistedSegmenter";
60 }
61
62 void
64 {
65 resultPointCloudName = getProperty<std::string>("ResultPointCloudName");
66
67 offeringTopic(getProperty<std::string>("UserAssistedSegmenterTopicName"));
68
69
70 publishFrequency = getProperty<float>("PublishFrequency");
71 }
72
73 void
75 {
76 enableResultPointClouds<PointL>(resultPointCloudName);
77
79 getProperty<std::string>("UserAssistedSegmenterTopicName"));
80
81 if (publishFrequency > 0)
82 {
84 this,
86 static_cast<int>(std::round(1000.f / publishFrequency)));
87 }
88 }
89
90 void
92 {
93 if (provideTask)
94 {
95 provideTask->stop();
96 }
97 }
98
99 void
103
104 void
106 {
107 if (!waitForPointClouds(50000))
108 {
109 ARMARX_WARNING << "Timeout or error in wait for pointclouds";
110 return;
111 }
112
113 PointCloudL::Ptr pointCloudPtr(new PointCloudL());
114 if (!getPointClouds(pointCloudPtr))
115 {
116 ARMARX_WARNING << "Unable to get point cloud data.";
117 return;
118 }
119
120 ARMARX_VERBOSE << "Received point cloud with " << pointCloudPtr->size() << " points.";
121
122 const visionx::ColoredLabeledPointCloud visionxPointCloud =
124 updatesListener->reportSegmentation(visionxPointCloud);
125 }
126
127 void
128 UserAssistedSegmenter::publishSegmentation(const visionx::ColoredLabeledPointCloud& pointCloud,
129 const Ice::Current&)
130 {
131 ARMARX_INFO << "Publishing user segmentation";
132
133 resultPointCloud.reset(new PointCloudL());
134 visionx::tools::convertToPCL(pointCloud, *resultPointCloud);
135
136 if (!provideTask)
137 {
138 provideResultPointCloud(); // one shot
139 }
140 else if (!provideTask->isRunning())
141 {
142 provideTask->start();
143 }
144 }
145
146 void
148 {
149 if (resultPointCloud)
150 {
151 provideResultPointClouds(resultPointCloud, resultPointCloudName);
152 }
153 }
154
161
162} // namespace visionx
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
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.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
UserAssistedSegmenterPropertyDefinitions.
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void onExitPointCloudProcessor() override
virtual void onConnectPointCloudProcessor() override
virtual void onDisconnectPointCloudProcessor() override
virtual void onInitPointCloudProcessor() override
virtual std::string getDefaultName() const override
virtual void publishSegmentation(const visionx::ColoredLabeledPointCloud &pointCloud, const Ice::Current &=Ice::emptyCurrent) override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#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
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void convertToPCL(void **source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud< pcl::PointXYZRGBA >::Ptr targetPtr)
void convertFromPCL(pcl::PointCloud< pcl::PointXYZRGBA >::Ptr sourcePtr, void **target)
ArmarX headers.