Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes in file #1278

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
26 changes: 26 additions & 0 deletions Core/Kernel/elxComponentDatabase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "itkImage.h"
#include "itkSmartPointer.h"
#include "itkObject.h"
// Include the headers where FixedImageType and MovingImageType are defined
// If they are not defined elsewhere, define them here
// #include "itkFixedImageType.h"
// #include "itkMovingImageType.h"

namespace elastix
{

class ComponentDatabase : public itk::Object
{
public:

/** Types for the masks. */
using MaskPixelType = unsigned char;
// Define FixedImageType and MovingImageType if not defined elsewhere
using FixedImageType = itk::Image<float, 3>; // Example definition, adjust as necessary
using MovingImageType = itk::Image<float, 3>; // Example definition, adjust as necessary
using MaskImageType = itk::Image<MaskPixelType, itk::GetImageDimension<FixedImageType>::ImageDimension>;

};
} // end namespace elastix

#endif // end #ifndef elxComponentDatabase_h
23 changes: 23 additions & 0 deletions Core/Kernel/elxElastixBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,28 @@ ElastixBase::GetNumberOfTransformConfigurations() const
return m_TransformConfigurations.size();
}

void
ElastixBase::SetFixedWeightedMask(const MaskImageType * mask)
{
m_FixedWeightedMask = mask;
}

ElastixBase::MaskImageType *
ElastixBase::GetModifiableFixedWeightedMask()
{
return m_FixedWeightedMask;
}

void
ElastixBase::SetMovingWeightedMask(const MaskImageType * mask)
{
m_MovingWeightedMask = mask;
}

ElastixBase::MaskImageType *
ElastixBase::GetModifiableMovingWeightedMask()
{
return m_MovingWeightedMask;
}

} // end namespace elastix
15 changes: 15 additions & 0 deletions Core/Kernel/elxElastixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class ElastixBase
/** Typedef that is used in the elastix dll version. */
using ParameterMapType = itk::ParameterMapInterface::ParameterMapType;

/** Types for the masks. */
using MaskPixelType = unsigned char;
using MaskImageType = itk::Image<MaskPixelType, itk::GetImageDimension<FixedImageType>::ImageDimension>;

/** Set/Get the Configuration Object. */
elxGetObjectMacro(Configuration, Configuration);
elxSetObjectMacro(Configuration, Configuration);
Expand Down Expand Up @@ -299,6 +303,14 @@ class ElastixBase
elxSetObjectMacro(FinalTransform, itk::Object);
elxGetObjectMacro(FinalTransform, itk::Object);

/** Set/Get the fixed weighted mask. */
void SetFixedWeightedMask(const MaskImageType * mask);
MaskImageType * GetModifiableFixedWeightedMask();

/** Set/Get the moving weighted mask. */
void SetMovingWeightedMask(const MaskImageType * mask);
MaskImageType * GetModifiableMovingWeightedMask();

/** Empty Run()-function to be overridden. */
virtual int
Run() = 0;
Expand Down Expand Up @@ -540,6 +552,9 @@ class ElastixBase
* From Elastix 4.3 to 4.7: Ignore direction cosines by default, for
* backward compatability. From Elastix 4.8: set it to true by default. */
bool m_UseDirectionCosines{ true };

MaskImageType * m_FixedWeightedMask{ nullptr };
MaskImageType * m_MovingWeightedMask{ nullptr };
};

} // end namespace elastix
Expand Down
40 changes: 38 additions & 2 deletions Core/Kernel/elxElastixMain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ using itk::Deref;
/**
* ********************* Constructor ****************************
*/

ElastixMain::ElastixMain() = default;

/**
Expand Down Expand Up @@ -145,13 +144,15 @@ ElastixMain::Run()
return 1;
}

/** Set the images and masks. If not set by the user, it is not a problem.
/** Set the images, masks, and weighted masks. If not set by the user, it is not a problem.
* ElastixTemplate will try to load them from disk.
*/
elastixBase.SetFixedImageContainer(this->GetModifiableFixedImageContainer());
elastixBase.SetMovingImageContainer(this->GetModifiableMovingImageContainer());
elastixBase.SetFixedMaskContainer(this->GetModifiableFixedMaskContainer());
elastixBase.SetMovingMaskContainer(this->GetModifiableMovingMaskContainer());
elastixBase.SetFixedWeightedMask(this->GetModifiableFixedWeightedMask()); // Set fixed weighted mask
elastixBase.SetMovingWeightedMask(this->GetModifiableMovingWeightedMask()); // Set moving weighted mask
elastixBase.SetResultImageContainer(this->GetModifiableResultImageContainer());

elastixBase.SetFixedPoints(m_FixedPoints);
Expand Down Expand Up @@ -559,5 +560,40 @@ ElastixMain::GetImageInformationFromFile(const std::string & filename, ImageDime

} // end GetImageInformationFromFile()

/**
* ******************** SetFixedWeightedMask ********************
*/
void
ElastixMain::SetFixedWeightedMask(const MaskImageType * mask)
{
m_FixedWeightedMask = mask;
}

/**
* ******************** GetModifiableFixedWeightedMask ********************
*/
ElastixMain::MaskImageType *
ElastixMain::GetModifiableFixedWeightedMask()
{
return m_FixedWeightedMask;
}

/**
* ******************** SetMovingWeightedMask ********************
*/
void
ElastixMain::SetMovingWeightedMask(const MaskImageType * mask)
{
m_MovingWeightedMask = mask;
}

/**
* ******************** GetModifiableMovingWeightedMask ********************
*/
ElastixMain::MaskImageType *
ElastixMain::GetModifiableMovingWeightedMask()
{
return m_MovingWeightedMask;
}

} // end namespace elastix
22 changes: 21 additions & 1 deletion Core/Kernel/elxElastixMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#define elxElastixMain_h

#include "elxMainBase.h"

#include "itkImage.h"
#include "itkSmartPointer.h"
#include "itkObject.h"

namespace elastix
{
Expand Down Expand Up @@ -82,6 +84,7 @@ class ElastixMain : public MainBase
/** Run-time type information (and related methods). */
itkOverrideGetNameOfClassMacro(ElastixMain);


/** Set/Get functions for the fixed images
* (if these are not used, elastix tries to read them from disk,
* according to the command line parameters).
Expand All @@ -98,9 +101,23 @@ class ElastixMain : public MainBase
itkGetModifiableObjectMacro(FixedMaskContainer, DataObjectContainerType);
itkGetModifiableObjectMacro(MovingMaskContainer, DataObjectContainerType);

/** Set/Get functions for the fixed and moving weighted masks. */
itkSetObjectMacro(FixedWeightedMask, MaskImageType);
itkSetObjectMacro(MovingWeightedMask, MaskImageType);
itkGetModifiableObjectMacro(FixedWeightedMask, MaskImageType);
itkGetModifiableObjectMacro(MovingWeightedMask, MaskImageType);

itkSetConstObjectMacro(FixedPoints, itk::Object);
itkSetConstObjectMacro(MovingPoints, itk::Object);

/** Set/Get the fixed weighted mask. */
void SetFixedWeightedMask(const MaskImageType * mask);
MaskImageType * GetModifiableFixedWeightedMask();

/** Set/Get the moving weighted mask. */
void SetMovingWeightedMask(const MaskImageType * mask);
MaskImageType * GetModifiableMovingWeightedMask();

/** Get the final transform (the result of running elastix).
* You may pass this as an InitialTransform in an other instantiation
* of ElastixMain.
Expand Down Expand Up @@ -181,6 +198,9 @@ class ElastixMain : public MainBase
itk::SmartPointer<const itk::Object> m_FixedPoints{ nullptr };
itk::SmartPointer<const itk::Object> m_MovingPoints{ nullptr };

/** Weighted masks for fixed and moving images. */
MaskImageType::Pointer m_FixedWeightedMask;
MaskImageType::Pointer m_MovingWeightedMask;

/** A transform that is the result of registration. */
ObjectPointer m_FinalTransform{ nullptr };
Expand Down
11 changes: 11 additions & 0 deletions Core/Kernel/elxElastixTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <itkCommand.h>
#include <itkImage.h>
#include <itkObject.h>
#include "itkSmartPointer.h"

#include <sstream>

Expand Down Expand Up @@ -209,6 +210,16 @@ class ITK_TEMPLATE_EXPORT ElastixTemplate final : public ElastixBase
MovingMaskType *
GetMovingMask(unsigned int idx = 0) const;

/** Get pointers to the weighted masks. They are obtained from the
* {Fixed,Moving}WeightedMaskContainer and casted to the appropriate type.
*/

FixedMaskType *
GetFixedWeightedMask() const;

MovingMaskType *
GetMovingWeightedMask() const;

/** Main functions:
* Run() for registration, and ApplyTransform() for just
* applying a transform to an image.
Expand Down
18 changes: 18 additions & 0 deletions Core/Kernel/elxElastixTemplate.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,24 @@ ElastixTemplate<TFixedImage, TMovingImage>::GetMovingMask(unsigned int idx) cons

} // end SetMovingMask()

/**
* ********************** GetFixedWeightedMask *************************
*/
template <typename TFixedImage, typename TMovingImage>
typename ElastixTemplate<TFixedImage, TMovingImage>::FixedMaskType *
ElastixTemplate<TFixedImage, TMovingImage>::GetFixedWeightedMask() const
{
return dynamic_cast<FixedMaskType *>(this->GetModifiableFixedWeightedMask());
}
/**
* ********************** GetMovingWeightedMask *************************
*/
template <typename TFixedImage, typename TMovingImage>
typename ElastixTemplate<TFixedImage, TMovingImage>::MovingMaskType *
ElastixTemplate<TFixedImage, TMovingImage>::GetMovingWeightedMask() const
{
return dynamic_cast<MovingMaskType *>(this->GetModifiableMovingWeightedMask());
}

/**
* **************************** Run *****************************
Expand Down
10 changes: 10 additions & 0 deletions Core/Kernel/elxMainBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "itkParameterMapInterface.h"

#include <itkObject.h>
#include "itkImage.h"
#include "itkSmartPointer.h"
#include "itkObject.h"

// Standard C++ header files:
#include <fstream>
Expand Down Expand Up @@ -164,6 +167,13 @@ class MainBase : public itk::Object
static const ComponentDatabase &
GetComponentDatabase();

/** Types for the masks. */
using MaskPixelType = unsigned char;
// Define FixedImageType and MovingImageType if not defined elsewhere
using FixedImageType = itk::Image<float, 3>; // Example definition, adjust as necessary
using MovingImageType = itk::Image<float, 3>; // Example definition, adjust as necessary
using MaskImageType = itk::Image<MaskPixelType, itk::GetImageDimension<FixedImageType>::ImageDimension>;

protected:
MainBase();
~MainBase() override = 0;
Expand Down
28 changes: 28 additions & 0 deletions Core/Main/itkElastixRegistrationMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,34 @@ class ITK_TEMPLATE_EXPORT ElastixRegistrationMethod : public itk::ImageSource<TF
unsigned int
GetNumberOfMovingMasks() const;

/** Set/Add/Get/Remove/NumberOf fixed weighted masks. */
virtual void
AddFixedWeightedMask(FixedMaskType * fixedWeightedMask);
virtual void
SetFixedWeightedMask(FixedMaskType * fixedWeightedMask);
const FixedMaskType *
GetFixedWeightedMask() const;
const FixedMaskType *
GetFixedWeightedMask(const unsigned int index) const;
void
RemoveFixedWeightedMask();
unsigned int
GetNumberOfFixedWeightedMasks() const;

/** Set/Add/Get/Remove/NumberOf moving weighted masks. */
virtual void
SetMovingWeightedMask(MovingMaskType * movingWeightedMask);
virtual void
AddMovingWeightedMask(MovingMaskType * movingWeightedMask);
const MovingMaskType *
GetMovingWeightedMask() const;
const MovingMaskType *
GetMovingWeightedMask(const unsigned int index) const;
virtual void
RemoveMovingWeightedMask();
unsigned int
GetNumberOfMovingWeightedMasks() const;

itkSetConstObjectMacro(FixedPoints, PointContainerType<double>);
itkSetConstObjectMacro(MovingPoints, PointContainerType<double>);

Expand Down
Loading