ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
FastGlobalRegistrationDlg.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 // common
11 #include <ecvQtHelpers.h>
12 
13 // qCC_db
14 #include <ecvDisplayTools.h>
15 #include <ecvOctree.h>
16 #include <ecvPointCloud.h>
17 
18 // system
19 #include <assert.h>
20 
21 static double s_featureRadius = 0;
22 
24  const std::vector<ccPointCloud*>& allClouds,
25  QWidget* parent /*=nullptr*/)
26  : QDialog(parent, Qt::Tool),
28  clouds(allClouds),
29  referencesCloudUinqueID(ccUniqueIDGenerator::InvalidUniqueID) {
30  setupUi(this);
31 
32  ccQtHelpers::SetButtonColor(dataColorButton, Qt::red);
33  ccQtHelpers::SetButtonColor(modelColorButton, Qt::yellow);
34 
35  for (ccPointCloud* cloud : clouds) {
36  referenceComboBox->addItem(cloud->getName(), cloud->getUniqueID());
37  }
38 
39  if (!clouds.empty()) {
40  referencesCloudUinqueID = clouds.front()->getUniqueID();
41  }
42 
43  updateGUI();
44 
45  // restore semi-persistent settings
46  {
47  // semi-persistent options
48  double previousRadius = s_featureRadius;
49  if (previousRadius == 0) {
50  for (ccPointCloud* cloud : clouds) {
51  double radius = ccOctree::GuessNaiveRadius(cloud);
52  previousRadius = std::max(radius, previousRadius);
53  }
54  }
55 
56  featureRadiusDoubleSpinBox->setValue(previousRadius);
57  }
58 
59  connect(autoRadiusToolButton, &QToolButton::clicked, this,
61  connect(referenceComboBox, qOverload<int>(&QComboBox::currentIndexChanged),
63 }
64 
67  for (ccPointCloud* cloud : clouds) {
68  cloud->enableTempColor(false);
69  cloud->setForceRedraw(true);
70  }
71 
73 }
74 
77 }
78 
80  for (ccPointCloud* cloud : clouds) {
81  if (cloud->getUniqueID() == referencesCloudUinqueID) return cloud;
82  }
83 
84  return nullptr;
85 }
86 
88  return featureRadiusDoubleSpinBox->value();
89 }
90 
92  if (clouds.size() < 2) return;
93 
94  ccPointCloud* referenceCloud = getReferenceCloud();
95  if (!referenceCloud) {
96  assert(false);
97  return;
98  }
99 
100  // aligned cloud(s)
101  ccPointCloud* alignedCloud = nullptr; // only one of them
102  int referenceCloudIndex = -1;
104  for (size_t i = 0; i < clouds.size(); ++i) {
105  ccPointCloud* cloud = clouds[i];
106  if (cloud->getUniqueID() != referencesCloudUinqueID) {
107  alignedCloud = cloud;
108  alignedCloud->setVisible(true);
109  alignedCloud->setTempColor(ecvColor::red);
110  alignedCloud->setForceRedraw(true);
111  } else {
112  referenceCloudIndex = static_cast<int>(i);
113  }
114  }
115  alignedLineEdit->setText(
116  clouds.size() == 2 ? alignedCloud->getName()
117  : tr("%1 other clouds").arg(clouds.size() - 1));
118 
119  // reference cloud
120  referenceCloud->setVisible(true);
121  referenceCloud->setTempColor(ecvColor::yellow);
122  referenceCloud->setForceRedraw(true);
123 
124  referenceComboBox->blockSignals(true);
125  referenceComboBox->setCurrentIndex(referenceCloudIndex);
126  referenceComboBox->blockSignals(false);
127 
129 }
130 
132  referencesCloudUinqueID = referenceComboBox->itemData(index).toUInt();
133 
134  updateGUI();
135 }
136 
139  {
140  params.aimedPopulationPerCell = 64;
141  params.aimedPopulationRange = 16;
142  params.minCellPopulation = 48;
143  params.minAboveMinRatio = 0.97;
144  }
145 
146  PointCoordinateType largestRadius = 0.0;
147  for (ccPointCloud* cloud : clouds) {
148  PointCoordinateType radius =
150  if (radius < 0) {
151  CVLog::Error(tr("Failed to estimate the radius for cloud %1")
152  .arg(cloud->getName()));
153  return;
154  }
155  largestRadius = std::max(largestRadius, radius);
156  }
157 
158  featureRadiusDoubleSpinBox->setValue(largestRadius);
159 }
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
static double s_featureRadius
cmdLineReadable * params[]
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
Fast Global Registration dialog.
double getFeatureRadius() const
Returns the feature descritor comptation radius.
unsigned referencesCloudUinqueID
Reference cloud unique ID.
FastGlobalRegistrationDialog(const std::vector< ccPointCloud * > &allClouds, QWidget *parent=nullptr)
Default constructor.
std::vector< ccPointCloud * > clouds
All clouds (input)
void saveParameters() const
Saves parameters for next call.
~FastGlobalRegistrationDialog() override
Default destructor.
ccPointCloud * getReferenceCloud()
Returns the 'reference' cloud.
virtual void setTempColor(const ecvColor::Rgb &col, bool autoActivate=true)
Sets current temporary (unique)
virtual void setVisible(bool state)
Sets entity visibility.
virtual void setForceRedraw(bool state)
Sets force redraw.
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
virtual unsigned getUniqueID() const
Returns object unique ID.
Definition: ecvObject.h:86
static PointCoordinateType GuessBestRadiusAutoComputeOctree(ccGenericPointCloud *cloud, const BestRadiusParams &params, QWidget *parentWidget=nullptr)
static PointCoordinateType GuessNaiveRadius(ccGenericPointCloud *cloud)
Tries to guess a very naive 'local radius' for octree-based computation.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
static void SetButtonColor(QAbstractButton *button, const QColor &col)
Sets a button background color.
Definition: ecvQtHelpers.h:17
static void SetRedrawRecursive(bool redraw=false)
static void RedrawDisplay(bool only2D=false, bool forceRedraw=true)
int max(int a, int b)
Definition: cutil_math.h:48
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb yellow(MAX, MAX, 0)
Parameters for the GuessBestRadius method.
Definition: ecvOctree.h:122