From 0b89b60c7a47d4f740ea68a285a8a9179f1755a5 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Fri, 23 Feb 2018 15:52:55 +0100
Subject: [PATCH] ENH: adding an ugly objectlistinterface class and method...

---
 .../Core/ObjectList/include/otbObjectList.h   |  8 +++-
 .../Core/ObjectList/include/otbObjectList.txx | 10 +++++
 .../include/otbObjectListInterface.h          | 45 +++++++++++++++++++
 .../src/otbWrapperApplication.cxx             | 14 ++++++
 4 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 Modules/Core/ObjectList/include/otbObjectListInterface.h

diff --git a/Modules/Core/ObjectList/include/otbObjectList.h b/Modules/Core/ObjectList/include/otbObjectList.h
index b9db494bec..dcd1182b56 100644
--- a/Modules/Core/ObjectList/include/otbObjectList.h
+++ b/Modules/Core/ObjectList/include/otbObjectList.h
@@ -23,6 +23,7 @@
 
 #include <vector>
 #include "itkDataObject.h"
+#include "otbObjectListInterface.h"
 #include "itkObjectFactory.h"
 
 namespace otb
@@ -36,7 +37,7 @@ namespace otb
  * \ingroup OTBObjectList
  */
 template <class TObject>
-class ITK_EXPORT ObjectList : public itk::DataObject
+class ITK_EXPORT ObjectList : public itk::DataObject , public ObjectListInterface
 {
 public:
   /** Standard typedefs */
@@ -99,6 +100,11 @@ public:
    * \return The pointer to the nth element of the list.
    */
   ObjectPointerType GetNthElement(unsigned int index) const;
+  /**
+   * Get the nth element of the list as a DataObject *.
+   * \param index The index of the object to get.
+   */
+  Superclass *  GetNthDataObject(unsigned int index) const;
   /**
    * Return the first element of the list.
    * \return The first element of the list.
diff --git a/Modules/Core/ObjectList/include/otbObjectList.txx b/Modules/Core/ObjectList/include/otbObjectList.txx
index 26044b1432..121dfd90b0 100644
--- a/Modules/Core/ObjectList/include/otbObjectList.txx
+++ b/Modules/Core/ObjectList/include/otbObjectList.txx
@@ -162,6 +162,16 @@ ObjectList<TObject>
     }
   return m_InternalContainer[index];
 }
+
+template <class TObject>
+typename ObjectList<TObject>::Superclass *
+ObjectList<TObject>
+::GetNthDataObject(unsigned int index) const
+{
+  ObjectType * object = GetNthElement(index).GetPointer();
+  return dynamic_cast< Superclass * > ( object );
+}
+
 /**
    * Return the first element of the list.
    * \return The first element of the list.
diff --git a/Modules/Core/ObjectList/include/otbObjectListInterface.h b/Modules/Core/ObjectList/include/otbObjectListInterface.h
new file mode 100644
index 0000000000..a99df955c6
--- /dev/null
+++ b/Modules/Core/ObjectList/include/otbObjectListInterface.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
+ *
+ * This file is part of Orfeo Toolbox
+ *
+ *     https://www.orfeo-toolbox.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef otbObjectListInterface_h
+#define otbObjectListInterface_h
+
+#include "itkDataObject.h"
+
+namespace otb
+{
+
+class ObjectListInterface
+{
+
+public:
+
+  ObjectListInterface() {};
+  virtual ~ObjectListInterface(){};
+
+  virtual itk::DataObject * GetNthDataObject(unsigned int index) const = 0;
+
+  virtual std::size_t Size(void) const = 0;
+
+};
+
+} // end of otb namespace
+
+#endif
diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
index e3458e9fab..dbf71f5647 100644
--- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
+++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx
@@ -449,6 +449,20 @@ Application::RegisterPipeline()
     if ( inputData.count( current ) || !current )
       continue;
     std::cout<<"it is not an input"<<std::endl;
+    if ( dynamic_cast< ObjectListInterface *> (current) )
+      {
+      ObjectListInterface * list = 
+        dynamic_cast< ObjectListInterface *> (current);
+      int length = list->Size();
+      for ( int i = 0 ; i < length ; i++ )
+        {
+        itk::DataObject * newData = list->GetNthDataObject(i);
+        if ( inputData.count( current ) || !current )
+          continue;
+        dataStack.push( newData );
+        }
+      continue;
+      }
     itk::ProcessObject * process = (current->GetSource()).GetPointer();
     if ( m_Filters.find( process ) != m_Filters.end() || !process )
       continue;
-- 
GitLab