From 4c104780f6be8152bbe6090951bbbea456ebaa76 Mon Sep 17 00:00:00 2001
From: even <philippe.even@loria.fr>
Date: Sat, 24 Nov 2018 22:00:55 +0100
Subject: [PATCH] Tests restored and Scan lines standardized

---
 Code/Seg/BSTools/bsdetectionwidget.cpp | 15 ++---
 Code/Seg/ImageTools/pt2i.cpp           | 78 ++++++++++++++------------
 Methode/ctrl.tex                       |  5 +-
 3 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp
index 2392827..1997d42 100755
--- a/Code/Seg/BSTools/bsdetectionwidget.cpp
+++ b/Code/Seg/BSTools/bsdetectionwidget.cpp
@@ -988,8 +988,9 @@ void BSDetectionWidget::alternateTest ()
 
 void BSDetectionWidget::performanceTest ()
 {
-  if (detector.isMultiSelection ())
+  if (p1.equals (p2))
   {
+    // No stroke -> automatic
     cout << "Automatic extraction test" << endl;
     clock_t start = clock ();
     for (int i = 0; i < 100; i++) detector.detectAll ();
@@ -999,11 +1000,7 @@ void BSDetectionWidget::performanceTest ()
   }
   else
   {
-    if (p1.equals (p2))
-    {
-      cout << "Stroke undefined" << endl;
-      return;
-    }
+    udef = true;
     cout << "Run test" << endl;
     clock_t start = clock ();
     for (int i = 0; i < 1000; i++) detector.detect (p1, p2);
@@ -1018,11 +1015,7 @@ void BSDetectionWidget::localTest ()
 {
   cout << "Run test" << endl;
 
-/*
-  p1 = Pt2i (212, 169);
-  p2 = Pt2i (232, 152);
-*/
-
+  udef = true;
   p1 = Pt2i (175, 40);
   p2 = Pt2i (246, 79);
 
diff --git a/Code/Seg/ImageTools/pt2i.cpp b/Code/Seg/ImageTools/pt2i.cpp
index 2da3694..06fbb41 100755
--- a/Code/Seg/ImageTools/pt2i.cpp
+++ b/Code/Seg/ImageTools/pt2i.cpp
@@ -1,5 +1,5 @@
 #include "pt2i.h"
-#include <cmath>
+// #include <cmath>
 
 
 Pt2i::Pt2i ()
@@ -194,7 +194,7 @@ Pt2i *Pt2i::drawing (const Pt2i p, int *n) const
     {
       *n = dx + 1;
       pts = new Pt2i[dx + 1];
-      e = dx;
+      e = dx - 1; // car le point limite est trace en dessous de la droite
       dx *= 2;
       dy *= 2;
       while (x1 < x2)
@@ -216,7 +216,7 @@ Pt2i *Pt2i::drawing (const Pt2i p, int *n) const
     {
       *n = dy + 1;
       pts = new Pt2i[dy + 1];
-      e = dy;
+      e = dy; // car le point limite est trace a droite de la droite
       dx *= 2;
       dy *= 2;
       while (y1 < y2)
@@ -241,7 +241,7 @@ Pt2i *Pt2i::drawing (const Pt2i p, int *n) const
     {
       *n = 1 + dx;
       pts = new Pt2i[dx + 1];
-      e = dx;
+      e = dx - 1; // car le point limite est trace en dessous de la droite
       dx *= 2;
       dy *= 2;
       while (x1 < x2)
@@ -263,18 +263,18 @@ Pt2i *Pt2i::drawing (const Pt2i p, int *n) const
     {
       *n = 1 - dy;
       pts = new Pt2i[1 - dy];
-      e = dy;
+      e = - dy; // car le point limite est trace a gauche de la droite
       dx *= 2;
       dy *= 2;
       while (y1 > y2)
       {
         pts[i++] = Pt2i (x1, y1);
         y1 --;
-        e += dx;
-        if (e > 0)
+        e -= dx;
+        if (e < 0)
         {
           x1 ++;
-          e += dy;
+          e -= dy;
         }
       }
       pts[i] = Pt2i (x1, y1);
@@ -310,7 +310,7 @@ void Pt2i::draw (vector<Pt2i> &line, Pt2i p) const
     // Octant 1
     if (dx >= dy)
     {
-      e = dx;
+      e = dx - 1; // car le point limite est trace en dessous de la droite
       dx *= 2;
       dy *= 2;
       while (x1 < x2)
@@ -330,7 +330,7 @@ void Pt2i::draw (vector<Pt2i> &line, Pt2i p) const
     // Octant 2
     else
     {
-      e = dy;
+      e = dy; // car le point limite est trace a droite de la droite
       dx *= 2;
       dy *= 2;
       while (y1 < y2)
@@ -353,7 +353,7 @@ void Pt2i::draw (vector<Pt2i> &line, Pt2i p) const
     // Octant 8
     if (dx >= -dy)
     {
-      e = dx;
+      e = dx - 1; // car le point limite est trace en dessous de la droite
       dx *= 2;
       dy *= 2;
       while (x1 < x2)
@@ -373,18 +373,18 @@ void Pt2i::draw (vector<Pt2i> &line, Pt2i p) const
     // Octant 7
     else
     {
-      e = dy;
+      e = - dy; // car le point limite est trace a gauche de la droite
       dx *= 2;
       dy *= 2;
       while (y1 > y2)
       {
         line.push_back (Pt2i (x1, y1));
         y1 --;
-        e += dx;
-        if (e > 0)
+        e -= dx;
+        if (e < 0)
         {
           x1 ++;
-          e += dy;
+          e -= dy;
         }
       }
       line.push_back (Pt2i (x1, y1));
@@ -424,7 +424,8 @@ Pt2i *Pt2i::pathTo (Pt2i p, int *n) const
     {
       *n = dx;
       pts = new Pt2i[dx];
-      e = dx;
+      e = dx - 1; // car le point limite est trace en dessous de la droite
+      if (delta < 0) e++; // .. au dessus
       dx *= 2;
       dy *= 2;
       while (x1 < x2)
@@ -446,7 +447,8 @@ Pt2i *Pt2i::pathTo (Pt2i p, int *n) const
     {
       *n = dy;
       pts = new Pt2i[dy];
-      e = dy;
+      e = dy; // car le point limite est trace a droite de la droite
+      if (delta < 0) e--; // .. a gauche
       dx *= 2;
       dy *= 2;
       while (y1 < y2)
@@ -471,7 +473,8 @@ Pt2i *Pt2i::pathTo (Pt2i p, int *n) const
     {
       *n = dx;
       pts = new Pt2i[dx];
-      e = dx;
+      e = dx - 1; // car le point limite est trace en dessous de la droite
+      if (delta < 0) e++; // .. au dessus
       dx *= 2;
       dy *= 2;
       while (x1 < x2)
@@ -490,19 +493,20 @@ Pt2i *Pt2i::pathTo (Pt2i p, int *n) const
     // Octant 7
     else
     {
-      *n = dy;
+      *n = -dy;
       pts = new Pt2i[-dy];
-      e = dy;
+      e = - dy; // car le point limite est trace a gauche de la droite
+      if (delta < 0) e--; // .. a droite
       dx *= 2;
       dy *= 2;
       while (y1 > y2)
       {
         y1 --;
-        e += dx;
-        if (e > 0)
+        e -= dx;
+        if (e < 0)
         {
           x1 ++;
-          e += dy;
+          e -= dy;
           pts[i++] = Pt2i (delta, -delta);
         }
         else pts[i++] = Pt2i (0, -delta);
@@ -515,33 +519,35 @@ Pt2i *Pt2i::pathTo (Pt2i p, int *n) const
 
 bool *Pt2i::stepsTo (Pt2i p, int *n) const
 {
+  bool negx = p.xp < xp;
+  bool negy = p.yp < yp;
   int x2 = (xp > p.xp) ? xp - p.xp : p.xp - xp;
   int y2 = (yp > p.yp) ? yp - p.yp : p.yp - yp;
-  int dx = x2, dy = y2;
+  int dx = x2, dy = y2, e = 0;
   if (y2 > x2)
   {
     dx = y2;
     dy = x2;
     x2 = y2;
+    if (negx == negy) e++;
   }
-  int e, x = 0, i = 0;
-  *n = x2;
-  bool *paliers = new bool[x2];
-
-  e = dx;
+  else if (negx != negy) e++;
+  e += dx - 1;
   dx *= 2;
   dy *= 2;
 
+  int x = 0;
+  *n = x2;
+  bool *paliers = new bool[x2];
   while (x < x2)
   {
-    x ++;
     e -= dy;
     if (e < 0)
     {
       e += dx;
-      paliers[i++] = true;
+      paliers[x++] = true;
     }
-    else paliers[i++] = false;
+    else paliers[x++] = false;
   }
   return (paliers); 
 }
@@ -571,7 +577,7 @@ vector<Pt2i> Pt2i::drawOrtho (const Pt2i p2, int offset) const
   {
     if (dx >= dy) // Octant 1
     {
-      e = dx;
+      e = dx - 1;
       dx = dx * 2;
       dy = dy * 2;
       if (offset < 0) floors = (steps * dy - e) / dx;
@@ -625,7 +631,7 @@ vector<Pt2i> Pt2i::drawOrtho (const Pt2i p2, int offset) const
   {
     if (dx >= -dy) // Octant 8
     {
-      e = dx;
+      e = dx - 1;
       dx = dx * 2;
       dy = dy * 2;
       if (offset < 0) floors = (e - 1 + steps * dy) / dx;
@@ -681,7 +687,7 @@ vector<Pt2i> Pt2i::drawOrtho (const Pt2i p2, int offset) const
   {
     if (-dx >= dy) // Octant 4
     {
-      e = dx;
+      e = dx - 1;
       dx = dx * 2;
       dy = dy * 2;
       if (offset < 0) floors = - (steps * dy + e) / dx;
@@ -735,7 +741,7 @@ vector<Pt2i> Pt2i::drawOrtho (const Pt2i p2, int offset) const
   {
     if (dx <= dy) // Octant 5
     {
-      e = dx;
+      e = dx - 1;
       dx = dx * 2;
       dy = dy * 2;
       if (offset < 0) floors = (steps * dy - e - 1) / dx;
diff --git a/Methode/ctrl.tex b/Methode/ctrl.tex
index fc34159..f50a6f3 100755
--- a/Methode/ctrl.tex
+++ b/Methode/ctrl.tex
@@ -7,7 +7,7 @@
 \headsep -1.5cm
 \oddsidemargin 0.5cm
 \evensidemargin 0.5cm
-\textheight 27.0cm
+\textheight 27.5cm
 \textwidth 15.0cm
 \footskip 1.5cm
 \parindent 0.0cm
@@ -85,6 +85,9 @@ w && Largeur de correlation \\
 t && Epaisseur de correlation \\
 r && Taux de correlation \\
 $\wedge \vee$ && Parcours des bandes \\
+\hline \hline
+\multicolumn{3}{|l|}{Analyse de la d\'etection initiale :} \\
+$< \wedge > \vee$ && D\'ecalage de l'observation \\
 \hline
 \end{tabular}
 
-- 
GitLab