PointCloudRecorder.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 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#include "PointCloudRecorder.h"
24
25#include <Eigen/Core>
26
27#include <pcl/filters/filter.h>
28
30
32
33using namespace armarx;
34
42
43void
45{
47 offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
48 offeringTopic(getProperty<std::string>("DebugDrawerTopicName").getValue());
49
50 cycleKeeper.reset(new CycleUtil(1000.0f / getProperty<float>("UpdateRate").getValue()));
51
52 numClouds = getProperty<int>("NumPointClouds").getValue();
53 currentCloud = 0;
54
55 writeBinary = getProperty<bool>("WriteBinary").getValue();
56 removeNaNs = getProperty<bool>("RemoveNaNs").getValue();
57}
58
59void
61{
64 getProperty<std::string>("DebugObserverName").getValue());
66 getProperty<std::string>("DebugDrawerTopicName").getValue());
67
68
70}
71
72void
76
77void
81
82void
84{
86 pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
88 if (!waitForPointClouds())
89 {
91 ARMARX_INFO << "Timeout or error while waiting for point cloud data";
92 return;
93 }
94 else
95 {
97 getPointClouds(inputCloud);
98 }
99 // StringVariantBaseMap debugValues;
100 // debugValues["debug_value"] = new Variant(inputCloud->header.timestamp);
101 // debugObserver->setDebugChannel(getName(), debugValues);
102
103 currentCloud++;
104
106 std::string fileName = getProperty<std::string>("Folder").getValue() + "/cloud_" +
107 std::to_string(inputCloud->header.stamp) + ".pcd";
108
109 const auto isNan = [](const PointT& p) -> bool { return std::isnan(p.z); };
110
111 if (removeNaNs) // remove all invalid points
112 {
113 inputCloud->points.erase(
114 std::remove_if(inputCloud->points.begin(), inputCloud->points.end(), isNan),
115 inputCloud->points.end());
116
117 inputCloud->width = inputCloud->points.size();
118 inputCloud->height = 1;
119 inputCloud->is_dense = true;
120 }
121
122 if (writeBinary)
123 {
124 pcl::io::savePCDFileBinary(fileName, *inputCloud);
125 }
126 else
127 {
128 pcl::io::savePCDFileASCII(fileName, *inputCloud);
129 }
130
131 ARMARX_LOG << "writing to file: " << fileName;
132
133 provideResultPointClouds(inputCloud);
134
135
136 if (numClouds && currentCloud >= numClouds)
137 {
139 this->getArmarXManager()->asyncShutdown();
140 PointCloudProcessor::onDisconnectComponent();
141 }
142
143
144 cycleKeeper->waitForCycleDuration();
145}
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
This util class helps with keeping a cycle time during a control cycle.
Definition CycleUtil.h:41
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onExitPointCloudProcessor() override
void onConnectPointCloudProcessor() override
void onDisconnectPointCloudProcessor() override
void onInitPointCloudProcessor() override
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
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
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_LOG
Definition Logging.h:165
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
pcl::PointXYZRGBL PointT
Definition Common.h:30
#define ARMARX_TRACE
Definition trace.h:77