21 #include <QApplication>
22 #include <QFileDialog>
24 #include <QMainWindow>
25 #include <QMessageBox>
26 #include <QPushButton>
45 : QDialog(app ? app->getActiveWindow() : 0),
46 Ui::Canupo2DViewDialog(),
48 m_classifierSaved(false),
49 m_descriptors1(descriptors1),
50 m_descriptors2(descriptors2),
51 m_evaluationDescriptors(evaluationDescriptors),
53 m_cloud1Name(cloud1Name),
54 m_cloud2Name(cloud2Name),
59 m_selectedPointIndex(-1),
64 cloud1NameLabel->setText(QString(
"class %1: ").arg(
m_class1) +
66 cloud2NameLabel->setText(QString(
"class %1: ").arg(
m_class2) +
90 viewFrame->setLayout(
new QHBoxLayout());
106 connect(resetToolButton, SIGNAL(clicked()),
this, SLOT(
resetBoundary()));
107 connect(statisticsToolButton, SIGNAL(clicked()),
this,
109 connect(savePushButton, SIGNAL(clicked()),
this, SLOT(
saveClassifier()));
111 connect(pointSizeSpinBox, SIGNAL(valueChanged(
int)),
this,
113 connect(scalesCountSpinBox, SIGNAL(valueChanged(
int)),
this,
128 scalesListLineEdit->setText(
"Invalid descriptors!");
129 scalesCountSpinBox->setEnabled(
false);
132 int maxScaleCount =
static_cast<int>(allScales.size());
133 scalesCountSpinBox->setRange(1, maxScaleCount);
134 if (firstTime) scalesCountSpinBox->setValue(maxScaleCount);
136 int currentScaleCount = scalesCountSpinBox->value();
137 QStringList scalesList;
138 for (
int i = 0; i < currentScaleCount; ++i)
139 scalesList << QString::number(
140 allScales[maxScaleCount - currentScaleCount + i]);
142 scalesListLineEdit->setText(scalesList.join(
" "));
143 scalesCountSpinBox->setEnabled(
true);
166 int maxScaleCount =
static_cast<int>(allScales.size());
167 int currentScaleCount = scalesCountSpinBox->value();
168 assert(currentScaleCount >= 1 && currentScaleCount <= maxScaleCount);
169 currentScaleCount = std::min<int>(currentScaleCount, maxScaleCount);
170 scales.resize(currentScaleCount);
171 for (
int i = 0; i < currentScaleCount; ++i) {
174 scales[i] = allScales[maxScaleCount - currentScaleCount + i];
187 statisticsToolButton->setEnabled(
false);
189 QApplication::processEvents();
192 std::vector<float> scales;
254 statisticsToolButton->setEnabled(
true);
261 scalesCountSpinBox->blockSignals(
true);
263 scalesCountSpinBox->blockSignals(
false);
274 std::vector<float> scales;
284 info << QString(
"\tTotal: %1").arg(
params.true1 +
params.false1);
285 info << QString(
"\tTruly classified: %1").arg(
params.true1);
286 info << QString(
"\tFalsely classified: %1").arg(
params.false1);
287 info << QString(
"\tDist. to boundary: %1 +/- %2")
292 info << QString(
"\tTotal: %1").arg(
params.true2 +
params.false2);
293 info << QString(
"\tTruly classified: %1").arg(
params.true2);
294 info << QString(
"\tFalsely classified: %1").arg(
params.false2);
295 info << QString(
"\tDist. to boundary: %1 +/- %2")
299 info << QString(
"Balanced accuracy (ba) = %1").arg(
params.ba());
300 info << QString(
"Fisher Discriminant Ratio (fdr) = %1")
303 QMessageBox::information(
this,
"Statistics", info.join(
"\n"),
318 if (QMessageBox::warning(
this,
"Classifier has not been saved!",
319 "Do you really want to close the dialog "
320 "before saving the classifier?",
322 QMessageBox::No) == QMessageBox::No)
349 if (pathLength > 1) {
354 for (
unsigned i = 0; i < pathLength; ++i)
357 -std::numeric_limits<PointCoordinateType>::epsilon()));
367 QSettings settings(
"qCanupo");
368 settings.beginGroup(
"Classif");
369 QString currentPath =
370 settings.value(
"MscCurrentPath", QApplication::applicationDirPath())
373 QString
filename = QFileDialog::getSaveFileName(
this,
"Save Classifier",
374 currentPath,
"*.prm");
386 QString(
"Classifier file saved: '%1'").arg(
filename));
394 currentPath = QFileInfo(
filename).absolutePath();
395 settings.setValue(
"MscCurrentPath", currentPath);
402 for (
unsigned i = 0; i <
m_poly->
size(); ++i) {
454 float closestSquareDist = 0;
455 for (
unsigned i = 0; i <
m_poly->
size(); ++i) {
457 if (closeIndex < 0 || squareDist < closestSquareDist) {
458 closestSquareDist = squareDist;
459 closeIndex =
static_cast<int>(i);
484 if (closeIndex >= 0) {
486 if ((P - *B).norm() <= maxPickingDist) {
494 double nearestProjectionDist = maxPickingDist;
496 int nearestSegIndex = -1;
497 for (
unsigned i = 0; i + 1 <
m_poly->
size(); ++i) {
513 if (
dist < nearestProjectionDist) {
514 nearestProjectionDist =
dist;
515 nearestProj = AH + *A;
516 nearestSegIndex =
static_cast<int>(i);
521 if (nearestSegIndex >= 0) {
523 closeIndex = nearestSegIndex;
529 if ((P - *A).norm2() < (P - *B).norm2()) {
532 closeIndex =
static_cast<int>(
m_poly->
size() - 1);
543 unsigned newIndexInCloud = vertices->
size();
544 vertices->
reserve(newIndexInCloud + 1);
556 while (newIndexInPoly < m_poly->
size()) {
557 unsigned previousIndexInCloud =
560 newIndexInCloud = previousIndexInCloud;
572 if (polySize < 3)
return;
578 if (closeIndex < 0)
return;
586 if ((P - *B).norm() > maxPickingDist) {
593 for (
unsigned i =
static_cast<unsigned>(closeIndex); i < polySize - 1; ++i)
602 Qt::MouseButtons buttons) {
603 if (buttons != Qt::LeftButton)
return;
constexpr PointCoordinateType PC_ONE
'1' as a PointCoordinateType value
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
cmdLineReadable * params[]
bool save(QString filename, QString &error)
Saves classifier as a CANUPO's classifier file (.prm)
Vector2Tpl< float > Point2D
2D point
std::vector< Point2D > path
Set of (core) point descriptors.
const std::vector< float > & scales() const
Returns associated scales.
Type dot(const Vector3Tpl &v) const
Dot product.
Type norm2() const
Returns vector square norm.
Type norm() const
Returns vector norm.
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
virtual void setVisible(bool state)
Sets entity visibility.
virtual void showColors(bool state)
Sets colors visibility.
void setTranslation(const Vector3Tpl< float > &Tr)
Sets translation (float version)
Float version of ccGLMatrixTpl.
void enableStippling(bool state)
Enables polygon stippling.
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
virtual void setColor(const ecvColor::Rgb &col)
Sets primitive color (shortcut)
Hierarchical CLOUDVIEWER Object.
virtual ccBBox getDisplayBB_recursive(bool relative)
Returns the bounding-box of this entity and it's children WHEN DISPLAYED.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool reserve(unsigned numberOfPoints) override
Reserves memory for all the active features.
void clear() override
Clears the entity from all its points and features.
void setVertexMarkerWidth(int width)
Sets the width of vertex markers.
void showVertices(bool state)
Sets whether to display or hide the polyline vertices.
void setColor(const ecvColor::Rgb &col)
Sets the polyline color.
void setWidth(PointCoordinateType width)
Sets the width of the line.
T getMaxBoxDim() const
Returns maximal box dimension.
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
unsigned size() const override
void clear(bool unusedParam=true) override
Clears the cloud.
virtual bool addPointIndex(unsigned globalIndex)
Point global index insertion mechanism.
virtual GenericIndexedCloudPersist * getAssociatedCloud()
Returns the associated (source) cloud.
unsigned size() const override
Returns the number of points.
virtual void setPointIndex(unsigned localIndex, unsigned globalIndex)
Sets global index for a given element.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
virtual bool resize(unsigned n)
Presets the size of the vector used to store point references.
virtual bool reserve(unsigned n)
Reserves some memory for hosting the point references.
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
Main application interface (for plugins)
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
void removePoint(int, int)
Classifier m_classifier
Associated classifier.
bool m_classifierSaved
Whether the classifier has been saved (at least once)
virtual ~qCanupo2DViewDialog()
Destructor.
ccPointCloud * m_cloud
Associated cloud.
void reset()
Resets display.
const CorePointDescSet * m_evaluationDescriptors
bool trainClassifier()
Trains the classifier (with the current number of scales!)
void setPickingRadius(int radius)
Sets picking radius (for polyline vertices)
const CorePointDescSet * m_descriptors1
CCVector3 getClickPos(int x, int y) const
Returns the click position in 3D.
void updateScalesList(bool firstTime)
Updates the list of active scales.
void updateClassifierPath(Classifier &classifier) const
Updates classifier path with the currently displayed polyline.
void addOrSelectPoint(int, int)
const CorePointDescSet * m_descriptors2
qCanupo2DViewDialog(const CorePointDescSet *descriptors1, const CorePointDescSet *descriptors2, QString cloud1Name, QString cloud2Name, int class1=1, int class2=2, const CorePointDescSet *evaluationDescriptors=0, ecvMainAppInterface *app=0)
Default constructor.
void computeStatistics()
Computes statistics with the current classifier.
int m_pickingRadius
Picking radius.
void moveSelectedPoint(int, int, Qt::MouseButtons)
void resetBoundary()
Updates the boundary representation.
void getActiveScales(std::vector< float > &scales) const
Returns the list of active scales.
int m_selectedPointIndex
Currently selected polyline point.
void addObject(ccHObject *obj)
Adds a custom object to the 2D view.
ecvMainAppInterface * m_app
Gives access to the application (data-base, UI, etc.)
void updateZoom()
Updates zoom.
void onScalesCountSpinBoxChanged(int)
ccPointCloud * m_polyVertices
Associated polyline vertices.
ccPolyline * m_poly
Associated polyline.
int getClosestVertex(int x, int y, CCVector3 &P) const
Returns closest vertex.
__host__ __device__ float dot(float2 a, float2 b)
static double dist(double x1, double y1, double x2, double y2)
static void error(char *msg)
constexpr Rgb magenta(MAX, 0, MAX)
constexpr Rgb red(MAX, 0, 0)
constexpr Rgb blue(0, 0, MAX)
static bool s_firstDisplay
static int s_trainingValue
OpenGL camera parameters.
bool unproject(const CCVector3d &input2D, CCVector3d &output3D) const
Unprojects a 2D point (+ normalized 'z' coordinate) in 3D.