From 0d1911c0b40b28d84190fb92a357a8d5227741b6 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Tue, 13 Feb 2018 08:47:46 +0000
Subject: [PATCH] BUG: Track down upstream pipeline for each image in ImageList
 (fix #1516)

---
 .../include/otbPipelineMemoryPrintCalculator.h  |  2 +-
 .../src/otbPipelineMemoryPrintCalculator.cxx    | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

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..424d1ccd3a 100644
--- a/Modules/Core/Streaming/src/otbPipelineMemoryPrintCalculator.cxx
+++ b/Modules/Core/Streaming/src/otbPipelineMemoryPrintCalculator.cxx
@@ -183,11 +183,16 @@ 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())                                        \
+         {                                                              \
+         it.Get()->PropagateRequestedRegion();                                   \
+         print += this->EvaluateProcessObjectPrintRecursive(it.Get()->GetSource());\
+         }                                                              \
+else                                                                    \
+         print += this->EvaluateDataObjectPrint(it.Get());              \
        }                                                           \
     return print;                                                  \
     }                                                              \
@@ -198,8 +203,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