1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.cxx,v $
6 Date: $Date: 2005/12/21 14:48:09 $
7 Version: $Revision: 1.41 $
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
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 // Constructor / Destructor
39 * \brief Constructor from a given SerieHelper
41 SerieHelper::SerieHelper()
43 m_UseSeriesDetails = false;
45 UserLessThanFunction = 0;
50 * \brief Canonical destructor.
52 SerieHelper::~SerieHelper()
58 * \brief Preventively, clear everything at constructor time.
59 * ( use it at destructor time.)
61 void SerieHelper::ClearAll()
63 // For all the 'Single SerieUID' Filesets that may already exist
64 FileList *l = GetFirstSingleSerieUIDFileSet();
67 // For all the gdcm::File of a File set
68 for (gdcm::FileList::iterator it = l->begin();
72 (*it)->Delete(); // remove each entry
75 delete l; // remove the container
76 l = GetNextSingleSerieUIDFileSet();
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
86 * \brief add a gdcm::File to the Fileset corresponding to its Serie UID
87 * @param filename Name of the file to deal with
89 void SerieHelper::AddFileName(std::string const &filename)
91 // Create a DICOM file
92 File *header = File::New();
93 header->SetLoadMode(LoadMode);
94 header->SetFileName( filename );
97 if ( header->IsReadable() )
100 // First step : the user defined a set of rules for the DICOM file
101 // he is looking for.
102 // Make sure the file corresponds to his set of rules:
105 for(SerieExRestrictions::iterator it2 = ExRestrictions.begin();
106 it2 != ExRestrictions.end();
109 const ExRule &r = *it2;
110 s = header->GetEntryString( r.group, r.elem );
111 if ( !Util::CompareDicomString(s, r.value.c_str(), r.op) )
113 // Argh ! This rule is unmatched; let's just quit
120 if ( allrules ) // all rules are respected:
122 // Allright! we have a found a DICOM that matches the user expectation.
125 // 0020 000e UI REL Series Instance UID
126 const std::string &uid = header->GetEntryString(0x0020, 0x000e);
127 // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
128 // no need here to do anything special
131 if ( SingleSerieUIDFileSetHT.count(uid) == 0 )
133 gdcmDebugMacro(" New Serie UID :[" << uid << "]");
134 // create a std::list in 'uid' position
135 SingleSerieUIDFileSetHT[uid] = new FileList;
137 // Current Serie UID and DICOM header seems to match; add the file:
138 SingleSerieUIDFileSetHT[uid]->push_back( header );
142 // at least one rule was unmatched we need to deallocate the file:
148 gdcmWarningMacro("Could not read file: " << filename );
154 * \brief add a gdcm::File to the first (and supposed to be unique) file set
155 * of the gdcm::SerieHelper.
156 * \warning : this method should be used by aware users only!
157 * Passing a gdcm::File* has the same effect than passing a file name!
158 * \todo : decide which one is wrong (the method, or the commentary)!
159 * the following comment doesn't match the method :-(
160 * User is supposed to know the files he want to deal with
161 * and consider them they belong to the same Serie
162 * (even if their Serie UID is different)
163 * user will probabely OrderFileList() this list (actually, ordering
164 * user choosen gdm::File is the sole interest of this method)
165 * Moreover, using vtkGdcmReader::SetCoherentFileList() will avoid
166 * vtkGdcmReader parsing twice the same files.
167 * *no* coherence check is performed, but those specified
168 * by SerieHelper::AddRestriction()
169 * @param header gdcm::File* of the file to deal with
171 void SerieHelper::AddGdcmFile(File *header)
174 // First step the user has defined a set of rules for the DICOM
175 // he is looking for.
176 // make sure the file correspond to his set of rules:
177 for(SerieRestrictions::iterator it = Restrictions.begin();
178 it != Restrictions.end();
182 const std::string s;// = header->GetEntryString( r.first );
183 if ( !Util::DicomStringEqual(s, r.second.c_str()) )
185 // Argh ! This rule is unmatch let's just quit
190 if ( allrules ) // all rules are respected:
192 // Allright ! we have a found a DICOM that match the user expectation.
195 const std::string &uid = "0";
196 // Serie UID of the gdcm::File* may be different.
197 // User is supposed to know what he wants
199 if ( SingleSerieUIDFileSetHT.count(uid) == 0 )
201 gdcmDebugMacro(" New Serie UID :[" << uid << "]");
202 // create a std::list in 'uid' position
203 SingleSerieUIDFileSetHT[uid] = new FileList;
205 // Current Serie UID and DICOM header seems to match; add the file:
206 SingleSerieUIDFileSetHT[uid]->push_back( header );
208 // Even if a rule was unmatch we don't deallocate the gdcm::File:
212 * \brief add a rule for restricting a DICOM file to be in the serie we are
213 * trying to find. For example you can select only the DICOM files from a
214 * directory which would have a particular EchoTime==4.0.
215 * This method is a user level, value is not required to be formatted as a DICOM
217 * \todo find a trick to allow user to say if he wants the Rectrictions
218 * to be *ored* (and not only *anded*)
219 * @param key Target tag we want restrict on a given value
220 * @param value value to be checked to exclude File
221 * @param op operator we want to use to check
223 void SerieHelper::AddRestriction(TagKey const &key,
224 std::string const &value, int op)
231 ExRestrictions.push_back( r );
235 * \brief add a rule for restricting a DICOM file to be in the serie we are
236 * trying to find. For example you can select only the DICOM file from a
237 * directory which would have a particular EchoTime==4.0.
238 * This method is a user level, value is not required to be formatted as a DICOM
240 * \todo find a trick to allow user if he wants the Rectrictions to be *ored*
241 * (and not only *anded*)
242 * @param group tag group number we want restrict on a given value
243 * @param elem tag element number we want restrict on a given value
244 * @param value value to be checked to exclude File
245 * @param op operator we want to use to check
247 void SerieHelper::AddRestriction(uint16_t group, uint16_t elem,
248 std::string const &value, int op)
255 ExRestrictions.push_back( r );
259 * \brief add an extra 'SerieDetail' for building a 'Serie Identifier'
260 * that ensures (hope so) File constistency (Series Instance UID doesn't.
261 * @param group tag group number we want restrict on a given value
262 * @param elem tag element number we want restrict on a given value
263 * @param convert wether we want 'convertion', to allow further ordering
264 * e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK
266 void SerieHelper::AddSeriesDetail(uint16_t group, uint16_t elem, bool convert)
273 ExDetails.push_back( d );
276 * \brief Sets the root Directory
277 * @param dir Name of the directory to deal with
278 * @param recursive whether we want explore recursively the root Directory
280 void SerieHelper::SetDirectory(std::string const &dir, bool recursive)
282 DirList dirList(dir, recursive); // OS specific
284 DirListType filenames_list = dirList.GetFilenames();
285 for( DirListType::const_iterator it = filenames_list.begin();
286 it != filenames_list.end(); ++it)
293 * \brief Sorts the given Fileset
294 * \warning This could be implemented in a 'Strategy Pattern' approach
295 * But as I don't know how to do it, I leave it this way
296 * BTW, this is also a Strategy, I don't know this is
297 * the best approach :)
299 void SerieHelper::OrderFileList(FileList *fileSet)
302 if ( SerieHelper::UserLessThanFunction )
304 UserOrdering( fileSet );
307 else if ( ImagePositionPatientOrdering( fileSet ) )
311 else if ( ImageNumberOrdering(fileSet ) )
317 FileNameOrdering(fileSet );
322 * \brief Elementary coherence checking of the files with the same Serie UID
323 * Only sizes and pixel type are checked right now ...
325 bool SerieHelper::IsCoherent(FileList *fileSet)
327 if(fileSet->size() == 1)
330 FileList::const_iterator it = fileSet->begin();
332 int nX = (*it)->GetXSize();
333 int nY = (*it)->GetYSize();
334 int pixelSize = (*it)->GetPixelSize();
335 bool signedPixelData = (*it)->IsSignedPixelData();
338 it != fileSet->end();
341 if ( (*it)->GetXSize() != nX )
343 if ( (*it)->GetYSize() != nY )
345 if ( (*it)->GetPixelSize() != pixelSize )
347 if ( (*it)->IsSignedPixelData() != signedPixelData )
349 // probabely more is to be checked (?)
354 #ifndef GDCM_LEGACY_REMOVE
356 FileList *SerieHelper::GetFirstCoherentFileList()
358 ItFileSetHt = SingleSerieUIDFileSetHT.begin();
359 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
360 return ItFileSetHt->second;
365 FileList *SerieHelper::GetNextCoherentFileList()
367 gdcmAssertMacro (ItFileSetHt != SingleSerieUIDFileSetHT.end());
370 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
371 return ItFileSetHt->second;
376 FileList *SerieHelper::GetCoherentFileList(std::string SerieUID)
378 if ( SingleSerieUIDFileSetHT.count(SerieUID) == 0 )
380 return SingleSerieUIDFileSetHT[SerieUID];
386 * \brief Get the first Fileset while visiting the SingleSerieUIDFileSetmap
387 * @return The first FileList (SingleSerieUIDFileSet) if found, otherwhise 0
389 FileList *SerieHelper::GetFirstSingleSerieUIDFileSet()
391 ItFileSetHt = SingleSerieUIDFileSetHT.begin();
392 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
393 return ItFileSetHt->second;
398 * \brief Get the next Fileset while visiting the SingleSerieUIDFileSetmap
399 * \note : meaningfull only if GetNextSingleSerieUIDFileSet() already called
400 * @return The next FileList (SingleSerieUIDFileSet) if found, otherwhise 0
402 FileList *SerieHelper::GetNextSingleSerieUIDFileSet()
404 gdcmAssertMacro (ItFileSetHt != SingleSerieUIDFileSetHT.end());
407 if ( ItFileSetHt != SingleSerieUIDFileSetHT.end() )
408 return ItFileSetHt->second;
413 * \brief Get the SingleSerieUIDFileSet according to its Serie UID
414 * @param SerieUID SerieUID to retrieve
415 * \return pointer to the FileList (SingleSerieUIDFileSet) if found, otherwhise 0
417 FileList *SerieHelper::GetSingleSerieUIDFileSet(std::string SerieUID)
419 if ( SingleSerieUIDFileSetHT.count(SerieUID) == 0 )
421 return SingleSerieUIDFileSetHT[SerieUID];
425 * \brief Splits a Single SerieUID Fileset according to the Orientations
426 * @param fileSet File Set to be splitted
427 * \return std::map of 'Xcoherent' File sets
430 XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
432 XCoherentFileSetmap CoherentFileSet;
434 int nb = fileSet->size();
436 return CoherentFileSet;
439 std::string strOrient;
440 std::ostringstream ossOrient;
441 FileList::const_iterator it = fileSet->begin();
444 it != fileSet->end();
447 // Information is in :
448 // 0020 0037 : Image Orientation (Patient) or
449 // 0020 0035 : Image Orientation (RET)
451 // Let's build again the 'cosines' string, to be sure of it's format
452 (*it)->GetImageOrientationPatient(iop);
455 for (int i = 1; i < 6; i++)
460 strOrient = ossOrient.str();
462 // FIXME : is it a 'cleaner' way to initialize an ostringstream?
464 if ( CoherentFileSet.count(strOrient) == 0 )
466 gdcmDebugMacro(" New Orientation :[" << strOrient << "]");
467 // create a File set in 'orientation' position
468 CoherentFileSet[strOrient] = new FileList;
470 // Current Orientation and DICOM header match; add the file:
471 CoherentFileSet[strOrient]->push_back( (*it) );
473 return CoherentFileSet;
477 * \brief Splits a 'Single SerieUID' Fileset according to the Positions
478 * @param fileSet File Set to be splitted
479 * \return std::map of 'Xcoherent' File sets
482 XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet)
484 XCoherentFileSetmap CoherentFileSet;
486 int nb = fileSet->size();
488 return CoherentFileSet;
490 std::string strImPos; // read on disc
491 std::ostringstream ossPosition;
492 std::string strPosition; // re computed
493 FileList::const_iterator it = fileSet->begin();
496 it != fileSet->end();
499 // Information is in :
500 // 0020,0032 : Image Position Patient
501 // 0020,0030 : Image Position (RET)
503 strImPos = (*it)->GetEntryString(0x0020,0x0032);
504 if ( strImPos == GDCM_UNFOUND)
506 gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
507 strImPos = (*it)->GetEntryString(0x0020,0x0030); // For ACR-NEMA images
508 if ( strImPos == GDCM_UNFOUND )
510 gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
511 // User wants to split on the 'Position'
512 // No 'Position' info found.
513 // We return an empty Htable !
514 return CoherentFileSet;
518 if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ",
519 &pos[0], &pos[1], &pos[2]) != 3 )
521 gdcmWarningMacro( "Wrong number for Position : ["
522 << strImPos << "]" );
523 return CoherentFileSet;
526 // Let's build again the 'position' string, to be sure of it's format
528 ossPosition << pos[0];
529 for (int i = 1; i < 3; i++)
532 ossPosition << pos[i];
534 strPosition = ossPosition.str();
537 if ( CoherentFileSet.count(strPosition) == 0 )
539 gdcmDebugMacro(" New Position :[" << strPosition << "]");
540 // create a File set in 'position' position
541 CoherentFileSet[strPosition] = new FileList;
543 // Current Position and DICOM header match; add the file:
544 CoherentFileSet[strPosition]->push_back( (*it) );
546 return CoherentFileSet;
550 * \brief Splits a 'Single SerieUID' File set Coherent according to the
551 * value of a given Tag
552 * @param fileSet File Set to be splitted
553 * @param group group number of the target Element
554 * @param elem element number of the target Element
555 * \return std::map of 'Xcoherent' File sets
558 XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet,
559 uint16_t group, uint16_t elem)
561 XCoherentFileSetmap CoherentFileSet;
563 int nb = fileSet->size();
565 return CoherentFileSet;
567 std::string strTagValue; // read on disc
569 FileList::const_iterator it = fileSet->begin();
572 it != fileSet->end();
575 // Information is in :
576 // 0020,0032 : Image Position Patient
577 // 0020,0030 : Image Position (RET)
579 strTagValue = (*it)->GetEntryString(group,elem);
581 if ( CoherentFileSet.count(strTagValue) == 0 )
583 gdcmDebugMacro(" New Tag Value :[" << strTagValue << "]");
584 // create a File set in 'position' position
585 CoherentFileSet[strTagValue] = new FileList;
587 // Current Tag value and DICOM header match; add the file:
588 CoherentFileSet[strTagValue]->push_back( (*it) );
590 return CoherentFileSet;
593 //-----------------------------------------------------------------------------
596 //-----------------------------------------------------------------------------
599 * \brief sorts the images, according to their Patient Position.
601 * We may order, considering :
602 * -# Image Position Patient
605 * -# More to come :-)
606 * \note : FileList = std::vector<File* >
607 * @param fileList Coherent File list (same Serie UID) to sort
608 * @return false only if the header is bugged !
610 bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList )
611 //based on Jolinda Smith's algorithm
613 //iop is calculated based on the file file
618 double min = 0, max = 0;
621 std::multimap<double,File *> distmultimap;
622 // Use a multimap to sort the distances from 0,0,0
623 for ( FileList::const_iterator
624 it = fileList->begin();
625 it != fileList->end(); ++it )
629 (*it)->GetImageOrientationPatient( cosines );
631 // You only have to do this once for all slices in the volume. Next,
632 // for each slice, calculate the distance along the slice normal
633 // using the IPP ("Image Position Patient") tag.
634 // ("dist" is initialized to zero before reading the first slice) :
635 normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
636 normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
637 normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
639 ipp[0] = (*it)->GetXOrigin();
640 ipp[1] = (*it)->GetYOrigin();
641 ipp[2] = (*it)->GetZOrigin();
644 for ( int i = 0; i < 3; ++i )
646 dist += normal[i]*ipp[i];
649 distmultimap.insert(std::pair<const double,File *>(dist, *it));
656 ipp[0] = (*it)->GetXOrigin();
657 ipp[1] = (*it)->GetYOrigin();
658 ipp[2] = (*it)->GetZOrigin();
661 for ( int i = 0; i < 3; ++i )
663 dist += normal[i]*ipp[i];
666 distmultimap.insert(std::pair<const double,File *>(dist, *it));
668 min = (min < dist) ? min : dist;
669 max = (max > dist) ? max : dist;
674 // Find out if min/max are coherent
677 gdcmWarningMacro("Looks like all images have the exact same image position"
678 << ". No PositionPatientOrdering sort performed" );
682 // Check to see if image shares a common position
684 for (std::multimap<double, File *>::iterator it2 = distmultimap.begin();
685 it2 != distmultimap.end();
688 if (distmultimap.count((*it2).first) != 1)
690 gdcmErrorMacro("File: "
691 << ((*it2).second->GetFileName())
694 << " position is not unique");
703 fileList->clear(); // doesn't delete list elements, only nodes
707 for (std::multimap<double, File *>::iterator it3 = distmultimap.begin();
708 it3 != distmultimap.end();
711 fileList->push_back( (*it3).second );
714 else // user asked for reverse order
716 std::multimap<double, File *>::const_iterator it4;
717 it4 = distmultimap.end();
721 fileList->push_back( (*it4).second );
722 } while (it4 != distmultimap.begin() );
725 distmultimap.clear();
730 bool SerieHelper::ImageNumberLessThan(File *file1, File *file2)
732 return file1->GetImageNumber() < file2->GetImageNumber();
735 bool SerieHelper::ImageNumberGreaterThan(File *file1, File *file2)
737 return file1->GetImageNumber() > file2->GetImageNumber();
741 * \brief sorts the images, according to their Image Number
742 * \note Works only on bona fide files (i.e image number is a character string
743 * corresponding to an integer)
744 * within a bona fide serie (i.e image numbers are consecutive)
745 * @param fileList File set (same Serie UID) to sort
746 * @return false if non bona fide stuff encountered
748 bool SerieHelper::ImageNumberOrdering(FileList *fileList)
751 int n = fileList->size();
753 FileList::const_iterator it = fileList->begin();
754 min = max = (*it)->GetImageNumber();
756 for (; it != fileList->end(); ++it, ++n)
758 pos = (*it)->GetImageNumber();
759 min = (min < pos) ? min : pos;
760 max = (max > pos) ? max : pos;
763 // Find out if image numbers are coherent (consecutive)
764 if ( min == max || max == 0 || max >= (n+min) )
766 gdcmWarningMacro( " 'Image numbers' not coherent. "
767 << " No ImageNumberOrdering sort performed.");
771 std::sort(fileList->begin(), fileList->end(),
772 SerieHelper::ImageNumberLessThan );
774 std::sort(fileList->begin(), fileList->end(),
775 SerieHelper::ImageNumberGreaterThan );
780 bool SerieHelper::FileNameLessThan(File *file1, File *file2)
782 return file1->GetFileName() < file2->GetFileName();
785 bool SerieHelper::FileNameGreaterThan(File *file1, File *file2)
787 return file1->GetFileName() > file2->GetFileName();
790 * \brief sorts the images, according to their File Name
791 * @param fileList Coherent File list (same Serie UID) to sort
792 * @return false only if the header is bugged !
794 bool SerieHelper::FileNameOrdering(FileList *fileList)
797 std::sort(fileList->begin(), fileList->end(),
798 SerieHelper::FileNameLessThan);
800 std::sort(fileList->begin(), fileList->end(),
801 SerieHelper::FileNameGreaterThan);
807 * \brief sorts the images, according to user supplied function
808 * @param fileList Coherent File list (same Serie UID) to sort
809 * @return false only if the header is bugged !
811 bool SerieHelper::UserOrdering(FileList *fileList)
813 std::sort(fileList->begin(), fileList->end(),
814 SerieHelper::UserLessThanFunction);
817 std::reverse(fileList->begin(), fileList->end());
823 * \brief Heuristics to *try* to build a Serie Identifier that would ensure
824 * all the images are coherent.
826 * By default, uses the SeriesUID. If UseSeriesDetails(true) has been called,
827 * then additional identifying information is used.
828 * We allow user to add his own critierions, using AddSeriesDetail
829 * (he knows more than we do about his images!)
830 * ex : in tagging series, the only pertnent tag is
831 * 0018|1312 [In-plane Phase Encoding Direction] value : ROW/COLUMN
832 * @param inFile gdcm::File we want to build a Serie Identifier for.
833 * @return the SeriesIdentifier
835 std::string SerieHelper::CreateUniqueSeriesIdentifier( File *inFile )
837 if( inFile->IsReadable() )
839 // 0020 000e UI REL Series Instance UID
840 std::string uid = inFile->GetEntryString (0x0020, 0x000e);
841 std::string id = uid.c_str();
842 if(m_UseSeriesDetails)
844 // If the user requests, additional information can be appended
845 // to the SeriesUID to further differentiate volumes in the DICOM
846 // objects being processed.
848 // 0020 0011 Series Number
849 // A scout scan prior to a CT volume scan can share the same
850 // SeriesUID, but they will sometimes have a different Series Number
851 std::string sNum = inFile->GetEntryString(0x0020, 0x0011);
852 if( sNum == gdcm::GDCM_UNFOUND )
856 // 0018 0024 Sequence Name
857 // For T1-map and phase-contrast MRA, the different flip angles and
858 // directions are only distinguished by the Sequence Name
859 std::string sName = inFile->GetEntryString(0x0018, 0x0024);
860 if( sName == gdcm::GDCM_UNFOUND )
865 // You can think on checking Image Orientation (0020,0037), as well.
868 // 0018 0050 Slice Thickness
869 // On some CT systems, scout scans and subsequence volume scans will
870 // have the same SeriesUID and Series Number - YET the slice
871 // thickness will differ from the scout slice and the volume slices.
872 std::string sThick = inFile->GetEntryString (0x0018, 0x0050);
873 if( sThick == gdcm::GDCM_UNFOUND )
878 // If the 2D images in a sequence don't have the same number of rows,
879 // then it is difficult to reconstruct them into a 3D volume.
880 std::string sRows = inFile->GetEntryString (0x0028, 0x0010);
881 if( sRows == gdcm::GDCM_UNFOUND )
886 // If the 2D images in a sequence don't have the same number of columns,
887 // then it is difficult to reconstruct them into a 3D volume.
888 std::string sColumns = inFile->GetEntryString (0x0028, 0x0011);
889 if( sColumns == gdcm::GDCM_UNFOUND )
894 // Concat the new info
895 std::string num = sNum.c_str();
896 num += sName.c_str();
897 num += sThick.c_str();
898 num += sRows.c_str();
899 num += sColumns.c_str();
901 // Add a loop, here, to deal with any extra user supplied tag.
902 // We allow user to add his own critierions
903 // (he knows more than we do about his images!)
904 // ex : in tagging series, the only pertinent tag is
905 // 0018|1312 [In-plane Phase Encoding Direction] values : ROW/COLUMN
908 for(SeriesExDetails::iterator it2 = ExDetails.begin();
909 it2 != ExDetails.end();
912 const ExDetail &r = *it2;
913 s = inFile->GetEntryString( r.group, r.elem );
917 // Append the new info to the SeriesUID
922 // Eliminate non-alphanum characters, including whitespace...
923 // that may have been introduced by concats.
924 for(unsigned int i=0; i<id.size(); i++)
927 && !( id[i] == '.' || id[i] == '-' || id[i] == '_'
928 || (id[i] >= 'a' && id[i] <= 'z')
929 || (id[i] >= '0' && id[i] <= '9')
930 || (id[i] >= 'A' && id[i] <= 'Z')))
937 else // Could not open inFile
939 gdcmWarningMacro("Could not parse series info.");
940 std::string id = gdcm::GDCM_UNFOUND;
946 * \brief Allow user to build is own File Identifier (to be able to sort
947 * temporal series just as he wants)
948 * Criterions will be set with AddSeriesDetail.
949 * (Maybe the method should be moved elsewhere
950 * -File class? FileHelper class?-
951 * @return FileIdentifier (Tokenizable on '_')
953 std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile )
955 // Deal with all user supplied tags.
956 // (user knows more than we do about his images!)
961 char charConverted[17];
963 for(SeriesExDetails::iterator it2 = ExDetails.begin();
964 it2 != ExDetails.end();
967 const ExDetail &r = *it2;
968 s = inFile->GetEntryString( r.group, r.elem );
970 // User is allowed to ask 'convertion', to allow further ordering
971 // e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK
974 converted = atof(s.c_str());
975 // probabely something much more complicated is possible,
976 // using C++ features
977 /// \todo check the behaviour when there are >0 and <0 numbers
978 sprintf(charConverted, "%016.6f",converted);
981 // Eliminate non-alphanum characters, including whitespace.
982 for(unsigned int i=0; i<s.size(); i++)
985 && !( s[i] == '.' || s[i] == '-'
986 || (s[i] >= 'a' && s[i] <= 'z')
987 || (s[i] >= '0' && s[i] <= '9')
988 || (s[i] >= 'A' && s[i] <= 'Z')))
995 id += "_"; // make the FileIdentifier Tokenizable
1000 //-----------------------------------------------------------------------------
1003 * \brief Canonical printer.
1005 void SerieHelper::Print(std::ostream &os, std::string const &indent)
1007 // For all the Coherent File lists of the gdcm::Serie
1008 SingleSerieUIDFileSetmap::iterator itl = SingleSerieUIDFileSetHT.begin();
1009 if ( itl == SingleSerieUIDFileSetHT.end() )
1011 gdcmWarningMacro( "No SingleSerieUID File set found" );
1014 while (itl != SingleSerieUIDFileSetHT.end())
1016 os << "Serie UID :[" << itl->first << "]" << std::endl;
1018 // For all the files of a SingleSerieUID File set
1019 for (FileList::iterator it = (itl->second)->begin();
1020 it != (itl->second)->end();
1023 os << indent << " --- " << (*it)->GetFileName() << std::endl;
1029 //-----------------------------------------------------------------------------
1030 } // end namespace gdcm