From ca5c1b8ef41161704fbdafa12032f84a53bcf49d Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Mon, 8 Aug 2011 12:01:36 +0200 Subject: [PATCH] ADD: a rescale example, thaht had a persistet filter in the DoExcecute method --- Example/CMakeLists.txt | 3 +- Example/otbRescale.cxx | 119 ++++++++++++++++++++++++++++ Testing/Java/CMakeLists.txt | 8 ++ Testing/Java/JavaRescaleTest.java | 27 +++++++ Testing/Lua/CMakeLists.txt | 7 ++ Testing/Lua/LuaRescaleTest.lua | 9 +++ Testing/PyQt/CMakeLists.txt | 6 ++ Testing/Python/CMakeLists.txt | 6 ++ Testing/Python/PythonRescaleTest.py | 21 +++++ Testing/Ruby/CMakeLists.txt | 7 ++ Testing/Ruby/RubyRescaleTest.rb | 15 ++++ 11 files changed, 227 insertions(+), 1 deletion(-) create mode 100644 Example/otbRescale.cxx create mode 100644 Testing/Java/JavaRescaleTest.java create mode 100644 Testing/Lua/LuaRescaleTest.lua create mode 100644 Testing/Python/PythonRescaleTest.py create mode 100644 Testing/Ruby/RubyRescaleTest.rb diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 30232f6ae2..dc4ca2b298 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -2,4 +2,5 @@ include(WrapperMacros) OTB_CREATE_APPLICATION(NAME Addition SOURCES otbAddition.cxx) OTB_CREATE_APPLICATION(NAME Smoothing SOURCES otbSmoothing.cxx) -OTB_CREATE_APPLICATION(NAME TestApplication SOURCES otbTestApplication.cxx) \ No newline at end of file +OTB_CREATE_APPLICATION(NAME Rescale SOURCES otbRescale.cxx) +OTB_CREATE_APPLICATION(NAME TestApplication SOURCES otbTestApplication.cxx) diff --git a/Example/otbRescale.cxx b/Example/otbRescale.cxx new file mode 100644 index 0000000000..41d088677c --- /dev/null +++ b/Example/otbRescale.cxx @@ -0,0 +1,119 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ +#include "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbStreamingMinMaxVectorImageFilter.h" +#include "otbVectorRescaleIntensityImageFilter.h" + +namespace otb +{ +namespace Wrapper +{ + + +class Rescale : public Application +{ +public: + /** Standard class typedefs. */ + typedef Rescale Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(Rescale, otb::Application); + + /** Filters typedef */ + typedef otb::StreamingMinMaxVectorImageFilter<VectorImageType> MinMaxFilterType; + typedef otb::VectorRescaleIntensityImageFilter<VectorImageType> RescaleImageFilterType; + + +private: + Rescale() + { + SetName("Rescale"); + SetDescription("Rescale the image between two given values."); + m_RescaleFilter = RescaleImageFilterType::New(); + m_MinMaxFilter = MinMaxFilterType::New(); + } + + virtual ~Rescale() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + + AddParameter(ParameterType_Float, "outmin", "Output min value"); + AddParameter(ParameterType_Float, "outmax", "Output max value"); + SetParameterFloat("outmin", 0); + SetParameterFloat("outmax", 255); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + VectorImageType::Pointer inImage = GetParameterImage("in"); + + std::cout<<"first step"<<std::endl; + + m_MinMaxFilter = MinMaxFilterType::New(); + std::cout<<"minmax instanciated"<<std::endl; + m_RescaleFilter = RescaleImageFilterType::New(); + + m_MinMaxFilter->SetInput( inImage ); + m_MinMaxFilter->Update(); + std::cout<<"Input min value: "<<m_MinMaxFilter->GetMinimum()<<std::endl; + std::cout<<"Input max value: "<<m_MinMaxFilter->GetMaximum()<<std::endl; + + m_RescaleFilter->SetInput( inImage ); + m_RescaleFilter->SetInputMinimum( m_MinMaxFilter->GetMinimum() ); + m_RescaleFilter->SetInputMaximum( m_MinMaxFilter->GetMaximum() ); + std::cout<<"input min/max set"<<std::endl; + + m_RescaleFilter->SetOutputMinimum( GetParameterFloat("outmin") ); + m_RescaleFilter->SetOutputMaximum( GetParameterFloat("outmax") ); + + std::cout<<"output min/max set"<<std::endl; + m_RescaleFilter->UpdateOutputInformation(); + std::cout<<"UpdateOutputInformation done"<<std::endl; + + SetParameterOutputImage("out", m_RescaleFilter->GetOutput()); + std::cout<<"output updated"<<std::endl; + } + + RescaleImageFilterType::Pointer m_RescaleFilter; + MinMaxFilterType::Pointer m_MinMaxFilter; +}; + + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::Rescale) + diff --git a/Testing/Java/CMakeLists.txt b/Testing/Java/CMakeLists.txt index b4ad74bdcd..a1b1f118ea 100644 --- a/Testing/Java/CMakeLists.txt +++ b/Testing/Java/CMakeLists.txt @@ -14,3 +14,11 @@ add_test( NAME jaTvSmoothing ${JAVA_COMMAND} -cp ${CMAKE_JAVA_INCLUDE_PATH}:JavaSmoothingTest.jar SmoothingTest ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif ${TEMP}/jaTvSmoothing_ ) + +add_jar( JavaRescaleTest JavaRescaleTest.java ) +add_dependencies( JavaRescaleTest org_otb_Application_jar ) +add_test( NAME jaTvRescale + COMMAND ${TEST_DRIVER} Execute + ${JAVA_COMMAND} -cp ${CMAKE_JAVA_INCLUDE_PATH}:JavaRescaleTest.jar RescaleTest + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/jaTvRescale ) diff --git a/Testing/Java/JavaRescaleTest.java b/Testing/Java/JavaRescaleTest.java new file mode 100644 index 0000000000..c842b4ee04 --- /dev/null +++ b/Testing/Java/JavaRescaleTest.java @@ -0,0 +1,27 @@ +/* + * Example on the use of the Rescale + */ + +import org.otb.application.*; + + +class RescaleTest { + + public static void main( String argv[] ) { + + vectorstring appAvailable = Registry.GetAvailableApplications(); + System.out.println( "Available applications :" ); + + for (int i = 0; i < appAvailable.size(); i++) + { + System.out.println( appAvailable.get(i) ); + } + + System.out.println( "Creating application " + "Rescale"); + Application_Pointer app = Registry.CreateApplication("Rescale"); + + System.out.println( Registry.CreateApplication("Rescale").GetDescription() ); + + } + +} \ No newline at end of file diff --git a/Testing/Lua/CMakeLists.txt b/Testing/Lua/CMakeLists.txt index 9752bd30d2..642512e594 100644 --- a/Testing/Lua/CMakeLists.txt +++ b/Testing/Lua/CMakeLists.txt @@ -10,3 +10,10 @@ add_test( NAME luTvSmoothing ${CMAKE_CURRENT_SOURCE_DIR}/LuaSmoothingTest.lua ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif ${TEMP}/rbTvSmoothing_ ) + +add_test( NAME luTvRescale + COMMAND ${TEST_DRIVER} Execute + ${CMAKE_BINARY_DIR}/Code/Wrappers/SWIG/otbApplicationLua + ${CMAKE_CURRENT_SOURCE_DIR}/LuaRescaleTest.lua + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/rbTvRescale ) diff --git a/Testing/Lua/LuaRescaleTest.lua b/Testing/Lua/LuaRescaleTest.lua new file mode 100644 index 0000000000..fdca6b6571 --- /dev/null +++ b/Testing/Lua/LuaRescaleTest.lua @@ -0,0 +1,9 @@ +print ( "Lua test begin" ) + +r = otbApplication.Registry +apps = r:GetAvailableApplications() + +print ( "otbApplication.Registry:GetAvailableApplications OK" ) +print ( "apps" ) +print ( apps ) +os.exit ( 0 ) \ No newline at end of file diff --git a/Testing/PyQt/CMakeLists.txt b/Testing/PyQt/CMakeLists.txt index c904be3b0e..f6b808e42a 100644 --- a/Testing/PyQt/CMakeLists.txt +++ b/Testing/PyQt/CMakeLists.txt @@ -10,3 +10,9 @@ add_test( NAME pqTvSmoothing ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PyQtTest.py ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif ${TEMP}/pyTvSmoothing_ ) + +add_test( NAME pqTvRescale + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PyQtTest.py + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/pyTvRescale ) \ No newline at end of file diff --git a/Testing/Python/CMakeLists.txt b/Testing/Python/CMakeLists.txt index 7d3c7d2888..86ad1a6aaf 100644 --- a/Testing/Python/CMakeLists.txt +++ b/Testing/Python/CMakeLists.txt @@ -9,3 +9,9 @@ add_test( NAME pyTvSmoothing ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonSmoothingTest.py ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif ${TEMP}/pyTvSmoothing_ ) + +add_test( NAME pyTvRescale + COMMAND ${TEST_DRIVER} Execute + ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonRescaleTest.py + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/pyTvRescale) \ No newline at end of file diff --git a/Testing/Python/PythonRescaleTest.py b/Testing/Python/PythonRescaleTest.py new file mode 100644 index 0000000000..c2eaa0f656 --- /dev/null +++ b/Testing/Python/PythonRescaleTest.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +# +# Example on the use of the Rescale +# +from sys import argv +import otbApplication as otb + +print "Available applications : " + str(otb.Registry.GetAvailableApplications()) + +app = otb.Registry.CreateApplication("Rescale") +print app.GetParametersKeys() + +app.SetParameterString("in", argv[1]) + +app.SetParameterFloat("outmin", 1) +app.SetParameterFloat("outmax", 100) +app.SetParameterString("out", argv[2] + ".tif") +app.Execute() + +print dir(app) diff --git a/Testing/Ruby/CMakeLists.txt b/Testing/Ruby/CMakeLists.txt index 099aa0fba6..9e3a712ddd 100644 --- a/Testing/Ruby/CMakeLists.txt +++ b/Testing/Ruby/CMakeLists.txt @@ -9,3 +9,10 @@ add_test( NAME rbTvSmoothing ${RUBY_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/RubySmoothingTest.rb ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif ${TEMP}/rbTvSmoothing_ ) + +add_test( NAME rbTvRescale + COMMAND ${TEST_DRIVER} Execute + ${RUBY_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/RubyRescaleTest.rb + ${OTB_DATA_ROOT}/Input/ToulouseExtract_WithGeom.tif + ${TEMP}/rbTvRescale ) + diff --git a/Testing/Ruby/RubyRescaleTest.rb b/Testing/Ruby/RubyRescaleTest.rb new file mode 100644 index 0000000000..43e49adb1a --- /dev/null +++ b/Testing/Ruby/RubyRescaleTest.rb @@ -0,0 +1,15 @@ +# +# Example on the use of the Rescale +# +require 'otbapplication' + +if ARGV.length < 2 then + puts( "Usage: RubyRescaleTest input outputbasename" ) + exit( 1 ) +end + +tag = ARGV[0]; + +r = Otbapplication::Registry +applist = r.get_available_applications() +puts( applist ) -- GitLab