+void SerieHelper::CreateDefaultUniqueSeriesIdentifier()
+{
+ // If the user requests, additional information can be appended
+ // to the SeriesUID to further differentiate volumes in the DICOM
+ // objects being processed.
+
+ // 0020 0011 Series Number
+ // 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.
+ AddRestriction( TagKey(0x0028, 0x0011));
+}
+
+/**
+ * \brief Heuristics to *try* to build a Serie Identifier that would ensure
+ * all the images are coherent.
+ *
+ * By default, uses the SeriesUID. If UseSeriesDetails(true) has been called,
+ * then additional identifying information is used.
+ * We allow user to add his own critierions, using AddSeriesDetail
+ * (he knows more than we do about his images!)
+ * ex : in tagging series, the only pertinent tag is
+ * 0018|1312 [In-plane Phase Encoding Direction] value : ROW/COLUMN
+ * @param inFile GDCM_NAME_SPACE::File we want to build a Serie Identifier for.
+ * @return the SeriesIdentifier
+ */
+std::string SerieHelper::CreateUniqueSeriesIdentifier( File *inFile )
+{
+ if( inFile->IsReadable() )
+ {
+ // 0020 000e UI REL Series Instance UID
+ std::string uid = inFile->GetEntryString (0x0020, 0x000e);
+ std::string id = uid.c_str();
+ if(m_UseSeriesDetails)
+ {
+ for(SerieExRestrictions::iterator it2 = ExRefine.begin();
+ it2 != ExRefine.end();
+ ++it2)
+ {
+ const ExRule &r = *it2;
+ std::string s = inFile->GetEntryString( r.group, r.elem );
+ if( s == GDCM_UNFOUND )
+ {
+ s = "";
+ }
+ if( id == uid && !s.empty() )
+ {
+ id += "."; // add separator
+ }
+ id += s;
+ }
+ }
+ // Eliminate non-alnum characters, including whitespace...
+ // that may have been introduced by concats.
+ unsigned int s_size = id.size();
+ for(unsigned int i=0; i<s_size; i++)
+ {
+ while(i<s_size
+ && !( id[i] == '.' || id[i] == '%' || id[i] == '_'
+ || (id[i] >= '+' && id[i] <= '-')
+ || (id[i] >= 'a' && id[i] <= 'z')
+ || (id[i] >= '0' && id[i] <= '9')
+ || (id[i] >= 'A' && id[i] <= 'Z')))
+ {
+ id.replace(i, 1, "_"); // ImagePositionPatient related stuff will be more human readable
+ }
+ }
+ // deal with Dicom strings trailing '\0'
+ if(id[s_size-1] == '_')
+ id.erase(s_size-1, 1);
+ return id;
+ }
+ else // Could not open inFile
+ {
+ gdcmWarningMacro("Could not parse series info.");
+ std::string id = GDCM_UNFOUND;
+ return id;
+ }
+}
+
+/**
+ * \brief Allow user to build is own File Identifier (to be able to sort
+ * temporal series just as he wants)
+ * Criterions will be set with AddSeriesDetail.
+ * (Maybe the method should be moved elsewhere
+ * -File class? FileHelper class?-
+ * @return FileIdentifier (Tokenizable on '%%%'. Hope it's enough !)
+ */
+std::string SerieHelper::CreateUserDefinedFileIdentifier( File *inFile )
+{
+ // Deal with all user supplied tags.
+ // (user knows more than we do about his images!)
+
+ double converted;
+ std::string id;
+ std::string s;
+ char charConverted[17];
+
+ for(SeriesExDetails::iterator it2 = ExDetails.begin();
+ it2 != ExDetails.end();
+ ++it2)
+ {
+ const ExDetail &r = *it2;
+ s = inFile->GetEntryString( r.group, r.elem );
+ if (s == "") // avoid troubles when empty string is found
+ s = "-";
+
+ // 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)
+ {
+ if ( s != GDCM_UNFOUND) // Don't convert unfound fields !
+ {
+ converted = atof(s.c_str());
+ // probabely something much more complicated is possible,
+ // using C++ features
+ /// \todo check the behaviour when there are >0 and <0 numbers
+ sprintf(charConverted, "%016.6f",converted);
+ s = charConverted;
+ }
+ }
+ // Eliminate non-alphanum characters, including whitespace.
+ unsigned int s_size = s.size();
+ for(unsigned int i=0; i<s_size; i++)
+ {
+ while(i<s_size
+ && !( s[i] == '.' || s[i] == '%' || 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.replace(i, 1, "_"); // ImagePositionPatient related stuff will be more human readable
+ }
+ }
+ // deal with Dicom strings trailing '\0'
+ if(s[s_size-1] == '_')
+ s.erase(s_size-1, 1);
+
+ id += s.c_str();
+ id += "%%%"; // make the FileIdentifier Tokenizable
+ }
+ id += inFile->GetFileName();
+ id += "%%%";
+ return id;
+}
+
+//-----------------------------------------------------------------------------
+// Sort
+/**
+ * \brief Sort FileList.
+ */
+void SerieHelper::Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) )
+{
+ std::sort(fileList->begin(), fileList->end(), pt2Func );
+}
+
+/*
+#ifndef GDCM_LEGACY_REMOVE
+bool SerieHelper::AddGdcmFile(File* header)
+{
+ return AddFile(header);
+}
+#endif
+*/
+