Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Core/Configuration/elxConfiguration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,59 @@ Configuration::PrintParameterMap() const
<< "\n=============== end of ParameterMap ===============\n");

} // end PrintParameterMap()


/**
* ************************ AccessParameter ***************************
*/

void
Configuration::AccessParameter(const std::string & parameterName) const
{
std::size_t i{};

for (const auto & pair : m_ParameterMapInterface->GetParameterMap())
{
if (pair.first == parameterName)
{
// Conceptually, m_ParameterAccessFlags[i] is mutable.
m_ParameterAccessFlags[i] = true;
return;
}
++i;
}
Comment on lines +128 to +137
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is O(n), rather than O(1), but I don't think it's worth optimizing the performance of AccessParameter(parameterName). It should not be called inside a performance critical loop anyway.

}


/**
* ************************ AfterRegistration ***************************
*/

void
Configuration::AfterRegistration()
{
const auto & parameterMap = m_ParameterMapInterface->GetParameterMap();
const bool * const parameterAccessFlags = m_ParameterAccessFlags.get();

if (const auto numberOfUnusedParameters =
std::count(parameterAccessFlags, parameterAccessFlags + parameterMap.size(), false);
numberOfUnusedParameters > 0)
{
log::warn("WARNING: " + std::to_string(numberOfUnusedParameters) + " unused parameter(s) found!");
std::size_t i{};

for (const auto & pair : parameterMap)
{
if (!parameterAccessFlags[i])
{
log::warn(" Unused parameter: " + pair.first);
}
++i;
}
}
}


/**
* ************************ BeforeAll ***************************
*/
Expand Down Expand Up @@ -218,6 +271,8 @@ Configuration::Initialize(const CommandLineArgumentMapType & _arg)
m_ParameterMapInterface->SetParameterMap(
AddDataFromExternalTransformFile(m_ParameterFileName, parameterFileParser->GetParameterMap()));

m_ParameterAccessFlags = std::make_unique<bool[]>(m_ParameterMapInterface->GetParameterMap().size());

/** Silently check in the parameter file if error messages should be printed. */
m_ParameterMapInterface->SetPrintErrorMessages(false);
bool printErrorMessages = true;
Expand Down Expand Up @@ -254,6 +309,8 @@ Configuration::Initialize(const CommandLineArgumentMapType & _ar

m_ParameterMapInterface->SetParameterMap(AddDataFromExternalTransformFile(m_ParameterFileName, inputMap));

m_ParameterAccessFlags = std::make_unique<bool[]>(m_ParameterMapInterface->GetParameterMap().size());

/** Silently check in the parameter file if error messages should be printed. */
m_ParameterMapInterface->SetPrintErrorMessages(false);
bool printErrorMessages = true;
Expand Down
18 changes: 18 additions & 0 deletions Core/Configuration/elxConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Configuration
std::size_t
CountNumberOfParameterEntries(const std::string & parameterName) const
{
AccessParameter(parameterName);
return m_ParameterMapInterface->CountNumberOfParameterEntries(parameterName);
}

Expand All @@ -157,6 +158,7 @@ class Configuration
const unsigned int entry_nr,
const bool produceWarningMessage) const
{
AccessParameter(parameterName);
std::string warningMessage = "";
bool found = m_ParameterMapInterface->ReadParameter(
parameterValue, parameterName, entry_nr, produceWarningMessage, warningMessage);
Expand All @@ -174,6 +176,7 @@ class Configuration
bool
ReadParameter(T & parameterValue, const std::string & parameterName, const unsigned int entry_nr) const
{
AccessParameter(parameterName);
std::string warningMessage = "";
bool found = m_ParameterMapInterface->ReadParameter(parameterValue, parameterName, entry_nr, warningMessage);
if (!warningMessage.empty())
Expand All @@ -195,6 +198,7 @@ class Configuration
const int default_entry_nr,
const bool produceWarningMessage) const
{
AccessParameter(parameterName);
std::string warningMessage = "";
bool found = m_ParameterMapInterface->ReadParameter(
parameterValue, parameterName, prefix, entry_nr, default_entry_nr, produceWarningMessage, warningMessage);
Expand All @@ -216,6 +220,7 @@ class Configuration
const unsigned int entry_nr,
const int default_entry_nr) const
{
AccessParameter(parameterName);
std::string warningMessage = "";
bool found = m_ParameterMapInterface->ReadParameter(
parameterValue, parameterName, prefix, entry_nr, default_entry_nr, warningMessage);
Expand All @@ -232,6 +237,7 @@ class Configuration
bool
HasParameter(const std::string & parameterName) const
{
AccessParameter(parameterName);
return m_ParameterMapInterface->HasParameter(parameterName);
}

Expand All @@ -240,6 +246,7 @@ class Configuration
std::vector<std::string>
GetValuesOfParameter(const std::string & parameterName) const
{
AccessParameter(parameterName);
return m_ParameterMapInterface->GetValues(parameterName);
}

Expand All @@ -253,6 +260,7 @@ class Configuration
std::unique_ptr<std::vector<T>>
RetrieveValuesOfParameter(const std::string & parameterName) const
{
AccessParameter(parameterName);
return m_ParameterMapInterface->RetrieveValues<T>(parameterName);
}

Expand Down Expand Up @@ -292,6 +300,7 @@ class Configuration
const unsigned int entry_nr_end,
const bool produceWarningMessage) const
{
AccessParameter(parameterName);
std::string warningMessage = "";
bool found = m_ParameterMapInterface->ReadParameter(
parameterValues, parameterName, entry_nr_start, entry_nr_end, produceWarningMessage, warningMessage);
Expand Down Expand Up @@ -320,10 +329,19 @@ class Configuration
PrintParameterMap() const;

private:
void
AccessParameter(const std::string & parameterName) const;

void
AfterRegistration() override;

CommandLineArgumentMapType m_CommandLineArgumentMap{};
std::string m_ParameterFileName{};
const itk::ParameterMapInterface::Pointer m_ParameterMapInterface{ itk::ParameterMapInterface::New() };

// Tells for each parameter whether it is accessed.
std::unique_ptr<bool[]> m_ParameterAccessFlags;

bool m_IsInitialized{ false };
unsigned int m_ElastixLevel{ 0 };
unsigned int m_TotalNumberOfElastixLevels{ 1 };
Expand Down
Loading