10 #include <Utils/cc2sm.h>
11 #include <Utils/sm2cc.h>
13 #include "PclUtils/PCLModules.h"
24 #include <QMainWindow>
31 tr(
"Template Alignment"),
32 tr(
"Template Alignment"),
33 tr(
"Template Alignment from clouds"),
34 ":/toolbar/PclAlgorithms/icons/templateAlignment.png")),
36 m_templateMatch(nullptr),
37 m_targetCloud(nullptr),
38 m_useVoxelGrid(false),
40 m_normalRadius(0.02f),
41 m_featureRadius(0.02f),
42 m_minSampleDistance(0.05f),
43 m_maxCorrespondenceDistance(0.01f * 0.01f),
45 m_maxThreadCount(1) {}
58 if (have_cloud != 1)
return -11;
117 if (!cloud1 && !cloud2) {
124 assert(cloud1 != cloud2);
146 PointCloudT::Ptr cloudFiltered =
148 if (cloudFiltered->width * cloudFiltered->height != 0) {
150 PCLModules::FeatureCloud template_cloud;
155 template_cloud.setInputCloud(cloudFiltered);
162 PointCloudT::Ptr cloudFiltered = cc2smReader(
m_targetCloud).getXYZ2();
165 PointCloudT::Ptr tempCloud(
new PointCloudT);
166 if (!PCLModules::VoxelGridFilter<PointT>(cloudFiltered, tempCloud,
171 cloudFiltered = tempCloud;
174 if (!cloudFiltered) {
179 PCLModules::FeatureCloud target_cloud;
184 target_cloud.setInputCloud(cloudFiltered);
189 PCLModules::TemplateMatching::Result best_alignment;
191 const PCLModules::FeatureCloud* best_template =
193 if (!best_template) {
199 tr(
"(values less than 0.00002 are good) Best fitness score: %1")
200 .arg(best_alignment.fitness_score));
202 ccGLMatrixd transMat(best_alignment.final_transformation.data());
205 PCLCloud out_cloud_sm;
206 TO_PCL_CLOUD(*best_template->getPointCloud(), out_cloud_sm);
207 if (out_cloud_sm.height * out_cloud_sm.width == 0) {
212 ccPointCloud* out_cloud_cc = pcl2cc::Convert(out_cloud_sm);
223 out_cloud_cc->
showSF(
false);
229 if (best_index == 0) {
231 }
else if (best_index == 1) {
236 QString outName = cloud->
getName() +
"-alignment";
237 out_cloud_cc->
setName(outName);
257 CVLog::Print(tr(
"[ApplyTransformation] Applied transformation matrix:"));
260 tr(
"Hint: copy it (CTRL+C) and apply it - or its inverse - on any "
261 "entity with the 'Edit > Apply transformation' tool"));
271 "Selected entity does not have any suitable scalar field "
275 "Wrong Parameters. One or more parameters cannot be "
279 "Template Alignment does not returned any point. Try "
280 "relaxing your parameters");
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.
static bool Print(const char *format,...)
Prints out a formatted message in console.
CANUPO plugin's training dialog.
float getMaxCorrespondenceDistance() const
Returns the Maximum Correspondence Distance.
float getFeatureRadius() const
Returns the Feature Radius.
float getVoxelGridLeafSize() const
float getMinSampleDistance() const
Returns the Minimum Sample Distance.
bool getScales(std::vector< float > &scales) const
Returns input scales.
int getMaxIterations() const
Returns the Maximum Iterations.
void saveParamsToPersistentSettings()
Saves parameters to persistent settings.
ccPointCloud * getTemplate1Cloud()
Get template #1 point cloud.
float getNormalRadius() const
Returns the Normal Radius.
void refreshCloudComboBox()
ccPointCloud * getTemplate2Cloud()
Get template #2 point cloud.
ccPointCloud * getEvaluationCloud()
Get evaluation point cloud.
void applyTransformation(ccHObject *entity, const ccGLMatrixd &mat)
virtual int checkSelected()
Checks if current selection is compliant with the filter.
virtual int openInputDialog()
float m_minSampleDistance
virtual void getParametersFromDialog()
Collects parameters from the filter dialog (if openDialog is successful)
virtual ~TemplateAlignment()
std::vector< float > m_scales
virtual int checkParameters()
virtual QString getErrorMessage(int errorCode)
Returns the error message corresponding to a given error code.
virtual int compute()
Performs the actual filter job.
TemplateAlignmentDialog * m_dialog
std::vector< ccPointCloud * > m_templateClouds
ccPointCloud * m_targetCloud
float m_maxCorrespondenceDistance
PCLModules::TemplateMatching * m_templateMatch
virtual void showColors(bool state)
Sets colors visibility.
virtual void showSF(bool state)
Sets active scalarfield visibility.
virtual void setGLTransformation(const ccGLMatrix &trans)
Associates entity with a GL transformation (rotation + translation)
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.
Double version of ccGLMatrixTpl.
Hierarchical CLOUDVIEWER Object.
void applyGLTransformation_recursive(const ccGLMatrix *trans=nullptr)
Applies the active OpenGL transformation to the entity (recursive)
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.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool setRGBColor(ColorCompType r, ColorCompType g, ColorCompType b)
Set a unique color for the whole cloud (shortcut)
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.
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
constexpr Rgb darkBlue(0, 0, MAX/2)