From 9a7001cd26020cc79994c973180481aa87ad14ea Mon Sep 17 00:00:00 2001 From: Thomas Greneir Date: Tue, 19 Sep 2017 17:08:59 +0200 Subject: [PATCH] - static cast for signed unsigned comparisons - csv output file cleaned --- .../itkSTMS_ImageSequenceToTemporalSet.txx | 18 +++++++-------- .../itkSTMS_TemporalSetToImageSequence.txx | 22 +++++++++---------- .../itkSTMS_BlurringSTMS.txx | 17 +++++++++----- Src/STMS_GrayLevelFiltering.cxx | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/Lib/PrePostProcessing/itkSTMS_ImageSequenceToTemporalSet.txx b/Lib/PrePostProcessing/itkSTMS_ImageSequenceToTemporalSet.txx index ed74c3c..1f55193 100755 --- a/Lib/PrePostProcessing/itkSTMS_ImageSequenceToTemporalSet.txx +++ b/Lib/PrePostProcessing/itkSTMS_ImageSequenceToTemporalSet.txx @@ -120,20 +120,18 @@ itkSTMS_ImageSequenceToTemporalSet< ImageType, MaskImageType > idx = 0; char buffer[6]; - int n = 0; + // int n = 0; // used to debug sprintf : n = sprintf( ... - if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) n=sprintf (buffer, "%05d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) n=sprintf (buffer, "%04d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) n=sprintf (buffer, "%03d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) n=sprintf (buffer, "%02d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) n=sprintf (buffer, "%01d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) sprintf (buffer, "%05d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) sprintf (buffer, "%04d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) sprintf (buffer, "%03d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) sprintf (buffer, "%02d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) sprintf (buffer, "%01d", i + stmsParameters->startTimePoint - 1); std::string imagePath = expDescription->experimentPath+expDescription->inputFolder+expDescription->inputCommonRoot+buffer+expDescription->imageExtension; - ImagePointer image - = ImageType::New(); - ReaderPointer reader - = itk::ImageFileReader< ImageType >::New(); + ImagePointer image = ImageType::New(); + ReaderPointer reader = itk::ImageFileReader< ImageType >::New(); reader->SetFileName( imagePath ); reader->Update(); diff --git a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx index 2d51318..c988bb7 100755 --- a/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx +++ b/Lib/PrePostProcessing/itkSTMS_TemporalSetToImageSequence.txx @@ -138,13 +138,13 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i ) { char buffer[6]; - int n; + // int n; - if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) n=sprintf (buffer, "%05d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) n=sprintf (buffer, "%04d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) n=sprintf (buffer, "%03d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) n=sprintf (buffer, "%02d", i + stmsParameters->startTimePoint - 1); - if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) n=sprintf (buffer, "%01d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 6 ) sprintf( buffer, "%05d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 5 ) sprintf( buffer, "%04d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 4 ) sprintf( buffer, "%03d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 3 ) sprintf( buffer, "%02d", i + stmsParameters->startTimePoint - 1); + if( sizeof(STMS_NUMBERING_FORM_ONE) == 2 ) sprintf( buffer, "%01d", i + stmsParameters->startTimePoint - 1); outputPath = expDescription->experimentPath+expDescription->outputFolder+ expDescription->outputCommonRoot+ @@ -154,15 +154,12 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > "_R-"+std::to_string(stmsParameters->rScale)+"_"+ buffer+expDescription->outputImageExtension; - ImagePointer outImage - = ImageType::New(); - + ImagePointer outImage = ImageType::New(); outImage->SetRegions( region ); outImage->Allocate(); outImage->FillBuffer( 15.0 ); - WriterPointer writer - = WriterType::New(); + WriterPointer writer = WriterType::New(); writer->SetFileName( outputPath ); //#pragma omp parrallel for ... @@ -207,13 +204,14 @@ itkSTMS_TemporalSetToImageSequence< ImageType, ClassImageType > "_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::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 << delimiter << std::count (classSet->begin(), classSet->end(), j+1); + ofs << delimiter << stmsParameters->startTimePoint << delimiter << stmsParameters->numTimePoints; for( unsigned int i=1 ; i<=stmsParameters->numTimePoints - stmsParameters->startTimePoint + 1; ++i ) ofs << delimiter << rangeSet->at(j)[i-1]*stmsParameters->rScale ; ofs << std::endl; diff --git a/Lib/SpatioTemporalMeanShift/itkSTMS_BlurringSTMS.txx b/Lib/SpatioTemporalMeanShift/itkSTMS_BlurringSTMS.txx index 8dda232..1e37fbd 100755 --- a/Lib/SpatioTemporalMeanShift/itkSTMS_BlurringSTMS.txx +++ b/Lib/SpatioTemporalMeanShift/itkSTMS_BlurringSTMS.txx @@ -60,6 +60,7 @@ #ifndef itkSTMS_BlurringSTMS_TXX #define itkSTMS_BlurringSTMS_TXX +#include #include #include #include @@ -524,7 +525,7 @@ void itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType > ::FinalMerging() { - unsigned int size = INFINITY; + unsigned int size = std::numeric_limits::max() - 1; // INFINITY; std::string imagePath = expDescription->experimentPath+expDescription->inputFolder+expDescription->inputCommonRoot+STMS_NUMBERING_FORM_ONE+expDescription->imageExtension; while(size > classSet->size()){ @@ -628,7 +629,8 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType > idx[0] = refClass->at(m)[0]+x; idx[1] = refClass->at(m)[1]+y; - if(idx[0]GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]GetBufferedRegion().GetSize()[1] && idx[1]>0) + if( ( idx[0] < static_cast(image->GetBufferedRegion().GetSize()[0]) ) && (idx[0]>0) + && (idx[1] < static_cast(image->GetBufferedRegion().GetSize()[1]) ) && (idx[1]>0) ) { if(image->GetPixel(idx) == 2) { @@ -656,7 +658,8 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType > idx[0] = candClass->at(m)[0]+x; idx[1] = candClass->at(m)[1]+y; - if(idx[0]GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]GetBufferedRegion().GetSize()[1] && idx[1]>0) + if( ( idx[0] < static_cast(image->GetBufferedRegion().GetSize()[0]) ) && ( idx[0] > 0 ) + && ( idx[1] < static_cast(image->GetBufferedRegion().GetSize()[1]) ) && ( idx[1] > 0 ) ) { if(image->GetPixel(idx) == 1) { @@ -691,7 +694,9 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType > idx[1] = refClass->at(m)[1]+y; idx[2] = refClass->at(m)[2]+z; - if(idx[0]GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]GetBufferedRegion().GetSize()[1] && idx[1]>0 && idx[2]GetBufferedRegion().GetSize()[2] && idx[2]>0) + if( ( idx[0] < static_cast(image->GetBufferedRegion().GetSize()[0]) ) && (idx[0] > 0) && + ( idx[1] < static_cast(image->GetBufferedRegion().GetSize()[1]) ) && (idx[1] > 0) && + ( idx[2] < static_cast(image->GetBufferedRegion().GetSize()[2]) ) && (idx[2] > 0) ) { if(image->GetPixel(idx) == 2) { @@ -724,7 +729,9 @@ itkSTMS_BlurringSTMS< IndexType, SpatialType, PixelType, ImageType > idx[1] = candClass->at(m)[1]+y; idx[2] = candClass->at(m)[2]+z; - if(idx[0]GetBufferedRegion().GetSize()[0] && idx[0]>0 && idx[1]GetBufferedRegion().GetSize()[1] && idx[1]>0 && idx[2]GetBufferedRegion().GetSize()[2] && idx[2]>0) + if( ( idx[0] < static_cast(image->GetBufferedRegion().GetSize()[0]) ) && ( idx[0] > 0 ) && + ( idx[1] < static_cast(image->GetBufferedRegion().GetSize()[1]) ) && ( idx[1] > 0 ) && + ( idx[2] < static_cast(image->GetBufferedRegion().GetSize()[2]) ) && ( idx[2] > 0 ) ) { if(image->GetPixel(idx) == 1) { diff --git a/Src/STMS_GrayLevelFiltering.cxx b/Src/STMS_GrayLevelFiltering.cxx index 6de7883..f999b5f 100755 --- a/Src/STMS_GrayLevelFiltering.cxx +++ b/Src/STMS_GrayLevelFiltering.cxx @@ -60,7 +60,7 @@ #include #include -#define STMS_NUMBERING_FORM_ONE "001" +#define STMS_NUMBERING_FORM_ONE "01" #include "itkImage.h" #include "itkSTMS_ArgumentsAnalysis.h" -- 2.45.0