From 93fcba52abde7029b20eb4b15ac8a872632cfec8 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Tue, 14 May 2019 17:59:07 +0200
Subject: [PATCH] ENH: add condition to avoid creating new objects

---
 .../include/otbWrapperInputImageParameter.hxx      | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.hxx b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.hxx
index 37ffbd7efa..5423a5ccba 100644
--- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.hxx
+++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.hxx
@@ -158,6 +158,20 @@ InputImageParameter::GetImage()
       {
       return nullptr;
       }
+    // Check if the image type asked here is the same as m_image
+    else if ( dynamic_cast < TImageType* > ( m_Image.GetPointer() ) )
+      {
+      return dynamic_cast < TImageType* > ( m_Image.GetPointer() );
+      }
+    // check if we already done this cast
+    else if ( dynamic_cast < 
+      ClampImageFilter < DoubleVectorImageType , TImageType >* >
+      ( m_OutputCaster.GetPointer() ) )
+      {
+      return dynamic_cast < 
+      ClampImageFilter < DoubleVectorImageType , TImageType >* >
+        ( m_OutputCaster.GetPointer() )->GetOutput();
+      }
     else
       CLAMP_IMAGE_BASE( TImageType, m_Image.GetPointer() );
     }
-- 
GitLab