浏览代码

Fin du soft pour comparer deux lignes

Rémi Synave 10 月之前
父节点
当前提交
a327cff0e1
共有 3 个文件被更改,包括 30 次插入12 次删除
  1. 28 9
      StrengthLine/StrengthLine.cpp
  2. 1 2
      StrengthLine/StrengthLine.hpp
  3. 1 1
      clf/WorkArea.cpp

+ 28 - 9
StrengthLine/StrengthLine.cpp

@@ -300,12 +300,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (int imgWidth, i
 			 new QPoint (*p2));
 }
 
-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
+float StrengthLine::ea_score(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);
@@ -315,16 +310,40 @@ double StrengthLine::distance(const StrengthLine *sl, double imgWidth, double im
   QPoint* p1SL2 = std::get < 0 > (pointsSL2);
   QPoint* p2SL2 = std::get < 1 > (pointsSL2);
 
+  float u[2] = {p2SL1->x()-p1SL1->x(), p2SL1->y()-p1SL1->y()};
+  float v[2] = {p2SL2->x()-p1SL2->x(), p2SL2->y()-p1SL2->y()};
+  float normU = sqrt(u[0]*u[0]+u[1]*u[1]);
+  float normV = sqrt(v[0]*v[0]+v[1]*v[1]);
+  u[0]=u[0]/normU;
+  u[1]=u[1]/normU;
+  v[0]=v[0]/normV;
+  v[1]=v[1]/normV;
+  float angle = 0;
+  
+  if((u[0]!=v[0]) || (u[1]!=v[1]))
+    {
+      float prodScal=u[0]*v[0]+u[1]*v[1];
+	
+      // In case of number approximation...
+      if(prodScal>1)
+	prodScal=1;
+      if(prodScal<-1)
+	prodScal=-1;
+	     			     
+      angle = acos(prodScal);
+    }
+
+  float sT = 1 - (angle/(M_PI/2));
 
   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);
 
+  float sd = 1 - sqrt(((midSL1X-midSL2X)*(midSL1X-midSL2X))+((midSL1Y-midSL2Y)*(midSL1Y-midSL2Y)));
 
-  return sqrt(((midSL1X-midSL2X)*(midSL1X-midSL2X))+((midSL1Y-midSL2Y)*(midSL1Y-midSL2Y)));
-  
-  //return std::rand();
+
+  return ((sT*sd)*(sT*sd));
 }
 
 StrengthLine* StrengthLine::getRandomLine (QImage * img)

+ 1 - 2
StrengthLine/StrengthLine.hpp

@@ -47,8 +47,7 @@ public:
   std::pair < QPoint *, QPoint * > toDraw (int imgWidth, int imgHeight) const;
   std::pair < QPoint *, QPoint * > interpolateToEdge (QImage * img) const;
   std::pair < QPoint *, QPoint * > interpolateToEdge (int imgWidth, int imgHeight) const;
-  double ea_score(const StrengthLine *sl, double imgWidth, double imgHeight) const;
-  double distance(const StrengthLine *sl, double imgWidth, double imgHeight) const;
+  float ea_score(const StrengthLine *sl, double imgWidth, double imgHeight) const;
 
   static StrengthLine* getRandomLine (QImage * img);
   static StrengthLine* getRandomLine (int width, int height);

+ 1 - 1
clf/WorkArea.cpp

@@ -147,5 +147,5 @@ WorkArea::getDistance() const
 {
   StrengthLine *sl1 = new StrengthLine(liste_points[0], liste_points[1]);
   StrengthLine *sl2 = new StrengthLine(liste_points[2], liste_points[3]);
-  return sl1->distance(sl2, screenSizeX, screenSizeY);
+  return sl1->ea_score(sl2, screenSizeX, screenSizeY);
 }