From f0e413c2c9e040814d7c8bf4909337d9d7b88714 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 29 Jul 2005 15:07:16 +0000 Subject: [PATCH] User may now use SetSortOrderToDirect() or SetSortOrderToReverse() to choose the ways the File* will be sorted. --- src/gdcmSerieHelper.cxx | 50 ++++++++++++++++++++++++++++++++--------- src/gdcmSerieHelper.h | 16 +++++++++++-- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/gdcmSerieHelper.cxx b/src/gdcmSerieHelper.cxx index aad62e48..cf592ea3 100644 --- a/src/gdcmSerieHelper.cxx +++ b/src/gdcmSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2005/07/21 06:39:24 $ - Version: $Revision: 1.15 $ + Date: $Date: 2005/07/29 15:07:16 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -52,6 +52,7 @@ SerieHelper::SerieHelper() delete l;; l = GetNextCoherentFileList(); } + DirectOrder = true; } /** @@ -219,7 +220,6 @@ void SerieHelper::AddGdcmFile(File *header) // Even if a rule was unmatch we don't deallocate the gdcm::File: } - /** * \brief add a rules for restricting a DICOM file to be in the serie we are * trying to find. For example you can select only the DICOM file from a @@ -457,13 +457,26 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList ) } fileList->clear(); // doesn't delete list elements, only nodes - - //VC++ don't understand what scope is !! it -> it3 - for (FileVector::const_iterator it3 = CoherentFileVector.begin(); - it3 != CoherentFileVector.end(); ++it3) - { - fileList->push_back( *it3 ); + + if (DirectOrder) + { + //VC++ don't understand what scope is !! it -> it3 + for (FileVector::const_iterator it3 = CoherentFileVector.begin(); + it3 != CoherentFileVector.end(); ++it3) + { + fileList->push_back( *it3 ); + } } + else // user asked for reverse order + { + FileVector::const_iterator it4; + it4 = CoherentFileVector.end(); + do + { + it4--; + fileList->push_back( *it4 ); + } while (it4 != CoherentFileVector.begin() ); + } distlist.clear(); CoherentFileVector.clear(); @@ -476,6 +489,10 @@ bool SerieHelper::ImageNumberLessThan(File *file1, File *file2) return file1->GetImageNumber() < file2->GetImageNumber(); } +bool SerieHelper::ImageNumberGreaterThan(File *file1, File *file2) +{ + return file1->GetImageNumber() > file2->GetImageNumber(); +} /** * \brief sorts the images, according to their Image Number * \note Works only on bona fide files (i.e image number is a character string @@ -505,7 +522,10 @@ bool SerieHelper::ImageNumberOrdering(FileList *fileList) gdcmWarningMacro( " 'Image numbers' not coherent. No ImageNumberOrdering sort performed."); return false; } - std::sort(fileList->begin(), fileList->end(), SerieHelper::ImageNumberLessThan ); + if (DirectOrder) + std::sort(fileList->begin(), fileList->end(), SerieHelper::ImageNumberLessThan ); + else + std::sort(fileList->begin(), fileList->end(), SerieHelper::ImageNumberGreaterThan ); return true; } @@ -515,6 +535,10 @@ bool SerieHelper::FileNameLessThan(File *file1, File *file2) return file1->GetFileName() < file2->GetFileName(); } +bool SerieHelper::FileNameGreaterThan(File *file1, File *file2) +{ + return file1->GetFileName() > file2->GetFileName(); +} /** * \brief sorts the images, according to their File Name * @param fileList Coherent File list (same Serie UID) to sort @@ -522,7 +546,11 @@ bool SerieHelper::FileNameLessThan(File *file1, File *file2) */ bool SerieHelper::FileNameOrdering(FileList *fileList) { - std::sort(fileList->begin(), fileList->end(), SerieHelper::FileNameLessThan); + if (DirectOrder) + std::sort(fileList->begin(), fileList->end(), SerieHelper::FileNameLessThan); + else + std::sort(fileList->begin(), fileList->end(), SerieHelper::FileNameGreaterThan); + return true; } diff --git a/src/gdcmSerieHelper.h b/src/gdcmSerieHelper.h index ef9036b8..28790ec5 100644 --- a/src/gdcmSerieHelper.h +++ b/src/gdcmSerieHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.h,v $ Language: C++ - Date: $Date: 2005/07/21 05:00:30 $ - Version: $Revision: 1.14 $ + Date: $Date: 2005/07/29 15:07:16 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -83,13 +83,21 @@ public: */ void SetLoadMode (int mode) { LoadMode = mode; } +/// Brief User wants the files to be sorted Direct Order (default value) + void SetSortOrderToDirect() { DirectOrder = true; } + +/// Brief User wants the files to be sorted Reverse Order + void SetSortOrderToReverse() { DirectOrder = false; } + private: bool ImagePositionPatientOrdering(FileList *coherentFileList); bool ImageNumberOrdering(FileList *coherentFileList); bool FileNameOrdering(FileList *coherentFileList); static bool ImageNumberLessThan(File *file1, File *file2); + static bool ImageNumberGreaterThan(File *file1, File *file2); static bool FileNameLessThan(File *file1, File *file2); + static bool FileNameGreaterThan(File *file1, File *file2); //Attributes: CoherentFileListmap CoherentFileListHT; @@ -114,6 +122,10 @@ private: /// Bit 1 : Skip Shadow Groups if possible /// Probabely, some more to add int LoadMode; + + /// \brief whether we want to sort in direct order or not (reverse order). + /// To be used by aware user only + bool DirectOrder; }; } // end namespace gdcm -- 2.45.1