From 7de885e176a04ad1ac1f800d36a80e6fa21ae7e6 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Wed, 11 Jun 2014 10:48:09 +0200
Subject: [PATCH] BUG: Fixing bug #943

---
 Code/Learning/otbListSampleGenerator.h   |  4 +++-
 Code/Learning/otbListSampleGenerator.txx | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/Code/Learning/otbListSampleGenerator.h b/Code/Learning/otbListSampleGenerator.h
index 62a16aef81..bebfea70ee 100644
--- a/Code/Learning/otbListSampleGenerator.h
+++ b/Code/Learning/otbListSampleGenerator.h
@@ -145,7 +145,9 @@ protected:
   void PrintSelf(std::ostream& os, itk::Indent indent) const;
 
   /** Triggers the Computation of the sample list */
-  void GenerateData(void);
+  virtual void GenerateData(void);
+
+  virtual void GenerateInputRequestedRegion(void);
 
   /** Compute the calss statistics*/
   void GenerateClassStatistics();
diff --git a/Code/Learning/otbListSampleGenerator.txx b/Code/Learning/otbListSampleGenerator.txx
index 5351fe16f4..c1a7ea684d 100644
--- a/Code/Learning/otbListSampleGenerator.txx
+++ b/Code/Learning/otbListSampleGenerator.txx
@@ -188,6 +188,27 @@ ListSampleGenerator<TImage, TVectorData>
   return dynamic_cast<ListLabelType*>(this->itk::ProcessObject::GetOutput(3));
 }
 
+template <class TImage, class TVectorData>
+void
+ListSampleGenerator<TImage, TVectorData>
+::GenerateInputRequestedRegion()
+{
+  ImagePointerType img = static_cast<ImageType *>(this->ProcessObject::GetInput(0));
+
+  if(img.IsNotNull())
+    {
+
+    // Requested regions will be generated during GenerateData
+    // call. For now request an empty region so as to avoid requesting
+    // the largest possible region (fixes bug #943 )
+    typename ImageType::RegionType dummyRegion;
+    typename ImageType::SizeType dummySize;
+    dummySize.Fill(0);
+    dummyRegion.SetSize(dummySize);
+    img->SetRequestedRegion(dummyRegion);
+    }
+}
+
 
 template <class TImage, class TVectorData>
 void
-- 
GitLab