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
28
29namespace visionx
30{
31
33 std::string prefix) :
35 {
36 // POINT CLOUDS
37
38 defineOptionalProperty<std::string>("ResultPointCloudName",
39 "UserAssistedSegmenterResult",
40 "Name of the output segmented point cloud.");
41
42
43 // TOPICS
44
45 defineOptionalProperty<std::string>("UserAssistedSegmenterTopicName",
46 "UserAssistedSegmenterUpdates",
47 "Topic where received point clouds are reported.");
48
49
50 // PARAMETERS
51
52 defineOptionalProperty<float>("PublishFrequency",
53 1.0f,
54 "Rate [1/s] the result point cloud will be published at."
55 "If zero, the point cloud will be published exactly once.");
56 }
57
58 std::string
60 {
61 return "UserAssistedSegmenter";
62 }
63
64 std::string
69
70 void
72 {
73 resultPointCloudName = getProperty<std::string>("ResultPointCloudName");
74
75 offeringTopic(getProperty<std::string>("UserAssistedSegmenterTopicName"));
76
77
78 publishFrequency = getProperty<float>("PublishFrequency");
79 }
80
81 void
83 {
84 enableResultPointClouds<PointL>(resultPointCloudName);
85
87 getProperty<std::string>("UserAssistedSegmenterTopicName"));
88
89 if (publishFrequency > 0)
90 {
92 this,
94 static_cast<int>(std::round(1000.f / publishFrequency)));
95 }
96 }
97
98 void
100 {
101 if (provideTask)
102 {
103 provideTask->stop();
104 }
105 }
106
107 void
111
112 void
114 {
115 if (!waitForPointClouds(50000))
116 {
117 ARMARX_WARNING << "Timeout or error in wait for pointclouds";
118 return;
119 }
120
121 PointCloudL::Ptr pointCloudPtr(new PointCloudL());
122 if (!getPointClouds(pointCloudPtr))
123 {
124 ARMARX_WARNING << "Unable to get point cloud data.";
125 return;
126 }
127
128 ARMARX_VERBOSE << "Received point cloud with " << pointCloudPtr->size() << " points.";
129
130 const visionx::ColoredLabeledPointCloud visionxPointCloud =
132 updatesListener->reportSegmentation(visionxPointCloud);
133 }
134
135 void
136 UserAssistedSegmenter::publishSegmentation(const visionx::ColoredLabeledPointCloud& pointCloud,
137 const Ice::Current&)
138 {
139 ARMARX_INFO << "Publishing user segmentation";
140
141 resultPointCloud.reset(new PointCloudL());
142 visionx::tools::convertToPCL(pointCloud, *resultPointCloud);
143
144 if (!provideTask)
145 {
146 provideResultPointCloud(); // one shot
147 }
148 else if (!provideTask->isRunning())
149 {
150 provideTask->start();
151 }
152 }
153
154 void
156 {
157 if (resultPointCloud)
158 {
159 provideResultPointClouds(resultPointCloud, resultPointCloudName);
160 }
161 }
162
169
170
172} // namespace visionx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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.
Brief description of class UserAssistedSegmenter.
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void onExitPointCloudProcessor() override
virtual void onConnectPointCloudProcessor() override
virtual void onDisconnectPointCloudProcessor() override
virtual void onInitPointCloudProcessor() override
std::string getDefaultName() const override
Retrieve default name of component.
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.