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 static std::string GetDefaultName();
65 std::string getDefaultName() const override;
66
67
68 protected:
69 void onInitPointCloudProcessor() override;
70 void onConnectPointCloudProcessor() override;
71 void onDisconnectPointCloudProcessor() override;
72 void onExitPointCloudProcessor() override;
73
74 void process() override;
75
77
78
79 private:
80 template <class PointT, class AronT>
81 void
82 getDataAndSendToMemory()
83 {
85 armarx::Duration timeGetPointClouds;
86
87 typename pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
88 if (waitForPointClouds(static_cast<int>(timeout.toMilliSeconds())))
89 {
90 TIMING_START(GetPointClouds);
91 getPointClouds(inputCloud);
92 TIMING_END_STREAM(GetPointClouds, ARMARX_VERBOSE);
93 timeGetPointClouds =
94 armarx::Duration::MicroSeconds(GetPointClouds.toMicroSeconds());
95
96 ARMARX_CHECK(inputCloud);
97 currentCloud++;
98
99 if (p.numClouds <= 0 || currentCloud <= p.numClouds)
100 {
101 if (p.removeNaNs) // remove all invalid points
102 {
103 visionx::filterNaNs(*inputCloud);
104 }
105
106 // Also provide PC in legacy mode
107 provideResultPointClouds(inputCloud);
108
109 // Send PC to armem
110 {
111 AronT arondto;
112 arondto.pointcloud = *inputCloud;
113
115 armarx::armem::EntityUpdate& eu = c.add();
116 eu.confidence = 1.0;
117
119 p.targetMemoryName,
123
124 eu.instancesData = {arondto.toAron()};
125
126 eu.referencedTime =
127 armarx::core::time::DateTime::Now(); // Get creation time of PC
129 auto result = memoryWriter.commit(c);
130
131 if (not result.allSuccess())
132 {
134 << "An error occured when sending pointclouds to the memory. "
135 "Try to continue with next PC. The message was: "
136 << result.allErrorMessages();
137 }
138 }
139
140 ARMARX_DEBUG << "Wait for next point cloud...";
141 }
142 }
143 else
144 {
145 ARMARX_INFO << "Timeout or error while waiting for point cloud data";
146 return;
147 }
148 }
149
150 private:
151 int currentCloud;
152
154
155 struct Properties
156 {
157 int numClouds = 0;
158 bool removeNaNs = true;
159
161
162 std::string targetMemoryName = "Vision";
163
164 } p;
165
166 std::atomic_bool processing = false;
167 };
168} // 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
Helps a memory client sending data to a memory.
Definition Writer.h:23
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...
static std::string GetDefaultName()
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