go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
elxGenericPyramidHelper.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 elxGenericPyramidHelper_h
19#define elxGenericPyramidHelper_h
20
21#include <string> // For is_same.
22#include <type_traits> // For is_same.
23
24#include "elxConfiguration.h"
25#include <itkDeref.h>
26
27namespace elastix
28{
29template <class TElastix>
30class FixedGenericPyramid;
31
32template <class TElastix>
33class MovingGenericPyramid;
34
37{
38public:
40 template <typename TPyramid>
41 static void
42 SetSchedule(TPyramid & pyramid)
43 {
44 using ElastixType = typename TPyramid::ElastixType;
45
46 constexpr bool isFixed = std::is_same_v<TPyramid, FixedGenericPyramid<ElastixType>>;
47 constexpr bool isMoving = std::is_same_v<TPyramid, MovingGenericPyramid<ElastixType>>;
48
49 static_assert(isMoving != isFixed, "TPyramid must be either FixedGenericPyramid or MovingGenericPyramid!");
50
51 const std::string parameterPrefix = isFixed ? "Fixed" : "Moving";
52 constexpr const char * pyramidAdjective = isFixed ? "fixed" : "moving";
53
54 // It is assumed for more than ten years already that the configuration is not null, looking at
55 // "src/Components/FixedImagePyramids/FixedGenericPyramid/elxFixedGenericPyramid.hxx" revision
56 // f84ac0d1094ebdb13e456b1b8cf1f6f9bfcd0a38 "ENH: First checkin of a generic pyramid...", Marius Staring, 2012-02-02
57
58 const Configuration & configuration = itk::Deref(pyramid.GetConfiguration());
59
61 const unsigned int ImageDimension = TPyramid::ImageDimension;
62
64 unsigned int numberOfResolutions = 3;
65 configuration.ReadParameter(numberOfResolutions, "NumberOfResolutions", 0, true);
66 if (numberOfResolutions == 0)
67 {
68 itkGenericExceptionMacro("The NumberOfResolutions parameter must have a non-zero value!");
69 }
70
72 pyramid.GetAsITKBaseType()->SetNumberOfLevels(numberOfResolutions);
73 typename TPyramid::RescaleScheduleType rescaleSchedule = pyramid.GetRescaleSchedule();
74 typename TPyramid::SmoothingScheduleType smoothingSchedule = pyramid.GetSmoothingSchedule();
75
83 bool foundRescale = true;
84 for (unsigned int i = 0; i < numberOfResolutions; ++i)
85 {
86 for (unsigned int j = 0; j < ImageDimension; ++j)
87 {
88 bool ijfound = false;
89 const unsigned int entrynr = i * ImageDimension + j;
90 ijfound |= configuration.ReadParameter(rescaleSchedule[i][j], "ImagePyramidRescaleSchedule", entrynr, false);
91 ijfound |= configuration.ReadParameter(rescaleSchedule[i][j], "ImagePyramidSchedule", entrynr, false);
92 ijfound |= configuration.ReadParameter(
93 rescaleSchedule[i][j], parameterPrefix + "ImagePyramidRescaleSchedule", entrynr, false);
94 ijfound |=
95 configuration.ReadParameter(rescaleSchedule[i][j], parameterPrefix + "ImagePyramidSchedule", entrynr, false);
96
98 foundRescale &= ijfound;
99
100 } // end for ImageDimension
101 } // end for numberOfResolutions
102
103 if (!foundRescale && pyramid.GetConfiguration()->GetPrintErrorMessages())
104 {
105 log::warn(std::ostringstream{} << "WARNING: the " << pyramidAdjective
106 << " pyramid rescale schedule is not fully specified!\n"
107 << " A default pyramid rescale schedule is used.");
108 }
109 else
110 {
112 pyramid.SetRescaleSchedule(rescaleSchedule);
113
114 const auto newSchedule = pyramid.GetRescaleSchedule();
115
116 if (newSchedule != rescaleSchedule)
117 {
118 log::warn(
119 std::ostringstream{} << "WARNING: the " << pyramidAdjective
120 << " pyramid rescale schedule is adjusted!\n Input schedule from configuration:\n"
121 << rescaleSchedule << "\n Adjusted schedule:\n"
122 << newSchedule);
123 }
124 }
125
131 bool foundSmoothing = true;
132 for (unsigned int i = 0; i < numberOfResolutions; ++i)
133 {
134 for (unsigned int j = 0; j < ImageDimension; ++j)
135 {
136 bool ijfound = false;
137 const unsigned int entrynr = i * ImageDimension + j;
138 ijfound |=
139 configuration.ReadParameter(smoothingSchedule[i][j], "ImagePyramidSmoothingSchedule", entrynr, false);
140 ijfound |= configuration.ReadParameter(
141 smoothingSchedule[i][j], parameterPrefix + "ImagePyramidSmoothingSchedule", entrynr, false);
142
144 foundSmoothing &= ijfound;
145
146 } // end for ImageDimension
147 } // end for numberOfResolutions
148
149 if (!foundSmoothing && pyramid.GetConfiguration()->GetPrintErrorMessages())
150 {
151 log::warn(std::ostringstream{} << "WARNING: the " << pyramidAdjective
152 << " pyramid smoothing schedule is not fully specified!\n"
153 << " A default pyramid smoothing schedule is used.");
154 }
155 else
156 {
158 pyramid.SetSmoothingSchedule(smoothingSchedule);
159
160 const auto newSchedule = pyramid.GetSmoothingSchedule();
161
162 if (newSchedule != smoothingSchedule)
163 {
164 log::warn(
165 std::ostringstream{} << "WARNING: the " << pyramidAdjective
166 << " pyramid smoothing schedule is adjusted!\n Input schedule from configuration:\n"
167 << smoothingSchedule << "\n Adjusted schedule:\n"
168 << newSchedule);
169 }
170 }
171
172 // configuration.CountNumberOfParameterEntries( "ImagePyramidRescaleSchedule" );
173
177 /*bool useRescaleSchedule = true;
178 configuration.ReadParameter( useRescaleSchedule,
179 "UseImagePyramidRescaleSchedule", 0, false );
180 pyramid.SetUseMultiResolutionRescaleSchedule( useRescaleSchedule );*/
181
185 /*bool useSmoothingSchedule = true;
186 configuration.ReadParameter( useSmoothingSchedule,
187 "UseImagePyramidSmoothingSchedule", 0, false );
188 pyramid.SetUseMultiResolutionSmoothingSchedule( useSmoothingSchedule );*/
189
191 bool useShrinkImageFilter = false;
192 configuration.ReadParameter(useShrinkImageFilter, "ImagePyramidUseShrinkImageFilter", 0, false);
193 pyramid.SetUseShrinkImageFilter(useShrinkImageFilter);
194
199 bool computeThisResolution = false;
200 configuration.ReadParameter(computeThisResolution, "ComputePyramidImagesPerResolution", 0, false);
201 pyramid.SetComputeOnlyForCurrentLevel(computeThisResolution);
202 }
203};
204
205} // namespace elastix
206
207#endif
A class that deals with user given parameters and command line arguments.
bool ReadParameter(T &parameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool produceWarningMessage) const
static void SetSchedule(TPyramid &pyramid)


Generated on 2024-07-17 for elastix by doxygen 1.11.0 (9b424b03c9833626cd435af22a444888fbbb192d) elastix logo