10 #include <Utils/cc2sm.h>
11 #include <Utils/sm2cc.h>
13 #include "PclUtils/PCLModules.h"
14 #include "Tools/Common/CurveFitting.h"
15 #include "Tools/Common/ecvTools.h"
27 #include <QMainWindow>
34 tr(
"BSpline Curve Fitting"),
35 tr(
"BSpline Curve Fitting"),
36 tr(
"BSpline Curve Fitting from clouds"),
37 ":/toolbar/PclAlgorithms/icons/bspline_curve.png")),
40 m_useVoxelGrid(false),
41 m_exportProjectedCloud(false),
42 m_curveFitting3D(true),
45 m_minimizationType(0),
48 m_curveSmoothness(0.000001f) {}
58 if (have_cloud != 1)
return -11;
84 m_dialog->exportProjectedCloudCheckBox->isChecked();
91 static_cast<float>(
m_dialog->curveSmoothnessSpinBox->value());
98 if (!cloud)
return -1;
100 PointCloudRGB::Ptr outCurve(
new PointCloudRGB);
101 PointCloudT::Ptr xyzCloud = cc2smReader(cloud).getXYZ2();
102 if (!xyzCloud)
return -1;
107 3 * PCLModules::ComputeCloudResolution<PointT>(xyzCloud);
109 PointCloudT::Ptr tempCloud(
new PointCloudT);
110 if (!PCLModules::VoxelGridFilter<PointT>(
111 xyzCloud, tempCloud, leafSize, leafSize, leafSize)) {
114 xyzCloud = tempCloud;
119 PointCloudT::Ptr outCurve(
new PointCloudT);
121 fit.setInputcloud(xyzCloud);
122 PointCloudT::Ptr point_mean(
new PointCloudT);
123 std::vector<double> x_mean, y_mean, z_mean;
126 fit.grid_mean_xyz(0.5, -1, x_mean, y_mean, z_mean, point_mean);
127 fit.polynomial3D_fitting(x_mean, y_mean, z_mean, a, b, c);
128 fit.getPolynomial3D(outCurve, 0.01);
130 if (outCurve->points.size() > 1)
132 PointT sp = outCurve->points[0];
133 CVLog::Print(tr(
"Start Point: X1= %1, Y1= %2, Z1= %3").arg(sp.x).arg(sp.y).arg(sp.z));
134 PointT ep = outCurve->points[outCurve->points.size() -1];
135 CVLog::Print(tr(
"End Point: X2= %1, Y2= %2, Z2= %3").arg(ep.x).arg(ep.y).arg(ep.z));
136 CVLog::Print(tr(
"space polynomial curve equation: z = %1 * (x^2+y^2) + %2 * sqrt(x^2+y^2) + %3").arg(a).arg(b).arg(c));
162 Eigen::Matrix4f xoyTransformation(makeZPosMatrix.
data());
163 pcl::transformPointCloud(*xyzCloud, *xyzCloud, xoyTransformation);
166 #if defined(WITH_PCL_NURBS)
168 PointCloudT::Ptr zoyCloud(
new PointCloudT);
170 if (!PCLModules::BSplineCurveFitting3D<PointT>(
176 if (outCurve->points.size() == 0) {
181 PCLModules::CurveFittingMethod fittingMethod =
183 if (!PCLModules::BSplineCurveFitting2D<PointT>(
189 if (outCurve->points.size() == 0) {
195 tr(
"[NurbsCurveFitting] PCL not supported with nurbs, please "
196 "rebuild pcl with -DBUILD_surface_on_nurbs=ON again"));
202 Eigen::Matrix4f inverseXoyTransformation(
204 pcl::transformPointCloud(*outCurve, *outCurve,
205 inverseXoyTransformation);
211 PCLCloud::Ptr curve_sm(
new PCLCloud);
212 TO_PCL_CLOUD(*outCurve, *curve_sm);
213 curvePoly = ecvTools::GetPolylines(curve_sm,
"fitting-curve",
m_closed);
217 CVLog::Print(tr(
"[NurbsCurveFitting] curve : %1 point(s)")
218 .arg(curvePoly->
size()));
224 :
"" + QString(
" [curve-fitting]-"));
228 TO_PCL_CLOUD(*xyzCloud, curve_sm);
229 ccPointCloud* projectedCloud = pcl2cc::Convert(curve_sm);
230 if (projectedCloud) {
231 projectedCloud->
setName(
"projected-xoy");
237 outObject->
addChild(projectedCloud);
249 outObject = curvePoly;
269 "Selected entity does not have any suitable scalar field "
273 "Wrong Parameters. One or more parameters cannot be "
277 "Nurbs Curve Fitting does not returned any point. Try "
278 "relaxing your parameters");
constexpr PointCoordinateType PC_ONE
'1' as a PointCoordinateType value
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
Base abstract class for each implemented PCL filter.
int isFirstSelectedCcPointCloud()
Returns 1 if the first selected object is a ccPointCloud.
void newEntity(ccHObject *)
Signal emitted when a new entity is created by the filter.
ecvMainAppInterface * m_app
Associated application interface.
virtual QString getErrorMessage(int errorCode)
Returns the error message corresponding to a given error code.
ccPointCloud * getSelectedEntityAsCCPointCloud() const
Returns the first selected entity as a ccPointCloud.
static bool Print(const char *format,...)
Prints out a formatted message in console.
virtual int checkParameters()
virtual int compute()
Performs the actual filter job.
virtual void getParametersFromDialog()
Collects parameters from the filter dialog (if openDialog is successful)
bool m_exportProjectedCloud
virtual QString getErrorMessage(int errorCode)
Returns the error message corresponding to a given error code.
virtual ~NurbsCurveFitting()
NurbsCurveFittingDlg * m_dialog
virtual int checkSelected()
Checks if current selection is compliant with the filter.
virtual int openInputDialog()
virtual void setVisible(bool state)
Sets entity visibility.
static ccGLMatrixTpl< float > FromToRotation(const Vector3Tpl< float > &from, const Vector3Tpl< float > &to)
Creates a transformation matrix that rotates a vector to another.
T * data()
Returns a pointer to internal data.
ccGLMatrixTpl< T > inverse() const
Returns inverse transformation.
Float version of ccGLMatrixTpl.
Hierarchical CLOUDVIEWER Object.
unsigned getChildrenNumber() const
Returns the number of children.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccHObject * getParent() const
Returns parent object.
virtual QString getName() const
Returns object name.
virtual void setName(const QString &name)
Sets object name.
static ccPlane * Fit(cloudViewer::GenericIndexedCloudPersist *cloud, double *rms=0)
Fits a plane primitive on a cloud.
CCVector3 getNormal() const override
Returns the entity normal.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
virtual void setGlobalScale(double scale)
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
virtual const CCVector3d & getGlobalShift() const
Returns the shift applied to original coordinates.
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
unsigned size() const override
Returns the number of points.
virtual QWidget * getActiveWindow()=0