Skip to content

Commit

Permalink
ENH: Support "ShowProgressPercentage" parameter (false by default)
Browse files Browse the repository at this point in the history
Allows enabling showing progress percentages at the console (standard output), by adding the following elastix parameter:

    (ShowProgressPercentage "true")

Discussed with Marius Staring.
  • Loading branch information
N-Dekker committed Mar 13, 2023
1 parent e39de3a commit 05d2b40
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -852,10 +852,13 @@ AdaptiveStochasticGradientDescent<TElastix>::SampleGradients(const ParametersTyp

} // end if NewSamplesEveryIteration.

const Configuration & configuration = Deref(Superclass2::GetConfiguration());

/** Prepare for progress printing. */
const auto progressObserver = BaseComponent::IsElastixLibrary()
? nullptr
: ProgressCommand::CreateAndSetUpdateFrequency(this->m_NumberOfGradientMeasurements);
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver = showProgressPercentage
? ProgressCommand::CreateAndSetUpdateFrequency(this->m_NumberOfGradientMeasurements)
: nullptr;
log::info(" Sampling gradients ...");

/** Initialize some variables for storing gradients and their magnitudes. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,13 @@ PreconditionedStochasticGradientDescent<TElastix>::SampleGradients(const Paramet

} // end if NewSamplesEveryIteration.

const Configuration & configuration = Deref(Superclass2::GetConfiguration());

/** Prepare for progress printing. */
const auto progressObserver = BaseComponent::IsElastixLibrary()
? nullptr
: ProgressCommand::CreateAndSetUpdateFrequency(this->m_NumberOfGradientMeasurements);
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver = showProgressPercentage
? ProgressCommand::CreateAndSetUpdateFrequency(this->m_NumberOfGradientMeasurements)
: nullptr;
log::info(" Sampling gradients ...");

/** Initialize some variables for storing gradients and their magnitudes. */
Expand Down
15 changes: 9 additions & 6 deletions Core/ComponentBaseClasses/elxResamplerBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,12 @@ ResamplerBase<TElastix>::ResampleAndWriteResultImage(const char * filename, cons
/** Make sure the resampler is updated. */
resampleImageFilter.Modified();

const Configuration & configuration = Deref(Superclass::GetConfiguration());

/** Add a progress observer to the resampler. */
const auto progressObserver = (!showProgress || BaseComponent::IsElastixLibrary())
? nullptr
: ProgressCommand::CreateAndConnect(resampleImageFilter);
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver =
(showProgress && showProgressPercentage) ? ProgressCommand::CreateAndConnect(resampleImageFilter) : nullptr;

/** Do the resampling. */
try
Expand Down Expand Up @@ -423,8 +425,11 @@ ResamplerBase<TElastix>::CreateItkResultImage()
/** Make sure the resampler is updated. */
resampleImageFilter.Modified();

const Configuration & configuration = Deref(Superclass::GetConfiguration());

const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver =
BaseComponent::IsElastixLibrary() ? nullptr : ProgressCommand::CreateAndConnect(*(this->GetAsITKBaseType()));
showProgressPercentage ? ProgressCommand::CreateAndConnect(*(this->GetAsITKBaseType())) : nullptr;

/** Do the resampling. */
try
Expand Down Expand Up @@ -455,8 +460,6 @@ ResamplerBase<TElastix>::CreateItkResultImage()
resampleImageFilter.SetTransform(testptr->GetTransform());
}

const Configuration & configuration = Deref(Superclass::GetConfiguration());

/** Read output pixeltype from parameter the file. */
std::string resultImagePixelType = "short";
configuration.ReadParameter(resultImagePixelType, "ResultImagePixelType", 0, false);
Expand Down
14 changes: 8 additions & 6 deletions Core/ComponentBaseClasses/elxTransformBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,11 @@ TransformBase<TElastix>::GenerateDeformationFieldImage() const -> typename Defor
infoChanger->SetChangeDirection(retdc & !this->GetElastix()->GetUseDirectionCosines());
infoChanger->SetInput(defGenerator->GetOutput());

const Configuration & configuration = Deref(Superclass::GetConfiguration());

/** Track the progress of the generation of the deformation field. */
const auto progressObserver =
BaseComponent::IsElastixLibrary() ? nullptr : ProgressCommand::CreateAndConnect(*defGenerator);
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver = showProgressPercentage ? ProgressCommand::CreateAndConnect(*defGenerator) : nullptr;

try
{
Expand Down Expand Up @@ -1110,8 +1112,8 @@ TransformBase<TElastix>::ComputeAndWriteSpatialJacobianDeterminantImage() const
const auto infoChanger = CreateChangeInformationImageFilter(jacGenerator->GetOutput());

/** Track the progress of the generation of the deformation field. */
const auto progressObserver =
BaseComponent::IsElastixLibrary() ? nullptr : ProgressCommand::CreateAndConnect(*jacGenerator);
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver = showProgressPercentage ? ProgressCommand::CreateAndConnect(*jacGenerator) : nullptr;
/** Create a name for the deformation field file. */
std::string resultImageFormat = "mhd";
configuration.ReadParameter(resultImageFormat, "ResultImageFormat", 0, false);
Expand Down Expand Up @@ -1164,8 +1166,8 @@ TransformBase<TElastix>::ComputeAndWriteSpatialJacobianMatrixImage() const

const auto infoChanger = CreateChangeInformationImageFilter(jacGenerator->GetOutput());

const auto progressObserver =
BaseComponent::IsElastixLibrary() ? nullptr : ProgressCommand::CreateAndConnect(*jacGenerator);
const bool showProgressPercentage = configuration.RetrieveParameterValue(false, "ShowProgressPercentage", 0, false);
const auto progressObserver = showProgressPercentage ? ProgressCommand::CreateAndConnect(*jacGenerator) : nullptr;
/** Create a name for the deformation field file. */
std::string resultImageFormat = "mhd";
configuration.ReadParameter(resultImageFormat, "ResultImageFormat", 0, false);
Expand Down

0 comments on commit 05d2b40

Please sign in to comment.