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 
23 #include "UserAssistedSegmenter.h"
24 
26 
27 
28 namespace visionx
29 {
30 
33  {
34  // POINT CLOUDS
35 
36  defineOptionalProperty<std::string>(
37  "ResultPointCloudName", "UserAssistedSegmenterResult",
38  "Name of the output segmented point cloud.");
39 
40 
41  // TOPICS
42 
43  defineOptionalProperty<std::string>(
44  "UserAssistedSegmenterTopicName", "UserAssistedSegmenterUpdates",
45  "Topic where received point clouds are reported.");
46 
47 
48  // PARAMETERS
49 
50  defineOptionalProperty<float>(
51  "PublishFrequency", 1.0f, "Rate [1/s] the result point cloud will be published at."
52  "If zero, the point cloud will be published exactly once.");
53  }
54 
55 
57  {
58  return "UserAssistedSegmenter";
59  }
60 
61 
63  {
64  resultPointCloudName = getProperty<std::string>("ResultPointCloudName");
65 
66  offeringTopic(getProperty<std::string>("UserAssistedSegmenterTopicName"));
67 
68 
69  publishFrequency = getProperty<float>("PublishFrequency");
70  }
71 
73  {
74  enableResultPointClouds<PointL>(resultPointCloudName);
75 
76  updatesListener = getTopic<visionx::UserAssistedSegmenterListenerPrx>(
77  getProperty<std::string>("UserAssistedSegmenterTopicName"));
78 
79  if (publishFrequency > 0)
80  {
83  static_cast<int>(std::round(1000.f / publishFrequency)));
84  }
85  }
86 
88  {
89  if (provideTask)
90  {
91  provideTask->stop();
92  }
93  }
94 
96  {
97  }
98 
100  {
101  if (!waitForPointClouds(50000))
102  {
103  ARMARX_WARNING << "Timeout or error in wait for pointclouds";
104  return;
105  }
106 
107  PointCloudL::Ptr pointCloudPtr(new PointCloudL());
108  if (!getPointClouds(pointCloudPtr))
109  {
110  ARMARX_WARNING << "Unable to get point cloud data.";
111  return;
112  }
113 
114  ARMARX_VERBOSE << "Received point cloud with " << pointCloudPtr->size() << " points.";
115 
116  const visionx::ColoredLabeledPointCloud visionxPointCloud =
117  visionx::tools::convertFromPCL<visionx::ColoredLabeledPoint3D>(*pointCloudPtr);
118  updatesListener->reportSegmentation(visionxPointCloud);
119  }
120 
121 
123  const visionx::ColoredLabeledPointCloud& pointCloud, const Ice::Current&)
124  {
125  ARMARX_INFO << "Publishing user segmentation";
126 
127  resultPointCloud.reset(new PointCloudL());
128  visionx::tools::convertToPCL(pointCloud, *resultPointCloud);
129 
130  if (!provideTask)
131  {
132  provideResultPointCloud(); // one shot
133  }
134  else if (!provideTask->isRunning())
135  {
136  provideTask->start();
137  }
138  }
139 
141  {
142  if (resultPointCloud)
143  {
144  provideResultPointClouds(resultPointCloud, resultPointCloudName);
145  }
146  }
147 
149  {
152  }
153 
154 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
UserAssistedSegmenter.h
visionx::UserAssistedSegmenter::publishSegmentation
virtual void publishSegmentation(const visionx::ColoredLabeledPointCloud &pointCloud, const Ice::Current &=Ice::emptyCurrent) override
Definition: UserAssistedSegmenter.cpp:122
visionx::UserAssistedSegmenter::onConnectPointCloudProcessor
virtual void onConnectPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:72
visionx::UserAssistedSegmenter::onDisconnectPointCloudProcessor
virtual void onDisconnectPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:87
visionx::PointCloudProcessor::provideResultPointClouds
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
Definition: PointCloudProcessor.h:286
visionx::UserAssistedSegmenter::process
virtual void process() override
Definition: UserAssistedSegmenter.cpp:99
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:433
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:173
visionx::PointCloudProcessor::getPointClouds
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
Definition: PointCloudProcessor.h:373
visionx::UserAssistedSegmenterPropertyDefinitions
UserAssistedSegmenterPropertyDefinitions.
Definition: UserAssistedSegmenter.h:35
visionx::tools::convertToPCL
void convertToPCL(void **source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud< pcl::PointXYZRGBA >::Ptr targetPtr)
Definition: PointCloudConversions.cpp:146
visionx::UserAssistedSegmenter::onExitPointCloudProcessor
virtual void onExitPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:95
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
PointCloudConversions.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:290
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::UserAssistedSegmenterPropertyDefinitions::UserAssistedSegmenterPropertyDefinitions
UserAssistedSegmenterPropertyDefinitions(std::string prefix)
Definition: UserAssistedSegmenter.cpp:31
visionx::UserAssistedSegmenter::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: UserAssistedSegmenter.cpp:148
visionx::UserAssistedSegmenter::provideResultPointCloud
void provideResultPointCloud()
Definition: UserAssistedSegmenter.cpp:140
visionx::UserAssistedSegmenter::getDefaultName
virtual std::string getDefaultName() const override
Definition: UserAssistedSegmenter.cpp:56
armarx::PeriodicTask
Definition: ArmarXManager.h:70
visionx::UserAssistedSegmenter::onInitPointCloudProcessor
virtual void onInitPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:62
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34