Skip to content

Commit

Permalink
Merge remote branch 'origin/master' into fixRegistrationRandomSeed
Browse files Browse the repository at this point in the history
Conflicts:
	Examples/itkantsRegistrationHelper.h
  • Loading branch information
cookpa committed Jun 5, 2018
2 parents 43a6c30 + 6a84ee3 commit 792d673
Show file tree
Hide file tree
Showing 26 changed files with 397 additions and 125 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ addons:
- cmake-data

before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then CMAKE_INSTALLER=install-cmake.sh && curl -sSL https://cmake.org/files/v3.11/cmake-3.11.3-Linux-x86_64.sh -o ${CMAKE_INSTALLER} && chmod +x ${CMAKE_INSTALLER} && sudo ./${CMAKE_INSTALLER} --prefix=/usr/local --skip-license; fi
- alias cmake=/usr/local/bin/cmake
- export PATH=/usr/local/bin/cmake/bin:/usr/local/bin:${PATH}
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then echo "need cmake 3.2"; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update && brew install ccache; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew upgrade cmake; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
- mkdir antsbin
- cd antsbin
Expand Down
2 changes: 1 addition & 1 deletion ANTS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ message(STATUS "Building ${PROJECT_NAME} version \"${${PROJECT_NAME}_VERSION}\""


# Set up ITK
find_package(ITK 4 REQUIRED)
find_package(ITK 5 REQUIRED)
include(${ITK_USE_FILE})


Expand Down
4 changes: 2 additions & 2 deletions CTestCustom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
".*OpenCV.*"
".*VTK.*"
".*has no symbols."
"ITKv4"
"ITKv5"
"SlicerExecutionModel"
"SimpleITK"

Expand Down Expand Up @@ -352,7 +352,7 @@ set(CTEST_CUSTOM_ERROR_EXCEPTION
".*OpenCV.*"
".*VTK.*"
".*has no symbols."
"ITKv4"
"ITKv5"
"SlicerExecutionModel"
"SimpleITK"

Expand Down
7 changes: 3 additions & 4 deletions Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ set(ANTS_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
# endif("${isSystemDir}" STREQUAL "-1")
#####################################################################################################

set(USE_ITKv4 ON)
set(ITK_VERSION_MAJOR 4 CACHE STRING "Choose the expected ITK major version to build ANTS only version 4 allowed.")
set(USE_ITKv5 ON)
set(ITK_VERSION_MAJOR 5 CACHE STRING "Choose the expected ITK major version to build ANTS only version 5 allowed.")
# Set the possible values of ITK major version for cmake-gui
set_property(CACHE ITK_VERSION_MAJOR PROPERTY STRINGS "4")
set_property(CACHE ITK_VERSION_MAJOR PROPERTY STRINGS "5")
set(expected_ITK_VERSION_MAJOR ${ITK_VERSION_MAJOR})
if(${ITK_VERSION_MAJOR} VERSION_LESS ${expected_ITK_VERSION_MAJOR})
# Note: Since ITKv3 doesn't include a ITKConfigVersion.cmake file, let's check the version
Expand Down Expand Up @@ -158,4 +158,3 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()
endif()

3 changes: 1 addition & 2 deletions Examples/CreateDTICohort.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,7 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser )
duplicator->SetInputImage( inputAtlas );
duplicator->Update();

typename TensorImageType::Pointer dti = duplicator->GetModifiableOutput();
dti->DisconnectPipeline();
typename TensorImageType::Pointer dti = duplicator->GetOutput();

// If we are to apply intersubject variability, we calculate random
// projection.
Expand Down
2 changes: 1 addition & 1 deletion Examples/CreateTiledMosaic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ int CreateMosaic( itk::ants::CommandLineParser *parser )
duplicator->SetInputImage( outputRgbSlice2 );
duplicator->Update();

compositeRgbSlice = duplicator->GetModifiableOutput();
compositeRgbSlice = duplicator->GetOutput();
}
compositeAlpha = currentAlpha;
}
Expand Down
23 changes: 17 additions & 6 deletions Examples/ImageMath_Templates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7869,7 +7869,12 @@ int PropagateLabelsThroughMask(int argc, char *argv[])
std::string lname = tempname + std::string("_label") + extension;
WriteImage<ImageType>(fastimage, kname.c_str() );
WriteImage<ImageType>(outlabimage, outname.c_str() );
WriteImage<LabelImageType>(fastMarching->GetLabelImage(), lname.c_str() );

// this nonsense fixes a type error
typedef itk::CastImageFilter<LabelImageType, LabelImageType> CastFilterType;
typename CastFilterType::Pointer castRegions = CastFilterType::New();
castRegions->SetInput( fastMarching->GetLabelImage() );
WriteImage<LabelImageType>( castRegions->GetOutput(), lname.c_str() );
return 0;
}

Expand Down Expand Up @@ -8141,7 +8146,13 @@ int itkPropagateLabelsThroughMask(int argc, char *argv[])
std::string lname = tempname + std::string("_label") + extension;
WriteImage<ImageType>(fastimage, kname.c_str() );
WriteImage<ImageType>(outlabimage, outname.c_str() );
WriteImage<LabelImageType>(fastMarching->GetLabelImage(), lname.c_str() );

// this nonsense fixes a type error
typedef itk::CastImageFilter<LabelImageType, LabelImageType> CastFilterType;
typename CastFilterType::Pointer castRegions = CastFilterType::New();
castRegions->SetInput( fastMarching->GetLabelImage() );
WriteImage<LabelImageType>( castRegions->GetOutput(), lname.c_str() );

return 0;
}

Expand Down Expand Up @@ -8701,7 +8712,7 @@ int PoissonDiffusion( int argc, char *argv[])
duplicator->SetInputImage( reader->GetOutput() );
duplicator->Update();

typename ImageType::Pointer output = duplicator->GetModifiableOutput();
typename ImageType::Pointer output = duplicator->GetOutput();
output->DisconnectPipeline();

typedef itk::ImageFileReader<LabelImageType> LabelReaderType;
Expand Down Expand Up @@ -12750,7 +12761,7 @@ int InPaint(int argc, char *argv[])
typename DuplicatorType::Pointer duplicator = DuplicatorType::New();
duplicator->SetInputImage( image1 );
duplicator->Update();
typename ImageType::Pointer varimage = duplicator->GetModifiableOutput();
typename ImageType::Pointer varimage = duplicator->GetOutput();
for ( unsigned int i = 0; i < sigma; i++ )
{
typedef itk::ConvolutionImageFilter< ImageType, ImageType > FilterType;
Expand Down Expand Up @@ -12991,7 +13002,7 @@ int Check3TissueLabeling( int argc, char *argv[] )
duplicator->SetInputImage( labelImage );
duplicator->Update();

typename LabelImageType::Pointer permutedLabelImage = duplicator->GetModifiableOutput();
typename LabelImageType::Pointer permutedLabelImage = duplicator->GetOutput();

itk::ImageRegionIterator<LabelImageType> ItP( permutedLabelImage, permutedLabelImage->GetRequestedRegion() );
for( ItP.GoToBegin(); !ItP.IsAtEnd(); ++ItP )
Expand Down Expand Up @@ -13065,7 +13076,7 @@ int Check3TissueLabeling( int argc, char *argv[] )
duplicator->SetInputImage( labelImage );
duplicator->Update();

typename LabelImageType::Pointer permutedLabelImage = duplicator->GetModifiableOutput();
typename LabelImageType::Pointer permutedLabelImage = duplicator->GetOutput();

itk::ImageRegionIteratorWithIndex<LabelImageType> ItP( permutedLabelImage,
permutedLabelImage->GetRequestedRegion() );
Expand Down
5 changes: 5 additions & 0 deletions Examples/LabelClustersUniquely.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ int LabelClustersUniquely( std::vector<std::string> args, std::ostream* /*out_st
return LabelUniquely<3>(argc, argv + 1);
}
break;
case 4:
{
return LabelUniquely<4>(argc, argv + 1);
}
break;
default:
std::cout << "Unsupported dimension" << std::endl;
return EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion Examples/LabelGeometryMeasures.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ int LabelGeometryMeasures( int argc, char * argv[] )
}

std::vector<std::string> rowHeaders;
std::ostringstream convert;// stream used for the conversion
for( allLabelsIt = allLabels.begin(); allLabelsIt != allLabels.end(); allLabelsIt++ )
{
if( *allLabelsIt == 0 )
{
continue;
}
std::ostringstream convert;// stream used for the conversion
convert << *allLabelsIt; // insert the textual representation of 'Number' in the characters in the stream
rowHeaders.push_back( convert.str() ); // set 'Result' to the contents of the stream
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/SmoothDisplacementField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int SmoothDisplacementField( int argc, char *argv[] )
duplicator->SetInputImage( field );
duplicator->Update();

smoothField = duplicator->GetModifiableOutput();
smoothField = duplicator->GetOutput();

itk::TimeProbe timer;
timer.Start();
Expand Down
44 changes: 27 additions & 17 deletions Examples/antsAI.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,15 @@ int antsAI( itk::ants::CommandLineParser *parser )
itk::ants::CommandLineParser::OptionType::Pointer translationSearchGridOption = parser->GetOption( "translation-search-grid" );
if( translationSearchGridOption && translationSearchGridOption->GetNumberOfFunctions() )
{
translationSearchGrid = parser->ConvertVector<RealType>( translationSearchGridOption->GetFunction( 0 )->GetParameter( 0 ) );

translationSearchStepSize = parser->Convert<RealType>( translationSearchGridOption->GetFunction( 0 )->GetParameter( 0 ) );

if( translationSearchGridOption->GetFunction( 0 )->GetNumberOfParameters() > 1 )
{
translationSearchStepSize = parser->Convert<RealType>( translationSearchGridOption->GetFunction( 0 )->GetParameter( 1 ) );
translationSearchGrid = parser->ConvertVector<RealType>( translationSearchGridOption->GetFunction( 0 )->GetParameter( 1 ) );
}
}

itk::ants::CommandLineParser::OptionType::Pointer transformOption = parser->GetOption( "transform" );
if( transformOption && transformOption->GetNumberOfFunctions() )
{
Expand Down Expand Up @@ -1179,8 +1181,16 @@ int antsAI( itk::ants::CommandLineParser *parser )

typedef typename itk::Statistics::MersenneTwisterRandomVariateGenerator RandomizerType;
typename RandomizerType::Pointer randomizer = RandomizerType::New();
randomizer->SetSeed( 1234 );

char* antsRandomSeed = getenv( "ANTS_RANDOM_SEED" );
if ( antsRandomSeed != NULL )
{
randomizer->SetSeed( atoi( antsRandomSeed ) );
}
else
{
randomizer->SetSeed( 1234 );
}
unsigned long index = 0;

switch( samplingStrategy )
Expand Down Expand Up @@ -1295,7 +1305,7 @@ int antsAI( itk::ants::CommandLineParser *parser )
multiStartOptimizer->SetMetric( imageMetric );

unsigned int trialCounter = 0;

typename MultiStartOptimizerType::ParametersListType parametersList = multiStartOptimizer->GetParametersList();
for( RealType angle1 = ( vnl_math::pi * -arcFraction ); angle1 <= ( vnl_math::pi * arcFraction + 0.000001 ); angle1 += searchFactor )
{
Expand All @@ -1310,14 +1320,14 @@ int antsAI( itk::ants::CommandLineParser *parser )
typename AffineTransformType::OutputVectorType searchTranslation;
searchTranslation[0] = translation1;
searchTranslation[1] = translation2;

affineSearchTransform->SetIdentity();
affineSearchTransform->SetCenter( initialTransform->GetCenter() );
affineSearchTransform->SetMatrix( initialTransform->GetMatrix() );
affineSearchTransform->SetOffset( initialTransform->GetOffset() );
affineSearchTransform->Translate( searchTranslation , 1 );
affineSearchTransform->Rotate2D( angle1, 1 );

if( strcmp( transform.c_str(), "affine" ) == 0 )
{
affineSearchTransform->Scale( bestScale );
Expand All @@ -1329,7 +1339,7 @@ int antsAI( itk::ants::CommandLineParser *parser )
rigidSearchTransform->SetCenter( initialTransform->GetCenter() );
rigidSearchTransform->SetMatrix( affineSearchTransform->GetMatrix() );
rigidSearchTransform->SetOffset( initialTransform->GetOffset() );

parametersList.push_back( rigidSearchTransform->GetParameters() );
}
else if( strcmp( transform.c_str(), "similarity" ) == 0 )
Expand All @@ -1339,9 +1349,9 @@ int antsAI( itk::ants::CommandLineParser *parser )
similaritySearchTransform->SetMatrix( affineSearchTransform->GetMatrix() );
similaritySearchTransform->SetOffset( initialTransform->GetOffset() );
similaritySearchTransform->SetScale( bestScale );

similaritySearchTransform->SetScale( bestScale );

parametersList.push_back( similaritySearchTransform->GetParameters() );
}
trialCounter++;
Expand All @@ -1367,7 +1377,7 @@ int antsAI( itk::ants::CommandLineParser *parser )
searchTranslation[0] = translation1;
searchTranslation[1] = translation2;
searchTranslation[2] = translation3;

affineSearchTransform->SetIdentity();
affineSearchTransform->SetCenter( initialTransform->GetCenter() );
affineSearchTransform->SetOffset( initialTransform->GetOffset() );
Expand All @@ -1376,7 +1386,7 @@ int antsAI( itk::ants::CommandLineParser *parser )
affineSearchTransform->Rotate3D( axis1, angle1, 1 );
affineSearchTransform->Rotate3D( axis2, angle2, 1 );
affineSearchTransform->Rotate3D( axis1, angle3, 1 );

if( strcmp( transform.c_str(), "affine" ) == 0 )
{
affineSearchTransform->Scale( bestScale );
Expand All @@ -1398,7 +1408,7 @@ int antsAI( itk::ants::CommandLineParser *parser )
similaritySearchTransform->SetOffset( initialTransform->GetOffset() );
similaritySearchTransform->SetMatrix( affineSearchTransform->GetMatrix() );
similaritySearchTransform->SetScale( bestScale );

parametersList.push_back( similaritySearchTransform->GetParameters() );
}
}
Expand All @@ -1409,17 +1419,17 @@ int antsAI( itk::ants::CommandLineParser *parser )
}
}
}

if( verbose )
{
std::cout << "Starting optimizer with " << trialCounter << " starting points" << std::endl;
}

multiStartOptimizer->SetParametersList( parametersList );
multiStartOptimizer->SetLocalOptimizer( localOptimizer );
multiStartOptimizer->StartOptimization();


/////////////////////////////////////////////////////////////////
//
// Write the output after convergence
Expand Down Expand Up @@ -1572,7 +1582,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser )
option->SetDescription( description );
parser->AddOption( option );
}

{
std::string description =
std::string( "Number of iterations." );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ class antsDisplacementAndVelocityFieldRegistrationCommandIterationUpdate : publi
GetInverseDisplacementField() );
FixedInverseDisplacementDuplicator->Update();

myFixedToMiddleTransform->SetDisplacementField( FixedDisplacementDuplicator->GetModifiableOutput() );
myFixedToMiddleTransform->SetInverseDisplacementField( FixedInverseDisplacementDuplicator->GetModifiableOutput() );
myFixedToMiddleTransform->SetDisplacementField( FixedDisplacementDuplicator->GetOutput() );
myFixedToMiddleTransform->SetInverseDisplacementField( FixedInverseDisplacementDuplicator->GetOutput() );

// copy MovingToMiddleTransform
typename DisplacementFieldDuplicatorType::Pointer MovingDisplacementDuplicator =
Expand All @@ -288,8 +288,8 @@ class antsDisplacementAndVelocityFieldRegistrationCommandIterationUpdate : publi
GetInverseDisplacementField() );
MovingInverseDisplacementDuplicator->Update();

myMovingToMiddleTransform->SetDisplacementField( MovingDisplacementDuplicator->GetModifiableOutput() );
myMovingToMiddleTransform->SetInverseDisplacementField( MovingInverseDisplacementDuplicator->GetModifiableOutput() );
myMovingToMiddleTransform->SetDisplacementField( MovingDisplacementDuplicator->GetOutput() );
myMovingToMiddleTransform->SetInverseDisplacementField( MovingInverseDisplacementDuplicator->GetOutput() );

// Based on SyN Registration implementation, fixed composite and moving composite transforms are generated to
// compute the metric value at each iteration.
Expand Down Expand Up @@ -413,8 +413,8 @@ class antsDisplacementAndVelocityFieldRegistrationCommandIterationUpdate : publi
disInverseDuplicator->Update();

typename DisplacementFieldTransformType::Pointer outputTransformReadyToUse = DisplacementFieldTransformType::New();
outputTransformReadyToUse->SetDisplacementField( disDuplicator->GetModifiableOutput() );
outputTransformReadyToUse->SetInverseDisplacementField( disInverseDuplicator->GetModifiableOutput() );
outputTransformReadyToUse->SetDisplacementField( disDuplicator->GetOutput() );
outputTransformReadyToUse->SetInverseDisplacementField( disInverseDuplicator->GetOutput() );

// Now add this updated transform to the composite transform including the initial trnasform
typedef typename TFilter::InitialTransformType InitialTransformType;
Expand Down
Loading

0 comments on commit 792d673

Please sign in to comment.