Skip to content

Commit 3324070

Browse files
committed
ENH: Replace "vnl_sample.h" with <random> in ConnectedComponent tests
Follow-up to pull request #5611 commit f7daf24 "ENH: Replace "vnl/vnl_sample.h" with `<random>`, in Core tests"
1 parent 6568876 commit 3324070

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

Modules/Segmentation/ConnectedComponents/test/itkConnectedComponentImageFilterTest.cxx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#include "itkImageFileReader.h"
2323
#include "itkImageFileWriter.h"
2424
#include "itkSimpleFilterWatcher.h"
25-
#include "vnl/vnl_sample.h"
2625
#include "itkTestingMacros.h"
2726
#include <algorithm> // For generate.
27+
#include <random> // For mt19937.
2828

2929
int
3030
itkConnectedComponentImageFilterTest(int argc, char * argv[])
@@ -124,12 +124,19 @@ itkConnectedComponentImageFilterTest(int argc, char * argv[])
124124

125125
std::vector<RGBPixelType> colormap;
126126
colormap.resize(numObjects + 1);
127-
vnl_sample_reseed(1031571);
127+
128+
using RGBComponentType = RGBPixelType::ComponentType;
129+
constexpr auto maxRGBComponentValue = std::numeric_limits<RGBComponentType>::max();
130+
131+
std::mt19937 randomNumberEngine{};
132+
std::uniform_int_distribution<> randomNumberDistribution(maxRGBComponentValue / 3, maxRGBComponentValue);
133+
128134
for (auto & i : colormap)
129135
{
130136
RGBPixelType px;
131-
std::generate(
132-
px.begin(), px.end(), [] { return static_cast<unsigned char>(255 * vnl_sample_uniform(0.3333, 1.0)); });
137+
std::generate(px.begin(), px.end(), [&randomNumberEngine, &randomNumberDistribution] {
138+
return randomNumberDistribution(randomNumberEngine);
139+
});
133140

134141
i = px;
135142
}

Modules/Segmentation/ConnectedComponents/test/itkConnectedComponentImageFilterTestRGB.cxx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "itkImageFileWriter.h"
2424
#include "itkSimpleFilterWatcher.h"
2525
#include "itkTestingMacros.h"
26-
#include "vnl/vnl_sample.h"
2726
#include <algorithm> // For generate.
27+
#include <random> // For mt19937.
2828

2929
int
3030
itkConnectedComponentImageFilterTestRGB(int argc, char * argv[])
@@ -104,11 +104,18 @@ itkConnectedComponentImageFilterTestRGB(int argc, char * argv[])
104104
std::vector<RGBPixelType> colormap;
105105
RGBPixelType px;
106106
colormap.resize(numObjects + 1);
107-
vnl_sample_reseed(1031571);
107+
108+
using RGBComponentType = RGBPixelType::ComponentType;
109+
constexpr auto maxRGBComponentValue = std::numeric_limits<RGBComponentType>::max();
110+
111+
std::mt19937 randomNumberEngine{};
112+
std::uniform_int_distribution<> randomNumberDistribution(maxRGBComponentValue / 3, maxRGBComponentValue);
113+
108114
for (auto & i : colormap)
109115
{
110-
std::generate(
111-
px.begin(), px.end(), [] { return static_cast<unsigned char>(255 * vnl_sample_uniform(0.3333, 1.0)); });
116+
std::generate(px.begin(), px.end(), [&randomNumberEngine, &randomNumberDistribution] {
117+
return randomNumberDistribution(randomNumberEngine);
118+
});
112119

113120
i = px;
114121
}

0 commit comments

Comments
 (0)