14 #include <Utils/cc2sm.h>
15 #include <Utils/sm2cc.h>
17 #include "PclUtils/PCLModules.h"
20 #include <pcl/features/fpfh_omp.h>
29 #include <QMainWindow>
32 #include <boost/make_shared.hpp>
39 tr(
"Fast Global Registration"),
40 tr(
"Fast Global Registration, by Zhou et al."),
41 tr(
"Attempts to automatically register clouds (with normals) "
42 "without initial alignment"),
43 ":/toolbar/PclAlgorithms/icons/fastGlobalRegistration.png")),
45 m_referenceCloud(nullptr),
53 return tr(
"Clouds must have normals");
83 unsigned pointCount = cloud->
size();
84 if (pointCount == 0) {
89 pcl::PointCloud<pcl::PointNormal>::Ptr tmp_cloud =
90 cc2smReader(cloud).getAsPointNormal();
96 pcl::PointCloud<pcl::FPFHSignature33> objectFeatures;
98 pcl::FPFHEstimationOMP<pcl::PointNormal, pcl::PointNormal,
101 featEstimation.setRadiusSearch(radius);
102 featEstimation.setInputCloud(tmp_cloud);
103 featEstimation.setInputNormals(tmp_cloud);
104 featEstimation.compute(objectFeatures);
111 features.resize(pointCount, Eigen::VectorXf(33));
112 for (
unsigned i = 0; i < pointCount; ++i) {
113 const pcl::FPFHSignature33& feature = objectFeatures.points[i];
114 memcpy(features[i].data(), feature.histogram,
sizeof(
float) * 33);
116 }
catch (
const std::bad_alloc&) {
125 unsigned pointCount = cloud.
size();
126 if (pointCount == 0) {
132 points.resize(pointCount);
133 for (
unsigned i = 0; i < pointCount; ++i) {
135 points[i] = Eigen::Vector3f(P->
x, P->
y, P->
z);
137 }
catch (
const std::bad_alloc&) {
151 std::vector<ccPointCloud*> clouds;
160 clouds.push_back(cloud);
163 if (clouds.size() < 2) {
170 if (!dialog.exec()) {
204 "Failed to compute the reference cloud feature descriptors");
216 if (!alignedCloud->hasNormals()) {
224 CVLog::Warning(
"Failed to compute the point feature descriptors");
237 fgrProcess.
LoadFeature(referencePoints, referenceFeatures);
238 fgrProcess.
LoadFeature(alignedPoints, alignedFeatures);
243 "Failed to perform pair-wise optimization (not enough "
249 for (
int i = 0; i < 16; ++i) {
252 ccTrans.
data()[i] = trans.data()[i];
256 "Failed to determine the Global Registration matrix");
260 alignedCloud->setGLTransformation(ccTrans);
263 tr(
"[Fast Global Registration] Resulting matrix for cloud %1")
264 .arg(alignedCloud->getName()));
267 tr(
"Hint: copy it (CTRL+C) and apply it - or its inverse - on "
268 "any entity with the 'Edit > Apply transformation' tool"));
static constexpr int NoNormals
static bool ComputeFeatures(ccPointCloud *cloud, fgr::Features &features, double radius)
static bool ConverFromTo(const ccPointCloud &cloud, fgr::Points &points)
Base abstract class for each implemented PCL filter.
ecvMainAppInterface * m_app
Associated application interface.
virtual QString getErrorMessage(int errorCode)
Returns the error message corresponding to a given error code.
ccHObject::Container m_selected
Pointer to the main window.
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
static bool Print(const char *format,...)
Prints out a formatted message in console.
Fast Global Registration dialog.
double getFeatureRadius() const
Returns the feature descritor comptation radius.
void saveParameters() const
Saves parameters for next call.
ccPointCloud * getReferenceCloud()
Returns the 'reference' cloud.
virtual int checkSelected() override
Checks if current selection is compliant with the filter.
std::vector< ccPointCloud * > m_alignedClouds
FastGlobalRegistrationFilter()
virtual QString getErrorMessage(int errorCode) override
Returns the error message corresponding to a given error code.
virtual int compute() override
Performs the actual filter job.
ccPointCloud * m_referenceCloud
virtual void getParametersFromDialog() override
Collects parameters from the filter dialog (if openDialog is successful)
~FastGlobalRegistrationFilter() override
QString toString(int precision=12, QChar separator=' ') const
Returns matrix as a string.
T * data()
Returns a pointer to internal data.
Float version of ccGLMatrixTpl.
static ccPointCloud * ToPointCloud(ccHObject *obj, bool *isLockedVertices=nullptr)
Converts current object to 'equivalent' ccPointCloud.
Hierarchical CLOUDVIEWER Object.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasNormals() const override
Returns whether normals are enabled or not.
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
unsigned size() const override
const CCVector3 * getPoint(unsigned index) const override
virtual QMainWindow * getMainWindow()=0
Returns main window.
bool OptimizePairwise(bool decrease_mu=true)
void LoadFeature(const Points &pts, const Features &feat)
Eigen::Matrix4f GetOutputTrans() const
void AdvancedMatching(bool crossCheck=true, bool tupleConstraint=true)
std::vector< Eigen::Vector3f > Points
std::vector< Eigen::VectorXf > Features