go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
Loading...
Searching...
No Matches
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
26namespace elastix
27{
28template <class TElastix>
29class FixedGenericPyramid;
30
31template <class TElastix>
32class MovingGenericPyramid;
33
36{
37public:
39 template <typename TPyramid>
40 static void
41 SetSchedule(TPyramid & pyramid)
42 {
43 using ElastixType = typename TPyramid::ElastixType;
44
45 constexpr bool isFixed = std::is_same<TPyramid, FixedGenericPyramid<ElastixType>>::value;
46 constexpr bool isMoving = std::is_same<TPyramid, MovingGenericPyramid<ElastixType>>::value;
47
48 static_assert(isMoving != isFixed, "TPyramid must be either FixedGenericPyramid or MovingGenericPyramid!");
49
50 const std::string parameterPrefix = isFixed ? "Fixed" : "Moving";
51 constexpr const char * pyramidAdjective = isFixed ? "fixed" : "moving";
52
53 // It is assumed for more than ten years already that the configuration is not null, looking at
54 // "src/Components/FixedImagePyramids/FixedGenericPyramid/elxFixedGenericPyramid.hxx" revision
55 // f84ac0d1094ebdb13e456b1b8cf1f6f9bfcd0a38 "ENH: First checkin of a generic pyramid...", Marius Staring, 2012-02-02
56
57 Configuration & configuration = *(pyramid.GetConfiguration());
58
60 const unsigned int ImageDimension = TPyramid::ImageDimension;
61
63 unsigned int numberOfResolutions = 3;
64 configuration.ReadParameter(numberOfResolutions, "NumberOfResolutions", 0, true);
65 if (numberOfResolutions == 0)
66 {
67 numberOfResolutions = 1;
68 }
69
71 pyramid.GetAsITKBaseType()->SetNumberOfLevels(numberOfResolutions);
72 typename TPyramid::RescaleScheduleType rescaleSchedule = pyramid.GetRescaleSchedule();
73 typename TPyramid::SmoothingScheduleType smoothingSchedule = pyramid.GetSmoothingSchedule();
74
82 bool foundRescale = true;
83 for (unsigned int i = 0; i < numberOfResolutions; ++i)
84 {
85 for (unsigned int j = 0; j < ImageDimension; ++j)
86 {
87 bool ijfound = false;
88 const unsigned int entrynr = i * ImageDimension + j;
89 ijfound |= configuration.ReadParameter(rescaleSchedule[i][j], "ImagePyramidRescaleSchedule", entrynr, false);
90 ijfound |= configuration.ReadParameter(rescaleSchedule[i][j], "ImagePyramidSchedule", entrynr, false);
91 ijfound |= configuration.ReadParameter(
92 rescaleSchedule[i][j], parameterPrefix + "ImagePyramidRescaleSchedule", entrynr, false);
93 ijfound |=
94 configuration.ReadParameter(rescaleSchedule[i][j], parameterPrefix + "ImagePyramidSchedule", entrynr, false);
95
97 foundRescale &= ijfound;
98
99 } // end for ImageDimension
100 } // end for numberOfResolutions
101
102 if (!foundRescale && pyramid.GetConfiguration()->GetPrintErrorMessages())
103 {
104 xl::xout["warning"] << "WARNING: the " << pyramidAdjective
105 << " pyramid rescale schedule is not fully specified!\n";
106 xl::xout["warning"] << " A default pyramid rescale schedule is used." << std::endl;
107 }
108 else
109 {
111 pyramid.SetRescaleSchedule(rescaleSchedule);
112
113 const auto newSchedule = pyramid.GetRescaleSchedule();
114
115 if (newSchedule != rescaleSchedule)
116 {
117 xl::xout["warning"] << "WARNING: the " << pyramidAdjective
118 << " pyramid rescale schedule is adjusted!\n Input schedule from configuration:\n"
119 << rescaleSchedule << "\n Adjusted schedule:\n"
120 << newSchedule << std::endl;
121 }
122 }
123
129 bool foundSmoothing = true;
130 for (unsigned int i = 0; i < numberOfResolutions; ++i)
131 {
132 for (unsigned int j = 0; j < ImageDimension; ++j)
133 {
134 bool ijfound = false;
135 const unsigned int entrynr = i * ImageDimension + j;
136 ijfound |=
137 configuration.ReadParameter(smoothingSchedule[i][j], "ImagePyramidSmoothingSchedule", entrynr, false);
138 ijfound |= configuration.ReadParameter(
139 smoothingSchedule[i][j], parameterPrefix + "ImagePyramidSmoothingSchedule", entrynr, false);
140
142 foundSmoothing &= ijfound;
143
144 } // end for ImageDimension
145 } // end for numberOfResolutions
146
147 if (!foundSmoothing && pyramid.GetConfiguration()->GetPrintErrorMessages())
148 {
149 xl::xout["warning"] << "WARNING: the " << pyramidAdjective
150 << " pyramid smoothing schedule is not fully specified!\n";
151 xl::xout["warning"] << " A default pyramid smoothing schedule is used." << std::endl;
152 }
153 else
154 {
156 pyramid.SetSmoothingSchedule(smoothingSchedule);
157
158 const auto newSchedule = pyramid.GetSmoothingSchedule();
159
160 if (newSchedule != smoothingSchedule)
161 {
162 xl::xout["warning"] << "WARNING: the " << pyramidAdjective
163 << " pyramid smoothing schedule is adjusted!\n Input schedule from configuration:\n"
164 << smoothingSchedule << "\n Adjusted schedule:\n"
165 << newSchedule << std::endl;
166 }
167 }
168
169 // configuration.CountNumberOfParameterEntries( "ImagePyramidRescaleSchedule" );
170
174 /*bool useRescaleSchedule = true;
175 configuration.ReadParameter( useRescaleSchedule,
176 "UseImagePyramidRescaleSchedule", 0, false );
177 pyramid.SetUseMultiResolutionRescaleSchedule( useRescaleSchedule );*/
178
182 /*bool useSmoothingSchedule = true;
183 configuration.ReadParameter( useSmoothingSchedule,
184 "UseImagePyramidSmoothingSchedule", 0, false );
185 pyramid.SetUseMultiResolutionSmoothingSchedule( useSmoothingSchedule );*/
186
188 bool useShrinkImageFilter = false;
189 configuration.ReadParameter(useShrinkImageFilter, "ImagePyramidUseShrinkImageFilter", 0, false);
190 pyramid.SetUseShrinkImageFilter(useShrinkImageFilter);
191
196 bool computeThisResolution = false;
197 configuration.ReadParameter(computeThisResolution, "ComputePyramidImagesPerResolution", 0, false);
198 pyramid.SetComputeOnlyForCurrentLevel(computeThisResolution);
199 }
200};
201
202} // namespace elastix
203
204#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 printThisErrorMessage) const
static void SetSchedule(TPyramid &pyramid)


Generated on 1711392802 for elastix by doxygen 1.9.8 elastix logo