|
@@ -24,9 +24,23 @@
|
|
|
#include <cstdlib>
|
|
|
#include <ctime>
|
|
|
#include <stdexcept>
|
|
|
+#include <QDebug>
|
|
|
|
|
|
#include "StrengthLine.hpp"
|
|
|
|
|
|
+StrengthLine::StrengthLine (double ax, double ay, double bx, double by)
|
|
|
+{
|
|
|
+ if (p1 == NULL || p2 == NULL)
|
|
|
+ throw std::
|
|
|
+ invalid_argument ("Points defining a strength line can't be NULL.");
|
|
|
+ if (ax == bx && ay == by)
|
|
|
+ throw std::
|
|
|
+ invalid_argument ("Points defining a strength line can't be equals.");
|
|
|
+
|
|
|
+ this->p1 = new QPoint(ax, ay);
|
|
|
+ this->p2 = new QPoint(bx, by);
|
|
|
+}
|
|
|
+
|
|
|
StrengthLine::StrengthLine (QPoint * p1, QPoint * p2)
|
|
|
{
|
|
|
if (p1 == NULL || p2 == NULL)
|
|
@@ -62,34 +76,8 @@ StrengthLine::equation () const
|
|
|
return std::make_pair (a, b);
|
|
|
}
|
|
|
|
|
|
-std::pair < QPoint *, QPoint * >StrengthLine::toDraw (QImage * img) const
|
|
|
+std::pair < QPoint *, QPoint * >StrengthLine::toDraw (QImage * img) const
|
|
|
{
|
|
|
- /*
|
|
|
- // Methode qui va calculer les points pour l'affichage des droites
|
|
|
- // sur l'image passées en paramètre. Calcul rapide donc
|
|
|
- // les points peuvent sortir de l'image.
|
|
|
-
|
|
|
- // ligne verticale
|
|
|
- if (p1->x () == p2->x ())
|
|
|
- return std::make_pair (new QPoint (p1->x (), 0),
|
|
|
- new QPoint (p1->x (), img->height ()));
|
|
|
-
|
|
|
- // ligne horizontale
|
|
|
- if (p1->y () == p2->y ())
|
|
|
- return std::make_pair (new QPoint (0, p1->y ()),
|
|
|
- new QPoint (img->width (), p1->y ()));
|
|
|
-
|
|
|
- // Equation de la droite et on prend les points gauche et droite de la ligne
|
|
|
- std::pair < float, float >
|
|
|
- eq = this->equation ();
|
|
|
- float
|
|
|
- a = std::get < 0 > (eq);
|
|
|
- float
|
|
|
- b = std::get < 1 > (eq);
|
|
|
-
|
|
|
- return std::make_pair (new QPoint (0, b),
|
|
|
- new QPoint (img->width (), a * img->width () + b));
|
|
|
- */
|
|
|
return this->toDraw(img->width(), img->height());
|
|
|
}
|
|
|
|
|
@@ -110,6 +98,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::toDraw (int imgWidth, int imgHeigh
|
|
|
new QPoint (imgWidth, p1->y ()));
|
|
|
|
|
|
// Equation de la droite et on prend les points gauche et droite de la ligne
|
|
|
+
|
|
|
std::pair < float, float >
|
|
|
eq = this->equation ();
|
|
|
float
|
|
@@ -118,10 +107,15 @@ std::pair < QPoint *, QPoint * >StrengthLine::toDraw (int imgWidth, int imgHeigh
|
|
|
b = std::get < 1 > (eq);
|
|
|
|
|
|
return std::make_pair (new QPoint (0, b),
|
|
|
- new QPoint (imgWidth, a * imgWidth + b));
|
|
|
+ new QPoint (imgWidth, imgWidth * a + b));
|
|
|
}
|
|
|
|
|
|
std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) const
|
|
|
+{
|
|
|
+ return this->interpolateToEdge(img->width(), img->height());
|
|
|
+}
|
|
|
+
|
|
|
+std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (int imgWidth, int imgHeight) const
|
|
|
{
|
|
|
// Methode qui va calculer les points sur les bords des images
|
|
|
// en fonction des deux points attributs qui définissent
|
|
@@ -130,12 +124,12 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// ligne verticale
|
|
|
if (p1->x () == p2->x ())
|
|
|
return std::make_pair (new QPoint (p1->x (), 0),
|
|
|
- new QPoint (p1->x (), img->height ()));
|
|
|
+ new QPoint (p1->x (), imgHeight));
|
|
|
|
|
|
// ligne horizontale
|
|
|
if (p1->y () == p2->y ())
|
|
|
return std::make_pair (new QPoint (0, p1->y ()),
|
|
|
- new QPoint (img->width (), p1->y ()));
|
|
|
+ new QPoint (imgWidth, p1->y ()));
|
|
|
|
|
|
// Equation de la droite et on prend les points gauche et droite de la ligne
|
|
|
std::pair < float, float >
|
|
@@ -149,7 +143,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
{
|
|
|
if(b<0)
|
|
|
{
|
|
|
- if((a*img->width()+b) > img->height())
|
|
|
+ if((a*imgWidth+b) > imgHeight)
|
|
|
{
|
|
|
// |------------------------------------------|
|
|
|
// | * |
|
|
@@ -164,7 +158,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
return std::make_pair (new QPoint (-1*(b/a), 0),
|
|
|
- new QPoint ((img->height()-b)/a, img->height ()));
|
|
|
+ new QPoint ((imgHeight-b)/a, imgHeight));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -181,13 +175,13 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
return std::make_pair (new QPoint (-1*(b/a), 0),
|
|
|
- new QPoint (img->width (), a * img->width () + b));
|
|
|
+ new QPoint (imgWidth, a * imgWidth + b));
|
|
|
}
|
|
|
}
|
|
|
else // a>0 and b>0
|
|
|
{
|
|
|
|
|
|
- if((a*img->width()+b) > img->height())
|
|
|
+ if((a*imgWidth+b) > imgHeight)
|
|
|
{
|
|
|
// |------------------------------------------|
|
|
|
// | |
|
|
@@ -202,7 +196,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
return std::make_pair (new QPoint (0, b),
|
|
|
- new QPoint ((img->height () -b )/a, img->height ()));
|
|
|
+ new QPoint ((imgHeight -b )/a, imgHeight));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -219,15 +213,15 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
return std::make_pair (new QPoint (0, b),
|
|
|
- new QPoint (img->width(), a*img->width ()+b));
|
|
|
+ new QPoint (imgWidth, a*imgWidth+b));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else // a<0
|
|
|
{
|
|
|
- if((a*img->width()+b)>0)
|
|
|
+ if((a*imgWidth+b)>0)
|
|
|
{
|
|
|
- if(b > img->height())
|
|
|
+ if(b > imgHeight)
|
|
|
{
|
|
|
// |------------------------------------------|
|
|
|
// | |
|
|
@@ -241,8 +235,8 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// | * |
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
- return std::make_pair (new QPoint ((img->height()-b)/a, img->height()),
|
|
|
- new QPoint (img->width(), a*img->width()+b));
|
|
|
+ return std::make_pair (new QPoint ((imgHeight-b)/a, imgHeight),
|
|
|
+ new QPoint (imgWidth, a*imgWidth+b));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -259,13 +253,13 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
return std::make_pair (new QPoint (0, b),
|
|
|
- new QPoint (img->width (), a * img->width () + b));
|
|
|
+ new QPoint (imgWidth, a * imgWidth + b));
|
|
|
}
|
|
|
}
|
|
|
- else // a>0 and (a*img->width()+b) < 0
|
|
|
+ else // a>0 and (a*imgWidth+b) < 0
|
|
|
{
|
|
|
|
|
|
- if(b > img->height())
|
|
|
+ if(b > imgHeight)
|
|
|
{
|
|
|
// |------------------------------------------|
|
|
|
// | * |
|
|
@@ -280,7 +274,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
// |------------------------------------------|
|
|
|
|
|
|
return std::make_pair (new QPoint (-1*(b/a), 0),
|
|
|
- new QPoint ((img->height()-b)/a, img->height ()));
|
|
|
+ new QPoint ((imgHeight-b)/a, imgHeight));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -306,11 +300,31 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (QImage * img) c
|
|
|
new QPoint (*p2));
|
|
|
}
|
|
|
|
|
|
-double StrengthLine::distance(const StrengthLine *sl) const
|
|
|
+double StrengthLine::ea_score(const StrengthLine *sl, double imgWidth, double imgHeight) const
|
|
|
+{
|
|
|
+ return this->distance(sl, imgWidth, imgHeight);
|
|
|
+}
|
|
|
+
|
|
|
+double StrengthLine::distance(const StrengthLine *sl, double imgWidth, double imgHeight) const
|
|
|
{
|
|
|
std::srand(static_cast<unsigned int>(std::time(nullptr)+std::rand()));
|
|
|
+ std::pair < QPoint*, QPoint* > pointsSL1 = this->interpolateToEdge (imgWidth, imgHeight);
|
|
|
+ std::pair < QPoint*, QPoint* > pointsSL2 = sl->interpolateToEdge (imgWidth, imgHeight);
|
|
|
+ QPoint* p1SL1 = std::get < 0 > (pointsSL1);
|
|
|
+ QPoint* p2SL1 = std::get < 1 > (pointsSL1);
|
|
|
+ QPoint* p1SL2 = std::get < 0 > (pointsSL2);
|
|
|
+ QPoint* p2SL2 = std::get < 1 > (pointsSL2);
|
|
|
+
|
|
|
+
|
|
|
+ float midSL1X = ((p1SL1->x() + p2SL1->x())/2.0)/(imgWidth*1.0);
|
|
|
+ float midSL1Y = ((p1SL1->y() + p2SL1->y())/2.0)/(imgHeight*1.0);
|
|
|
+ float midSL2X = ((p1SL2->x() + p2SL2->x())/2.0)/(imgWidth*1.0);
|
|
|
+ float midSL2Y = ((p1SL2->y() + p2SL2->y())/2.0)/(imgHeight*1.0);
|
|
|
+
|
|
|
+
|
|
|
+ return sqrt(((midSL1X-midSL2X)*(midSL1X-midSL2X))+((midSL1Y-midSL2Y)*(midSL1Y-midSL2Y)));
|
|
|
|
|
|
- return std::rand();
|
|
|
+ //return std::rand();
|
|
|
}
|
|
|
|
|
|
StrengthLine* StrengthLine::getRandomLine (QImage * img)
|