diff --git a/Code/ApplicationEngine/otbWrapperApplication.cxx b/Code/ApplicationEngine/otbWrapperApplication.cxx index a44992ed0fe8bf66493302f861241515745c4a1e..95bf39308d994954acc0939f3b0ece849b45907f 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.cxx +++ b/Code/ApplicationEngine/otbWrapperApplication.cxx @@ -123,7 +123,30 @@ void Application::UpdateParameters() int Application::Execute() { int ret = 0; - + // before execute we set the seed of mersenne twister + std::vector<std::string> paramList = GetParametersKeys(true); + bool UseSpecificSeed = false; + + for (std::vector<std::string>::const_iterator it = paramList.begin(); it != paramList.end(); ++it) + { + std::string key = *it; + + if ((key.compare(0, 4, "rand") == 0) && HasValue("rand")) + { + UseSpecificSeed = true; + Parameter* param = GetParameterByKey(key); + IntParameter* randParam = dynamic_cast<IntParameter*> (param); + int seed = randParam->GetValue(); + itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(seed); + } + + } + + if (!UseSpecificSeed) + { + itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->Initialize(); + } + this->DoExecute(); return ret; @@ -1144,6 +1167,27 @@ void Application::AddRAMParameter(std::string paramKey) SetParameterDescription(paramKey, "Available memory for processing (in MB)"); } +void Application::AddRANDParameter(std::string paramKey, std::string paramName, unsigned int defaultValue) +{ + GetParameterList()->AddParameter(ParameterType_Int, paramKey, paramName); + SetDefaultParameterInt(paramKey, defaultValue); + MandatoryOff(paramKey); +} + +// paramKey default value = rand +void Application::AddRANDParameter(std::string paramKey) +{ + // Get the RAND Parameter from the configuration file + + GetParameterList()->AddParameter(ParameterType_Int, paramKey, "set user defined seed"); + MandatoryOff(paramKey); + SetParameterDescription(paramKey, "Set specific seed. with integer value."); + +} + + + + std::vector< std::pair<std::string, std::string> > Application::GetOutputParametersSumUp() { diff --git a/Code/ApplicationEngine/otbWrapperApplication.h b/Code/ApplicationEngine/otbWrapperApplication.h index 5ae896f609b5275b5d694a741864f72e3555be57..c4d6564404c6359f803a83f1d8af143fa39e7f10 100644 --- a/Code/ApplicationEngine/otbWrapperApplication.h +++ b/Code/ApplicationEngine/otbWrapperApplication.h @@ -35,6 +35,7 @@ #include "otbWrapperComplexOutputImageParameter.h" #include "otbWrapperDocExampleStructure.h" +#include "itkMersenneTwisterRandomVariateGenerator.h" namespace otb { @@ -617,6 +618,14 @@ protected: /** Add a parameterRAM method with no parameter*/ void AddRAMParameter(std::string paramKey="ram"); + /** Add a parameterRAND method with parameter + * by default seed initialization is based on time value*/ + void AddRANDParameter(std::string paramKey, std::string paramName, unsigned int defaultValue); + + /** Add a parameterRAND method with no parameter*/ + void AddRANDParameter(std::string paramKey="rand"); + + /** Remove the items added to the ListWidget */ void ClearChoices(std::string key); diff --git a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx index 077f542d948b0e8ce9e537b43cbffff232956e40..f64ac6ddf095d58f6d0fdd08e26058d2ed1772db 100644 --- a/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx +++ b/Code/Wrappers/CommandLine/otbWrapperCommandLineLauncher.cxx @@ -41,7 +41,7 @@ #include "otbWrapperStringListParameter.h" #include "otbStreamingImageFileWriter.h" -#include "itkMersenneTwisterRandomVariateGenerator.h" + #include "otbWrapperApplicationRegistry.h" #include "otbWrapperApplication.h" @@ -645,8 +645,8 @@ void CommandLineLauncher::DisplayHelp() void CommandLineLauncher::LoadTestEnv() { //Set seed for rand and itk mersenne twister - srand(1); - itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(121212); + //srand(1); + // itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(121212); }