Commit 3a234a27 authored by Jonathan Guinet's avatar Jonathan Guinet

ENH: AddRANDParameter option in order to Set mersenne twister seed. if no...

ENH: AddRANDParameter option in order to Set mersenne twister seed. if no value given rand gen is initialized with time dependant value.
parent aef8cf59
......@@ -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()
{
......
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment