From ed09c02a4a8109b5fac8a9b46f0d4f9972951906 Mon Sep 17 00:00:00 2001
From: even <philippe.even@loria.fr>
Date: Tue, 18 Dec 2018 15:25:34 +0100
Subject: [PATCH] Article: algoAuto debugged

---
 Article/Fig_method/algoAuto.tex        | 28 ++++++++--------
 Code/Seg/BlurredSegment/bsdetector.cpp | 45 ++++++++++++++++++++++++++
 Code/Seg/BlurredSegment/bsdetector.h   |  7 ++++
 3 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/Article/Fig_method/algoAuto.tex b/Article/Fig_method/algoAuto.tex
index bafd70f..8c25e21 100644
--- a/Article/Fig_method/algoAuto.tex
+++ b/Article/Fig_method/algoAuto.tex
@@ -24,21 +24,21 @@
   \BlankLine
   \bslist $\leftarrow$ \nullset\;
   \mask $\leftarrow$ \nullset\;
-  $i \leftarrow$ \resol/2\;
-  \Repeat{$i <$ \iwidth/2}{
-    \bslist $\leftarrow$ \bslist + \multi (\pt(\iwidth/2-i,\iheight),
-                                           \pt(\iwidth/2-i,0), \mask)\;
-    \bslist $\leftarrow$ \bslist + \multi (\pt(\iwidth/2+i,\iheight),
-                                           \pt(\iwidth/2+i,0), \mask)\;
-    $i \leftarrow i -$ \resol\;
+  $x \leftarrow$ \resol/2\;
+  \Repeat{$x <$ \iwidth/2}{
+    \bslist $\leftarrow$ \bslist + \multi (\pt(\iwidth/2-x,\iheight),
+                                           \pt(\iwidth/2-x,0), \mask)\;
+    \bslist $\leftarrow$ \bslist + \multi (\pt(\iwidth/2+x,\iheight),
+                                           \pt(\iwidth/2+x,0), \mask)\;
+    $x \leftarrow x~+$ \resol\;
   }
-  $i \leftarrow$ \resol/2\;
-  \Repeat{$i <$ \iheight/2}{
-    \bslist $\leftarrow$ \bslist + \multi (\pt(0,\iheight/2-i),
-                                           \pt(\iwidth,\iheight/2-i), \mask)\;
-    \bslist $\leftarrow$ \bslist + \multi (\pt(0,\iheight/2+i),
-                                           \pt(\iwidth,\iheight/2+i), \mask)\;
-    $i \leftarrow i -$ \resol\;
+  $y \leftarrow$ \resol/2\;
+  \Repeat{$y <$ \iheight/2}{
+    \bslist $\leftarrow$ \bslist + \multi (\pt(0,\iheight/2-y),
+                                           \pt(\iwidth,\iheight/2-y), \mask)\;
+    \bslist $\leftarrow$ \bslist + \multi (\pt(0,\iheight/2+y),
+                                           \pt(\iwidth,\iheight/2+y), \mask)\;
+    $y \leftarrow y~+$ \resol\;
   }
   
   \caption{AutoDetect: finds all blurred segments in the image.}
diff --git a/Code/Seg/BlurredSegment/bsdetector.cpp b/Code/Seg/BlurredSegment/bsdetector.cpp
index a31b1ff..5313898 100755
--- a/Code/Seg/BlurredSegment/bsdetector.cpp
+++ b/Code/Seg/BlurredSegment/bsdetector.cpp
@@ -115,6 +115,51 @@ void BSDetector::detectAll ()
 }
 
 
+void BSDetector::detectAllWithBalancedXY ()
+{
+  autodet = true;
+  freeMultiSelection ();
+  gMap->setMasking (true);
+
+  bool isnext = true;
+  nbtrials = 0;
+  int width = gMap->getWidth ();
+  int height = gMap->getHeight ();
+  int xg = width / 2, yb = height / 2;
+  int xd = xg + autoResol, yh = yb + autoResol;
+  bool agauche = true, enbas = true, adroite = true, enhaut = true;
+  while (isnext && (agauche || enbas || adroite || enhaut))
+  {
+    if (agauche)
+    {
+      isnext = runMultiDetection (Pt2i (xg, 0), Pt2i (xg, height - 1));
+      xg -= autoResol;
+      if (xg <= 0) agauche = false;
+    }
+    if (isnext && enbas)
+    {
+      isnext = runMultiDetection (Pt2i (0, yb), Pt2i (width - 1, yb));
+      yb -= autoResol;
+      if (yb <= 0) enbas = false;
+    }
+    if (isnext && adroite)
+    {
+      isnext = runMultiDetection (Pt2i (xd, 0), Pt2i (xd, height - 1));
+      xd += autoResol;
+      if (xd >= width - 1) adroite = false;
+    }
+    if (isnext && enhaut)
+    {
+      isnext = runMultiDetection (Pt2i (0, yh), Pt2i (width - 1, yh));
+      yh += autoResol;
+      if (yh >= height - 1) enhaut = false;
+    }
+  }
+  gMap->clearMask ();
+  gMap->setMasking (false);
+}
+
+
 void BSDetector::detectSelection (const Pt2i &p1, const Pt2i &p2)
 {
   autodet = false;
diff --git a/Code/Seg/BlurredSegment/bsdetector.h b/Code/Seg/BlurredSegment/bsdetector.h
index 8784144..8944d97 100755
--- a/Code/Seg/BlurredSegment/bsdetector.h
+++ b/Code/Seg/BlurredSegment/bsdetector.h
@@ -74,9 +74,16 @@ public:
 
   /**
    * \brief Detects all blurred segments in the picture.
+   * Parses X direction first, the Y direction.
    */
   void detectAll ();
 
+  /**
+   * \brief Detects all blurred segments in the picture.
+   * Parses simultaneously the X and Y directions.
+   */
+  void detectAllWithBalancedXY ();
+
   /**
    * \brief Detects blurred segments between two input points.
    * @param p1 First input point.
-- 
GitLab