From 3d8ddf164889cda62a0a2d427390ce3b2d24fa42 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Mon, 19 Feb 2018 09:07:58 +0100
Subject: [PATCH] Merge branch '1516--memory-print-image-list' into
 'release-6.4'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Resolve "PipelineMemoryPrintEstimator stops at ImageList"

See merge request orfeotoolbox/otb!9

(cherry picked from commit 51bbe2d9c546efbea69f4939359995b393d3e199)

0d1911c0 BUG: Track down upstream pipeline for each image in ImageList (fix #1516)
c47e4540 COMP: Fix compilation error (prototype mismatch)
3e227125 BUG: Moving PropageRequestedRegion() at the correct place in ImageList, and…
14c23e6b BUG: Only call UpdateOutputData() if object has Source
---
 .../Core/ObjectList/include/otbImageList.h    |  2 +
 .../Core/ObjectList/include/otbImageList.txx  | 44 ++++++++++++++-----
 .../otbPipelineMemoryPrintCalculator.h        |  2 +-
 .../src/otbPipelineMemoryPrintCalculator.cxx  | 16 ++++---
 4 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/Modules/Core/ObjectList/include/otbImageList.h b/Modules/Core/ObjectList/include/otbImageList.h
index 611d84a47a..4cb77bddec 100644
--- a/Modules/Core/ObjectList/include/otbImageList.h
+++ b/Modules/Core/ObjectList/include/otbImageList.h
@@ -68,6 +68,8 @@ public:
     throw (itk::InvalidRequestedRegionError) ITK_OVERRIDE;
   void UpdateOutputData(void) ITK_OVERRIDE;
 
+  void SetRequestedRegion(const itk::DataObject * source);
+  
 protected:
   /** Constructor */
   ImageList() {};
diff --git a/Modules/Core/ObjectList/include/otbImageList.txx b/Modules/Core/ObjectList/include/otbImageList.txx
index dc0cbc9b6f..426a594027 100644
--- a/Modules/Core/ObjectList/include/otbImageList.txx
+++ b/Modules/Core/ObjectList/include/otbImageList.txx
@@ -39,10 +39,33 @@ ImageList<TImage>
         || it.Get()->GetDataReleased()
         || it.Get()->RequestedRegionIsOutsideOfTheBufferedRegion())
       {
+      if(it.Get()->GetSource())
+        {
+        it.Get()->GetSource()->UpdateOutputData(it.Get());
+        }
+      }
+    }
+}
+
+template <class TImage>
+void
+ImageList<TImage>
+::PropagateRequestedRegion() throw (itk::InvalidRequestedRegionError)
+  {
+  Superclass::PropagateRequestedRegion();
+
+  for (ConstIterator it = this->Begin(); it != this->End(); ++it)
+    {
+    if (it.Get()->GetUpdateMTime() < it.Get()->GetPipelineMTime()
+        || it.Get()->GetDataReleased()
+        || it.Get()->RequestedRegionIsOutsideOfTheBufferedRegion())
+      {
+
+      std::cout<<"Requested region: "<<it.Get()<<" "<<it.Get()->GetRequestedRegion()<<std::endl;
       if (it.Get()->GetSource())
         {
         it.Get()->GetSource()->PropagateRequestedRegion(it.Get());
-
+        
         // Check that the requested region lies within the largest possible region
         if (!it.Get()->VerifyRequestedRegion())
           {
@@ -51,23 +74,24 @@ ImageList<TImage>
           e.SetLocation(ITK_LOCATION);
           e.SetDataObject(it.Get());
           e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
-
+          
           throw e;
           }
-
-        it.Get()->GetSource()->UpdateOutputData(it.Get());
         }
       }
     }
-}
+  }
 
-template <class TImage>
+template<class TImage>
 void
 ImageList<TImage>
-::PropagateRequestedRegion() throw (itk::InvalidRequestedRegionError)
-  {
-  Superclass::PropagateRequestedRegion();
-  }
+::SetRequestedRegion(const itk::DataObject * source)
+{
+  for (ConstIterator it = this->Begin(); it != this->End(); ++it)
+    {
+    it.Get()->SetRequestedRegion(source);
+    }
+}
 
 template <class TImage>
 void
diff --git a/Modules/Core/Streaming/include/otbPipelineMemoryPrintCalculator.h b/Modules/Core/Streaming/include/otbPipelineMemoryPrintCalculator.h
index 826478711d..41fe7808e9 100644
--- a/Modules/Core/Streaming/include/otbPipelineMemoryPrintCalculator.h
+++ b/Modules/Core/Streaming/include/otbPipelineMemoryPrintCalculator.h
@@ -121,7 +121,7 @@ public:
   static const double MegabyteToByte;
 
   /** Evaluate the print (in bytes) of a single data object */
-  MemoryPrintType EvaluateDataObjectPrint(DataObjectType * data) const;
+  MemoryPrintType EvaluateDataObjectPrint(DataObjectType * data);
 
 protected:
   /** Constructor */
diff --git a/Modules/Core/Streaming/src/otbPipelineMemoryPrintCalculator.cxx b/Modules/Core/Streaming/src/otbPipelineMemoryPrintCalculator.cxx
index 033c58bc37..d7d62e8c88 100644
--- a/Modules/Core/Streaming/src/otbPipelineMemoryPrintCalculator.cxx
+++ b/Modules/Core/Streaming/src/otbPipelineMemoryPrintCalculator.cxx
@@ -162,7 +162,7 @@ PipelineMemoryPrintCalculator
 
 PipelineMemoryPrintCalculator::MemoryPrintType
 PipelineMemoryPrintCalculator
-::EvaluateDataObjectPrint(DataObjectType * data) const
+::EvaluateDataObjectPrint(DataObjectType * data)
 {
   otbMsgDevMacro(<< "EvaluateMemoryPrint for " << data->GetNameOfClass() << " (" << data << ")")
 
@@ -183,11 +183,13 @@ PipelineMemoryPrintCalculator
     {                                                                   \
     ImageList<Image<type, 2> > * imageList = dynamic_cast<otb::ImageList<otb::Image<type, 2> > *>(data); \
     MemoryPrintType print(0);                                         \
-    for(ImageList<Image<type, 2> >::ConstIterator it = imageList->Begin(); \
+    for(ImageList<Image<type, 2> >::Iterator it = imageList->Begin(); \
        it != imageList->End(); ++it)                                    \
        {                                                             \
-       print += it.Get()->GetRequestedRegion().GetNumberOfPixels()   \
-       * it.Get()->GetNumberOfComponentsPerPixel() * sizeof(type); \
+       if(it.Get()->GetSource())                                        \
+         print += this->EvaluateProcessObjectPrintRecursive(it.Get()->GetSource());\
+       else                                                             \
+         print += this->EvaluateDataObjectPrint(it.Get());              \
        }                                                           \
     return print;                                                  \
     }                                                              \
@@ -198,8 +200,10 @@ PipelineMemoryPrintCalculator
     for(ImageList<VectorImage<type, 2> >::ConstIterator it = imageList->Begin(); \
        it != imageList->End(); ++it)                                    \
        {                                                             \
-       print += it.Get()->GetRequestedRegion().GetNumberOfPixels()   \
-       * it.Get()->GetNumberOfComponentsPerPixel() * sizeof(type); \
+       if(it.Get()->GetSource())                                        \
+         print += this->EvaluateProcessObjectPrintRecursive(it.Get()->GetSource());\
+       else                                                             \
+         print += this->EvaluateDataObjectPrint(it.Get());              \
        }                                                           \
     return print;                                                  \
     }                                                              \
-- 
GitLab