Skip to content
Snippets Groups Projects
Commit e6dcc71c authored by Kasper Marstal's avatar Kasper Marstal
Browse files

WIP: CorrespondingPointsEuclideanDistanceMetric ElastixFilter test

parent 06d052e8
No related branches found
No related tags found
No related merge requests found
...@@ -52,13 +52,13 @@ public: ...@@ -52,13 +52,13 @@ public:
void SetParameterObject( ParameterObjectPointer parameterObject ); void SetParameterObject( ParameterObjectPointer parameterObject );
ParameterObjectConstPointer GetTransformParameters( void ) const; ParameterObjectConstPointer GetTransformParameters( void ) const;
itkSetMacro( FixedPointSetFileName, std::string ); itkSetMacro( FixedMeshFileName, std::string );
itkGetConstMacro( FixedPointSetFileName, std::string ); itkGetConstMacro( FixedMeshFileName, std::string );
void DeleteFixedPointSet( void ) { this->SetFixedPointSetFileName( std::string() ); }; void DeleteFixedMesh( void ) { this->SetFixedMeshFileName( std::string() ); };
itkSetMacro( MovingPointSetFileName, std::string ); itkSetMacro( MovingMeshFileName, std::string );
itkGetConstMacro( MovingPointSetFileName, std::string ); itkGetConstMacro( MovingMeshFileName, std::string );
void DeleteMovingPointSet( void ) { this->SetMovingPointSetFileName( std::string() ); }; void DeleteMovingMesh( void ) { this->SetMovingMeshFileName( std::string() ); };
itkSetMacro( LogToConsole, bool ); itkSetMacro( LogToConsole, bool );
itkGetConstMacro( LogToConsole, bool ); itkGetConstMacro( LogToConsole, bool );
...@@ -82,8 +82,8 @@ private: ...@@ -82,8 +82,8 @@ private:
DataObjectContainerPointer m_FixedMaskContainer; DataObjectContainerPointer m_FixedMaskContainer;
DataObjectContainerPointer m_MovingMaskContainer; DataObjectContainerPointer m_MovingMaskContainer;
std::string m_FixedPointSetFileName; std::string m_FixedMeshFileName;
std::string m_MovingPointSetFileName; std::string m_MovingMeshFileName;
bool m_LogToConsole; bool m_LogToConsole;
std::string m_LogToFile; std::string m_LogToFile;
......
...@@ -17,8 +17,8 @@ ElastixFilter< TFixedImage, TMovingImage > ...@@ -17,8 +17,8 @@ ElastixFilter< TFixedImage, TMovingImage >
this->m_FixedImageContainer = DataObjectContainerType::New(); this->m_FixedImageContainer = DataObjectContainerType::New();
this->m_MovingImageContainer = DataObjectContainerType::New(); this->m_MovingImageContainer = DataObjectContainerType::New();
this->m_FixedPointSetFileName = std::string(); this->m_FixedMeshFileName = std::string();
this->m_MovingPointSetFileName = std::string(); this->m_MovingMeshFileName = std::string();
} }
template< typename TFixedImage, typename TMovingImage > template< typename TFixedImage, typename TMovingImage >
...@@ -58,15 +58,16 @@ ElastixFilter< TFixedImage, TMovingImage > ...@@ -58,15 +58,16 @@ ElastixFilter< TFixedImage, TMovingImage >
ArgumentMapType argumentMap; ArgumentMapType argumentMap;
argumentMap.insert( ArgumentMapEntryType( "-out", std::string( "output_path_not_set" ) ) ); argumentMap.insert( ArgumentMapEntryType( "-out", std::string( "output_path_not_set" ) ) );
// Set point sets // Fixed mesh (optional)
if( !this->m_FixedPointSetFileName.empty() ) if( !this->m_FixedMeshFileName.empty() )
{ {
argumentMap.insert( ArgumentMapEntryType( "-fp", std::string( this->m_FixedPointSetFileName ) ) ); argumentMap.insert( ArgumentMapEntryType( "-fp", std::string( this->m_FixedMeshFileName ) ) );
} }
if( !this->m_MovingPointSetFileName.empty() ) // Moving mesh (optional)
if( !this->m_MovingMeshFileName.empty() )
{ {
argumentMap.insert( ArgumentMapEntryType( "-mp", std::string( this->m_MovingPointSetFileName ) ) ); argumentMap.insert( ArgumentMapEntryType( "-mp", std::string( this->m_MovingMeshFileName ) ) );
} }
// Setup xout // Setup xout
......
#include "elxElastixFilter.h" #include "elxElastixFilter.h"
#include "elxParameterObject.h" #include "elxParameterObject.h"
#include "itkMesh.h"
#include "itkMeshFileReader.h"
#include "itkImageFileReader.h" #include "itkImageFileReader.h"
#include "itkImageFileWriter.h" #include "itkImageFileWriter.h"
...@@ -15,43 +17,54 @@ protected: ...@@ -15,43 +17,54 @@ protected:
typedef DataManager DataManagerType; typedef DataManager DataManagerType;
typedef itk::Image< float, 2u > ImageType; // Mesh typedef
ImageType::Pointer fixedImage; typedef itk::Mesh< float, 2u > MeshType;
ImageType::Pointer movingImage; typedef itk::MeshFileReader< MeshType > MeshReaderType;
ImageType::Pointer resultImage;
// Image typedefs
typedef itk::Image< float, 2u > ImageType;
typedef itk::ImageFileReader< ImageType > ImageReaderType; typedef itk::ImageFileReader< ImageType > ImageReaderType;
typedef itk::ImageFileWriter< ImageType > ImageWriterType; typedef itk::ImageFileWriter< ImageType > ImageWriterType;
// Parameter typedefs
typedef ParameterObject::ParameterValuesType ParameterValuesType; typedef ParameterObject::ParameterValuesType ParameterValuesType;
typedef ParameterObject::ParameterMapType ParameterMapType; typedef ParameterObject::ParameterMapType ParameterMapType;
ParameterObject::Pointer parameterObject;
ParameterObject::ConstPointer TransformParameterObject;
// Elastix typedefs
typedef ElastixFilter< ImageType, ImageType > ElastixFilterType; typedef ElastixFilter< ImageType, ImageType > ElastixFilterType;
typedef ElastixFilterType::DataObjectContainerType DataObjectContainerType; typedef ElastixFilterType::DataObjectContainerType DataObjectContainerType;
typedef ElastixFilterType::DataObjectContainerPointer DataObjectContainerPointer; typedef ElastixFilterType::DataObjectContainerPointer DataObjectContainerPointer;
// Variables used by multiple tests
ImageType::Pointer fixedImage;
ImageType::Pointer movingImage;
ImageType::Pointer resultImage;
std::string fixedMeshFileName;
std::string movingMeshFileName;
ParameterObject::Pointer parameterObject;
ParameterObject::Pointer correspondingPointsParameterObject;
ParameterObject::ConstPointer transformParameterObject;
virtual void SetUp() virtual void SetUp()
{ {
DataManagerType::Pointer dataManager = DataManagerType::New(); DataManagerType::Pointer dataManager = DataManagerType::New();
ImageReaderType::Pointer reader = ImageReaderType::New(); // TODO: All calls to update here should not be needed but should be propagated to reader by ElastixFilter
reader->SetFileName( dataManager->GetInputFile( "cthead1-Float.mha" ) ); // Input images
fixedImage = reader->GetOutput(); ImageReaderType::Pointer fixedImageReader = ImageReaderType::New();
fixedImageReader->SetFileName( dataManager->GetInputFile( "cthead1-Float.mha" ) );
fixedImage = fixedImageReader->GetOutput();
fixedImageReader->Update();
// TODO: Only call update on writer ImageReaderType::Pointer movingImageReader = ImageReaderType::New();
reader->Update(); movingImageReader->SetFileName( dataManager->GetInputFile( "cthead1-Float.mha" ) );
movingImage = movingImageReader->GetOutput();
movingImageReader->Update();
reader->SetFileName( dataManager->GetInputFile( "cthead1-Float.mha" ) ); // Nonrigid ParameterMap
movingImage = reader->GetOutput();
// TODO: Only call update on writer
reader->Update();
// ParameterMap
ParameterMapType parameterMap = ParameterMapType(); ParameterMapType parameterMap = ParameterMapType();
// Images // Images
...@@ -93,8 +106,18 @@ protected: ...@@ -93,8 +106,18 @@ protected:
parameterMap[ "Metric" ] = ParameterValuesType( 1, "AdvancedMattesMutualInformation" ); parameterMap[ "Metric" ] = ParameterValuesType( 1, "AdvancedMattesMutualInformation" );
parameterMap[ "MaximumNumberOfIterations" ] = ParameterValuesType( 1, "128" ); parameterMap[ "MaximumNumberOfIterations" ] = ParameterValuesType( 1, "128" );
ParameterMapType nonRigidParameterMap = parameterMap;
parameterObject = ParameterObject::New(); parameterObject = ParameterObject::New();
parameterObject->SetParameterMap( parameterMap ); parameterObject->SetParameterMap( nonRigidParameterMap );
ParameterMapType correspondingPointsParameterMap = parameterMap;
// TODO: WHY DOES THIS SEGFAULT?
//correspondingPointsParameterMap[ "Metric" ][ 1 ] = "CorrespondingPointsEuclideanDistanceMetric";
//correspondingPointsParameterObject->SetParameterMap( correspondingPointsParameterMap );
fixedMeshFileName = dataManager->GetInputFile( "bioid_0000.vtk" );
movingMeshFileName = dataManager->GetInputFile( "bioid_0001.vtk" );
} }
}; };
...@@ -107,16 +130,16 @@ TEST_F( ElastixFilterTest, PairwiseRegistration ) ...@@ -107,16 +130,16 @@ TEST_F( ElastixFilterTest, PairwiseRegistration )
{ {
ElastixFilterType::Pointer elastixFilter = ElastixFilterType::New(); ElastixFilterType::Pointer elastixFilter = ElastixFilterType::New();
elastixFilter->LogToConsoleOn(); EXPECT_NO_THROW( elastixFilter->LogToConsoleOn() );
elastixFilter->SetFixedImage( fixedImage ); EXPECT_NO_THROW( elastixFilter->SetFixedImage( fixedImage ) );
elastixFilter->SetMovingImage( movingImage ); EXPECT_NO_THROW( elastixFilter->SetMovingImage( movingImage ) );
elastixFilter->SetParameterObject( parameterObject ); EXPECT_NO_THROW( elastixFilter->SetParameterObject( parameterObject ) );
// TODO: This update should not be needed // TODO: This update should not be needed
elastixFilter->Update(); EXPECT_NO_THROW( elastixFilter->Update() );
EXPECT_NO_THROW( resultImage = elastixFilter->GetOutput() ); EXPECT_NO_THROW( resultImage = elastixFilter->GetOutput() );
EXPECT_NO_THROW( TransformParameterObject = elastixFilter->GetTransformParameters() ); EXPECT_NO_THROW( transformParameterObject = elastixFilter->GetTransformParameters() );
ImageWriterType::Pointer writer = ImageWriterType::New(); ImageWriterType::Pointer writer = ImageWriterType::New();
writer->SetFileName( "ElastixResultImage.nii" ); writer->SetFileName( "ElastixResultImage.nii" );
...@@ -138,21 +161,45 @@ TEST_F( ElastixFilterTest, MultiPairwiseRegistration ) ...@@ -138,21 +161,45 @@ TEST_F( ElastixFilterTest, MultiPairwiseRegistration )
movingImages->CreateElementAt( 0 ) = static_cast< itk::DataObject* >( movingImage ); movingImages->CreateElementAt( 0 ) = static_cast< itk::DataObject* >( movingImage );
movingImages->CreateElementAt( 1 ) = static_cast< itk::DataObject* >( movingImage ); movingImages->CreateElementAt( 1 ) = static_cast< itk::DataObject* >( movingImage );
elastixFilter->LogToConsoleOn(); EXPECT_NO_THROW( elastixFilter->LogToConsoleOn() );
elastixFilter->SetFixedImage( fixedImages ); EXPECT_NO_THROW( elastixFilter->SetFixedImage( fixedImages ) );
elastixFilter->SetMovingImage( movingImages ); EXPECT_NO_THROW( elastixFilter->SetMovingImage( movingImages ) );
elastixFilter->SetParameterObject( parameterObject ); EXPECT_NO_THROW( elastixFilter->SetParameterObject( parameterObject ) );
// TODO: This update should not be needed
EXPECT_NO_THROW( elastixFilter->Update() );
EXPECT_NO_THROW( resultImage = elastixFilter->GetOutput() );
EXPECT_NO_THROW( transformParameterObject = elastixFilter->GetTransformParameters() );
ImageWriterType::Pointer writer = ImageWriterType::New();
writer->SetFileName( "ElastixResultImage.nii" );
writer->SetInput( elastixFilter->GetOutput() );
EXPECT_NO_THROW( writer->Update() );
}
TEST_F( ElastixFilterTest, PointSetRegistration )
{
ElastixFilterType::Pointer elastixFilter = ElastixFilterType::New();
EXPECT_NO_THROW( elastixFilter->LogToConsoleOn() );
EXPECT_NO_THROW( elastixFilter->SetFixedImage( fixedImage ) );
EXPECT_NO_THROW( elastixFilter->SetFixedMeshFileName( fixedMeshFileName ) );
EXPECT_NO_THROW( elastixFilter->SetMovingImage( movingImage ) );
EXPECT_NO_THROW( elastixFilter->SetMovingMeshFileName( movingMeshFileName ) );
EXPECT_NO_THROW( elastixFilter->SetParameterObject( parameterObject ) );
// TODO: This update should not be needed // TODO: This update should not be needed
elastixFilter->Update(); EXPECT_NO_THROW( elastixFilter->Update() );
EXPECT_NO_THROW( resultImage = elastixFilter->GetOutput() ); EXPECT_NO_THROW( resultImage = elastixFilter->GetOutput() );
EXPECT_NO_THROW( TransformParameterObject = elastixFilter->GetTransformParameters() ); EXPECT_NO_THROW( transformParameterObject = elastixFilter->GetTransformParameters() );
ImageWriterType::Pointer writer = ImageWriterType::New(); ImageWriterType::Pointer writer = ImageWriterType::New();
writer->SetFileName( "ElastixResultImage.nii" ); writer->SetFileName( "ElastixResultImage.nii" );
writer->SetInput( elastixFilter->GetOutput() ); writer->SetInput( elastixFilter->GetOutput() );
EXPECT_NO_THROW( writer->Update() ); EXPECT_NO_THROW( writer->Update() );
} }
// TODO: Write test with point sets // TODO: Write test with point sets
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment