From: tbaudier Date: Wed, 4 Oct 2017 11:51:15 +0000 (+0200) Subject: Debug #54 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=09189117040bdb0c9d46a5132671567efea31632;p=clitk.git Debug #54 --- diff --git a/common/clitkCommon.cxx b/common/clitkCommon.cxx index 57be29e..d1a14bf 100644 --- a/common/clitkCommon.cxx +++ b/common/clitkCommon.cxx @@ -69,6 +69,20 @@ std::string clitk::GetExtension(const std::string& filename) } //// //------------------------------------------------------------------ + +//------------------------------------------------------------------ +// Return filename splitting in 1 or 2 parts : directory name (if exists) & filename +std::vector clitk::SplitFilename(const std::string& filename) +{ + std::vector dirname; + std::size_t found = filename.find_last_of("/\\"); + dirname.push_back(filename.substr(0,found)); + dirname.push_back(filename.substr(found+1,found)); + return( dirname ); +} //// +//------------------------------------------------------------------ + + //------------------------------------------------------------------ // Display progression void clitk::VerboseInProgress(const int nb, const int current, const int percentage) diff --git a/common/clitkCommon.h b/common/clitkCommon.h index d7cd460..3729584 100644 --- a/common/clitkCommon.h +++ b/common/clitkCommon.h @@ -99,6 +99,9 @@ namespace clitk { // Return filename extension std::string GetExtension(const std::string& filename); + // Return filename splitting in 1 or 2 parts : directory name (if exists) & filename + std::vector SplitFilename(const std::string& filename); + //-------------------------------------------------------------------- // Convert float, double ... to string template std::string toString(const T & t); diff --git a/tools/clitkDicom2Image.cxx b/tools/clitkDicom2Image.cxx index b1b105d..e08f0de 100644 --- a/tools/clitkDicom2Image.cxx +++ b/tools/clitkDicom2Image.cxx @@ -84,7 +84,7 @@ int main(int argc, char * argv[]) series_number_att.SetFromDataSet(ds); series_number = series_number_att.GetValue(); } - + series_numbers.insert(series_number); theorigin[series_number] = gdcm::ImageHelper::GetOriginValue(hreader.GetFile()); theorientation[series_number] = gdcm::ImageHelper::GetDirectionCosinesValue(hreader.GetFile()); @@ -99,7 +99,7 @@ int main(int argc, char * argv[]) theorigin[series_number][2]*n3; sliceLocations[series_number].push_back(sloc); seriesFiles[series_number].push_back(input_files[i]); - + gdcm::Attribute<0x28, 0x100> pixel_size; pixel_size.SetFromDataSet(ds); /* if (pixel_size.GetValue() != 16) @@ -118,7 +118,7 @@ int main(int argc, char * argv[]) if (args_info.extract_series_flag) { series_number = atoi(header->GetEntryValue(0x20,0x11).c_str()); } - + series_numbers.insert(series_number); theorigin[series_number].resize(3); theorigin[series_number][0] = header->GetXOrigin(); @@ -200,7 +200,7 @@ int main(int argc, char * argv[]) std::cerr << reader->GetLastError() << std::endl; return 1; } - + vvImage::Pointer image = reader->GetOutput(); vtkImageData* vtk_image = image->GetFirstVTKImageData(); vtkImageChangeInformation* modifier = vtkImageChangeInformation::New(); @@ -226,7 +226,11 @@ int main(int argc, char * argv[]) outfile = args_info.output_arg; else { std::ostringstream name; - name << *sn << "_" << args_info.output_arg; + std::vector directory = clitk::SplitFilename(args_info.output_arg); + if (directory.size() == 2) + name << directory[0] << *sn << "_" << directory[1]; + else + name << *sn << "_" << args_info.output_arg; outfile = name.str(); } //Check on transform @@ -251,9 +255,9 @@ int main(int argc, char * argv[]) writer->Update(); modifier->Delete(); - + sn++; } - + return 0; }