File: qCanupoClassifDialog.cpp

package info (click to toggle)
cloudcompare 2.10.1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,916 kB
  • sloc: cpp: 219,837; ansic: 29,944; makefile: 67; sh: 45
file content (286 lines) | stat: -rw-r--r-- 9,881 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//##########################################################################
//#                                                                        #
//#                     CLOUDCOMPARE PLUGIN: qCANUPO                       #
//#                                                                        #
//#  This program is free software; you can redistribute it and/or modify  #
//#  it under the terms of the GNU General Public License as published by  #
//#  the Free Software Foundation; version 2 or later of the License.      #
//#                                                                        #
//#  This program is distributed in the hope that it will be useful,       #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          #
//#  GNU General Public License for more details.                          #
//#                                                                        #
//#      COPYRIGHT: UEB (UNIVERSITE EUROPEENNE DE BRETAGNE) / CNRS         #
//#                                                                        #
//##########################################################################

#include "qCanupoClassifDialog.h"

//local
#include "classifier.h"
#include "qCanupoTools.h"

//qCC_plugins
#include "../../ccMainAppInterface.h"

//qCC_db
#include <ccPointCloud.h>

//Qt
#include <QSettings>
#include <QMainWindow>
#include <QComboBox>
#include <QFileInfo>
#include <QFileDialog>
#include <QPushButton>
#include <QApplication>
#include <QThread>

qCanupoClassifDialog::qCanupoClassifDialog(ccPointCloud* cloud, ccMainAppInterface* app)
	: QDialog(app ? app->getMainWindow() : 0)
	, Ui::CanupoClassifDialog()
	, m_app(app)
	, m_cloud(cloud)
{
	setupUi(this);

#ifndef COMPILE_PRIVATE_CANUPO
	generateRoughnessSFsCheckBox->setVisible(false);
#endif

	int maxThreadCount = QThread::idealThreadCount();
	maxThreadCountSpinBox->setRange(1, maxThreadCount);
	maxThreadCountSpinBox->setSuffix(QString(" / %1").arg(maxThreadCount));

	loadParamsFromPersistentSettings();

	if (cloud)
	{
		//check if a the cloud has an active SF!
		useSFCheckBox->setEnabled(cloud->getCurrentDisplayedScalarField() != 0);
	}

	if (m_app)
	{
		//add list of clouds to the combo-boxes
		ccHObject::Container clouds;
		if (m_app->dbRootObject())
			m_app->dbRootObject()->filterChildren(clouds,true,CC_TYPES::POINT_CLOUD);

		for (size_t i=0; i<clouds.size(); ++i)
		{
			if (clouds[i]->isA(CC_TYPES::POINT_CLOUD)) //as filterChildren only test 'isKindOf'
				cpOtherCloudComboBox->addItem(qCanupoTools::GetEntityName(clouds[i]),QVariant(clouds[i]->getUniqueID()));
		}
	}

	connect(browseToolButton,		SIGNAL(clicked()), this, SLOT(browseClassifierFile()));
	connect(mscBrowseToolButton,	SIGNAL(clicked()), this, SLOT(browseMscFile()));

	buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}

double qCanupoClassifDialog::getConfidenceTrehshold() const
{
	if (!useConfThresholdGroupBox->isChecked())
		return 0.0;

	//confidence threshold between 0 and 1
	assert(pokDoubleSpinBox->value() >= 0 && pokDoubleSpinBox->value() <= 1.0);
	return pokDoubleSpinBox->value();
}

bool qCanupoClassifDialog::useSF() const
{
	return useConfThresholdGroupBox->isChecked() && useSFCheckBox->isChecked();
}

int qCanupoClassifDialog::getMaxThreadCount() const
{
	return maxThreadCountSpinBox->value();
}

qCanupoClassifDialog::CORE_CLOUD_SOURCES qCanupoClassifDialog::getCorePointsCloudSource() const
{
	if (cpUseCloudRadioButton->isChecked())
	{
		return ORIGINAL;
	}
	else if (cpSubsampleRadioButton->isChecked())
	{
		return SUBSAMPLED;
	}
	else if (cpUseOtherCloudRadioButton->isChecked())
	{
		return OTHER;
	}
	else if (cpMscFileRadioButton->isChecked())
	{
		return MSC_FILE;
	}

	assert(false);
	return ORIGINAL;
}

QString qCanupoClassifDialog::getMscFilename() const
{
	return mscFileLineEdit->text();
}

ccPointCloud* qCanupoClassifDialog::getCorePointsCloud()
{
	if (cpUseCloudRadioButton->isChecked())
	{
		return m_cloud;
	}
	else if (cpUseOtherCloudRadioButton->isChecked())
	{
		//return the cloud currently selected in the combox box
		return qCanupoTools::GetCloudFromCombo(cpOtherCloudComboBox, m_app->dbRootObject());
	}
	else
	{
		return 0;
	}
}

void qCanupoClassifDialog::loadParamsFromPersistentSettings()
{
	QSettings settings("qCanupo");
	settings.beginGroup("Classif");

	//read out parameters
	//double minScale = settings.value("MinScale",minScaleDoubleSpinBox->value()).toDouble();
	//double step = settings.value("Step",stepScaleDoubleSpinBox->value()).toDouble();
	//double maxScale = settings.value("MaxScale",maxScaleDoubleSpinBox->value()).toDouble();

	double subsampleRadius = settings.value("SubsampleRadius",cpSubsamplingDoubleSpinBox->value()).toDouble();
	bool subsampleEnabled = settings.value("SubsampleEnabled",cpSubsampleRadioButton->isChecked()).toBool();

	QString currentPath = settings.value("CurrentPath",QApplication::applicationDirPath()).toString();
	QString mscCurrentPath = settings.value("MscCurrentPath",QApplication::applicationDirPath()).toString();

	bool useConfThreshold = settings.value("UseConfThreshold",useConfThresholdGroupBox->isChecked()).toBool();
	double pok = settings.value("Pok",pokDoubleSpinBox->value()).toDouble();
	bool useSF = settings.value("UseSF",useSFCheckBox->isChecked()).toBool();
	bool additionalSF = settings.value("AdditionalSF",generateAdditionalSFsCheckBox->isChecked()).toBool();
	bool roughnessSF = settings.value("RoughnessSF",generateRoughnessSFsCheckBox->isChecked()).toBool();
	int maxThreadCount = settings.value("MaxThreadCount", maxThreadCountSpinBox->maximum()).toInt();

	//apply parameters

	//minScaleDoubleSpinBox->setValue(minScale);
	//stepScaleDoubleSpinBox->setValue(step);
	//maxScaleDoubleSpinBox->setValue(maxScale);

	cpSubsamplingDoubleSpinBox->setValue(subsampleRadius);
	if (subsampleEnabled)
		cpSubsampleRadioButton->setChecked(true);
	
	classifFileLineEdit->setText(currentPath);
	mscFileLineEdit->setText(mscCurrentPath);

	useConfThresholdGroupBox->setChecked(useConfThreshold);
	pokDoubleSpinBox->setValue(pok);
	useSFCheckBox->setChecked(useSF);
	generateAdditionalSFsCheckBox->setChecked(additionalSF);
	generateRoughnessSFsCheckBox->setChecked(roughnessSF);
	maxThreadCountSpinBox->setValue(maxThreadCount);
}

void qCanupoClassifDialog::saveParamsToPersistentSettings()
{
	QSettings settings("qCanupo");
	settings.beginGroup("Classif");

	//save parameters
	//settings.setValue("MinScale",minScaleDoubleSpinBox->value());
	//settings.setValue("Step",stepScaleDoubleSpinBox->value());
	//settings.setValue("MaxScale",maxScaleDoubleSpinBox->value());

	settings.setValue("SubsampleRadius",cpSubsamplingDoubleSpinBox->value());
	settings.setValue("SubsampleEnabled",cpSubsampleRadioButton->isChecked());

	QString currentPath = QFileInfo(classifFileLineEdit->text()).absolutePath();
	settings.setValue("CurrentPath",currentPath);

	settings.setValue("UseConfThreshold",useConfThresholdGroupBox->isChecked());
	settings.setValue("Pok",pokDoubleSpinBox->value());
	settings.setValue("UseSF",useSFCheckBox->isChecked());
	settings.setValue("AdditionalSF",generateAdditionalSFsCheckBox->isChecked());
	settings.setValue("RoughnessSF",generateRoughnessSFsCheckBox->isChecked());

	settings.setValue("MaxThreadCount", maxThreadCountSpinBox->value());
}

void qCanupoClassifDialog::browseMscFile()
{
	//select file to open
	QSettings settings("qCanupo");
	settings.beginGroup("Classif");
	QString currentPath = settings.value("MscCurrentPath",mscFileLineEdit->text()).toString();

	QString filename = QFileDialog::getOpenFileName(this,"Load MSC file",currentPath,"*.msc");
	if (filename.isEmpty())
		return;

	//we update current file path
	mscFileLineEdit->setText(filename);
	currentPath = QFileInfo(filename).absolutePath();
	settings.setValue("MscCurrentPath",currentPath);
}

void qCanupoClassifDialog::browseClassifierFile()
{
	//select file to open
	QString filename;
	QSettings settings("qCanupo");
	settings.beginGroup("Classif");
	QString currentPath = settings.value("CurrentPath",classifFileLineEdit->text()).toString();

	filename = QFileDialog::getOpenFileName(this,"Load classifier file",currentPath,"*.prm");
	if (filename.isEmpty())
		return;

	//we update current file path
	classifFileLineEdit->setText(filename);
	currentPath = QFileInfo(filename).absolutePath();
	settings.setValue("CurrentPath",currentPath);

	//and we try to load the file header (to display some info)
	std::vector<Classifier> classifiers;
	std::vector<PointCoordinateType> scales;
	QString error;
	Classifier::FileHeader header;
	if (Classifier::Load(filename, classifiers, scales, error, &header, true))
	{
		//display classifier file description
		QStringList fileDesc;
		fileDesc << QString("File: %1").arg(QFileInfo(filename).fileName());
		fileDesc << QString("Classifier(s) in file: %1").arg(header.classifierCount);

		assert(header.descID != 0);
		ScaleParamsComputer* computer = ScaleParamsComputer::GetByID(header.descID);
		QString descriptorName = computer? computer->getName() : QString("INVALID");
		fileDesc << QString("Descriptor ID: %1 (%2)").arg(header.descID).arg(descriptorName);

		fileDesc << QString("Dimensions per scale: %1").arg(header.dimPerScale);
		fileDesc << QString("Scales: %1").arg(scales.size());
		QString scalesStr("    [ ");
		for (size_t i=0; i<scales.size(); ++i)
			scalesStr.append(QString("%1 ").arg(scales[scales.size()-1-i])); //reverse order as scales are sorted from biggest to smallest
		scalesStr.append("]");
		fileDesc << scalesStr;

		classifInfoTextEdit->setText(fileDesc.join("\n"));
	
		buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
	}
	else
	{
		classifInfoTextEdit->setText("Error: failed to open/read the input file");
		buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
	}
}