From 899e84df04040566381e7252faa0b47d0863baca Mon Sep 17 00:00:00 2001 From: Eduardo DAVILA Date: Wed, 24 Feb 2016 21:32:49 +0100 Subject: [PATCH] #2853 BBTK Feature New Normal - std:FilesFromDirectory box add option to create list of directories --- packages/itk/src/bbitkResampleImageFilter.h | 3 + packages/std/src/bbstdFilesFromDirectory.cxx | 231 ++++++++++++++++++- packages/std/src/bbstdFilesFromDirectory.h | 26 ++- 3 files changed, 242 insertions(+), 18 deletions(-) diff --git a/packages/itk/src/bbitkResampleImageFilter.h b/packages/itk/src/bbitkResampleImageFilter.h index 65222c5..f66167a 100644 --- a/packages/itk/src/bbitkResampleImageFilter.h +++ b/packages/itk/src/bbitkResampleImageFilter.h @@ -153,8 +153,10 @@ namespace bbitk // We create an interpolator of the found type typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); filter->SetInterpolator( interpolator ); +printf("EED ResampleImageFilter NearestNeighbor \n"); } else if ( bbGetInputInterpolation() == "BSpline") { +printf("EED ResampleImageFilter BSpline \n"); typedef itk::BSplineInterpolateImageFunction < ImageType, double > InterpolatorType; // We create an interpolator of the found type typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); @@ -168,6 +170,7 @@ namespace bbitk } //end else if // Interpolation else { // if ( bbGetInputInterpolation() == "Linear" ) { +printf("EED ResampleImageFilter Linear \n"); typedef itk::LinearInterpolateImageFunction < ImageType, double > InterpolatorType; // We create an interpolator of the found type typename InterpolatorType::Pointer interpolator = InterpolatorType::New(); diff --git a/packages/std/src/bbstdFilesFromDirectory.cxx b/packages/std/src/bbstdFilesFromDirectory.cxx index fc271c2..1aefdb1 100644 --- a/packages/std/src/bbstdFilesFromDirectory.cxx +++ b/packages/std/src/bbstdFilesFromDirectory.cxx @@ -47,19 +47,20 @@ BBTK_BLACK_BOX_IMPLEMENTATION(FilesFromDirectory,bbtk::AtomicBlackBox); void FilesFromDirectory::Process() { - DirName = bbGetInputIn(); - bool rec = bbGetInputRecursive(); - /*int nbFiles = */ Explore(DirName, rec); - bbSetOutputOut(Filenames); - -// for (int i=0; id_name; + std::string temp = fileName; + if( stat(fileName.c_str(), &buf) != 0 ) + { + //gdcmErrorMacro( strerror(errno) ); + } // stat + if ( S_ISREG(buf.st_mode) ) //is it a regular file? + { + if ( d->d_name[0]!='.') + { + +/* + std::string::size_type spacePosition = temp.find_first_of(' '); + if (spacePosition != std::string::npos) + { + std::cout << "=========================================== File name : [" <d_name[0] != '.' && recursive ) //we also skip hidden files + { + if (bbGetInputType()==1) + { + Filenames.push_back(fileName); + numberOfFiles++; + } // Type All_directories + + tmpNumberOfFiles = Explore( fileName, recursive); + if ((bbGetInputType()==2)&&tmpNumberOfFiles==0) + { + Filenames.push_back(fileName); + numberOfFiles++; + } // Type Lsast_directories + numberOfFiles = numberOfFiles+tmpNumberOfFiles; + } // d_name + } else { + //gdcmErrorMacro( "Unexpected error" ); + return -1; + } // Regular FILE + } + if( closedir(dir) != 0 ) + { + //gdcmErrorMacro( strerror(errno) ); + }// closedir +#endif + + + return numberOfFiles; +} + + +//------------------------------------------------------------------------------ +void FilesFromDirectory::CleanFilenames( std::string basePath ) +{ + std::string tmpString; + int i,ii,sizeFilenames = Filenames.size(); + +// Cleanning paths with spaces + for (i=0; iFilenames[ii]) + { + tmpString=Filenames[i]; + Filenames[i]=Filenames[ii]; + Filenames[ii]=tmpString; + } // if + } // for ii + } // for i + +// Creating SimpleFilenames + unsigned int lenghtBasePath = basePath.length(); + for (i=0; id_name[0]!='.') { - std::string::size_type /* long int */ spacePosition = temp.find_first_of(' '); + std::string::size_type spacePosition = temp.find_first_of(' '); if (spacePosition != std::string::npos) { std::cout << "=========================================== File name : [" <); + BBTK_DECLARE_OUTPUT(OutSimple,std::vector); BBTK_PROCESS(Process); void Process(); private : std::string NormalizePath(std::string const &pathname); - int Explore(std::string const &dirpath, bool recursive); - + int Explore(std::string const &dirpath, bool recursive); + void CleanFilenames( std::string basePath ); + /// List of file names std::vector Filenames; + std::vector SimpleFilenames; /// name of the root directory to explore std::string DirName; }; @@ -58,14 +62,18 @@ namespace bbstd //================================================================= // BlackBox description BBTK_BEGIN_DESCRIBE_BLACK_BOX(FilesFromDirectory,bbtk::AtomicBlackBox); - BBTK_NAME("FilesFromDirectory"); - BBTK_AUTHOR("jpr@creatis.univ-lyon1.fr"); - BBTK_DESCRIPTION("returns the fullPathNames of the files in a Directory"); - BBTK_CATEGORY(""); - BBTK_INPUT(FilesFromDirectory,In,"Directory Name",std::string,""); - BBTK_INPUT(FilesFromDirectory,Recursive,"Recursive directory exploration",bool,""); + BBTK_NAME("FilesFromDirectory"); + BBTK_AUTHOR("jpr@creatis.univ-lyon1.fr"); + BBTK_DESCRIPTION("returns the fullPathNames of the files in a Directory"); + BBTK_CATEGORY(""); + + BBTK_INPUT(FilesFromDirectory,In,"Directory Name",std::string,""); + BBTK_INPUT(FilesFromDirectory,Recursive,"Recursive directory exploration",bool,""); + BBTK_INPUT(FilesFromDirectory,Type,"0=files 1=All_directories 2=last_directories (0 default)",int,""); - BBTK_OUTPUT(FilesFromDirectory,Out,"FullPathNames of the files",std::vector,""); + BBTK_OUTPUT(FilesFromDirectory,Out,"FullPathNames of the files",std::vector,""); + BBTK_OUTPUT(FilesFromDirectory,OutSimple,"Simple Full PathNames of the files",std::vector,""); + BBTK_END_DESCRIBE_BLACK_BOX(FilesFromDirectory); } -- 2.44.0