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 
26 #include <pcl/filters/filter.h>
27 #include <Eigen/Core>
28 
31 
32 using namespace armarx;
33 
34 
35 
37 {
41 }
42 
43 
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 
60 {
62  debugObserver = getTopic<DebugObserverInterfacePrx>(getProperty<std::string>("DebugObserverName").getValue());
63  debugDrawer = getTopic<DebugDrawerInterfacePrx>(getProperty<std::string>("DebugDrawerTopicName").getValue());
64 
65 
66  enableResultPointClouds<PointT>();
67 }
68 
69 
71 {
72 }
73 
75 {
76 }
77 
79 {
81  pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
83  if (!waitForPointClouds())
84  {
86  ARMARX_INFO << "Timeout or error while waiting for point cloud data";
87  return;
88  }
89  else
90  {
92  getPointClouds(inputCloud);
93  }
94  // StringVariantBaseMap debugValues;
95  // debugValues["debug_value"] = new Variant(inputCloud->header.timestamp);
96  // debugObserver->setDebugChannel(getName(), debugValues);
97 
98  currentCloud++;
99 
100  ARMARX_TRACE;
101  std::string fileName = getProperty<std::string>("Folder").getValue() + "/cloud_" + std::to_string(inputCloud->header.stamp) + ".pcd";
102 
103  const auto isNan = [](const PointT& p)->bool{
104  return std::isnan(p.z);
105  };
106 
107  if(removeNaNs) // remove all invalid points
108  {
109  inputCloud->points.erase(std::remove_if(inputCloud->points.begin(), inputCloud->points.end(), isNan), inputCloud->points.end());
110 
111  inputCloud->width = inputCloud->points.size();
112  inputCloud->height = 1;
113  inputCloud->is_dense = true;
114  }
115 
116  if(writeBinary)
117  {
118  pcl::io::savePCDFileBinary(fileName, *inputCloud);
119  }
120  else
121  {
122  pcl::io::savePCDFileASCII(fileName, *inputCloud);
123  }
124 
125  ARMARX_LOG << "writing to file: " << fileName;
126 
127  provideResultPointClouds(inputCloud);
128 
129 
130  if (numClouds && currentCloud >= numClouds)
131  {
132  ARMARX_TRACE;
133  this->getArmarXManager()->asyncShutdown();
134  PointCloudProcessor::onDisconnectComponent();
135  }
136 
137 
138  cycleKeeper->waitForCycleDuration();
139 }
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:53
armarx::PointCloudRecorder::process
void process() override
Definition: PointCloudRecorder.cpp:78
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
armarx::PointT
pcl::PointXYZRGBL PointT
Definition: Common.h:28
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:40
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::PointCloudRecorder::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:59
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::PointCloudRecorder::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:44
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::PointCloudRecorder::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:70
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PointCloudRecorder::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: PointCloudRecorder.cpp:74