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 
33 using namespace armarx;
34 
37 {
41 }
42 
43 void
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 
59 void
61 {
63  debugObserver = getTopic<DebugObserverInterfacePrx>(
64  getProperty<std::string>("DebugObserverName").getValue());
65  debugDrawer = getTopic<DebugDrawerInterfacePrx>(
66  getProperty<std::string>("DebugDrawerTopicName").getValue());
67 
68 
69  enableResultPointClouds<PointT>();
70 }
71 
72 void
74 {
75 }
76 
77 void
79 {
80 }
81 
82 void
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 
105  ARMARX_TRACE;
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  {
138  ARMARX_TRACE;
139  this->getArmarXManager()->asyncShutdown();
140  PointCloudProcessor::onDisconnectComponent();
141  }
142 
143 
144  cycleKeeper->waitForCycleDuration();
145 }
Pose.h
trace.h
armarx::CycleUtil
This util class helps with keeping a cycle time during a control cycle.
Definition: CycleUtil.h:40
armarx::PointCloudRecorderPropertyDefinitions
Definition: PointCloudRecorder.h:46
armarx::PointCloudRecorder::process
void process() override
Definition: PointCloudRecorder.cpp:83
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:30
armarx::PointCloudRecorder::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: PointCloudRecorder.cpp:36
PointCloudRecorder.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:165
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::PointCloudRecorder::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:60
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::PointCloudRecorder::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:44
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::PointCloudRecorder::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:73
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::PointCloudRecorder::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:78