PointCloudToArMem.h
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 VisionX::ArmarXObjects::PointCloudRecorder
17 * @author Markus Grotz ( markus dot grotz at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25// pcl
26#include <pcl/io/pcd_io.h>
27#include <pcl/point_types.h>
28
29
30// base classes
32
34
36#include <VisionX/components/pointcloud_processor/PointCloudToArMem/PointCloudToArMemInterface.h>
37
38// aron
39#include <VisionX/libraries/armem/vision/pointcloud/core/aron/PointCloudXYZ.aron.generated.h>
40#include <VisionX/libraries/armem/vision/pointcloud/core/aron/PointCloudXYZL.aron.generated.h>
41#include <VisionX/libraries/armem/vision/pointcloud/core/aron/PointCloudXYZRGBA.aron.generated.h>
42#include <VisionX/libraries/armem/vision/pointcloud/core/aron/PointCloudXYZRGBL.aron.generated.h>
43
44// memory
46
47// VisionX PC stuff
49
50// pc
53
54namespace visionx
55{
56
61 {
62
63 public:
64 std::string
65 getDefaultName() const override
66 {
67 return "PointCloudToArMem";
68 }
69
70
71 protected:
72 void onInitPointCloudProcessor() override;
73 void onConnectPointCloudProcessor() override;
74 void onDisconnectPointCloudProcessor() override;
75 void onExitPointCloudProcessor() override;
76
77 void process() override;
78
80
81
82 private:
83 template <class PointT, class AronT>
84 void
85 getDataAndSendToMemory()
86 {
88 armarx::Duration timeGetPointClouds;
89
90 typename pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
91 if (waitForPointClouds(static_cast<int>(timeout.toMilliSeconds())))
92 {
93 TIMING_START(GetPointClouds);
94 getPointClouds(inputCloud);
95 TIMING_END_STREAM(GetPointClouds, ARMARX_VERBOSE);
96 timeGetPointClouds =
97 armarx::Duration::MicroSeconds(GetPointClouds.toMicroSeconds());
98
99 ARMARX_CHECK(inputCloud);
100 currentCloud++;
101
102 if (p.numClouds <= 0 || currentCloud <= p.numClouds)
103 {
104 if (p.removeNaNs) // remove all invalid points
105 {
106 visionx::filterNaNs(*inputCloud);
107 }
108
109 // Also provide PC in legacy mode
110 provideResultPointClouds(inputCloud);
111
112 // Send PC to armem
113 {
114 AronT arondto;
115 arondto.pointcloud = *inputCloud;
116
118 armarx::armem::EntityUpdate& eu = c.add();
119 eu.confidence = 1.0;
120
122 p.targetMemoryName,
126
127 eu.instancesData = {arondto.toAron()};
128
129 eu.referencedTime =
130 armarx::core::time::DateTime::Now(); // Get creation time of PC
132 auto result = memoryWriter.commit(c);
133
134 if (not result.allSuccess())
135 {
137 << "An error occured when sending pointclouds to the memory. "
138 "Try to continue with next PC. The message was: "
139 << result.allErrorMessages();
140 }
141 }
142
143 ARMARX_DEBUG << "Wait for next point cloud...";
144 }
145 }
146 else
147 {
148 ARMARX_INFO << "Timeout or error while waiting for point cloud data";
149 return;
150 }
151 }
152
153 private:
154 int currentCloud;
155
156 armarx::armem::client::Writer memoryWriter;
157
158 struct Properties
159 {
160 int numClouds = 0;
161 bool removeNaNs = true;
162
164
165 std::string targetMemoryName = "Vision";
166
167 } p;
168
169 std::atomic_bool processing = false;
170 };
171} // namespace visionx
constexpr T c
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
static DateTime Now()
Definition DateTime.cpp:51
Represents a duration.
Definition Duration.h:17
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Definition Duration.cpp:60
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
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
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
void onConnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
void onDisconnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component looses net...
void onInitPointCloudProcessor() override
Setup the vision component.
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
#define TIMING_START(name)
Helper macro to do timing tests.
Definition TimeUtil.h:289
#define TIMING_END_STREAM(name, os)
Prints duration.
Definition TimeUtil.h:310
plugins::PluginUser PluginUser
Definition PluginUser.h:47
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const constexpr char * POINT_XYZRGBA_SLUG
Definition constants.h:88
std::string GetCoreSegmentNameFor()
Definition constants.h:23
const constexpr char * ENTITY_NAME
Definition constants.h:19
ArmarX headers.
void filterNaNs(pcl::PointCloud< PointT > &pc)
Definition tools.h:120
A bundle of updates to be sent to the memory.
Definition Commit.h:90
An update of an entity for a specific point in time.
Definition Commit.h:26
float confidence
An optional confidence, may be used for things like decay.
Definition Commit.h:43
MemoryID entityID
The entity's ID.
Definition Commit.h:28
Time referencedTime
Time when this entity update was created (e.g.
Definition Commit.h:37
std::vector< aron::data::DictPtr > instancesData
The entity data.
Definition Commit.h:31
Time sentTime
Time when this update was sent to the memory server.
Definition Commit.h:53