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
26
27#include <Eigen/Core>
28
29#include <pcl/filters/filter.h>
30
32
34
35using namespace armarx;
36
44
45void
47{
49 offeringTopic(getProperty<std::string>("DebugObserverName").getValue());
50 offeringTopic(getProperty<std::string>("DebugDrawerTopicName").getValue());
51
52 cycleKeeper.reset(new CycleUtil(1000.0f / getProperty<float>("UpdateRate").getValue()));
53
54 numClouds = getProperty<int>("NumPointClouds").getValue();
55 currentCloud = 0;
56
57 writeBinary = getProperty<bool>("WriteBinary").getValue();
58 removeNaNs = getProperty<bool>("RemoveNaNs").getValue();
59}
60
61void
63{
66 getProperty<std::string>("DebugObserverName").getValue());
68 getProperty<std::string>("DebugDrawerTopicName").getValue());
69
70
72}
73
74void
78
79void
83
84void
86{
88 pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
90 if (!waitForPointClouds())
91 {
93 ARMARX_INFO << "Timeout or error while waiting for point cloud data";
94 return;
95 }
96 else
97 {
99 getPointClouds(inputCloud);
100 }
101 // StringVariantBaseMap debugValues;
102 // debugValues["debug_value"] = new Variant(inputCloud->header.timestamp);
103 // debugObserver->setDebugChannel(getName(), debugValues);
104
105 currentCloud++;
106
108 std::string fileName = getProperty<std::string>("Folder").getValue() + "/cloud_" +
109 std::to_string(inputCloud->header.stamp) + ".pcd";
110
111 const auto isNan = [](const PointT& p) -> bool { return std::isnan(p.z); };
112
113 if (removeNaNs) // remove all invalid points
114 {
115 inputCloud->points.erase(
116 std::remove_if(inputCloud->points.begin(), inputCloud->points.end(), isNan),
117 inputCloud->points.end());
118
119 inputCloud->width = inputCloud->points.size();
120 inputCloud->height = 1;
121 inputCloud->is_dense = true;
122 }
123
124 if (writeBinary)
125 {
126 pcl::io::savePCDFileBinary(fileName, *inputCloud);
127 }
128 else
129 {
130 pcl::io::savePCDFileASCII(fileName, *inputCloud);
131 }
132
133 ARMARX_LOG << "writing to file: " << fileName;
134
135 provideResultPointClouds(inputCloud);
136
137
138 if (numClouds && currentCloud >= numClouds)
139 {
141 this->getArmarXManager()->asyncShutdown();
142 PointCloudProcessor::onDisconnectComponent();
143 }
144
145
146 cycleKeeper->waitForCycleDuration();
147}
148
149std::string
151{
152 return "PointCloudRecorder";
153}
154
155std::string
160
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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.
Brief description of class PointCloudRecorder.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onExitPointCloudProcessor() override
void onConnectPointCloudProcessor() override
void onDisconnectPointCloudProcessor() override
static std::string GetDefaultName()
void onInitPointCloudProcessor() override
std::string getDefaultName() const override
Retrieve default name of component.
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