Loading...
Searching...
No Matches
elxGenericPyramidHelper.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef elxGenericPyramidHelper_h
#define elxGenericPyramidHelper_h
#include <string> // For is_same.
#include <type_traits> // For is_same.
#include "elxConfiguration.h"
#include <itkDeref.h>
namespace elastix
{
template <class TElastix>
class FixedGenericPyramid;
template <class TElastix>
class MovingGenericPyramid;
class GenericPyramidHelper
{
public:
template <typename TPyramid>
static void
SetSchedule(TPyramid & pyramid)
{
using ElastixType = typename TPyramid::ElastixType;
constexpr bool isFixed = std::is_same_v<TPyramid, FixedGenericPyramid<ElastixType>>;
constexpr bool isMoving = std::is_same_v<TPyramid, MovingGenericPyramid<ElastixType>>;
static_assert(isMoving != isFixed, "TPyramid must be either FixedGenericPyramid or MovingGenericPyramid!");
const std::string parameterPrefix = isFixed ? "Fixed" : "Moving";
constexpr const char * pyramidAdjective = isFixed ? "fixed" : "moving";
// It is assumed for more than ten years already that the configuration is not null, looking at
// "src/Components/FixedImagePyramids/FixedGenericPyramid/elxFixedGenericPyramid.hxx" revision
// f84ac0d1094ebdb13e456b1b8cf1f6f9bfcd0a38 "ENH: First checkin of a generic pyramid...", Marius Staring, 2012-02-02
const Configuration & configuration = itk::Deref(pyramid.GetConfiguration());
const unsigned int ImageDimension = TPyramid::ImageDimension;
unsigned int numberOfResolutions = 3;
configuration.ReadParameter(numberOfResolutions, "NumberOfResolutions", 0, true);
if (numberOfResolutions == 0)
{
itkGenericExceptionMacro("The NumberOfResolutions parameter must have a non-zero value!");
}
pyramid.GetAsITKBaseType()->SetNumberOfLevels(numberOfResolutions);
typename TPyramid::RescaleScheduleType rescaleSchedule = pyramid.GetRescaleSchedule();
typename TPyramid::SmoothingScheduleType smoothingSchedule = pyramid.GetSmoothingSchedule();
bool foundRescale = true;
for (unsigned int i = 0; i < numberOfResolutions; ++i)
{
for (unsigned int j = 0; j < ImageDimension; ++j)
{
bool ijfound = false;
const unsigned int entrynr = i * ImageDimension + j;
ijfound |= configuration.ReadParameter(rescaleSchedule[i][j], "ImagePyramidRescaleSchedule", entrynr, false);
ijfound |= configuration.ReadParameter(rescaleSchedule[i][j], "ImagePyramidSchedule", entrynr, false);
ijfound |= configuration.ReadParameter(
rescaleSchedule[i][j], parameterPrefix + "ImagePyramidRescaleSchedule", entrynr, false);
ijfound |=
configuration.ReadParameter(rescaleSchedule[i][j], parameterPrefix + "ImagePyramidSchedule", entrynr, false);
foundRescale &= ijfound;
} // end for ImageDimension
} // end for numberOfResolutions
if (!foundRescale && pyramid.GetConfiguration()->GetPrintErrorMessages())
{
log::warn(std::ostringstream{} << "WARNING: the " << pyramidAdjective
<< " pyramid rescale schedule is not fully specified!\n"
<< " A default pyramid rescale schedule is used.");
}
else
{
pyramid.SetRescaleSchedule(rescaleSchedule);
const auto newSchedule = pyramid.GetRescaleSchedule();
if (newSchedule != rescaleSchedule)
{
log::warn(
std::ostringstream{} << "WARNING: the " << pyramidAdjective
<< " pyramid rescale schedule is adjusted!\n Input schedule from configuration:\n"
<< rescaleSchedule << "\n Adjusted schedule:\n"
<< newSchedule);
}
}
bool foundSmoothing = true;
for (unsigned int i = 0; i < numberOfResolutions; ++i)
{
for (unsigned int j = 0; j < ImageDimension; ++j)
{
bool ijfound = false;
const unsigned int entrynr = i * ImageDimension + j;
ijfound |=
configuration.ReadParameter(smoothingSchedule[i][j], "ImagePyramidSmoothingSchedule", entrynr, false);
ijfound |= configuration.ReadParameter(
smoothingSchedule[i][j], parameterPrefix + "ImagePyramidSmoothingSchedule", entrynr, false);
foundSmoothing &= ijfound;
} // end for ImageDimension
} // end for numberOfResolutions
if (!foundSmoothing && pyramid.GetConfiguration()->GetPrintErrorMessages())
{
log::warn(std::ostringstream{} << "WARNING: the " << pyramidAdjective
<< " pyramid smoothing schedule is not fully specified!\n"
<< " A default pyramid smoothing schedule is used.");
}
else
{
pyramid.SetSmoothingSchedule(smoothingSchedule);
const auto newSchedule = pyramid.GetSmoothingSchedule();
if (newSchedule != smoothingSchedule)
{
log::warn(
std::ostringstream{} << "WARNING: the " << pyramidAdjective
<< " pyramid smoothing schedule is adjusted!\n Input schedule from configuration:\n"
<< smoothingSchedule << "\n Adjusted schedule:\n"
<< newSchedule);
}
}
// configuration.CountNumberOfParameterEntries( "ImagePyramidRescaleSchedule" );
/*bool useRescaleSchedule = true;
configuration.ReadParameter( useRescaleSchedule,
"UseImagePyramidRescaleSchedule", 0, false );
pyramid.SetUseMultiResolutionRescaleSchedule( useRescaleSchedule );*/
/*bool useSmoothingSchedule = true;
configuration.ReadParameter( useSmoothingSchedule,
"UseImagePyramidSmoothingSchedule", 0, false );
pyramid.SetUseMultiResolutionSmoothingSchedule( useSmoothingSchedule );*/
bool useShrinkImageFilter = false;
configuration.ReadParameter(useShrinkImageFilter, "ImagePyramidUseShrinkImageFilter", 0, false);
pyramid.SetUseShrinkImageFilter(useShrinkImageFilter);
bool computeThisResolution = false;
configuration.ReadParameter(computeThisResolution, "ComputePyramidImagesPerResolution", 0, false);
pyramid.SetComputeOnlyForCurrentLevel(computeThisResolution);
}
};
} // namespace elastix
#endif
elastix::Configuration
A class that deals with user given parameters and command line arguments.
Definition elxConfiguration.h:53
elastix::Configuration::ReadParameter
bool ReadParameter(T &parameterValue, const std::string &parameterName, const unsigned int entry_nr, const bool produceWarningMessage) const
Definition elxConfiguration.h:150
elastix::FixedGenericPyramid
A pyramid based on the itk::GenericMultiResolutionPyramidImageFilter.
Definition elxFixedGenericPyramid.h:72
elastix::GenericPyramidHelper
Definition elxGenericPyramidHelper.h:37
elastix::GenericPyramidHelper::SetSchedule
static void SetSchedule(TPyramid &pyramid)
Definition elxGenericPyramidHelper.h:42
elastix::MovingGenericPyramid
A pyramid based on the itk::GenericMultiResolutionPyramidImageFilter.
Definition elxMovingGenericPyramid.h:72
elastix::log::level::warn
@ warn
Definition elxlog.h:37
elxConfiguration.h
elastix
Definition elxDefaultConstruct.h:25

Generated on 1768596610 for elastix by 1.15.0 |