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 namespace 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 
78  updatesListener = getTopic<visionx::UserAssistedSegmenterListenerPrx>(
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
101  {
102  }
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 =
123  visionx::tools::convertFromPCL<visionx::ColoredLabeledPoint3D>(*pointCloudPtr);
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 
157  {
160  }
161 
162 } // namespace visionx
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
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:128
visionx::UserAssistedSegmenter::onConnectPointCloudProcessor
virtual void onConnectPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:74
visionx::UserAssistedSegmenter::onDisconnectPointCloudProcessor
virtual void onDisconnectPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:91
visionx::PointCloudProcessor::provideResultPointClouds
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
Definition: PointCloudProcessor.h:288
visionx::UserAssistedSegmenter::process
virtual void process() override
Definition: UserAssistedSegmenter.cpp:105
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:458
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:166
visionx::PointCloudProcessor::getPointClouds
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
Definition: PointCloudProcessor.h:380
visionx::UserAssistedSegmenterPropertyDefinitions
UserAssistedSegmenterPropertyDefinitions.
Definition: UserAssistedSegmenter.h:34
visionx::tools::convertToPCL
void convertToPCL(void **source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud< pcl::PointXYZRGBA >::Ptr targetPtr)
Definition: PointCloudConversions.cpp:169
visionx::UserAssistedSegmenter::onExitPointCloudProcessor
virtual void onExitPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:100
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
PointCloudConversions.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle< class PropertyDefinitionContainer >
visionx::UserAssistedSegmenterPropertyDefinitions::UserAssistedSegmenterPropertyDefinitions
UserAssistedSegmenterPropertyDefinitions(std::string prefix)
Definition: UserAssistedSegmenter.cpp:30
visionx::UserAssistedSegmenter::createPropertyDefinitions
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: UserAssistedSegmenter.cpp:156
visionx::UserAssistedSegmenter::provideResultPointCloud
void provideResultPointCloud()
Definition: UserAssistedSegmenter.cpp:147
visionx::UserAssistedSegmenter::getDefaultName
virtual std::string getDefaultName() const override
Definition: UserAssistedSegmenter.cpp:57
armarx::PeriodicTask
Definition: ArmarXManager.h:70
visionx::UserAssistedSegmenter::onInitPointCloudProcessor
virtual void onInitPointCloudProcessor() override
Definition: UserAssistedSegmenter.cpp:63
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35