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 
54 namespace 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,
123  visionx::armem::pointcloud::GetCoreSegmentNameFor<PointT>(),
124  getDefaultName(),
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 
163  std::string pointtype = visionx::armem::pointcloud::POINT_XYZRGBA_SLUG;
164 
165  std::string targetMemoryName = "Vision";
166 
167  } p;
168 
169  std::atomic_bool processing = false;
170  };
171 } // namespace visionx
visionx::PointCloudToArMemInterface
Definition: PointCloudToArMemInterface.ice:31
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
TIMING_START
#define TIMING_START(name)
Definition: TimeUtil.h:280
visionx::PointCloudToArMem::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: PointCloudToArMem.h:65
Writer.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::armem::EntityUpdate::instancesData
std::vector< aron::data::DictPtr > instancesData
The entity data.
Definition: Commit.h:33
armarx::armem::Commit
A bundle of updates to be sent to the memory.
Definition: Commit.h:89
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::armem::EntityUpdate::confidence
float confidence
An optional confidence, may be used for things like decay.
Definition: Commit.h:45
visionx::PointCloudToArMem
Definition: PointCloudToArMem.h:57
visionx::PointCloudToArMem::process
void process() override
Process the vision component.
Definition: PointCloudToArMem.cpp:91
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::PointCloudToArMem::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component is fully i...
Definition: PointCloudToArMem.cpp:58
constants.h
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
TIMING_END_STREAM
#define TIMING_END_STREAM(name, os)
Definition: TimeUtil.h:300
armarx::armem::client::plugins::PluginUser
Adds the Memory Name System client component plugin.
Definition: PluginUser.h:29
constants.h
visionx::armem::pointcloud::ENTITY_NAME
const constexpr char * ENTITY_NAME
Definition: constants.h:19
visionx::PointCloudProcessor::provideResultPointClouds
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
Definition: PointCloudProcessor.h:286
visionx::PointCloudProcessor
The PointCloudProcessor class provides an interface for access to PointCloudProviders via Ice and sha...
Definition: PointCloudProcessor.h:186
visionx::PointCloudToArMem::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Setup the vision component.
Definition: PointCloudToArMem.cpp:51
visionx::PointCloudToArMem::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PointCloudToArMem.cpp:27
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:433
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:27
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:22
armarx::armem::client::Writer::commit
CommitResult commit(const Commit &commit) const
Writes a Commit to the memory.
Definition: Writer.cpp:59
visionx::PointCloudToArMem::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Implement this method in the PointCloudProcessor in order execute parts when the component looses net...
Definition: PointCloudToArMem.cpp:81
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
PointCloudProcessor.h
visionx::PointCloudProcessor::getPointClouds
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
Definition: PointCloudProcessor.h:373
Component.h
visionx::filterNaNs
void filterNaNs(pcl::PointCloud< PointT > &pc)
Definition: tools.h:116
armarx::armem::EntityUpdate::referencedTime
Time referencedTime
Time when this entity update was created (e.g.
Definition: Commit.h:39
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
PluginUser.h
armarx::core::time::Duration::toMilliSeconds
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Definition: Duration.cpp:69
visionx::PointCloudToArMem::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Exit the ImapeProcessor component.
Definition: PointCloudToArMem.cpp:86
tools.h
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27
armarx::armem::EntityUpdate::entityID
MemoryID entityID
The entity's ID.
Definition: Commit.h:30
armarx::armem::EntityUpdate::sentTime
Time sentTime
Time when this update was sent to the memory server.
Definition: Commit.h:55
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55
visionx::armem::pointcloud::POINT_XYZRGBA_SLUG
const constexpr char * POINT_XYZRGBA_SLUG
Definition: constants.h:88
armarx::human::MemoryID
const armem::MemoryID MemoryID
Definition: memory_ids.cpp:29