diff --git a/Modules/Applications/AppTest/app/otbMemoryTestApplication.cxx b/Modules/Applications/AppTest/app/otbMemoryTestApplication.cxx index 44712e35c38d0dc62b40a16f7d84901b29817ab7..ef3f715560c7b5d89f9451a21fb13d8bcf707a3d 100644 --- a/Modules/Applications/AppTest/app/otbMemoryTestApplication.cxx +++ b/Modules/Applications/AppTest/app/otbMemoryTestApplication.cxx @@ -94,7 +94,7 @@ private: #ifdef MEM_DEBUG extractor->DebugOn(); #endif - m_Filters.push_back(extractor.GetPointer()); + // m_Filters.push_back(extractor.GetPointer()); #ifdef MEM_DEBUG std::cout<<"Debug on extractor "<<std::endl; extractor->DebugOn(); @@ -107,6 +107,9 @@ private: extractor->GetOutput()->DebugOn(); #endif SetParameterOutputImage("out" , extractor->GetOutput() ); + std::cout<<"Registering"<<std::endl; + RegisterPipeline(); + std::cout<<"Registered"<<std::endl; } }; diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index 97a56268914297e955aee7be6c7328766dcd422a..c6d9c6c0e4e6ed2a0b5db51b1d79d06adc64d324 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -848,6 +848,8 @@ public: this->SetDocLink(link); } + void RegisterPipeline(); + std::vector<itk::ProcessObject::Pointer> m_Filters; protected: diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h index 3f83839de104e5bb536c821d9efa2573d13e8890..852006791c1625c921b093b896db0a0d3812d209 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperInputImageParameter.h @@ -111,6 +111,10 @@ public: void ClearValue() ITK_OVERRIDE; + ImageBaseType::Pointer GetPointer() + { + return m_Image; + } protected: /** Constructor */ diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index c32feb4b8b30ffaacf7e001078ab900e64677e0a..0dd8d63a41fc896768171b337953fb82b860f5b9 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -45,6 +45,8 @@ #include "otbWrapperTypes.h" #include <exception> #include "itkMacro.h" +#include <stack> +#include <set> namespace otb { @@ -75,6 +77,83 @@ Application::~Application() { } +void +Application::RegisterPipeline() +{ + m_Filters.clear(); + std::stack< itk::DataObject * > dataStack; + std::set< itk::DataObject * > inputData; + std::vector<std::string> paramList = GetParametersKeys(true); + for (std::vector<std::string>::const_iterator it = paramList.begin(); + it != paramList.end(); + ++it) + { + std::string key = *it; + if ( GetParameterType(key) == ParameterType_OutputImage ) + { + Parameter* param = GetParameterByKey(key); + OutputImageParameter * outP = dynamic_cast<OutputImageParameter*>(param); + itk::ImageBase<2> * outData = outP->GetValue(); + std::cout<<"one image in output"<<std::endl; + dataStack.push(outData); + } + else if ( GetParameterType(key) == ParameterType_OutputVectorData ) + { + Parameter* param = GetParameterByKey(key); + OutputVectorDataParameter * outP = dynamic_cast<OutputVectorDataParameter*>(param); + Wrapper::VectorDataType * outData = outP->GetValue(); + dataStack.push(outData); + } + else if ( GetParameterType(key) == ParameterType_InputImage ) + { + Parameter* param = GetParameterByKey(key); + InputImageParameter * inP = dynamic_cast<InputImageParameter*>(param); + itk::ImageBase<2> * inData = inP->GetPointer(); + inputData.insert(inData); + } + } + // DFS + std::set< itk::ProcessObject * > processSet; + while ( !dataStack.empty() ) + { + std::cout<<"one data is processed"<<std::endl; + itk::DataObject * current = dataStack.top(); + dataStack.pop(); + if ( inputData.find( current ) != inputData.end() ) + continue; + std::cout<<"not an input"<<std::endl; + if ( dynamic_cast<itk::ImageBase<2> * > ( current ) ) + { + itk::ImageBase<2> * image = dynamic_cast<itk::ImageBase<2> * > ( current ); + itk::ImageBase<2>::SizeType sizenull; + sizenull.Fill(0); + if ( image->GetLargestPossibleRegion() == image->GetBufferedRegion() && image->GetBufferedRegion().GetSize() != sizenull ) + continue; + } + std::cout<<"not empty"<<std::endl; + itk::ProcessObject * process = (current->GetSource()).GetPointer(); + if ( processSet.find( process ) != processSet.end()) + continue; + std::cout<<"add process to set"<<std::endl; + processSet.insert( process ); + std::vector< itk::DataObject::Pointer > inputs = process->GetInputs(); + for ( auto it : inputs ) + { + if ( inputData.find(it.GetPointer()) != inputData.end() ) + continue; + dataStack.push( it.GetPointer() ); + } + } + + for ( auto it : processSet ) + { + std::cout<<"one filter is registered"<<std::endl; + m_Filters.push_back( it ); + } + + +} + otb::Logger* Application::GetLogger() const { return m_Logger; diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx index 71471e3fc29033c4085daa9ec4852be592383054..37d91b86d0344c3c52df5e07264c8864809f1077 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx @@ -475,9 +475,6 @@ OutputImageParameter::Write() { itkExceptionMacro("Unknown image type"); } - - // Clear writer - m_UInt8Writer = nullptr; } @@ -658,14 +655,6 @@ void OutputImageParameter::ClearValue() { m_Image = nullptr; // m_FileName = ""; - - m_UInt8Writer = nullptr; - m_Int16Writer = nullptr; - m_UInt16Writer = nullptr; - m_Int32Writer = nullptr; - m_UInt32Writer = nullptr; - m_FloatWriter = nullptr; - m_DoubleWriter = nullptr; m_VectorUInt8Writer = nullptr; m_VectorInt16Writer = nullptr;