go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxGTestUtilities.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright UMC Utrecht and contributors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef elxGTestUtilities_h
19#define elxGTestUtilities_h
20
21#include <itkOptimizerParameters.h>
22#include <itkPoint.h>
23#include <itkSize.h>
24#include <itkSmartPointer.h>
25#include <itkVector.h>
26
27// GoogleTest header file:
28#include <gtest/gtest.h>
29
30#include <algorithm> // For generate_n.
31#include <cassert>
32#include <cfloat> // For DBL_MAX.
33#include <random>
34
35namespace elastix
36{
37namespace GTestUtilities
38{
39
41template <typename TMap>
42void
43ExpectAllKeysUnique(const TMap & map1, const TMap & map2)
44{
45 const auto endOfMap2 = map2.end();
46
47 for (const auto & keyValuePair : map1)
48 {
49 EXPECT_EQ(map2.find(keyValuePair.first), endOfMap2);
50 }
51}
52
53
55template <typename TMap>
56TMap
57MakeMergedMap(TMap map1, const TMap & map2)
58{
59 // Note: This for-loop should be equivalent to C++17 `map1.merge(TMap{map2});`
60 for (const auto & keyValuePair : map2)
61 {
62 map1.insert(keyValuePair);
63 }
64 return map1;
65}
66
67
70template <typename TElastix>
71itk::SmartPointer<TElastix>
73{
74 using FixedImageType = typename TElastix::FixedImageType;
75 using MovingImageType = typename TElastix::MovingImageType;
76
77 const auto elastixObject = TElastix::New();
78
79 elastixObject->SetConfiguration(elx::Configuration::New());
80
81 const auto fixedImageContainer = elx::ElastixBase::DataObjectContainerType::New();
82 fixedImageContainer->push_back(FixedImageType::New());
83 elastixObject->SetFixedImageContainer(fixedImageContainer);
84
85 const auto movingImageContainer = elx::ElastixBase::DataObjectContainerType::New();
86 movingImageContainer->push_back(MovingImageType::New());
87 elastixObject->SetMovingImageContainer(movingImageContainer);
88
89 return elastixObject;
90}
91
92
95inline itk::OptimizerParameters<double>
96GeneratePseudoRandomParameters(const unsigned numberOfParameters, const double minValue, const double maxValue = 1.0)
97{
98 assert(minValue < maxValue);
99 assert((maxValue - minValue) <= DBL_MAX);
100
101 itk::OptimizerParameters<double> parameters(numberOfParameters);
102
103 std::mt19937 randomNumberEngine;
104
105 std::generate_n(parameters.begin(), numberOfParameters, [&randomNumberEngine, minValue, maxValue] {
106 return std::uniform_real_distribution<>{ minValue, maxValue }(randomNumberEngine);
107 });
108 return parameters;
109}
110
111} // namespace GTestUtilities
112} // namespace elastix
113
114
115#endif
itk::OptimizerParameters< double > GeneratePseudoRandomParameters(const unsigned numberOfParameters, const double minValue, const double maxValue=1.0)
void ExpectAllKeysUnique(const TMap &map1, const TMap &map2)
Expect that all keys of both specified maps are unique.
TMap MakeMergedMap(TMap map1, const TMap &map2)
Makes a map by merging its two arguments together.
itk::SmartPointer< TElastix > CreateDefaultElastixObject()


Generated on 2023-01-13 for elastix by doxygen 1.9.6 elastix logo