136 const itk::Index<VImageDimension> & regionIndex,
137 const itk::Size<VImageDimension> & regionSize)
139 const itk::ImageRegionRange<itk::Image<TPixel, VImageDimension>> imageRegionRange{
140 image, itk::ImageRegion<VImageDimension>{ regionIndex, regionSize }
142 std::fill(std::begin(imageRegionRange), std::end(imageRegionRange), 1);
151 std::vector<double> vectorOfDouble(strings.size());
153 std::transform(strings.cbegin(), strings.cend(), vectorOfDouble.begin(), [](
const std::string & str) {
155 const auto result = std::stod(str, &index);
158 EXPECT_EQ(index, str.size());
162 return vectorOfDouble;
173 itk::Offset<VDimension> result;
176 for (
const double value : doubles)
178 const auto roundedValue = std::round(value);
180 EXPECT_GE(roundedValue, std::numeric_limits<itk::OffsetValueType>::min());
181 EXPECT_LE(roundedValue, std::numeric_limits<itk::OffsetValueType>::max());
183 result[i] =
static_cast<itk::OffsetValueType
>(roundedValue);
192 std::initializer_list<std::pair<std::string, std::vector<std::string>>> initializerList)
194 std::map<std::string, std::vector<std::string>> result;
196 for (
const auto & pair : initializerList)
198 EXPECT_TRUE(result.insert(pair).second);
205 std::initializer_list<std::pair<std::string, std::string>> initializerList)
207 std::map<std::string, std::vector<std::string>> result;
209 for (
const auto & pair : initializerList)
211 EXPECT_TRUE(result.insert({ pair.first, { pair.second } }).second);
252 EXPECT_EQ(transformParameterMaps.size(), 1);
254 if (transformParameterMaps.empty())
256 throw Exception(
"Error: GetTransformParametersFromMaps should not return an empty ParameterMap!");
259 const auto & transformParameterMap = transformParameterMaps.front();
260 const auto found = transformParameterMap.find(
"TransformParameters");
262 if (found == transformParameterMap.cend())
264 throw Exception(
"Error: GetTransformParametersFromMaps did not find TransformParameters!");
315 : direction(image.GetDirection())
316 , index(image.GetLargestPossibleRegion().GetIndex())
317 , size(image.GetLargestPossibleRegion().GetSize())
318 , spacing(image.GetSpacing())
319 , origin(image.GetOrigin())
328 : direction(initialDirection)
329 , index(initialIndex)
331 , spacing(initialSpacing)
332 , origin(initialOrigin)
337 ToImage(itk::ImageBase<VDimension> & image)
const
339 image.SetDirection(direction);
340 image.SetRegions({ index, size });
341 image.SetSpacing(spacing);
342 image.SetOrigin(origin);
351 {
"Direction", elx::Conversion::ToVectorOfStrings(direction) },
352 {
"Index", elx::Conversion::ToVectorOfStrings(index) },
353 {
"Origin", elx::Conversion::ToVectorOfStrings(origin) },
354 {
"Size", elx::Conversion::ToVectorOfStrings(size) },
355 {
"Spacing", elx::Conversion::ToVectorOfStrings(spacing) },
369 return !(lhs == rhs);
388 const auto createRandomDirection = [&randomNumberEngine] {
389 using DirectionType =
typename ImageDomainType::DirectionType;
390 auto randomDirection = DirectionType::GetIdentity();
393 const auto randomRotation = std::uniform_real_distribution<>{ -M_PI, M_PI }(randomNumberEngine);
394 const auto cosRandomRotation = std::cos(randomRotation);
395 const auto sinRandomRotation = std::sin(randomRotation);
397 randomDirection[0][0] = cosRandomRotation;
398 randomDirection[0][1] = sinRandomRotation;
399 randomDirection[1][0] = -sinRandomRotation;
400 randomDirection[1][1] = cosRandomRotation;
402 return randomDirection;
404 const auto createRandomIndex = [&randomNumberEngine] {
405 typename ImageDomainType::IndexType randomIndex{};
409 std::generate(randomIndex.begin(), randomIndex.end(), [&randomNumberEngine] {
410 return std::uniform_int_distribution{ std::numeric_limits<int>::min() / 2,
411 std::numeric_limits<int>::max() / 2 }(randomNumberEngine);
415 const auto createRandomSmallImageSize = [&randomNumberEngine] {
416 typename ImageDomainType::SizeType randomImageSize{};
417 std::generate(randomImageSize.begin(), randomImageSize.end(), [&randomNumberEngine] {
418 return std::uniform_int_distribution<itk::SizeValueType>{ minimumImageSizeValue,
419 2 * minimumImageSizeValue }(randomNumberEngine);
421 return randomImageSize;
423 const auto createRandomSpacing = [&randomNumberEngine] {
424 typename ImageDomainType::SpacingType randomSpacing{};
425 std::generate(randomSpacing.begin(), randomSpacing.end(), [&randomNumberEngine] {
428 return std::uniform_real_distribution<itk::SpacePrecisionType>{ 0.1, 10.0 }(randomNumberEngine);
430 return randomSpacing;
432 const auto createRandomPoint = [&randomNumberEngine] {
433 typename ImageDomainType::PointType randomPoint{};
434 std::generate(randomPoint.begin(), randomPoint.end(), [&randomNumberEngine] {
438 return std::uniform_real_distribution<itk::SpacePrecisionType>{
439 std::numeric_limits<int>::min(), std::numeric_limits<int>::max()
440 }(randomNumberEngine);
445 return ImageDomainType{ createRandomDirection(),
447 createRandomSmallImageSize(),
448 createRandomSpacing(),
449 createRandomPoint() };