From f055c40920102780af252ab573efe81843ebb2e6 Mon Sep 17 00:00:00 2001
From: even <philippe.even@loria.fr>
Date: Fri, 9 Nov 2018 20:43:43 +0100
Subject: [PATCH] BS inspection window update

---
 Code/Seg/BSTools/bsaccumulatoritem.cpp |  3 +-
 Code/Seg/BSTools/bsdetectionwidget.cpp | 43 +++++++++++++++++++-------
 Code/Seg/BSTools/bsstructureitem.cpp   | 14 +++++++--
 Code/Seg/BSTools/bsstructureitem.h     |  7 +++++
 Code/Seg/BSTools/bsstructureview.cpp   | 27 ++++++++++------
 Code/Seg/BSTools/bsstructureview.h     |  5 +++
 Code/Seg/BlurredSegment/bsdetector.cpp | 11 +++++++
 Code/Seg/BlurredSegment/bsdetector.h   |  5 +++
 8 files changed, 91 insertions(+), 24 deletions(-)

diff --git a/Code/Seg/BSTools/bsaccumulatoritem.cpp b/Code/Seg/BSTools/bsaccumulatoritem.cpp
index 3ecf8c0..3d834ac 100755
--- a/Code/Seg/BSTools/bsaccumulatoritem.cpp
+++ b/Code/Seg/BSTools/bsaccumulatoritem.cpp
@@ -53,7 +53,8 @@ void BSAccumulatorItem::paint (QPainter *painter,
   Q_UNUSED (option);
   Q_UNUSED (widget);
 
-  if (! detector->isFiltering (selaccu))
+  if (! (detector->getBlurredSegments(1).empty ()
+         && detector->isFiltering (selaccu)))
   {
     painter->fillRect (0, 0, width, height, QBrush (Qt::black));
     return;
diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp
index 82e379a..c1af1a6 100755
--- a/Code/Seg/BSTools/bsdetectionwidget.cpp
+++ b/Code/Seg/BSTools/bsdetectionwidget.cpp
@@ -549,7 +549,11 @@ void BSDetectionWidget::extract ()
   drawLine (p1, p2, Qt::red, painter);
 
   if (detector.isMultiSelection ()) detector.multidetect (p1, p2);
-  else detector.detect (p1, p2);
+  else
+  {
+    detector.freeMultiSelection ();
+    detector.detect (p1, p2);
+  }
 
   // Update auxiliary view if not dragging
   if (fixed)
@@ -560,7 +564,11 @@ void BSDetectionWidget::extract ()
       profileview->scene()->update ();
     }
     if (accuview != NULL) accuview->scene()->update ();
-    if (strucview != NULL) strucview->scene()->update ();
+    if (strucview != NULL)
+    {
+      strucview->setExamined (-1);
+      strucview->scene()->update ();
+    }
   }
 
   if (detector.isMultiSelection ())
@@ -609,18 +617,22 @@ void BSDetectionWidget::extractAll ()
 
   detector.detectAll ();
 
-  // Update auxiliary view if not dragging
-  if (fixed)
+  // Update auxiliary view
+  if (profileview != NULL)
   {
-    if (profileview != NULL)
-    {
-      profileview->buildScans (p1, p2);
-      profileview->scene()->update ();
-    }
-    if (accuview != NULL) accuview->scene()->update ();
-    if (strucview != NULL) strucview->scene()->update ();
+    profileview->buildScans (p1, p2);
+    profileview->scene()->update ();
+  }
+  if (accuview != NULL) accuview->scene()->update ();
+  if (strucview != NULL)
+  {
+    strucview->setExamined (-1);
+    strucview->scene()->update ();
   }
 
+  // Update auxiliary view
+  if (strucview != NULL) strucview->scene()->update ();
+
   vector<BlurredSegment *> mbs = detector.getBlurredSegments (1);
   cout << mbs.size () << " blurred segments detected" << endl;
   vector<BlurredSegment *>::iterator it = mbs.begin ();
@@ -660,8 +672,15 @@ void BSDetectionWidget::displayNext (int dir)
 
   augmentedImage = loadedImage;
   QPainter painter (&augmentedImage);
-
   exam = (exam + dir) % ((int) (mbs.size ()));
+
+  // Update auxiliary view
+  if (strucview != NULL)
+  {
+    strucview->setExamined (exam);
+    strucview->scene()->update ();
+  }
+
   vector<BlurredSegment *>::iterator it = mbs.begin ();
   QColor bsCol = Qt::blue;
   int index = 0;
diff --git a/Code/Seg/BSTools/bsstructureitem.cpp b/Code/Seg/BSTools/bsstructureitem.cpp
index c4cf294..8677a38 100755
--- a/Code/Seg/BSTools/bsstructureitem.cpp
+++ b/Code/Seg/BSTools/bsstructureitem.cpp
@@ -109,7 +109,11 @@ void BSStructureItem::paint(QPainter *painter,
 
 void BSStructureItem::paintBlurredSegment (QPainter *painter, int step)
 {
-  BlurredSegment *bs = det->getBlurredSegment (step);
+  BlurredSegment *bs = NULL;
+  vector<BlurredSegment *> mbs = det->getBlurredSegments (step);
+  if (mbs.empty ()) bs = det->getBlurredSegment (step);
+  else if (exam != -1) bs = mbs[exam];
+    
   if (bs != NULL)
   {
     DigitalStraightSegment *dss = bs->getSegment ();
@@ -156,7 +160,11 @@ void BSStructureItem::paintBlurredSegment (QPainter *painter, int step)
 
 void BSStructureItem::paintConnectedComponents (QPainter *painter, int step)
 {
-  BlurredSegment *bs = det->getBlurredSegment (step);
+  BlurredSegment *bs = NULL;
+  vector<BlurredSegment *> mbs = det->getBlurredSegments (step);
+  if (mbs.empty ()) bs = det->getBlurredSegment (step);
+  else if (exam != -1) bs = mbs[exam];
+    
   if (bs != NULL)
   {
     QColor cols[] = {Qt::blue, Qt::red, Qt::green};
@@ -204,6 +212,8 @@ void BSStructureItem::paintConnectedComponents (QPainter *painter, int step)
 
 void BSStructureItem::paintScansAndFilter (QPainter *painter, int step)
 {
+  if (! (det->getBlurredSegments(step).empty ())) return;
+    
   if (det->scanRecordOn (step))
   {
     if (displayScanLines)
diff --git a/Code/Seg/BSTools/bsstructureitem.h b/Code/Seg/BSTools/bsstructureitem.h
index d8ea16f..73d19c0 100755
--- a/Code/Seg/BSTools/bsstructureitem.h
+++ b/Code/Seg/BSTools/bsstructureitem.h
@@ -70,6 +70,11 @@ public:
    */
   inline void switchScanDisplay () { displayScanLines = ! displayScanLines; }
 
+  /**
+   * Sets the examined segment from a multi-selection.
+   */
+  inline void setExamined (int index) { exam = index; }
+
   /**
    * \brief Returns the displayed information title.
    */
@@ -153,6 +158,8 @@ private:
   QPen infoPen;
   /** Information text vertical offset. */
   int textOffset;
+  /** Index of the examined segment in the multi-selection. */
+  int exam;
 
 
   /**
diff --git a/Code/Seg/BSTools/bsstructureview.cpp b/Code/Seg/BSTools/bsstructureview.cpp
index d43e081..6c5396c 100755
--- a/Code/Seg/BSTools/bsstructureview.cpp
+++ b/Code/Seg/BSTools/bsstructureview.cpp
@@ -106,64 +106,73 @@ bool BSStructureView::processKeyEvent (QKeyEvent *event)
       if (event->modifiers () & Qt::ControlModifier) grid->switchScanDisplay ();
       else grid->toggleDisplay ((event->modifiers () & Qt::ShiftModifier) == 0);
       setWindowTitle (grid->itemTitle ());
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_V : // Info display
       grid->switchInfoDisplay ();
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_B : // Background
       if (event->modifiers () & Qt::ShiftModifier) toggleGradient ();
       else toggleBackground ();
       updateBackground (true);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_Plus : // Zoom in
       grid->zoomIn ();
       updateBackground (true);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_Minus : // Zoom out
       grid->zoomOut ();
       updateBackground (true);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_Left : // Go leftwards
       grid->shift (-1, 0);
       updateBackground (false);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_Right : // Go rightwards
       grid->shift (1, 0);
       updateBackground (false);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_Up : // Go upwards
       grid->shift (0, -1);
       updateBackground (false);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_Down : // Go downwards
       grid->shift (0, 1);
       updateBackground (false);
+      scene()->update ();
       update ();
-      processed = true;
+      processed = false;
       break;
 
     case Qt::Key_C : // Increments the connected components min size
diff --git a/Code/Seg/BSTools/bsstructureview.h b/Code/Seg/BSTools/bsstructureview.h
index 6f6dce8..2c905a0 100755
--- a/Code/Seg/BSTools/bsstructureview.h
+++ b/Code/Seg/BSTools/bsstructureview.h
@@ -26,6 +26,11 @@ public:
    */
   void setGradientImage (VMap *gMap);
 
+  /**
+   * Sets the examined segment from a multi-selection.
+   */
+  inline void setExamined (int index) { grid->setExamined (index); }
+
   /**
    * Toggles the window background between the current image or plain white.
    */
diff --git a/Code/Seg/BlurredSegment/bsdetector.cpp b/Code/Seg/BlurredSegment/bsdetector.cpp
index ffd2fe2..efa1ae6 100755
--- a/Code/Seg/BlurredSegment/bsdetector.cpp
+++ b/Code/Seg/BlurredSegment/bsdetector.cpp
@@ -71,6 +71,17 @@ void BSDetector::setGradientMap (VMap *data)
 }
 
 
+void BSDetector::freeMultiSelection ()
+{
+  vector<BlurredSegment *>::iterator it = mbsini.begin ();
+  while (it != mbsini.end ()) delete (*it++);
+  mbsini.clear ();
+  it = mbsf.begin ();
+  while (it != mbsf.end ()) delete (*it++);
+  mbsf.clear ();
+}
+
+
 void BSDetector::detectAll ()
 {
   // Deletes former blurred segments
diff --git a/Code/Seg/BlurredSegment/bsdetector.h b/Code/Seg/BlurredSegment/bsdetector.h
index f0ec3c8..468d5d1 100755
--- a/Code/Seg/BlurredSegment/bsdetector.h
+++ b/Code/Seg/BlurredSegment/bsdetector.h
@@ -101,6 +101,11 @@ public:
   inline vector<BlurredSegment *> getBlurredSegments (int step) {
     return (step == 0 ? mbsini : mbsf); }
 
+  /**
+   * \brief Resets the multi-selection list.
+   */
+  void freeMultiSelection ();
+
   /**
    * \brief Avoids the deletion of the last extracted blurred segent.
    */
-- 
GitLab