1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.cxx,v $
6 Date: $Date: 2006/02/16 20:06:15 $
7 Version: $Revision: 1.47 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmSerieHelper.h"
20 #include "gdcmDirList.h"
22 #include "gdcmDictEntry.h" // for TranslateToKey
23 #include "gdcmDebug.h"
30 #include <stdio.h> //for sscanf
35 //-----------------------------------------------------------------------------
36 // Constructor / Destructor
38 * \brief Constructor from a given SerieHelper
40 SerieHelper::SerieHelper()
42 m_UseSeriesDetails = false;
44 UserLessThanFunction = 0;
49 * \brief Canonical destructor.
51 SerieHelper::~SerieHelper()
57 * \brief Preventively, clear everything at constructor time.
58 * ( use it at destructor time.)
60 void SerieHelper::ClearAll()
62 // For all the 'Single SerieUID' Filesets that may already exist
63 FileList *l = GetFirstSingleSerieUIDFileSet();
66 // For all the gdcm::File of a File set
67 for (gdcm::FileList::iterator it = l->begin();
71 (*it)->Delete(); // remove each entry
74 delete l; // remove the container
75 l = GetNextSingleSerieUIDFileSet();
77 // Need to clear that too:
78 SingleSerieUIDFileSetHT.clear();
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
87 * \brief add a gdcm::File to the Fileset corresponding to its Serie UID
88 * @param filename Name of the file to deal with
90 void SerieHelper::AddFileName(std::string const &filename)
92 // Create a DICOM file
93 File *header = File::New();
94 header->SetLoadMode(LoadMode);
95 header->SetFileName( filename );
98 if ( header->IsReadable() )
100 if ( !AddFile( header ) )
102 // at least one rule was unmatched we need to deallocate the file:
108 gdcmWarningMacro("Could not read file: " << filename );
114 * \brief add a gdcm::File to the first (and supposed to be unique) file set
115 * of the gdcm::SerieHelper.
116 * \warning : this method should be used by aware users only!
117 * Passing a gdcm::File* has the same effect than passing a file name!
118 * \todo : decide which one is wrong (the method, or the commentary)!
119 * the following comment doesn't match the method :-(
120 * User is supposed to know the files he want to deal with
121 * and consider them they belong to the same Serie
122 * (even if their Serie UID is different)
123 * user will probabely OrderFileList() this list (actually, ordering
124 * user choosen gdm::File is the sole interest of this method)
125 * Moreover, using vtkGdcmReader::SetCoherentFileList() will avoid
126 * vtkGdcmReader parsing twice the same files.
127 * *no* coherence check is performed, but those specified
128 * by SerieHelper::AddRestriction()
129 * @param header gdcm::File* of the file to deal with
130 * @return true if file was added, false if file was rejected
132 bool SerieHelper::AddFile(File *header)
135 // First step the user has defined a set of rules for the DICOM
136 // he is looking for.
137 // make sure the file correspond to his set of rules:
140 for(SerieExRestrictions::iterator it2 = ExRestrictions.begin();
141 it2 != ExRestrictions.end();
144 const ExRule &r = *it2;
145 s = header->GetEntryString( r.group, r.elem );
146 if ( !Util::CompareDicomString(s, r.value.c_str(), r.op) )
148 // Argh ! This rule is unmatched; let's just quit
154 if ( allrules ) // all rules are respected:
156 // Allright! we have a found a DICOM that matches the user expectation.
157 // Let's add it to the specific 'id' which by default is uid (Serie UID)
158 // but can be `refined` by user with more paramater (see AddRestriction(g,e))
160 std::string id = CreateUniqueSeriesIdentifier( header );
161 // if id == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
162 // no need here to do anything special
164 if ( SingleSerieUIDFileSetHT.count(id) == 0 )
166 gdcmDebugMacro(" New Serie UID :[" << id << "]");
167 // create a std::list in 'id' position
168 SingleSerieUIDFileSetHT[id] = new FileList;
170 // Current Serie UID and DICOM header seems to match add the file:
171 SingleSerieUIDFileSetHT[id]->push_back( header );
175 // one rule not matched, tell user:
182 * \brief add a rule for restricting a DICOM file to be in the serie we are
183 * trying to find. For example you can select only the DICOM files from a
184 * directory which would have a particular EchoTime==4.0.
185 * This method is a user level, value is not required to be formatted as a DICOM
187 * \todo find a trick to allow user to say if he wants the Rectrictions
188 * to be *ored* (and not only *anded*)
189 * @param key Target tag we want restrict on a given value
190 * @param value value to be checked to exclude File
191 * @param op operator we want to use to check
193 void SerieHelper::AddRestriction(TagKey const &key,
194 std::string const &value, int op)
201 ExRestrictions.push_back( r );
204 void SerieHelper::AddRestriction(TagKey const &key)
209 ExRefine.push_back( r );
212 #ifndef GDCM_LEGACY_REMOVE
214 * \brief add a rule for restricting a DICOM file to be in the serie we are
215 * trying to find. For example you can select only the DICOM files from a
216 * directory which would have a particular EchoTime==4.0.
217 * This method is a user level, value is not required to be formatted as a DICOM
219 * @param group tag group number we want restrict on a given value
220 * @param elem tag element number we want restrict on a given value
221 * @param value value to be checked to exclude File
222 * @param op operator we want to use to check
223 * @deprecated use : AddRestriction(TagKey const &key,
224 * std::string const &value, int op);
226 void SerieHelper::AddRestriction(uint16_t group, uint16_t elem,
227 std::string const &value, int op)
229 TagKey t(group, elem);
230 AddRestriction(t, value, op);
235 * \brief add an extra 'SerieDetail' for building a 'Serie Identifier'
236 * that ensures (hope so) File constistency (Series Instance UID doesn't.
237 * @param group tag group number we want restrict on a given value
238 * @param elem tag element number we want restrict on a given value
239 * @param convert wether we want 'convertion', to allow further ordering
240 * e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK
242 void SerieHelper::AddSeriesDetail(uint16_t group, uint16_t elem, bool convert)
249 ExDetails.push_back( d );
252 * \brief Sets the root Directory
253 * @param dir Name of the directory to deal with
254 * @param recursive whether we want explore recursively the root Directory
256 void SerieHelper::SetDirectory(std::string const &dir, bool recursive)
258 DirList dirList(dir, recursive); // OS specific
260 DirListType filenames_list = dirList.GetFilenames();
261 for( DirListType::const_iterator it = filenames_list.begin();
262 it != filenames_list.end(); ++it)
269 * \brief Sorts the given Fileset
270 * \warning This could be implemented in a 'Strategy Pattern' approach
271 * But as I don't know how to do it, I leave it this way
272 * BTW, this is also a Strategy, I don't know this is
273 * the best approach :)
275 void SerieHelper::OrderFileList(FileList *fileSet)
278 if ( SerieHelper::UserLessThanFunction )
280 UserOrdering( fileSet );
283 else if ( ImagePositionPatientOrdering( fileSet ) )
287 else if ( ImageNumberOrdering(fileSet ) )
293 FileNameOrdering(fileSet );
298 * \brief Elementary coherence checking of the files with the same Serie UID
299 * Only sizes and pixel type are checked right now ...
301 bool SerieHelper::IsCoherent(FileList *fileSet)
303 if(fileSet->size() == 1)
306 FileList::const_iterator it = fileSet->begin();
308 int nX = (*it)->GetXSize();
309 int nY = (*it)->GetYSize();
310 int pixelSize = (*it)->GetPixelSize();
311 bool signedPixelData = (*it)->IsSignedPixelData();
314 it != fileSet->end();
317 if ( (*it)->GetXSize() != nX )
319 if ( (*it)->GetYSize() != nY )
321 if ( (*it)->GetPixelSize() != pixelSize )
323 if ( (*it)->IsSignedPixelData() != signedPixelData )
325 // probabely more is to be checked (?)
330 #ifndef GDCM_LEGACY_REMOVE
332 * \brief accessor (DEPRECATED : use GetFirstSingleSerieUIDFileSet )
333 * Warning : 'coherent' means here they have the same Serie UID
334 * @return The first FileList if found, otherwhise NULL
336 FileList *SerieHelper::GetFirstCoherentFileList()
338 ItFileSetHt = SingleSerieUIDFileSetHT.begin();
339 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
340 return ItFileSetHt->second;
345 * \brief accessor (DEPRECATED : use GetNextSingleSerieUIDFileSet )
346 * Warning : 'coherent' means here they have the same Serie UID
347 * \note : meaningfull only if GetFirstCoherentFileList() already called
348 * @return The next FileList if found, otherwhise NULL
350 FileList *SerieHelper::GetNextCoherentFileList()
352 gdcmAssertMacro (ItFileSetHt != SingleSerieUIDFileSetHT.end());
355 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
356 return ItFileSetHt->second;
361 * \brief accessor (DEPRECATED : use GetSingleSerieUIDFileSet )
362 * Warning : 'coherent' means here they have the same Serie UID
363 * @param SerieUID SerieUID
364 * \return pointer to the FileList if found, otherwhise NULL
366 FileList *SerieHelper::GetCoherentFileList(std::string SerieUID)
368 if ( SingleSerieUIDFileSetHT.count(SerieUID) == 0 )
370 return SingleSerieUIDFileSetHT[SerieUID];
376 * \brief Get the first Fileset while visiting the SingleSerieUIDFileSetmap
377 * @return The first FileList (SingleSerieUIDFileSet) if found, otherwhise 0
379 FileList *SerieHelper::GetFirstSingleSerieUIDFileSet()
381 ItFileSetHt = SingleSerieUIDFileSetHT.begin();
382 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
383 return ItFileSetHt->second;
388 * \brief Get the next Fileset while visiting the SingleSerieUIDFileSetmap
389 * \note : meaningfull only if GetNextSingleSerieUIDFileSet() already called
390 * @return The next FileList (SingleSerieUIDFileSet) if found, otherwhise 0
392 FileList *SerieHelper::GetNextSingleSerieUIDFileSet()
394 gdcmAssertMacro (ItFileSetHt != SingleSerieUIDFileSetHT.end());
397 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
398 return ItFileSetHt->second;
403 * \brief Get the SingleSerieUIDFileSet according to its Serie UID
404 * @param SerieUID SerieUID to retrieve
405 * \return pointer to the FileList (SingleSerieUIDFileSet) if found, otherwhise 0
407 FileList *SerieHelper::GetSingleSerieUIDFileSet(std::string SerieUID)
409 if ( SingleSerieUIDFileSetHT.count(SerieUID) == 0 )
411 return SingleSerieUIDFileSetHT[SerieUID];
415 * \brief Splits a Single SerieUID Fileset according to the Orientations
416 * @param fileSet File Set to be splitted
417 * \return std::map of 'Xcoherent' File sets
420 XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
422 XCoherentFileSetmap CoherentFileSet;
424 int nb = fileSet->size();
426 return CoherentFileSet;
428 std::string strOrient;
429 std::ostringstream ossOrient;
431 FileList::const_iterator it = fileSet->begin();
434 it != fileSet->end();
437 // Information is in :
438 // 0020 0037 : Image Orientation (Patient) or
439 // 0020 0035 : Image Orientation (RET)
441 // Let's build again the 'cosines' string, to be sure of it's format
442 (*it)->GetImageOrientationPatient(iop);
445 for (int i = 1; i < 6; i++)
450 strOrient = ossOrient.str();
452 if ( CoherentFileSet.count(strOrient) == 0 )
454 gdcmDebugMacro(" New Orientation :[" << strOrient << "]");
455 // create a File set in 'orientation' position
456 CoherentFileSet[strOrient] = new FileList;
458 // Current Orientation and DICOM header match; add the file:
459 CoherentFileSet[strOrient]->push_back( (*it) );
461 return CoherentFileSet;
465 * \brief Splits a 'Single SerieUID' Fileset according to the Positions
466 * @param fileSet File Set to be splitted
467 * \return std::map of 'Xcoherent' File sets
470 XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet)
472 XCoherentFileSetmap CoherentFileSet;
474 int nb = fileSet->size();
476 return CoherentFileSet;
478 std::string strImPos; // read on disc
479 std::ostringstream ossPosition;
480 std::string strPosition; // re computed
481 FileList::const_iterator it = fileSet->begin();
484 it != fileSet->end();
487 // Information is in :
488 // 0020,0032 : Image Position Patient
489 // 0020,0030 : Image Position (RET)
491 strImPos = (*it)->GetEntryString(0x0020,0x0032);
492 if ( strImPos == GDCM_UNFOUND)
494 gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
495 strImPos = (*it)->GetEntryString(0x0020,0x0030); // For ACR-NEMA images
496 if ( strImPos == GDCM_UNFOUND )
498 gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
499 // User wants to split on the 'Position'
500 // No 'Position' info found.
501 // We return an empty Htable !
502 return CoherentFileSet;
506 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ",
507 &pos[0], &pos[1], &pos[2]) != 3 )
509 gdcmWarningMacro( "Wrong number for Position : ["
510 << strImPos << "]" );
511 return CoherentFileSet;
514 // Let's build again the 'position' string, to be sure of it's format
516 ossPosition << pos[0];
517 for (int i = 1; i < 3; i++)
520 ossPosition << pos[i];
522 strPosition = ossPosition.str();
525 if ( CoherentFileSet.count(strPosition) == 0 )
527 gdcmDebugMacro(" New Position :[" << strPosition << "]");
528 // create a File set in 'position' position
529 CoherentFileSet[strPosition] = new FileList;
531 // Current Position and DICOM header match; add the file:
532 CoherentFileSet[strPosition]->push_back( (*it) );
534 return CoherentFileSet;
538 * \brief Splits a 'Single SerieUID' File set Coherent according to the
539 * value of a given Tag
540 * @param fileSet File Set to be splitted
541 * @param group group number of the target Element
542 * @param elem element number of the target Element
543 * \return std::map of 'Xcoherent' File sets
546 XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet,
547 uint16_t group, uint16_t element)
549 XCoherentFileSetmap CoherentFileSet;
551 int nb = fileSet->size();
553 return CoherentFileSet;
555 std::string strTagValue; // read on disc
557 FileList::const_iterator it = fileSet->begin();
560 it != fileSet->end();
563 // Information is in :
564 // 0020,0032 : Image Position Patient
565 // 0020,0030 : Image Position (RET)
567 strTagValue = (*it)->GetEntryString(group,element);
569 if ( CoherentFileSet.count(strTagValue) == 0 )
571 gdcmDebugMacro(" New Tag Value :[" << strTagValue << "]");
572 // create a File set in 'position' position
573 CoherentFileSet[strTagValue] = new FileList;
575 // Current Tag value and DICOM header match; add the file:
576 CoherentFileSet[strTagValue]->push_back( (*it) );
578 return CoherentFileSet;
581 //-----------------------------------------------------------------------------
584 //-----------------------------------------------------------------------------
587 * \brief sorts the images, according to their Patient Position.
589 * We may order, considering :
590 * -# Image Position Patient
593 * -# More to come :-)
594 * \note : FileList = std::vector<File* >
595 * @param fileList Coherent File list (same Serie UID) to sort
596 * @return false only if the header is bugged !
598 bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList )
599 //based on Jolinda Smith's algorithm
601 //iop is calculated based on the file file
606 double min = 0, max = 0;
609 std::multimap<double,File *> distmultimap;
610 // Use a multimap to sort the distances from 0,0,0
611 for ( FileList::const_iterator
612 it = fileList->begin();
613 it != fileList->end(); ++it )
617 (*it)->GetImageOrientationPatient( cosines );
619 // You only have to do this once for all slices in the volume. Next,
620 // for each slice, calculate the distance along the slice normal
621 // using the IPP ("Image Position Patient") tag.
622 // ("dist" is initialized to zero before reading the first slice) :
623 normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
624 normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
625 normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
627 ipp[0] = (*it)->GetXOrigin();
628 ipp[1] = (*it)->GetYOrigin();
629 ipp[2] = (*it)->GetZOrigin();
632 for ( int i = 0; i < 3; ++i )
634 dist += normal[i]*ipp[i];
637 distmultimap.insert(std::pair<const double,File *>(dist, *it));
644 ipp[0] = (*it)->GetXOrigin();
645 ipp[1] = (*it)->GetYOrigin();
646 ipp[2] = (*it)->GetZOrigin();
649 for ( int i = 0; i < 3; ++i )
651 dist += normal[i]*ipp[i];
654 distmultimap.insert(std::pair<const double,File *>(dist, *it));
656 min = (min < dist) ? min : dist;
657 max = (max > dist) ? max : dist;
661 // Find out if min/max are coherent
664 gdcmWarningMacro("Looks like all images have the exact same image position"
665 << ". No PositionPatientOrdering sort performed" );
669 // Check to see if image shares a common position
671 for (std::multimap<double, File *>::iterator it2 = distmultimap.begin();
672 it2 != distmultimap.end();
675 if (distmultimap.count((*it2).first) != 1)
677 gdcmErrorMacro("File: "
678 << ((*it2).second->GetFileName())
681 << " position is not unique");
691 fileList->clear(); // doesn't delete list elements, only nodes
695 for (std::multimap<double, File *>::iterator it3 = distmultimap.begin();
696 it3 != distmultimap.end();
699 fileList->push_back( (*it3).second );
702 else // user asked for reverse order
704 std::multimap<double, File *>::const_iterator it4;
705 it4 = distmultimap.end();
709 fileList->push_back( (*it4).second );
710 } while (it4 != distmultimap.begin() );
713 distmultimap.clear();
718 bool SerieHelper::ImageNumberLessThan(File *file1, File *file2)
720 return file1->GetImageNumber() < file2->GetImageNumber();
723 bool SerieHelper::ImageNumberGreaterThan(File *file1, File *file2)
725 return file1->GetImageNumber() > file2->GetImageNumber();
729 * \brief sorts the images, according to their Image Number
730 * \note Works only on bona fide files (i.e image number is a character string
731 * corresponding to an integer)
732 * within a bona fide serie (i.e image numbers are consecutive)
733 * @param fileList File set (same Serie UID) to sort
734 * @return false if non bona fide stuff encountered
736 bool SerieHelper::ImageNumberOrdering(FileList *fileList)
739 int n = fileList->size();
741 FileList::const_iterator it = fileList->begin();
742 min = max = (*it)->GetImageNumber();
744 for (; it != fileList->end(); ++it, ++n)
746 pos = (*it)->GetImageNumber();
747 min = (min < pos) ? min : pos;
748 max = (max > pos) ? max : pos;
751 // Find out if image numbers are coherent (consecutive)
752 if ( min == max || max == 0 || max >= (n+min) )
754 gdcmWarningMacro( " 'Image numbers' not coherent. "
755 << " No ImageNumberOrdering sort performed.");
759 Sort(fileList,SerieHelper::ImageNumberLessThan);
761 Sort(fileList,SerieHelper::ImageNumberGreaterThan);
766 bool SerieHelper::FileNameLessThan(File *file1, File *file2)
768 return file1->GetFileName() < file2->GetFileName();
771 bool SerieHelper::FileNameGreaterThan(File *file1, File *file2)
773 return file1->GetFileName() > file2->GetFileName();
776 * \brief sorts the images, according to their File Name
777 * @param fileList Coherent File list (same Serie UID) to sort
778 * @return false only if the header is bugged !
780 bool SerieHelper::FileNameOrdering(FileList *fileList)
783 Sort(fileList,SerieHelper::FileNameLessThan);
785 Sort(fileList,SerieHelper::FileNameGreaterThan);
791 * \brief sorts the images, according to user supplied function
792 * @param fileList Coherent File list (same Serie UID) to sort
793 * @return false only if the header is bugged !
795 bool SerieHelper::UserOrdering(FileList *fileList)
797 Sort(fileList,SerieHelper::UserLessThanFunction);
800 std::reverse(fileList->begin(), fileList->end());
805 //-----------------------------------------------------------------------------
808 * \brief Canonical printer.
810 void SerieHelper::Print(std::ostream &os, std::string const &indent)
812 // For all the Coherent File lists of the gdcm::Serie
813 SingleSerieUIDFileSetmap::iterator itl = SingleSerieUIDFileSetHT.begin();
814 if ( itl == SingleSerieUIDFileSetHT.end() )
816 gdcmWarningMacro( "No SingleSerieUID File set found" );
819 while (itl != SingleSerieUIDFileSetHT.end())
821 os << "Serie UID :[" << itl->first << "]" << std::endl;
823 // For all the files of a SingleSerieUID File set
824 for (FileList::iterator it = (itl->second)->begin();
825 it != (itl->second)->end();
828 os << indent << " --- " << (*it)->GetFileName() << std::endl;
834 void SerieHelper::CreateDefaultUniqueSeriesIdentifier()
836 // If the user requests, additional information can be appended
837 // to the SeriesUID to further differentiate volumes in the DICOM
838 // objects being processed.
840 // 0020 0011 Series Number
841 // A scout scan prior to a CT volume scan can share the same
842 // SeriesUID, but they will sometimes have a different Series Number
843 AddRestriction( TagKey(0x0020, 0x0011) );
844 // 0018 0024 Sequence Name
845 // For T1-map and phase-contrast MRA, the different flip angles and
846 // directions are only distinguished by the Sequence Name
847 AddRestriction( TagKey(0x0018, 0x0024) );
848 // 0018 0050 Slice Thickness
849 // On some CT systems, scout scans and subsequence volume scans will
850 // have the same SeriesUID and Series Number - YET the slice
851 // thickness will differ from the scout slice and the volume slices.
852 AddRestriction( TagKey(0x0018, 0x0050));
854 // If the 2D images in a sequence don't have the same number of rows,
855 // then it is difficult to reconstruct them into a 3D volume.
856 AddRestriction( TagKey(0x0028, 0x0010));
858 // If the 2D images in a sequence don't have the same number of columns,
859 // then it is difficult to reconstruct them into a 3D volume.
860 AddRestriction( TagKey(0x0028, 0x0011));
864 * \brief Heuristics to *try* to build a Serie Identifier that would ensure
865 * all the images are coherent.
867 * By default, uses the SeriesUID. If UseSeriesDetails(true) has been called,
868 * then additional identifying information is used.
869 * We allow user to add his own critierions, using AddSeriesDetail
870 * (he knows more than we do about his images!)
871 * ex : in tagging series, the only pertnent tag is
872 * 0018|1312 [In-plane Phase Encoding Direction] value : ROW/COLUMN
873 * @param inFile gdcm::File we want to build a Serie Identifier for.
874 * @return the SeriesIdentifier
876 std::string SerieHelper::CreateUniqueSeriesIdentifier( File *inFile )
878 if( inFile->IsReadable() )
880 // 0020 000e UI REL Series Instance UID
881 std::string uid = inFile->GetEntryString (0x0020, 0x000e);
882 std::string id = uid.c_str();
883 if(m_UseSeriesDetails)
885 for(SerieExRestrictions::iterator it2 = ExRefine.begin();
886 it2 != ExRefine.end();
889 const ExRule &r = *it2;
890 std::string s = inFile->GetEntryString( r.group, r.elem );
891 if( s == gdcm::GDCM_UNFOUND )
895 if( id == uid && !s.empty() )
897 id += "."; // add separator
902 // Eliminate non-alnum characters, including whitespace...
903 // that may have been introduced by concats.
904 for(unsigned int i=0; i<id.size(); i++)
908 || (id[i] >= 'a' && id[i] <= 'z')
909 || (id[i] >= '0' && id[i] <= '9')
910 || (id[i] >= 'A' && id[i] <= 'Z')))
917 else // Could not open inFile
919 gdcmWarningMacro("Could not parse series info.");
920 std::string id = gdcm::GDCM_UNFOUND;
926 * \brief Allow user to build is own File Identifier (to be able to sort
927 * temporal series just as he wants)
928 * Criterions will be set with AddSeriesDetail.
929 * (Maybe the method should be moved elsewhere
930 * -File class? FileHelper class?-
931 * @return FileIdentifier (Tokenizable on '%%%'. Hope it's enough !)
933 std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile )
935 // Deal with all user supplied tags.
936 // (user knows more than we do about his images!)
941 char charConverted[17];
943 for(SeriesExDetails::iterator it2 = ExDetails.begin();
944 it2 != ExDetails.end();
947 const ExDetail &r = *it2;
948 s = inFile->GetEntryString( r.group, r.elem );
950 // User is allowed to ask 'convertion', to allow further ordering
951 // e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK
954 if ( s != GDCM_UNFOUND) // Don't convert unfound fields !
956 converted = atof(s.c_str());
957 // probabely something much more complicated is possible,
958 // using C++ features
959 /// \todo check the behaviour when there are >0 and <0 numbers
960 sprintf(charConverted, "%016.6f",converted);
964 // Eliminate non-alphanum characters, including whitespace.
965 for(unsigned int i=0; i<s.size(); i++)
968 && !( s[i] == '.' || s[i] == '%'
969 || (s[i] >= 'a' && s[i] <= 'z')
970 || (s[i] >= '0' && s[i] <= '9')
971 || (s[i] >= 'A' && s[i] <= 'Z')))
978 id += "%%%"; // make the FileIdentifier Tokenizable
984 //-----------------------------------------------------------------------------
987 * \brief Sort FileList.
989 void SerieHelper::Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) )
991 std::sort(fileList->begin(), fileList->end(), pt2Func );
994 //-----------------------------------------------------------------------------
995 } // end namespace gdcm