Skip to content

Commit d4dcb59

Browse files
N-Dekkerhjmjohnson
authored andcommitted
ENH: Replace "vnl_sample.h" with <random> in ImageIntensity tests
Follow-up to pull request #5611 commit f7daf24 "ENH: Replace "vnl/vnl_sample.h" with `<random>`, in Core tests"
1 parent 931c049 commit d4dcb59

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Modules/Filtering/ImageIntensity/test/itkAdaptImageFilterTest.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@
3636
#include "itkGreenPixelAccessor.h"
3737
#include "itkBluePixelAccessor.h"
3838
#include "itkSimpleFilterWatcher.h"
39-
40-
#include "vnl/vnl_sample.h"
4139
#include "itkMath.h"
4240

4341
#include <algorithm> // For generate.
42+
#include <random> // For mt19937.
4443

4544

4645
//-------------------------------------
@@ -87,11 +86,16 @@ itkAdaptImageFilterTest(int, char *[])
8786
// Value to initialize the pixels
8887
myRGBImageType::PixelType color;
8988

89+
std::mt19937 randomNumberEngine{};
90+
std::uniform_real_distribution<float> randomNumberDistribution{};
91+
9092
// Initializing all the pixel in the image
9193
it1.GoToBegin();
9294
while (!it1.IsAtEnd())
9395
{
94-
std::generate(color.begin(), color.end(), [] { return static_cast<float>(vnl_sample_uniform(0.0, 1.0)); });
96+
std::generate(color.begin(), color.end(), [&randomNumberEngine, &randomNumberDistribution] {
97+
return randomNumberDistribution(randomNumberEngine);
98+
});
9599
it1.Set(color);
96100
++it1;
97101
}

Modules/Filtering/ImageIntensity/test/itkAdaptImageFilterTest2.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333

3434
#include "itkAdaptImageFilter.h"
3535
#include "itkNthElementPixelAccessor.h"
36-
37-
#include "vnl/vnl_sample.h"
3836
#include "itkMath.h"
3937

4038
#include <algorithm> // For generate.
39+
#include <random> // For mt19937.
4140

4241

4342
//-------------------------------------
@@ -79,14 +78,19 @@ itkAdaptImageFilterTest2(int, char *[])
7978

8079
myVectorIteratorType it1(myImage, myImage->GetRequestedRegion());
8180

81+
std::mt19937 randomNumberEngine{};
82+
std::uniform_real_distribution<float> randomNumberDistribution{};
83+
8284
// Value to initialize the pixels
8385
myVectorImageType::PixelType color;
8486

8587
// Initializing all the pixel in the image
8688
it1.GoToBegin();
8789
while (!it1.IsAtEnd())
8890
{
89-
std::generate(color.begin(), color.end(), [] { return static_cast<float>(vnl_sample_uniform(0.0, 1.0)); });
91+
std::generate(color.begin(), color.end(), [&randomNumberEngine, &randomNumberDistribution] {
92+
return randomNumberDistribution(randomNumberEngine);
93+
});
9094
it1.Set(color);
9195
++it1;
9296
}

Modules/Filtering/ImageIntensity/test/itkRGBToVectorAdaptImageFilterTest.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131

3232
#include "itkAdaptImageFilter.h"
3333
#include "itkRGBToVectorPixelAccessor.h"
34-
35-
#include "vnl/vnl_sample.h"
3634
#include "itkMath.h"
3735

3836
#include <algorithm> // For generate.
37+
#include <random> // For mt19937.
3938

4039

4140
//-------------------------
@@ -82,14 +81,19 @@ itkRGBToVectorAdaptImageFilterTest(int, char *[])
8281

8382
myRGBIteratorType it1(myImage, myImage->GetRequestedRegion());
8483

84+
std::mt19937 randomNumberEngine{};
85+
std::uniform_real_distribution<float> randomNumberDistribution{};
86+
8587
// Value to initialize the pixels
8688
RGBImageType::PixelType color;
8789

8890
// Initializing all the pixel in the image
8991
it1.GoToBegin();
9092
while (!it1.IsAtEnd())
9193
{
92-
std::generate(color.begin(), color.end(), [] { return static_cast<float>(vnl_sample_uniform(0.0, 1.0)); });
94+
std::generate(color.begin(), color.end(), [&randomNumberEngine, &randomNumberDistribution] {
95+
return randomNumberDistribution(randomNumberEngine);
96+
});
9397
it1.Set(color);
9498
++it1;
9599
}

0 commit comments

Comments
 (0)