diff --git a/Examples/ANTSConformalMapping.cxx b/Examples/ANTSConformalMapping.cxx index 932590b83..2e06bf505 100644 --- a/Examples/ANTSConformalMapping.cxx +++ b/Examples/ANTSConformalMapping.cxx @@ -1,5 +1,4 @@ -#include "itkCommandLineOption.h" -#include "itkCommandLineParser.h" +#include "antsCommandLineParser.h" #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" @@ -56,9 +55,9 @@ class CommandIterationUpdate : public itk::Command } }; -void InitializeCommandLineOptions( itk::CommandLineParser *parser ) +void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) { - typedef itk::CommandLineParser::OptionType OptionType; + typedef itk::ants::CommandLineParser::OptionType OptionType; { std::string description = @@ -191,7 +190,7 @@ void InitializeCommandLineOptions( itk::CommandLineParser *parser ) } template -int ANTSConformalMapping( itk::CommandLineParser *parser ) +int ANTSConformalMapping( itk::ants::CommandLineParser *parser ) { typedef float PixelType; typedef float RealType; @@ -212,7 +211,7 @@ int ANTSConformalMapping( itk::CommandLineParser *parser ) // first find out if the user wants to inflate the mesh ... unsigned int inflate_iterations = 0; float inflate_param = 0; - typename itk::CommandLineParser::OptionType::Pointer infOption = + typename itk::ants::CommandLineParser::OptionType::Pointer infOption = parser->GetOption( "inflate" ); if( infOption && infOption->GetNumberOfValues() > 0 ) { @@ -232,7 +231,7 @@ int ANTSConformalMapping( itk::CommandLineParser *parser ) } float maxCost = 40, distCostW = 1, labelCostW = 0; - typename itk::CommandLineParser::OptionType::Pointer costOption = + typename itk::ants::CommandLineParser::OptionType::Pointer costOption = parser->GetOption( "segmentation-cost" ); if( costOption && costOption->GetNumberOfValues() > 0 ) { @@ -250,7 +249,7 @@ int ANTSConformalMapping( itk::CommandLineParser *parser ) } } - typename itk::CommandLineParser::OptionType::Pointer displayOption = parser->GetOption( "display-mesh" ); + typename itk::ants::CommandLineParser::OptionType::Pointer displayOption = parser->GetOption( "display-mesh" ); if( displayOption && displayOption->GetNumberOfValues() > 0 ) { if( displayOption->GetNumberOfParameters() > 0 ) @@ -299,7 +298,7 @@ int ANTSConformalMapping( itk::CommandLineParser *parser ) /** * Initialization */ - typename itk::CommandLineParser::OptionType::Pointer inOption = + typename itk::ants::CommandLineParser::OptionType::Pointer inOption = parser->GetOption( "input-mesh" ); if( inOption && inOption->GetNumberOfParameters() == 2 ) { @@ -394,7 +393,7 @@ int ANTSConformalMapping( itk::CommandLineParser *parser ) /** * output */ - typename itk::CommandLineParser::OptionType::Pointer outputOption = + typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); if( outputOption && outputOption->GetNumberOfValues() > 0 ) { @@ -455,7 +454,7 @@ int main( int argc, char *argv[] ) exit( 1 ); } - itk::CommandLineParser::Pointer parser = itk::CommandLineParser::New(); + itk::ants::CommandLineParser::Pointer parser = itk::ants::CommandLineParser::New(); parser->SetCommand( argv[0] ); std::string commandDescription = diff --git a/Examples/Atropos.cxx b/Examples/Atropos.cxx index 750a6532d..044befb1d 100644 --- a/Examples/Atropos.cxx +++ b/Examples/Atropos.cxx @@ -1,22 +1,23 @@ -#include "itkAtroposSegmentationImageFilter.h" -#include "itkBoxPlotQuantileListSampleFilter.h" -#include "itkCommandLineOption.h" -#include "itkCommandLineParser.h" -#include "itkGaussianListSampleFunction.h" -#include "itkGrubbsRosnerListSampleFilter.h" -#include "itkHistogramParzenWindowsListSampleFunction.h" #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkImageRegionIterator.h" -#include "itkListSampleToListSampleFilter.h" -#include "itkManifoldParzenWindowsListSampleFunction.h" #include "itkMaskImageFilter.h" #include "itkNumericSeriesFileNames.h" -#include "itkPassThroughListSampleFilter.h" #include "itkVectorImage.h" #include "itkVectorIndexSelectionCastImageFilter.h" +#include "antsAtroposSegmentationImageFilter.h" +#include "antsBoxPlotQuantileListSampleFilter.h" +#include "antsCommandLineOption.h" +#include "antsCommandLineParser.h" +#include "antsGaussianListSampleFunction.h" +#include "antsGrubbsRosnerListSampleFilter.h" +#include "antsHistogramParzenWindowsListSampleFunction.h" +#include "antsListSampleToListSampleFilter.h" +#include "antsManifoldParzenWindowsListSampleFunction.h" +#include "antsPassThroughListSampleFilter.h" + #include #include #include @@ -67,7 +68,7 @@ void ConvertToLowerCase( std::string& str ) } template -int AtroposSegmentation( itk::CommandLineParser *parser ) +int AtroposSegmentation( itk::ants::CommandLineParser *parser ) { typedef float PixelType; typedef float RealType; @@ -76,7 +77,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) typedef unsigned char LabelType; typedef itk::Image LabelImageType; - typedef itk::AtroposSegmentationImageFilter + typedef itk::ants::AtroposSegmentationImageFilter SegmentationFilterType; typename SegmentationFilterType::Pointer segmenter = SegmentationFilterType::New(); @@ -89,7 +90,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * Initialization */ - typename itk::CommandLineParser::OptionType::Pointer initializationOption = + typename itk::ants::CommandLineParser::OptionType::Pointer initializationOption = parser->GetOption( "initialization" ); if( initializationOption && initializationOption->GetNumberOfParameters() < 1 ) @@ -214,7 +215,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * convergence options */ - typename itk::CommandLineParser::OptionType::Pointer convergenceOption = + typename itk::ants::CommandLineParser::OptionType::Pointer convergenceOption = parser->GetOption( "convergence" ); if( convergenceOption ) { @@ -233,7 +234,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * Mask image */ - typename itk::CommandLineParser::OptionType::Pointer maskOption = + typename itk::ants::CommandLineParser::OptionType::Pointer maskOption = parser->GetOption( "mask-image" ); if( maskOption && maskOption->GetNumberOfValues() > 0 ) { @@ -255,7 +256,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) * BSpline options */ - typename itk::CommandLineParser::OptionType::Pointer bsplineOption = + typename itk::ants::CommandLineParser::OptionType::Pointer bsplineOption = parser->GetOption( "bspline" ); if( bsplineOption && bsplineOption->GetNumberOfValues() ) { @@ -316,7 +317,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * labels */ - typename itk::CommandLineParser::OptionType::Pointer labelOption = + typename itk::ants::CommandLineParser::OptionType::Pointer labelOption = parser->GetOption( "labels" ); if( labelOption && labelOption->GetNumberOfValues() > 0 ) { @@ -355,7 +356,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * intensity images */ - typename itk::CommandLineParser::OptionType::Pointer imageOption = + typename itk::ants::CommandLineParser::OptionType::Pointer imageOption = parser->GetOption( "intensity-image" ); if( imageOption && imageOption->GetNumberOfValues() > 0 ) { @@ -410,7 +411,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * MRF options */ - typename itk::CommandLineParser::OptionType::Pointer mrfOption = + typename itk::ants::CommandLineParser::OptionType::Pointer mrfOption = parser->GetOption( "mrf" ); if( mrfOption && mrfOption->GetNumberOfValues() > 0 ) { @@ -448,7 +449,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * euclidean distance */ - typename itk::CommandLineParser::OptionType::Pointer distanceOption = + typename itk::ants::CommandLineParser::OptionType::Pointer distanceOption = parser->GetOption( "use-euclidean-distance" ); if( distanceOption && distanceOption->GetNumberOfValues() > 0 ) { @@ -459,7 +460,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * memory-usage */ - typename itk::CommandLineParser::OptionType::Pointer memoryOption = + typename itk::ants::CommandLineParser::OptionType::Pointer memoryOption = parser->GetOption( "minimize-memory-usage" ); if( memoryOption && memoryOption->GetNumberOfValues() > 0 ) { @@ -470,7 +471,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * likelihood */ - typename itk::CommandLineParser::OptionType::Pointer likelihoodOption = + typename itk::ants::CommandLineParser::OptionType::Pointer likelihoodOption = parser->GetOption( "likelihood-model" ); if( likelihoodOption && likelihoodOption->GetNumberOfValues() > 0 ) { @@ -479,7 +480,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) if( !likelihoodModel.compare( std::string( "gaussian" ) ) ) { typedef typename SegmentationFilterType::SampleType SampleType; - typedef itk::Statistics::GaussianListSampleFunction + typedef itk::ants::Statistics::GaussianListSampleFunction LikelihoodType; for( unsigned int n = 0; n < segmenter->GetNumberOfClasses(); n++ ) { @@ -491,7 +492,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) else if( !likelihoodModel.compare( std::string( "manifoldparzenwindows" ) ) ) { typedef typename SegmentationFilterType::SampleType SampleType; - typedef itk::Statistics::ManifoldParzenWindowsListSampleFunction + typedef itk::ants::Statistics::ManifoldParzenWindowsListSampleFunction LikelihoodType; float regularizationSigma = 1.0; @@ -532,7 +533,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) else if( !likelihoodModel.compare( std::string( "histogramparzenwindows" ) ) ) { typedef typename SegmentationFilterType::SampleType SampleType; - typedef itk::Statistics::HistogramParzenWindowsListSampleFunction + typedef itk::ants::Statistics::HistogramParzenWindowsListSampleFunction LikelihoodType; float sigma = 1.0; @@ -566,7 +567,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * outliers? */ - typename itk::CommandLineParser::OptionType::Pointer outlierOption = + typename itk::ants::CommandLineParser::OptionType::Pointer outlierOption = parser->GetOption( "winsorize-outliers" ); if( outlierOption && outlierOption->GetNumberOfValues() > 0 ) { @@ -575,7 +576,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) if( !outlierStrategy.compare( std::string( "boxplot" ) ) ) { typedef typename SegmentationFilterType::SampleType SampleType; - typedef itk::Statistics::BoxPlotQuantileListSampleFilter + typedef itk::ants::Statistics::BoxPlotQuantileListSampleFilter SampleFilterType; typename SampleFilterType::Pointer boxplotFilter = SampleFilterType::New(); @@ -600,7 +601,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) else if( !outlierStrategy.compare( std::string( "grubbsrosner" ) ) ) { typedef typename SegmentationFilterType::SampleType SampleType; - typedef itk::Statistics::GrubbsRosnerListSampleFilter + typedef itk::ants::Statistics::GrubbsRosnerListSampleFilter SampleFilterType; typename SampleFilterType::Pointer grubbsFilter = SampleFilterType::New(); @@ -637,7 +638,7 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) /** * output */ - typename itk::CommandLineParser::OptionType::Pointer outputOption = + typename itk::ants::CommandLineParser::OptionType::Pointer outputOption = parser->GetOption( "output" ); if( outputOption && outputOption->GetNumberOfValues() > 0 ) { @@ -762,9 +763,9 @@ int AtroposSegmentation( itk::CommandLineParser *parser ) return EXIT_SUCCESS; } -void InitializeCommandLineOptions( itk::CommandLineParser *parser ) +void InitializeCommandLineOptions( itk::ants::CommandLineParser *parser ) { - typedef itk::CommandLineParser::OptionType OptionType; + typedef itk::ants::CommandLineParser::OptionType OptionType; { std::string description = @@ -863,7 +864,7 @@ void InitializeCommandLineOptions( itk::CommandLineParser *parser ) + std::string( "less than the specified threshold from the previous " ) + std::string( "iteration the program terminates."); -// std::string( "\t Usage: \n" ) + +// std::string( "\t Usage: \n" ) + // std::string( "\t [,]" ); OptionType::Pointer option = OptionType::New(); @@ -1040,11 +1041,12 @@ int main( int argc, char *argv[] ) if( argc < 2 ) { std::cout << "Usage: " << argv[0] - << " imageDimension args" << std::endl; + << " -h or --help " << std::endl; exit( 1 ); } - itk::CommandLineParser::Pointer parser = itk::CommandLineParser::New(); + itk::ants::CommandLineParser::Pointer parser = + itk::ants::CommandLineParser::New(); parser->SetCommand( argv[0] ); std::string commandDescription = diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index c812fc556..08bf598e7 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -56,7 +56,7 @@ INCLUDE_DIRECTORIES(${PICSL_INCLUDE_DIRS}) LINK_DIRECTORIES( ${ITK_LIBRARY_PATH} ) # non-templated class -- this should be stored in a library and linked in... -SET(UI_SOURCES "../Utilities/itkCommandLineParser" "../Utilities/itkCommandLineOption" ) +SET(UI_SOURCES "../Utilities/antsCommandLineParser" "../Utilities/antsCommandLineOption" ) ADD_EXECUTABLE(ANTS ANTS.cxx ${UI_SOURCES}) TARGET_LINK_LIBRARIES(ANTS ITKCommon ITKBasicFilters ITKIO ITKNumerics ITKStatistics ITKFEM ) diff --git a/ImageRegistration/itkANTSImageRegistrationOptimizer.h b/ImageRegistration/itkANTSImageRegistrationOptimizer.h index 2bd504058..bf7867eaf 100644 --- a/ImageRegistration/itkANTSImageRegistrationOptimizer.h +++ b/ImageRegistration/itkANTSImageRegistrationOptimizer.h @@ -21,7 +21,7 @@ #include "itkObject.h" #include "itkObjectFactory.h" #include "itkVectorGaussianInterpolateImageFunction.h" -#include "itkCommandLineParser.h" +#include "antsCommandLineParser.h" #include "itkShiftScaleImageFilter.h" #include "itkMinimumMaximumImageFilter.h" #include "itkImage.h" @@ -105,7 +105,7 @@ class ITK_EXPORT ANTSImageRegistrationOptimizer float> VelocityFieldInterpolatorType2; typedef typename DeformationFieldType::IndexType IndexType; - typedef CommandLineParser ParserType; + typedef ants::CommandLineParser ParserType; typedef typename ParserType::OptionType OptionType; typedef GeneralToBSplineDeformationFieldFilter BSplineFilterType; diff --git a/ImageRegistration/itkANTSImageTransformation.h b/ImageRegistration/itkANTSImageTransformation.h index b24432d29..221ceb10b 100644 --- a/ImageRegistration/itkANTSImageTransformation.h +++ b/ImageRegistration/itkANTSImageTransformation.h @@ -21,7 +21,7 @@ #include "itkObject.h" #include "itkObjectFactory.h" -#include "itkCommandLineParser.h" +#include "antsCommandLineParser.h" #include "itkImage.h" #include "itkMacro.h" @@ -33,7 +33,6 @@ #include "itkCenteredTransformInitializer.h" #include "itkTransformFileReader.h" #include "itkTransformFileWriter.h" - namespace itk { template @@ -70,8 +69,8 @@ class ITK_EXPORT ANTSImageTransformation typedef typename DeformationFieldType::SizeType DeformationRegionOfInterestSizeType; typedef typename DeformationFieldType::PointType DeformationRegionOfInterestCenterType; - typedef CommandLineParser ParserType; - typedef typename ParserType::OptionType OptionType; + typedef typename ants::CommandLineParser ParserType; + typedef typename ParserType::OptionType OptionType; /** Set functions */ void SetDeformationRegionOfInterest( DeformationRegionOfInterestCenterType DRC, diff --git a/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.h b/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.h index 668c82e29..7f0cdd4ae 100644 --- a/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.h +++ b/ImageRegistration/itkPICSLAdvancedNormalizationToolKit.h @@ -24,7 +24,7 @@ #include "itkANTSImageTransformation.h" #include "itkANTSImageRegistrationOptimizer.h" #include "itkANTSSimilarityMetric.h" -#include "itkCommandLineParser.h" +#include "antsCommandLineParser.h" #include "itkImage.h" #include "itkMacro.h" #include "itkANTSLabeledPointSet.h" @@ -74,7 +74,7 @@ class ITK_EXPORT PICSLAdvancedNormalizationToolKit typedef std::vector SimilarityMetricListType; typedef typename SimilarityMetricType::MetricType MetricBaseType; - typedef CommandLineParser ParserType; + typedef ants::CommandLineParser ParserType; typedef typename ParserType::OptionType OptionType; void ParseCommandLine( int argc, char * *argv ); diff --git a/ImageSegmentation/itkAtroposSegmentationImageFilter.h b/ImageSegmentation/itkAtroposSegmentationImageFilter.h deleted file mode 100644 index 0966be5d1..000000000 --- a/ImageSegmentation/itkAtroposSegmentationImageFilter.h +++ /dev/null @@ -1,366 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkAtroposSegmentationImageFilter.h,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkAtroposSegmentationImageFilter_h -#define __itkAtroposSegmentationImageFilter_h - -#include "itkImageToImageFilter.h" - -#include "itkArray.h" -#include "itkBSplineScatteredDataPointSetToImageFilter.h" -#include "itkFixedArray.h" -#include "itkListSample.h" -#include "itkListSampleFunction.h" -#include "itkListSampleToListSampleFilter.h" -#include "itkPointSet.h" -#include "itkVector.h" - -#include -#include -#include -#include - -namespace itk -{ -/** \class AtroposSegmentationImageFilter - * \brief Atropos: A Priori Classification with Registration Initialized - * Template Assistance - * - * This filter provides an Expectation-Maximization framework for statistical - * segmentation where the intensity profile of each class is modeled as a - * mixture model and spatial smoothness is enforced by an MRF prior. - * - * Initial labeling can be performed by otsu thresholding, kmeans clustering, - * a set of user-specified prior probability images, or a prior label image. - * If specified, the latter two initialization options are also used as - * priors in the MRF update step. - * - * The assumed labeling is such that classes are assigned consecutive - * indices 1, 2, 3, etc. Label 0 is reserved for the background when a - * mask is specified. - * - */ - -template ::ImageDimension>, - class TClassifiedImage = TMaskImage> -class ITK_EXPORT AtroposSegmentationImageFilter : - public ImageToImageFilter -{ -public: - /** Standard class typdedefs. */ - typedef AtroposSegmentationImageFilter Self; - typedef ImageToImageFilter Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information (and related methods). */ - itkTypeMacro( AtroposSegmentationImageFilter, ImageToImageFilter ); - - /** Dimension of the images. */ - itkStaticConstMacro( ImageDimension, unsigned int, - TInputImage::ImageDimension ); - itkStaticConstMacro( ClassifiedImageDimension, unsigned int, - TClassifiedImage::ImageDimension ); - itkStaticConstMacro( MaskImageDimension, unsigned int, - TMaskImage::ImageDimension ); - - /** Typedef support of input types. */ - typedef TInputImage ImageType; - typedef typename ImageType::PixelType PixelType; - typedef TMaskImage MaskImageType; - typedef typename MaskImageType::PixelType MaskLabelType; - typedef TClassifiedImage ClassifiedImageType; - typedef typename ClassifiedImageType::PixelType LabelType; - - /** Some convenient typedefs. */ - typedef float RealType; - typedef Image RealImageType; - typedef FixedArray ArrayType; - - /** Mixture model component typedefs */ - typedef Array MeasurementVectorType; - typedef typename Statistics::ListSample - SampleType; - typedef SmartPointer SamplePointer; - typedef Statistics::ListSampleFunction - LikelihoodFunctionType; - typedef typename LikelihoodFunctionType::Pointer LikelihoodFunctionPointer; - typedef typename LikelihoodFunctionType:: - WeightArrayType WeightArrayType; - - /** Outlier handling typedefs */ - typedef Statistics::ListSampleToListSampleFilter - OutlierHandlingFilterType; - - /** B-spline fitting typedefs */ - typedef Vector ScalarType; - typedef Image ScalarImageType; - typedef PointSet PointSetType; - typedef BSplineScatteredDataPointSetToImageFilter - BSplineFilterType; - typedef typename - BSplineFilterType::PointDataImageType ControlPointLatticeType; - typedef std::vector ControlPointLatticeContainerType; - - /** Initialization typedefs */ - enum InitializationStrategyType - { Random, KMeans, Otsu, PriorProbabilityImages, PriorLabelImage }; - - typedef std::pair LabelParametersType; - typedef std::map LabelParameterMapType; - - /** ivars Set/Get functionality */ - - itkSetClampMacro( NumberOfClasses, unsigned int, 2, - NumericTraits::max() ); - itkGetConstMacro( NumberOfClasses, unsigned int ); - - itkSetMacro( MaximumNumberOfIterations, unsigned int ); - itkGetConstMacro( MaximumNumberOfIterations, unsigned int ); - - itkSetMacro( ConvergenceThreshold, RealType ); - itkGetConstMacro( ConvergenceThreshold, RealType ); - - itkGetConstMacro( CurrentConvergenceMeasurement, RealType ); - - itkGetConstMacro( ElapsedIterations, unsigned int ); - - itkSetMacro( MRFSmoothingFactor, RealType ); - itkGetConstMacro( MRFSmoothingFactor, RealType ); - - itkSetMacro( MRFRadius, ArrayType ); - itkGetConstMacro( MRFRadius, ArrayType ); - - itkSetMacro( InitializationStrategy, InitializationStrategyType ); - itkGetConstMacro( InitializationStrategy, InitializationStrategyType ); - - itkSetMacro( SplineOrder, unsigned int ); - itkGetConstMacro( SplineOrder, unsigned int ); - - itkSetMacro( NumberOfLevels, ArrayType ); - itkGetConstMacro( NumberOfLevels, ArrayType ); - - itkSetMacro( NumberOfControlPoints, ArrayType ); - itkGetConstMacro( NumberOfControlPoints, ArrayType ); - - itkSetMacro( MinimizeMemoryUsage, bool ); - itkGetConstMacro( MinimizeMemoryUsage, bool ); - itkBooleanMacro( MinimizeMemoryUsage ); - - void SetMaskImage( const MaskImageType * mask ); - - const MaskImageType * GetMaskImage() const; - - itkSetClampMacro( PriorProbabilityWeight, RealType, 0.0, 1.0 ); - itkGetConstMacro( PriorProbabilityWeight, RealType ); - - void SetAdaptiveSmoothingWeight( unsigned int idx, RealType weight ) - { - RealType clampedWeight = vnl_math_min( NumericTraits::One, - vnl_math_max( NumericTraits::Zero, weight ) ); - - /** - * Clamp values between 0 and 1. Also, index [0] corresponds to the - * input image and [1]...[n], correspond to the auxiliary images. - */ - if( idx >= this->m_AdaptiveSmoothingWeights.size() ) - { - this->m_AdaptiveSmoothingWeights.resize( idx + 1 ); - this->m_AdaptiveSmoothingWeights[idx] = clampedWeight; - this->Modified(); - } - if( this->m_AdaptiveSmoothingWeights[idx] != weight ) - { - this->m_AdaptiveSmoothingWeights[idx] = clampedWeight; - this->Modified(); - } - } - - RealType GetAdaptiveSmoothingWeight( unsigned int idx ) - { - /** - * [0] corresponds to the input image and [1]...[n], correspond to - * the auxiliary images. - */ - if( idx < this->m_AdaptiveSmoothingWeights.size() ) - { - return this->m_AdaptiveSmoothingWeights[idx]; - } - } - - void SetPriorLabelParameterMap( LabelParameterMapType m ) - { - this->m_PriorLabelParameterMap = m; - this->Modified(); - } - - void GetPriorLabelParameterMap() - { - return this->m_PriorLabelParameterMap; - } - - /** - * Prior probability images (numbered between 1,...,numberOfClasses) - */ - void SetPriorProbabilityImage(unsigned int whichClass, const RealImageType * prior ); - - const RealImageType * GetPriorProbabilityImage( unsigned int whichClass ) const; - - void SetPriorLabelImage( const ClassifiedImageType * prior ); - - const ClassifiedImageType * GetPriorLabelImage() const; - - /** - * Auxiliary images (numbered between 1,...,n) - */ - void SetIntensityImage( unsigned int which, const ImageType * image ); - - const ImageType * GetIntensityImage( unsigned int which ) const; - - /** - * Euclidean distance uses Maurer to calculate the distance transform image. - * Otherwise use the fast marching filter. The former option is faster but it - * for non-Euclidean shapes (such as the cortex), it might be more accurate - * to use the latter option. - */ - itkSetMacro( UseEuclideanDistanceForPriorLabels, bool ); - itkGetConstMacro( UseEuclideanDistanceForPriorLabels, bool ); - itkBooleanMacro( UseEuclideanDistanceForPriorLabels ); - - itkSetObjectMacro( OutlierHandlingFilter, OutlierHandlingFilterType ); - itkGetObjectMacro( OutlierHandlingFilter, OutlierHandlingFilterType ); - - void SetLikelihoodFunction( unsigned int n, LikelihoodFunctionType *prob ) - { - if( n < this->m_MixtureModelComponents.size() && this->m_MixtureModelComponents[n] != prob ) - { - this->m_MixtureModelComponents[n] = prob; - this->Modified(); - } - else if( n >= this->m_MixtureModelComponents.size() ) - { - this->m_MixtureModelComponents.resize( n + 1 ); - this->m_MixtureModelComponents[n] = prob; - this->Modified(); - } - } - - LikelihoodFunctionType * GetLikelihoodFunction( unsigned int n ) - { - if( n < this->m_MixtureModelComponents.size() ) - { - return this->m_MixtureModelComponents[n].GetPointer(); - } - else - { - return NULL; - } - } - - typename RealImageType::Pointer GetPosteriorProbabilityImage( unsigned int ); - - typename RealImageType::Pointer CalculateSmoothIntensityImageFromPriorProbabilityImage(unsigned int, unsigned int ); - - typename RealImageType::Pointer GetDistancePriorProbabilityImageFromPriorLabelImage( unsigned int ); - - typename SampleType::Pointer GetScalarSamples( unsigned int ); - -#ifdef ITK_USE_CONCEPT_CHECKING - /** Begin concept checking */ - itkConceptMacro( SameDimensionCheck1, - ( Concept::SameDimension ) ); - itkConceptMacro( SameDimensionCheck2, - ( Concept::SameDimension ) ); - /** End concept checking */ -#endif -protected: - AtroposSegmentationImageFilter(); - ~AtroposSegmentationImageFilter(); - - void PrintSelf( std::ostream& os, Indent indent ) const; - - void GenerateData(); - -private: - AtroposSegmentationImageFilter(const Self &); // purposely not implemented - void operator=(const Self &); // purposely not implemented - - void NormalizePriorProbabilityImages(); - - void GenerateInitialClassLabeling(); - - void GenerateInitialClassLabelingWithOtsuThresholding(); - - void GenerateInitialClassLabelingWithKMeansClustering(); - - void GenerateInitialClassLabelingWithPriorProbabilityImages(); - - RealType UpdateClassParametersAndLabeling(); - - unsigned int m_NumberOfClasses; - unsigned int m_NumberOfIntensityImages; - unsigned int m_ElapsedIterations; - unsigned int m_MaximumNumberOfIterations; - RealType m_CurrentConvergenceMeasurement; - RealType m_ConvergenceThreshold; - - MaskLabelType m_MaskLabel; - - std::vector m_MixtureModelComponents; - Array m_MixtureModelProportions; - InitializationStrategyType m_InitializationStrategy; - - typename OutlierHandlingFilterType::Pointer m_OutlierHandlingFilter; - - ArrayType m_MRFRadius; - RealType m_MRFSmoothingFactor; - - std::vector m_AdaptiveSmoothingWeights; - RealType m_PriorProbabilityWeight; - LabelParameterMapType m_PriorLabelParameterMap; - - unsigned int m_SplineOrder; - ArrayType m_NumberOfLevels; - ArrayType m_NumberOfControlPoints; - std::vector m_ControlPointLattices; - - typename RealImageType::Pointer m_SumDistancePriorProbabilityImage; - typename RealImageType::Pointer m_SumPosteriorProbabilityImage; - bool m_MinimizeMemoryUsage; - - bool m_UseEuclideanDistanceForPriorLabels; - std::vector m_DistancePriorProbabilityImages; - std::vector m_PosteriorProbabilityImages; -}; -} // namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkAtroposSegmentationImageFilter.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkBoxPlotQuantileListSampleFilter.h b/ImageSegmentation/itkBoxPlotQuantileListSampleFilter.h deleted file mode 100644 index 242301015..000000000 --- a/ImageSegmentation/itkBoxPlotQuantileListSampleFilter.h +++ /dev/null @@ -1,119 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkBoxPlotQuantileListSampleFilter.h,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkBoxPlotQuantileListSampleFilter_h -#define __itkBoxPlotQuantileListSampleFilter_h - -#include "itkListSampleToListSampleFilter.h" - -#include - -namespace itk -{ -namespace Statistics -{ -/** \class BoxPlotQuantileListSampleFilter - * \brief Base class of filters intended to generate scalar samples from - * intensity samples. - * - */ - -template -class ITK_EXPORT BoxPlotQuantileListSampleFilter - : public ListSampleToListSampleFilter -{ -public: - /** - * Standard class typedefs. - */ - typedef BoxPlotQuantileListSampleFilter Self; - typedef ListSampleToListSampleFilter - Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** - * Standard macros - */ - itkTypeMacro( BoxPlotQuantileListSampleFilter, - ListSampleToScalarListSampleFilter ); - - /** - * Method for creation through the object factory. - */ - itkNewMacro( Self ); - - /** - * Conveneient typedefs - */ - typedef double RealType; - typedef TScalarListSample ScalarListSampleType; - typedef typename ScalarListSampleType - ::MeasurementVectorType MeasurementVectorType; - typedef typename ScalarListSampleType - ::InstanceIdentifier InstanceIdentifierType; - typedef std::vector InstanceIdentifierContainerType; - - enum OutlierHandlingType { None, Trim, Winsorize }; - - itkSetMacro( OutlierHandling, OutlierHandlingType ); - itkGetConstMacro( OutlierHandling, OutlierHandlingType ); - - itkSetMacro( WhiskerScalingFactor, RealType ); - itkGetConstMacro( WhiskerScalingFactor, RealType ); - - itkSetClampMacro( UpperPercentile, RealType, 0, 1 ); - itkGetConstMacro( UpperPercentile, RealType ); - - itkSetClampMacro( LowerPercentile, RealType, 0, 1 ); - itkGetConstMacro( LowerPercentile, RealType ); - - InstanceIdentifierContainerType GetOutlierInstanceIdentifiers() - { - return this->m_OutlierInstanceIdentifiers; - } - -// itkGetConstMacro( Outliers, InstanceIdentifierContainerType ); -protected: - BoxPlotQuantileListSampleFilter(); - virtual ~BoxPlotQuantileListSampleFilter(); - - void PrintSelf( std::ostream& os, Indent indent ) const; - - virtual void GenerateData(); - -private: - BoxPlotQuantileListSampleFilter( const Self & ); // purposely not implemented - void operator=( const Self & ); // purposely not implemented - - InstanceIdentifierType FindMaximumNonOutlierDeviationValue( RealType, RealType ); - bool IsMeasurementAnOutlier( RealType, RealType, RealType, unsigned long ); - - OutlierHandlingType m_OutlierHandling; - InstanceIdentifierContainerType m_OutlierInstanceIdentifiers; - RealType m_WhiskerScalingFactor; - RealType m_LowerPercentile; - RealType m_UpperPercentile; -}; // end of class -} // end of namespace Statistics -} // end of namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkBoxPlotQuantileListSampleFilter.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkGrubbsRosnerListSampleFilter.h b/ImageSegmentation/itkGrubbsRosnerListSampleFilter.h deleted file mode 100644 index 2937fbcbb..000000000 --- a/ImageSegmentation/itkGrubbsRosnerListSampleFilter.h +++ /dev/null @@ -1,115 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkGrubbsRosnerListSampleFilter.h,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkGrubbsRosnerListSampleFilter_h -#define __itkGrubbsRosnerListSampleFilter_h - -#include "itkListSampleToListSampleFilter.h" - -#include - -namespace itk -{ -namespace Statistics -{ -/** \class GrubbsRosnerListSampleFilter - * \brief Base class of filters intended to generate scalar samples from - * intensity samples. - * - */ - -template -class ITK_EXPORT GrubbsRosnerListSampleFilter - : public ListSampleToListSampleFilter -{ -public: - /** - * Standard class typedefs. - */ - typedef GrubbsRosnerListSampleFilter Self; - typedef ListSampleToListSampleFilter - Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** - * Standard macros - */ - itkTypeMacro( GrubbsRosnerListSampleFilter, - ListSampleToScalarListSampleFilter ); - - /** - * Method for creation through the object factory. - */ - itkNewMacro( Self ); - - /** - * Conveneient typedefs - */ - typedef double RealType; - typedef TScalarListSample ScalarListSampleType; - typedef typename ScalarListSampleType - ::MeasurementVectorType MeasurementVectorType; - typedef typename ScalarListSampleType - ::InstanceIdentifier InstanceIdentifierType; - typedef std::vector InstanceIdentifierContainerType; - - enum OutlierHandlingType { None, Trim, Winsorize }; - - itkSetMacro( OutlierHandling, OutlierHandlingType ); - itkGetConstMacro( OutlierHandling, OutlierHandlingType ); - - itkSetMacro( WinsorizingLevel, RealType ); - itkGetConstMacro( WinsorizingLevel, RealType ); - - itkSetMacro( SignificanceLevel, RealType ); - itkGetConstMacro( SignificanceLevel, RealType ); - - InstanceIdentifierContainerType GetOutlierInstanceIdentifiers() - { - return this->m_OutlierInstanceIdentifiers; - } - -// itkGetConstMacro( Outliers, InstanceIdentifierContainerType ); -protected: - GrubbsRosnerListSampleFilter(); - virtual ~GrubbsRosnerListSampleFilter(); - - void PrintSelf( std::ostream& os, Indent indent ) const; - - virtual void GenerateData(); - -private: - GrubbsRosnerListSampleFilter( const Self & ); // purposely not implemented - void operator=( const Self & ); // purposely not implemented - - InstanceIdentifierType FindMaximumNonOutlierDeviationValue( RealType, RealType ); - bool IsMeasurementAnOutlier( RealType, RealType, RealType, unsigned long ); - - OutlierHandlingType m_OutlierHandling; - RealType m_WinsorizingLevel; - InstanceIdentifierContainerType m_OutlierInstanceIdentifiers; - RealType m_SignificanceLevel; -}; // end of class -} // end of namespace Statistics -} // end of namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkGrubbsRosnerListSampleFilter.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkGrubbsRosnerListSampleFilter.txx b/ImageSegmentation/itkGrubbsRosnerListSampleFilter.txx deleted file mode 100644 index 121191690..000000000 --- a/ImageSegmentation/itkGrubbsRosnerListSampleFilter.txx +++ /dev/null @@ -1,276 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkGrubbsRosnerListSampleFilter.txx,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkGrubbsRosnerListSampleFilter_txx -#define __itkGrubbsRosnerListSampleFilter_txx - -#include "itkGrubbsRosnerListSampleFilter.h" - -#include "itkTDistribution.h" - -namespace itk -{ -namespace Statistics -{ -template -GrubbsRosnerListSampleFilter -::GrubbsRosnerListSampleFilter() -{ - this->AllocateOutput(); - this->GetOutput()->SetMeasurementVectorSize( 1 ); - - this->m_OutlierHandling = Winsorize; - this->m_WinsorizingLevel = 0.10; - this->m_SignificanceLevel = 0.05; -} - -template -GrubbsRosnerListSampleFilter -::~GrubbsRosnerListSampleFilter() -{ -} - -template -void -GrubbsRosnerListSampleFilter -::GenerateData() -{ - if( this->GetInput()->GetMeasurementVectorSize() != 1 ) - { - itkExceptionMacro( "The input sample must be univariate." ); - } - - const unsigned int scalarMeasurementVectorSize = - this->GetOutput()->GetMeasurementVectorSize(); - - this->GetOutput()->SetMeasurementVectorSize( scalarMeasurementVectorSize ); - - /** - * A common hueristic is that Grubbs-Rosner outlier removal does not work for - * sample sizes less than or equal to 6. - */ - if( this->GetInput()->Size() <= 6 ) - { - typename ScalarListSampleType::ConstIterator It = - this->GetInput()->Begin(); - while( It != this->GetInput()->End() ) - { - MeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - MeasurementVectorType outputMeasurement; - outputMeasurement.SetSize( scalarMeasurementVectorSize ); - for( unsigned int d = 0; d < scalarMeasurementVectorSize; d++ ) - { - outputMeasurement[d] = inputMeasurement[d]; - } - this->GetOutput()->PushBack( outputMeasurement ); - ++It; - } - - return; - } - - /** - * Otherwise, iterate through the input list, removing t - */ - - RealType mean = 0.0; - RealType variance = 0.0; - RealType count = 0.0; - - typename ScalarListSampleType::ConstIterator It = this->GetInput()->Begin(); - while( It != this->GetInput()->End() ) - { - MeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - - count += 1.0; - variance += ( count - 1.0 ) - * vnl_math_sqr( inputMeasurement[0] - mean ) / count; - mean = mean + ( inputMeasurement[0] - mean ) / count; - ++It; - } - - variance /= ( count - 1.0 ); - - bool outlierFound = true; - this->m_OutlierInstanceIdentifiers.clear(); - while( outlierFound == true && - ( this->GetInput()->Size() - this->m_OutlierInstanceIdentifiers.size() > 6 ) ) - { - outlierFound = false; - InstanceIdentifierType id = - this->FindMaximumNonOutlierDeviationValue( mean, variance ); - if( this->GetInput()->GetFrequency( id ) > 0 ) - { - MeasurementVectorType measurement = - this->GetInput()->GetMeasurementVector( id ); - outlierFound = this->IsMeasurementAnOutlier( measurement[0], mean, variance, - this->GetInput()->Size() - - this->m_OutlierInstanceIdentifiers.size() ); - if( outlierFound ) - { - /** Retabulate the variance and mean by removing the previous estimate */ - RealType count = this->GetInput()->Size() - - this->m_OutlierInstanceIdentifiers.size(); - mean = ( mean * count - measurement[0] ) / ( count - 1.0 ); - variance = ( count - 1.0 ) * variance - ( count - 1.0 ) - * vnl_math_sqr( measurement[0] - mean ) / count; - variance /= ( count - 2.0 ); - this->m_OutlierInstanceIdentifiers.push_back( id ); - } - } - } - - RealType lowerWinsorBound = 0.0; - RealType upperWinsorBound = 0.0; - if( this->m_OutlierHandling == Winsorize ) - { - typename Statistics::TDistribution::Pointer tdistribution = - Statistics::TDistribution::New(); - RealType t = tdistribution->EvaluateInverseCDF( - 1.0 - 0.5 * this->m_WinsorizingLevel, - this->GetInput()->Size() - this->m_OutlierInstanceIdentifiers.size() ); - - lowerWinsorBound = mean - t * vcl_sqrt( variance ); - upperWinsorBound = mean + t * vcl_sqrt( variance ); - } - - It = this->GetInput()->Begin(); - while( It != this->GetInput()->End() ) - { - MeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - MeasurementVectorType outputMeasurement; - outputMeasurement.SetSize( scalarMeasurementVectorSize ); - - if( this->m_OutlierHandling == None || std::find( - this->m_OutlierInstanceIdentifiers.begin(), - this->m_OutlierInstanceIdentifiers.end(), It.GetInstanceIdentifier() ) == - this->m_OutlierInstanceIdentifiers.end() ) - { - outputMeasurement[0] = inputMeasurement[0]; - this->GetOutput()->PushBack( outputMeasurement ); - } - else if( this->m_OutlierHandling == Winsorize ) - { - if( inputMeasurement[0] < lowerWinsorBound ) - { - outputMeasurement[0] = lowerWinsorBound; - } - else - { - outputMeasurement[0] = upperWinsorBound; - } - this->GetOutput()->PushBack( outputMeasurement ); - } - ++It; - } -} - -template -typename GrubbsRosnerListSampleFilter -::InstanceIdentifierType -GrubbsRosnerListSampleFilter -::FindMaximumNonOutlierDeviationValue( RealType mean, RealType variance ) -{ - RealType maximumDeviation = 0.0; - InstanceIdentifierType maximumID = - NumericTraits::max(); - - typename ScalarListSampleType::ConstIterator It = this->GetInput()->Begin(); - while( It != this->GetInput()->End() ) - { - MeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - InstanceIdentifierType inputID = It.GetInstanceIdentifier(); - - if( std::find( this->m_OutlierInstanceIdentifiers.begin(), - this->m_OutlierInstanceIdentifiers.end(), inputID ) == - this->m_OutlierInstanceIdentifiers.end() ) - { - if( vnl_math_abs( inputMeasurement[0] - mean ) > maximumDeviation ) - { - maximumDeviation = vnl_math_abs( inputMeasurement[0] - mean ); - maximumID = inputID; - } - } - ++It; - } - - return maximumID; -} - -template -bool -GrubbsRosnerListSampleFilter -::IsMeasurementAnOutlier( RealType x, RealType mean, RealType variance, - unsigned long N ) -{ - /** - * The Grubb critical two-sided value is defined to be - * (N-1)/sqrt(N)*sqrt( t*t / (N-2+t*t) ) where t is at the - * (alpha / (2N)) signficance level with N-2 degrees of freedom. - */ - - RealType sig = this->m_SignificanceLevel / ( 2.0 * static_cast( N ) ); - - typename Statistics::TDistribution::Pointer tdistribution = - Statistics::TDistribution::New(); - - RealType t = tdistribution->EvaluateInverseCDF( 1.0 - sig, N - 2 ); - - RealType nu = static_cast( N - 1 ); - RealType g = nu / vcl_sqrt( nu + 1.0 ) * vcl_sqrt( t * t / ( nu - 1 + t * t ) ); - - return g < ( vnl_math_abs( x - mean ) / vcl_sqrt( variance ) ); -} - -template -void -GrubbsRosnerListSampleFilter -::PrintSelf( std::ostream& os, Indent indent ) const -{ - os << indent << "Significance level: " << this->m_SignificanceLevel - << std::endl; - os << indent << "Outlier handling: "; - if( this->m_OutlierHandling == None ) - { - os << "None" << std::endl; - } - if( this->m_OutlierHandling == Trim ) - { - os << "Trim" << std::endl; - } - if( this->m_OutlierHandling == Winsorize ) - { - os << "Winsorize"; - os << " (level = " << this->m_WinsorizingLevel << ")" << std::endl; - } - if( this->m_OutlierInstanceIdentifiers.size() > 0 ) - { - os << indent << "Outlier Identifiers: " << std::endl; - for( unsigned int d = 0; d < this->m_OutlierInstanceIdentifiers.size(); d++ ) - { - os << indent << " " << this->m_OutlierInstanceIdentifiers[d] << std::endl; - } - } - else - { - os << indent << "There are no outliers." << std::endl; - } -} -} // end of namespace Statistics -} // end of namespace itk - -#endif diff --git a/ImageSegmentation/itkHistogramParzenWindowsListSampleFunction.h b/ImageSegmentation/itkHistogramParzenWindowsListSampleFunction.h deleted file mode 100644 index e2c618b80..000000000 --- a/ImageSegmentation/itkHistogramParzenWindowsListSampleFunction.h +++ /dev/null @@ -1,99 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkHistogramParzenWindowsListSampleFunction.h,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkHistogramParzenWindowsListSampleFunction_h -#define __itkHistogramParzenWindowsListSampleFunction_h - -#include "itkListSampleFunction.h" - -#include "itkImage.h" - -namespace itk -{ -namespace Statistics -{ -/** \class HistogramParzenWindowsListSampleFunction.h - * \brief point set filter. - */ - -template -class ITK_EXPORT HistogramParzenWindowsListSampleFunction - : public ListSampleFunction -{ -public: - typedef HistogramParzenWindowsListSampleFunction Self; - typedef ListSampleFunction - Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information (and related methods). */ - itkTypeMacro( HistogramParzenWindowsListSampleFunction, ListSampleFunction ); - - typedef typename Superclass::InputListSampleType InputListSampleType; - typedef typename Superclass::InputMeasurementVectorType InputMeasurementVectorType; - typedef typename Superclass::InputMeasurementType InputMeasurementType; - - /** List sample typedef support. */ - typedef TListSample ListSampleType; - - /** Other typedef */ - typedef TOutput RealType; - typedef TOutput OutputType; - - typedef Image HistogramImageType; - - /** Helper functions */ - - itkSetMacro( Sigma, RealType ); - itkGetConstMacro( Sigma, RealType ); - - itkSetMacro( NumberOfHistogramBins, unsigned int ); - itkGetConstMacro( NumberOfHistogramBins, unsigned int ); - - virtual void SetInputListSample( const InputListSampleType * ptr ); - - virtual TOutput Evaluate( const InputMeasurementVectorType& measurement ) const; - -protected: - HistogramParzenWindowsListSampleFunction(); - virtual ~HistogramParzenWindowsListSampleFunction(); - void PrintSelf( std::ostream& os, Indent indent ) const; - - void GenerateData(); - -private: - // purposely not implemented - HistogramParzenWindowsListSampleFunction( const Self & ); - void operator=( const Self & ); - - unsigned int m_NumberOfHistogramBins; - RealType m_Sigma; - - std::vector m_HistogramImages; -}; -} // end of namespace Statistics -} // end of namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkHistogramParzenWindowsListSampleFunction.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkHistogramParzenWindowsListSampleFunction.txx b/ImageSegmentation/itkHistogramParzenWindowsListSampleFunction.txx deleted file mode 100644 index 3fe70611a..000000000 --- a/ImageSegmentation/itkHistogramParzenWindowsListSampleFunction.txx +++ /dev/null @@ -1,241 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkHistogramParzenWindowsListSampleFunction.txx,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkHistogramParzenWindowsListSampleFunction_txx -#define __itkHistogramParzenWindowsListSampleFunction_txx - -#include "itkHistogramParzenWindowsListSampleFunction.h" - -#include "itkArray.h" -#include "itkBSplineInterpolateImageFunction.h" -#include "itkContinuousIndex.h" -#include "itkDiscreteGaussianImageFilter.h" -#include "itkDivideByConstantImageFilter.h" -#include "itkStatisticsImageFilter.h" - -namespace itk -{ -namespace Statistics -{ -template -HistogramParzenWindowsListSampleFunction -::HistogramParzenWindowsListSampleFunction() -{ - this->m_NumberOfHistogramBins = 32; - this->m_Sigma = 1.0; -} - -template -HistogramParzenWindowsListSampleFunction -::~HistogramParzenWindowsListSampleFunction() -{ -} - -template -void -HistogramParzenWindowsListSampleFunction -::SetInputListSample( const InputListSampleType * ptr ) -{ - this->m_ListSample = ptr; - - if( !this->m_ListSample ) - { - itkExceptionMacro( "Attempting to set the input list sample to NULL." ); - } - - if( this->m_ListSample->Size() <= 1 ) - { - itkWarningMacro( "The input list sample has <= 1 element." - << "Function evaluations will be equal to 0." ); - return; - } - - const unsigned int Dimension = - this->m_ListSample->GetMeasurementVectorSize(); - - /** - * Find the min/max values to define the histogram domain - */ - - Array minValues( Dimension ); - minValues.Fill( NumericTraits::max() ); - Array maxValues( Dimension ); - maxValues.Fill( NumericTraits::NonpositiveMin() ); - - typename InputListSampleType::ConstIterator It - = this->m_ListSample->Begin(); - while( It != this->m_ListSample->End() ) - { - InputMeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - for( unsigned int d = 0; d < Dimension; d++ ) - { - if( inputMeasurement[d] < minValues[d] ) - { - minValues[d] = inputMeasurement[d]; - } - if( inputMeasurement[d] > maxValues[d] ) - { - maxValues[d] = inputMeasurement[d]; - } - } - ++It; - } - - this->m_HistogramImages.clear(); - for( unsigned int d = 0; d < Dimension; d++ ) - { - this->m_HistogramImages.push_back( HistogramImageType::New() ); - - typename HistogramImageType::SpacingType spacing; - spacing[0] = ( maxValues[d] - minValues[d] ) - / static_cast( this->m_NumberOfHistogramBins - 1 ); - - typename HistogramImageType::PointType origin; - origin[0] = minValues[d] - 3.0 * ( this->m_Sigma * spacing[0] ); - - typename HistogramImageType::SizeType size; - size[0] = static_cast( - vcl_ceil( ( maxValues[d] + 3.0 * ( this->m_Sigma * spacing[0] ) - - ( minValues[d] - 3.0 * ( this->m_Sigma * spacing[0] ) ) ) / spacing[0] ) ); - - this->m_HistogramImages[d]->SetOrigin( origin ); - this->m_HistogramImages[d]->SetSpacing( spacing ); - this->m_HistogramImages[d]->SetRegions( size ); - this->m_HistogramImages[d]->Allocate(); - this->m_HistogramImages[d]->FillBuffer( 0 ); - } - - unsigned long count = 0; - It = this->m_ListSample->Begin(); - while( It != this->m_ListSample->End() ) - { - InputMeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - - RealType newWeight = 1.0; - if( this->m_Weights.Size() == this->m_ListSample->Size() ) - { - newWeight = this->m_Weights[count]; - } - for( unsigned int d = 0; d < Dimension; d++ ) - { - typename HistogramImageType::PointType point; - point[0] = inputMeasurement[d]; - - ContinuousIndex cidx; - this->m_HistogramImages[d]->TransformPhysicalPointToContinuousIndex( - point, cidx ); - - typename HistogramImageType::IndexType idx; - - idx[0] = static_cast( vcl_floor( cidx[0] ) ); - if( this->m_HistogramImages[d]->GetLargestPossibleRegion().IsInside( idx ) ) - { - RealType oldWeight = this->m_HistogramImages[d]->GetPixel( idx ); - this->m_HistogramImages[d]->SetPixel( idx, - ( 1.0 - ( cidx[0] - idx[0] ) ) * newWeight + oldWeight ); - } - - idx[0]++; - if( this->m_HistogramImages[d]->GetLargestPossibleRegion().IsInside( idx ) ) - { - RealType oldWeight = this->m_HistogramImages[d]->GetPixel( idx ); - this->m_HistogramImages[d]->SetPixel( idx, - ( 1.0 - ( idx[0] - cidx[0] ) ) * newWeight + oldWeight ); - } - } - ++count; - ++It; - } - for( unsigned int d = 0; d < Dimension; d++ ) - { - typedef DiscreteGaussianImageFilter - GaussianFilterType; - typename GaussianFilterType::Pointer gaussian = GaussianFilterType::New(); - gaussian->SetInput( this->m_HistogramImages[d] ); - gaussian->SetVariance( this->m_Sigma * this->m_Sigma ); - gaussian->SetMaximumError( 0.01 ); - gaussian->SetUseImageSpacing( false ); - gaussian->Update(); - - typedef StatisticsImageFilter StatsFilterType; - typename StatsFilterType::Pointer stats = StatsFilterType::New(); - stats->SetInput( gaussian->GetOutput() ); - stats->Update(); - - typedef DivideByConstantImageFilter DividerType; - typename DividerType::Pointer divider = DividerType::New(); - divider->SetInput( gaussian->GetOutput() ); - divider->SetConstant( stats->GetSum() ); - divider->Update(); - this->m_HistogramImages[d] = divider->GetOutput(); - } -} - -template -TOutput -HistogramParzenWindowsListSampleFunction -::Evaluate( const InputMeasurementVectorType & measurement ) const -{ - if( this->m_ListSample->Size() <= 1 ) - { - return 0; - } - - typedef BSplineInterpolateImageFunction InterpolatorType; - - RealType probability = 1.0; - for( unsigned int d = 0; d < this->m_HistogramImages.size(); d++ ) - { - typename HistogramImageType::PointType point; - point[0] = measurement[d]; - - typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); - interpolator->SetSplineOrder( 3 ); - interpolator->SetInputImage( this->m_HistogramImages[d] ); - if( interpolator->IsInsideBuffer( point ) ) - { - probability *= interpolator->Evaluate( point ); - } - else - { - return 0; - } - } - return probability; -} - -/** - * Standard "PrintSelf" method - */ -template -void -HistogramParzenWindowsListSampleFunction -::PrintSelf( - std::ostream& os, - Indent indent) const -{ - os << indent << "Sigma: " - << this->m_Sigma << std::endl; - os << indent << "Number of histogram bins: " - << this->m_NumberOfHistogramBins << std::endl; -} -} // end of namespace Statistics -} // end of namespace itk - -#endif diff --git a/ImageSegmentation/itkListSampleFunction.h b/ImageSegmentation/itkListSampleFunction.h deleted file mode 100644 index b00bbeb7d..000000000 --- a/ImageSegmentation/itkListSampleFunction.h +++ /dev/null @@ -1,128 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkListSampleFunction.h,v $ - Language: C++ - Date: $Date: 2008/10/18 00:20:04 $ - Version: $Revision: 1.1.1.1 $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkListSampleFunction_h -#define __itkListSampleFunction_h - -#include "itkFunctionBase.h" - -#include "itkArray.h" - -namespace itk -{ -namespace Statistics -{ -/** \class ListSampleFunction - * \brief Evaluates a function of an image at specified position. - * - * ListSampleFunction is a baseclass for all objects that evaluates - * a function of a list sample at a measurement - * This class is templated over the input list type, the type - * of the function output and the coordinate representation type - * (e.g. float or double). - * - * The input list sample is set via method SetInputListSample(). - * The methods Evaluate() evaluates the function at a measurement vector. - * - * \ingroup ListSampleFunctions - */ -template -class ITK_EXPORT ListSampleFunction : - public FunctionBase -{ -public: - - /** Standard class typedefs. */ - typedef ListSampleFunction Self; - typedef FunctionBase Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** Run-time type information (and related methods). */ - itkTypeMacro( ListSampleFunction, FunctionBase ); - - /** InputListSampleType typedef support. */ - typedef TInputListSample InputListSampleType; - - /** Array typedef for weights */ - typedef Array WeightArrayType; - - /** InputPixel typedef support */ - typedef typename InputListSampleType::MeasurementVectorType InputMeasurementVectorType; - typedef typename InputListSampleType::MeasurementType InputMeasurementType; - - /** OutputType typedef support. */ - typedef TOutput OutputType; - - /** CoordRepType typedef support. */ - typedef TCoordRep CoordRepType; - - /** Set the input point set. - * \warning this method caches BufferedRegion information. - * If the BufferedRegion has changed, user must call - * SetInputListSample again to update cached values. */ - virtual void SetInputListSample( const InputListSampleType * ptr ); - - /** Get the input image. */ - const InputListSampleType * GetInputListSample() const - { - return m_ListSample.GetPointer(); - } - - /** Sets the weights using an array */ - virtual void SetWeights( WeightArrayType* array ); - - /** Gets the weights array */ - WeightArrayType * GetWeights(); - - /** Evaluate the function at specified Point position. - * Subclasses must provide this method. */ - virtual TOutput Evaluate( const InputMeasurementVectorType& measurement ) const = 0; - -protected: - ListSampleFunction(); - ~ListSampleFunction() - { - } - - void PrintSelf(std::ostream& os, Indent indent) const; - - /** Const pointer to the input image. */ - typename InputListSampleType::ConstPointer m_ListSample; - WeightArrayType m_Weights; -private: - ListSampleFunction(const Self &); // purposely not implemented - void operator=(const Self &); // purposely not implemented -}; -} // end of namespace Statistics -} // end of namespace itk - -// Define instantiation macro for this template. -#define ITK_TEMPLATE_ListSampleFunction(_, EXPORT, x, y) namespace itk { \ - _(3 (class EXPORT ListSampleFunction ) ) \ - namespace Templates { typedef ListSampleFunction ListSampleFunction##y; } \ - } - -#if ITK_TEMPLATE_EXPLICIT -#include "Templates/itkListSampleFunction+-.h" -#endif - -#if ITK_TEMPLATE_TXX -#include "itkListSampleFunction.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkListSampleFunction.txx b/ImageSegmentation/itkListSampleFunction.txx deleted file mode 100644 index 3ea38c396..000000000 --- a/ImageSegmentation/itkListSampleFunction.txx +++ /dev/null @@ -1,82 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkListSampleFunction.txx,v $ - Language: C++ - Date: $Date: 2008/10/18 00:20:04 $ - Version: $Revision: 1.1.1.1 $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkListSampleFunction_txx -#define __itkListSampleFunction_txx - -#include "itkListSampleFunction.h" - -namespace itk -{ -namespace Statistics -{ -/** - * Constructor - */ -template -ListSampleFunction -::ListSampleFunction() -{ - this->m_ListSample = NULL; -} - -/** - * Standard "PrintSelf" method - */ -template -void -ListSampleFunction -::PrintSelf( - std::ostream& os, - Indent indent) const -{ - os << indent << "InputListSample: " << m_ListSample.GetPointer() << std::endl; -} - -template -void -ListSampleFunction -::SetWeights( WeightArrayType* array ) -{ - this->m_Weights = *array; - this->Modified(); -} - -template -typename ListSampleFunction::WeightArrayType -* ListSampleFunction -::GetWeights() - { - return &this->m_Weights; - } - -/** - * Initialize by setting the input point set - */ -template -void -ListSampleFunction -::SetInputListSample( - const InputListSampleType * ptr ) -{ - // set the input image - m_ListSample = ptr; -} -} // end of namespace Statistics -} // end of namespace itk - -#endif diff --git a/ImageSegmentation/itkListSampleToListSampleFilter.h b/ImageSegmentation/itkListSampleToListSampleFilter.h deleted file mode 100644 index 52fec86b0..000000000 --- a/ImageSegmentation/itkListSampleToListSampleFilter.h +++ /dev/null @@ -1,96 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkListSampleToListSampleFilter.h,v $ - Language: C++ - Date: $$ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkListSampleToListSampleFilter_h -#define __itkListSampleToListSampleFilter_h - -#include "itkProcessObject.h" - -namespace itk -{ -namespace Statistics -{ -/** \class ListSampleToListSampleFilter - * \brief Base class for filters that take a list sample as an input and output - * another list sample. - * - * ListSampleToListSampleFilter is the base class for all process objects that output - * list sample data, and require list sample data as input. Specifically, this class - * defines the SetInput() method for defining the input to a filter. - * - * \ingroup ListSampleFilters - * - */ -template -class ITK_EXPORT ListSampleToListSampleFilter : public ProcessObject -{ -public: - /** Standard class typedefs. */ - typedef ListSampleToListSampleFilter Self; - typedef ProcessObject Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** Run-time type information (and related methods). */ - itkTypeMacro( ListSampleToListSampleFilter, ProcessObject ); - - /** Some convenient typedefs. */ - typedef TInputListSample InputListSampleType; - typedef TOutputListSample OutputListSampleType; - - /** Set the list sample input of this object. */ - void SetInput( const InputListSampleType *input ); - - /** Get the list sample input of this object. */ - InputListSampleType * GetInput(); - - /** Get the list sample output of this object. */ - OutputListSampleType * GetOutput(); - - virtual void Update() - { - this->GenerateData(); - } - -protected: - ListSampleToListSampleFilter(); - ~ListSampleToListSampleFilter() - { - }; - - virtual void GenerateData() = 0; - - void AllocateOutput(); - -private: - ListSampleToListSampleFilter( const Self & ); // purposely not implemented - void operator=( const Self & ); // purposely not implemented - -// typename InputListSampleType::ConstPointer m_InputListSample; -// typename OutputListSampleType::Pointer m_OutputListSample; -}; -} // end namespace Statistics -} // end namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkListSampleToListSampleFilter.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkListSampleToListSampleFilter.txx b/ImageSegmentation/itkListSampleToListSampleFilter.txx deleted file mode 100644 index a5c831007..000000000 --- a/ImageSegmentation/itkListSampleToListSampleFilter.txx +++ /dev/null @@ -1,98 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkListSampleToListSampleFilter.txx,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - Portions of this code are covered under the VTK copyright. - See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef _itkListSampleToListSampleFilter_txx -#define _itkListSampleToListSampleFilter_txx - -#include "itkListSampleToListSampleFilter.h" - -namespace itk -{ -namespace Statistics -{ -/** - * - */ -template -ListSampleToListSampleFilter -::ListSampleToListSampleFilter() -{ - // Modify superclass default values, can be overridden by subclasses - this->SetNumberOfRequiredInputs( 1 ); - this->SetNumberOfRequiredOutputs( 1 ); -} - -template -void -ListSampleToListSampleFilter -::SetInput( const TInputListSample *input ) -{ -// this->m_InputListSample = const_cast( input ); - this->ProcessObject::SetNthInput( 0, - reinterpret_cast( - const_cast( input ) ) ); -} - -template -void -ListSampleToListSampleFilter -::AllocateOutput() -{ - typename DataObject::Pointer obj = - reinterpret_cast(TOutputListSample::New().GetPointer() ); - -// typename TOutputListSample::Pointer output -// = reinterpret_cast(obj.GetPointer()); - this->ProcessObject::SetNumberOfRequiredOutputs( 1 ); - this->ProcessObject::SetNthOutput( 0, obj.GetPointer() ); - -// this->m_OutputListSample = OutputListSampleType::New(); -} - -/** - * - */ -template -typename ListSampleToListSampleFilter::InputListSampleType -* ListSampleToListSampleFilter -::GetInput() - { - return reinterpret_cast( - this->ProcessObject::GetInput( 0 ) ); - } - -template -typename ListSampleToListSampleFilter::OutputListSampleType -* ListSampleToListSampleFilter -::GetOutput() - { - if( this->GetNumberOfOutputs() < 1 ) - { - return 0; - } - - // we assume that the first output is of the templated type - return reinterpret_cast( this->ProcessObject::GetOutput( 0 ) ); -// return this->m_OutputListSample.GetPointer(); - } -} // end of namespace Statistics -} // end of namespace itk - -#endif diff --git a/ImageSegmentation/itkManifoldParzenWindowsListSampleFunction.h b/ImageSegmentation/itkManifoldParzenWindowsListSampleFunction.h deleted file mode 100644 index 8f0ea432a..000000000 --- a/ImageSegmentation/itkManifoldParzenWindowsListSampleFunction.h +++ /dev/null @@ -1,123 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkManifoldParzenWindowsListSampleFunction.h,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkManifoldParzenWindowsListSampleFunction_h -#define __itkManifoldParzenWindowsListSampleFunction_h - -#include "itkListSampleFunction.h" - -#include "itkGaussianMembershipFunction.h" -#include "itkWeightedCentroidKdTreeGenerator.h" - -#include - -namespace itk -{ -namespace Statistics -{ -/** \class ManifoldParzenWindowsListSampleFunction.h - * \brief point set filter. - */ - -template -class ITK_EXPORT ManifoldParzenWindowsListSampleFunction - : public ListSampleFunction -{ -public: - typedef ManifoldParzenWindowsListSampleFunction Self; - typedef ListSampleFunction - Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information (and related methods). */ - itkTypeMacro( ManifoldParzenWindowsListSampleFunction, ListSampleFunction ); - - typedef typename Superclass::InputListSampleType InputListSampleType; - typedef typename Superclass::InputMeasurementVectorType InputMeasurementVectorType; - typedef typename Superclass::InputMeasurementType InputMeasurementType; - - /** List sample typedef support. */ - typedef TListSample ListSampleType; - - /** Kd tree typedefs */ - typedef typename Statistics:: - WeightedCentroidKdTreeGenerator TreeGeneratorType; - typedef typename TreeGeneratorType::KdTreeType KdTreeType; - typedef typename KdTreeType - ::InstanceIdentifierVectorType NeighborhoodIdentifierType; - - /** Other typedef */ - typedef TOutput RealType; - typedef TOutput OutputType; - - typedef typename Statistics::GaussianMembershipFunction - GaussianType; - typedef std::vector GaussianContainerType; - typedef typename GaussianType::CovarianceType CovarianceMatrixType; - - /** Helper functions */ - - itkSetMacro( EvaluationKNeighborhood, unsigned int ); - itkGetConstMacro( EvaluationKNeighborhood, unsigned int ); - - itkSetMacro( RegularizationSigma, RealType ); - itkGetConstMacro( RegularizationSigma, RealType ); - - itkSetMacro( CovarianceKNeighborhood, unsigned int ); - itkGetConstMacro( CovarianceKNeighborhood, unsigned int ); - - itkSetMacro( KernelSigma, RealType ); - itkGetConstMacro( KernelSigma, RealType ); - - virtual void SetInputListSample( const InputListSampleType * ptr ); - - virtual TOutput Evaluate( const InputMeasurementVectorType& measurement ) const; - -protected: - ManifoldParzenWindowsListSampleFunction(); - virtual ~ManifoldParzenWindowsListSampleFunction(); - void PrintSelf( std::ostream& os, Indent indent ) const; - - void GenerateData(); - -private: - // purposely not implemented - ManifoldParzenWindowsListSampleFunction( const Self & ); - void operator=( const Self & ); - - unsigned int m_CovarianceKNeighborhood; - unsigned int m_EvaluationKNeighborhood; - RealType m_RegularizationSigma; - RealType m_KernelSigma; - RealType m_NormalizationFactor; - - typename TreeGeneratorType::Pointer m_KdTreeGenerator; - - GaussianContainerType m_Gaussians; -}; -} // end of namespace Statistics -} // end of namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkManifoldParzenWindowsListSampleFunction.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkManifoldParzenWindowsListSampleFunction.txx b/ImageSegmentation/itkManifoldParzenWindowsListSampleFunction.txx deleted file mode 100644 index 5dbc4d891..000000000 --- a/ImageSegmentation/itkManifoldParzenWindowsListSampleFunction.txx +++ /dev/null @@ -1,251 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkManifoldParzenWindowsListSampleFunction.txx,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkManifoldParzenWindowsListSampleFunction_txx -#define __itkManifoldParzenWindowsListSampleFunction_txx - -#include "itkManifoldParzenWindowsListSampleFunction.h" - -namespace itk -{ -namespace Statistics -{ -template -ManifoldParzenWindowsListSampleFunction -::ManifoldParzenWindowsListSampleFunction() -{ - this->m_KdTreeGenerator = NULL; - - this->m_EvaluationKNeighborhood = 50; - this->m_RegularizationSigma = 1.0; - - this->m_CovarianceKNeighborhood = 0; - this->m_KernelSigma = 0.0; -} - -template -ManifoldParzenWindowsListSampleFunction -::~ManifoldParzenWindowsListSampleFunction() -{ -} - -template -void -ManifoldParzenWindowsListSampleFunction -::SetInputListSample( const InputListSampleType * ptr ) -{ - this->m_ListSample = ptr; - - if( !this->m_ListSample ) - { - itkExceptionMacro( "Attempting to set the input list sample to NULL." ); - } - - if( this->m_ListSample->Size() <= 1 ) - { - itkWarningMacro( "The input list sample has <= 1 element." - << "Function evaluations will be equal to 0." ); - return; - } - - /** - * Generate KdTree and create set of gaussians from input point set - */ - this->m_KdTreeGenerator = TreeGeneratorType::New(); - this->m_KdTreeGenerator->SetSample( const_cast( - this->m_ListSample.GetPointer() ) ); - this->m_KdTreeGenerator->SetBucketSize( 16 ); - this->m_KdTreeGenerator->Update(); - - /** - * Calculate covariance matrices - */ - this->m_Gaussians.resize( this->m_ListSample->Size() ); - const unsigned int Dimension = - this->m_ListSample->GetMeasurementVectorSize(); - - unsigned long count = 0; - typename InputListSampleType::ConstIterator It - = this->m_ListSample->Begin(); - while( It != this->m_ListSample->End() ) - { - InputMeasurementVectorType inputMeasurement = It.GetMeasurementVector(); - - typename GaussianType::MeanType mean( Dimension ); - for( unsigned int d = 0; d < Dimension; d++ ) - { - mean[d] = inputMeasurement[d]; - } - - this->m_Gaussians[count] = GaussianType::New(); - this->m_Gaussians[count]->SetMean( mean ); - - if( this->m_CovarianceKNeighborhood > 0 ) - { - /** Temporarily set the covariance */ - CovarianceMatrixType Cov( Dimension, Dimension ); - Cov.SetIdentity(); - Cov *= this->m_KernelSigma; - this->m_Gaussians[count]->SetCovariance( Cov ); - - Cov.Fill( 0 ); - - typename TreeGeneratorType::KdTreeType - ::InstanceIdentifierVectorType neighbors; - unsigned int numberOfNeighbors = vnl_math_min( - this->m_CovarianceKNeighborhood, static_cast( - this->m_ListSample->Size() ) ); - this->m_KdTreeGenerator->GetOutput()->Search( - inputMeasurement, numberOfNeighbors, neighbors ); - - RealType denominator = 0.0; - for( unsigned int j = 0; j < numberOfNeighbors; j++ ) - { - if( neighbors[j] != count - && neighbors[j] < this->m_ListSample->Size() ) - { - InputMeasurementVectorType neighbor - = this->m_KdTreeGenerator->GetOutput()->GetMeasurementVector( - neighbors[j] ); - - RealType kernelValue = this->m_Gaussians[count]->Evaluate( neighbor ); - if( this->m_Weights.Size() == this->m_Gaussians.size() ) - { - kernelValue *= this->m_Weights[count]; - } - - denominator += kernelValue; - if( kernelValue > 0.0 ) - { - for( unsigned int m = 0; m < Dimension; m++ ) - { - for( unsigned int n = m; n < Dimension; n++ ) - { - RealType covariance = kernelValue - * ( neighbor[m] - inputMeasurement[m] ) - * ( neighbor[n] - inputMeasurement[n] ); - Cov( m, n ) += covariance; - Cov( n, m ) += covariance; - } - } - } - } - } - if( denominator > 0.0 ) - { - Cov /= denominator; - } - for( unsigned int m = 0; m < Dimension; m++ ) - { - Cov( m, m ) += - ( this->m_RegularizationSigma * this->m_RegularizationSigma ); - } - this->m_Gaussians[count]->SetCovariance( Cov ); - } - else - { - CovarianceMatrixType Cov( Dimension, Dimension ); - Cov.SetIdentity(); - Cov *= this->m_RegularizationSigma; - this->m_Gaussians[count]->SetCovariance( Cov ); - } - ++It; - ++count; - } - - /** - * Calculate normalization factor - */ - this->m_NormalizationFactor = 0.0; - for( unsigned int i = 0; i < this->m_Gaussians.size(); i++ ) - { - if( this->m_Weights.Size() == this->m_Gaussians.size() ) - { - this->m_NormalizationFactor += this->m_Weights[i]; - } - else - { - this->m_NormalizationFactor += 1.0; - } - } -} - -template -TOutput -ManifoldParzenWindowsListSampleFunction -::Evaluate( const InputMeasurementVectorType & measurement ) const -{ - if( this->m_ListSample->Size() <= 1 ) - { - return 0; - } - - unsigned int numberOfNeighbors = vnl_math_min( - this->m_EvaluationKNeighborhood, - static_cast( this->m_Gaussians.size() ) ); - - OutputType sum = 0.0; - - if( numberOfNeighbors == this->m_Gaussians.size() ) - { - for( unsigned int j = 0; j < this->m_Gaussians.size(); j++ ) - { - sum += static_cast( - this->m_Gaussians[j]->Evaluate( measurement ) ); - } - } - else - { - typename TreeGeneratorType::KdTreeType - ::InstanceIdentifierVectorType neighbors; - this->m_KdTreeGenerator->GetOutput()->Search( measurement, - numberOfNeighbors, neighbors ); - for( unsigned int j = 0; j < numberOfNeighbors; j++ ) - { - sum += static_cast( - this->m_Gaussians[neighbors[j]]->Evaluate( measurement ) ); - } - } - return static_cast( sum / this->m_NormalizationFactor ); -} - -/** - * Standard "PrintSelf" method - */ -template -void -ManifoldParzenWindowsListSampleFunction -::PrintSelf( - std::ostream& os, - Indent indent) const -{ - os << indent << "Regularization sigma: " - << this->m_RegularizationSigma << std::endl; - os << indent << "Evaluation K neighborhood: " - << this->m_EvaluationKNeighborhood << std::endl; - if( this->m_CovarianceKNeighborhood > 0 ) - { - os << indent << "Covariance K neighborhood: " - << this->m_CovarianceKNeighborhood << std::endl; - os << indent << "Kernel sigma: " - << this->m_KernelSigma << std::endl; - } -} -} // end of namespace Statistics -} // end of namespace itk - -#endif diff --git a/ImageSegmentation/itkPassThroughListSampleFilter.h b/ImageSegmentation/itkPassThroughListSampleFilter.h deleted file mode 100644 index 15da88291..000000000 --- a/ImageSegmentation/itkPassThroughListSampleFilter.h +++ /dev/null @@ -1,82 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkPassThroughListSampleFilter.h,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkPassThroughListSampleFilter_h -#define __itkPassThroughListSampleFilter_h - -#include "itkListSampleToListSampleFilter.h" - -namespace itk -{ -namespace Statistics -{ -/** \class PassThroughListSampleFilter - * \brief Simple class which pass the input to the output. - * - */ - -template -class ITK_EXPORT PassThroughListSampleFilter - : public ListSampleToListSampleFilter -{ -public: - /** - * Standard class typedefs. - */ - typedef PassThroughListSampleFilter Self; - typedef ListSampleToListSampleFilter Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** - * Standard macros - */ - itkTypeMacro( PassThroughListSampleFilter, - ListSampleToScalarListSampleFilter ); - - /** - * Method for creation through the object factory. - */ - itkNewMacro( Self ); - - /** - * Conveneient typedefs - */ - typedef TListSample ListSampleType; - typedef ListSampleType InputType; - typedef typename ListSampleType::MeasurementVectorType MeasurementVectorType; - typedef typename ListSampleType::MeasurementType MeasurementType; -protected: - PassThroughListSampleFilter(); - virtual ~PassThroughListSampleFilter(); - - void PrintSelf( std::ostream& os, Indent indent ) const; - - virtual void GenerateData(); - -private: - PassThroughListSampleFilter( const Self & ); // purposely not implemented - void operator=( const Self & ); // purposely not implemented -}; // end of class -} // end of namespace Statistics -} // end of namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkPassThroughListSampleFilter.txx" -#endif - -#endif diff --git a/ImageSegmentation/itkPassThroughListSampleFilter.txx b/ImageSegmentation/itkPassThroughListSampleFilter.txx deleted file mode 100644 index ef358e3b5..000000000 --- a/ImageSegmentation/itkPassThroughListSampleFilter.txx +++ /dev/null @@ -1,71 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkPassThroughListSampleFilter.txx,v $ - Language: C++ - Date: $Date: $ - Version: $Revision: $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkPassThroughListSampleFilter_txx -#define __itkPassThroughListSampleFilter_txx - -#include "itkPassThroughListSampleFilter.h" - -namespace itk -{ -namespace Statistics -{ -template -PassThroughListSampleFilter -::PassThroughListSampleFilter() -{ - this->AllocateOutput(); - this->GetOutput()->SetMeasurementVectorSize( - this->GetInput()->GetMeasurementVectorSize() ); -} - -template -PassThroughListSampleFilter -::~PassThroughListSampleFilter() -{ -} - -template -void -PassThroughListSampleFilter -::GenerateData() -{ - const unsigned int measurementVectorSize = - this->GetOutput()->GetMeasurementVectorSize(); - - /** - * Simply pass the input to the output. - */ - typename ListSampleType::ConstIterator It = this->GetInput()->Begin(); - while( It != this->GetInput()->End() ) - { - this->GetOutput()->PushBack( It.GetMeasurementVector() ); - ++It; - } -} - -template -void -PassThroughListSampleFilter -::PrintSelf( std::ostream& os, Indent indent ) const -{ - this->Superclass::PrintSelf( os, indent ); -} -} // end of namespace Statistics -} // end of namespace itk - -#endif diff --git a/README.txt b/README.txt index 9d197cb05..b0983c292 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -Release 1.9 --- svn release 437 +Release 1.9.1 --- svn release 595 Homepage: http://www.picsl.upenn.edu/ANTS/ @@ -30,6 +30,11 @@ segmentation and brain extracton. The ants.pdf file has more details and examples. +New Stuff 1.9.1 : + +Atropos refactored , vtk dependencies allowed , additional tools for surface-based mapping (not much tested) + + New Stuff 1.9 : Atropos revisions + various utilities. diff --git a/Utilities/itkCommandLineOption.cxx b/Utilities/itkCommandLineOption.cxx deleted file mode 100644 index d3a2b1301..000000000 --- a/Utilities/itkCommandLineOption.cxx +++ /dev/null @@ -1,89 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkCommandLineOption.cxx,v $ - Language: C++ - Date: $Date: 2009/01/22 22:48:30 $ - Version: $Revision: 1.1 $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "itkCommandLineOption.h" - -namespace itk -{ -CommandLineOption -::CommandLineOption() : m_ShortName( '\0' ), - m_LongName( "" ), - m_Description( "" ) -{ - this->m_Values.clear(); - this->m_UsageOptions.clear(); -} - -void -CommandLineOption -::AddValue( std::string value, char leftDelimiter, char rightDelimiter ) -{ - std::string::size_type leftDelimiterPos = value.find( leftDelimiter ); - std::string::size_type rightDelimiterPos = value.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 ); - } - else - { - ValueStackType parameters; - - this->m_Values.push_front( value.substr( 0, leftDelimiterPos ) ); - - std::string::size_type leftPos = leftDelimiterPos; - std::string::size_type rightPos = value.find( ',', leftPos + 1 ); - while( rightPos != std::string::npos ) - { - parameters.push_back( value.substr( leftPos + 1, rightPos - leftPos - 1 ) ); - leftPos = rightPos; - rightPos = value.find( ',', leftPos + 1 ); - } - - rightPos = rightDelimiterPos; - parameters.push_back( value.substr( leftPos + 1, rightPos - leftPos - 1 ) ); - - this->m_Parameters.push_front( parameters ); - } - - this->Modified(); -} - -void -CommandLineOption -::SetValue( unsigned int i, std::string value ) -{ - this->m_Values[i] = value; - this->Modified(); -} - -void -CommandLineOption -::SetUsageOption( unsigned int i, std::string usage ) -{ - if( i >= this->m_UsageOptions.size() ) - { - this->m_UsageOptions.resize( i + 1 ); - } - this->m_UsageOptions[i] = usage; - this->Modified(); -} -} // end namespace itk diff --git a/Utilities/itkCommandLineOption.h b/Utilities/itkCommandLineOption.h deleted file mode 100644 index 47a6eb355..000000000 --- a/Utilities/itkCommandLineOption.h +++ /dev/null @@ -1,186 +0,0 @@ -/*========================================================================= - - Program: Advanced Normalization Tools - Module: $RCSfile: itkCommandLineOption.h,v $ - Language: C++ - Date: $Date: 2009/01/22 22:48:30 $ - Version: $Revision: 1.1 $ - - Copyright (c) ConsortiumOfANTS. All rights reserved. - See accompanying COPYING.txt or - http://sourceforge.net/projects/advants/files/ANTS/ANTSCopyright.txt for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkCommandLineOption_h -#define __itkCommandLineOption_h - -#include "itkDataObject.h" -#include "itkObjectFactory.h" - -#include "itkMacro.h" -#include "itkNumericTraits.h" - -#include -#include -#include - -namespace itk -{ -/** \class CommandLineOption - \brief Simple data structure for holding command line options. - An option can have multiple values with each value holding 0 or more - parameters. E.g. suppose we were creating an image registration program - which has several transformation model options such as 'rigid', 'affine', - and 'deformable'. A instance of the command line option could have a - long name of "transformation", short name 't', and description - "Transformation model---rigid, affine, or deformable". The values for - this option would be "rigid", "affine", and "deformable". Each value - would then hold parameters that relate to that value. For example, a - possible subsection of the command line would be - - " --transformation rigid[parameter1,parameter2,etc.] - -m mutualinformation[parameter1] --optimization gradientdescent" -*/ - -class ITK_EXPORT CommandLineOption - : public DataObject -{ -public: - typedef CommandLineOption Self; - typedef DataObject Superclass; - typedef SmartPointer Pointer; - - itkNewMacro( Self ); - - itkTypeMacro( Option, DataObject ); - - typedef std::string ValueType; - typedef std::deque ValueStackType; - typedef std::deque ParameterStackType; - - ValueStackType GetValues() - { - return this->m_Values; - } - - unsigned int GetNumberOfValues() - { - return this->m_Values.size(); - } - - std::string GetValue( unsigned int i = 0 ) - { - if( i < this->m_Values.size() ) - { - return this->m_Values[i]; - } - else - { - return std::string( "" ); - } - } - - ValueStackType GetUsageOptions() - { - return this->m_UsageOptions; - } - - unsigned int GetNumberOfUsageOptions() - { - return this->m_UsageOptions.size(); - } - - std::string GetUsageOption( unsigned int i = 0 ) - { - if( i < this->m_UsageOptions.size() ) - { - return this->m_UsageOptions[i]; - } - else - { - return std::string( "" ); - } - } - - ValueStackType GetParameters( unsigned int i = 0 ) - { - if( i < this->m_Parameters.size() ) - { - return this->m_Parameters[i]; - } - else - { - ValueStackType empty; - return empty; - } - } - - std::string GetParameter( unsigned int i, unsigned int j ) - { - if( i < this->m_Parameters.size() && j < this->m_Parameters[i].size() ) - { - return this->m_Parameters[i][j]; - } - else - { - return std::string( "" ); - } - } - - std::string GetParameter( unsigned int j ) - { - return this->GetParameter( 0, j ); - } - - unsigned int GetNumberOfParameters( unsigned int i = 0 ) - { - if( i < this->m_Parameters.size() ) - { - return this->m_Parameters[i].size(); - } - else - { - return 0; - } - } - - itkSetMacro( ShortName, char ); - itkGetMacro( ShortName, char ); - - itkSetMacro( LongName, std::string ); - itkGetMacro( LongName, std::string ); - - itkSetMacro( Description, std::string ); - itkGetMacro( Description, std::string ); - - void AddValue( std::string, char, char ); - - void AddValue( std::string s ) - { - this->AddValue( s, '[', ']' ); - } - - void SetValue( unsigned int, std::string ); - - void SetUsageOption( unsigned int, std::string ); - -protected: - CommandLineOption(); - virtual ~CommandLineOption() - { - }; -private: - char m_ShortName; - std::string m_LongName; - std::string m_Description; - ValueStackType m_UsageOptions; - ValueStackType m_Values; - ParameterStackType m_Parameters; -}; -} // end namespace itk - -#endif diff --git a/Utilities/itkCommandLineParser.cxx b/Utilities/itkCommandLineParser.cxx deleted file mode 100644 index a4a50d764..000000000 --- a/Utilities/itkCommandLineParser.cxx +++ /dev/null @@ -1,535 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkCommandLineParser.cxx,v $ - Language: C++ - Date: $Date: 2009/01/22 22:43:11 $ - Version: $Revision: 1.1 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#include "itkCommandLineParser.h" - -namespace itk -{ -CommandLineParser -::CommandLineParser() -{ - this->m_Options.clear(); - this->m_Command.clear(); - this->m_CommandDescription.clear(); - this->m_UnknownOptions.clear(); - - this->m_LeftDelimiter = '['; - this->m_RightDelimiter = ']'; -} - -void -CommandLineParser -::AddOption( OptionType::Pointer option ) -{ - if( ( option->GetShortName() != '\0' || - !this->GetOption( option->GetShortName() ) ) - || ( !option->GetLongName().empty() || - !this->GetOption( option->GetLongName() ) ) ) - { - this->m_Options.push_back( option ); - } - else - { - if( option->GetShortName() != '\0' && - this->GetOption( option->GetShortName() ) ) - { - itkWarningMacro( "Duplicate short option '-" - << option->GetShortName() << "'" ); - } - if( !( option->GetLongName().empty() ) && - this->GetOption( option->GetLongName() ) ) - { - itkWarningMacro( "Duplicate long option '--" - << option->GetLongName() << "'" ); - } - } -} - -void -CommandLineParser -::Parse( unsigned int argc, char * *argv ) -{ - std::vector arguments = - this->RegroupCommandLineArguments( argc, argv ); - - unsigned int n = 0; - - this->m_Command = arguments[n++]; - - while( n < arguments.size() ) - { - std::string argument = arguments[n++]; - std::string name; - - name.clear(); - if( argument.find( "--" ) == 0 ) - { - name = argument.substr( 2, argument.length() - 1 ); - } - else if( argument.find( "-" ) == 0 && argument.find( "--" ) > 0 ) - { - name = argument.substr( 1, 2 ); - } - - if( !( name.empty() ) ) - { - OptionType::Pointer option = this->GetOption( name ); - if( !option ) - { - OptionType::Pointer unknownOption = OptionType::New(); - if( name.length() > 1 ) - { - unknownOption->SetLongName( name ); - } - else - { - unknownOption->SetShortName( name.at( 0 ) ); - } - if( n == arguments.size() ) - { - unknownOption->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); - } - else - { - for( unsigned int m = n; m < arguments.size(); m++ ) - { - std::string value = arguments[m]; - if( value.find( "-" ) != 0 ) - { - unknownOption->AddValue( value, - this->m_LeftDelimiter, this->m_RightDelimiter ); - } - else - { - if( m == n ) - { - unknownOption->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); - } - n = m; - break; - } - } - } - this->m_UnknownOptions.push_back( unknownOption ); - } - else // the option exists - { - if( n == arguments.size() ) - { - option->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); - } - else - { - for( unsigned int m = n; m < arguments.size(); m++ ) - { - std::string value = arguments[m]; - if( value.find( "-" ) != 0 ) - { - option->AddValue( value, - this->m_LeftDelimiter, this->m_RightDelimiter ); - } - else - { - if( m == n ) - { - option->AddValue( "1", - this->m_LeftDelimiter, this->m_RightDelimiter ); - } - n = m; - break; - } - } - } - } - } - } -} - -std::vector -CommandLineParser -::RegroupCommandLineArguments( unsigned int argc, char * *argv ) -{ - /** - * Inclusion of this function allows the user to use spaces inside - * the left and right delimiters. - */ - - std::vector arguments; - - std::string currentArg( "" ); - bool isArgOpen = false; - - for( unsigned int n = 0; n < argc; n++ ) - { - std::string a( argv[n] ); - - if( isArgOpen ) - { - std::size_t leftDelimiterPosition = a.find( this->m_LeftDelimiter ); - if( leftDelimiterPosition != std::string::npos ) - { - itkExceptionMacro( "Incorrect command line specification." ); - } - - std::size_t rightDelimiterPosition = a.find( this->m_RightDelimiter ); - if( rightDelimiterPosition != std::string::npos ) - { - if( rightDelimiterPosition < a.length() - 1 ) - { - itkExceptionMacro( "Incorrect command line specification." ); - } - else - { - currentArg += a; - arguments.push_back( currentArg ); - currentArg.clear(); - isArgOpen = false; - } - } - else - { - currentArg += a; - } - } - else - { - std::size_t leftDelimiterPosition = a.find( this->m_LeftDelimiter ); - std::size_t rightDelimiterPosition = a.find( this->m_RightDelimiter ); - - if( leftDelimiterPosition == std::string::npos ) - { - if( rightDelimiterPosition == std::string::npos ) - { - currentArg += a; - arguments.push_back( currentArg ); - currentArg.clear(); - } - else - { - itkExceptionMacro( "Incorrect command line specification." ); - } - } - else if( leftDelimiterPosition != std::string::npos && - rightDelimiterPosition != std::string::npos && - leftDelimiterPosition < rightDelimiterPosition ) - { - if( rightDelimiterPosition < a.length() - 1 ) - { - itkExceptionMacro( "Incorrect command line specification." ); - } - currentArg += a; - arguments.push_back( currentArg ); - currentArg.clear(); - isArgOpen = false; - } - else if( rightDelimiterPosition == std::string::npos && - leftDelimiterPosition != std::string::npos ) - { - currentArg += a; - isArgOpen = true; - } - } - } - - return arguments; -} - -CommandLineParser::OptionType::Pointer -CommandLineParser -::GetOption( std::string name ) -{ - if( name.length() == 1 ) - { - return this->GetOption( name.at( 0 ) ); - } - - OptionListType::iterator it; - for( it = this->m_Options.begin(); it != this->m_Options.end(); it++ ) - { - if( name.compare( (*it)->GetLongName() ) == 0 ) - { - return *it; - } - } - return NULL; -} - -CommandLineParser::OptionType::Pointer -CommandLineParser -::GetOption( char name ) -{ - OptionListType::iterator it; - - for( it = this->m_Options.begin(); it != this->m_Options.end(); it++ ) - { - if( name == (*it)->GetShortName() ) - { - return *it; - } - } - return NULL; -} - -void -CommandLineParser -::PrintMenu( std::ostream& os, Indent indent, bool printShortVersion ) const -{ - os << std::endl; - os << "COMMAND: " << std::endl; - os << indent << this->m_Command << std::endl; - if( !this->m_CommandDescription.empty() && !printShortVersion ) - { - std::stringstream ss1; - ss1 << indent << indent; - - std::stringstream ss2; - ss2 << this->m_CommandDescription; - - std::string description = this->BreakUpStringIntoNewLines( - ss2.str(), ss1.str(), 80 ); - - os << indent << indent << description << std::endl; - } - os << std::endl; - os << "OPTIONS: " << std::endl; - - OptionListType::const_iterator it; - for( it = this->m_Options.begin(); it != this->m_Options.end(); it++ ) - { - os << indent; - std::stringstream ss; - ss << indent; - - if( (*it)->GetShortName() != '\0' ) - { - os << "-" << (*it)->GetShortName(); - ss << Indent( 2 ); - if( !( (*it)->GetLongName() ).empty() ) - { - os << ", " << "--" << (*it)->GetLongName() << " " << std::flush; - ss << Indent( 5 + ( (*it)->GetLongName() ).length() ); - } - else - { - os << " " << std::flush; - ss << Indent( 1 ); - } - } - else - { - os << "--" << (*it)->GetLongName() << " " << std::flush; - ss << Indent( 3 + ( (*it)->GetLongName() ).length() ); - } - if( (*it)->GetNumberOfUsageOptions() > 0 ) - { - os << (*it)->GetUsageOption( 0 ) << std::endl; - for( unsigned int i = 1; i < (*it)->GetNumberOfUsageOptions(); i++ ) - { - os << ss.str() << (*it)->GetUsageOption( i ) << std::endl; - } - } - else - { - os << std::endl; - } - - if( !( (*it)->GetDescription().empty() ) && !printShortVersion ) - { - std::stringstream ss1; - ss1 << indent << indent; - - std::stringstream ss2; - ss2 << (*it)->GetDescription(); - - std::string description = this->BreakUpStringIntoNewLines( - ss2.str(), ss1.str(), 80 ); - - os << indent << indent << description << std::endl; - } - if( !printShortVersion ) - { - if( (*it)->GetValues().size() == 1 ) - { - os << indent << indent << ": " << (*it)->GetValue( 0 ); - if( (*it)->GetParameters( 0 ).size() > 0 ) - { - os << "["; - if( (*it)->GetParameters( 0 ).size() == 1 ) - { - os << (*it)->GetParameter( 0, 0 ); - } - else - { - for( unsigned int i = 0; - i < (*it)->GetParameters( 0 ).size() - 1; i++ ) - { - os << (*it)->GetParameter( 0, i ) << ","; - } - os << (*it)->GetParameter( 0, (*it)->GetParameters( 0 ).size() - 1 ); - } - os << "]"; - } - os << std::endl; - } - else if( (*it)->GetValues().size() > 1 ) - { - os << indent << indent << ": "; - for( unsigned int n = 0; n < (*it)->GetValues().size() - 1; n++ ) - { - os << (*it)->GetValue( n ); - if( (*it)->GetParameters( n ).size() > 0 ) - { - os << "["; - if( (*it)->GetParameters( n ).size() == 1 ) - { - os << (*it)->GetParameter( n, 0 ) << "], "; - } - else - { - for( unsigned int i = 0; - i < (*it)->GetParameters( n ).size() - 1; i++ ) - { - os << (*it)->GetParameter( n, i ) << ","; - } - os << (*it)->GetParameter( n, - (*it)->GetParameters( n ).size() - 1 ) << "], "; - } - } - else - { - os << ", "; - } - } - - unsigned int n = (*it)->GetValues().size() - 1; - - os << (*it)->GetValue( n ); - if( (*it)->GetParameters( n ).size() > 0 ) - { - os << "["; - if( (*it)->GetParameters( n ).size() == 1 ) - { - os << (*it)->GetParameter( n, 0 ) << "]"; - } - else - { - for( unsigned int i = 0; - i < (*it)->GetParameters( n ).size() - 1; i++ ) - { - os << (*it)->GetParameter( n, i ) << ","; - } - os << (*it)->GetParameter( n, - (*it)->GetParameters( n ).size() - 1 ) << "]"; - } - } - } - os << std::endl; - } - } -} - -std::string -CommandLineParser -::BreakUpStringIntoNewLines( std::string longString, - std::string indentString, unsigned int numberOfCharactersPerLine ) const -{ - std::vector tokens; - - this->TokenizeString( longString, tokens, " " ); - - std::string newString( "" ); - unsigned int currentTokenId = 0; - unsigned int currentLineLength = 0; - while( currentTokenId < tokens.size() ) - { - if( tokens[currentTokenId].length() >= numberOfCharactersPerLine ) - { - newString += ( std::string( "\n" ) + tokens[currentTokenId] - + std::string( "\n" ) ); - currentTokenId++; - currentLineLength = 0; - } - else if( currentTokenId < tokens.size() && currentLineLength - + tokens[currentTokenId].length() > numberOfCharactersPerLine ) - { - newString += ( std::string( "\n" ) + indentString ); - currentLineLength = 0; - } - else - { - newString += ( tokens[currentTokenId] + std::string( " " ) ); - currentLineLength += ( tokens[currentTokenId].length() + 1 ); - currentTokenId++; - } - } - - return newString; -} - -void -CommandLineParser -::TokenizeString( std::string str, std::vector & tokens, - std::string delimiters ) const -{ - // Skip delimiters at beginning. - std::string::size_type lastPos = str.find_first_not_of( delimiters, 0 ); - // Find first "non-delimiter". - std::string::size_type pos = str.find_first_of( delimiters, lastPos ); - - while( std::string::npos != pos || std::string::npos != lastPos ) - { - // Found a token, add it to the vector. - tokens.push_back( str.substr( lastPos, pos - lastPos ) ); - // Skip delimiters. Note the "not_of" - lastPos = str.find_first_not_of( delimiters, pos ); - // Find next "non-delimiter" - pos = str.find_first_of( delimiters, lastPos ); - } -} - -/** - * Standard "PrintSelf" method - */ -void -CommandLineParser -::PrintSelf( std::ostream& os, Indent indent) const -{ - Superclass::PrintSelf( os, indent ); - - os << indent << "Command: " << this->m_Command << std::endl; - os << indent << "Options: " << std::endl; - - OptionListType::const_iterator it; - for( it = this->m_Options.begin(); it != this->m_Options.end(); it++ ) - { - (*it)->Print( os, indent ); - } - - if( this->m_UnknownOptions.size() ) - { - os << indent << "Unknown Options: " << std::endl; - OptionListType::const_iterator its; - for( its = this->m_UnknownOptions.begin(); - its != this->m_UnknownOptions.end(); its++ ) - { - (*its)->Print( os, indent ); - } - } -} -} // end namespace itk diff --git a/Utilities/itkCommandLineParser.h b/Utilities/itkCommandLineParser.h deleted file mode 100644 index 0312681bf..000000000 --- a/Utilities/itkCommandLineParser.h +++ /dev/null @@ -1,163 +0,0 @@ -/*========================================================================= - - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkCommandLineParser.h,v $ - Language: C++ - Date: $Date: 2009/01/22 22:43:11 $ - Version: $Revision: 1.1 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ -#ifndef __itkCommandLineParser_h -#define __itkCommandLineParser_h - -#include "itkDataObject.h" -#include "itkObjectFactory.h" - -#include "itkCommandLineOption.h" -#include "itkMacro.h" -#include "itkNumericTraits.h" - -#include -#include -#include -#include - -namespace itk -{ -/** \class CommandLineParser - \brief Simple command line parser. - \par - Parses the standard ( argc, argv ) variables which are stored - as options in the helper class itkCommandLineOption. Also contains - routines for converting types including std::vectors using 'x' as a - delimiter. For example, I can specify the 3-element std::vector - {10, 20, 30} as "10x20x30". -*/ - -class ITK_EXPORT CommandLineParser - : public DataObject -{ -public: - /** Standard class typedefs. */ - typedef CommandLineParser Self; - typedef DataObject Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information (and related methods). */ - itkTypeMacro( CommandLineParser, DataObject ); - - typedef CommandLineOption OptionType; - typedef std::list OptionListType; - typedef std::list StringListType; - - /** - * Interface routines - */ - - OptionType::Pointer GetOption( char ); - - OptionType::Pointer GetOption( std::string ); - - void Parse( unsigned int, char * * ); - - void AddOption( OptionType::Pointer ); - - void PrintMenu( std::ostream& os, Indent indent, bool printShortVersion = false ) const; - - itkSetStringMacro( Command ); - itkGetStringMacro( Command ); - - itkSetStringMacro( CommandDescription ); - itkGetStringMacro( CommandDescription ); - - itkGetConstMacro( Options, OptionListType ); - itkGetConstMacro( UnknownOptions, OptionListType ); - - template - TValue Convert( std::string optionString ) - { - TValue value; - std::istringstream iss( optionString ); - - iss >> value; - return value; - } - - template - std::vector ConvertVector( std::string optionString ) - { - std::vector values; - std::string::size_type crosspos = optionString.find( 'x', 0 ); - - if( crosspos == std::string::npos ) - { - values.push_back( this->Convert( optionString ) ); - } - else - { - std::string element = optionString.substr( 0, crosspos ); - TValue value; - std::istringstream iss( element ); - iss >> value; - values.push_back( value ); - while( crosspos != std::string::npos ) - { - std::string::size_type crossposfrom = crosspos; - crosspos = optionString.find( 'x', crossposfrom + 1 ); - if( crosspos == std::string::npos ) - { - element = optionString.substr( - crossposfrom + 1, optionString.length() ); - } - else - { - element = optionString.substr( crossposfrom + 1, crosspos ); - } - std::istringstream iss( element ); - iss >> value; - values.push_back( value ); - } - } - return values; - } - -protected: - CommandLineParser(); - virtual ~CommandLineParser() - { - } - - void PrintSelf( std::ostream& os, Indent indent ) const; - -private: - CommandLineParser( const Self & ); // purposely not implemented - void operator=( const Self & ); // purposely not implemented - - std::vector RegroupCommandLineArguments( unsigned int, char * * ); - - std::string BreakUpStringIntoNewLines( std::string, const std::string, unsigned int ) const; - - void TokenizeString( std::string, std::vector &, std::string ) const; - - OptionListType m_Options; - std::string m_Command; - std::string m_CommandDescription; - OptionListType m_UnknownOptions; - - char m_LeftDelimiter; - char m_RightDelimiter; -}; -} // end namespace itk - -#endif