Skip to content

Commit d993427

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 d993427

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Modules/Segmentation/ConnectedComponents/test/itkConnectedComponentImageFilterTest.cxx

Lines changed: 12 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,20 @@ 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+
constexpr std::mt19937::result_type randomSeed{ 1031571 };
132+
std::mt19937 randomNumberEngine(randomSeed);
133+
std::uniform_int_distribution<> randomNumberDistribution(maxRGBComponentValue / 3, maxRGBComponentValue);
134+
128135
for (auto & i : colormap)
129136
{
130137
RGBPixelType px;
131-
std::generate(
132-
px.begin(), px.end(), [] { return static_cast<unsigned char>(255 * vnl_sample_uniform(0.3333, 1.0)); });
138+
std::generate(px.begin(), px.end(), [&randomNumberEngine, &randomNumberDistribution] {
139+
return static_cast<RGBComponentType>(randomNumberDistribution(randomNumberEngine));
140+
});
133141

134142
i = px;
135143
}

Modules/Segmentation/ConnectedComponents/test/itkConnectedComponentImageFilterTestRGB.cxx

Lines changed: 12 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,19 @@ 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+
constexpr std::mt19937::result_type randomSeed{ 1031571 };
112+
std::mt19937 randomNumberEngine(randomSeed);
113+
std::uniform_int_distribution<> randomNumberDistribution(maxRGBComponentValue / 3, maxRGBComponentValue);
114+
108115
for (auto & i : colormap)
109116
{
110-
std::generate(
111-
px.begin(), px.end(), [] { return static_cast<unsigned char>(255 * vnl_sample_uniform(0.3333, 1.0)); });
117+
std::generate(px.begin(), px.end(), [&randomNumberEngine, &randomNumberDistribution] {
118+
return static_cast<RGBComponentType>(randomNumberDistribution(randomNumberEngine));
119+
});
112120

113121
i = px;
114122
}

0 commit comments

Comments
 (0)