Skip to content
Snippets Groups Projects
Commit 92841156 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

Merge branch 'develop' into ELASTIX-44-Unite-Interface-framework-with-Factory-framework

parents bd061e7b 1c4dee57
No related branches found
No related tags found
No related merge requests found
Showing
with 512 additions and 147 deletions
......@@ -35,7 +35,7 @@ macro( _elxmodule_enable MODULE_NAME )
endmacro()
macro( _elxmodule_disable MODULE_NAME )
# TODO
# TODO: elxmodule_disable
endmacro()
macro( _elxmodules_initialize )
......
list( APPEND ElastixRequiredITKModules
list( APPEND RequiredITKModules
ITKReview
)
foreach( ITKModule ${ElastixRequiredITKModules} )
foreach( ITKModule ${RequiredITKModules} )
if( NOT ${ITKModule}_LOADED )
message( FATAL_ERROR "Elastix requires that ITK is build with ${ITKModule}. Please rebuild ITK with Module_${ITKModule} set to ON." )
endif()
......
# Visual Studio complains if paths are too long
string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n )
if( n GREATER 50 )
message(
FATAL_ERROR
"Source code directory path length is too long for MSVC (${n} > 50)."
"Please move the source code directory to a directory with a shorter path."
)
endif()
string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n )
if( n GREATER 50 )
message(
FATAL_ERROR
"Build directory path length is too long for MSVC (${n} > 50)."
"Please move the build directory to a directory with a shorter path."
)
endif()
\ No newline at end of file
cmake_minimum_required( VERSION 2.8 )
cmake_minimum_required( VERSION 3.0.2 )
# Explicitly add INCREMENTAL linking option to command lines.
# http://www.cmake.org/pipermail/cmake/2010-February/035174.html
......@@ -17,9 +17,36 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY
# Include SuperElastix CMake scripts
list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake" )
# -----------------------------------------------------------------
# Compiler-dependent settings
# GCC
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL GNU )
add_definitions(
-DVCL_CAN_STATIC_CONST_INIT_FLOAT=0
-DVCL_CAN_STATIC_CONST_INIT_INT=0
)
endif()
# MSVC
if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC )
include( elxWinConfig )
string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n )
if( n GREATER 50 )
message(
FATAL_ERROR
"Source code directory path length is too long for MSVC (${n} > 50)."
"Please move the source code directory to a directory with a shorter path."
)
endif()
string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n )
if( n GREATER 50 )
message(
FATAL_ERROR
"Build directory path length is too long for MSVC (${n} > 50)."
"Please move the build directory to a directory with a shorter path."
)
endif()
endif()
# ---------------------------------------------------------------------
......@@ -30,11 +57,11 @@ endif()
find_package( ITK REQUIRED )
include( ${ITK_USE_FILE} )
include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxITKRequiredModules.cmake" )
include("${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxRequiredITKModules.cmake")
# ---------------------------------------------------------------------
# Boost Graph Library
find_package( Boost )
find_package( Boost REQUIRED )
include_directories( ${Boost_INCLUDE_DIRS} )
# ---------------------------------------------------------------------
......@@ -49,24 +76,20 @@ endif()
# ---------------------------------------------------------------------
# Build SuperElastix
# For now we just enable all modules
include( elxModules )
elxmodule_enable( ModuleCore )
elxmodule_enable( ModuleElastix )
# TODO: Build tests depending on enabled modules
# ---------------------------------------------------------------------
# Testing
# Testing requires CMake version 2.8.11 to download test data
if( CMAKE_VERSION VERSION_LESS 2.8.11 )
set( SUPERELASTIX_BUILD_TESTING_DEFAULT OFF )
message( STATUS "ELASTIX_BUILD_TESTING is set to OFF because CMake version is less than 2.8.11" )
else()
set( SUPERELASTIX_BUILD_TESTING_DEFAULT ON )
endif()
option( SUPERELASTIX_BUILD_TESTING "Enable building tests." ${SUPERELASTIX_BUILD_TESTING_DEFAULT} )
option( SUPERELASTIX_BUILD_TESTING "Enable building tests." ON )
if( ${SUPERELASTIX_BUILD_TESTING} )
option( SUPERELASTIX_BUILD_LONG_TESTS OFF )
enable_testing()
add_subdirectory( Testing )
endif()
......
# Module that exposes the old elastix as a component
# Module that exposes old elastix as an ITK filter
set( MODULE ModuleElastix )
if( NOT EXISTS ${ELASTIX_USE_FILE} )
......@@ -8,6 +8,14 @@ endif()
include( ${ELASTIX_USE_FILE} )
# If OpenMP is supported by this machine, elastix will be compiled with
# OpenMP flags, and we need to add them here as well
find_package( OpenMP )
if (OPENMP_FOUND)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
endif()
# Export include files
set( ${MODULE}_INCLUDE_DIRS
${${MODULE}_SOURCE_DIR}/include
......
#ifndef ElastixComponent_h
#define ElastixComponent_h
#ifndef ElastixFilter_h
#define ElastixFilter_h
// ITK
#include "itkProcessObject.h"
#include "itkImageSource.h"
// Elastix
......@@ -15,9 +14,8 @@
namespace selx {
template< typename TFixedImage,
typename TMovingImage,
typename TOutputImage >
class ElastixFilter : public itk::ImageSource< TOutputImage >
typename TMovingImage >
class ElastixFilter : public itk::ImageSource< TFixedImage >
{
public:
......@@ -37,8 +35,9 @@ public:
typedef ParameterObject::ParameterMapListType ParameterMapListType;
typedef ParameterObject::ParameterMapType ParameterMapType;
typedef ParameterObject::ParameterValuesType ParameterValuesType;
typedef ParameterObject::ParameterVectorType ParameterVectorType;
typedef typename ParameterObject::Pointer ParameterObjectPointer;
typedef typename ParameterObject::ConstPointer ParameterObjectConstPointer;
typedef typename TFixedImage::Pointer FixedImagePointer;
typedef typename TMovingImage::Pointer MovingImagePointer;
......@@ -47,18 +46,31 @@ public:
void SetFixedImage( DataObjectContainerPointer fixedImage );
void SetMovingImage( MovingImagePointer movingImage );
void SetMovingImage( DataObjectContainerPointer movingImage );
void SetParameterObject( ParameterObjectPointer parameterObject );
void SetFixedMask( FixedImagePointer fixedMask );
void SetMovingMask( MovingImagePointer movingMask );
void SetParameterObject( ParameterObjectPointer parameterObject );
ParameterObjectPointer GetTransformParameters( void );
itkSetMacro( FixedMeshFileName, std::string );
itkGetConstMacro( FixedMeshFileName, std::string );
void DeleteFixedMeshFileName( void ) { this->SetFixedMeshFileName( std::string() ); };
itkSetMacro( MovingMeshFileName, std::string );
itkGetConstMacro( MovingMeshFileName, std::string );
void DeleteMovingMeshFileName( void ) { this->SetMovingMeshFileName( std::string() ); };
itkSetMacro( OutputDirectory, std::string );
itkGetConstMacro( OutputDirectory, std::string );
void DeleteOutputDirectory() { this->m_OutputDirectory = std::string(); };
itkSetMacro( LogToConsole, bool );
itkGetMacro( LogToConsole, bool );
itkGetConstMacro( LogToConsole, bool );
itkBooleanMacro( LogToConsole );
itkSetMacro( LogToFile, std::string );
itkGetMacro( LogToFile, std::string );
itkSetMacro( LogToFile, bool );
itkGetConstMacro( LogToFile, bool );
itkBooleanMacro( LogToFile );
protected:
......@@ -68,13 +80,18 @@ private:
ElastixFilter();
// TODO: When set to true, ReleaseDataFlag should also touch these input containers
DataObjectContainerPointer m_FixedImageContainer;
DataObjectContainerPointer m_MovingImageContainer;
DataObjectContainerPointer m_FixedMaskContainer;
DataObjectContainerPointer m_MovingMaskContainer;
std::string m_FixedMeshFileName;
std::string m_MovingMeshFileName;
std::string m_OutputDirectory;
bool m_LogToConsole;
std::string m_LogToFile;
bool m_LogToFile;
};
......
#ifndef ElastixComponent_hxx
#define ElastixComponent_hxx
#ifndef ElastixFilter_hxx
#define ElastixFilter_hxx
namespace selx {
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
template< typename TFixedImage, typename TMovingImage >
ElastixFilter< TFixedImage, TMovingImage >
::ElastixFilter( void )
{
this->AddRequiredInputName( "FixedImage" );
......@@ -16,60 +16,99 @@ ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
this->m_FixedImageContainer = DataObjectContainerType::New();
this->m_MovingImageContainer = DataObjectContainerType::New();
this->m_FixedMeshFileName = std::string();
this->m_MovingMeshFileName = std::string();
this->m_OutputDirectory = std::string();
this->LogToConsoleOff();
this->LogToFileOff();
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::GenerateData( void )
{
// Initialize variables here so they don't go out of scope between iterations of the main loop
ElastixMainObjectPointer transform = 0;
DataObjectContainerPointer fixedImageContainer = this->m_FixedImageContainer;
DataObjectContainerPointer movingImageContainer = this->m_MovingImageContainer;
DataObjectContainerPointer fixedMaskContainer = 0;
DataObjectContainerPointer movingMaskContainer = 0;
DataObjectContainerPointer resultImageContainer = 0;
ParameterMapListType TransformParameterMapList;
FlatDirectionCosinesType fixedImageOriginalDirection;
// Fixed mask (optional)
if( this->HasInput( "FixedMask" ) )
{
fixedMaskContainer = DataObjectContainerType::New();
fixedMaskContainer = DataObjectContainerType::New();
fixedMaskContainer->CreateElementAt( 0 ) = this->GetInput( "FixedMask" );
}
// Moving mask (optional)
if( this->HasInput( "MovingMask" ) )
{
movingMaskContainer = DataObjectContainerType::New();
movingMaskContainer = DataObjectContainerType::New();
movingMaskContainer->CreateElementAt( 0 ) = this->GetInput( "MovingMask" );
}
// Get ParameterMap
ParameterObjectPointer parameterObject = static_cast< ParameterObject* >( this->GetInput( "ParameterObject" ) );
ParameterMapListType parameterMapList = parameterObject->GetParameterMapList();
// Emulate command line parameters. There must be an "-out", this is checked later in code
// There must be an "-out", this is checked later in the code
ArgumentMapType argumentMap;
argumentMap.insert( ArgumentMapEntryType( std::string( "-out" ), std::string( "output_path_not_set" ) ) );
if( this->GetOutputDirectory().empty() ) {
// There must be an "-out", this is checked later in the code
argumentMap.insert( ArgumentMapEntryType( "-out", "output_path_not_set" ) );
}
else
{
argumentMap.insert( ArgumentMapEntryType( "-out", this->GetOutputDirectory() ) );
}
// Fixed mesh (optional)
if( !this->m_FixedMeshFileName.empty() )
{
argumentMap.insert( ArgumentMapEntryType( "-fp", std::string( this->m_FixedMeshFileName ) ) );
}
// Direction Cosines
FlatDirectionCosinesType fixedImageOriginalDirection;
// Moving mesh (optional)
if( !this->m_MovingMeshFileName.empty() )
{
argumentMap.insert( ArgumentMapEntryType( "-mp", std::string( this->m_MovingMeshFileName ) ) );
}
// Setup xout
if( elx::xoutSetup( this->GetLogToFile().c_str(), this->GetLogToFile() != std::string(), this->GetLogToConsole() ) )
std::string logFileName;
if( this->GetLogToFile() )
{
if( this->GetOutputDirectory().empty() )
{
itkExceptionMacro( "LogToFileOn() requires an output directory to be specified. Use SetOutputDirectory().")
}
logFileName = this->GetOutputDirectory() + "transformix.log";
}
if( elx::xoutSetup( logFileName.c_str(), this->GetLogToFile(), this->GetLogToConsole() ) )
{
itkExceptionMacro( "ERROR while setting up xout." );
// TODO: The following exception thrown if two different filters are initialized by the same process
itkExceptionMacro( "ERROR while setting up xout" );
}
// Get ParameterMap
ParameterObjectConstPointer parameterObject = static_cast< const ParameterObject* >( this->GetInput( "ParameterObject" ) );
ParameterMapListType parameterMapList = parameterObject->GetParameterMapList();
// Run the (possibly multiple) registration(s)
unsigned int isError;
for( unsigned int i = 0; i < parameterMapList.size(); ++i )
{
// Create another instance of ElastixMain
ElastixMainPointer elastix = ElastixMainType::New();
// Set the current elastix-level
elastix->SetElastixLevel( i );
elastix->SetTotalNumberOfElastixLevels( parameterMapList.size() );
// Set stuff we get from a previous registration
elastix->SetInitialTransform( transform );
elastix->SetFixedImageContainer( fixedImageContainer );
......@@ -79,20 +118,26 @@ ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
elastix->SetResultImageContainer( resultImageContainer );
elastix->SetOriginalFixedImageDirectionFlat( fixedImageOriginalDirection );
// Set the current elastix-level
elastix->SetElastixLevel( i );
elastix->SetTotalNumberOfElastixLevels( 1 );
// ITK pipe-line mechanism need a result image
parameterMapList[ i ][ "WriteResultImage"] = ParameterValuesType( 1, std::string( "true" ) );
// Start registration
isError = elastix->Run( argumentMap, parameterMapList[ i ] );
unsigned int isError = 0;
try
{
unsigned int isError = elastix->Run( argumentMap, parameterMapList[ i ] );
}
catch( itk::ExceptionObject &e )
{
itkExceptionMacro( << "Errors occurred during registration: " << e.what() );
}
if( isError == -2 )
{
itkExceptionMacro( << "Errors occurred during registration: Output directory does not exist." );
}
// Assert success
if( isError != 0 )
{
itkExceptionMacro( "Errors occured" );
std::cout << std::endl << isError << std::endl;
itkExceptionMacro( << "Uncought errors occurred during registration." );
}
// Get the transform, the fixedImage and the movingImage
......@@ -125,30 +170,30 @@ ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
// Save parameter map
ParameterObject::Pointer TransformParameters = ParameterObject::New();
TransformParameters->SetParameterMapList( TransformParameterMapList );
this->SetOutput( "TransformParametersObject", static_cast< itk::DataObject* >( TransformParameters ) );
this->SetOutput( "TransformParameterObject", static_cast< itk::DataObject* >( TransformParameters ) );
// Clean up
transform = 0;
fixedImageContainer = 0;
movingImageContainer = 0;
fixedMaskContainer = 0;
movingMaskContainer = 0;
resultImageContainer = 0;
transform = ITK_NULLPTR;
fixedImageContainer = ITK_NULLPTR;
movingImageContainer = ITK_NULLPTR;
fixedMaskContainer = ITK_NULLPTR;
movingMaskContainer = ITK_NULLPTR;
resultImageContainer = ITK_NULLPTR;
// Close the modules
ElastixMainType::UnloadComponents();
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetFixedImage( FixedImagePointer fixedImage )
{
// Free references to fixed images that has already been set
if( this->m_FixedImageContainer->Size() > 0 )
{
// Free images that has already been given
this->m_FixedImageContainer = 0;
this->m_FixedImageContainer = ITK_NULLPTR;
}
// Input for elastix
......@@ -158,9 +203,9 @@ ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
this->SetInput( DataObjectIdentifierType( "FixedImage" ), this->m_FixedImageContainer->ElementAt( 0 ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetFixedImage( DataObjectContainerPointer fixedImages )
{
// Input for elastix
......@@ -170,68 +215,69 @@ ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
this->SetInput( DataObjectIdentifierType( "FixedImage" ), this->m_FixedImageContainer->ElementAt( 0 ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetMovingImage( MovingImagePointer movingImage )
{
// Free references to moving images that has already been set
if( this->m_MovingImageContainer->Size() > 0 )
{
// Free images that has already been given
this->m_MovingImageContainer = 0;
this->m_MovingImageContainer = ITK_NULLPTR;
}
// Input for elastix
this->m_MovingImageContainer->CreateElementAt( 0 ) = static_cast< itk::DataObject* >( movingImage ) ;
// Primary input for ITK pipeline
// Input for ITK pipeline
this->SetInput( DataObjectIdentifierType( "MovingImage" ), this->m_MovingImageContainer->ElementAt( 0 ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetMovingImage( DataObjectContainerPointer movingImages )
{
// Input for elastix
this->m_MovingImageContainer = movingImages;
// Primary input for ITK pipeline
// Input for ITK pipeline
this->SetInput( DataObjectIdentifierType( "MovingImage" ), this->m_MovingImageContainer->ElementAt( 0 ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetParameterObject( ParameterObjectPointer parameterObject )
{
this->SetInput( DataObjectIdentifierType( "ParameterObject" ), static_cast< itk::DataObject* >( parameterObject ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetFixedMask( FixedImagePointer fixedMask )
{
this->SetInput( DataObjectIdentifierType( "FixedMask" ), static_cast< itk::DataObject* >( fixedMask ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
template< typename TFixedImage, typename TMovingImage >
void
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
ElastixFilter< TFixedImage, TMovingImage >
::SetMovingMask( MovingImagePointer movingMask )
{
this->SetInput( DataObjectIdentifierType( "MovingMask" ), static_cast< itk::DataObject* >( movingMask ) );
}
template< typename TFixedImage, typename TMovingImage, typename TOutputImage >
typename selx::ElastixFilter< TFixedImage, TMovingImage, TOutputImage >::ParameterObjectPointer
ElastixFilter< TFixedImage, TMovingImage, TOutputImage >
template< typename TFixedImage, typename TMovingImage >
typename selx::ElastixFilter< TFixedImage, TMovingImage >::ParameterObjectPointer
ElastixFilter< TFixedImage, TMovingImage >
::GetTransformParameters( void )
{
return static_cast< ParameterObject* >( itk::ProcessObject::GetOutput( DataObjectIdentifierType( "TransformParametersObject" ) ) );
return static_cast< ParameterObject* >( itk::ProcessObject::GetOutput( DataObjectIdentifierType( "TransformParameterObject" ) ) );
}
} // namespace selx
#endif // ElastixComponent_hxx
\ No newline at end of file
#endif // ElastixFilter_hxx
\ No newline at end of file
#ifndef TransformixFilter_h
#define TransformixFilter_h
// ITK
#include "itkImageSource.h"
// Transformix
#include "elxTransformixMain.h"
// SuperElastix
#include "elxMacro.h"
#include "elxParameterObject.h"
namespace selx {
template< typename TInputImage >
class TransformixFilter : public itk::ImageSource< TInputImage >
{
public:
elxNewMacro( TransformixFilter, itk::ImageSource );
typedef elastix::TransformixMain TransformixMainType;
typedef TransformixMainType::Pointer TransformixMainPointer;
typedef TransformixMainType::ArgumentMapType ArgumentMapType;
typedef ArgumentMapType::value_type ArgumentMapEntryType;
typedef itk::ProcessObject::DataObjectIdentifierType DataObjectIdentifierType;
typedef TransformixMainType::DataObjectContainerType DataObjectContainerType;
typedef TransformixMainType::DataObjectContainerPointer DataObjectContainerPointer;
typedef ParameterObject::ParameterMapListType ParameterMapListType;
typedef ParameterObject::ParameterMapType ParameterMapType;
typedef ParameterObject::ParameterVectorType ParameterVectorType;
typedef typename ParameterObject::Pointer ParameterObjectPointer;
typedef typename ParameterObject::ConstPointer ParameterObjectConstPointer;
typedef typename TInputImage::Pointer InputImagePointer;
void SetInputImage( InputImagePointer inputImage );
void SetTransformParameters( ParameterObjectPointer parameterObject );
ParameterObjectPointer GetTransformParameters( void );
itkSetMacro( ComputeSpatialJacobian, bool );
itkGetConstMacro( ComputeSpatialJacobian, bool );
itkBooleanMacro( ComputeSpatialJacobian );
itkSetMacro( ComputeDeterminantOfSpatialJacobian, bool );
itkGetConstMacro( ComputeDeterminantOfSpatialJacobian, bool );
itkBooleanMacro( ComputeDeterminantOfSpatialJacobian );
itkSetMacro( ComputeDeformationField, bool );
itkGetConstMacro( ComputeDeformationField, bool );
itkBooleanMacro( ComputeDeformationField );
itkSetMacro( PointSetFileName, std::string );
itkGetConstMacro( PointSetFileName, std::string );
void DeletePointSetFileName() { this->m_PointSetFileName = std::string(); };
itkSetMacro( OutputDirectory, std::string );
itkGetConstMacro( OutputDirectory, std::string );
void DeleteOutputDirectory() { this->m_OutputDirectory = std::string(); };
itkSetMacro( LogToConsole, bool );
itkGetConstMacro( LogToConsole, bool );
itkBooleanMacro( LogToConsole );
itkSetMacro( LogToFile, bool );
itkGetConstMacro( LogToFile, bool );
itkBooleanMacro( LogToFile );
protected:
void GenerateData( void ) ITK_OVERRIDE;
private:
TransformixFilter();
bool m_ComputeSpatialJacobian;
bool m_ComputeDeterminantOfSpatialJacobian;
bool m_ComputeDeformationField;
std::string m_PointSetFileName;
std::string m_OutputDirectory;
bool m_LogToConsole;
bool m_LogToFile;
};
} // namespace selx
#ifndef ITK_MANUAL_INSTANTIATION
#include "elxTransformixFilter.hxx"
#endif
#endif // TransformixFilter_h
\ No newline at end of file
#ifndef TransformixFilter_hxx
#define TransformixFilter_hxx
namespace selx {
template< typename TInputImage >
TransformixFilter< TInputImage >
::TransformixFilter( void )
{
this->AddRequiredInputName( "TransformParameterObject");
this->SetPrimaryInputName( "InputImage" );
this->SetPrimaryOutputName( "ResultImage" );
this->ComputeSpatialJacobianOff();
this->ComputeDeterminantOfSpatialJacobianOff();
this->m_PointSetFileName = std::string();
this->LogToConsoleOff();
this->LogToFileOff();
}
template< typename TInputImage >
void
TransformixFilter< TInputImage >
::GenerateData( void )
{
// Assert that at least one output has been requested
if( !this->HasInput( "InputImage" ) &&
!this->GetComputeSpatialJacobian() &&
!this->GetComputeDeterminantOfSpatialJacobian() &&
!this->GetComputeDeformationField() &&
this->GetPointSetFileName().empty() )
{
itkExceptionMacro( << "Expected at least one of SetInputImage(), ComputeSpatialJacobianOn(), "
<< "ComputeDeterminantOfSpatialJacobianOn(), SetPointSetFileName() or " );
}
// Check if an output directory is needed
// TODO: Change behaviour upstream to have transformix save all output to its resultImageContainer
if( ( this->GetComputeSpatialJacobian() ||
this->GetComputeDeterminantOfSpatialJacobian() ||
this->GetComputeDeformationField() ||
!this->GetPointSetFileName().empty() ||
this->GetLogToFile() ) &&
this->GetOutputDirectory().empty() )
{
itkExceptionMacro( << "The requested outputs require an output directory to be specified."
<< "Use SetOutputDirectory()." )
}
// Transformix uses "-def" for path to point sets AND as flag for writing deformatin field
// TODO: Change behaviour upstream: Split into seperate arguments
if( this->GetComputeDeformationField() && !this->GetPointSetFileName().empty() )
{
itkExceptionMacro( << "Only one of ComputeDeformationFieldOn() or SetPointSetFileName() can be "
<< "active at any one time for backwards compatibility." )
}
// Setup arguments that transformix uses to figure out what needs to be done
ArgumentMapType argumentMap;
if( this->GetOutputDirectory().empty() ) {
// There must be an "-out", this is checked later in the code
argumentMap.insert( ArgumentMapEntryType( "-out", "output_path_not_set" ) );
}
else
{
argumentMap.insert( ArgumentMapEntryType( "-out", this->GetOutputDirectory() ) );
}
if( this->GetComputeSpatialJacobian() )
{
argumentMap.insert( ArgumentMapEntryType( "-jacmat", "all" ) );
}
if( this->GetComputeDeterminantOfSpatialJacobian() )
{
argumentMap.insert( ArgumentMapEntryType( "-jac", "all" ) );
}
if( this->GetComputeDeformationField() )
{
argumentMap.insert( ArgumentMapEntryType( "-def" , "all" ) );
}
if( !this->GetPointSetFileName().empty() )
{
argumentMap.insert( ArgumentMapEntryType( "-def", this->GetPointSetFileName() ) );
}
// Setup xout
std::string logFileName;
if( this->GetLogToFile() )
{
if( this->GetOutputDirectory().empty() )
{
itkExceptionMacro( "LogToFileOn() requires an output directory to be specified. Use SetOutputDirectory().")
}
logFileName = this->GetOutputDirectory() + "transformix.log";
}
if( elx::xoutSetup( logFileName.c_str(), this->GetLogToFile(), this->GetLogToConsole() ) )
{
// TODO: The following exception is thrown if two different filters are initialized by the same process
itkExceptionMacro( "ERROR while setting up xout" );
}
TransformixMainPointer transformix = TransformixMainType::New();
// Setup image containers
DataObjectContainerPointer inputImageContainer = 0;
if( this->HasInput( "InputImage" ) ) {
std::cout << "Input image is set" << std::endl;
DataObjectContainerPointer inputImageContainer = DataObjectContainerType::New();
inputImageContainer->CreateElementAt(0) = this->GetInput("InputImage");
}
transformix->SetMovingImageContainer( inputImageContainer );
DataObjectContainerPointer resultImageContainer = 0;
transformix->SetResultImageContainer( resultImageContainer );
// Get ParameterMap
ParameterObjectConstPointer transformParameterObject = static_cast< const ParameterObject* >( this->GetInput( "TransformParameterObject" ) );
ParameterMapListType transformParameterMapList = transformParameterObject->GetParameterMapList();
// Run transformix
unsigned int isError = 0;
try
{
isError = transformix->Run( argumentMap, transformParameterMapList );
}
catch( itk::ExceptionObject &e )
{
itkExceptionMacro( << "Errors occured during registration: " << e.what() );
}
if( isError != 0 )
{
std::cout << std::endl << isError << std::endl;
itkExceptionMacro( << "Uncought errors occured during registration." );
}
// Save result image
resultImageContainer = transformix->GetResultImageContainer();
if( resultImageContainer.IsNotNull() && resultImageContainer->Size() > 0 )
{
this->SetOutput( "ResultImage", resultImageContainer->ElementAt( 0 ) );
}
}
template< typename TInputImage >
void
TransformixFilter< TInputImage >
::SetInputImage( InputImagePointer inputImage )
{
this->SetInput( DataObjectIdentifierType( "InputImage" ), static_cast< itk::DataObject* >( inputImage ) );
}
template< typename TInputImage >
void
TransformixFilter< TInputImage >
::SetTransformParameters( ParameterObjectPointer parameterObject )
{
this->SetInput( DataObjectIdentifierType( "TransformParameterObject" ), static_cast< itk::DataObject* >( parameterObject ) );
}
template< typename TInputImage >
typename selx::TransformixFilter< TInputImage >::ParameterObjectPointer
TransformixFilter< TInputImage >
::GetTransformParameters( void )
{
return static_cast< ParameterObject* >( itk::ProcessObject::GetInput( DataObjectIdentifierType( "TransformParameterObject" ) ) );
}
} // namespace selx
#endif // TransformixFilter_hxx
\ No newline at end of file
#ifndef __elxMacro_h
#define __elxMacro_h
#ifndef elxMacro_h
#define elxMacro_h
/**
* Register class with the object factory and set RTTI (Run-Time Type
......@@ -12,4 +12,4 @@
itkNewMacro( Self ); \
itkTypeMacro( Self, superClassName ); \
#endif // __elxMacro_h
\ No newline at end of file
#endif // elxMacro_h
\ No newline at end of file
......@@ -14,9 +14,11 @@ public:
elxNewMacro( ParameterObject, itk::DataObject );
typedef std::vector< std::string > ParameterValuesType;
typedef std::map< std::string, ParameterValuesType > ParameterMapType;
typedef std::vector< ParameterMapType > ParameterMapListType;
typedef std::string ParameterKeyType;
typedef std::string ParameterValueType;
typedef std::vector< ParameterKeyType > ParameterVectorType;
typedef std::map< ParameterKeyType, ParameterVectorType > ParameterMapType;
typedef std::vector< ParameterMapType > ParameterMapListType;
void SetParameterMap( ParameterMapType parameterMap )
{
......@@ -30,20 +32,16 @@ public:
this->m_ParameterMapList = parameterMapList;
};
ParameterMapListType GetParameterMapList( void )
ParameterMapListType& GetParameterMapList( void )
{
this->Modified();
return this->m_ParameterMapList;
};
// TODO:
// itkSetMacro( ParameterMap, ParameterMapType )
// itkGetMacro( ParameterMap, ParameterMapType )
// friend ITKCommon_EXPORT std::ostream& operator<<( std::ostream& os, const ParameterObject& parameterObject )
// {
// os << parameterObject.m_ParameterMapList;
// return os;
// }
const ParameterMapListType& GetParameterMapList( void ) const
{
return this->m_ParameterMapList;
};
private:
......
cmake_minimum_required( VERSION 2.8 )
cmake_minimum_required( VERSION 3.0.2 )
# ---------------------------------------------------------------------
project( SuperElastixSuperBuild )
......@@ -56,6 +56,28 @@ else()
include( ExternalITK )
endif()
# ---------------------------------------------------------------------
# Build Old Elastix
set( ELASTIX_VERSION_MAJOR "4" )
set( ELASTIX_VERSION_MINOR "8" )
set( ELASTIX_VERSION_STRING "${ELASTIX_VERSION_MAJOR}.${ELASTIX_VERSION_MINOR}" )
mark_as_advanced( SUPERELASTIX_BUILD_ELASTIX )
option( SUPERELASTIX_BUILD_ELASTIX "Build SuperElastix support Elastix ${ELASTIX_VERSION_STRING}." ON )
if( SUPERELASTIX_BUILD_ELASTIX )
if( USE_SYSTEM_ELASTIX )
if( NOT EXISTS ${ELASTIX_USE_FILE} )
# Expose CMake variable to user
set( ELASTIX_USE_FILE )
# Stop the build
message( FATAL_ERROR "Please point ELASTIX_USE_FILE to your systems UseElastix.cmake file." )
endif()
else()
include( ExternalElastix )
endif()
endif()
# ---------------------------------------------------------------------
# Boost Graph Library
......@@ -81,24 +103,6 @@ if ( SUPERELASTIX_BUILD_TESTING )
endif()
endif()
# ---------------------------------------------------------------------
# Build Elastix
mark_as_advanced( SUPERELASTIX_BUILD_ELASTIX )
option( SUPERELASTIX_BUILD_ELASTIX ON )
if( SUPERELASTIX_BUILD_ELASTIX )
if( USE_SYSTEM_ELASTIX )
if( NOT EXISTS ${ELASTIX_USE_FILE} )
# Expose CMake variable to user
set( ELASTIX_USE_FILE )
# Stop the build
message( FATAL_ERROR "Please point ELASTIX_USE_FILE to your systems UseElastix.cmake file." )
endif()
else()
include( ExternalElastix )
endif()
endif()
# ---------------------------------------------------------------------
# Build SuperElastix
......
set( proj Elastix )
set( ELASTIX_REPOSITORY git://github.com/mstaring/elastix.git )
set( ELASTIX_REPOSITORY https://github.com/mstaring/elastix.git )
set( ELASTIX_TAG c35842cd0152d8fd2894e7c6706d2dd8396f0fed )
ExternalProject_Add( ${proj}
......
......@@ -6,10 +6,16 @@
set( ElastixUnitTestFilenames
elxBlueprintTest.cxx
elxElastixFilterTest.cxx
elxTransformixFilterTest.cxx
elxComponentFactoryTest.cxx
elxComponentInterfaceTest.cxx
)
# ---------------------------------------------------------------------
# Options
if( SUPERELASTIX_BUILD_LONG_TESTS )
add_definitions( -DSUPERELASTIX_RUN_LONG_TESTS )
endif()
# ---------------------------------------------------------------------
# Set data directories
......@@ -44,6 +50,7 @@ list( APPEND TEST_LIBRARIES
# ---------------------------------------------------------------------
# Build tests
message( STATUS "ITK_LIBRARIES: ${ITK_LIBRARIES}" )
foreach( ElastixUnitTestFilename ${ElastixUnitTestFilenames} )
# Build tests executables
string( REPLACE ".cxx" "" ElastixUnitTest ${ElastixUnitTestFilename} )
......
58e10b6898a5d5271a890eecf25093c2
073df8eb397d1746d2343c78dd4bd964
\ No newline at end of file
073df8eb397d1746d2343c78dd4bd964
9967b9c9bae3af9c3aac9676663ee05d
646be5659d98e7cef40b63b3dff86726
610392a128986d934dfc0a1b0dc27e91
\ No newline at end of file
610392a128986d934dfc0a1b0dc27e91
eefa617b3220c1cea47bdc4672541b2d
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment