+ return SingleSerieUIDFileSetHT[SerieUID];
+}
+
+/**
+ * \brief Splits a Single SerieUID Fileset according to the Orientations
+ * @param fileSet File Set to be splitted
+ * \return std::map of 'Xcoherent' File sets
+ */
+
+XCoherentFileSetmap SerieHelper::SplitOnOrientation(FileList *fileSet)
+{
+ XCoherentFileSetmap CoherentFileSet;
+
+ int nb = fileSet->size();
+ if (nb == 0 )
+ return CoherentFileSet;
+ float iop[6];
+
+ std::string strOrient;
+ std::ostringstream ossOrient;
+ FileList::const_iterator it = fileSet->begin();
+ it ++;
+ for ( ;
+ it != fileSet->end();
+ ++it)
+ {
+ // Information is in :
+ // 0020 0037 : Image Orientation (Patient) or
+ // 0020 0035 : Image Orientation (RET)
+
+ // Let's build again the 'cosines' string, to be sure of it's format
+ (*it)->GetImageOrientationPatient(iop);
+
+ ossOrient << iop[0];
+ for (int i = 1; i < 6; i++)
+ {
+ ossOrient << "\\";
+ ossOrient << iop[i];
+ }
+ strOrient = ossOrient.str();
+ ossOrient.str("");
+ // FIXME : is it a 'cleaner' way to initialize an ostringstream?
+
+ if ( CoherentFileSet.count(strOrient) == 0 )
+ {
+ gdcmDebugMacro(" New Orientation :[" << strOrient << "]");
+ // create a File set in 'orientation' position
+ CoherentFileSet[strOrient] = new FileList;
+ }
+ // Current Orientation and DICOM header match; add the file:
+ CoherentFileSet[strOrient]->push_back( (*it) );
+ }
+ return CoherentFileSet;
+}
+
+/**
+ * \brief Splits a 'Single SerieUID' Fileset according to the Positions
+ * @param fileSet File Set to be splitted
+ * \return std::map of 'Xcoherent' File sets
+ */
+
+XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet)
+{
+ XCoherentFileSetmap CoherentFileSet;
+
+ int nb = fileSet->size();
+ if (nb == 0 )
+ return CoherentFileSet;
+ float pos[3];
+ std::string strImPos; // read on disc
+ std::ostringstream ossPosition;
+ std::string strPosition; // re computed
+ FileList::const_iterator it = fileSet->begin();
+ it ++;
+ for ( ;
+ it != fileSet->end();
+ ++it)
+ {
+ // Information is in :
+ // 0020,0032 : Image Position Patient
+ // 0020,0030 : Image Position (RET)
+
+ strImPos = (*it)->GetEntryString(0x0020,0x0032);
+ if ( strImPos == GDCM_UNFOUND)
+ {
+ gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)");
+ strImPos = (*it)->GetEntryString(0x0020,0x0030); // For ACR-NEMA images
+ if ( strImPos == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)");
+ // User wants to split on the 'Position'
+ // No 'Position' info found.
+ // We return an empty Htable !
+ return CoherentFileSet;
+ }
+ }
+
+ if ( sscanf( strImPos.c_str(), "%f \\%f \\%f ",
+ &pos[0], &pos[1], &pos[2]) != 3 )
+ {
+ gdcmWarningMacro( "Wrong number for Position : ["
+ << strImPos << "]" );
+ return CoherentFileSet;
+ }
+
+ // Let's build again the 'position' string, to be sure of it's format
+
+ ossPosition << pos[0];
+ for (int i = 1; i < 3; i++)
+ {
+ ossPosition << "\\";
+ ossPosition << pos[i];
+ }
+ strPosition = ossPosition.str();
+
+ if ( CoherentFileSet.count(strPosition) == 0 )
+ {
+ gdcmDebugMacro(" New Position :[" << strPosition << "]");
+ // create a File set in 'position' position
+ CoherentFileSet[strPosition] = new FileList;
+ }
+ // Current Position and DICOM header match; add the file:
+ CoherentFileSet[strPosition]->push_back( (*it) );
+ }
+ return CoherentFileSet;
+}
+
+/**
+ * \brief Splits a 'Single SerieUID' File set Coherent according to the
+ * value of a given Tag
+ * @param fileSet File Set to be splitted
+ * @param group group number of the target Element
+ * @param elem element number of the target Element
+ * \return std::map of 'Xcoherent' File sets
+ */
+
+XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet,
+ uint16_t group, uint16_t elem)
+{
+ XCoherentFileSetmap CoherentFileSet;
+
+ int nb = fileSet->size();
+ if (nb == 0 )
+ return CoherentFileSet;
+
+ std::string strTagValue; // read on disc
+
+ FileList::const_iterator it = fileSet->begin();
+ it ++;
+ for ( ;
+ it != fileSet->end();
+ ++it)
+ {
+ // Information is in :
+ // 0020,0032 : Image Position Patient
+ // 0020,0030 : Image Position (RET)
+
+ strTagValue = (*it)->GetEntryString(group,elem);
+
+ if ( CoherentFileSet.count(strTagValue) == 0 )
+ {
+ gdcmDebugMacro(" New Tag Value :[" << strTagValue << "]");
+ // create a File set in 'position' position
+ CoherentFileSet[strTagValue] = new FileList;
+ }
+ // Current Tag value and DICOM header match; add the file:
+ CoherentFileSet[strTagValue]->push_back( (*it) );
+ }
+ return CoherentFileSet;