diff --git a/Core/Kernel/elxComponentDatabase.h b/Core/Kernel/elxComponentDatabase.h new file mode 100644 index 000000000..edf7d1d49 --- /dev/null +++ b/Core/Kernel/elxComponentDatabase.h @@ -0,0 +1,28 @@ +#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" + +// Ensure FixedImageType and MovingImageType are defined before using MaskImageType +using FixedImageType = itk::Image; // Example definition, adjust as necessary +using MovingImageType = itk::Image; // Example definition, adjust as necessary + +namespace elastix +{ + +class ComponentDatabase : public itk::Object +{ +public: + + /** Types for the masks. */ + using MaskPixelType = unsigned char; + // Ensure MaskImageType is defined before using it + using MaskImageType = itk::Image::ImageDimension>; + +}; +} // end namespace elastix + +#endif // end #ifndef elxComponentDatabase_h diff --git a/Core/Kernel/elxElastixBase.cxx b/Core/Kernel/elxElastixBase.cxx index e76f7005e..a25467c28 100644 --- a/Core/Kernel/elxElastixBase.cxx +++ b/Core/Kernel/elxElastixBase.cxx @@ -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 diff --git a/Core/Kernel/elxElastixBase.h b/Core/Kernel/elxElastixBase.h index 836f24ecc..d037364a5 100644 --- a/Core/Kernel/elxElastixBase.h +++ b/Core/Kernel/elxElastixBase.h @@ -42,6 +42,17 @@ #include #include #include +#include "itkImage.h" +#include "itkSmartPointer.h" +#include "itkObject.h" + +// Ensure FixedImageType and MovingImageType are defined before using MaskImageType +using FixedImageType = itk::Image; // Example definition, adjust as necessary +using MovingImageType = itk::Image; // Example definition, adjust as necessary + +// Types for the masks +using MaskPixelType = unsigned char; +using MaskImageType = itk::Image::ImageDimension>; #include #include @@ -175,6 +186,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::ImageDimension>; + /** Set/Get the Configuration Object. */ elxGetObjectMacro(Configuration, Configuration); elxSetObjectMacro(Configuration, Configuration); @@ -299,6 +314,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; @@ -540,6 +563,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 diff --git a/Core/Kernel/elxElastixMain.cxx b/Core/Kernel/elxElastixMain.cxx index 8d99ada38..ac7475f2b 100644 --- a/Core/Kernel/elxElastixMain.cxx +++ b/Core/Kernel/elxElastixMain.cxx @@ -31,7 +31,6 @@ using itk::Deref; /** * ********************* Constructor **************************** */ - ElastixMain::ElastixMain() = default; /** @@ -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); @@ -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 diff --git a/Core/Kernel/elxElastixMain.h b/Core/Kernel/elxElastixMain.h index 37b6a3f3d..bee07365f 100644 --- a/Core/Kernel/elxElastixMain.h +++ b/Core/Kernel/elxElastixMain.h @@ -19,7 +19,13 @@ #define elxElastixMain_h #include "elxMainBase.h" +#include "itkImage.h" +#include "itkSmartPointer.h" +#include "itkObject.h" +// Ensure FixedImageType and MovingImageType are defined before using MaskImageType +using FixedImageType = itk::Image; // Example definition, adjust as necessary +using MovingImageType = itk::Image; // Example definition, adjust as necessary namespace elastix { @@ -82,6 +88,10 @@ class ElastixMain : public MainBase /** Run-time type information (and related methods). */ itkOverrideGetNameOfClassMacro(ElastixMain); + /** Types for the masks. */ + using MaskPixelType = unsigned char; + using MaskImageType = itk::Image::ImageDimension>; + /** 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). @@ -98,8 +108,21 @@ class ElastixMain : public MainBase itkGetModifiableObjectMacro(FixedMaskContainer, DataObjectContainerType); itkGetModifiableObjectMacro(MovingMaskContainer, DataObjectContainerType); - itkSetConstObjectMacro(FixedPoints, itk::Object); - itkSetConstObjectMacro(MovingPoints, itk::Object); + /** + * Set/Get functions for the fixed and moving weighted masks. + * These masks are used to apply weights to different regions of the fixed and moving images + * during the registration process. The weights can influence the registration by giving more + * importance to certain areas of the images. + */ + + + itkGetModifiableObjectMacro(FixedWeightedMask, MaskImageType); + itkGetModifiableObjectMacro(MovingWeightedMask, MaskImageType); + + itkGetConstObjectMacro(FixedWeightedPoints, itk::Object); + itkGetConstObjectMacro(MovingWeightedPoints, itk::Object); + + /** Get the final transform (the result of running elastix). * You may pass this as an InitialTransform in an other instantiation @@ -181,6 +204,9 @@ class ElastixMain : public MainBase itk::SmartPointer m_FixedPoints{ nullptr }; itk::SmartPointer 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 }; diff --git a/Core/Kernel/elxElastixTemplate.h b/Core/Kernel/elxElastixTemplate.h index 6297f9c3e..845856088 100644 --- a/Core/Kernel/elxElastixTemplate.h +++ b/Core/Kernel/elxElastixTemplate.h @@ -34,6 +34,7 @@ #include #include #include +#include "itkSmartPointer.h" #include @@ -130,6 +131,7 @@ class ITK_TEMPLATE_EXPORT ElastixTemplate final : public ElastixBase /** Types for the masks. */ using MaskPixelType = unsigned char; + using MaskImageType = itk::Image::ImageDimension>; using FixedMaskType = itk::Image; using MovingMaskType = itk::Image; using FixedMaskPointer = typename FixedMaskType::Pointer; @@ -209,6 +211,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. diff --git a/Core/Kernel/elxElastixTemplate.hxx b/Core/Kernel/elxElastixTemplate.hxx index c42353f12..baa831218 100644 --- a/Core/Kernel/elxElastixTemplate.hxx +++ b/Core/Kernel/elxElastixTemplate.hxx @@ -107,6 +107,24 @@ ElastixTemplate::GetMovingMask(unsigned int idx) cons } // end SetMovingMask() +/** + * ********************** GetFixedWeightedMask ************************* + */ +template +typename ElastixTemplate::FixedMaskType * +ElastixTemplate::GetFixedWeightedMask() const +{ + return dynamic_cast(this->GetModifiableFixedWeightedMask()); +} +/** + * ********************** GetMovingWeightedMask ************************* + */ +template +typename ElastixTemplate::MovingMaskType * +ElastixTemplate::GetMovingWeightedMask() const +{ + return dynamic_cast(this->GetModifiableMovingWeightedMask()); +} /** * **************************** Run ***************************** diff --git a/Core/Kernel/elxMainBase.h b/Core/Kernel/elxMainBase.h index 6f4a75ff4..4892f46a2 100644 --- a/Core/Kernel/elxMainBase.h +++ b/Core/Kernel/elxMainBase.h @@ -24,12 +24,18 @@ #include "itkParameterMapInterface.h" #include +#include "itkImage.h" +#include "itkSmartPointer.h" +#include "itkObject.h" // Standard C++ header files: #include #include #include +// Ensure FixedImageType and MovingImageType are defined before using MaskImageType +using FixedImageType = itk::Image; // Example definition, adjust as necessary +using MovingImageType = itk::Image; // Example definition, adjust as necessary namespace elastix { @@ -164,6 +170,10 @@ class MainBase : public itk::Object static const ComponentDatabase & GetComponentDatabase(); + /** Types for the masks. */ + using MaskPixelType = unsigned char; + using MaskImageType = itk::Image::ImageDimension>; + protected: MainBase(); ~MainBase() override = 0; diff --git a/Core/Kernel/elxParameterObject.h b/Core/Kernel/elxParameterObject.h new file mode 100644 index 000000000..b994a5499 --- /dev/null +++ b/Core/Kernel/elxParameterObject.h @@ -0,0 +1,19 @@ +// ...existing code... + +// Ensure FixedImageType and MovingImageType are defined before using MaskImageType +using FixedImageType = itk::Image; // Example definition, adjust as necessary +using MovingImageType = itk::Image; // Example definition, adjust as necessary + +namespace elastix +{ +// ...existing code... + + /** Types for the masks. */ + using MaskPixelType = unsigned char; + using MaskImageType = itk::Image::ImageDimension>; + +// ...existing code... +}; +} // end namespace elastix + +#endif // end #ifndef elxParameterObject_h diff --git a/Core/Main/itkElastixRegistrationMethod.h b/Core/Main/itkElastixRegistrationMethod.h index 0ca0ae474..955501773 100644 --- a/Core/Main/itkElastixRegistrationMethod.h +++ b/Core/Main/itkElastixRegistrationMethod.h @@ -166,6 +166,34 @@ class ITK_TEMPLATE_EXPORT ElastixRegistrationMethod : public itk::ImageSource); itkSetConstObjectMacro(MovingPoints, PointContainerType); diff --git a/Core/Main/itkElastixRegistrationMethod.hxx b/Core/Main/itkElastixRegistrationMethod.hxx index 52b242b3f..56b8e911d 100644 --- a/Core/Main/itkElastixRegistrationMethod.hxx +++ b/Core/Main/itkElastixRegistrationMethod.hxx @@ -1050,6 +1050,90 @@ ElastixRegistrationMethod::ConvertToItkTransform(cons itkGenericExceptionMacro("Failed to convert transform object " << elxTransform); } +template +void +ElastixRegistrationMethod::AddFixedWeightedMask(FixedMaskType * fixedWeightedMask) +{ + this->GetElastixMain()->SetFixedWeightedMask(fixedWeightedMask); +} + +template +void +ElastixRegistrationMethod::SetFixedWeightedMask(FixedMaskType * fixedWeightedMask) +{ + this->GetElastixMain()->SetFixedWeightedMask(fixedWeightedMask); +} + +template +const typename ElastixRegistrationMethod::FixedMaskType * +ElastixRegistrationMethod::GetFixedWeightedMask() const +{ + return this->GetElastixMain()->GetModifiableFixedWeightedMask(); +} + +template +const typename ElastixRegistrationMethod::FixedMaskType * +ElastixRegistrationMethod::GetFixedWeightedMask(const unsigned int index) const +{ + return this->GetElastixMain()->GetModifiableFixedWeightedMask(); +} + +template +void +ElastixRegistrationMethod::RemoveFixedWeightedMask() +{ + this->GetElastixMain()->SetFixedWeightedMask(nullptr); +} + +template +unsigned int +ElastixRegistrationMethod::GetNumberOfFixedWeightedMasks() const +{ + return this->GetElastixMain()->GetModifiableFixedWeightedMask() ? 1 : 0; +} + +template +void +ElastixRegistrationMethod::SetMovingWeightedMask(MovingMaskType * movingWeightedMask) +{ + this->GetElastixMain()->SetMovingWeightedMask(movingWeightedMask); +} + +template +void +ElastixRegistrationMethod::AddMovingWeightedMask(MovingMaskType * movingWeightedMask) +{ + this->GetElastixMain()->SetMovingWeightedMask(movingWeightedMask); +} + +template +const typename ElastixRegistrationMethod::MovingMaskType * +ElastixRegistrationMethod::GetMovingWeightedMask() const +{ + return this->GetElastixMain()->GetModifiableMovingWeightedMask(); +} + +template +const typename ElastixRegistrationMethod::MovingMaskType * +ElastixRegistrationMethod::GetMovingWeightedMask(const unsigned int index) const +{ + return this->GetElastixMain()->GetModifiableMovingWeightedMask(); +} + +template +void +ElastixRegistrationMethod::RemoveMovingWeightedMask() +{ + this->GetElastixMain()->SetMovingWeightedMask(nullptr); +} + +template +unsigned int +ElastixRegistrationMethod::GetNumberOfMovingWeightedMasks() const +{ + return this->GetElastixMain()->GetModifiableMovingWeightedMask() ? 1 : 0; +} + } // namespace itk #endif