From 06d646fa83dc002ad793814d37004ad72f126ca7 Mon Sep 17 00:00:00 2001 From: Grenier Thomas Date: Wed, 19 Jul 2017 19:05:48 +0200 Subject: [PATCH] Adding CSV file generation --- .../itkSTMS_TemporalSetToImageSequence.h | 2 ++ .../itkSTMS_TemporalSetToImageSequence.txx | 36 +++++++++++++++++-- Lib/PrePostProcessing/itkSTMS_XMLFileParser.h | 1 + .../itkSTMS_XMLFileParser.hxx | 10 +++++- Src/STMS_GrayLevelFiltering.cxx | 6 +++- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h index dd93ea4..7c5e586 100755 --- a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h +++ b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.h @@ -62,6 +62,7 @@ #include #include +#include #include #include "itkImage.h" @@ -120,6 +121,7 @@ namespace itkSTMS itkSTMS::ParserOutputType* desc ); void GenerateImageSequence(); + void GenerateCSVFile(); private: // Attributes diff --git a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx index 698e3ae..f5a00e9 100755 --- a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx +++ b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx @@ -127,7 +127,7 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > "_Class_X-"+std::to_string((unsigned int)stmsParameters->spScales[0])+ "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+ "_Z-"+std::to_string((unsigned int)stmsParameters->spScales[2])+ - "_R-"+std::to_string(stmsParameters->rScale)+"_"+ + "_R-"+std::to_string(stmsParameters->rScale)+ expDescription->outputImageExtension; ClassWriterPointer classWriter @@ -135,8 +135,8 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > classWriter->SetFileName( classPath ); // Filetered image sequence and class image saving - for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i ){ - + for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i ) + { char buffer[6]; int n; @@ -194,6 +194,36 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > } } + +template < class ImageType, class ClassImageType> +void +itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > +::GenerateCSVFile() +{ + std::string CSVFilename = expDescription->experimentPath+expDescription->outputFolder+ + expDescription->outputCommonRoot+ + "_X-"+std::to_string((unsigned int)stmsParameters->spScales[0])+ + "_Y-"+std::to_string((unsigned int)stmsParameters->spScales[1])+ + "_Z-"+std::to_string((unsigned int)stmsParameters->spScales[2])+ + "_R-"+std::to_string(stmsParameters->rScale)+".csv"; + + std::cout << "Writing CSV File (classID, nb of pixels, values of time serie), : " << CSVFilename << std::endl; + std::ofstream ofs; + ofs.open (CSVFilename.c_str(), std::ofstream::out | std::ofstream::trunc); + + for(unsigned int j=0 ; jsize() ; ++j) + { + ofs << j+1 <<", " << std::count (classSet->begin(), classSet->end(), j+1); + for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i ) + ofs << ", " << rangeSet->at(j)[i-1]*stmsParameters->rScale ; + ofs << std::endl; + } + + ofs.close(); + +} + + } // end of namespace itkSTMS #endif diff --git a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h index 0c3589e..7bc7b18 100755 --- a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h +++ b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.h @@ -75,6 +75,7 @@ namespace itkSTMS std::string maskImage; std::string outputFolder; std::string outputCommonRoot; + std::string outputCSV; }; diff --git a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx index 1bb4c27..191adb3 100755 --- a/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx +++ b/Lib/PrePostProcessing/itkSTMS_XMLFileParser.hxx @@ -74,6 +74,7 @@ itkSTMS_XMLFileParser::itkSTMS_XMLFileParser() xmlParams.maskImage = ""; xmlParams.outputFolder = ""; xmlParams.outputCommonRoot = ""; + xmlParams.outputCSV = ""; } @@ -108,7 +109,7 @@ void itkSTMS_XMLFileParser::Update() xmlParams.outputImageExtension = DomObject->GetAttribute( "outputImageExtension" ); if ( xmlParams.outputImageExtension == "" ) { - std::cout << std::endl << std::endl << "outputImageExtension not found" << std::endl << std::endl; + std::cout << std::endl << std::endl << "outputImageExtension not set" << std::endl << std::endl; std::exit( EXIT_FAILURE ); } @@ -150,6 +151,13 @@ void itkSTMS_XMLFileParser::Update() std::cout << std::endl << std::endl << "outputCommonRoot not found" << std::endl << std::endl; std::exit( EXIT_FAILURE ); } + + xmlParams.outputCSV = listOutput->GetAttribute( "outputCSV" ); + if ( xmlParams.outputCSV == "" ) + { + std::cout << std::endl << std::endl << "outputCSV not set: no CSV file will be created" << std::endl << std::endl; + } + } } // end of namespace itkSTMS #endif // itkSTMS_XMLFileParser_HXX diff --git a/Src/STMS_GrayLevelFiltering.cxx b/Src/STMS_GrayLevelFiltering.cxx index d2bcb3d..7f2cd02 100755 --- a/Src/STMS_GrayLevelFiltering.cxx +++ b/Src/STMS_GrayLevelFiltering.cxx @@ -60,7 +60,7 @@ #include #include -#define STMS_NUMBERING_FORM_ONE "01" +#define STMS_NUMBERING_FORM_ONE "001" #include "itkImage.h" #include "itkSTMS_ArgumentsAnalysis.h" @@ -161,6 +161,8 @@ int main(int argc, char **argv){ preProcess->GetExperimentDescription()); postProcess->GenerateImageSequence(); + if(preProcess->GetExperimentDescription()->outputCSV == "true" ) + postProcess->GenerateCSVFile( ); dtime = gettime_hp()-dtime; std::cout<GetExperimentDescription()); postProcess->GenerateImageSequence(); + if(preProcess->GetExperimentDescription()->outputCSV == "true" ) + postProcess->GenerateCSVFile(); dtime = gettime_hp()-dtime; std::cout<