Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ WeightedCombinationTransformElastix<TElastix>::LoadSubTransforms(void)
/** Create a SubTransform. */
typename ObjectType::Pointer subTransform;
PtrToCreator testcreator = nullptr;
testcreator =
this->GetElastix()->GetComponentDatabase()->GetCreator(subTransformName, this->m_Elastix->GetDBIndex());
testcreator = ElastixMain::GetComponentDatabase().GetCreator(subTransformName, this->m_Elastix->GetDBIndex());

// Note that ObjectType::Pointer() yields a default-constructed SmartPointer (null).
subTransform = testcreator ? testcreator() : typename ObjectType::Pointer();
Expand Down
3 changes: 2 additions & 1 deletion Core/ComponentBaseClasses/elxTransformBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define elxTransformBase_hxx

#include "elxTransformBase.h"
#include "elxElastixMain.h"
#include "elxTransformIO.h"

#include "itkPointSet.h"
Expand Down Expand Up @@ -548,7 +549,7 @@ TransformBase<TElastix>::ReadInitialTransformFromConfiguration(

/** Create an InitialTransform. */
const PtrToCreator testcreator =
this->GetElastix()->GetComponentDatabase()->GetCreator(initialTransformName, this->m_Elastix->GetDBIndex());
ElastixMain::GetComponentDatabase().GetCreator(initialTransformName, this->m_Elastix->GetDBIndex());
const ObjectType::Pointer initialTransform = (testcreator == nullptr) ? nullptr : testcreator();

const auto elx_initialTransform = dynamic_cast<Self *>(initialTransform.GetPointer());
Expand Down
23 changes: 1 addition & 22 deletions Core/Install/elxComponentLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ ComponentLoader::ComponentLoader()
* ****************** Destructor *********************************
*/

ComponentLoader::~ComponentLoader()
{
this->UnloadComponents();
}
ComponentLoader::~ComponentLoader() = default;


/**
Expand Down Expand Up @@ -160,22 +157,4 @@ ComponentLoader::LoadComponents(void)

} // end LoadComponents


/**
* ****************** UnloadComponents ****************************
*/

void
ComponentLoader::UnloadComponents()
{
/**
* This function used to be more useful when we still used .dll's.
*/

// Not necessary I think:
// this->m_ComponentDatabase = 0;

} // end UnloadComponents


} // end namespace elastix
4 changes: 0 additions & 4 deletions Core/Install/elxComponentLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ class ComponentLoader : public itk::Object
int
LoadComponents(void);

/** Function to unload components. */
void
UnloadComponents(void);

protected:
/** Standard constructor and destructor. */
ComponentLoader();
Expand Down
1 change: 0 additions & 1 deletion Core/Kernel/elxElastixBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ ElastixBase::ElastixBase()
{
/** Initialize. */
this->m_Configuration = nullptr;
this->m_ComponentDatabase = nullptr;
this->m_DBIndex = 0;

/** The default output precision of elxout is set to 6. */
Expand Down
13 changes: 2 additions & 11 deletions Core/Kernel/elxElastixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ class ElastixBase
return this->m_DBIndex;
}


/** Functions to get/set the ComponentDatabase
* The component database contains pointers to functions
* that create components.
*/
elxGetObjectMacro(ComponentDatabase, ComponentDatabaseType);
elxSetObjectMacro(ComponentDatabase, ComponentDatabaseType);

/** Get the component containers.
* The component containers store components, such as
* the metric, in the form of an itk::Object::Pointer.
Expand Down Expand Up @@ -397,9 +389,8 @@ class ElastixBase
ElastixBase();
~ElastixBase() override = default;

ConfigurationPointer m_Configuration;
DBIndexType m_DBIndex;
ComponentDatabasePointer m_ComponentDatabase;
ConfigurationPointer m_Configuration;
DBIndexType m_DBIndex;

FlatDirectionCosinesType m_OriginalFixedImageDirection;

Expand Down
108 changes: 30 additions & 78 deletions Core/Kernel/elxElastixMain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#endif

#include "elxElastixMain.h"
#include "elxComponentLoader.h"

#include "elxMacro.h"
#include "itkPlatformMultiThreader.h"
Expand Down Expand Up @@ -182,12 +183,27 @@ ElastixMain::ElastixMain()


/**
* ****************** Initialization of static members *********
* ****************** GetComponentDatabase *********
*/

// Both s_CDB and s_ComponentLoader are defaulted-constructed to null.
ElastixMain::ComponentDatabasePointer ElastixMain::s_CDB;
ElastixMain::ComponentLoaderPointer ElastixMain::s_ComponentLoader;
const ComponentDatabase &
ElastixMain::GetComponentDatabase(void)
{
// Improved thread-safety by using C++11 "magic statics".
static const auto componentDatabase = [] {
const auto componentDatabase = ComponentDatabase::New();
const auto componentLoader = ComponentLoader::New();
componentLoader->SetComponentDatabase(componentDatabase);

if (componentLoader->LoadComponents() != 0)
{
xout["error"] << "Loading components failed" << std::endl;
}
return componentDatabase;
}();
return *componentDatabase;
}


/**
* ********************** Destructor ****************************
Expand Down Expand Up @@ -338,7 +354,6 @@ ElastixMain::Run(void)

/** Set some information in the ElastixBase. */
this->GetElastixBase()->SetConfiguration(this->m_Configuration);
this->GetElastixBase()->SetComponentDatabase(this->s_CDB);
this->GetElastixBase()->SetDBIndex(this->m_DBIndex);

/** Populate the component containers. ImageSampler is not mandatory.
Expand Down Expand Up @@ -635,32 +650,18 @@ ElastixMain::InitDBIndex(void)
}
}

/** Load the components. */
if (this->s_CDB.IsNull())
/** Get the DBIndex from the ComponentDatabase. */
this->m_DBIndex = GetComponentDatabase().GetIndex(this->m_FixedImagePixelType,
this->m_FixedImageDimension,
this->m_MovingImagePixelType,
this->m_MovingImageDimension);
if (this->m_DBIndex == 0)
{
int loadReturnCode = this->LoadComponents();
if (loadReturnCode != 0)
{
xout["error"] << "Loading components failed" << std::endl;
return loadReturnCode;
}
xout["error"] << "ERROR:" << std::endl;
xout["error"] << "Something went wrong in the ComponentDatabase" << std::endl;
return 1;
}

if (this->s_CDB.IsNotNull())
{
/** Get the DBIndex from the ComponentDatabase. */
this->m_DBIndex = this->s_CDB->GetIndex(this->m_FixedImagePixelType,
this->m_FixedImageDimension,
this->m_MovingImagePixelType,
this->m_MovingImageDimension);
if (this->m_DBIndex == 0)
{
xout["error"] << "ERROR:" << std::endl;
xout["error"] << "Something went wrong in the ComponentDatabase" << std::endl;
return 1;
}
} // end if s_CDB!=0

} // end if m_Configuration->Initialized();
else
{
Expand Down Expand Up @@ -727,55 +728,6 @@ ElastixMain::GetTotalNumberOfElastixLevels(void)
} // end GetTotalNumberOfElastixLevels()


/**
* ********************* LoadComponents **************************
*
* Store the install function of each component in the
* component database.
*/

int
ElastixMain::LoadComponents(void)
{
/** Create a ComponentDatabase. */
if (this->s_CDB.IsNull())
{
this->s_CDB = ComponentDatabaseType::New();
}

/** Create a ComponentLoader and set the database. */
if (this->s_ComponentLoader.IsNull())
{
this->s_ComponentLoader = ComponentLoaderType::New();
this->s_ComponentLoader->SetComponentDatabase(s_CDB);
}

/** Load the components. */
return this->s_ComponentLoader->LoadComponents();

} // end LoadComponents()


/**
* ********************* UnloadComponents **************************
*/

void
ElastixMain::UnloadComponents(void)
{
s_CDB = nullptr;
s_ComponentLoader->SetComponentDatabase(nullptr);

if (s_ComponentLoader)
{
s_ComponentLoader->UnloadComponents();
}

s_ComponentLoader = nullptr;

} // end UnloadComponents()


/**
* ************************* GetElastixBase ***************************
*/
Expand Down Expand Up @@ -806,7 +758,7 @@ ElastixMain::CreateComponent(const ComponentDescriptionType & name)
{
/** A pointer to the New() function. */
PtrToCreator testcreator = nullptr;
testcreator = this->s_CDB->GetCreator(name, this->m_DBIndex);
testcreator = GetComponentDatabase().GetCreator(name, this->m_DBIndex);

// Note that ObjectPointer() yields a default-constructed SmartPointer (null).
ObjectPointer testpointer = testcreator ? testcreator() : ObjectPointer();
Expand Down
33 changes: 3 additions & 30 deletions Core/Kernel/elxElastixMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define elxElastixMain_h

#include "elxComponentDatabase.h"
#include "elxComponentLoader.h"

#include "elxElastixBase.h"
#include "itkParameterMapInterface.h"
Expand Down Expand Up @@ -169,10 +168,6 @@ class ElastixMain : public itk::Object
typedef ComponentDatabaseType::ImageDimensionType ImageDimensionType;
typedef ComponentDatabaseType::IndexType DBIndexType;

/** Typedef for class that populates a ComponentDatabase. */
typedef ComponentLoader ComponentLoaderType;
typedef ComponentLoaderType::Pointer ComponentLoaderPointer;

/** Typedef that is used in the elastix dll version. */
typedef itk::ParameterMapInterface::ParameterMapType ParameterMapType;

Expand Down Expand Up @@ -315,31 +310,14 @@ class ElastixMain : public itk::Object
virtual void
SetMaximumNumberOfThreads(void) const;

/** Functions to get/set the ComponentDatabase. */
static ComponentDatabase *
GetComponentDatabase(void)
{
return s_CDB.GetPointer();
}


static void
SetComponentDatabase(ComponentDatabase * arg)
{
if (s_CDB != arg)
{
s_CDB = arg;
}
}

/** Function to get the ComponentDatabase. */
static const ComponentDatabase &
GetComponentDatabase(void);

/** GetTransformParametersMap */
virtual ParameterMapType
GetTransformParametersMap(void) const;

static void
UnloadComponents(void);

protected:
ElastixMain();
~ElastixMain() override;
Expand Down Expand Up @@ -383,11 +361,6 @@ class ElastixMain : public itk::Object

FlatDirectionCosinesType m_OriginalFixedImageDirection;

static ComponentDatabasePointer s_CDB;
static ComponentLoaderPointer s_ComponentLoader;
virtual int
LoadComponents(void);

/** InitDBIndex sets m_DBIndex by asking the ImageTypes
* from the Configuration object and obtaining the corresponding
* DB index from the ComponentDatabase.
Expand Down
33 changes: 9 additions & 24 deletions Core/Kernel/elxTransformixMain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ TransformixMain::Run(void)

/** Set some information in the ElastixBase. */
this->GetElastixBase()->SetConfiguration(this->m_Configuration);
this->GetElastixBase()->SetComponentDatabase(this->s_CDB);
this->GetElastixBase()->SetDBIndex(this->m_DBIndex);

/** Populate the component containers. No default is specified for the Transform. */
Expand Down Expand Up @@ -268,32 +267,18 @@ TransformixMain::InitDBIndex(void)
}
}

/** Load the components. */
if (this->s_CDB.IsNull())
/** Get the DBIndex from the ComponentDatabase. */
this->m_DBIndex = this->GetComponentDatabase().GetIndex(this->m_FixedImagePixelType,
this->m_FixedImageDimension,
this->m_MovingImagePixelType,
this->m_MovingImageDimension);
if (this->m_DBIndex == 0)
{
int loadReturnCode = this->LoadComponents();
if (loadReturnCode != 0)
{
xl::xout["error"] << "Loading components failed" << std::endl;
return loadReturnCode;
}
xl::xout["error"] << "ERROR:" << std::endl;
xl::xout["error"] << "Something went wrong in the ComponentDatabase." << std::endl;
return 1;
}

if (this->s_CDB.IsNotNull())
{
/** Get the DBIndex from the ComponentDatabase. */
this->m_DBIndex = this->s_CDB->GetIndex(this->m_FixedImagePixelType,
this->m_FixedImageDimension,
this->m_MovingImagePixelType,
this->m_MovingImageDimension);
if (this->m_DBIndex == 0)
{
xl::xout["error"] << "ERROR:" << std::endl;
xl::xout["error"] << "Something went wrong in the ComponentDatabase." << std::endl;
return 1;
}
} // end if s_CDB!=0

} // end if m_Configuration->Initialized();
else
{
Expand Down
4 changes: 0 additions & 4 deletions Core/Kernel/elxTransformixMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ class TransformixMain : public ElastixMain
typedef Superclass::ImageDimensionType ImageDimensionType;
typedef Superclass::DBIndexType DBIndexType;

/** Typedef for class that populates a ComponentDatabase. */
typedef Superclass::ComponentLoaderType ComponentLoaderType;
typedef Superclass::ComponentLoaderPointer ComponentLoaderPointer;

/** Typedef that is used in the elastix dll version. */
typedef Superclass::ParameterMapType ParameterMapType;

Expand Down
3 changes: 0 additions & 3 deletions Core/Main/elastix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ main(int argc, char ** argv)
fixedMaskContainer = nullptr;
movingMaskContainer = nullptr;

/** Close the modules. */
ElastixMainType::UnloadComponents();

/** Exit and return the error code. */
return 0;

Expand Down
Loading