From a07c2f32b30fe2ef5007ab04e63512ad7a10b55c Mon Sep 17 00:00:00 2001 From: Nick Tustison Date: Thu, 25 Oct 2012 02:48:06 +0000 Subject: [PATCH] ENH: Changes to the command line parser to permit multiple metrics per stage in antsRegistration. --- Examples/ANTSConformalMapping.cxx | 40 +- Examples/Atropos.cxx | 350 ++++++++---------- Examples/AtroposMin.cxx | 62 ++-- Examples/CreateDTICohort.cxx | 130 +++---- Examples/KellyKapowski.cxx | 138 +++---- Examples/N4BiasFieldCorrection.cxx | 86 ++--- Examples/antsAlignOrigin.cxx | 54 +-- Examples/antsApplyTransforms.cxx | 85 ++--- Examples/antsApplyTransformsToPoints.cxx | 45 +-- Examples/antsMotionCorr.cxx | 140 +++---- Examples/antsRegistration.cxx | 242 ++++++------ Examples/itkantsRegistrationHelper.h | 39 +- Examples/make_interpolator_snip.tmpl | 64 ++-- Examples/sccan.cxx | 178 ++++----- .../itkANTSImageRegistrationOptimizer.h | 70 ++-- .../itkPICSLAdvancedNormalizationToolKit.hxx | 173 ++++----- Utilities/antsCommandLineOption.cxx | 42 +-- Utilities/antsCommandLineOption.h | 145 +++++--- Utilities/antsCommandLineParser.cxx | 134 ++++--- Utilities/antsCommandLineParser.h | 8 + 20 files changed, 1134 insertions(+), 1091 deletions(-) diff --git a/Examples/ANTSConformalMapping.cxx b/Examples/ANTSConformalMapping.cxx index 8d5fd3197..a15765a2c 100644 --- a/Examples/ANTSConformalMapping.cxx +++ b/Examples/ANTSConformalMapping.cxx @@ -145,7 +145,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -155,7 +155,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -220,9 +220,9 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) float inflate_param = 0; typename itk::ants::CommandLineParser::OptionType::Pointer infOption = parser->GetOption( "inflate" ); - if( infOption && infOption->GetNumberOfValues() > 0 ) + if( infOption && infOption->GetNumberOfFunctions() ) { - if( infOption->GetNumberOfParameters() == 2 ) + if( infOption->GetFunction( 0 )->GetNumberOfParameters() == 2 ) { inflate_param = parser->Convert(infOption->GetParameter( 0 ) ); inflate_iterations = parser->Convert(infOption->GetParameter( 1 ) ); @@ -240,9 +240,9 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) float maxCost = 40, distCostW = 1, labelCostW = 0; typename itk::ants::CommandLineParser::OptionType::Pointer costOption = parser->GetOption( "segmentation-cost" ); - if( costOption && costOption->GetNumberOfValues() > 0 ) + if( costOption && costOption->GetNumberOfFunctions() ) { - if( costOption->GetNumberOfParameters() == 3 ) + if( costOption->GetFunction( 0 )->GetNumberOfParameters() == 3 ) { maxCost = parser->Convert(costOption->GetParameter( 0 ) ); distCostW = parser->Convert(costOption->GetParameter( 1 ) ); @@ -257,9 +257,9 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) } typename itk::ants::CommandLineParser::OptionType::Pointer displayOption = parser->GetOption( "display-mesh" ); - if( displayOption && displayOption->GetNumberOfValues() > 0 ) + if( displayOption && displayOption->GetNumberOfFunctions() ) { - if( displayOption->GetNumberOfParameters() > 0 ) + if( displayOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { std::string dispm = displayOption->GetParameter( 0 ); antscout << " render " << dispm << std::endl; @@ -309,7 +309,7 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer inOption = parser->GetOption( "input-mesh" ); - if( inOption && inOption->GetNumberOfParameters() == 2 ) + if( inOption && inOption->GetFunction( 0 )->GetNumberOfParameters() == 2 ) { std::string innm = inOption->GetParameter( 0 ); vtkSmartPointer labReader = vtkSmartPointer::New(); @@ -355,9 +355,9 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) inflatedmesh = vtkSmartPointer(smoother->GetOutput() ); antscout << " done smoothing " << std::endl; flattener->SetSurfaceMesh(inflatedmesh); - if( outputOption->GetNumberOfParameters() > 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - for( unsigned int p = 0; p < outputOption->GetNumberOfParameters(); p++ ) + for( unsigned int p = 0; p < outputOption->GetFunction( 0 )->GetNumberOfParameters(); p++ ) { if( p == 2 && inflatedmesh ) { @@ -379,13 +379,13 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) flattener->SetSurfaceFeatureMesh(featuremesh); } - bool paramws = parser->template Convert( parser->GetOption( "param-while-searching" )->GetValue() ); + bool paramws = parser->template Convert( parser->GetOption( "param-while-searching" )->GetFunction() ); flattener->SetParamWhileSearching(paramws); unsigned int labeltoflatten = parser->template Convert( - parser->GetOption( "label-to-flatten" )->GetValue() ); + parser->GetOption( "label-to-flatten" )->GetFunction() ); flattener->SetLabelToFlatten(labeltoflatten); - std::string canonicaldomain = parser->GetOption( "canonical-domain" )->GetValue(); + std::string canonicaldomain = parser->GetOption( "canonical-domain" )->GetFunction(); // canonicaldomain=ConvertToLowerCase( canonicaldomain ); antscout << " you will map label " << labeltoflatten << " to a " << canonicaldomain << std::endl; if( canonicaldomain == std::string("circle") ) @@ -402,7 +402,7 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) return EXIT_FAILURE; } - std::string boundaryparam = parser->GetOption( "boundary-param" )->GetValue(); + std::string boundaryparam = parser->GetOption( "boundary-param" )->GetFunction(); // do stuff -- but not implemented yet // flattener->SetDiscBoundaryList(NULL); @@ -420,11 +420,11 @@ int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) /** * output */ - if( outputOption && outputOption->GetNumberOfValues() > 0 ) + if( outputOption && outputOption->GetNumberOfFunctions() ) { - if( outputOption->GetNumberOfParameters() > 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - for( unsigned int p = 0; p < outputOption->GetNumberOfParameters(); p++ ) + for( unsigned int p = 0; p < outputOption->GetFunction( 0 )->GetNumberOfParameters(); p++ ) { if( p == 0 ) { @@ -531,7 +531,7 @@ int ANTSConformalMapping( std::vector args, std::ostream* out_strea parser->Parse( argc, argv ); if( argc < 2 || parser->Convert( - parser->GetOption( "help" )->GetValue() ) ) + parser->GetOption( "help" )->GetFunction() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -541,7 +541,7 @@ int ANTSConformalMapping( std::vector args, std::ostream* out_strea return EXIT_SUCCESS; } else if( parser->Convert( - parser->GetOption( 'h' )->GetValue() ) ) + parser->GetOption( 'h' )->GetFunction() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; diff --git a/Examples/Atropos.cxx b/Examples/Atropos.cxx index e13a8fd81..e6de4bc72 100644 --- a/Examples/Atropos.cxx +++ b/Examples/Atropos.cxx @@ -107,10 +107,10 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer memoryOption = parser->GetOption( "minimize-memory-usage" ); - if( memoryOption && memoryOption->GetNumberOfValues() > 0 ) + if( memoryOption && memoryOption->GetNumberOfFunctions() ) { segmenter->SetMinimizeMemoryUsage( parser->Convert( - memoryOption->GetValue() ) ); + memoryOption->GetFunction( 0 )->GetName() ) ); } /** @@ -119,7 +119,7 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer initializationOption = parser->GetOption( "initialization" ); if( initializationOption - && initializationOption->GetNumberOfParameters() < 1 ) + && initializationOption->GetFunction( 0 )->GetNumberOfParameters() < 1 ) { antscout << "Incorrect initialization option specification." << std::endl; antscout << " " << initializationOption->GetDescription() << std::endl; @@ -128,9 +128,9 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) else { segmenter->SetNumberOfTissueClasses( parser->Convert( - initializationOption->GetParameter( 0 ) ) ); + initializationOption->GetFunction( 0 )->GetParameter( 0 ) ) ); - std::string initializationStrategy = initializationOption->GetValue(); + std::string initializationStrategy = initializationOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( initializationStrategy ); if( !initializationStrategy.compare( std::string( "random" ) ) ) { @@ -143,10 +143,10 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) else if( !initializationStrategy.compare( std::string( "kmeans" ) ) ) { segmenter->SetInitializationStrategy( SegmentationFilterType::KMeans ); - if( initializationOption->GetNumberOfParameters() > 1 ) + if( initializationOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { std::vector clusterCenters = parser->ConvertVector( - initializationOption->GetParameter( 1 ) ); + initializationOption->GetFunction( 0 )->GetParameter( 1 ) ); if( clusterCenters.size() != segmenter->GetNumberOfTissueClasses() ) { antscout << "The cluster center vector size does not equal the " @@ -170,7 +170,7 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) { segmenter->SetInitializationStrategy( SegmentationFilterType::PriorProbabilityImages ); - if( initializationOption->GetNumberOfParameters() < 3 ) + if( initializationOption->GetFunction( 0 )->GetNumberOfParameters() < 3 ) { antscout << "Incorrect initialization option specification." << std::endl; @@ -179,14 +179,14 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) return EXIT_FAILURE; } segmenter->SetPriorProbabilityWeight( parser->Convert( - initializationOption->GetParameter( 2 ) ) ); - if( initializationOption->GetNumberOfParameters() > 3 ) + initializationOption->GetFunction( 0 )->GetParameter( 2 ) ) ); + if( initializationOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { segmenter->SetProbabilityThreshold( parser->Convert( - initializationOption->GetParameter( 3 ) ) ); + initializationOption->GetFunction( 0 )->GetParameter( 3 ) ) ); } - std::string filename = initializationOption->GetParameter( 1 ); + std::string filename = initializationOption->GetFunction( 0 )->GetParameter( 1 ); if( filename.find( std::string( "%" ) ) != std::string::npos ) { @@ -234,10 +234,10 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) segmenter->SetPriorProbabilityImage( k + 1, caster->GetOutput() ); } } - if( initializationOption->GetNumberOfParameters() > 3 ) + if( initializationOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { segmenter->SetProbabilityThreshold( parser->Convert( - initializationOption->GetParameter( 3 ) ) ); + initializationOption->GetFunction( 0 )->GetParameter( 3 ) ) ); } } else if( !initializationStrategy.compare( std::string( "priorlabelimage" ) ) ) @@ -245,16 +245,16 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) segmenter->SetInitializationStrategy( SegmentationFilterType::PriorLabelImage ); - if( initializationOption->GetNumberOfParameters() < 3 ) + if( initializationOption->GetFunction( 0 )->GetNumberOfParameters() < 3 ) { antscout << "Incorrect initialization option specification." << std::endl; antscout << " " << initializationOption->GetDescription() << std::endl; return EXIT_FAILURE; } segmenter->SetPriorProbabilityWeight( parser->Convert( - initializationOption->GetParameter( 2 ) ) ); + initializationOption->GetFunction( 0 )->GetParameter( 2 ) ) ); - std::string filename = initializationOption->GetParameter( 1 ); + std::string filename = initializationOption->GetFunction( 0 )->GetParameter( 1 ); typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( filename.c_str() ); @@ -276,16 +276,16 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) parser->GetOption( "posterior-formulation" ); if( posteriorOption ) { - if( posteriorOption->GetNumberOfParameters() > 0 ) + if( posteriorOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { segmenter->SetUseMixtureModelProportions( parser->Convert( - posteriorOption->GetParameter( 0 ) ) ); + posteriorOption->GetFunction( 0 )->GetParameter( 0 ) ) ); RealType annealingTemperature = 1.0; - if( posteriorOption->GetNumberOfParameters() > 1 ) + if( posteriorOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { annealingTemperature = - parser->Convert( posteriorOption->GetParameter( 1 ) ); + parser->Convert( posteriorOption->GetFunction( 0 )->GetParameter( 1 ) ); if( annealingTemperature <= 0.0 ) { antscout << "Annealing temperature must be positive." << std::endl; @@ -295,10 +295,10 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) segmenter->SetInitialAnnealingTemperature( annealingTemperature ); RealType annealingRate = 1.0; - if( posteriorOption->GetNumberOfParameters() > 2 ) + if( posteriorOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { annealingRate = - parser->Convert( posteriorOption->GetParameter( 2 ) ); + parser->Convert( posteriorOption->GetFunction( 0 )->GetParameter( 2 ) ); if( annealingRate < 0.0 || annealingRate > 1.0 ) { antscout << "Annealing rate must be in the range [0, 1]." << std::endl; @@ -307,14 +307,14 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) } segmenter->SetAnnealingRate( annealingRate ); - if( posteriorOption->GetNumberOfParameters() > 3 ) + if( posteriorOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { RealType minimumAnnealingTemperature = - parser->Convert( posteriorOption->GetParameter( 3 ) ); + parser->Convert( posteriorOption->GetFunction( 0 )->GetParameter( 3 ) ); segmenter->SetMinimumAnnealingTemperature( minimumAnnealingTemperature ); } } - std::string posteriorStrategy = posteriorOption->GetValue(); + std::string posteriorStrategy = posteriorOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( posteriorStrategy ); if( !posteriorStrategy.compare( std::string( "socrates" ) ) ) @@ -341,15 +341,15 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) parser->GetOption( "convergence" ); if( convergenceOption ) { - if( convergenceOption->GetNumberOfParameters() > 0 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { segmenter->SetMaximumNumberOfIterations( parser->Convert( - convergenceOption->GetParameter( 0 ) ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } - if( convergenceOption->GetNumberOfParameters() > 1 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { segmenter->SetConvergenceThreshold( parser->Convert( - convergenceOption->GetParameter( 1 ) ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } } @@ -358,13 +358,13 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer maskOption = parser->GetOption( "mask-image" ); - if( maskOption && maskOption->GetNumberOfValues() > 0 ) + if( maskOption && maskOption->GetNumberOfFunctions() ) { try { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( ( maskOption->GetValue() ).c_str() ); + reader->SetFileName( ( maskOption->GetFunction( 0 )->GetName() ).c_str() ); reader->Update(); segmenter->SetMaskImage( reader->GetOutput() ); @@ -446,12 +446,12 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer bsplineOption = parser->GetOption( "bspline" ); - if( bsplineOption && bsplineOption->GetNumberOfValues() ) + if( bsplineOption && bsplineOption->GetNumberOfFunctions() ) { - if( bsplineOption->GetNumberOfParameters() > 0 ) + if( bsplineOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { std::vector numLevels = parser->ConvertVector( - bsplineOption->GetParameter( 0 ) ); + bsplineOption->GetFunction( 0 )->GetParameter( 0 ) ); typename SegmentationFilterType::ArrayType numberOfFittingLevels; if( numLevels.size() == 1 ) @@ -472,15 +472,15 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) } segmenter->SetNumberOfLevels( numberOfFittingLevels ); } - if( bsplineOption->GetNumberOfParameters() > 2 ) + if( bsplineOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { segmenter->SetSplineOrder( parser->Convert( - bsplineOption->GetParameter( 2 ) ) ); + bsplineOption->GetFunction( 0 )->GetParameter( 2 ) ) ); } - if( bsplineOption->GetNumberOfParameters() > 1 ) + if( bsplineOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { std::vector array = parser->ConvertVector( - bsplineOption->GetParameter( 1 ) ); + bsplineOption->GetFunction( 0 )->GetParameter( 1 ) ); typename SegmentationFilterType::ArrayType numberOfControlPoints; if( array.size() == 1 ) { @@ -507,20 +507,20 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer labelOption = parser->GetOption( "label-propagation" ); - if( labelOption && labelOption->GetNumberOfValues() > 0 ) + if( labelOption && labelOption->GetNumberOfFunctions() ) { - if( labelOption->GetNumberOfValues() == 1 && - ( labelOption->GetValue( 0 ) ).empty() ) + if( labelOption->GetNumberOfFunctions() == 1 && + ( labelOption->GetFunction( 0 )->GetName() ).empty() ) { typename SegmentationFilterType::LabelParameterMapType labelMap; float labelLambda = parser->Convert( - labelOption->GetParameter( 0, 0 ) ); + labelOption->GetFunction( 0 )->GetParameter( 0 ) ); float labelBoundaryProbability = 1.0; - if( labelOption->GetNumberOfParameters( 0 ) > 1 ) + if( labelOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { labelBoundaryProbability = parser->Convert( - labelOption->GetParameter( 0, 1 ) ); + labelOption->GetFunction( 0 )->GetParameter( 1 ) ); if( labelBoundaryProbability < 0.0 ) { labelBoundaryProbability = 0.0; @@ -542,17 +542,16 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) else { typename SegmentationFilterType::LabelParameterMapType labelMap; - for( unsigned int n = 0; n < labelOption->GetNumberOfValues(); n++ ) + for( unsigned int n = 0; n < labelOption->GetNumberOfFunctions(); n++ ) { typename SegmentationFilterType::LabelParametersType labelPair; float labelLambda = parser->Convert( - labelOption->GetParameter( n, 0 ) ); + labelOption->GetFunction( n )->GetParameter( 0 ) ); float labelBoundaryProbability = 1.0; - if( labelOption->GetNumberOfParameters( n ) > 1 ) + if( labelOption->GetFunction( n )->GetNumberOfParameters() > 1 ) { - labelBoundaryProbability = parser->Convert( - labelOption->GetParameter( n, 1 ) ); + labelBoundaryProbability = parser->Convert( labelOption->GetFunction( n )->GetParameter( 1 ) ); if( labelBoundaryProbability < 0.0 ) { labelBoundaryProbability = 0.0; @@ -565,8 +564,7 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) labelPair.first = labelLambda; labelPair.second = labelBoundaryProbability; - unsigned int whichClass = parser->Convert( - labelOption->GetValue( n ) ); + unsigned int whichClass = parser->Convert( labelOption->GetFunction( n )->GetName() ); labelMap[whichClass] = labelPair; } @@ -579,28 +577,29 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "intensity-image" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() ) { unsigned int count = 0; - for( int n = imageOption->GetNumberOfValues() - 1; n >= 0; n-- ) + for( int n = imageOption->GetNumberOfFunctions() - 1; n >= 0; n-- ) { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - if( imageOption->GetNumberOfParameters( n ) > 0 ) + if( imageOption->GetFunction( n )->GetNumberOfParameters() > 0 ) { - reader->SetFileName( imageOption->GetParameter( n, 0 ) ); + reader->SetFileName( imageOption->GetFunction( n )->GetParameter( 0 ) ); } else { - reader->SetFileName( imageOption->GetValue( n ) ); + reader->SetFileName( imageOption->GetFunction( n )->GetName() ); } reader->Update(); segmenter->SetIntensityImage( count, reader->GetOutput() ); - if( imageOption->GetNumberOfParameters( count ) > 1 ) + if( imageOption->GetFunction( count )->GetNumberOfParameters() > 1 ) { - segmenter->SetAdaptiveSmoothingWeight( count, parser->Convert( - imageOption->GetParameter( count, 1 ) ) ); + segmenter->SetAdaptiveSmoothingWeight( count, + parser->Convert( imageOption->GetFunction( count )->GetParameter( + 1 ) ) ); } else { @@ -621,9 +620,9 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer mrfOption = parser->GetOption( "mrf" ); - if( mrfOption && mrfOption->GetNumberOfValues() > 0 ) + if( mrfOption && mrfOption->GetNumberOfFunctions() ) { - if( mrfOption->GetNumberOfParameters() > 0 ) + if( mrfOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { try { @@ -633,7 +632,7 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) MRFNeighborhoodImageReaderType; typename MRFNeighborhoodImageReaderType::Pointer mrfNeighborhoodReader = MRFNeighborhoodImageReaderType::New(); - mrfNeighborhoodReader->SetFileName( mrfOption->GetParameter( 0 ) ); + mrfNeighborhoodReader->SetFileName( mrfOption->GetFunction( 0 )->GetParameter( 0 ) ); typename MRFCoefficientImageType::Pointer mrfCoefficientImage = mrfNeighborhoodReader->GetOutput(); @@ -644,14 +643,13 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) } catch( ... ) { - segmenter->SetMRFSmoothingFactor( parser->Convert( - mrfOption->GetParameter( 0 ) ) ); + segmenter->SetMRFSmoothingFactor( parser->Convert( mrfOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } } - if( mrfOption->GetNumberOfParameters() > 1 ) + if( mrfOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - std::vector array = parser->ConvertVector( - mrfOption->GetParameter( 1 ) ); + std::vector array = + parser->ConvertVector( mrfOption->GetFunction( 0 )->GetParameter( 1 ) ); typename SegmentationFilterType::ArrayType radius; if( array.size() == 1 ) { @@ -679,22 +677,21 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer icmOption = parser->GetOption( "icm" ); - if( icmOption && icmOption->GetNumberOfValues() == 1 ) + if( icmOption && icmOption->GetNumberOfFunctions() == 1 ) { segmenter->SetUseAsynchronousUpdating( parser->Convert( - icmOption->GetValue( 0 ) ) ); + icmOption->GetFunction( 0 )->GetName() ) ); } - if( icmOption && icmOption->GetNumberOfValues() > 0 ) + if( icmOption && icmOption->GetNumberOfFunctions() ) { - if( icmOption->GetNumberOfParameters() > 0 ) + if( icmOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - segmenter->SetUseAsynchronousUpdating( parser->Convert( - icmOption->GetParameter( 0 ) ) ); + segmenter->SetUseAsynchronousUpdating( parser->Convert( icmOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } - if( icmOption->GetNumberOfParameters() > 1 ) + if( icmOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - segmenter->SetMaximumNumberOfICMIterations( parser->Convert( - icmOption->GetParameter( 1 ) ) ); + segmenter->SetMaximumNumberOfICMIterations( parser->Convert( icmOption->GetFunction( 0 )-> + GetParameter( 1 ) ) ); } } @@ -703,10 +700,10 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer distanceOption = parser->GetOption( "use-euclidean-distance" ); - if( distanceOption && distanceOption->GetNumberOfValues() > 0 ) + if( distanceOption && distanceOption->GetNumberOfFunctions() ) { segmenter->SetUseEuclideanDistanceForPriorLabels( - parser->Convert( distanceOption->GetValue() ) ); + parser->Convert( distanceOption->GetFunction( 0 )->GetName() ) ); } /** @@ -714,9 +711,9 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer likelihoodOption = parser->GetOption( "likelihood-model" ); - if( likelihoodOption && likelihoodOption->GetNumberOfValues() > 0 ) + if( likelihoodOption && likelihoodOption->GetNumberOfFunctions() ) { - std::string likelihoodModel = likelihoodOption->GetValue(); + std::string likelihoodModel = likelihoodOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( likelihoodModel ); if( !likelihoodModel.compare( std::string( "gaussian" ) ) ) { @@ -737,28 +734,24 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) LikelihoodType; float regularizationSigma = 1.0; - if( likelihoodOption->GetNumberOfParameters() > 0 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - regularizationSigma = parser->Convert( - likelihoodOption->GetParameter( 0 ) ); + regularizationSigma = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 0 ) ); } unsigned int evalNeighborhood = 50; - if( likelihoodOption->GetNumberOfParameters() > 1 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - evalNeighborhood = parser->Convert( - likelihoodOption->GetParameter( 1 ) ); + evalNeighborhood = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 1 ) ); } unsigned int covNeighborhood = 0; - if( likelihoodOption->GetNumberOfParameters() > 2 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - covNeighborhood = parser->Convert( - likelihoodOption->GetParameter( 2 ) ); + covNeighborhood = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 2 ) ); } float covSigma = 1.0; - if( likelihoodOption->GetNumberOfParameters() > 3 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { - covSigma = parser->Convert( - likelihoodOption->GetParameter( 3 ) ); + covSigma = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 3 ) ); } for( unsigned int n = 0; n < segmenter->GetNumberOfTissueClasses(); n++ ) { @@ -778,16 +771,14 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) LikelihoodType; float sigma = 1.0; - if( likelihoodOption->GetNumberOfParameters() > 0 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - sigma = parser->Convert( - likelihoodOption->GetParameter( 0 ) ); + sigma = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 0 ) ); } unsigned int numberOfBins = 32; - if( likelihoodOption->GetNumberOfParameters() > 1 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - numberOfBins = parser->Convert( - likelihoodOption->GetParameter( 1 ) ); + numberOfBins = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 1 ) ); } for( unsigned int n = 0; n < segmenter->GetNumberOfTissueClasses(); n++ ) { @@ -814,28 +805,25 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) LikelihoodType; float shapeSigma = 2.0; - if( likelihoodOption->GetNumberOfParameters() > 0 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - shapeSigma = parser->Convert( - likelihoodOption->GetParameter( 0 ) ); + shapeSigma = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 0 ) ); } unsigned int numberOfShapeBins = 64; - if( likelihoodOption->GetNumberOfParameters() > 1 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - numberOfShapeBins = parser->Convert( - likelihoodOption->GetParameter( 1 ) ); + numberOfShapeBins = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 1 ) ); } float orientationSigma = 1.0; - if( likelihoodOption->GetNumberOfParameters() > 2 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - orientationSigma = parser->Convert( - likelihoodOption->GetParameter( 2 ) ); + orientationSigma = parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 2 ) ); } unsigned int numberOfOrientationBins = 32; - if( likelihoodOption->GetNumberOfParameters() > 3 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { - numberOfOrientationBins = parser->Convert( - likelihoodOption->GetParameter(3) ); + numberOfOrientationBins = + parser->Convert( likelihoodOption->GetFunction( 0 )->GetParameter( 3 ) ); } for( unsigned int n = 0; n < segmenter->GetNumberOfTissueClasses(); n++ ) { @@ -881,13 +869,13 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer pvOption = parser->GetOption( "partial-volume-label-set" ); - if( pvOption && pvOption->GetNumberOfValues() > 0 ) + if( pvOption && pvOption->GetNumberOfFunctions() ) { unsigned int labelSetCount = 0; - for( int n = pvOption->GetNumberOfValues() - 1; n >= 0; n-- ) + for( int n = pvOption->GetNumberOfFunctions() - 1; n >= 0; n-- ) { typename SegmentationFilterType::PartialVolumeLabelSetType labelSet = - parser->ConvertVector( pvOption->GetValue( n ) ); + parser->ConvertVector( pvOption->GetFunction( n )->GetName() ); if( labelSet.size() != 2 ) { antscout << "Error: Currently Atropos only supports partial " @@ -911,9 +899,9 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) parser->GetOption( "use-partial-volume-likelihoods" ); bool useLikelihoods = false; - if( pvlOption && pvlOption->GetNumberOfValues() > 0 ) + if( pvlOption && pvlOption->GetNumberOfFunctions() ) { - std::string value = pvlOption->GetValue(); + std::string value = pvlOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( value ); if( !value.compare( "true" ) || !value.compare( "1" ) ) { @@ -932,9 +920,9 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer outlierOption = parser->GetOption( "winsorize-outliers" ); - if( outlierOption && outlierOption->GetNumberOfValues() > 0 ) + if( outlierOption && outlierOption->GetNumberOfFunctions() ) { - std::string outlierStrategy = outlierOption->GetValue(); + std::string outlierStrategy = outlierOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( outlierStrategy ); if( !outlierStrategy.compare( std::string( "boxplot" ) ) ) { @@ -944,20 +932,18 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) typename SampleFilterType::Pointer boxplotFilter = SampleFilterType::New(); - if( outlierOption->GetNumberOfParameters( 0 ) > 0 ) + if( outlierOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - boxplotFilter->SetLowerPercentile( parser->Convert( - outlierOption->GetParameter( 0 ) ) ); + boxplotFilter->SetLowerPercentile( parser->Convert( outlierOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } - if( outlierOption->GetNumberOfParameters( 0 ) > 1 ) + if( outlierOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - boxplotFilter->SetUpperPercentile( parser->Convert( - outlierOption->GetParameter( 1 ) ) ); + boxplotFilter->SetUpperPercentile( parser->Convert( outlierOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } - if( outlierOption->GetNumberOfParameters( 0 ) > 2 ) + if( outlierOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - boxplotFilter->SetWhiskerScalingFactor( parser->Convert( - outlierOption->GetParameter( 2 ) ) ); + boxplotFilter->SetWhiskerScalingFactor( parser->Convert( outlierOption->GetFunction( 0 )->GetParameter( + 2 ) ) ); } segmenter->SetOutlierHandlingFilter( boxplotFilter ); } @@ -966,18 +952,15 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) typedef typename SegmentationFilterType::SampleType SampleType; typedef itk::ants::Statistics::GrubbsRosnerListSampleFilter SampleFilterType; - typename SampleFilterType::Pointer grubbsFilter = - SampleFilterType::New(); + typename SampleFilterType::Pointer grubbsFilter = SampleFilterType::New(); - if( outlierOption->GetNumberOfParameters( 0 ) > 0 ) + if( outlierOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - grubbsFilter->SetSignificanceLevel( parser->Convert( - outlierOption->GetParameter( 0 ) ) ); + grubbsFilter->SetSignificanceLevel( parser->Convert( outlierOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } - if( outlierOption->GetNumberOfParameters( 0 ) > 1 ) + if( outlierOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - grubbsFilter->SetWinsorizingLevel( parser->Convert( - outlierOption->GetParameter( 1 ) ) ); + grubbsFilter->SetWinsorizingLevel( parser->Convert( outlierOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } segmenter->SetOutlierHandlingFilter( grubbsFilter ); } @@ -1009,14 +992,14 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) /** * output */ - if( icmOption && icmOption->GetNumberOfParameters() > 2 ) + if( icmOption && icmOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { if( segmenter->GetUseAsynchronousUpdating() && segmenter->GetICMCodeImage() ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( segmenter->GetICMCodeImage() ); - writer->SetFileName( ( icmOption->GetParameter( 2 ) ).c_str() ); + writer->SetFileName( ( icmOption->GetFunction( 0 )->GetParameter( 2 ) ).c_str() ); writer->Update(); } } @@ -1024,35 +1007,33 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) antscout << std::endl << "Writing output:" << std::endl; typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( outputOption && outputOption->GetNumberOfValues() > 0 ) + if( outputOption && outputOption->GetNumberOfFunctions() ) { - if( outputOption->GetNumberOfParameters() == 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() == 0 ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( segmenter->GetOutput() ); - writer->SetFileName( ( outputOption->GetValue() ).c_str() ); + writer->SetFileName( ( outputOption->GetFunction( 0 )->GetName() ).c_str() ); writer->Update(); } - if( outputOption->GetNumberOfParameters() > 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( segmenter->GetOutput() ); - writer->SetFileName( ( outputOption->GetParameter( 0 ) ).c_str() ); + writer->SetFileName( ( outputOption->GetFunction( 0 )->GetParameter( 0 ) ).c_str() ); writer->Update(); } - if( outputOption->GetNumberOfParameters() > 1 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - std::string filename = outputOption->GetParameter( 1 ); + std::string filename = outputOption->GetFunction( 0 )->GetParameter( 1 ); - itk::NumericSeriesFileNames::Pointer fileNamesCreator = - itk::NumericSeriesFileNames::New(); + itk::NumericSeriesFileNames::Pointer fileNamesCreator = itk::NumericSeriesFileNames::New(); fileNamesCreator->SetStartIndex( 1 ); fileNamesCreator->SetEndIndex( segmenter->GetNumberOfTissueClasses() ); fileNamesCreator->SetSeriesFormat( filename.c_str() ); - const std::vector & imageNames - = fileNamesCreator->GetFileNames(); + const std::vector & imageNames = fileNamesCreator->GetFileNames(); for( unsigned int i = 0; i < imageNames.size(); i++ ) { antscout << " Writing posterior image (class " << i + 1 << ")" @@ -1062,8 +1043,7 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) if( segmenter->GetMaskImage() ) { - typedef itk::MaskImageFilter MaskerType; + typedef itk::MaskImageFilter MaskerType; typename MaskerType::Pointer masker = MaskerType::New(); masker->SetInput1( probabilityImage ); masker->SetInput2( segmenter->GetMaskImage() ); @@ -1080,23 +1060,20 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) writer->Update(); } } - if( outputOption->GetNumberOfParameters() > 2 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - std::string filename = outputOption->GetParameter( 2 ); + std::string filename = outputOption->GetFunction( 0 )->GetParameter( 2 ); - itk::NumericSeriesFileNames::Pointer fileNamesCreator = - itk::NumericSeriesFileNames::New(); + itk::NumericSeriesFileNames::Pointer fileNamesCreator = itk::NumericSeriesFileNames::New(); fileNamesCreator->SetStartIndex( 1 ); fileNamesCreator->SetEndIndex( segmenter->GetNumberOfTissueClasses() ); fileNamesCreator->SetSeriesFormat( filename.c_str() ); - const std::vector & imageNames - = fileNamesCreator->GetFileNames(); + const std::vector & imageNames = fileNamesCreator->GetFileNames(); for( unsigned int i = 0; i < segmenter->GetNumberOfTissueClasses(); i++ ) { antscout << " Writing likelihood image (class " << i + 1 << ")" << std::endl; - typename InputImageType::Pointer likelihoodImage = segmenter-> - GetLikelihoodImage( i + 1 ); + typename InputImageType::Pointer likelihoodImage = segmenter->GetLikelihoodImage( i + 1 ); typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( likelihoodImage ); @@ -1104,27 +1081,23 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) writer->Update(); } } - if( outputOption->GetNumberOfParameters() > 3 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { - std::string filename = outputOption->GetParameter( 3 ); + std::string filename = outputOption->GetFunction( 0 )->GetParameter( 3 ); - itk::NumericSeriesFileNames::Pointer fileNamesCreator = - itk::NumericSeriesFileNames::New(); + itk::NumericSeriesFileNames::Pointer fileNamesCreator = itk::NumericSeriesFileNames::New(); fileNamesCreator->SetStartIndex( 1 ); fileNamesCreator->SetEndIndex( segmenter->GetNumberOfTissueClasses() ); fileNamesCreator->SetSeriesFormat( filename.c_str() ); - const std::vector & imageNames - = fileNamesCreator->GetFileNames(); + const std::vector & imageNames = fileNamesCreator->GetFileNames(); for( unsigned int i = 0; i < segmenter->GetNumberOfTissueClasses(); i++ ) { - if( segmenter->GetPriorProbabilityImage( i + 1 ) || - segmenter->GetPriorLabelImage() ) + if( segmenter->GetPriorProbabilityImage( i + 1 ) || segmenter->GetPriorLabelImage() ) { antscout << " Writing distance image (class " << i + 1 << ")" << std::endl; - typename InputImageType::Pointer distanceImage = segmenter-> - GetDistancePriorProbabilityImage( i + 1 ); + typename InputImageType::Pointer distanceImage = segmenter->GetDistancePriorProbabilityImage( i + 1 ); typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); @@ -1134,17 +1107,15 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) } } } - if( outputOption->GetNumberOfParameters() > 4 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 4 ) { - std::string filename = outputOption->GetParameter( 4 ); + std::string filename = outputOption->GetFunction( 0 )->GetParameter( 4 ); - itk::NumericSeriesFileNames::Pointer fileNamesCreator = - itk::NumericSeriesFileNames::New(); + itk::NumericSeriesFileNames::Pointer fileNamesCreator = itk::NumericSeriesFileNames::New(); fileNamesCreator->SetStartIndex( 1 ); fileNamesCreator->SetEndIndex( segmenter->GetNumberOfTissueClasses() ); fileNamesCreator->SetSeriesFormat( filename.c_str() ); - const std::vector & imageNames - = fileNamesCreator->GetFileNames(); + const std::vector & imageNames = fileNamesCreator->GetFileNames(); if( segmenter->GetAdaptiveSmoothingWeight( 0 ) > 0.0 ) { @@ -1153,11 +1124,10 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) if( segmenter->GetPriorProbabilityImage( i + 1 ) || segmenter->GetPriorLabelImage() ) { - antscout << " Writing B-spline image (class " << i + 1 << ")" - << std::endl; + antscout << " Writing B-spline image (class " << i + 1 << ")" << std::endl; - typename InputImageType::Pointer bsplineImage = segmenter-> - GetSmoothIntensityImageFromPriorImage( 0, i + 1 ); + typename InputImageType::Pointer bsplineImage = + segmenter->GetSmoothIntensityImageFromPriorImage( 0, i + 1 ); typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); @@ -1485,7 +1455,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) option->SetShortName( 'u' ); option->SetUsageOption( 0, "(0)/1" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -1521,7 +1491,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) option->SetShortName( 'e' ); option->SetUsageOption( 0, "(0)/1" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -1551,7 +1521,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -1561,7 +1531,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -1633,7 +1603,7 @@ int Atropos( std::vector args, std::ostream* out_stream = NULL ) parser->Parse( argc, argv ); if( argc < 2 || parser->Convert( - parser->GetOption( "help" )->GetValue() ) ) + parser->GetOption( "help" )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -1643,7 +1613,7 @@ int Atropos( std::vector args, std::ostream* out_stream = NULL ) return EXIT_SUCCESS; } else if( parser->GetOption( 'h' ) && - parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) + parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -1654,9 +1624,9 @@ int Atropos( std::vector args, std::ostream* out_stream = NULL ) itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "image-dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { @@ -1665,15 +1635,15 @@ int Atropos( std::vector args, std::ostream* out_stream = NULL ) itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "intensity-image" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() ) { - if( imageOption->GetNumberOfParameters( 0 ) > 0 ) + if( imageOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = imageOption->GetParameter( 0, 0 ); + filename = imageOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = imageOption->GetValue( 0 ); + filename = imageOption->GetFunction( 0 )->GetName(); } } else diff --git a/Examples/AtroposMin.cxx b/Examples/AtroposMin.cxx index 5be7b150f..3e7fa325f 100644 --- a/Examples/AtroposMin.cxx +++ b/Examples/AtroposMin.cxx @@ -36,13 +36,13 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer maskOption = parser->GetOption( "mask-image" ); - if( maskOption && maskOption->GetNumberOfValues() > 0 ) + if( maskOption && maskOption->GetNumberOfFunctions() > 0 ) { try { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( ( maskOption->GetValue() ).c_str() ); + reader->SetFileName( ( maskOption->GetFunction( 0 )->GetName() ).c_str() ); reader->Update(); segmenter->SetMaskImage( reader->GetOutput() ); @@ -63,28 +63,28 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "intensity-image" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() > 0 ) { unsigned int count = 0; - for( int n = imageOption->GetNumberOfValues() - 1; n >= 0; n-- ) + for( int n = imageOption->GetNumberOfFunctions() - 1; n >= 0; n-- ) { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - if( imageOption->GetNumberOfParameters( n ) > 0 ) + if( imageOption->GetFunction( n )->GetNumberOfParameters() > 0 ) { - reader->SetFileName( imageOption->GetParameter( n, 0 ) ); + reader->SetFileName( imageOption->GetFunction( n )->GetParameter( 0 ) ); } else { - reader->SetFileName( imageOption->GetValue( n ) ); + reader->SetFileName( imageOption->GetFunction( n )->GetName() ); } reader->Update(); segmenter->SetIntensityImage( count, reader->GetOutput() ); - if( imageOption->GetNumberOfParameters( count ) > 1 ) + if( imageOption->GetFunction( count )->GetNumberOfParameters() > 1 ) { segmenter->SetAdaptiveSmoothingWeight( count, parser->Convert( - imageOption->GetParameter( count, 1 ) ) ); + imageOption->GetFunction( count )->GetParameter( 1 ) ) ); } else { @@ -105,9 +105,9 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer likelihoodOption = parser->GetOption( "likelihood-model" ); - if( likelihoodOption && likelihoodOption->GetNumberOfValues() > 0 ) + if( likelihoodOption && likelihoodOption->GetNumberOfFunctions() > 0 ) { - std::string likelihoodModel = likelihoodOption->GetValue(); + std::string likelihoodModel = likelihoodOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( likelihoodModel ); if( !likelihoodModel.compare( std::string( "jointshapeandorientationprobability" ) ) ) { @@ -125,28 +125,28 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) LikelihoodType; float shapeSigma = 1.0; - if( likelihoodOption->GetNumberOfParameters() > 0 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { shapeSigma = parser->Convert( - likelihoodOption->GetParameter( 0 ) ); + likelihoodOption->GetFunction( 0 )->GetParameter( 0 ) ); } unsigned int numberOfShapeBins = 32; - if( likelihoodOption->GetNumberOfParameters() > 1 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { numberOfShapeBins = parser->Convert( - likelihoodOption->GetParameter( 1 ) ); + likelihoodOption->GetFunction( 0 )->GetParameter( 1 ) ); } float orientationSigma = 2.0; - if( likelihoodOption->GetNumberOfParameters() > 2 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { orientationSigma = parser->Convert( - likelihoodOption->GetParameter( 2 ) ); + likelihoodOption->GetFunction( 0 )->GetParameter( 2 ) ); } unsigned int numberOfOrientationBins = 64; - if( likelihoodOption->GetNumberOfParameters() > 3 ) + if( likelihoodOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { numberOfOrientationBins = parser->Convert( - likelihoodOption->GetParameter(3) ); + likelihoodOption->GetFunction( 0 )->GetParameter(3) ); } for( unsigned int n = 0; n < segmenter->GetNumberOfTissueClasses(); n++ ) { @@ -169,12 +169,12 @@ int AtroposSegmentation( itk::ants::CommandLineParser *parser ) // antscout << std::endl << "Writing output:" << std::endl; // typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = // parser->GetOption( "output" ); -// if( outputOption && outputOption->GetNumberOfValues() > 0 ) +// if( outputOption && outputOption->GetNumberOfFunctions() > 0 ) // { // typedef itk::ImageFileWriter WriterType; // typename WriterType::Pointer writer = WriterType::New(); // writer->SetInput( segmenter->GetOutput() ); -// writer->SetFileName( ( outputOption->GetValue() ).c_str() ); +// writer->SetFileName( ( outputOption->GetFunction( 0 )->GetName() ).c_str() ); // writer->Update(); // } @@ -283,7 +283,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -293,7 +293,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -365,7 +365,7 @@ int AtroposMin( std::vector args, std::ostream* out_stream = NULL ) parser->Parse( argc, argv ); if( argc < 2 || parser->Convert( - parser->GetOption( "help" )->GetValue() ) ) + parser->GetOption( "help" )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -375,7 +375,7 @@ int AtroposMin( std::vector args, std::ostream* out_stream = NULL ) return EXIT_SUCCESS; } else if( parser->GetOption( 'h' ) && - parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) + parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -386,9 +386,9 @@ int AtroposMin( std::vector args, std::ostream* out_stream = NULL ) itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "image-dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() > 0 ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { @@ -397,15 +397,15 @@ int AtroposMin( std::vector args, std::ostream* out_stream = NULL ) itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "intensity-image" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() > 0 ) { - if( imageOption->GetNumberOfParameters( 0 ) > 0 ) + if( imageOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = imageOption->GetParameter( 0, 0 ); + filename = imageOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = imageOption->GetValue( 0 ); + filename = imageOption->GetFunction( 0 )->GetName(); } } else diff --git a/Examples/CreateDTICohort.cxx b/Examples/CreateDTICohort.cxx index dad1adbb9..819860cb4 100644 --- a/Examples/CreateDTICohort.cxx +++ b/Examples/CreateDTICohort.cxx @@ -121,9 +121,9 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer inputAtlasOption = parser->GetOption( "dti-atlas" ); - if( inputAtlasOption && inputAtlasOption->GetNumberOfValues() ) + if( inputAtlasOption && inputAtlasOption->GetNumberOfFunctions() ) { - std::string inputFile = inputAtlasOption->GetValue(); + std::string inputFile = inputAtlasOption->GetFunction( 0 )->GetName(); reader->SetFileName( inputFile.c_str() ); inputAtlas = reader->GetOutput(); @@ -146,26 +146,24 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( outputOption && outputOption->GetNumberOfValues() ) + if( outputOption && outputOption->GetNumberOfFunctions() ) { - if( outputOption->GetNumberOfParameters() > 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - outputDirectory = outputOption->GetParameter( 0 ); + outputDirectory = outputOption->GetFunction( 0 )->GetParameter( 0 ); outputDirectory += std::string( "/" ); } - if( outputOption->GetNumberOfParameters() > 1 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - rootOutputFileName = outputOption->GetParameter( 1 ); + rootOutputFileName = outputOption->GetFunction( 0 )->GetParameter( 1 ); } - if( outputOption->GetNumberOfParameters() > 2 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - numberOfControls = parser->Convert( - outputOption->GetParameter( 2 ) ); + numberOfControls = parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 2 ) ); } - if( outputOption->GetNumberOfParameters() > 3 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { - numberOfExperimentals = parser->Convert( - outputOption->GetParameter( 3 ) ); + numberOfExperimentals = parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 3 ) ); } } else @@ -179,10 +177,10 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer maskImageOption = parser->GetOption( "label-mask-image" ); - RealType lowerThresholdValue = 0.2; - if( maskImageOption && maskImageOption->GetNumberOfValues() ) + RealType lowerThresholdFunction = 0.2; + if( maskImageOption && maskImageOption->GetNumberOfFunctions() ) { - std::string inputFile = maskImageOption->GetValue(); + std::string inputFile = maskImageOption->GetFunction( 0 )->GetName(); typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer maskreader = ReaderType::New(); maskreader->SetFileName( inputFile.c_str() ); @@ -194,13 +192,13 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) } catch( ... ) { - lowerThresholdValue = parser->Convert( maskImageOption->GetValue() ); + lowerThresholdFunction = parser->Convert( maskImageOption->GetFunction( 0 )->GetName() ); } } if( !maskImage->GetBufferPointer() ) { antscout << "Mask not read. Creating mask by thresholding " - << "the FA of the DTI atlas at >= " << lowerThresholdValue + << "the FA of the DTI atlas at >= " << lowerThresholdFunction << "." << std::endl << std::endl; typename ImageType::Pointer faImage = @@ -221,7 +219,7 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) thresholder->SetInput( faImage ); thresholder->SetInsideValue( 1 ); thresholder->SetOutsideValue( 0 ); - thresholder->SetLowerThreshold( lowerThresholdValue ); + thresholder->SetLowerThreshold( lowerThresholdFunction ); thresholder->SetUpperThreshold( 2.0 ); maskImage = thresholder->GetOutput(); @@ -270,37 +268,36 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer pathologyOption = parser->GetOption( "pathology" ); - if( pathologyOption && pathologyOption->GetNumberOfValues() > 0 ) + if( pathologyOption && pathologyOption->GetNumberOfFunctions() ) { - if( pathologyOption->GetNumberOfValues() == 1 && - ( pathologyOption->GetValue( 0 ) ).empty() ) + if( pathologyOption->GetNumberOfFunctions() == 1 && + ( pathologyOption->GetFunction( 0 )->GetName() ).empty() ) { float pathologyDeltaEig1 = 0.0; float pathologyDeltaEig2_Eig3 = 0.0; float percentageVoxels = 0.0; - if( pathologyOption->GetNumberOfParameters( 0 ) > 0 ) + if( pathologyOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { pathologyDeltaEig1 = parser->Convert( - pathologyOption->GetParameter( 0, 0 ) ); + pathologyOption->GetFunction( 0 )->GetParameter( 0 ) ); } - if( pathologyOption->GetNumberOfParameters( 0 ) > 1 ) + if( pathologyOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { pathologyDeltaEig2_Eig3 = parser->Convert( - pathologyOption->GetParameter( 0, 1 ) ); + pathologyOption->GetFunction( 0 )->GetParameter( 1 ) ); } - if( pathologyOption->GetNumberOfParameters( 0 ) > 2 ) + if( pathologyOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { percentageVoxels = parser->Convert( - pathologyOption->GetParameter( 0, 2 ) ); + pathologyOption->GetFunction( 0 )->GetParameter( 2 ) ); } for( unsigned int n = 0; n < labels.size(); n++ ) { RealType percentage = percentageVoxels; if( percentage > 1.0 ) { - percentage /= static_cast( labelGeometry->GetVolume( - labels[n] ) ); + percentage /= static_cast( labelGeometry->GetVolume( labels[n] ) ); } pathologyParameters(n, 0) = pathologyDeltaEig1; @@ -310,13 +307,11 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) } else { - for( unsigned int n = 0; n < pathologyOption->GetNumberOfValues(); n++ ) + for( unsigned int n = 0; n < pathologyOption->GetNumberOfFunctions(); n++ ) { - LabelType whichClass = parser->Convert( - pathologyOption->GetValue( n ) ); + LabelType whichClass = parser->Convert( pathologyOption->GetFunction( n )->GetName() ); - std::vector::const_iterator it = - std::find( labels.begin(), labels.end(), whichClass ); + std::vector::const_iterator it = std::find( labels.begin(), labels.end(), whichClass ); if( it == labels.end() ) { @@ -327,20 +322,17 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) float pathologyDeltaEig2_Eig3 = 0.1; float percentageVoxels = 1.0; - if( pathologyOption->GetNumberOfParameters( n ) > 0 ) + if( pathologyOption->GetFunction( n )->GetNumberOfParameters() > 0 ) { - pathologyDeltaEig1 = parser->Convert( - pathologyOption->GetParameter( n, 0 ) ); + pathologyDeltaEig1 = parser->Convert( pathologyOption->GetFunction( n )->GetParameter( 0 ) ); } - if( pathologyOption->GetNumberOfParameters( n ) > 1 ) + if( pathologyOption->GetFunction( n )->GetNumberOfParameters() > 1 ) { - pathologyDeltaEig2_Eig3 = parser->Convert( - pathologyOption->GetParameter( n, 1 ) ); + pathologyDeltaEig2_Eig3 = parser->Convert( pathologyOption->GetFunction( n )->GetParameter( 1 ) ); } - if( pathologyOption->GetNumberOfParameters( n ) > 2 ) + if( pathologyOption->GetFunction( n )->GetNumberOfParameters() > 2 ) { - percentageVoxels = parser->Convert( - pathologyOption->GetParameter( n, 2 ) ); + percentageVoxels = parser->Convert( pathologyOption->GetFunction( n )->GetParameter( 2 ) ); } RealType percentage = percentageVoxels; @@ -361,16 +353,16 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) bool applyISV = false; typename MatrixType::InternalMatrixType ISV(1, 1); - typename itk::ants::CommandLineParser::OptionType::Pointer populationOption = - parser->GetOption( "registered-population" ); - if( populationOption && populationOption->GetNumberOfValues() > 0 ) + typename itk::ants::CommandLineParser::OptionType::Pointer populationOption = parser->GetOption( + "registered-population" ); + if( populationOption && populationOption->GetNumberOfFunctions() ) { antscout << "--- Modeling intersubject variability ---" << std::endl << std::endl; std::vector imageNames; - std::string filename = populationOption->GetValue(); + std::string filename = populationOption->GetFunction( 0 )->GetName(); std::string imageFile; @@ -482,23 +474,23 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer dwiOption = parser->GetOption( "dwi-parameters" ); - if( dwiOption && dwiOption->GetNumberOfValues() > 0 && - dwiOption->GetNumberOfParameters() > 1 ) + if( dwiOption && dwiOption->GetNumberOfFunctions() && + dwiOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader2 = ReaderType::New(); - reader2->SetFileName( dwiOption->GetParameter( 0 ) ); + reader2->SetFileName( dwiOption->GetFunction( 0 )->GetParameter( 0 ) ); reader2->Update(); b0Image = reader2->GetOutput(); b0Image->DisconnectPipeline(); - std::string directionsFileName = dwiOption->GetParameter( 1 ); + std::string directionsFileName = dwiOption->GetFunction( 0 )->GetParameter( 1 ); std::fstream str( directionsFileName.c_str() ); - if( dwiOption->GetNumberOfParameters() > 2 ) + if( dwiOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { bvalues.push_back( - parser->Convert( dwiOption->GetParameter( 2 ) ) ); + parser->Convert( dwiOption->GetFunction( 0 )->GetParameter( 2 ) ) ); str >> numberOfDirections; } @@ -513,7 +505,7 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) if( count % ImageDimension == 0 ) { directions.push_back( direction ); - if( dwiOption->GetNumberOfParameters() < 2 ) + if( dwiOption->GetFunction( 0 )->GetNumberOfParameters() < 2 ) { str >> x; bvalues.push_back( x ); @@ -545,9 +537,9 @@ int CreateDTICohort( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer noiseOption = parser->GetOption( "noise-sigma" ); - if( noiseOption && noiseOption->GetNumberOfValues() > 0 ) + if( noiseOption && noiseOption->GetNumberOfFunctions() ) { - noiseSigma = parser->Convert( noiseOption->GetValue() ); + noiseSigma = parser->Convert( noiseOption->GetFunction()->GetName() ); } // @@ -929,7 +921,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) option->SetLongName( "label-mask-image" ); option->SetShortName( 'x' ); option->SetUsageOption( 0, "maskImageFileName" ); - option->SetUsageOption( 1, "lowerThresholdValue" ); + option->SetUsageOption( 1, "lowerThresholdFunction" ); option->SetDescription( description ); parser->AddOption( option ); } @@ -1045,7 +1037,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -1055,7 +1047,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -1127,8 +1119,7 @@ int CreateDTICohort( std::vector args, std::ostream* out_stream = N parser->Parse( argc, argv ); - if( argc < 2 || parser->Convert( - parser->GetOption( "help" )->GetValue() ) ) + if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -1137,8 +1128,7 @@ int CreateDTICohort( std::vector args, std::ostream* out_stream = N } return EXIT_SUCCESS; } - else if( parser->Convert( - parser->GetOption( 'h' )->GetValue() ) ) + else if( parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -1149,9 +1139,9 @@ int CreateDTICohort( std::vector args, std::ostream* out_stream = N itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "image-dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction()->GetName() ); } else { @@ -1160,15 +1150,15 @@ int CreateDTICohort( std::vector args, std::ostream* out_stream = N itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "dti-atlas" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() ) { - if( imageOption->GetNumberOfParameters( 0 ) > 0 ) + if( imageOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = imageOption->GetParameter( 0, 0 ); + filename = imageOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = imageOption->GetValue( 0 ); + filename = imageOption->GetFunction( 0 )->GetName(); } } else diff --git a/Examples/KellyKapowski.cxx b/Examples/KellyKapowski.cxx index 1fa703ec4..d58ee6397 100644 --- a/Examples/KellyKapowski.cxx +++ b/Examples/KellyKapowski.cxx @@ -85,12 +85,11 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer debugOption = parser->GetOption( "print-debug-information" ); - if( debugOption && debugOption->GetNumberOfValues() > 0 ) + if( debugOption && debugOption->GetNumberOfFunctions() ) { - std::string value = debugOption->GetValue(); + std::string value = debugOption->GetFunction()->GetName(); ConvertToLowerCase( value ); - if( std::strcmp( value.c_str(), "true" ) || - parser->Convert( debugOption->GetValue() ) != 0 ) + if( std::strcmp( value.c_str(), "true" ) || parser->Convert( value ) != 0 ) { direct->DebugOn(); } @@ -101,43 +100,40 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer segmentationImageOption = parser->GetOption( "segmentation-image" ); - if( segmentationImageOption ) + if( segmentationImageOption && segmentationImageOption->GetNumberOfFunctions() ) { - if( segmentationImageOption->GetNumberOfValues() > 0 ) + if( segmentationImageOption->GetFunction( 0 )->GetNumberOfParameters() == 0 ) { - if( segmentationImageOption->GetNumberOfParameters() == 0 ) - { - typedef itk::ImageFileReader LabelReaderType; - typename LabelReaderType::Pointer labelReader = LabelReaderType::New(); + typedef itk::ImageFileReader LabelReaderType; + typename LabelReaderType::Pointer labelReader = LabelReaderType::New(); + + std::string inputFile = segmentationImageOption->GetFunction( 0 )->GetName(); + labelReader->SetFileName( inputFile.c_str() ); + + segmentationImage = labelReader->GetOutput(); + segmentationImage->Update(); + segmentationImage->DisconnectPipeline(); + } + else if( segmentationImageOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) + { + typedef itk::ImageFileReader LabelReaderType; + typename LabelReaderType::Pointer labelReader = LabelReaderType::New(); - std::string inputFile = segmentationImageOption->GetValue(); - labelReader->SetFileName( inputFile.c_str() ); + std::string inputFile = segmentationImageOption->GetFunction( 0 )->GetParameter( 0 ); + labelReader->SetFileName( inputFile.c_str() ); - segmentationImage = labelReader->GetOutput(); - segmentationImage->Update(); - segmentationImage->DisconnectPipeline(); + segmentationImage = labelReader->GetOutput(); + segmentationImage->Update(); + segmentationImage->DisconnectPipeline(); + if( segmentationImageOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) + { + direct->SetGrayMatterLabel( parser->Convert( + segmentationImageOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } - else if( segmentationImageOption->GetNumberOfParameters() > 0 ) + if( segmentationImageOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - typedef itk::ImageFileReader LabelReaderType; - typename LabelReaderType::Pointer labelReader = LabelReaderType::New(); - - std::string inputFile = segmentationImageOption->GetParameter( 0 ); - labelReader->SetFileName( inputFile.c_str() ); - - segmentationImage = labelReader->GetOutput(); - segmentationImage->Update(); - segmentationImage->DisconnectPipeline(); - if( segmentationImageOption->GetNumberOfParameters() > 1 ) - { - direct->SetGrayMatterLabel( parser->Convert( - segmentationImageOption->GetParameter( 1 ) ) ); - } - if( segmentationImageOption->GetNumberOfParameters() > 2 ) - { - direct->SetWhiteMatterLabel( parser->Convert( - segmentationImageOption->GetParameter( 2 ) ) ); - } + direct->SetWhiteMatterLabel( parser->Convert( + segmentationImageOption->GetFunction( 0 )->GetParameter( 2 ) ) ); } } } @@ -153,12 +149,12 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer grayMatterOption = parser->GetOption( "gray-matter-probability-image" ); - if( grayMatterOption && grayMatterOption->GetNumberOfValues() > 0 ) + if( grayMatterOption && grayMatterOption->GetNumberOfFunctions() ) { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer gmReader = ReaderType::New(); - std::string gmFile = grayMatterOption->GetValue(); + std::string gmFile = grayMatterOption->GetFunction()->GetName(); gmReader->SetFileName( gmFile.c_str() ); grayMatterProbabilityImage = gmReader->GetOutput(); @@ -197,12 +193,12 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer whiteMatterOption = parser->GetOption( "white-matter-probability-image" ); - if( whiteMatterOption && whiteMatterOption->GetNumberOfValues() > 0 ) + if( whiteMatterOption && whiteMatterOption->GetNumberOfFunctions() ) { typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer wmReader = ReaderType::New(); - std::string wmFile = whiteMatterOption->GetValue(); + std::string wmFile = whiteMatterOption->GetFunction( 0 )->GetName(); wmReader->SetFileName( wmFile.c_str() ); whiteMatterProbabilityImage = wmReader->GetOutput(); @@ -241,22 +237,22 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer convergenceOption = parser->GetOption( "convergence" ); - if( convergenceOption ) + if( convergenceOption && convergenceOption->GetNumberOfFunctions() ) { - if( convergenceOption->GetNumberOfParameters() > 0 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { direct->SetMaximumNumberOfIterations( parser->Convert( - convergenceOption->GetParameter( 0 ) ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } - if( convergenceOption->GetNumberOfParameters() > 1 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { direct->SetConvergenceThreshold( parser->Convert( - convergenceOption->GetParameter( 1 ) ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } - if( convergenceOption->GetNumberOfParameters() > 2 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { direct->SetConvergenceWindowSize( parser->Convert( - convergenceOption->GetParameter( 2 ) ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 2 ) ) ); } } @@ -265,10 +261,10 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer thicknessPriorOption = parser->GetOption( "thickness-prior-estimate" ); - if( thicknessPriorOption && thicknessPriorOption->GetNumberOfValues() > 0 ) + if( thicknessPriorOption && thicknessPriorOption->GetNumberOfFunctions() ) { direct->SetThicknessPriorEstimate( parser->Convert( - thicknessPriorOption->GetValue() ) ); + thicknessPriorOption->GetFunction( 0 )->GetName() ) ); } // @@ -276,10 +272,10 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer gradientStepOption = parser->GetOption( "gradient-step" ); - if( gradientStepOption && gradientStepOption->GetNumberOfValues() > 0 ) + if( gradientStepOption && gradientStepOption->GetNumberOfFunctions() ) { direct->SetInitialGradientStep( parser->Convert( - gradientStepOption->GetValue() ) ); + gradientStepOption->GetFunction( 0 )->GetName() ) ); } // @@ -287,22 +283,10 @@ int DiReCT( itk::ants::CommandLineParser *parser ) // typename itk::ants::CommandLineParser::OptionType::Pointer smoothingSigmaOption = parser->GetOption( "smoothing-sigma" ); - if( smoothingSigmaOption && smoothingSigmaOption->GetNumberOfValues() > 0 ) + if( smoothingSigmaOption && smoothingSigmaOption->GetNumberOfFunctions() ) { direct->SetSmoothingSigma( parser->Convert( - smoothingSigmaOption->GetValue() ) ); - } - - // - // set maximum number of threads - // - typename itk::ants::CommandLineParser::OptionType::Pointer - threadOption = parser->GetOption( "maximum-number-of-threads" ); - if( threadOption && threadOption->GetNumberOfValues() > 0 ) - { - unsigned int numThreads = parser->Convert( - threadOption->GetValue() ); - direct->SetNumberOfThreads( numThreads ); + smoothingSigmaOption->GetFunction( 0 )->GetName() ) ); } typedef CommandIterationUpdate CommandType; @@ -332,12 +316,12 @@ int DiReCT( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( outputOption ) + if( outputOption && outputOption->GetNumberOfFunctions() ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( direct->GetOutput() ); - writer->SetFileName( ( outputOption->GetValue() ).c_str() ); + writer->SetFileName( ( outputOption->GetFunction( 0 )->GetName() ).c_str() ); writer->Update(); } @@ -476,7 +460,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -486,7 +470,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -554,8 +538,7 @@ int KellyKapowski( std::vector args, std::ostream* out_stream = NUL InitializeCommandLineOptions( parser ); parser->Parse( argc, argv ); - if( argc < 2 || parser->Convert( - parser->GetOption( "help" )->GetValue() ) ) + if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetFunction( 0 )->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -564,8 +547,7 @@ int KellyKapowski( std::vector args, std::ostream* out_stream = NUL } return EXIT_SUCCESS; } - else if( parser->Convert( - parser->GetOption( 'h' )->GetValue() ) ) + else if( parser->Convert( parser->GetOption( 'h' )->GetFunction( 0 )->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -576,9 +558,9 @@ int KellyKapowski( std::vector args, std::ostream* out_stream = NUL itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "image-dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() > 0 ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { @@ -587,15 +569,15 @@ int KellyKapowski( std::vector args, std::ostream* out_stream = NUL itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "input-image" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() > 0 ) { - if( imageOption->GetNumberOfParameters( 0 ) > 0 ) + if( imageOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = imageOption->GetParameter( 0, 0 ); + filename = imageOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = imageOption->GetValue( 0 ); + filename = imageOption->GetFunction( 0 )->GetName(); } } else diff --git a/Examples/N4BiasFieldCorrection.cxx b/Examples/N4BiasFieldCorrection.cxx index 9a7b96b8a..ef25ba1f9 100644 --- a/Examples/N4BiasFieldCorrection.cxx +++ b/Examples/N4BiasFieldCorrection.cxx @@ -88,9 +88,9 @@ int N4( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer inputImageOption = parser->GetOption( "input-image" ); - if( inputImageOption ) + if( inputImageOption && inputImageOption->GetNumberOfFunctions() ) { - std::string inputFile = inputImageOption->GetValue(); + std::string inputFile = inputImageOption->GetFunction( 0 )->GetName(); reader->SetFileName( inputFile.c_str() ); inputImage = reader->GetOutput(); @@ -109,9 +109,9 @@ int N4( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer maskImageOption = parser->GetOption( "mask-image" ); - if( maskImageOption && maskImageOption->GetNumberOfValues() ) + if( maskImageOption && maskImageOption->GetNumberOfFunctions() ) { - std::string inputFile = maskImageOption->GetValue(); + std::string inputFile = maskImageOption->GetFunction( 0 )->GetName(); typedef itk::ImageFileReader MaskReaderType; typename MaskReaderType::Pointer maskreader = MaskReaderType::New(); maskreader->SetFileName( inputFile.c_str() ); @@ -145,9 +145,9 @@ int N4( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer weightImageOption = parser->GetOption( "weight-image" ); - if( weightImageOption && weightImageOption->GetNumberOfValues() ) + if( weightImageOption && weightImageOption->GetNumberOfFunctions() ) { - std::string inputFile = weightImageOption->GetValue(); + std::string inputFile = weightImageOption->GetFunction( 0 )->GetName(); typedef itk::ImageFileReader WeightReaderType; typename WeightReaderType::Pointer weightreader = WeightReaderType::New(); weightreader->SetFileName( inputFile.c_str() ); @@ -161,12 +161,12 @@ int N4( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer convergenceOption = parser->GetOption( "convergence" ); - if( convergenceOption && convergenceOption->GetNumberOfValues() ) + if( convergenceOption && convergenceOption->GetNumberOfFunctions() ) { - if( convergenceOption->GetNumberOfParameters() > 0 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { std::vector numIters = parser->ConvertVector( - convergenceOption->GetParameter( 0 ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 0 ) ); typename CorrecterType::VariableSizeArrayType maximumNumberOfIterations( numIters.size() ); for( unsigned int d = 0; d < numIters.size(); d++ ) @@ -179,10 +179,10 @@ int N4( itk::ants::CommandLineParser *parser ) numberOfFittingLevels.Fill( numIters.size() ); correcter->SetNumberOfFittingLevels( numberOfFittingLevels ); } - if( convergenceOption->GetNumberOfParameters() > 1 ) + if( convergenceOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { correcter->SetConvergenceThreshold( parser->Convert( - convergenceOption->GetParameter( 1 ) ) ); + convergenceOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } } else // set default values @@ -209,17 +209,17 @@ int N4( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer bsplineOption = parser->GetOption( "bspline-fitting" ); - if( bsplineOption ) + if( bsplineOption && bsplineOption->GetNumberOfFunctions() ) { - if( bsplineOption->GetNumberOfParameters() > 1 ) + if( bsplineOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { correcter->SetSplineOrder( parser->Convert( - bsplineOption->GetParameter( 1 ) ) ); + bsplineOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } - if( bsplineOption->GetNumberOfParameters() > 0 ) + if( bsplineOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { std::vector array = parser->ConvertVector( - bsplineOption->GetParameter( 0 ) ); + bsplineOption->GetFunction( 0 )->GetParameter( 0 ) ); typename CorrecterType::ArrayType numberOfControlPoints; if( array.size() == 1 ) { @@ -312,9 +312,9 @@ int N4( itk::ants::CommandLineParser *parser ) typename itk::ants::CommandLineParser::OptionType::Pointer shrinkFactorOption = parser->GetOption( "shrink-factor" ); int shrinkFactor = 4; - if( shrinkFactorOption && shrinkFactorOption->GetNumberOfValues() ) + if( shrinkFactorOption && shrinkFactorOption->GetNumberOfFunctions() ) { - shrinkFactor = parser->Convert( shrinkFactorOption->GetValue() ); + shrinkFactor = parser->Convert( shrinkFactorOption->GetFunction( 0 )->GetName() ); } shrinker->SetShrinkFactors( shrinkFactor ); maskshrinker->SetShrinkFactors( shrinkFactor ); @@ -332,7 +332,7 @@ int N4( itk::ants::CommandLineParser *parser ) if( weightImage ) { weightshrinker->SetInput( weightImage ); - weightshrinker->SetShrinkFactors(shrinkFactor); + weightshrinker->SetShrinkFactors( shrinkFactor ); weightshrinker->Update(); correcter->SetConfidenceImage( weightshrinker->GetOutput() ); @@ -347,22 +347,22 @@ int N4( itk::ants::CommandLineParser *parser ) */ typename itk::ants::CommandLineParser::OptionType::Pointer histOption = parser->GetOption( "histogram-sharpening" ); - if( histOption ) + if( histOption && histOption->GetNumberOfFunctions() ) { - if( histOption->GetNumberOfParameters() > 0 ) + if( histOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { correcter->SetBiasFieldFullWidthAtHalfMaximum( parser->Convert( - histOption->GetParameter( 0 ) ) ); + histOption->GetFunction( 0 )->GetParameter( 0 ) ) ); } - if( histOption->GetNumberOfParameters() > 1 ) + if( histOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { correcter->SetWienerFilterNoise( parser->Convert( - histOption->GetParameter( 1 ) ) ); + histOption->GetFunction( 0 )->GetParameter( 1 ) ) ); } - if( histOption->GetNumberOfParameters() > 2 ) + if( histOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { correcter->SetNumberOfHistogramBins( parser->Convert( - histOption->GetParameter( 2 ) ) ); + histOption->GetFunction( 0 )->GetParameter( 2 ) ) ); } } @@ -431,7 +431,7 @@ int N4( itk::ants::CommandLineParser *parser ) divider->Update(); if( weightImage && - ( maskImageOption && maskImageOption->GetNumberOfValues() > 0 ) ) + ( maskImageOption && maskImageOption->GetNumberOfFunctions() > 0 ) ) { itk::ImageRegionIteratorWithIndex ItD( divider->GetOutput(), divider->GetOutput()->GetLargestPossibleRegion() ); @@ -461,27 +461,27 @@ int N4( itk::ants::CommandLineParser *parser ) biasFieldCropper->SetDirectionCollapseToSubmatrix(); biasFieldCropper->Update(); - if( outputOption->GetNumberOfParameters() == 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() == 0 ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( cropper->GetOutput() ); - writer->SetFileName( ( outputOption->GetValue() ).c_str() ); + writer->SetFileName( ( outputOption->GetFunction( 0 )->GetName() ).c_str() ); writer->Update(); } - if( outputOption->GetNumberOfParameters() > 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); writer->SetInput( cropper->GetOutput() ); - writer->SetFileName( ( outputOption->GetParameter( 0 ) ).c_str() ); + writer->SetFileName( ( outputOption->GetFunction( 0 )->GetParameter( 0 ) ).c_str() ); writer->Update(); } - if( outputOption->GetNumberOfParameters() > 1 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { typedef itk::ImageFileWriter WriterType; typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName( ( outputOption->GetParameter( 1 ) ).c_str() ); + writer->SetFileName( ( outputOption->GetFunction( 0 )->GetParameter( 1 ) ).c_str() ); writer->SetInput( biasFieldCropper->GetOutput() ); writer->Update(); } @@ -651,7 +651,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -661,7 +661,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -737,7 +737,7 @@ int N4BiasFieldCorrection( std::vector args, std::ostream* out_stre parser->Parse( argc, argv ); - if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetValue() ) ) + if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetFunction( 0 )->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -746,7 +746,7 @@ int N4BiasFieldCorrection( std::vector args, std::ostream* out_stre } return EXIT_SUCCESS; } - else if( parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) + else if( parser->Convert( parser->GetOption( 'h' )->GetFunction( 0 )->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -757,9 +757,9 @@ int N4BiasFieldCorrection( std::vector args, std::ostream* out_stre itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "image-dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() > 0 ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { @@ -768,15 +768,15 @@ int N4BiasFieldCorrection( std::vector args, std::ostream* out_stre itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "input-image" ); - if( imageOption && imageOption->GetNumberOfValues() > 0 ) + if( imageOption && imageOption->GetNumberOfFunctions() > 0 ) { - if( imageOption->GetNumberOfParameters( 0 ) > 0 ) + if( imageOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = imageOption->GetParameter( 0, 0 ); + filename = imageOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = imageOption->GetValue( 0 ); + filename = imageOption->GetFunction( 0 )->GetName(); } } else diff --git a/Examples/antsAlignOrigin.cxx b/Examples/antsAlignOrigin.cxx index 93039d38d..b42375abe 100644 --- a/Examples/antsAlignOrigin.cxx +++ b/Examples/antsAlignOrigin.cxx @@ -50,20 +50,20 @@ int antsAlignOriginImplementation( itk::ants::CommandLineParser::Pointer & parse typename itk::ants::CommandLineParser::OptionType::Pointer inputOption = parser->GetOption( "input" ); typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( inputOption && inputOption->GetNumberOfValues() > 0 ) + if( inputOption && inputOption->GetNumberOfFunctions() > 0 ) { - if( inputOption->GetNumberOfParameters( 0 ) > 1 && - parser->Convert( outputOption->GetParameter( 0, 1 ) ) == 0 ) + if( inputOption->GetFunction()->GetNumberOfParameters() > 1 && + parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 1 ) ) == 0 ) { antscout << "An input image is required." << std::endl; return EXIT_FAILURE; } - antscout << "Input image: " << inputOption->GetValue() << std::endl; + antscout << "Input image: " << inputOption->GetFunction()->GetName() << std::endl; typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( ( inputOption->GetValue() ).c_str() ); + reader->SetFileName( ( inputOption->GetFunction()->GetName() ).c_str() ); reader->Update(); inputImage = reader->GetOutput(); } @@ -71,17 +71,17 @@ int antsAlignOriginImplementation( itk::ants::CommandLineParser::Pointer & parse std::string outputTransform; std::string outputWarpedImageName; - if( outputOption && outputOption->GetNumberOfValues() > 0 ) + if( outputOption && outputOption->GetNumberOfFunctions() > 0 ) { - outputTransform = outputOption->GetValue( 0 ); - if( outputOption->GetNumberOfParameters( 0 ) > 0 ) + outputTransform = outputOption->GetFunction( 0 )->GetName(); + if( outputOption->GetFunction()->GetNumberOfParameters() > 0 ) { - outputTransform = outputOption->GetParameter( 0, 0 ); + outputTransform = outputOption->GetFunction( 0 )->GetParameter( 0 ); } - if( outputOption->GetNumberOfParameters( 0 ) > 1 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - outputWarpedImageName = outputOption->GetParameter( 0, 1 ); + outputWarpedImageName = outputOption->GetFunction( 0 )->GetParameter( 1 ); } antscout << "Output transform: " << outputTransform << std::endl; @@ -98,15 +98,15 @@ int antsAlignOriginImplementation( itk::ants::CommandLineParser::Pointer & parse typename itk::ants::CommandLineParser::OptionType::Pointer referenceOption = parser->GetOption( "reference-image" ); - if( referenceOption && referenceOption->GetNumberOfValues() > 0 ) + if( referenceOption && referenceOption->GetNumberOfFunctions() > 0 ) { - antscout << "Reference image: " << referenceOption->GetValue() << std::endl; + antscout << "Reference image: " << referenceOption->GetFunction()->GetName() << std::endl; // read in the image as char since we only need the header information. typedef itk::ImageFileReader ReferenceReaderType; typename ReferenceReaderType::Pointer referenceReader = ReferenceReaderType::New(); - referenceReader->SetFileName( ( referenceOption->GetValue() ).c_str() ); + referenceReader->SetFileName( ( referenceOption->GetFunction()->GetName() ).c_str() ); referenceImage = referenceReader->GetOutput(); referenceImage->Update(); @@ -202,7 +202,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -212,7 +212,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -280,7 +280,7 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N parser->Parse( argc, argv ); if( argc < 2 || ( parser->GetOption( "help" ) && - ( parser->Convert( parser->GetOption( "help" )->GetValue() ) ) ) ) + ( parser->Convert( parser->GetOption( "help" )->GetFunction()->GetName() ) ) ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -290,7 +290,7 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N return EXIT_SUCCESS; } else if( parser->GetOption( 'h' ) && - ( parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) ) + ( parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -301,15 +301,15 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N itk::ants::CommandLineParser::OptionType::Pointer inputOption = parser->GetOption( "reference-image" ); - if( inputOption && inputOption->GetNumberOfValues() > 0 ) + if( inputOption && inputOption->GetNumberOfFunctions() > 0 ) { - if( inputOption->GetNumberOfParameters( 0 ) > 0 ) + if( inputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = inputOption->GetParameter( 0, 0 ); + filename = inputOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = inputOption->GetValue( 0 ); + filename = inputOption->GetFunction( 0 )->GetName(); } } else @@ -329,9 +329,9 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() > 0 ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction()->GetName() ); } switch( dimension ) @@ -340,7 +340,7 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N { if( inputImageTypeOption ) { - std::string inputImageType = inputImageTypeOption->GetValue(); + std::string inputImageType = inputImageTypeOption->GetFunction()->GetName(); if( !std::strcmp( inputImageType.c_str(), "scalar" ) || !std::strcmp( inputImageType.c_str(), "0" ) ) { @@ -370,7 +370,7 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N { if( inputImageTypeOption ) { - std::string inputImageType = inputImageTypeOption->GetValue(); + std::string inputImageType = inputImageTypeOption->GetFunction()->GetName(); if( !std::strcmp( inputImageType.c_str(), "scalar" ) || !std::strcmp( inputImageType.c_str(), "0" ) ) { @@ -400,7 +400,7 @@ int antsAlignOrigin( std::vector args, std::ostream* out_stream = N { if( inputImageTypeOption ) { - std::string inputImageType = inputImageTypeOption->GetValue(); + std::string inputImageType = inputImageTypeOption->GetFunction()->GetName(); if( !std::strcmp( inputImageType.c_str(), "scalar" ) || !std::strcmp( inputImageType.c_str(), "0" ) ) { diff --git a/Examples/antsApplyTransforms.cxx b/Examples/antsApplyTransforms.cxx index 00290a09b..b867440be 100644 --- a/Examples/antsApplyTransforms.cxx +++ b/Examples/antsApplyTransforms.cxx @@ -137,30 +137,30 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne typename itk::ants::CommandLineParser::OptionType::Pointer inputOption = parser->GetOption( "input" ); typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( inputImageType == 2 && inputOption && inputOption->GetNumberOfValues() > 0 ) + if( inputImageType == 2 && inputOption && inputOption->GetNumberOfFunctions() ) { - antscout << "Input tensor image: " << inputOption->GetValue() << std::endl; + antscout << "Input tensor image: " << inputOption->GetFunction( 0 )->GetName() << std::endl; - ReadTensorImage( tensorImage, ( inputOption->GetValue() ).c_str(), true ); + ReadTensorImage( tensorImage, ( inputOption->GetFunction( 0 )->GetName() ).c_str(), true ); } - else if( inputImageType == 0 && inputOption && inputOption->GetNumberOfValues() > 0 ) + else if( inputImageType == 0 && inputOption && inputOption->GetNumberOfFunctions() ) { - antscout << "Input scalar image: " << inputOption->GetValue() << std::endl; + antscout << "Input scalar image: " << inputOption->GetFunction( 0 )->GetName() << std::endl; typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( ( inputOption->GetValue() ).c_str() ); + reader->SetFileName( ( inputOption->GetFunction( 0 )->GetName() ).c_str() ); reader->Update(); inputImages.push_back( reader->GetOutput() ); } - else if( inputImageType == 1 && inputOption && inputOption->GetNumberOfValues() > 0 ) + else if( inputImageType == 1 && inputOption && inputOption->GetNumberOfFunctions() ) { - antscout << "Input vector image: " << inputOption->GetValue() << std::endl; + antscout << "Input vector image: " << inputOption->GetFunction( 0 )->GetName() << std::endl; typedef itk::ImageFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( ( inputOption->GetValue() ).c_str() ); + reader->SetFileName( ( inputOption->GetFunction( 0 )->GetName() ).c_str() ); try { @@ -174,10 +174,10 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne return EXIT_FAILURE; } } - else if( outputOption && outputOption->GetNumberOfValues() > 0 ) + else if( outputOption && outputOption->GetNumberOfFunctions() ) { - if( outputOption->GetNumberOfParameters( 0 ) > 1 && - parser->Convert( outputOption->GetParameter( 0, 1 ) ) == 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 && + parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 1 ) ) == 0 ) { antscout << "An input image is required." << std::endl; return EXIT_FAILURE; @@ -194,15 +194,15 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne typename itk::ants::CommandLineParser::OptionType::Pointer referenceOption = parser->GetOption( "reference-image" ); - if( referenceOption && referenceOption->GetNumberOfValues() > 0 ) + if( referenceOption && referenceOption->GetNumberOfFunctions() ) { - antscout << "Reference image: " << referenceOption->GetValue() << std::endl; + antscout << "Reference image: " << referenceOption->GetFunction( 0 )->GetName() << std::endl; // read in the image as char since we only need the header information. typedef itk::ImageFileReader ReferenceReaderType; typename ReferenceReaderType::Pointer referenceReader = ReferenceReaderType::New(); - referenceReader->SetFileName( ( referenceOption->GetValue() ).c_str() ); + referenceReader->SetFileName( ( referenceOption->GetFunction( 0 )->GetName() ).c_str() ); referenceImage = referenceReader->GetOutput(); referenceImage->Update(); @@ -266,9 +266,9 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne std::string whichInterpolator( "linear" ); typename itk::ants::CommandLineParser::OptionType::Pointer interpolationOption = parser->GetOption( "interpolation" ); - if( interpolationOption && interpolationOption->GetNumberOfValues() > 0 ) + if( interpolationOption && interpolationOption->GetNumberOfFunctions() ) { - whichInterpolator = interpolationOption->GetValue(); + whichInterpolator = interpolationOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( whichInterpolator ); } @@ -288,9 +288,9 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne PixelType defaultValue = 0; typename itk::ants::CommandLineParser::OptionType::Pointer defaultOption = parser->GetOption( "default-value" ); - if( defaultOption && defaultOption->GetNumberOfValues() > 0 ) + if( defaultOption && defaultOption->GetNumberOfFunctions() ) { - defaultValue = parser->Convert( defaultOption->GetValue() ); + defaultValue = parser->Convert( defaultOption->GetFunction( 0 )->GetName() ); } antscout << "Default pixel value: " << defaultValue << std::endl; for( unsigned int n = 0; n < inputImages.size(); n++ ) @@ -315,12 +315,13 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne /** * output */ - if( outputOption && outputOption->GetNumberOfValues() > 0 ) + if( outputOption && outputOption->GetNumberOfFunctions() ) { - if( outputOption->GetNumberOfParameters( 0 ) > 1 && - parser->Convert( outputOption->GetParameter( 0, 1 ) ) != 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 && + parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 1 ) ) != 0 ) { - antscout << "Output composite transform displacement field: " << outputOption->GetParameter( 0, 0 ) << std::endl; + antscout << "Output composite transform displacement field: " + << outputOption->GetFunction( 0 )->GetParameter( 0 ) << std::endl; typedef typename itk::TransformToDisplacementFieldSource ConverterType; typename ConverterType::Pointer converter = ConverterType::New(); @@ -330,20 +331,20 @@ int antsApplyTransforms( itk::ants::CommandLineParser::Pointer & parser, unsigne typedef itk::ImageFileWriter DisplacementFieldWriterType; typename DisplacementFieldWriterType::Pointer displacementFieldWriter = DisplacementFieldWriterType::New(); displacementFieldWriter->SetInput( converter->GetOutput() ); - displacementFieldWriter->SetFileName( ( outputOption->GetParameter( 0, 0 ) ).c_str() ); + displacementFieldWriter->SetFileName( ( outputOption->GetFunction( 0 )->GetParameter( 0 ) ).c_str() ); displacementFieldWriter->Update(); } else { std::string outputFileName = ""; - if( outputOption->GetNumberOfParameters( 0 ) > 1 && - parser->Convert( outputOption->GetParameter( 0, 1 ) ) == 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 && + parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 1 ) ) == 0 ) { - outputFileName = outputOption->GetParameter( 0, 0 ); + outputFileName = outputOption->GetFunction( 0 )->GetParameter( 0 ); } else { - outputFileName = outputOption->GetValue(); + outputFileName = outputOption->GetFunction( 0 )->GetName(); } antscout << "Output warped image: " << outputFileName << std::endl; @@ -468,7 +469,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) option->SetShortName( 'e' ); option->SetUsageOption( 0, "0/1/2 " ); option->SetUsageOption( 1, "scalar/vector/tensor " ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); option->SetDescription( description ); parser->AddOption( option ); } @@ -585,7 +586,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -595,7 +596,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -663,7 +664,7 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream parser->Parse( argc, argv ); if( argc < 2 || ( parser->GetOption( "help" ) && - ( parser->Convert( parser->GetOption( "help" )->GetValue() ) ) ) ) + ( parser->Convert( parser->GetOption( "help" )->GetFunction()->GetName() ) ) ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -673,7 +674,7 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream return EXIT_SUCCESS; } else if( parser->GetOption( 'h' ) && - ( parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) ) + ( parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -684,15 +685,15 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream itk::ants::CommandLineParser::OptionType::Pointer inputOption = parser->GetOption( "reference-image" ); - if( inputOption && inputOption->GetNumberOfValues() > 0 ) + if( inputOption && inputOption->GetNumberOfFunctions() ) { - if( inputOption->GetNumberOfParameters( 0 ) > 0 ) + if( inputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = inputOption->GetParameter( 0, 0 ); + filename = inputOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = inputOption->GetValue( 0 ); + filename = inputOption->GetFunction( 0 )->GetName(); } } else @@ -712,9 +713,9 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } switch( dimension ) @@ -723,7 +724,7 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream { if( inputImageTypeOption ) { - std::string inputImageType = inputImageTypeOption->GetValue(); + std::string inputImageType = inputImageTypeOption->GetFunction( 0 )->GetName(); if( !std::strcmp( inputImageType.c_str(), "scalar" ) || !std::strcmp( inputImageType.c_str(), "0" ) ) { @@ -753,7 +754,7 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream { if( inputImageTypeOption ) { - std::string inputImageType = inputImageTypeOption->GetValue(); + std::string inputImageType = inputImageTypeOption->GetFunction( 0 )->GetName(); if( !std::strcmp( inputImageType.c_str(), "scalar" ) || !std::strcmp( inputImageType.c_str(), "0" ) ) { @@ -783,7 +784,7 @@ int antsApplyTransforms( std::vector args, std::ostream* out_stream { if( inputImageTypeOption ) { - std::string inputImageType = inputImageTypeOption->GetValue(); + std::string inputImageType = inputImageTypeOption->GetFunction( 0 )->GetName(); if( !std::strcmp( inputImageType.c_str(), "scalar" ) || !std::strcmp( inputImageType.c_str(), "0" ) ) { diff --git a/Examples/antsApplyTransformsToPoints.cxx b/Examples/antsApplyTransformsToPoints.cxx index 60b0c667f..4f4fb4efa 100644 --- a/Examples/antsApplyTransformsToPoints.cxx +++ b/Examples/antsApplyTransformsToPoints.cxx @@ -40,15 +40,16 @@ int antsApplyTransformsToPoints( itk::ants::CommandLineParser::Pointer & parser */ typename itk::ants::CommandLineParser::OptionType::Pointer inputOption = parser->GetOption( "input" ); typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( inputOption && inputOption->GetNumberOfValues() > 0 ) + if( inputOption && inputOption->GetNumberOfFunctions() > 0 ) { - antscout << "Input csv file: " << inputOption->GetValue() << std::endl; - std::string ext = itksys::SystemTools::GetFilenameExtension( ( inputOption->GetValue() ).c_str() ); + antscout << "Input csv file: " << inputOption->GetFunction( 0 )->GetName() << std::endl; + std::string ext = + itksys::SystemTools::GetFilenameExtension( ( inputOption->GetFunction( 0 )->GetName() ).c_str() ); if( strcmp(ext.c_str(), ".csv") == 0 ) { typedef itk::CSVArray2DFileReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( ( inputOption->GetValue() ).c_str() ); + reader->SetFileName( ( inputOption->GetFunction( 0 )->GetName() ).c_str() ); reader->SetFieldDelimiterCharacter( ',' ); reader->SetStringDelimiterCharacter( '"' ); reader->HasColumnHeadersOn(); @@ -81,10 +82,10 @@ int antsApplyTransformsToPoints( itk::ants::CommandLineParser::Pointer & parser return EXIT_FAILURE; } - if( outputOption && outputOption->GetNumberOfValues() > 0 ) + if( outputOption && outputOption->GetNumberOfFunctions() > 0 ) { - if( outputOption->GetNumberOfParameters( 0 ) > 1 && - parser->Convert( outputOption->GetParameter( 0, 1 ) ) == 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 && + parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 1 ) ) == 0 ) { antscout << "An input csv file is required." << std::endl; return EXIT_FAILURE; @@ -142,17 +143,17 @@ int antsApplyTransformsToPoints( itk::ants::CommandLineParser::Pointer & parser /** * output */ - if( outputOption && outputOption->GetNumberOfValues() > 0 ) + if( outputOption && outputOption->GetNumberOfFunctions() > 0 ) { std::string outputFileName = ""; - if( outputOption->GetNumberOfParameters( 0 ) > 1 && - parser->Convert( outputOption->GetParameter( 0, 1 ) ) == 0 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 && + parser->Convert( outputOption->GetFunction( 0 )->GetParameter( 1 ) ) == 0 ) { - outputFileName = outputOption->GetParameter( 0, 0 ); + outputFileName = outputOption->GetFunction( 0 )->GetParameter( 0 ); } else { - outputFileName = outputOption->GetValue(); + outputFileName = outputOption->GetFunction( 0 )->GetName(); } antscout << "Output warped points to csv file: " << outputFileName << std::endl; std::vector ColumnHeaders; @@ -269,7 +270,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -279,7 +280,7 @@ static void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -347,7 +348,7 @@ int antsApplyTransformsToPoints( std::vector args, std::ostream* ou parser->Parse( argc, argv ); if( argc < 2 || ( parser->GetOption( "help" ) && - ( parser->Convert( parser->GetOption( "help" )->GetValue() ) ) ) ) + ( parser->Convert( parser->GetOption( "help" )->GetFunction()->GetName() ) ) ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -357,7 +358,7 @@ int antsApplyTransformsToPoints( std::vector args, std::ostream* ou return EXIT_SUCCESS; } else if( parser->GetOption( 'h' ) && - ( parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) ) + ( parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -368,15 +369,15 @@ int antsApplyTransformsToPoints( std::vector args, std::ostream* ou itk::ants::CommandLineParser::OptionType::Pointer inputOption = parser->GetOption( "input" ); - if( inputOption && inputOption->GetNumberOfValues() > 0 ) + if( inputOption && inputOption->GetNumberOfFunctions() > 0 ) { - if( inputOption->GetNumberOfParameters( 0 ) > 0 ) + if( inputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - filename = inputOption->GetParameter( 0, 0 ); + filename = inputOption->GetFunction( 0 )->GetParameter( 0 ); } else { - filename = inputOption->GetValue( 0 ); + filename = inputOption->GetFunction( 0 )->GetName(); } } else @@ -388,9 +389,9 @@ int antsApplyTransformsToPoints( std::vector args, std::ostream* ou unsigned int dimension = 3; itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() > 0 ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { diff --git a/Examples/antsMotionCorr.cxx b/Examples/antsMotionCorr.cxx index 5c6549aae..35ab88b6d 100644 --- a/Examples/antsMotionCorr.cxx +++ b/Examples/antsMotionCorr.cxx @@ -159,8 +159,8 @@ inline std::string ants_moco_to_string(const T& t) template typename ImageType::Pointer PreprocessImage( ImageType * inputImage, - typename ImageType::PixelType lowerScaleValue, - typename ImageType::PixelType upperScaleValue, + typename ImageType::PixelType lowerScaleFunction, + typename ImageType::PixelType upperScaleFunction, float winsorizeLowerQuantile, float winsorizeUpperQuantile, ImageType *histogramMatchSourceImage = NULL ) { @@ -182,17 +182,17 @@ typename ImageType::Pointer PreprocessImage( ImageType * inputImage, histogramFilter->SetMarginalScale( 10.0 ); histogramFilter->Update(); - float lowerValue = histogramFilter->GetOutput()->Quantile( 0, winsorizeLowerQuantile ); - float upperValue = histogramFilter->GetOutput()->Quantile( 0, winsorizeUpperQuantile ); + float lowerFunction = histogramFilter->GetOutput()->Quantile( 0, winsorizeLowerQuantile ); + float upperFunction = histogramFilter->GetOutput()->Quantile( 0, winsorizeUpperQuantile ); typedef itk::IntensityWindowingImageFilter IntensityWindowingImageFilterType; typename IntensityWindowingImageFilterType::Pointer windowingFilter = IntensityWindowingImageFilterType::New(); windowingFilter->SetInput( inputImage ); - windowingFilter->SetWindowMinimum( lowerValue ); - windowingFilter->SetWindowMaximum( upperValue ); - windowingFilter->SetOutputMinimum( lowerScaleValue ); - windowingFilter->SetOutputMaximum( upperScaleValue ); + windowingFilter->SetWindowMinimum( lowerFunction ); + windowingFilter->SetWindowMaximum( upperFunction ); + windowingFilter->SetOutputMinimum( lowerScaleFunction ); + windowingFilter->SetOutputMaximum( upperScaleFunction ); windowingFilter->Update(); typename ImageType::Pointer outputImage = NULL; @@ -433,7 +433,7 @@ int ants_motion( itk::ants::CommandLineParser *parser ) typedef typename ParserType::OptionType OptionType; typename OptionType::Pointer averageOption = parser->GetOption( "average-image" ); - if( averageOption && averageOption->GetNumberOfValues() > 0 ) + if( averageOption && averageOption->GetNumberOfFunctions() ) { typename OptionType::Pointer outputOption = parser->GetOption( "output" ); if( !outputOption ) @@ -441,12 +441,12 @@ int ants_motion( itk::ants::CommandLineParser *parser ) antscout << "Output option not specified. Should be the output average image name." << std::endl; return EXIT_FAILURE; } - std::string outputPrefix = outputOption->GetParameter( 0, 0 ); + std::string outputPrefix = outputOption->GetFunction( 0 )->GetParameter( 0 ); if( outputPrefix.length() < 3 ) { - outputPrefix = outputOption->GetValue( 0 ); + outputPrefix = outputOption->GetFunction( 0 )->GetName(); } - std::string fn = averageOption->GetValue( 0 ); + std::string fn = averageOption->GetFunction( 0 )->GetName(); typename MovingImageType::Pointer movingImage; if( fn[0] == '0' && fn[1] == 'x' ) { @@ -502,9 +502,9 @@ int ants_motion( itk::ants::CommandLineParser *parser ) } typename OptionType::Pointer transformOption = parser->GetOption( "transform" ); - if( transformOption && transformOption->GetNumberOfValues() > 0 ) + if( transformOption && transformOption->GetNumberOfFunctions() ) { - numberOfStages = transformOption->GetNumberOfValues(); + numberOfStages = transformOption->GetNumberOfFunctions(); } else { @@ -515,28 +515,28 @@ int ants_motion( itk::ants::CommandLineParser *parser ) antscout << "Registration using " << numberOfStages << " total stages." << std::endl; typename OptionType::Pointer metricOption = parser->GetOption( "metric" ); - if( !metricOption || metricOption->GetNumberOfValues() != numberOfStages ) + if( !metricOption || metricOption->GetNumberOfFunctions() != numberOfStages ) { antscout << "The number of metrics specified does not match the number of stages." << std::endl; return EXIT_FAILURE; } typename OptionType::Pointer iterationsOption = parser->GetOption( "iterations" ); - if( !iterationsOption || iterationsOption->GetNumberOfValues() != numberOfStages ) + if( !iterationsOption || iterationsOption->GetNumberOfFunctions() != numberOfStages ) { antscout << "The number of iteration sets specified does not match the number of stages." << std::endl; return EXIT_FAILURE; } typename OptionType::Pointer shrinkFactorsOption = parser->GetOption( "shrinkFactors" ); - if( !shrinkFactorsOption || shrinkFactorsOption->GetNumberOfValues() != numberOfStages ) + if( !shrinkFactorsOption || shrinkFactorsOption->GetNumberOfFunctions() != numberOfStages ) { antscout << "The number of shrinkFactor sets specified does not match the number of stages." << std::endl; return EXIT_FAILURE; } typename OptionType::Pointer smoothingSigmasOption = parser->GetOption( "smoothingSigmas" ); - if( !smoothingSigmasOption || smoothingSigmasOption->GetNumberOfValues() != numberOfStages ) + if( !smoothingSigmasOption || smoothingSigmasOption->GetNumberOfFunctions() != numberOfStages ) { antscout << "The number of smoothing sigma sets specified does not match the number of stages." << std::endl; return EXIT_FAILURE; @@ -548,27 +548,27 @@ int ants_motion( itk::ants::CommandLineParser *parser ) antscout << "Output option not specified." << std::endl; return EXIT_FAILURE; } - std::string outputPrefix = outputOption->GetParameter( 0, 0 ); + std::string outputPrefix = outputOption->GetFunction( 0 )->GetParameter( 0 ); if( outputPrefix.length() < 3 ) { - outputPrefix = outputOption->GetValue( 0 ); + outputPrefix = outputOption->GetFunction( 0 )->GetName(); } unsigned int nimagestoavg = 0; itk::ants::CommandLineParser::OptionType::Pointer navgOption = parser->GetOption( "n-images" ); - if( navgOption && navgOption->GetNumberOfValues() > 0 ) + if( navgOption && navgOption->GetNumberOfFunctions() ) { - nimagestoavg = parser->Convert( navgOption->GetValue() ); + nimagestoavg = parser->Convert( navgOption->GetFunction( 0 )->GetName() ); antscout << " nimagestoavg " << nimagestoavg << std::endl; } bool doEstimateLearningRateOnce(false); OptionType::Pointer rateOption = parser->GetOption( "use-estimate-learning-rate-once" ); - if( rateOption && rateOption->GetNumberOfValues() > 0 ) + if( rateOption && rateOption->GetNumberOfFunctions() ) { - std::string rateValue = rateOption->GetValue( 0 ); - ConvertToLowerCase( rateValue ); - if( rateValue.compare( "1" ) == 0 || rateValue.compare( "true" ) == 0 ) + std::string rateFunction = rateOption->GetFunction( 0 )->GetName(); + ConvertToLowerCase( rateFunction ); + if( rateFunction.compare( "1" ) == 0 || rateFunction.compare( "true" ) == 0 ) { doEstimateLearningRateOnce = true; } @@ -589,8 +589,8 @@ int ants_motion( itk::ants::CommandLineParser *parser ) // Get the fixed and moving images - std::string fixedImageFileName = metricOption->GetParameter( currentStage, 0 ); - std::string movingImageFileName = metricOption->GetParameter( currentStage, 1 ); + std::string fixedImageFileName = metricOption->GetFunction( currentStage )->GetParameter( 0 ); + std::string movingImageFileName = metricOption->GetFunction( currentStage )->GetParameter( 1 ); antscout << " fixed image: " << fixedImageFileName << std::endl; antscout << " moving image: " << movingImageFileName << std::endl; typename FixedImageType::Pointer fixed_time_slice = NULL; @@ -658,14 +658,14 @@ int ants_motion( itk::ants::CommandLineParser *parser ) // Get the number of iterations and use that information to specify the number of levels std::vector iterations = - parser->ConvertVector( iterationsOption->GetValue( currentStage ) ); + parser->ConvertVector( iterationsOption->GetFunction( currentStage )->GetName() ); unsigned int numberOfLevels = iterations.size(); antscout << " number of levels = " << numberOfLevels << std::endl; // Get shrink factors std::vector factors = - parser->ConvertVector( shrinkFactorsOption->GetValue( currentStage ) ); + parser->ConvertVector( shrinkFactorsOption->GetFunction( currentStage )->GetName() ); typename AffineRegistrationType::ShrinkFactorsArrayType shrinkFactorsPerLevel; shrinkFactorsPerLevel.SetSize( factors.size() ); @@ -685,7 +685,8 @@ int ants_motion( itk::ants::CommandLineParser *parser ) // Get smoothing sigmas - std::vector sigmas = parser->ConvertVector( smoothingSigmasOption->GetValue( currentStage ) ); + std::vector sigmas = parser->ConvertVector( smoothingSigmasOption->GetFunction( + currentStage )->GetName() ); typename AffineRegistrationType::SmoothingSigmasArrayType smoothingSigmasPerLevel; smoothingSigmasPerLevel.SetSize( sigmas.size() ); @@ -736,11 +737,11 @@ int ants_motion( itk::ants::CommandLineParser *parser ) extractRegion.SetSize(ImageDimension, 0); bool maptoneighbor = true; typename OptionType::Pointer fixedOption = parser->GetOption( "useFixedReferenceImage" ); - if( fixedOption && fixedOption->GetNumberOfValues() > 0 ) + if( fixedOption && fixedOption->GetNumberOfFunctions() ) { - std::string fixedValue = fixedOption->GetValue( 0 ); - ConvertToLowerCase( fixedValue ); - if( fixedValue.compare( "1" ) == 0 || fixedValue.compare( "true" ) == 0 ) + std::string fixedFunction = fixedOption->GetFunction( 0 )->GetName(); + ConvertToLowerCase( fixedFunction ); + if( fixedFunction.compare( "1" ) == 0 || fixedFunction.compare( "true" ) == 0 ) { if( timedim == 0 ) { @@ -819,19 +820,19 @@ int ants_motion( itk::ants::CommandLineParser *parser ) typedef itk::ImageToImageMetricv4 MetricType; typename MetricType::Pointer metric; - std::string whichMetric = metricOption->GetValue( currentStage ); + std::string whichMetric = metricOption->GetFunction( currentStage )->GetName(); ConvertToLowerCase( whichMetric ); float samplingPercentage = 1.0; - if( metricOption->GetNumberOfParameters() > 5 ) + if( metricOption->GetFunction( 0 )->GetNumberOfParameters() > 5 ) { - samplingPercentage = parser->Convert( metricOption->GetParameter( currentStage, 5 ) ); + samplingPercentage = parser->Convert( metricOption->GetFunction( currentStage )->GetParameter( 5 ) ); } std::string samplingStrategy = ""; - if( metricOption->GetNumberOfParameters() > 4 ) + if( metricOption->GetFunction( 0 )->GetNumberOfParameters() > 4 ) { - samplingStrategy = metricOption->GetParameter( currentStage, 4 ); + samplingStrategy = metricOption->GetFunction( currentStage )->GetParameter( 4 ); } ConvertToLowerCase( samplingStrategy ); typename AffineRegistrationType::MetricSamplingStrategyType metricSamplingStrategy = AffineRegistrationType::NONE; @@ -848,7 +849,8 @@ int ants_motion( itk::ants::CommandLineParser *parser ) if( std::strcmp( whichMetric.c_str(), "cc" ) == 0 ) { - unsigned int radiusOption = parser->Convert( metricOption->GetParameter( currentStage, 3 ) ); + unsigned int radiusOption = parser->Convert( metricOption->GetFunction( + currentStage )->GetParameter( 3 ) ); antscout << " using the CC metric (radius = " << radiusOption << ")." << std::endl; typedef itk::ANTSNeighborhoodCorrelationImageToImageMetricv4Convert( metricOption->GetParameter( currentStage, 3 ) ); + unsigned int binOption = + parser->Convert( metricOption->GetFunction( currentStage )->GetParameter( 3 ) ); unsigned int npoints_to_skip = - static_cast( 1 / std::atof( ( metricOption->GetParameter( currentStage, 5 ) ).c_str() ) ); + static_cast( 1 + / std::atof( ( metricOption->GetFunction( currentStage )->GetParameter( 5 ) ). + c_str() ) ); typedef itk::MattesMutualInformationImageToImageMetricv4 MutualInformationMetricType; typename MutualInformationMetricType::Pointer mutualInformationMetric = MutualInformationMetricType::New(); @@ -927,7 +932,7 @@ int ants_motion( itk::ants::CommandLineParser *parser ) scalesEstimator->SetTransformForward( true ); // scalesEstimator->SetSamplingStrategy(ScalesEstimatorType::CornerSampling); - float learningRate = parser->Convert( transformOption->GetParameter( currentStage, 0 ) ); + float learningRate = parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( 0 ) ); typedef itk::ConjugateGradientLineSearchOptimizerv4 OptimizerType; OptimizerType::Pointer optimizer = OptimizerType::New(); @@ -939,18 +944,18 @@ int ants_motion( itk::ants::CommandLineParser *parser ) optimizer->SetEpsilon( 0.1 ); typename OptionType::Pointer scalesOption = parser->GetOption( "useScalesEstimator" ); - if( scalesOption && scalesOption->GetNumberOfValues() > 0 ) + if( scalesOption && scalesOption->GetNumberOfFunctions() ) { - std::string scalesValue = scalesOption->GetValue( 0 ); - ConvertToLowerCase( scalesValue ); - if( scalesValue.compare( "1" ) == 0 || scalesValue.compare( "true" ) == 0 ) + std::string scalesFunction = scalesOption->GetFunction( 0 )->GetName(); + ConvertToLowerCase( scalesFunction ); + if( scalesFunction.compare( "1" ) == 0 || scalesFunction.compare( "true" ) == 0 ) { antscout << " employing scales estimator " << std::endl; optimizer->SetScalesEstimator( scalesEstimator ); } else { - antscout << " not employing scales estimator " << scalesValue << std::endl; + antscout << " not employing scales estimator " << scalesFunction << std::endl; } } double small_step = 0; @@ -964,7 +969,7 @@ int ants_motion( itk::ants::CommandLineParser *parser ) // optimizer->SetMaximumNewtonStepSizeInPhysicalUnits(sqrt(small_step)*learningR); // Set up the image registration methods along with the transforms - std::string whichTransform = transformOption->GetValue( currentStage ); + std::string whichTransform = transformOption->GetFunction( currentStage )->GetName(); ConvertToLowerCase( whichTransform ); if( std::strcmp( whichTransform.c_str(), "affine" ) == 0 ) { @@ -1117,8 +1122,10 @@ int ants_motion( itk::ants::CommandLineParser *parser ) typename DisplacementFieldRegistrationType::TransformParametersAdaptorsContainerType adaptors; // Extract parameters - RealType sigmaForUpdateField = parser->Convert( transformOption->GetParameter( currentStage, 1 ) ); - RealType sigmaForTotalField = parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); + RealType sigmaForUpdateField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 1 ) ); + RealType sigmaForTotalField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 2 ) ); outputDisplacementFieldTransform->SetGaussianSmoothingVarianceForTheUpdateField( sigmaForUpdateField ); outputDisplacementFieldTransform->SetGaussianSmoothingVarianceForTheTotalField( sigmaForTotalField ); outputDisplacementFieldTransform->SetDisplacementField( displacementField ); @@ -1198,8 +1205,10 @@ int ants_motion( itk::ants::CommandLineParser *parser ) else if( std::strcmp( whichTransform.c_str(), "SyN" ) == 0 || std::strcmp( whichTransform.c_str(), "syn" ) == 0 ) { - RealType sigmaForUpdateField = parser->Convert( transformOption->GetParameter( currentStage, 1 ) ); - RealType sigmaForTotalField = parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); + RealType sigmaForUpdateField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 1 ) ); + RealType sigmaForTotalField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 2 ) ); typedef itk::Vector VectorType; VectorType zeroVector( 0.0 ); typedef itk::Image DisplacementFieldType; @@ -1360,12 +1369,12 @@ int ants_motion( itk::ants::CommandLineParser *parser ) outputImage->SetPixel(ind, fval); } } - if( outputOption && outputOption->GetNumberOfParameters( 0 ) > 1 && currentStage == 0 ) + if( outputOption && outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 && currentStage == 0 ) { - std::string fileName = outputOption->GetParameter( 0, 1 ); + std::string fileName = outputOption->GetFunction( 0 )->GetParameter( 1 ); if( outputPrefix.length() < 3 ) { - outputPrefix = outputOption->GetValue( 0 ); + outputPrefix = outputOption->GetFunction( 0 )->GetName(); } if( fileName[0] == '0' && fileName[1] == 'x' ) { @@ -1384,9 +1393,10 @@ int ants_motion( itk::ants::CommandLineParser *parser ) writer->Update(); } } - if( outputOption && outputOption->GetNumberOfParameters( 0 ) > 2 && outputImage && currentStage == 0 ) + if( outputOption && outputOption->GetFunction( 0 )->GetNumberOfParameters() > 2 && outputImage && currentStage == + 0 ) { - std::string fileName = outputOption->GetParameter( 0, 2 ); + std::string fileName = outputOption->GetFunction( 0 )->GetParameter( 2 ); typename FixedImageType::Pointer avgImage; typedef itk::ExtractImageFilter ExtractFilterType; typename MovingImageType::RegionType extractRegion = movingImage->GetLargestPossibleRegion(); @@ -1641,7 +1651,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -1651,7 +1661,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -1719,7 +1729,7 @@ int antsMotionCorr( std::vector args, std::ostream* out_stream = NU parser->Parse( argc, argv ); - if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetValue() ) ) + if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -1728,7 +1738,7 @@ int antsMotionCorr( std::vector args, std::ostream* out_stream = NU } return EXIT_SUCCESS; } - else if( parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) + else if( parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -1738,9 +1748,9 @@ int antsMotionCorr( std::vector args, std::ostream* out_stream = NU unsigned int dimension = 3; itk::ants::CommandLineParser::OptionType::Pointer dimOption = parser->GetOption( "dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { diff --git a/Examples/antsRegistration.cxx b/Examples/antsRegistration.cxx index f9db0e228..5aa924cd1 100644 --- a/Examples/antsRegistration.cxx +++ b/Examples/antsRegistration.cxx @@ -72,7 +72,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) option->SetShortName( 'a' ); option->SetUsageOption( 0, "1/(0)" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -130,7 +130,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) option->SetShortName( 'b' ); option->SetUsageOption( 0, "(1)/0" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -318,7 +318,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -328,7 +328,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } } @@ -436,7 +436,7 @@ DoRegistration(typename ParserType::Pointer & parser) OptionType::Pointer compositeOutputOption = parser->GetOption( "write-composite-transform" ); - if( !outputOption ) + if( !outputOption || outputOption->GetNumberOfFunctions() == 0 ) { antscout << "Output option not specified." << std::endl; return EXIT_FAILURE; @@ -444,7 +444,7 @@ DoRegistration(typename ParserType::Pointer & parser) OptionType::Pointer collapseLinearTransforms = parser->GetOption( "collapse-linear-transforms-to-fixed-image-header" ); - if( parser->Convert( collapseLinearTransforms->GetValue( 0 ) ) ) + if( parser->Convert( collapseLinearTransforms->GetFunction( 0 )->GetName() ) ) { regHelper->SetApplyLinearTransformsToFixedImageHeader( true ); } @@ -453,26 +453,26 @@ DoRegistration(typename ParserType::Pointer & parser) regHelper->SetApplyLinearTransformsToFixedImageHeader( false ); } - std::string outputPrefix = outputOption->GetValue( 0 ); - if( outputOption->GetNumberOfParameters( 0 ) > 0 ) + std::string outputPrefix = outputOption->GetFunction( 0 )->GetName(); + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - outputPrefix = outputOption->GetParameter( 0, 0 ); + outputPrefix = outputOption->GetFunction( 0 )->GetParameter( 0 ); } std::string outputWarpedImageName; - if( outputOption->GetNumberOfParameters( 0 ) > 1 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - outputWarpedImageName = outputOption->GetParameter( 0, 1 ); + outputWarpedImageName = outputOption->GetFunction( 0 )->GetParameter( 1 ); } std::string outputInverseWarpedImageName; - if( outputOption->GetNumberOfParameters( 0 ) > 2 ) + if( outputOption->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - outputInverseWarpedImageName = outputOption->GetParameter( 0, 2 ); + outputInverseWarpedImageName = outputOption->GetFunction( 0 )->GetParameter( 2 ); } ParserType::OptionType::Pointer initialMovingTransformOption = parser->GetOption( "initial-moving-transform" ); - if( initialMovingTransformOption && initialMovingTransformOption->GetNumberOfValues() > 0 ) + if( initialMovingTransformOption && initialMovingTransformOption->GetNumberOfFunctions() ) { std::vector isDerivedInitialMovingTransform; typename CompositeTransformType::Pointer compositeTransform = @@ -498,7 +498,7 @@ DoRegistration(typename ParserType::Pointer & parser) ParserType::OptionType::Pointer initialFixedTransformOption = parser->GetOption( "initial-fixed-transform" ); - if( initialFixedTransformOption && initialFixedTransformOption->GetNumberOfValues() > 0 ) + if( initialFixedTransformOption && initialFixedTransformOption->GetNumberOfFunctions() ) { std::vector isDerivedInitialFixedTransform; typename CompositeTransformType::Pointer compositeTransform = @@ -525,14 +525,14 @@ DoRegistration(typename ParserType::Pointer & parser) { typedef typename RegistrationHelperType::MaskImageType MaskImageType; typedef itk::ImageFileReader ImageReaderType; - for( unsigned m = 0; m < maskOption->GetNumberOfParameters(); m++ ) + for( unsigned m = 0; m < maskOption->GetFunction( 0 )->GetNumberOfParameters(); m++ ) { - std::string fname = maskOption->GetParameter(0, m); + std::string fname = maskOption->GetFunction( 0 )->GetParameter( m ); typename MaskImageType::Pointer maskImage; typename ImageReaderType::Pointer reader = ImageReaderType::New(); - reader->SetFileName(fname.c_str() ); + reader->SetFileName( fname.c_str() ); try { reader->Update(); @@ -558,7 +558,7 @@ DoRegistration(typename ParserType::Pointer & parser) unsigned int numberOfStages; - if( transformOption.IsNull() || ( numberOfStages = transformOption->GetNumberOfValues() ) == 0 ) + if( transformOption.IsNull() || ( numberOfStages = transformOption->GetNumberOfFunctions() ) == 0 ) { antscout << "No transformations are specified." << std::endl; return EXIT_FAILURE; @@ -575,8 +575,8 @@ DoRegistration(typename ParserType::Pointer & parser) { // Get the fixed and moving images - std::string fixedImageFileName = metricOption->GetParameter( currentStage, 0 ); - std::string movingImageFileName = metricOption->GetParameter( currentStage, 1 ); + std::string fixedImageFileName = metricOption->GetFunction( currentStage )->GetParameter( 0 ); + std::string movingImageFileName = metricOption->GetFunction( currentStage )->GetParameter( 1 ); antscout << " fixed image: " << fixedImageFileName << std::endl; antscout << " moving image: " << movingImageFileName << std::endl; @@ -615,11 +615,10 @@ DoRegistration(typename ParserType::Pointer & parser) } movingImage->DisconnectPipeline(); - std::string whichMetric = metricOption->GetValue( currentStage ); + std::string whichMetric = metricOption->GetFunction( currentStage )->GetName(); ConvertToLowerCase( whichMetric ); - typename RegistrationHelperType::MetricEnumeration curMetric = - regHelper->StringToMetricType(whichMetric); + typename RegistrationHelperType::MetricEnumeration curMetric = regHelper->StringToMetricType( whichMetric ); float lowerQuantile = 0.0; float upperQuantile = 1.0; @@ -627,27 +626,27 @@ DoRegistration(typename ParserType::Pointer & parser) OptionType::Pointer winsorizeOption = parser->GetOption( "winsorize-image-intensities" ); bool doWinsorize(false); - if( winsorizeOption && winsorizeOption->GetNumberOfParameters( 0 ) > 0 ) + if( winsorizeOption && winsorizeOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { doWinsorize = true; - if( winsorizeOption->GetNumberOfParameters( 0 ) > 0 ) + if( winsorizeOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - lowerQuantile = parser->Convert( winsorizeOption->GetParameter( 0, 0 ) ); + lowerQuantile = parser->Convert( winsorizeOption->GetFunction( 0 )->GetParameter( 0 ) ); } - if( winsorizeOption->GetNumberOfParameters( 0 ) > 1 ) + if( winsorizeOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - upperQuantile = parser->Convert( winsorizeOption->GetParameter( 0, 1 ) ); + upperQuantile = parser->Convert( winsorizeOption->GetFunction( 0 )->GetParameter( 1 ) ); } } regHelper->SetWinsorizeImageIntensities(doWinsorize, lowerQuantile, upperQuantile); bool doHistogramMatch(false); OptionType::Pointer histOption = parser->GetOption( "use-histogram-matching" ); - if( histOption && histOption->GetNumberOfValues() > 0 ) + if( histOption && histOption->GetNumberOfFunctions() ) { - std::string histValue = histOption->GetValue( 0 ); - ConvertToLowerCase( histValue ); - if( histValue.compare( "1" ) == 0 || histValue.compare( "true" ) == 0 ) + std::string histFunction = histOption->GetFunction( 0 )->GetName(); + ConvertToLowerCase( histFunction ); + if( histFunction.compare( "1" ) == 0 || histFunction.compare( "true" ) == 0 ) { doHistogramMatch = true; } @@ -656,11 +655,11 @@ DoRegistration(typename ParserType::Pointer & parser) bool doEstimateLearningRateAtEachIteration = true; OptionType::Pointer rateOption = parser->GetOption( "use-estimate-learning-rate-once" ); - if( rateOption && rateOption->GetNumberOfValues() > 0 ) + if( rateOption && rateOption->GetNumberOfFunctions() ) { - std::string rateValue = rateOption->GetValue( 0 ); - ConvertToLowerCase( rateValue ); - if( rateValue.compare( "1" ) == 0 || rateValue.compare( "true" ) == 0 ) + std::string rateFunction = rateOption->GetFunction( 0 )->GetName(); + ConvertToLowerCase( rateFunction ); + if( rateFunction.compare( "1" ) == 0 || rateFunction.compare( "true" ) == 0 ) { doEstimateLearningRateAtEachIteration = false; } @@ -672,21 +671,24 @@ DoRegistration(typename ParserType::Pointer & parser) std::vector iterations; double convergenceThreshold = 1e-6; unsigned int convergenceWindowSize = 10; - if( convergenceOption->GetNumberOfParameters( currentStage ) == 0 ) + if( convergenceOption->GetFunction( currentStage )->GetNumberOfParameters() == 0 ) { - iterations = parser->ConvertVector( convergenceOption->GetValue( currentStage ) ); + iterations = parser->ConvertVector( convergenceOption->GetFunction( currentStage )->GetName() ); } - else if( convergenceOption->GetNumberOfParameters( currentStage ) > 0 ) + else if( convergenceOption->GetFunction( currentStage )->GetNumberOfParameters() > 0 ) { - iterations = parser->ConvertVector( convergenceOption->GetParameter( currentStage, 0 ) ); + iterations = parser->ConvertVector( convergenceOption->GetFunction( currentStage )->GetParameter( + 0 ) ); } - if( convergenceOption->GetNumberOfParameters( currentStage ) > 1 ) + if( convergenceOption->GetFunction( currentStage )->GetNumberOfParameters() > 1 ) { - convergenceThreshold = parser->Convert( convergenceOption->GetParameter( currentStage, 1 ) ); + convergenceThreshold = + parser->Convert( convergenceOption->GetFunction( currentStage )->GetParameter( 1 ) ); } - if( convergenceOption->GetNumberOfParameters( currentStage ) > 2 ) + if( convergenceOption->GetFunction( currentStage )->GetNumberOfParameters() > 2 ) { - convergenceWindowSize = parser->Convert( convergenceOption->GetParameter( currentStage, 2 ) ); + convergenceWindowSize = parser->Convert( convergenceOption->GetFunction( + currentStage )->GetParameter( 2 ) ); const unsigned int minAllowedconvergenceWindowSize = 2; // The BSplineScatteredDataPoints requires at least 2 // points for interpolation. if( convergenceWindowSize < minAllowedconvergenceWindowSize ) @@ -696,9 +698,9 @@ DoRegistration(typename ParserType::Pointer & parser) } } - iterationList.push_back(iterations); - convergenceThresholdList.push_back(convergenceThreshold); - convergenceWindowSizeList.push_back(convergenceWindowSize); + iterationList.push_back( iterations ); + convergenceThresholdList.push_back( convergenceThreshold ); + convergenceWindowSizeList.push_back( convergenceWindowSize ); unsigned int numberOfLevels = iterations.size(); antscout << " number of levels = " << numberOfLevels << std::endl; @@ -706,11 +708,11 @@ DoRegistration(typename ParserType::Pointer & parser) // Get shrink factors std::vector factors = - parser->ConvertVector( shrinkFactorsOption->GetValue( currentStage ) ); - shrinkFactorsList.push_back(factors); + parser->ConvertVector( shrinkFactorsOption->GetFunction( currentStage )->GetName() ); + shrinkFactorsList.push_back( factors ); // Get smoothing sigmas - std::string smoothingSigmasString = smoothingSigmasOption->GetValue( currentStage ); + std::string smoothingSigmasString = smoothingSigmasOption->GetFunction( currentStage )->GetName(); size_t mmPosition = smoothingSigmasString.find( "mm" ); size_t voxPosition = smoothingSigmasString.find( "vox" ); if( mmPosition != std::string::npos ) @@ -736,15 +738,15 @@ DoRegistration(typename ParserType::Pointer & parser) smoothingSigmasList.push_back( sigmas ); float samplingPercentage = 1.0; - if( metricOption->GetNumberOfParameters( currentStage ) > 5 ) + if( metricOption->GetFunction( currentStage )->GetNumberOfParameters() > 5 ) { - samplingPercentage = parser->Convert( metricOption->GetParameter( currentStage, 5 ) ); + samplingPercentage = parser->Convert( metricOption->GetFunction( currentStage )->GetParameter( 5 ) ); } std::string Strategy = "none"; - if( metricOption->GetNumberOfParameters( currentStage ) > 4 ) + if( metricOption->GetFunction( currentStage )->GetNumberOfParameters() > 4 ) { - Strategy = metricOption->GetParameter( currentStage, 4 ); + Strategy = metricOption->GetFunction( currentStage )->GetParameter( 4 ); } ConvertToLowerCase( Strategy ); @@ -772,7 +774,8 @@ DoRegistration(typename ParserType::Pointer & parser) { case RegistrationHelperType::CC: { - unsigned int radiusOption = parser->Convert( metricOption->GetParameter( currentStage, 3 ) ); + unsigned int radiusOption = parser->Convert( metricOption->GetFunction( + currentStage )->GetParameter( 3 ) ); regHelper->AddMetric(curMetric, fixedImage, movingImage, @@ -811,7 +814,8 @@ DoRegistration(typename ParserType::Pointer & parser) case RegistrationHelperType::Mattes: case RegistrationHelperType::MI: { - unsigned int binOption = parser->Convert( metricOption->GetParameter( currentStage, 3 ) ); + unsigned int binOption = + parser->Convert( metricOption->GetFunction( currentStage )->GetParameter( 3 ) ); regHelper->AddMetric(curMetric, fixedImage, movingImage, @@ -830,12 +834,12 @@ DoRegistration(typename ParserType::Pointer & parser) // Set up the optimizer. To change the iteration number for each level we rely // on the command observer. - float learningRate = parser->Convert( transformOption->GetParameter( currentStage, 0 ) ); + float learningRate = parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( 0 ) ); - std::string whichTransform = transformOption->GetValue( currentStage ); + std::string whichTransform = transformOption->GetFunction( currentStage )->GetName(); ConvertToLowerCase( whichTransform ); - TransformTypeNames.push_back(whichTransform); + TransformTypeNames.push_back(whichTransform ); typename RegistrationHelperType::XfrmMethod xfrmMethod = regHelper->StringToXfrmMethod(whichTransform); @@ -868,21 +872,23 @@ DoRegistration(typename ParserType::Pointer & parser) break; case RegistrationHelperType::GaussianDisplacementField: { - const float varianceForUpdateField = parser->Convert( transformOption->GetParameter( currentStage, 1 ) ); - const float varianceForTotalField = parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); + const float varianceForUpdateField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 1 ) ); + const float varianceForTotalField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 2 ) ); regHelper->AddGaussianDisplacementFieldTransform(learningRate, varianceForUpdateField, varianceForTotalField); } break; case RegistrationHelperType::BSplineDisplacementField: { std::vector meshSizeForTheUpdateField = - parser->ConvertVector( transformOption->GetParameter( currentStage, 1 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 1 ) ); std::vector meshSizeForTheTotalField; - if( transformOption->GetNumberOfParameters( currentStage ) > 2 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 2 ) { meshSizeForTheTotalField = - parser->ConvertVector( transformOption->GetParameter( currentStage, 2 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 2 ) ); } else { @@ -893,9 +899,10 @@ DoRegistration(typename ParserType::Pointer & parser) } unsigned int splineOrder = 3; - if( transformOption->GetNumberOfParameters( currentStage ) > 3 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 3 ) { - splineOrder = parser->Convert( transformOption->GetParameter( currentStage, 3 ) ); + splineOrder = + parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( 3 ) ); } regHelper->AddBSplineDisplacementFieldTransform(learningRate, meshSizeForTheUpdateField, @@ -906,20 +913,23 @@ DoRegistration(typename ParserType::Pointer & parser) case RegistrationHelperType::BSpline: { std::vector MeshSizeAtBaseLevel = - parser->ConvertVector( transformOption->GetParameter( currentStage, 1 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 1 ) ); regHelper->AddBSplineTransform(learningRate, MeshSizeAtBaseLevel); } break; case RegistrationHelperType::TimeVaryingVelocityField: { - unsigned int numberOfTimeIndices = parser->Convert( transformOption->GetParameter( 0, 1 ) ); - - const float varianceForUpdateField = parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); - const float varianceForUpdateFieldTime = parser->Convert( transformOption->GetParameter( currentStage, - 3 ) ); - const float varianceForTotalField = parser->Convert( transformOption->GetParameter( currentStage, 4 ) ); - const float varianceForTotalFieldTime = - parser->Convert( transformOption->GetParameter( currentStage, 5 ) ); + unsigned int numberOfTimeIndices = parser->Convert( transformOption->GetFunction( + 0 )->GetParameter( 1 ) ); + + const float varianceForUpdateField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 2 ) ); + const float varianceForUpdateFieldTime = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 3 ) ); + const float varianceForTotalField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 4 ) ); + const float varianceForTotalFieldTime = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 5 ) ); regHelper->AddTimeVaryingVelocityFieldTransform(learningRate, numberOfTimeIndices, varianceForUpdateField, @@ -930,17 +940,19 @@ DoRegistration(typename ParserType::Pointer & parser) break; case RegistrationHelperType::TimeVaryingBSplineVelocityField: { - std::vector meshSize = - parser->ConvertVector( transformOption->GetParameter( 0, 1 ) ); + std::vector meshSize = parser->ConvertVector( transformOption->GetFunction( + 0 )->GetParameter( 1 ) ); unsigned int numberOfTimePointSamples = 4; - if( transformOption->GetNumberOfParameters( currentStage ) > 2 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 2 ) { - numberOfTimePointSamples = parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); + numberOfTimePointSamples = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 2 ) ); } unsigned int splineOrder = 3; - if( transformOption->GetNumberOfParameters( currentStage ) > 3 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 3 ) { - splineOrder = parser->Convert( transformOption->GetParameter( currentStage, 3 ) ); + splineOrder = + parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( 3 ) ); } regHelper->AddTimeVaryingBSplineVelocityFieldTransform(learningRate, meshSize, @@ -951,14 +963,16 @@ DoRegistration(typename ParserType::Pointer & parser) case RegistrationHelperType::SyN: { float varianceForUpdateField = 3.0; - if( transformOption->GetNumberOfParameters( currentStage ) > 1 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 1 ) { - varianceForUpdateField = parser->Convert( transformOption->GetParameter( currentStage, 1 ) ); + varianceForUpdateField = parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( + 1 ) ); } float varianceForTotalField = 0.0; - if( transformOption->GetNumberOfParameters( currentStage ) > 2 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 2 ) { - varianceForTotalField = parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); + varianceForTotalField = parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( + 2 ) ); } regHelper->AddSyNTransform( learningRate, varianceForUpdateField, varianceForTotalField ); } @@ -966,14 +980,15 @@ DoRegistration(typename ParserType::Pointer & parser) case RegistrationHelperType::BSplineSyN: { std::vector meshSizeForTheUpdateField = - parser->ConvertVector( transformOption->GetParameter( currentStage, 1 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 1 ) ); std::vector meshSizeForTheTotalField = - parser->ConvertVector( transformOption->GetParameter( currentStage, 2 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 2 ) ); unsigned int splineOrder = 3; - if( transformOption->GetNumberOfParameters( currentStage ) > 3 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 3 ) { - splineOrder = parser->Convert( transformOption->GetParameter( currentStage, 3 ) ); + splineOrder = + parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( 3 ) ); } regHelper->AddBSplineSyNTransform(learningRate, meshSizeForTheUpdateField, @@ -983,15 +998,16 @@ DoRegistration(typename ParserType::Pointer & parser) break; case RegistrationHelperType::Exponential: { - const float varianceForUpdateField = - parser->Convert( transformOption->GetParameter( currentStage, 1 ) ); - const float varianceForVelocityField = - parser->Convert( transformOption->GetParameter( currentStage, 2 ) ); + const float varianceForUpdateField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 1 ) ); + const float varianceForVelocityField = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 2 ) ); unsigned int numberOfIntegrationSteps = 0; // If the number of integration steps = 0, compute steps // automatically - if( transformOption->GetNumberOfParameters( currentStage ) > 3 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 3 ) { - numberOfIntegrationSteps = parser->Convert( transformOption->GetParameter( currentStage, 3 ) ); + numberOfIntegrationSteps = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 3 ) ); } regHelper->AddExponentialTransform( learningRate, varianceForUpdateField, varianceForVelocityField, numberOfIntegrationSteps ); @@ -1000,13 +1016,13 @@ DoRegistration(typename ParserType::Pointer & parser) case RegistrationHelperType::BSplineExponential: { std::vector meshSizeForTheUpdateField = - parser->ConvertVector( transformOption->GetParameter( currentStage, 1 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 1 ) ); std::vector meshSizeForTheVelocityField; - if( transformOption->GetNumberOfParameters( currentStage ) > 2 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 2 ) { meshSizeForTheVelocityField = - parser->ConvertVector( transformOption->GetParameter( currentStage, 2 ) ); + parser->ConvertVector( transformOption->GetFunction( currentStage )->GetParameter( 2 ) ); } else { @@ -1018,15 +1034,17 @@ DoRegistration(typename ParserType::Pointer & parser) unsigned int numberOfIntegrationSteps = 0; // If the number of integration steps = 0, compute steps // automatically - if( transformOption->GetNumberOfParameters( currentStage ) > 3 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 3 ) { - numberOfIntegrationSteps = parser->Convert( transformOption->GetParameter( currentStage, 3 ) ); + numberOfIntegrationSteps = parser->Convert( transformOption->GetFunction( + currentStage )->GetParameter( 3 ) ); } unsigned int splineOrder = 3; - if( transformOption->GetNumberOfParameters( currentStage ) > 4 ) + if( transformOption->GetFunction( currentStage )->GetNumberOfParameters() > 4 ) { - splineOrder = parser->Convert( transformOption->GetParameter( currentStage, 4 ) ); + splineOrder = + parser->Convert( transformOption->GetFunction( currentStage )->GetParameter( 4 ) ); } regHelper->AddBSplineExponentialTransform( learningRate, meshSizeForTheUpdateField, @@ -1056,7 +1074,7 @@ DoRegistration(typename ParserType::Pointer & parser) // // write out transforms stored in the composite typename CompositeTransformType::Pointer resultTransform = regHelper->GetCompositeTransform(); - if( parser->Convert( compositeOutputOption->GetValue() ) ) + if( parser->Convert( compositeOutputOption->GetFunction( 0 )->GetName() ) ) { std::string compositeTransformFileName = outputPrefix + std::string( "Composite.h5" ); std::string inverseCompositeTransformFileName = outputPrefix + std::string( "InverseComposite.h5" ); @@ -1075,7 +1093,7 @@ DoRegistration(typename ParserType::Pointer & parser) } unsigned int numTransforms = resultTransform->GetNumberOfTransforms(); // write out transforms actually computed, so skip any initial transforms. - for( unsigned int i = initialMovingTransformOption->GetNumberOfValues(); i < numTransforms; ++i ) + for( unsigned int i = initialMovingTransformOption->GetNumberOfFunctions(); i < numTransforms; ++i ) { typename RegistrationHelperType::CompositeTransformType::TransformTypePointer curTransform = resultTransform->GetNthTransform( i ); @@ -1164,9 +1182,9 @@ DoRegistration(typename ParserType::Pointer & parser) typedef double RealType; std::string whichInterpolator( "linear" ); typename itk::ants::CommandLineParser::OptionType::Pointer interpolationOption = parser->GetOption( "interpolation" ); - if( interpolationOption && interpolationOption->GetNumberOfValues() > 0 ) + if( interpolationOption && interpolationOption->GetNumberOfFunctions() ) { - whichInterpolator = interpolationOption->GetValue(); + whichInterpolator = interpolationOption->GetFunction( 0 )->GetName(); ConvertToLowerCase( whichInterpolator ); } @@ -1178,7 +1196,7 @@ DoRegistration(typename ParserType::Pointer & parser) #if 1 // HACK:: This can just be cached when reading the fixedImage from above!! // - std::string fixedImageFileName = metricOption->GetParameter( numberOfStages - 1, 0 ); + std::string fixedImageFileName = metricOption->GetFunction( numberOfStages - 1 )->GetParameter( 0 ); typedef itk::ImageFileReader ImageReaderType; typename ImageReaderType::Pointer fixedImageReader = ImageReaderType::New(); @@ -1299,7 +1317,7 @@ int antsRegistration( std::vector args, std::ostream* out_stream = parser->Parse( argc, argv ); - if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetValue() ) ) + if( argc < 2 || parser->Convert( parser->GetOption( "help" )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, false ); if( argc < 2 ) @@ -1308,7 +1326,7 @@ int antsRegistration( std::vector args, std::ostream* out_stream = } return EXIT_SUCCESS; } - else if( parser->Convert( parser->GetOption( 'h' )->GetValue() ) ) + else if( parser->Convert( parser->GetOption( 'h' )->GetFunction()->GetName() ) ) { parser->PrintMenu( antscout, 5, true ); return EXIT_SUCCESS; @@ -1316,9 +1334,9 @@ int antsRegistration( std::vector args, std::ostream* out_stream = unsigned int dimension = 3; ParserType::OptionType::Pointer dimOption = parser->GetOption( "dimensionality" ); - if( dimOption && dimOption->GetNumberOfValues() > 0 ) + if( dimOption && dimOption->GetNumberOfFunctions() ) { - dimension = parser->Convert( dimOption->GetValue() ); + dimension = parser->Convert( dimOption->GetFunction( 0 )->GetName() ); } else { diff --git a/Examples/itkantsRegistrationHelper.h b/Examples/itkantsRegistrationHelper.h index 062e2ff50..7108640a6 100644 --- a/Examples/itkantsRegistrationHelper.h +++ b/Examples/itkantsRegistrationHelper.h @@ -582,8 +582,8 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, std::deque transformNames; std::deque transformTypes; - derivedTransforms.resize( initialTransformOption->GetNumberOfValues() ); - for( unsigned int n = 0; n < initialTransformOption->GetNumberOfValues(); n++ ) + derivedTransforms.resize( initialTransformOption->GetNumberOfFunctions() ); + for( unsigned int n = 0; n < initialTransformOption->GetNumberOfFunctions(); n++ ) { std::string initialTransformName; bool useInverse = false; @@ -591,17 +591,17 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, derivedTransforms[n] = false; - if( initialTransformOption->GetNumberOfParameters( n ) == 0 ) + if( initialTransformOption->GetFunction( n )->GetNumberOfParameters() == 0 ) { - initialTransformName = initialTransformOption->GetValue( n ); + initialTransformName = initialTransformOption->GetFunction( n )->GetName(); } - else if( initialTransformOption->GetNumberOfParameters( n ) > 2 ) + else if( initialTransformOption->GetFunction( n )->GetNumberOfParameters() > 2 ) { typedef itk::ImageFileReader ImageReaderType; typename ImageType::Pointer fixedImage = NULL; - std::string fixedImageFileName = initialTransformOption->GetParameter( 0, 0 ); + std::string fixedImageFileName = initialTransformOption->GetFunction( n )->GetParameter( 0 ); typename ImageReaderType::Pointer fixedReader = ImageReaderType::New(); fixedReader->SetFileName( fixedImageFileName.c_str() ); @@ -620,7 +620,7 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, if( fixedImage ) { - std::string movingImageFileName = initialTransformOption->GetParameter( 0, 1 ); + std::string movingImageFileName = initialTransformOption->GetFunction( n )->GetParameter( 1 ); typename ImageReaderType::Pointer movingReader = ImageReaderType::New(); movingReader->SetFileName( movingImageFileName.c_str() ); @@ -637,9 +637,9 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, } bool useCenterOfMass = true; - if( initialTransformOption->GetNumberOfParameters( 0 ) > 2 ) + if( initialTransformOption->GetFunction( n )->GetNumberOfParameters() > 2 ) { - std::string parameter = initialTransformOption->GetParameter( 0, 2 ); + std::string parameter = initialTransformOption->GetFunction( n )->GetParameter( 2 ); ConvertToLowerCase( parameter ); if( parameter.compare( "0" ) == 0 || parameter.compare( "false" ) == 0 ) { @@ -669,8 +669,9 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, } initializer->InitializeTransform(); - initialTransformName += std::string( "fixed image: " ) + initialTransformOption->GetParameter( 0, 0 ) - + std::string( " and moving image: " ) + initialTransformOption->GetParameter( 0, 1 ); + initialTransformName += std::string( "fixed image: " ) + + initialTransformOption->GetFunction( n )->GetParameter( 0 ) + + std::string( " and moving image: " ) + initialTransformOption->GetFunction( n )->GetParameter( 1 ); typedef itk::TranslationTransform TranslationTransformType; typename TranslationTransformType::Pointer translationTransform = TranslationTransformType::New(); @@ -687,17 +688,17 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, if( !calculatedTransformFromImages ) { - if( initialTransformOption->GetNumberOfParameters( n ) == 0 ) + if( initialTransformOption->GetFunction( n )->GetNumberOfParameters() == 0 ) { - initialTransformName = initialTransformOption->GetValue( n ); + initialTransformName = initialTransformOption->GetFunction( n )->GetName(); useInverse = false; } else { - initialTransformName = initialTransformOption->GetParameter( n, 0 ); - if( initialTransformOption->GetNumberOfParameters( n ) > 1 ) + initialTransformName = initialTransformOption->GetFunction( n )->GetParameter( 0 ); + if( initialTransformOption->GetFunction( n )->GetNumberOfParameters() > 1 ) { - useInverse = parser->Convert( initialTransformOption->GetParameter( n, 1 ) ); + useInverse = parser->Convert( initialTransformOption->GetFunction( n )->GetParameter( 1 ) ); } } } @@ -719,7 +720,7 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, typedef typename RegistrationHelperType::TransformType TransformType; typename TransformType::Pointer initialTransform = - itk::ants::ReadTransform(initialTransformName); + itk::ants::ReadTransform( initialTransformName ); if( initialTransform.IsNull() ) { ::ants::antscout << "Can't read initial transform " << initialTransformName << std::endl; @@ -745,9 +746,9 @@ GetCompositeTransformFromParserOption( typename ParserType::Pointer & parser, std::stringstream tempstream; tempstream << initialTransformName << "[" << i << "]"; - compositeTransform->AddTransform( tempComp->GetNthTransform(i) ); + compositeTransform->AddTransform( tempComp->GetNthTransform( i ) ); transformNames.push_back( tempstream.str() ); - transformTypes.push_back( tempComp->GetNthTransform(i)->GetNameOfClass() ); + transformTypes.push_back( tempComp->GetNthTransform( i )->GetNameOfClass() ); } } else diff --git a/Examples/make_interpolator_snip.tmpl b/Examples/make_interpolator_snip.tmpl index be0444974..48308b1c4 100644 --- a/Examples/make_interpolator_snip.tmpl +++ b/Examples/make_interpolator_snip.tmpl @@ -31,9 +31,9 @@ typename InterpolatorType::Pointer interpolator = NULL; { typedef itk::BSplineInterpolateImageFunction BSplineInterpolatorType; typename BSplineInterpolatorType::Pointer bSplineInterpolator = BSplineInterpolatorType::New(); - if( interpolationOption->GetNumberOfParameters() > 0 ) + if( interpolationOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - unsigned int bsplineOrder = parser->Convert( interpolationOption->GetParameter( 0, 0 ) ); + unsigned int bsplineOrder = parser->Convert( interpolationOption->GetFunction( 0 )->GetParameter( 0 ) ); bSplineInterpolator->SetSplineOrder( bsplineOrder ); } interpolator = bSplineInterpolator; @@ -49,27 +49,27 @@ typename InterpolatorType::Pointer interpolator = NULL; } double alpha = 1.0; - if( interpolationOption->GetNumberOfParameters() > 0 ) + if( interpolationOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - std::vector s = parser->ConvertVector( interpolationOption->GetParameter( 0 ) ); + std::vector s = parser->ConvertVector( interpolationOption->GetFunction( 0 )->GetParameter( 0 ) ); if( s.size() == VImageDimension ) - { - for( unsigned int d = 0; d < VImageDimension; d++ ) - { - sigma[d] = s[d]; - } - } + { + for( unsigned int d = 0; d < VImageDimension; d++ ) + { + sigma[d] = s[d]; + } + } else - { - for( unsigned int d = 0; d < VImageDimension; d++ ) - { - sigma[d] = s[0]; - } - } + { + for( unsigned int d = 0; d < VImageDimension; d++ ) + { + sigma[d] = s[0]; + } + } } - if( interpolationOption->GetNumberOfParameters() > 1 ) + if( interpolationOption->GetFunction( 0 )->GetNumberOfParameters() > 1 ) { - alpha = parser->Convert( interpolationOption->GetParameter( 1 ) ); + alpha = parser->Convert( interpolationOption->GetFunction( 0 )->GetParameter( 1 ) ); } gaussianInterpolator->SetParameters( sigma, alpha ); interpolator = gaussianInterpolator; @@ -122,23 +122,23 @@ typename InterpolatorType::Pointer interpolator = NULL; } double alpha = 4.0; - if( interpolationOption->GetNumberOfParameters() > 0 ) + if( interpolationOption->GetFunction( 0 )->GetNumberOfParameters() > 0 ) { - std::vector s = parser->ConvertVector( interpolationOption->GetParameter( 0 ) ); + std::vector s = parser->ConvertVector( interpolationOption->GetFunction( 0 )->GetParameter( 0 ) ); if( s.size() == VImageDimension ) - { - for( unsigned int d = 0; d < VImageDimension; d++ ) - { - sigma[d] = s[d]; - } - } + { + for( unsigned int d = 0; d < VImageDimension; d++ ) + { + sigma[d] = s[d]; + } + } else - { - for( unsigned int d = 0; d < VImageDimension; d++ ) - { - sigma[d] = s[0]; - } - } + { + for( unsigned int d = 0; d < VImageDimension; d++ ) + { + sigma[d] = s[0]; + } + } } multiLabelInterpolator->SetParameters( sigma, alpha ); interpolator = multiLabelInterpolator; diff --git a/Examples/sccan.cxx b/Examples/sccan.cxx index 6962ba022..d600b40ab 100644 --- a/Examples/sccan.cxx +++ b/Examples/sccan.cxx @@ -347,12 +347,12 @@ int matrixOperation( itk::ants::CommandLineParser::OptionType *option, // option->SetUsageOption( 2, "multires_matrix_invert[list.txt,maskhighres.nii.gz,masklowres.nii.gz,matrix.mhd]" ); - std::string value = option->GetValue( 0 ); + std::string value = option->GetFunction( 0 )->GetName(); if( strcmp( value.c_str(), "multires_matrix_invert" ) == 0 ) { - std::string listfn = option->GetParameter( 0 ); - std::string maskhfn = option->GetParameter( 1 ); - std::string masklfn = option->GetParameter( 2 ); + std::string listfn = option->GetFunction( 0 )->GetParameter( 0 ); + std::string maskhfn = option->GetFunction( 0 )->GetParameter( 1 ); + std::string masklfn = option->GetFunction( 0 )->GetParameter( 2 ); // vnl_matrix matrixinv=MultiResMatrixInvert( listfn, maskhfn, // masklfn ); } @@ -1020,7 +1020,7 @@ int SVD_One_View( itk::ants::CommandLineParser *parser, unsigned int permct, uns } itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( !outputOption || outputOption->GetNumberOfValues() == 0 ) + if( !outputOption || outputOption->GetNumberOfFunctions() == 0 ) { antscout << "Warning: no output option set." << std::endl; } @@ -1048,7 +1048,7 @@ int SVD_One_View( itk::ants::CommandLineParser *parser, unsigned int permct, uns typedef typename SCCANType::DiagonalMatrixType dMatrix; /** read the matrix images */ /** we refer to the two view matrices as P and Q */ - std::string pmatname = std::string(option->GetParameter( 0 ) ); + std::string pmatname = std::string(option->GetFunction( 0 )->GetParameter( 0 ) ); vMatrix p; ReadMatrixFromCSVorImageSet(pmatname, p); if( robustify > 0 ) @@ -1058,9 +1058,9 @@ int SVD_One_View( itk::ants::CommandLineParser *parser, unsigned int permct, uns } typename ImageType::Pointer mask1 = NULL; - bool have_p_mask = SCCANReadImage(mask1, option->GetParameter( 1 ).c_str() ); + bool have_p_mask = SCCANReadImage(mask1, option->GetFunction( 0 )->GetParameter( 1 ).c_str() ); /** the penalties define the fraction of non-zero values for each view */ - double FracNonZero1 = parser->Convert( option->GetParameter( 2 ) ); + double FracNonZero1 = parser->Convert( option->GetFunction( 0 )->GetParameter( 2 ) ); if( FracNonZero1 < 0 ) { FracNonZero1 = fabs(FracNonZero1); @@ -1069,9 +1069,9 @@ int SVD_One_View( itk::ants::CommandLineParser *parser, unsigned int permct, uns /** read the nuisance matrix image */ vMatrix r; - if( option->GetNumberOfParameters() > 3 ) + if( option->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { - std::string nuis_img = option->GetParameter( 3 ); + std::string nuis_img = option->GetFunction( 0 )->GetParameter( 3 ); if( nuis_img.length() > 3 ) { antscout << " nuis_img " << nuis_img << std::endl; @@ -1086,9 +1086,9 @@ int SVD_One_View( itk::ants::CommandLineParser *parser, unsigned int permct, uns if( partialccaOpt ) { // enum SCCANFormulationType{ PQ , PminusRQ , PQminusR , PminusRQminusR , PQR }; - if( partialccaOpt->GetNumberOfValues() > 0 ) + if( partialccaOpt->GetNumberOfFunctions() > 0 ) { - partialccaoption = parser->Convert( partialccaOpt->GetValue() ); + partialccaoption = parser->Convert( partialccaOpt->GetFunction()->GetName() ); } antscout << " Partial SCCA option " << partialccaoption << std::endl; if( !partialccaoption.compare( std::string( "PQ" ) ) ) @@ -1159,7 +1159,7 @@ int SVD_One_View( itk::ants::CommandLineParser *parser, unsigned int permct, uns if( outputOption ) { - std::string filename = outputOption->GetValue( 0 ); + std::string filename = outputOption->GetFunction( 0 )->GetName(); antscout << " write " << filename << std::endl; std::string::size_type pos = filename.rfind( "." ); std::string filepre = std::string( filename, 0, pos ); @@ -1237,7 +1237,7 @@ int SCCA_vnl( itk::ants::CommandLineParser *parser, unsigned int permct, unsigne parser->GetOption( "output" ); bool writeoutput = true; - if( !outputOption || outputOption->GetNumberOfValues() == 0 ) + if( !outputOption || outputOption->GetNumberOfFunctions() == 0 ) { antscout << "Warning: no output option set." << std::endl; writeoutput = false; @@ -1267,11 +1267,11 @@ int SCCA_vnl( itk::ants::CommandLineParser *parser, unsigned int permct, unsigne Scalar pinvtoler = 1.e-6; /** read the matrix images */ /** we refer to the two view matrices as P and Q */ - std::string pmatname = std::string(option->GetParameter( 0 ) ); + std::string pmatname = std::string(option->GetFunction( 0 )->GetParameter( 0 ) ); vMatrix p; // antscout <<" read-p "<< std::endl; ReadMatrixFromCSVorImageSet(pmatname, p); - std::string qmatname = std::string(option->GetParameter( 1 ) ); + std::string qmatname = std::string(option->GetFunction( 0 )->GetParameter( 1 ) ); vMatrix q; // antscout <<" read-q "<< std::endl; ReadMatrixFromCSVorImageSet(qmatname, q); @@ -1281,19 +1281,19 @@ int SCCA_vnl( itk::ants::CommandLineParser *parser, unsigned int permct, unsigne } typename ImageType::Pointer mask1 = NULL; - bool have_p_mask = SCCANReadImage(mask1, option->GetParameter( 2 ).c_str() ); + bool have_p_mask = SCCANReadImage(mask1, option->GetFunction( 0 )->GetParameter( 2 ).c_str() ); typename ImageType::Pointer mask2 = NULL; - bool have_q_mask = SCCANReadImage(mask2, option->GetParameter( 3 ).c_str() ); + bool have_q_mask = SCCANReadImage(mask2, option->GetFunction( 0 )->GetParameter( 3 ).c_str() ); /** the penalties define the fraction of non-zero values for each view */ - double FracNonZero1 = parser->Convert( option->GetParameter( 4 ) ); + double FracNonZero1 = parser->Convert( option->GetFunction( 0 )->GetParameter( 4 ) ); if( FracNonZero1 < 0 ) { FracNonZero1 = fabs(FracNonZero1); sccanobj->SetKeepPositiveP(false); } - double FracNonZero2 = parser->Convert( option->GetParameter( 5 ) ); + double FracNonZero2 = parser->Convert( option->GetFunction( 0 )->GetParameter( 5 ) ); if( FracNonZero2 < 0 ) { FracNonZero2 = fabs(FracNonZero2); @@ -1337,7 +1337,7 @@ int SCCA_vnl( itk::ants::CommandLineParser *parser, unsigned int permct, unsigne if( writeoutput ) { - std::string filename = outputOption->GetValue( 0 ); + std::string filename = outputOption->GetFunction( 0 )->GetName(); antscout << " write " << filename << std::endl; std::string::size_type pos = filename.rfind( "." ); std::string filepre = std::string( filename, 0, pos ); @@ -1449,7 +1449,7 @@ int SCCA_vnl( itk::ants::CommandLineParser *parser, unsigned int permct, unsigne if( writeoutput ) { - std::string filename = outputOption->GetValue( 0 ); + std::string filename = outputOption->GetFunction( 0 )->GetName(); antscout << " write " << filename << std::endl; std::string::size_type pos = filename.rfind( "." ); std::string filepre = std::string( filename, 0, pos ); @@ -1484,7 +1484,7 @@ int mSCCA_vnl( itk::ants::CommandLineParser *parser, antscout << " Entering MSCCA --- computing " << n_e_vecs << " canonical variates by default. " << std::endl; itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( !outputOption || outputOption->GetNumberOfValues() == 0 ) + if( !outputOption || outputOption->GetNumberOfFunctions() == 0 ) { antscout << "Warning: no output option set." << std::endl; } @@ -1511,13 +1511,13 @@ int mSCCA_vnl( itk::ants::CommandLineParser *parser, typedef itk::ImageFileReader imgReaderType; /** read the matrix images */ - std::string pmatname = std::string(option->GetParameter( 0 ) ); + std::string pmatname = std::string(option->GetFunction( 0 )->GetParameter( 0 ) ); vMatrix pin; ReadMatrixFromCSVorImageSet(pmatname, pin); - std::string qmatname = std::string(option->GetParameter( 1 ) ); + std::string qmatname = std::string(option->GetFunction( 0 )->GetParameter( 1 ) ); vMatrix qin; ReadMatrixFromCSVorImageSet(qmatname, qin); - std::string rmatname = std::string(option->GetParameter( 2 ) ); + std::string rmatname = std::string(option->GetFunction( 0 )->GetParameter( 2 ) ); vMatrix rin; ReadMatrixFromCSVorImageSet(rmatname, rin); if( CompareMatrixSizes( pin, qin ) == EXIT_FAILURE ) @@ -1534,25 +1534,25 @@ int mSCCA_vnl( itk::ants::CommandLineParser *parser, } typename ImageType::Pointer mask1 = NULL; - bool have_p_mask = SCCANReadImage(mask1, option->GetParameter( 3 ).c_str() ); + bool have_p_mask = SCCANReadImage(mask1, option->GetFunction( 0 )->GetParameter( 3 ).c_str() ); typename ImageType::Pointer mask2 = NULL; - bool have_q_mask = SCCANReadImage(mask2, option->GetParameter( 4 ).c_str() ); + bool have_q_mask = SCCANReadImage(mask2, option->GetFunction( 0 )->GetParameter( 4 ).c_str() ); typename ImageType::Pointer mask3 = NULL; /** the penalties define the fraction of non-zero values for each view */ - double FracNonZero1 = parser->Convert( option->GetParameter( 6 ) ); + double FracNonZero1 = parser->Convert( option->GetFunction( 0 )->GetParameter( 6 ) ); if( FracNonZero1 < 0 ) { FracNonZero1 = fabs(FracNonZero1); sccanobj->SetKeepPositiveP(false); } - double FracNonZero2 = parser->Convert( option->GetParameter( 7 ) ); + double FracNonZero2 = parser->Convert( option->GetFunction( 0 )->GetParameter( 7 ) ); if( FracNonZero2 < 0 ) { FracNonZero2 = fabs(FracNonZero2); sccanobj->SetKeepPositiveQ(false); } - double FracNonZero3 = parser->Convert( option->GetParameter( 8 ) ); + double FracNonZero3 = parser->Convert( option->GetFunction( 0 )->GetParameter( 8 ) ); if( FracNonZero3 < 0 ) { FracNonZero3 = fabs(FracNonZero3); @@ -1602,9 +1602,9 @@ int mSCCA_vnl( itk::ants::CommandLineParser *parser, if( partialccaOpt ) { // enum SCCANFormulationType{ PQ , PminusRQ , PQminusR , PminusRQminusR , PQR }; - if( partialccaOpt->GetNumberOfValues() > 0 ) + if( partialccaOpt->GetNumberOfFunctions() > 0 ) { - partialccaoption = parser->Convert( partialccaOpt->GetValue() ); + partialccaoption = parser->Convert( partialccaOpt->GetFunction()->GetName() ); } antscout << " Partial SCCA option " << partialccaoption << std::endl; if( !partialccaoption.compare( std::string( "PQ" ) ) ) @@ -1648,7 +1648,7 @@ int mSCCA_vnl( itk::ants::CommandLineParser *parser, if( outputOption ) { - std::string filename = outputOption->GetValue( 0 ); + std::string filename = outputOption->GetFunction( 0 )->GetName(); std::string::size_type pos = filename.rfind( "." ); std::string filepre = std::string( filename, 0, pos ); std::string extension = std::string( filename, pos, filename.length() - 1); @@ -1809,7 +1809,7 @@ int mSCCA_vnl( itk::ants::CommandLineParser *parser, } if( outputOption ) { - std::string filename = outputOption->GetValue( 0 ); + std::string filename = outputOption->GetFunction( 0 )->GetName(); antscout << " write " << filename << std::endl; std::string::size_type pos = filename.rfind( "." ); std::string filepre = std::string( filename, 0, pos ); @@ -1892,120 +1892,120 @@ int sccan( itk::ants::CommandLineParser *parser ) itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); - if( !outputOption || outputOption->GetNumberOfValues() == 0 ) + if( !outputOption || outputOption->GetNumberOfFunctions() == 0 ) { antscout << "Warning: no output option set." << std::endl; } unsigned int permct = 0; itk::ants::CommandLineParser::OptionType::Pointer permoption = parser->GetOption( "n_permutations" ); - if( !permoption || permoption->GetNumberOfValues() == 0 ) + if( !permoption || permoption->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - permct = parser->Convert( permoption->GetValue() ); + permct = parser->Convert( permoption->GetFunction()->GetName() ); } unsigned int iterct = 20; permoption = parser->GetOption( "iterations" ); - if( permoption && permoption->GetNumberOfValues() > 0 ) + if( permoption && permoption->GetNumberOfFunctions() > 0 ) { - iterct = parser->Convert( permoption->GetValue() ); + iterct = parser->Convert( permoption->GetFunction()->GetName() ); } // if (iterct < 20 ) iterct=20; unsigned int evec_ct = 1; itk::ants::CommandLineParser::OptionType::Pointer evec_option = parser->GetOption( "n_eigenvectors" ); - if( !evec_option || evec_option->GetNumberOfValues() == 0 ) + if( !evec_option || evec_option->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - evec_ct = parser->Convert( evec_option->GetValue() ); + evec_ct = parser->Convert( evec_option->GetFunction()->GetName() ); } matPixelType usel1 = 0.1; itk::ants::CommandLineParser::OptionType::Pointer l1_option = parser->GetOption( "l1" ); - if( !l1_option || l1_option->GetNumberOfValues() == 0 ) + if( !l1_option || l1_option->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - usel1 = parser->Convert( l1_option->GetValue() ); + usel1 = parser->Convert( l1_option->GetFunction()->GetName() ); } unsigned int robustify = 0; itk::ants::CommandLineParser::OptionType::Pointer robust_option = parser->GetOption( "robustify" ); - if( !robust_option || robust_option->GetNumberOfValues() == 0 ) + if( !robust_option || robust_option->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - robustify = parser->Convert( robust_option->GetValue() ); + robustify = parser->Convert( robust_option->GetFunction()->GetName() ); } matPixelType evecgradientpenalty = 1; itk::ants::CommandLineParser::OptionType::Pointer evecg_option = parser->GetOption( "EvecGradPenalty" ); - if( !evecg_option || evecg_option->GetNumberOfValues() == 0 ) + if( !evecg_option || evecg_option->GetNumberOfFunctions() == 0 ) { } else { - evecgradientpenalty = parser->Convert( evecg_option->GetValue() ); + evecgradientpenalty = parser->Convert( evecg_option->GetFunction()->GetName() ); } unsigned int p_cluster_thresh = 1; itk::ants::CommandLineParser::OptionType::Pointer clust_option = parser->GetOption( "PClusterThresh" ); - if( !clust_option || clust_option->GetNumberOfValues() == 0 ) + if( !clust_option || clust_option->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - p_cluster_thresh = parser->Convert( clust_option->GetValue() ); + p_cluster_thresh = parser->Convert( clust_option->GetFunction()->GetName() ); } unsigned int q_cluster_thresh = 1; clust_option = parser->GetOption( "QClusterThresh" ); - if( !clust_option || clust_option->GetNumberOfValues() == 0 ) + if( !clust_option || clust_option->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - q_cluster_thresh = parser->Convert( clust_option->GetValue() ); + q_cluster_thresh = parser->Convert( clust_option->GetFunction()->GetName() ); } bool eigen_imp = false; itk::ants::CommandLineParser::OptionType::Pointer eigen_option = parser->GetOption( "ridge_cca" ); - if( !eigen_option || eigen_option->GetNumberOfValues() == 0 ) + if( !eigen_option || eigen_option->GetNumberOfFunctions() == 0 ) { // antscout << "Warning: no permutation option set." << std::endl; } else { - eigen_imp = parser->Convert( eigen_option->GetValue() ); + eigen_imp = parser->Convert( eigen_option->GetFunction()->GetName() ); } // operations on individual matrices itk::ants::CommandLineParser::OptionType::Pointer matrixOption = parser->GetOption( "imageset-to-matrix" ); - if( matrixOption && matrixOption->GetNumberOfValues() > 0 ) + if( matrixOption && matrixOption->GetNumberOfFunctions() > 0 ) { - std::string outname = outputOption->GetValue( 0 ); - std::string imagelist = matrixOption->GetParameter( 0 ); - std::string maskfn = matrixOption->GetParameter( 1 ); + std::string outname = outputOption->GetFunction( 0 )->GetName(); + std::string imagelist = matrixOption->GetFunction( 0 )->GetParameter( 0 ); + std::string maskfn = matrixOption->GetFunction( 0 )->GetParameter( 1 ); ConvertImageListToMatrix( imagelist, maskfn, outname ); return EXIT_SUCCESS; } @@ -2013,20 +2013,20 @@ int sccan( itk::ants::CommandLineParser *parser ) // operations on individual matrices itk::ants::CommandLineParser::OptionType::Pointer matrixOptionTimeSeries = parser->GetOption( "timeseriesimage-to-matrix" ); - if( matrixOptionTimeSeries && matrixOptionTimeSeries->GetNumberOfValues() > 0 ) + if( matrixOptionTimeSeries && matrixOptionTimeSeries->GetNumberOfFunctions() > 0 ) { - std::string outname = outputOption->GetValue( 0 ); - std::string imagefn = matrixOptionTimeSeries->GetParameter( 0 ); - std::string maskfn = matrixOptionTimeSeries->GetParameter( 1 ); + std::string outname = outputOption->GetFunction( 0 )->GetName(); + std::string imagefn = matrixOptionTimeSeries->GetFunction( 0 )->GetParameter( 0 ); + std::string maskfn = matrixOptionTimeSeries->GetFunction( 0 )->GetParameter( 1 ); double smoother_space = 0; - if( matrixOptionTimeSeries->GetNumberOfParameters() > 2 ) + if( matrixOptionTimeSeries->GetFunction( 0 )->GetNumberOfParameters() > 2 ) { - smoother_space = parser->Convert( matrixOptionTimeSeries->GetParameter( 2 ) ); + smoother_space = parser->Convert( matrixOptionTimeSeries->GetFunction( 0 )->GetParameter( 2 ) ); } double smoother_time = 0; - if( matrixOptionTimeSeries->GetNumberOfParameters() > 3 ) + if( matrixOptionTimeSeries->GetFunction( 0 )->GetNumberOfParameters() > 3 ) { - smoother_time = parser->Convert( matrixOptionTimeSeries->GetParameter( 3 ) ); + smoother_time = parser->Convert( matrixOptionTimeSeries->GetFunction( 0 )->GetParameter( 3 ) ); } typedef itk::Image MyImageType; ConvertTimeSeriesImageToMatrix( imagefn, maskfn, outname, smoother_space, smoother_time ); @@ -2037,12 +2037,12 @@ int sccan( itk::ants::CommandLineParser *parser ) // operations on individual matrices itk::ants::CommandLineParser::OptionType::Pointer matrixOptionV2I = parser->GetOption( "vector-to-image" ); - if( matrixOptionV2I && matrixOptionV2I->GetNumberOfValues() > 0 ) + if( matrixOptionV2I && matrixOptionV2I->GetNumberOfFunctions() > 0 ) { - std::string outname = outputOption->GetValue( 0 ); - std::string csvfn = matrixOptionV2I->GetParameter( 0 ); - std::string maskfn = matrixOptionV2I->GetParameter( 1 ); - unsigned long rowOrCol = parser->Convert( matrixOptionV2I->GetParameter( 2 ) ); + std::string outname = outputOption->GetFunction( 0 )->GetName(); + std::string csvfn = matrixOptionV2I->GetFunction( 0 )->GetParameter( 0 ); + std::string maskfn = matrixOptionV2I->GetFunction( 0 )->GetParameter( 1 ); + unsigned long rowOrCol = parser->Convert( matrixOptionV2I->GetFunction( 0 )->GetParameter( 2 ) ); ConvertCSVVectorToImage( csvfn, maskfn, outname, rowOrCol ); antscout << " V2I done " << outname << std::endl; return EXIT_SUCCESS; @@ -2051,12 +2051,12 @@ int sccan( itk::ants::CommandLineParser *parser ) // p.d. itk::ants::CommandLineParser::OptionType::Pointer matrixProjectionOption = parser->GetOption( "imageset-to-projections" ); - if( matrixProjectionOption && matrixProjectionOption->GetNumberOfValues() > 0 ) + if( matrixProjectionOption && matrixProjectionOption->GetNumberOfFunctions() > 0 ) { - std::string outFilename = outputOption->GetValue( 0 ); - std::string vecList = matrixProjectionOption->GetParameter( 0 ); - std::string imageList = matrixProjectionOption->GetParameter( 1 ); - bool average = parser->Convert( matrixProjectionOption->GetParameter( 2 ) ); + std::string outFilename = outputOption->GetFunction( 0 )->GetName(); + std::string vecList = matrixProjectionOption->GetFunction( 0 )->GetParameter( 0 ); + std::string imageList = matrixProjectionOption->GetFunction( 0 )->GetParameter( 1 ); + bool average = parser->Convert( matrixProjectionOption->GetFunction( 0 )->GetParameter( 2 ) ); // antscout <<"here" << outFilename << " " << vecList << " " <GetOption( "svd" ); - if( svdOption && svdOption->GetNumberOfValues() > 0 ) + if( svdOption && svdOption->GetNumberOfFunctions() > 0 ) { - std::string initializationStrategy = svdOption->GetValue(); + std::string initializationStrategy = svdOption->GetFunction()->GetName(); if( !initializationStrategy.compare( std::string( "sparse" ) ) ) { SVD_One_View( parser, permct, evec_ct, robustify, p_cluster_thresh, iterct, 0, usel1 ); @@ -2110,14 +2110,14 @@ int sccan( itk::ants::CommandLineParser *parser ) // operations on pairs of matrices itk::ants::CommandLineParser::OptionType::Pointer matrixPairOption = parser->GetOption( "scca" ); - if( matrixPairOption && matrixPairOption->GetNumberOfValues() > 0 ) + if( matrixPairOption && matrixPairOption->GetNumberOfFunctions() > 0 ) { - if( matrixPairOption && matrixPairOption->GetNumberOfParameters() < 2 ) + if( matrixPairOption && matrixPairOption->GetFunction( 0 )->GetNumberOfParameters() < 2 ) { antscout << " Incorrect number of parameters." << std::endl; return EXIT_FAILURE; } - std::string initializationStrategy = matrixPairOption->GetValue(); + std::string initializationStrategy = matrixPairOption->GetFunction()->GetName(); // call RCCA_eigen or RCCA_vnl unsigned int exitvalue = EXIT_FAILURE; if( !initializationStrategy.compare( std::string( "two-view" ) ) ) @@ -2168,7 +2168,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetShortName( 'h' ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -2177,7 +2177,7 @@ void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) OptionType::Pointer option = OptionType::New(); option->SetLongName( "help" ); option->SetDescription( description ); - option->AddValue( std::string( "0" ) ); + option->AddFunction( std::string( "0" ) ); parser->AddOption( option ); } @@ -2448,7 +2448,7 @@ int sccan( std::vector args, std::ostream* out_stream = NULL ) itk::ants::CommandLineParser::OptionType::Pointer longHelpOption = parser->GetOption( "help" ); if( argc < 2 || ( shortHelpOption && - parser->Convert( shortHelpOption->GetValue() ) == 1 ) ) + parser->Convert( shortHelpOption->GetFunction()->GetName() ) == 1 ) ) { parser->PrintMenu( antscout, 5, true ); if( argc < 2 ) @@ -2457,21 +2457,21 @@ int sccan( std::vector args, std::ostream* out_stream = NULL ) } return EXIT_SUCCESS; } - if( longHelpOption && parser->Convert( longHelpOption->GetValue() ) == 1 ) + if( longHelpOption && parser->Convert( longHelpOption->GetFunction()->GetName() ) == 1 ) { parser->PrintMenu( antscout, 5, false ); return EXIT_SUCCESS; } // Print the long help menu for specific items - if( longHelpOption && longHelpOption->GetNumberOfValues() > 0 - && parser->Convert( longHelpOption->GetValue() ) != 0 ) + if( longHelpOption && longHelpOption->GetNumberOfFunctions() > 0 + && parser->Convert( longHelpOption->GetFunction()->GetName() ) != 0 ) { itk::ants::CommandLineParser::OptionListType options = parser->GetOptions(); - for( unsigned int n = 0; n < longHelpOption->GetNumberOfValues(); n++ ) + for( unsigned int n = 0; n < longHelpOption->GetNumberOfFunctions(); n++ ) { - std::string value = longHelpOption->GetValue( n ); + std::string value = longHelpOption->GetFunction( n )->GetName(); itk::ants::CommandLineParser::OptionListType::const_iterator it; for( it = options.begin(); it != options.end(); ++it ) { diff --git a/ImageRegistration/itkANTSImageRegistrationOptimizer.h b/ImageRegistration/itkANTSImageRegistrationOptimizer.h index 3335306de..18af30727 100644 --- a/ImageRegistration/itkANTSImageRegistrationOptimizer.h +++ b/ImageRegistration/itkANTSImageRegistrationOptimizer.h @@ -234,7 +234,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer typename ParserType::OptionType::Pointer regularizationOption = this->m_Parser->GetOption( "regularization" ); - if( ( regularizationOption->GetValue() ).find( "DMFFD" ) + if( ( regularizationOption->GetFunction( 0 )->GetName() ).find( "DMFFD" ) != std::string::npos ) { if( ( !TrueEqualsGradElseTotal && this->m_TotalSmoothingparam == 0.0 ) || @@ -813,7 +813,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer /** Univariate Deformable Mapping */ // set up parameters for deformation restriction - std::string temp = this->m_Parser->GetOption( "Restrict-Deformation" )->GetValue(); + std::string temp = this->m_Parser->GetOption( "Restrict-Deformation" )->GetFunction()->GetName(); this->m_RestrictDeformation = this->m_Parser->template ConvertVector(temp); if( this->m_RestrictDeformation.size() != ImageDimension ) @@ -829,13 +829,13 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer } // set up max iterations per level - temp = this->m_Parser->GetOption( "number-of-iterations" )->GetValue(); + temp = this->m_Parser->GetOption( "number-of-iterations" )->GetFunction()->GetName(); this->m_Iterations = this->m_Parser->template ConvertVector(temp); this->SetNumberOfLevels(this->m_Iterations.size() ); this->m_UseROI = false; if( typename OptionType::Pointer option = this->m_Parser->GetOption( "roi" ) ) { - temp = this->m_Parser->GetOption( "roi" )->GetValue(); + temp = this->m_Parser->GetOption( "roi" )->GetFunction()->GetName(); this->m_RoiNumbers = this->m_Parser->template ConvertVector(temp); if( temp.length() > 3 ) { @@ -845,11 +845,11 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer typename ParserType::OptionType::Pointer oOption = this->m_Parser->GetOption( "output-naming" ); - this->m_OutputNamingConvention = oOption->GetValue(); + this->m_OutputNamingConvention = oOption->GetFunction( 0 )->GetName(); typename ParserType::OptionType::Pointer thicknessOption = this->m_Parser->GetOption( "geodesic" ); - if( thicknessOption->GetValue() == "true" || thicknessOption->GetValue() == "1" ) + if( thicknessOption->GetFunction( 0 )->GetName() == "true" || thicknessOption->GetFunction( 0 )->GetName() == "1" ) { this->m_ComputeThickness = 1; this->m_SyNFullTime = 2; } // @@ -857,7 +857,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer // asymm // // forces - else if( thicknessOption->GetValue() == "2" ) + else if( thicknessOption->GetFunction( 0 )->GetName() == "2" ) { this->m_ComputeThickness = 1; this->m_SyNFullTime = 1; } // symmetric @@ -871,10 +871,10 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer */ typename ParserType::OptionType::Pointer transformOption = this->m_Parser->GetOption( "transformation-model" ); - this->SetTransformationModel( transformOption->GetValue() ); - if( transformOption->GetNumberOfParameters() >= 1 ) + this->SetTransformationModel( transformOption->GetFunction( 0 )->GetName() ); + if( transformOption->GetFunction( 0 )->GetNumberOfParameters() >= 1 ) { - std::string parameter = transformOption->GetParameter( 0, 0 ); + std::string parameter = transformOption->GetFunction( 0 )->GetParameter( 0 ); TReal _temp = this->m_Parser->template Convert( parameter ); this->m_Gradstep = _temp; this->m_GradstepAltered = _temp; @@ -883,18 +883,18 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer { this->m_Gradstep = 0.5; this->m_GradstepAltered = 0.5; } - if( transformOption->GetNumberOfParameters() >= 2 ) + if( transformOption->GetFunction( 0 )->GetNumberOfParameters() >= 2 ) { - std::string parameter = transformOption->GetParameter( 0, 1 ); + std::string parameter = transformOption->GetFunction( 0 )->GetParameter( 1 ); this->m_NTimeSteps = this->m_Parser->template Convert( parameter ); } else { this->m_NTimeSteps = 1; } - if( transformOption->GetNumberOfParameters() >= 3 ) + if( transformOption->GetFunction( 0 )->GetNumberOfParameters() >= 3 ) { - std::string parameter = transformOption->GetParameter( 0, 2 ); + std::string parameter = transformOption->GetFunction( 0 )->GetParameter( 2 ); this->m_DeltaTime = this->m_Parser->template Convert( parameter ); if( this->m_DeltaTime > 1 ) @@ -912,9 +912,9 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer { this->m_DeltaTime = 0.1; } -// if ( transformOption->GetNumberOfParameters() >= 3 ) +// if ( transformOption->GetFunction( 0 )->GetNumberOfParameters() >= 3 ) // { -// std::string parameter = transformOption->GetParameter( 0, 2 ); +// std::string parameter = transformOption->GetFunction( 0 )->GetParameter( 2 ); // this->m_SymmetryType // = this->m_Parser->template Convert( parameter ); // } @@ -929,29 +929,29 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer typename ParserType::OptionType::Pointer regularizationOption = this->m_Parser->GetOption( "regularization" ); - if( regularizationOption->GetValue() == "Gauss" ) + if( regularizationOption->GetFunction( 0 )->GetName() == "Gauss" ) { - if( regularizationOption->GetNumberOfParameters() >= 1 ) + if( regularizationOption->GetFunction( 0 )->GetNumberOfParameters() >= 1 ) { - std::string parameter = regularizationOption->GetParameter( 0, 0 ); + std::string parameter = regularizationOption->GetFunction( 0 )->GetParameter( 0 ); this->m_GradSmoothingparam = this->m_Parser->template Convert( parameter ); } else { this->m_GradSmoothingparam = 3; } - if( regularizationOption->GetNumberOfParameters() >= 2 ) + if( regularizationOption->GetFunction( 0 )->GetNumberOfParameters() >= 2 ) { - std::string parameter = regularizationOption->GetParameter( 0, 1 ); + std::string parameter = regularizationOption->GetFunction( 0 )->GetParameter( 1 ); this->m_TotalSmoothingparam = this->m_Parser->template Convert( parameter ); } else { this->m_TotalSmoothingparam = 0.5; } - if( regularizationOption->GetNumberOfParameters() >= 3 ) + if( regularizationOption->GetFunction( 0 )->GetNumberOfParameters() >= 3 ) { - std::string parameter = regularizationOption->GetParameter( 0, 2 ); + std::string parameter = regularizationOption->GetFunction( 0 )->GetParameter( 2 ); this->m_GaussianTruncation = this->m_Parser->template Convert( parameter ); } else @@ -961,12 +961,12 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer ::ants::antscout << " Grad Step " << this->m_Gradstep << " total-smoothing " << this->m_TotalSmoothingparam << " gradient-smoothing " << this->m_GradSmoothingparam << std::endl; } - else if( ( regularizationOption->GetValue() ).find( "DMFFD" ) + else if( ( regularizationOption->GetFunction( 0 )->GetName() ).find( "DMFFD" ) != std::string::npos ) { - if( regularizationOption->GetNumberOfParameters() >= 1 ) + if( regularizationOption->GetFunction( 0 )->GetNumberOfParameters() >= 1 ) { - std::string parameter = regularizationOption->GetParameter( 0, 0 ); + std::string parameter = regularizationOption->GetFunction( 0 )->GetParameter( 0 ); if( parameter.find( "x" ) != std::string::npos ) { std::vector gradMeshSize @@ -986,9 +986,9 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer { this->m_GradSmoothingparam = 3.0; } - if( regularizationOption->GetNumberOfParameters() >= 2 ) + if( regularizationOption->GetFunction( 0 )->GetNumberOfParameters() >= 2 ) { - std::string parameter = regularizationOption->GetParameter( 0, 1 ); + std::string parameter = regularizationOption->GetFunction( 0 )->GetParameter( 1 ); if( parameter.find( "x" ) != std::string::npos ) { std::vector totalMeshSize @@ -1008,9 +1008,9 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer { this->m_TotalSmoothingparam = 0.5; } - if( regularizationOption->GetNumberOfParameters() >= 3 ) + if( regularizationOption->GetFunction( 0 )->GetNumberOfParameters() >= 3 ) { - std::string parameter = regularizationOption->GetParameter( 0, 2 ); + std::string parameter = regularizationOption->GetFunction( 0 )->GetParameter( 2 ); this->m_BSplineFieldOrder = this->m_Parser->template Convert( parameter ); } @@ -1031,7 +1031,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer ::ants::antscout << " Default Regularization is Gaussian smoothing with : " << this->m_GradSmoothingparam << " & " << this->m_TotalSmoothingparam << std::endl; -// itkExceptionMacro( "Invalid regularization: " << regularizationOption->GetValue() ); +// itkExceptionMacro( "Invalid regularization: " << regularizationOption->GetFunction( 0 )->GetName() ); } } @@ -1161,7 +1161,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer // Get subsample factors and gaussian smoothing sigmas if specified // by the user. std::string subsamplingfactors = - this->m_Parser->GetOption( "subsampling-factors" )->GetValue(); + this->m_Parser->GetOption( "subsampling-factors" )->GetFunction()->GetName(); if( subsamplingfactors.size() > 0 ) { std::vector factors = @@ -1182,7 +1182,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer } std::string gaussiansmoothingsigmas = - this->m_Parser->GetOption( "gaussian-smoothing-sigmas" )->GetValue(); + this->m_Parser->GetOption( "gaussian-smoothing-sigmas" )->GetFunction()->GetName(); if( gaussiansmoothingsigmas.size() > 0 ) { std::vector sigmas = @@ -1428,7 +1428,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer // Added by Paul: allow weighted metric to be used here typename ParserType::OptionType::Pointer regularizationOption = this->m_Parser->GetOption( "use-all-metrics-for-convergence" ); - bool use_all_metrics = (atoi(regularizationOption->GetValue().c_str() ) > 0); + bool use_all_metrics = (atoi(regularizationOption->GetFunction()->GetName().c_str() ) > 0); unsigned int domtar = 12; if( this->m_CurrentIteration > domtar ) @@ -1808,7 +1808,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer typename ParserType::OptionType::Pointer thicknessOption = this->m_Parser->GetOption( "go-faster" ); - if( thicknessOption->GetValue() == "true" || thicknessOption->GetValue() == "1" ) + if( thicknessOption->GetFunction( 0 )->GetName() == "true" || thicknessOption->GetFunction( 0 )->GetName() == "1" ) { mytoler = 0.5; maxiter = 12; } diff --git a/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.hxx b/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.hxx index b82b86490..1fff06990 100644 --- a/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.hxx +++ b/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.hxx @@ -86,7 +86,7 @@ PICSLAdvancedNormalizationToolKit ::ants::antscout << std::endl; } - std::string printhelp_long = this->m_Parser->GetOption( "help" )->GetValue(); + std::string printhelp_long = this->m_Parser->GetOption( "help" )->GetFunction( 0 )->GetName(); unsigned int help_long = this->m_Parser->template Convert( printhelp_long ); if( help_long ) @@ -96,7 +96,7 @@ PICSLAdvancedNormalizationToolKit exit( EXIT_SUCCESS ); } - std::string printhelp_short = this->m_Parser->GetOption( 'h' )->GetValue(); + std::string printhelp_short = this->m_Parser->GetOption( 'h' )->GetFunction( 0 )->GetName(); unsigned int help_short = this->m_Parser->template Convert( printhelp_short ); if( help_short ) @@ -120,7 +120,7 @@ PICSLAdvancedNormalizationToolKit { this->m_RegistrationOptimizer = RegistrationOptimizerType::New(); } - std::string temp = this->m_Parser->GetOption( "output-naming" )->GetValue(); + std::string temp = this->m_Parser->GetOption( "output-naming" )->GetFunction( 0 )->GetName(); this->m_TransformationModel->SetNamingConvention( temp ); this->m_TransformationModel->InitializeTransform(); this->m_RegistrationOptimizer->SetParser( this->m_Parser ); @@ -142,7 +142,7 @@ PICSLAdvancedNormalizationToolKit if( typename OptionType::Pointer option = this->m_Parser->GetOption( "mask-image" ) ) { typedef ImageFileReader ReaderType; - std::string maskfn = this->m_Parser->GetOption( "mask-image" )->GetValue(); + std::string maskfn = this->m_Parser->GetOption( "mask-image" )->GetFunction( 0 )->GetName(); if( maskfn.length() > 4 ) { typename ReaderType::Pointer maskImageFileReader = ReaderType::New(); @@ -157,7 +157,7 @@ PICSLAdvancedNormalizationToolKit // added by songgang // try initialize the affine transform - typename OptionType::ValueType initial_affine_filename = this->m_Parser->GetOption( "initial-affine" )->GetValue(); + std::string initial_affine_filename = this->m_Parser->GetOption( "initial-affine" )->GetFunction( 0 )->GetName(); if( initial_affine_filename != "" ) { ::ants::antscout << "Loading affine registration from: " << initial_affine_filename << std::endl; @@ -168,8 +168,8 @@ PICSLAdvancedNormalizationToolKit ::ants::antscout << "Use identity affine transform as initial affine para." << std::endl; ::ants::antscout << "aff_init.IsNull()==" << aff_init.IsNull() << std::endl; } - typename OptionType::ValueType fixed_initial_affine_filename = this->m_Parser->GetOption( - "fixed-image-initial-affine" )->GetValue(); + std::string fixed_initial_affine_filename = this->m_Parser->GetOption( + "fixed-image-initial-affine" )->GetFunction( 0 )->GetName(); if( fixed_initial_affine_filename != "" ) { ::ants::antscout << "Loading affine registration from: " << fixed_initial_affine_filename << std::endl; @@ -180,7 +180,8 @@ PICSLAdvancedNormalizationToolKit << " FIXME! currently, if one passes a fixed initial affine mapping, then NO affine mapping will be performed subsequently! " << std::endl; - std::string refheader = this->m_Parser->GetOption( "fixed-image-initial-affine-ref-image" )->GetValue(); + std::string refheader = + this->m_Parser->GetOption( "fixed-image-initial-affine-ref-image" )->GetFunction( 0 )->GetName(); if( refheader != "" ) { ::ants::antscout << " Setting reference deformation space by " << refheader << std::endl; @@ -198,7 +199,8 @@ PICSLAdvancedNormalizationToolKit ::ants::antscout << "fixed_aff_init.IsNull()==" << fixed_aff_init.IsNull() << std::endl; } - bool useNN = this->m_Parser->template Convert( this->m_Parser->GetOption( "use-NN" )->GetValue() ); + bool useNN = + this->m_Parser->template Convert( this->m_Parser->GetOption( "use-NN" )->GetFunction()->GetName() ); if( useNN ) { this->m_RegistrationOptimizer->SetUseNearestNeighborInterpolation(true); @@ -208,7 +210,7 @@ PICSLAdvancedNormalizationToolKit this->m_RegistrationOptimizer->SetUseNearestNeighborInterpolation(false); } - typename OptionType::ValueType continue_affine = this->m_Parser->GetOption( "continue-affine" )->GetValue(); + std::string continue_affine = this->m_Parser->GetOption( "continue-affine" )->GetFunction( 0 )->GetName(); if( fixed_initial_affine_filename != "" ) { continue_affine = std::string("false"); @@ -221,10 +223,10 @@ PICSLAdvancedNormalizationToolKit // InitializeAffineOption() { affine_opt.transform_initial = aff_init; - std::string temp = this->m_Parser->GetOption( "number-of-affine-iterations" )->GetValue(); + std::string temp = this->m_Parser->GetOption( "number-of-affine-iterations" )->GetFunction( 0 )->GetName(); affine_opt.number_of_iteration_list = this->m_Parser->template ConvertVector(temp); affine_opt.number_of_levels = affine_opt.number_of_iteration_list.size(); - temp = this->m_Parser->GetOption( "affine-metric-type" )->GetValue(); + temp = this->m_Parser->GetOption( "affine-metric-type" )->GetFunction( 0 )->GetName(); if( temp == "MI" ) { affine_opt.metric_type = AffineWithMutualInformation; @@ -245,27 +247,27 @@ PICSLAdvancedNormalizationToolKit { affine_opt.metric_type = AffineWithGradientDifference; } - temp = this->m_Parser->GetOption( "MI-option" )->GetValue(); + temp = this->m_Parser->GetOption( "MI-option" )->GetFunction( 0 )->GetName(); std::vector mi_option = this->m_Parser->template ConvertVector(temp); affine_opt.MI_bins = mi_option[0]; affine_opt.MI_samples = mi_option[1]; - temp = this->m_Parser->GetOption( "rigid-affine" )->GetValue(); - std::string temp2 = this->m_Parser->GetOption( "do-rigid" )->GetValue(); + temp = this->m_Parser->GetOption( "rigid-affine" )->GetFunction( 0 )->GetName(); + std::string temp2 = this->m_Parser->GetOption( "do-rigid" )->GetFunction( 0 )->GetName(); affine_opt.is_rigid = ( ( temp == "true" ) || ( temp2 == "true" ) || ( temp == "1" ) || ( temp2 == "1" ) ); - temp = this->m_Parser->GetOption( "affine-gradient-descent-option" )->GetValue(); + temp = this->m_Parser->GetOption( "affine-gradient-descent-option" )->GetFunction( 0 )->GetName(); std::vector gradient_option = this->m_Parser->template ConvertVector(temp); affine_opt.maximum_step_length = gradient_option[0]; affine_opt.relaxation_factor = gradient_option[1]; affine_opt.minimum_step_length = gradient_option[2]; affine_opt.translation_scales = gradient_option[3]; // ::ants::antscout << affine_opt; - temp = this->m_Parser->GetOption( "use-rotation-header" )->GetValue(); + temp = this->m_Parser->GetOption( "use-rotation-header" )->GetFunction( 0 )->GetName(); affine_opt.use_rotation_header = (temp == "true"); ::ants::antscout << "affine_opt.use_rotation_header = " << affine_opt.use_rotation_header << std::endl; - temp = this->m_Parser->GetOption( "ignore-void-origin")->GetValue(); + temp = this->m_Parser->GetOption( "ignore-void-origin")->GetFunction( 0 )->GetName(); affine_opt.ignore_void_orgin = (temp == "true"); ::ants::antscout << "affine_opt.ignore_void_orgin = " << affine_opt.ignore_void_orgin << std::endl; } @@ -386,15 +388,15 @@ PICSLAdvancedNormalizationToolKit typedef ImageFileReader ReaderType; bool useHistMatch = this->m_Parser->template Convert( this->m_Parser->GetOption( - "use-Histogram-Matching" )->GetValue() ); + "use-Histogram-Matching" )->GetFunction()->GetName() ); /** * Read the metrics and image files */ if( typename OptionType::Pointer option = this->m_Parser->GetOption( "image-metric" ) ) { - ::ants::antscout << " values " << option->GetNumberOfValues() << std::endl; - for( unsigned int i = 0; i < option->GetNumberOfValues(); i++ ) + ::ants::antscout << " values " << option->GetNumberOfFunctions() << std::endl; + for( unsigned int i = 0; i < option->GetNumberOfFunctions(); i++ ) { SimilarityMetricPointer similarityMetric = SimilarityMetricType::New(); RealType similarityMetricScalarWeight = 1.0; @@ -403,7 +405,7 @@ PICSLAdvancedNormalizationToolKit unsigned int parameterCount = 0; typename ReaderType::Pointer fixedImageFileReader = ReaderType::New(); - fixedImageFileReader->SetFileName( option->GetParameter( i, parameterCount ) ); + fixedImageFileReader->SetFileName( option->GetFunction( i )->GetParameter( parameterCount ) ); fixedImageFileReader->Update(); ImagePointer fixedImage = this->PreprocessImage( fixedImageFileReader->GetOutput() ); @@ -414,7 +416,7 @@ PICSLAdvancedNormalizationToolKit << fixedImageFileReader->GetFileName() << std::endl; typename ReaderType::Pointer movingImageFileReader = ReaderType::New(); - movingImageFileReader->SetFileName( option->GetParameter( i, parameterCount ) ); + movingImageFileReader->SetFileName( option->GetFunction( i )->GetParameter( parameterCount ) ); movingImageFileReader->Update(); ImagePointer movingImage = this->PreprocessImage( movingImageFileReader->GetOutput() ); @@ -442,7 +444,7 @@ PICSLAdvancedNormalizationToolKit bool isMetricPointSetBased = false; - typename OptionType::ValueType whichMetric = option->GetValue( i ); + std::string whichMetric = option->GetFunction( i )->GetName(); if( whichMetric == "point-set-expectation" || whichMetric == "PointSetExpectation" || @@ -458,7 +460,7 @@ PICSLAdvancedNormalizationToolKit if( isMetricPointSetBased ) { ::ants::antscout << "Metric " << i << ": " << " Point-set " << whichMetric << " n-params " - << option->GetNumberOfParameters( i ) << std::endl; + << option->GetFunction( i )->GetNumberOfParameters() << std::endl; /** * Read in the point-set metric parameters */ @@ -468,19 +470,19 @@ PICSLAdvancedNormalizationToolKit typename PointSetReaderType::Pointer fixedPointSetReader = PointSetReaderType::New(); fixedPointSetReader->SetFileName( - option->GetParameter( i, parameterCount ) ); + option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; typename PointSetReaderType::Pointer movingPointSetReader = PointSetReaderType::New(); movingPointSetReader->SetFileName( - option->GetParameter( i, parameterCount ) ); + option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { similarityMetricScalarWeight = this->m_Parser->template - Convert( option->GetParameter( i, parameterCount ) ); + Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; } similarityMetric->SetWeightScalar( similarityMetricScalarWeight ); @@ -491,28 +493,28 @@ PICSLAdvancedNormalizationToolKit TReal pointSetSigma = 5.0; bool extractBoundaryPointsOnly = false; unsigned int kNeighborhood = 50; - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { pointSetPercent = this->m_Parser->template - Convert( option->GetParameter( i, parameterCount ) ); + Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; } - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { pointSetSigma = this->m_Parser->template - Convert( option->GetParameter( i, parameterCount ) ); + Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; } - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { extractBoundaryPointsOnly = this->m_Parser->template - Convert( option->GetParameter( i, parameterCount ) ); + Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; } - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { kNeighborhood = this->m_Parser->template - Convert( option->GetParameter( i, parameterCount ) ); + Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; } ::ants::antscout << " point-set sigma = " << pointSetSigma << std::endl; @@ -571,10 +573,10 @@ PICSLAdvancedNormalizationToolKit metric->SetMovingPointSetSigma( pointSetSigma ); metric->SetKNeighborhood( kNeighborhood ); - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { unsigned int pm = - this->m_Parser->template Convert( option->GetParameter( i, parameterCount ) ); + this->m_Parser->template Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); metric->SetUseSymmetricMatching( pm ); ::ants::antscout << " Symmetric match iterations -- going Asymmeric for the rest " << pm << std::endl; parameterCount++; @@ -601,17 +603,17 @@ PICSLAdvancedNormalizationToolKit // metric->SetFixedEvaluationKNeighborhood( kNeighborhood ); // metric->SetMovingEvaluationKNeighborhood( kNeighborhood ); // -// if ( option->GetNumberOfParameters( i ) > parameterCount ) +// if ( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) // { // metric->SetAlpha( this->m_Parser->template -// Convert( option->GetParameter( i, parameterCount ) ) ); +// Convert( option->GetFunction( i )->GetParameter( parameterCount ) ) ); // parameterCount++; // } -// if ( option->GetNumberOfParameters( i ) > parameterCount ) +// if ( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) // { // typename RegistrationOptimizerType::ArrayType meshResolution; // std::vector resolution = this->m_Parser->template -// ConvertVector( option->GetParameter( i, parameterCount ) ); +// ConvertVector( option->GetFunction( i )->GetParameter( parameterCount ) ); // if ( resolution.size() != TDimension ) // { // itkExceptionMacro( "Mesh resolution does not match image dimension." ); @@ -623,23 +625,23 @@ PICSLAdvancedNormalizationToolKit // metric->SetMeshResolution( meshResolution ); // parameterCount++; // } -// if ( option->GetNumberOfParameters( i ) > parameterCount ) +// if ( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) // { // metric->SetSplineOrder( this->m_Parser->template -// Convert( option->GetParameter( i, parameterCount ) ) ); +// Convert( option->GetFunction( i )->GetParameter( parameterCount ) ) ); // parameterCount++; // } -// if ( option->GetNumberOfParameters( i ) > parameterCount ) +// if ( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) // { // metric->SetNumberOfLevels( this->m_Parser->template -// Convert( option->GetParameter( i, parameterCount ) ) ); +// Convert( option->GetFunction( i )->GetParameter( parameterCount ) ) ); // parameterCount++; // } -// if ( option->GetNumberOfParameters( i ) > parameterCount ) +// if ( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) // { // metric->SetUseAnisotropicCovariances( // this->m_Parser->template Convert( -// option->GetParameter( i, parameterCount ) ) ); +// option->GetFunction( i )->GetParameter( parameterCount ) ) ); // parameterCount++; // } // @@ -672,10 +674,10 @@ PICSLAdvancedNormalizationToolKit similarityMetric->SetFixedPointSet( NULL); similarityMetric->SetMovingPointSet( NULL ); - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { similarityMetricScalarWeight = this->m_Parser->template - Convert( option->GetParameter( i, parameterCount ) ); + Convert( option->GetFunction( i )->GetParameter( parameterCount ) ); parameterCount++; } similarityMetric->SetWeightScalar( similarityMetricScalarWeight ); @@ -683,11 +685,11 @@ PICSLAdvancedNormalizationToolKit << similarityMetricScalarWeight << std::endl; radius.Fill( 0 ); - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { std::vector rad = this->m_Parser->template - ConvertVector( option->GetParameter( i, - parameterCount ) ); + ConvertVector( option->GetFunction( i )->GetParameter( + parameterCount ) ); if( rad.size() == 1 ) { @@ -710,9 +712,10 @@ PICSLAdvancedNormalizationToolKit ::ants::antscout << " Radius: " << radius << std::endl; TReal extraparam = -1.e12; - if( option->GetNumberOfParameters( i ) > parameterCount ) + if( option->GetFunction( i )->GetNumberOfParameters() > parameterCount ) { - extraparam = this->m_Parser->template Convert( option->GetParameter( i, parameterCount ) ); + extraparam = this->m_Parser->template Convert( option->GetFunction( i )->GetParameter( + parameterCount ) ); ::ants::antscout << " Setting Extra Param to : " << extraparam << " often used as a robustness parameter for longitudinal studies " << std::endl; parameterCount++; @@ -1028,7 +1031,7 @@ PICSLAdvancedNormalizationToolKit "TODO/FIXME: the --R sets an ROI option -- it passes a vector of parameters that sets the center and bounding box \n of the region of interest for a sub-field registration. e.g. in 3D the option setting \n -r 10x12x15x50x50x25 \n sets up a bounding box of size 50,50,25 with origin at 10,12,15 in voxel (should this be physical?) coordinates. " ); std::string roidefault = std::string("0"); /** set up a default parameter */ - option->AddValue(roidefault); + option->AddFunction(roidefault); this->m_Parser->AddOption( option ); } @@ -1040,7 +1043,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( "number of levels in multi-resolution optimization -- an integer :: 3 is a common choice " ); std::string nlevdefault = std::string("3"); /** set up a default parameter */ - option->AddValue(nlevdefault); + option->AddFunction(nlevdefault); this->m_Parser->AddOption( option ); } @@ -1052,7 +1055,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( "number of iterations per level -- a 'vector' e.g. : 100x100x20 " ); std::string nitdefault = std::string("10x10x5"); /** set up a default parameter */ - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1072,7 +1075,7 @@ PICSLAdvancedNormalizationToolKit nitdefault = std::string("1x1x1"); } /** set up a default parameter */ - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1153,7 +1156,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( " enable to use weighted sum of all metric terms for convergence computation. By default, only the first metric is used"); std::string zero = std::string( "0" ); - option->AddValue( zero ); + option->AddFunction( zero ); this->m_Parser->AddOption( option ); } @@ -1165,7 +1168,7 @@ PICSLAdvancedNormalizationToolKit option->SetShortName( 'h' ); option->SetDescription( description ); std::string zero = std::string( "0" ); - option->AddValue( zero ); + option->AddFunction( zero ); this->m_Parser->AddOption( option ); } @@ -1177,7 +1180,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "help" ); option->SetDescription( description ); std::string zero = std::string( "0" ); - option->AddValue( zero ); + option->AddFunction( zero ); this->m_Parser->AddOption( option ); } @@ -1190,7 +1193,7 @@ PICSLAdvancedNormalizationToolKit "TRANSFORMATION[gradient-step-length,number-of-time-steps,DeltaTime,symmetry-type].\n\t Choose one of the following TRANSFORMATIONS:\n\t\tDiff = diffeomorphic\n\t\tElast = Elastic\n\t\tExp = exponential diff\n\t\t Greedy Exp = greedy exponential diff, like diffeomorphic demons. same parameters. \n\t\tSyN -- symmetric normalization \n \n DeltaTime is the integration time-discretization step - sub-voxel - n-time steps currently fixed at 2 " ); std::string nitdefault = std::string("SyN[0.5]"); /** set up a default parameter */ - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1210,7 +1213,7 @@ PICSLAdvancedNormalizationToolKit // option->SetLongName( "gradient-field-sigma" ); // option->SetShortName( 'g' ); // option->SetDescription( "this smooths the gradient update field" ); -// option->AddValue("0.0"); +// option->AddFunction("0.0"); // this->m_Parser->AddOption( option ); // } // @@ -1220,7 +1223,7 @@ PICSLAdvancedNormalizationToolKit // option->SetLongName( "gradient-step-length" ); // option->SetShortName( 'l' ); // option->SetDescription( "gradient descent parameter - a TReal :: e.g. 1.0 " ); -// option->AddValue("1.0"); +// option->AddFunction("1.0"); // this->m_Parser->AddOption( option ); // } @@ -1233,7 +1236,7 @@ PICSLAdvancedNormalizationToolKit "REGULARIZATION[gradient-field-sigma,def-field-sigma,truncation].\n\t Choose one of the following REGULARIZATIONS:\n\t\tGauss = gaussian\n\t\tDMFFD = directly manipulated free form deformation" ); std::string nitdefault = std::string("Gauss[3,0.5]"); /** set up a default parameter */ - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1282,7 +1285,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( " true / false -- if true, SyN is faster but loses some accuracy wrt inverse-identity constraint, see Avants MIA 2008."); std::string nitdefault = std::string("false"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1293,7 +1296,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "continue-affine"); option->SetDescription( "true (default) | false, do (not) perform affine given the initial affine parameters"); std::string nitdefault = std::string("true"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1305,7 +1308,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "number-of-affine-iterations" ); option->SetDescription( "number of iterations per level -- a 'vector' e.g. : 100x100x20 " ); std::string nitdefault = std::string("10000x10000x10000"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } if( true ) @@ -1314,7 +1317,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "use-NN" ); option->SetDescription( "use nearest neighbor interpolation " ); std::string nitdefault = std::string("0"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } if( true ) @@ -1323,7 +1326,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "use-Histogram-Matching" ); option->SetDescription( "use histogram matching of moving to fixed image " ); std::string nitdefault = std::string("0"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1334,7 +1337,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( "MI: mutual information (default), MSQ: mean square error, SSD, CC: Normalized correlation, CCH: Histogram-based correlation coefficient (not recommended), GD: gradient difference (not recommended) " ); std::string nitdefault = std::string("MI"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1348,17 +1351,17 @@ PICSLAdvancedNormalizationToolKit { case 2: { - option->AddValue(std::string("32x5000") ); + option->AddFunction(std::string("32x5000") ); } break; case 3: { - option->AddValue(std::string("32x32000") ); + option->AddFunction(std::string("32x32000") ); } break; } // std::string nitdefault=std::string("32x8000"); - // option->AddValue(nitdefault); + // option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1368,7 +1371,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "rigid-affine" ); option->SetDescription( "use rigid transformation : true / false(default)" ); std::string nitdefault = std::string("false"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } if( true ) @@ -1377,7 +1380,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "do-rigid" ); option->SetDescription( "use rigid transformation : true / false(default)" ); std::string nitdefault = std::string("false"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1388,7 +1391,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( "option of gradient descent in affine transformation: maximum_step_length x relaxation_factor x minimum_step_length x translation_scales "); std::string nitdefault = std::string("0.1x0.5x1.e-4x1.e-4"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1398,7 +1401,7 @@ PICSLAdvancedNormalizationToolKit option->SetLongName( "use-rotation-header" ); option->SetDescription( "use rotation matrix in image headers: true (default) / false" ); std::string nitdefault = std::string("false"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1409,7 +1412,7 @@ PICSLAdvancedNormalizationToolKit option->SetDescription( "ignore the apparently unmatched origins (when use-rotation-header is false and the rotation matrix is identity: true (default) / false" ); std::string nitdefault = std::string("false"); - option->AddValue(nitdefault); + option->AddFunction(nitdefault); this->m_Parser->AddOption( option ); } @@ -1423,12 +1426,12 @@ PICSLAdvancedNormalizationToolKit + std::string( "both fixed and moving images for each resolution " ) + std::string( "level." ); - std::string defaultValue = std::string( "" ); + std::string defaultFunction = std::string( "" ); OptionType::Pointer option = OptionType::New(); option->SetLongName( "gaussian-smoothing-sigmas" ); option->SetDescription( description ); - option->AddValue( defaultValue ); + option->AddFunction( defaultFunction ); this->m_Parser->AddOption( option ); } @@ -1442,12 +1445,12 @@ PICSLAdvancedNormalizationToolKit + std::string( "both fixed and moving images for each resolution " ) + std::string( "level." ); - std::string defaultValue = std::string( "" ); + std::string defaultFunction = std::string( "" ); OptionType::Pointer option = OptionType::New(); option->SetLongName( "subsampling-factors" ); option->SetDescription( description ); - option->AddValue( defaultValue ); + option->AddFunction( defaultFunction ); this->m_Parser->AddOption( option ); } } diff --git a/Utilities/antsCommandLineOption.cxx b/Utilities/antsCommandLineOption.cxx index 1b67bcb8b..6f11e1f0e 100644 --- a/Utilities/antsCommandLineOption.cxx +++ b/Utilities/antsCommandLineOption.cxx @@ -26,54 +26,50 @@ ::CommandLineOption() : m_ShortName( '\0' ), m_LongName( "" ), m_Description( "" ) { - this->m_Values.clear(); + this->m_OptionFunctions.clear(); this->m_UsageOptions.clear(); } void CommandLineOption -::AddValue( std::string value, char leftDelimiter, char rightDelimiter ) +::AddFunction( std::string functionString, char leftDelimiter, char rightDelimiter, unsigned int order ) { - std::string::size_type leftDelimiterPos = value.find( leftDelimiter ); - std::string::size_type rightDelimiterPos = value.find( rightDelimiter ); + OptionFunctionType::Pointer optionFunction = OptionFunctionType::New(); + + optionFunction->SetArgOrder( order ); + + std::string::size_type leftDelimiterPos = functionString.find( leftDelimiter ); + std::string::size_type rightDelimiterPos = functionString.find( rightDelimiter ); if( leftDelimiterPos == std::string::npos || rightDelimiterPos == std::string::npos ) { - this->m_Values.push_front( value ); - - ValueStackType parameters; - this->m_Parameters.push_front( parameters ); + optionFunction->SetName( functionString ); + this->m_OptionFunctions.push_front( optionFunction ); } else { - ValueStackType parameters; + OptionFunctionType::ParameterStackType parameters; - this->m_Values.push_front( value.substr( 0, leftDelimiterPos ) ); + optionFunction->SetName( functionString.substr( 0, leftDelimiterPos ) ); std::string::size_type leftPos = leftDelimiterPos; - std::string::size_type rightPos = value.find( ',', leftPos + 1 ); + std::string::size_type rightPos = functionString.find( ',', leftPos + 1 ); while( rightPos != std::string::npos ) { - parameters.push_back( value.substr( leftPos + 1, rightPos - leftPos - 1 ) ); + parameters.push_back( functionString.substr( leftPos + 1, rightPos - leftPos - 1 ) ); leftPos = rightPos; - rightPos = value.find( ',', leftPos + 1 ); + rightPos = functionString.find( ',', leftPos + 1 ); } rightPos = rightDelimiterPos; - parameters.push_back( value.substr( leftPos + 1, rightPos - leftPos - 1 ) ); + parameters.push_back( functionString.substr( leftPos + 1, rightPos - leftPos - 1 ) ); - this->m_Parameters.push_front( parameters ); - } + optionFunction->SetParameters( parameters ); - this->Modified(); -} + this->m_OptionFunctions.push_front( optionFunction ); + } -void -CommandLineOption -::SetValue( unsigned int i, std::string value ) -{ - this->m_Values[i] = value; this->Modified(); } diff --git a/Utilities/antsCommandLineOption.h b/Utilities/antsCommandLineOption.h index 2b1a6fe3a..709c56fbb 100644 --- a/Utilities/antsCommandLineOption.h +++ b/Utilities/antsCommandLineOption.h @@ -47,11 +47,21 @@ namespace ants -m mutualinformation[parameter1] --optimization gradientdescent" */ -class ITK_EXPORT CommandLineOption +class ITK_EXPORT OptionFunction : public DataObject { public: - typedef CommandLineOption Self; + OptionFunction() : + m_Name( "" ), + m_ArgOrder( 0 ), + m_WhichStage( 0 ) + { + }; + ~OptionFunction() + { + }; + + typedef OptionFunction Self; typedef DataObject Superclass; typedef SmartPointer Pointer; @@ -59,114 +69,130 @@ class ITK_EXPORT CommandLineOption itkTypeMacro( Option, DataObject ); - typedef std::string ValueType; - typedef std::deque ValueStackType; - typedef std::deque ParameterStackType; + typedef std::deque ParameterStackType; + + itkSetMacro( Name, std::string ); + itkGetConstMacro( Name, std::string ); - ValueStackType GetValues() + itkSetMacro( ArgOrder, unsigned int ); + itkGetConstMacro( ArgOrder, unsigned int ); + + itkSetMacro( WhichStage, unsigned int ); + itkGetConstMacro( WhichStage, unsigned int ); + + ParameterStackType GetParameters() { - return this->m_Values; + return this->m_Parameters; } - unsigned int GetNumberOfValues() + void SetParameters( ParameterStackType parameters ) { - return this->m_Values.size(); + this->m_Parameters = parameters; + this->Modified(); } - std::string GetValue( unsigned int i = 0 ) + std::string GetParameter( unsigned int i = 0 ) { - if( i < this->m_Values.size() ) + if( i < this->m_Parameters.size() ) { - return this->m_Values[i]; + return this->m_Parameters[i]; } else { - return std::string( "" ); + std::string empty( "" ); + return empty; } } - ValueStackType GetUsageOptions() + unsigned int GetNumberOfParameters() { - return this->m_UsageOptions; + return this->m_Parameters.size(); } - unsigned int GetNumberOfUsageOptions() +private: + std::string m_Name; + unsigned int m_ArgOrder; + unsigned int m_WhichStage; + ParameterStackType m_Parameters; +}; + +class ITK_EXPORT CommandLineOption + : public DataObject +{ +public: + typedef CommandLineOption Self; + typedef DataObject Superclass; + typedef SmartPointer Pointer; + + itkNewMacro( Self ); + + itkTypeMacro( Option, DataObject ); + + typedef OptionFunction OptionFunctionType; + + typedef std::deque FunctionStackType; + typedef std::deque UsageOptionStackType; + + FunctionStackType GetFunctions() { - return this->m_UsageOptions.size(); + return this->m_OptionFunctions; } - std::string GetUsageOption( unsigned int i = 0 ) + unsigned int GetNumberOfFunctions() { - if( i < this->m_UsageOptions.size() ) - { - return this->m_UsageOptions[i]; - } - else - { - return std::string( "" ); - } + return this->m_OptionFunctions.size(); } - ValueStackType GetParameters( unsigned int i = 0 ) + OptionFunction::Pointer GetFunction( unsigned int i = 0 ) { - if( i < this->m_Parameters.size() ) + if( i < this->m_OptionFunctions.size() ) { - return this->m_Parameters[i]; + return this->m_OptionFunctions[i]; } else { - ValueStackType empty; - return empty; + return NULL; } } - std::string GetParameter( unsigned int i, unsigned int j ) + UsageOptionStackType GetUsageOptions() { - if( i < this->m_Parameters.size() && j < this->m_Parameters[i].size() ) - { - return this->m_Parameters[i][j]; - } - else - { - return std::string( "" ); - } + return this->m_UsageOptions; } - std::string GetParameter( unsigned int j ) + unsigned int GetNumberOfUsageOptions() { - return this->GetParameter( 0, j ); + return this->m_UsageOptions.size(); } - unsigned int GetNumberOfParameters( unsigned int i = 0 ) + std::string GetUsageOption( unsigned int i = 0 ) { - if( i < this->m_Parameters.size() ) + if( i < this->m_UsageOptions.size() ) { - return this->m_Parameters[i].size(); + return this->m_UsageOptions[i]; } else { - return 0; + return std::string( "" ); } } itkSetMacro( ShortName, char ); - itkGetMacro( ShortName, char ); + itkGetConstMacro( ShortName, char ); itkSetMacro( LongName, std::string ); - itkGetMacro( LongName, std::string ); + itkGetConstMacro( LongName, std::string ); itkSetMacro( Description, std::string ); - itkGetMacro( Description, std::string ); + itkGetConstMacro( Description, std::string ); - void AddValue( std::string, char, char ); + void AddFunction( std::string, char, char, unsigned int order = 0 ); - void AddValue( std::string s ) + void AddFunction( std::string s ) { - this->AddValue( s, '[', ']' ); + this->AddFunction( s, '[', ']' ); } - void SetValue( unsigned int, std::string ); - void SetUsageOption( unsigned int, std::string ); protected: @@ -175,12 +201,11 @@ class ITK_EXPORT CommandLineOption { }; private: - char m_ShortName; - std::string m_LongName; - std::string m_Description; - ValueStackType m_UsageOptions; - ValueStackType m_Values; - ParameterStackType m_Parameters; + char m_ShortName; + std::string m_LongName; + std::string m_Description; + UsageOptionStackType m_UsageOptions; + FunctionStackType m_OptionFunctions; }; } // end namespace ants } // end namespace itk diff --git a/Utilities/antsCommandLineParser.cxx b/Utilities/antsCommandLineParser.cxx index dc5d0888c..3813b75ae 100644 --- a/Utilities/antsCommandLineParser.cxx +++ b/Utilities/antsCommandLineParser.cxx @@ -70,6 +70,7 @@ ::Parse( unsigned int argc, char * *argv ) this->RegroupCommandLineArguments( argc, argv ); unsigned int n = 0; + unsigned int order = 0; this->m_Command = arguments[n++]; @@ -104,25 +105,25 @@ ::Parse( unsigned int argc, char * *argv ) } if( n == arguments.size() ) { - unknownOption->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); + unknownOption->AddFunction( "1", + this->m_LeftDelimiter, this->m_RightDelimiter, order++ ); } else { for( unsigned int m = n; m < arguments.size(); m++ ) { - std::string value = arguments[m]; - if( value.find( "-" ) != 0 ) + std::string function = arguments[m]; + if( function.find( "-" ) != 0 ) { - unknownOption->AddValue( value, - this->m_LeftDelimiter, this->m_RightDelimiter ); + unknownOption->AddFunction( function, + this->m_LeftDelimiter, this->m_RightDelimiter, order++ ); } else { if( m == n ) { - unknownOption->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); + unknownOption->AddFunction( "1", + this->m_LeftDelimiter, this->m_RightDelimiter, order++ ); } n = m; break; @@ -135,25 +136,25 @@ ::Parse( unsigned int argc, char * *argv ) { if( n == arguments.size() ) { - option->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); + option->AddFunction( "1", + this->m_LeftDelimiter, this->m_RightDelimiter, order++ ); } else { for( unsigned int m = n; m < arguments.size(); m++ ) { - std::string value = arguments[m]; - if( value.find( "-" ) != 0 || atof( value.c_str() ) ) + std::string function = arguments[m]; + if( function.find( "-" ) != 0 || atof( function.c_str() ) ) { - option->AddValue( value, - this->m_LeftDelimiter, this->m_RightDelimiter ); + option->AddFunction( function, + this->m_LeftDelimiter, this->m_RightDelimiter, order++ ); } else { if( m == n ) { - option->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); + option->AddFunction( "1", + this->m_LeftDelimiter, this->m_RightDelimiter, order++ ); } n = m; break; @@ -163,6 +164,8 @@ ::Parse( unsigned int argc, char * *argv ) } } } + + this->AssignStages(); } std::vector @@ -371,58 +374,56 @@ ::PrintMenu( std::ostream& os, Indent indent, bool printShortVersion ) const std::stringstream ss2; ss2 << (*it)->GetDescription(); - std::string description = this->BreakUpStringIntoNewLines( - ss2.str(), ss1.str(), 80 ); + std::string description = this->BreakUpStringIntoNewLines( ss2.str(), ss1.str(), 80 ); os << indent << indent << description << std::endl; } if( !printShortVersion ) { - if( (*it)->GetValues().size() == 1 ) + if( (*it)->GetFunctions().size() == 1 ) { - os << indent << indent << ": " << (*it)->GetValue( 0 ); - if( (*it)->GetParameters( 0 ).size() > 0 ) + os << indent << indent << ": " << (*it)->GetFunction( 0 )->GetName(); + if( (*it)->GetFunction( 0 )->GetParameters().size() > 0 ) { os << "["; - if( (*it)->GetParameters( 0 ).size() == 1 ) + if( (*it)->GetFunction( 0 )->GetParameters().size() == 1 ) { - os << (*it)->GetParameter( 0, 0 ); + os << (*it)->GetFunction( 0 )->GetParameter( 0 ); } else { - for( unsigned int i = 0; - i < (*it)->GetParameters( 0 ).size() - 1; i++ ) + for( unsigned int i = 0; i < (*it)->GetFunction( 0 )->GetParameters().size() - 1; i++ ) { - os << (*it)->GetParameter( 0, i ) << ","; + os << (*it)->GetFunction( 0 )->GetParameter( i ) << ","; } - os << (*it)->GetParameter( 0, (*it)->GetParameters( 0 ).size() - 1 ); + os << (*it)->GetFunction( 0 )->GetParameter( (*it)->GetFunction( 0 )->GetParameters().size() - 1 ); } os << "]"; } os << std::endl; } - else if( (*it)->GetValues().size() > 1 ) + else if( (*it)->GetFunctions().size() > 1 ) { os << indent << indent << ": "; - for( unsigned int n = 0; n < (*it)->GetValues().size() - 1; n++ ) + for( unsigned int n = 0; n < (*it)->GetFunctions().size() - 1; n++ ) { - os << (*it)->GetValue( n ); - if( (*it)->GetParameters( n ).size() > 0 ) + os << (*it)->GetFunction( n )->GetName(); + if( (*it)->GetFunction( n )->GetParameters().size() > 0 ) { os << "["; - if( (*it)->GetParameters( n ).size() == 1 ) + if( (*it)->GetFunction( n )->GetParameters().size() == 1 ) { - os << (*it)->GetParameter( n, 0 ) << "], "; + os << (*it)->GetFunction( n )->GetParameter( 0 ) << "], "; } else { - for( unsigned int i = 0; - i < (*it)->GetParameters( n ).size() - 1; i++ ) + for( unsigned int i = 0; i < (*it)->GetFunction( n )->GetParameters().size() - 1; i++ ) { - os << (*it)->GetParameter( n, i ) << ","; + os << (*it)->GetFunction( n )->GetParameter( i ) << ","; } - os << (*it)->GetParameter( n, - (*it)->GetParameters( n ).size() - 1 ) << "], "; + os + << (*it)->GetFunction( n )->GetParameter( (*it)->GetFunction( n )->GetParameters().size() + - 1 ) << "], "; } } else @@ -431,25 +432,23 @@ ::PrintMenu( std::ostream& os, Indent indent, bool printShortVersion ) const } } - unsigned int nn = (*it)->GetValues().size() - 1; + unsigned int nn = (*it)->GetFunctions().size() - 1; - os << (*it)->GetValue( nn ); - if( (*it)->GetParameters( nn ).size() > 0 ) + os << (*it)->GetFunction( nn )->GetName(); + if( (*it)->GetFunction( nn )->GetParameters().size() > 0 ) { os << "["; - if( (*it)->GetParameters( nn ).size() == 1 ) + if( (*it)->GetFunction( nn )->GetParameters().size() == 1 ) { - os << (*it)->GetParameter( nn, 0 ) << "]"; + os << (*it)->GetFunction( nn )->GetParameter( 0 ) << "]"; } else { - for( unsigned int i = 0; - i < (*it)->GetParameters( nn ).size() - 1; i++ ) + for( unsigned int i = 0; i < (*it)->GetFunction( nn )->GetParameters().size() - 1; i++ ) { - os << (*it)->GetParameter( nn, i ) << ","; + os << (*it)->GetFunction( nn )->GetParameter( i ) << ","; } - os << (*it)->GetParameter( nn, - (*it)->GetParameters( nn ).size() - 1 ) << "]"; + os << (*it)->GetFunction( nn )->GetParameter( (*it)->GetFunction( nn )->GetParameters().size() - 1 ) << "]"; } } } @@ -517,6 +516,45 @@ ::TokenizeString( std::string str, std::vector & tokens, } } +void +CommandLineParser +::AssignStages() +{ + OptionListType::const_iterator it; + + for( it = this->m_Options.begin(); it != this->m_Options.end(); it++ ) + { + typedef OptionType::FunctionStackType OptionFunctionStackType; + OptionFunctionStackType functions = (*it)->GetFunctions(); + + OptionFunctionStackType::const_iterator it2; + + unsigned int previousOrder = 0; + unsigned int currentOrder = 0; + for( it2 = functions.begin(); it2 != functions.end(); it2++ ) + { + if( it2 == functions.begin() ) + { + previousOrder = (*it2)->GetArgOrder(); + (*it2)->SetWhichStage( 0 ); + } + else + { + currentOrder = (*it2)->GetArgOrder(); + if( previousOrder == currentOrder + 1 ) + { + (*it2)->SetWhichStage( functions[it2 - functions.begin() - 1]->GetWhichStage() ); + } + else + { + (*it2)->SetWhichStage( functions[it2 - functions.begin() - 1]->GetWhichStage() + 1 ); + } + previousOrder = currentOrder; + } + } + } +} + /** * Standard "PrintSelf" method */ diff --git a/Utilities/antsCommandLineParser.h b/Utilities/antsCommandLineParser.h index 8973adb89..9b10be1c9 100644 --- a/Utilities/antsCommandLineParser.h +++ b/Utilities/antsCommandLineParser.h @@ -93,6 +93,14 @@ class ITK_EXPORT CommandLineParser return this->m_UnknownOptions; } + /** + * This feature is designed for a more advanced command line usage + * where multiple option values are used per stage (e.g. + * antsRegistration). Multiple option value are considered to be of + * the same stage if they are situated adjacently on the command line. + */ + void AssignStages(); + template TValue Convert( std::string optionString ) {