X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmSerieHelper.cxx;h=16616963b698c1c38ca51dad6d38e43ef2c62afa;hb=f2dd0107ba49eda3386b34715cdc0c046d12397f;hp=a16c8d0556a72f085a11ff3b893d8bae20a3a141;hpb=8fd45dc6d321d1419854dc0e4fa6a37d6826b655;p=gdcm.git diff --git a/src/gdcmSerieHelper.cxx b/src/gdcmSerieHelper.cxx index a16c8d05..16616963 100644 --- a/src/gdcmSerieHelper.cxx +++ b/src/gdcmSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:11 $ - Version: $Revision: 1.54 $ + Date: $Date: 2007/07/05 09:34:12 $ + Version: $Revision: 1.59 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,6 +43,7 @@ SerieHelper::SerieHelper() ClearAll(); UserLessThanFunction = 0; DirectOrder = true; + } /** @@ -242,8 +243,7 @@ void SerieHelper::AddRestriction(uint16_t group, uint16_t elem, * e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK */ void SerieHelper::AddSeriesDetail(uint16_t group, uint16_t elem, bool convert) -{ - +{ ExDetail d; d.group = group; d.elem = elem; @@ -267,6 +267,22 @@ void SerieHelper::SetDirectory(std::string const &dir, bool recursive) } } +/** + * \brief Sets the DicomDirSerie + * @param se DicomDirSerie to deal with + */ +void SerieHelper::SetDicomDirSerie(DicomDirSerie *se) +{ + DirList dirList(se); + + DirListType filenames_list = dirList.GetFilenames(); + for( DirListType::const_iterator it = filenames_list.begin(); + it != filenames_list.end(); ++it) + { + AddFileName( *it ); + } +} + /** * \brief Sorts the given Fileset * \warning This could be implemented in a 'Strategy Pattern' approach @@ -439,7 +455,7 @@ XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet) std::ostringstream ossOrient; FileList::const_iterator it = fileSet->begin(); - it ++; + //it ++; for ( ; it != fileSet->end(); ++it) @@ -489,7 +505,7 @@ XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet) std::ostringstream ossPosition; std::string strPosition; // re computed FileList::const_iterator it = fileSet->begin(); - it ++; + //it ++; for ( ; it != fileSet->end(); ++it) @@ -565,7 +581,7 @@ XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet, std::string strTagValue; // read on disc FileList::const_iterator it = fileSet->begin(); - it ++; + //it ++; for ( ; it != fileSet->end(); ++it) @@ -694,8 +710,9 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList ) // Find out if min/max are coherent if ( min == max ) { - gdcmWarningMacro("Looks like all images have the exact same image position" - << ". No PositionPatientOrdering sort performed" ); + gdcmWarningMacro("Looks like all images have the exact same image position. " + << "No PositionPatientOrdering sort performed. " + << "No 'ZSpacing' calculated! "); return false; } @@ -707,18 +724,21 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList ) { if (distmultimap.count((*it2).first) != 1) { - gdcmErrorMacro("File: " + gdcmErrorMacro("File: [" << ((*it2).second->GetFileName()) - << " Distance: " + << "] : more than ONE file at distance: '" << (*it2).first - << " position is not unique"); + << " (position is not unique!) " + << "No PositionPatientOrdering sort performed. " + << "No 'ZSpacing' calculated! "); ok = false; } } if (!ok) { - return false; + if (! DropDuplicatePositions) + return false; } // Now, we could calculate Z Spacing as the difference @@ -745,6 +765,12 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList ) ++it3) { fileList->push_back( (*it3).second ); + if (DropDuplicatePositions) + { + it3 = distmultimap.upper_bound((*it3).first); // skip all duplicates + if (it3 == distmultimap.end() ) // if last image, stop iterate + break; + } } } else // user asked for reverse order @@ -755,6 +781,12 @@ bool SerieHelper::ImagePositionPatientOrdering( FileList *fileList ) { it4--; fileList->push_back( (*it4).second ); + if (DropDuplicatePositions) // skip all duplicates + { + it4 = distmultimap.upper_bound((*it4).first); + if (it4 == distmultimap.begin() ) // if first image, stop iterate + break; + } } while (it4 != distmultimap.begin() ); } @@ -889,19 +921,23 @@ void SerieHelper::CreateDefaultUniqueSeriesIdentifier() // A scout scan prior to a CT volume scan can share the same // SeriesUID, but they will sometimes have a different Series Number AddRestriction( TagKey(0x0020, 0x0011) ); + // 0018 0024 Sequence Name // For T1-map and phase-contrast MRA, the different flip angles and // directions are only distinguished by the Sequence Name AddRestriction( TagKey(0x0018, 0x0024) ); + // 0018 0050 Slice Thickness // On some CT systems, scout scans and subsequence volume scans will // have the same SeriesUID and Series Number - YET the slice // thickness will differ from the scout slice and the volume slices. AddRestriction( TagKey(0x0018, 0x0050)); + // 0028 0010 Rows // If the 2D images in a sequence don't have the same number of rows, // then it is difficult to reconstruct them into a 3D volume. AddRestriction( TagKey(0x0028, 0x0010)); + // 0028 0011 Columns // If the 2D images in a sequence don't have the same number of columns, // then it is difficult to reconstruct them into a 3D volume. @@ -936,7 +972,7 @@ std::string SerieHelper::CreateUniqueSeriesIdentifier( File *inFile ) { const ExRule &r = *it2; std::string s = inFile->GetEntryString( r.group, r.elem ); - if( s == GDCM_NAME_SPACE::GDCM_UNFOUND ) + if( s == GDCM_UNFOUND ) { s = ""; } @@ -965,7 +1001,7 @@ std::string SerieHelper::CreateUniqueSeriesIdentifier( File *inFile ) else // Could not open inFile { gdcmWarningMacro("Could not parse series info."); - std::string id = GDCM_NAME_SPACE::GDCM_UNFOUND; + std::string id = GDCM_UNFOUND; return id; } } @@ -995,7 +1031,7 @@ std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile ) const ExDetail &r = *it2; s = inFile->GetEntryString( r.group, r.elem ); - // User is allowed to ask 'convertion', to allow further ordering + // User is allowed to ask for 'convertion', to allow further ordering // e.g : 100 would be *before* 20; 000020.00 vs 00100.00 : OK if (it2->convert) { @@ -1013,10 +1049,10 @@ std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile ) for(unsigned int i=0; i= 'a' && s[i] <= 'z') - || (s[i] >= '0' && s[i] <= '9') - || (s[i] >= 'A' && s[i] <= 'Z'))) + && !( s[i] == '.' || s[i] == '%' || s[i] == '_' + || (s[i] >= 'a' && s[i] <= 'z') + || (s[i] >= '0' && s[i] <= '9') + || (s[i] >= 'A' && s[i] <= 'Z'))) { s.erase(i, 1); } @@ -1025,7 +1061,8 @@ std::string SerieHelper::CreateUserDefinedFileIdentifier( File * inFile ) id += s.c_str(); id += "%%%"; // make the FileIdentifier Tokenizable } - + id += inFile->GetFileName(); + id += "%%%"; return id; }