33PointCloudUtility::fusePointclouds(std::string file1, std::string file2, std::string out)
35 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc1 = loadPointCloud(file1);
36 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc2 = loadPointCloud(file2);
37 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc1Aligned =
38 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr(
new pcl::PointCloud<pcl::PointXYZRGBA>);
39 pcl::ApproximateVoxelGrid<pcl::PointXYZRGBA> filter;
41 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr temp1 =
42 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr(
new pcl::PointCloud<pcl::PointXYZRGBA>);
43 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr temp2 =
44 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr(
new pcl::PointCloud<pcl::PointXYZRGBA>);
53 pcl::IterativeClosestPoint<pcl::PointXYZRGBA, pcl::PointXYZRGBA> aligner;
54 aligner.setEuclideanFitnessEpsilon(1e-20);
55 aligner.setTransformationEpsilon(1e-20);
56 aligner.setMaximumIterations(10000000);
57 aligner.setUseReciprocalCorrespondences(
true);
58 aligner.setInputSource(pc1);
59 aligner.setInputTarget(pc2);
60 aligner.align(*pc1Aligned);
61 pcl::PointCloud<pcl::PointXYZRGBA> pcout = *pc2 + *pc1Aligned;
63 pcl::io::savePCDFileASCII(out, pcout);
67PointCloudUtility::moveOrigin(std::string file, std::string out, Eigen::Vector3f translation)
69 Eigen::Matrix4f
transform = Eigen::Matrix4f::Identity();
70 transform.block<3, 1>(0, 3) = translation;
71 this->transformPointcloud(file, out,
transform);
75PointCloudUtility::rotatePointCloud(std::string file, std::string out, Eigen::Matrix3f rotation)
77 Eigen::Matrix4f
transform = Eigen::Matrix4f::Identity();
79 this->transformPointcloud(file, out,
transform);
83PointCloudUtility::transformPointcloud(std::string file, std::string out, Eigen::Matrix4f pose)
85 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc = loadPointCloud(file);
86 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr transformed_cloud(
87 new pcl::PointCloud<pcl::PointXYZRGBA>());
88 pcl::transformPointCloud<pcl::PointXYZRGBA>(*pc, *transformed_cloud, pose);
90 pcl::io::savePCDFileASCII(out, *transformed_cloud);
94PointCloudUtility::showResult(std::string file)
96 pcl::visualization::PCLVisualizer viewer;
97 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc = loadPointCloud(file);
98 viewer.addPointCloud(pc);
99 viewer.addCoordinateSystem(1.0);
101 while (!viewer.wasStopped())
107PointCloudUtility::process()
115 std::string temp =
"temp.pcd";
120 fusePointclouds(file1, file2, temp);
125 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc = loadPointCloud(file1);
126 pcl::io::savePCDFileASCII(temp, *pc);
130 Eigen::Vector3f tVector;
137 VirtualRobot::MathTools::posrpy2eigen4f(tVector, rot,
transpose);
138 transformPointcloud(temp, out,
transpose);
143 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr pc = loadPointCloud(temp);
144 pcl::io::savePCDFileASCII(out, *pc);
167pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
168PointCloudUtility::loadPointCloud(std::string filename)
171 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr model(
new pcl::PointCloud<pcl::PointXYZRGBA>());
174 ARMARX_ERROR <<
"Could not find point cloud file in ArmarXDataPath: " << filename;
177 else if (pcl::io::loadPCDFile<pcl::PointXYZRGBA>(filename.c_str(), *model) == -1)
179 ARMARX_WARNING <<
"unable to load point cloud from file " << filename;
213 return "PointCloudUtility";
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Brief description of class PointCloudUtility.
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
static std::string GetDefaultName()
void onExitComponent() override
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
SceneBounds merge(const std::vector< SceneBounds > &sceneBounds)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::vector< T > > transpose(const std::vector< std::vector< T > > &src, Thrower thrower)
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.