1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2010/04/09 15:38:18 $
7 Version: $Revision: 1.46 $
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 #ifndef _GDCMSERIEHELPER_H_
20 #define _GDCMSERIEHELPER_H_
22 #include "gdcmRefCounter.h"
23 #include "gdcmTagKey.h"
24 #include "gdcmDebug.h" // for LEGACY
26 #include "gdcmDicomDirSerie.h"
32 namespace GDCM_NAME_SPACE
36 typedef std::vector<File* > FileList;
37 #ifndef GDCM_LEGACY_REMOVE
38 typedef std::vector<File* > GdcmFileList;
41 /// \brief XCoherent stands for 'Extra Coherent',
42 /// (The name 'Coherent' would be enough but it was used before;
43 /// I don't want to put a bomb in the code)
44 /// Any 'better name' is welcome !
45 typedef std::map<std::string, FileList *> XCoherentFileSetmap;
47 typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
49 //-----------------------------------------------------------------------------
52 * This class should be used for a stack of 2D dicom images.
54 * - It allows to explore (recursively or not) a directory and
55 * makes a set of 'Single SerieUID Filesets'
57 * - - to sort any of the 'Single SerieUID Fileset' on the image position.
58 * - - to split any of the Single SerieUID Filesets (better use this name than
59 * 'CoherentFileList' : it's NOT a std::list, files are NOT coherent ...)
60 * into several XCoherent Filesets
61 * XCoherent stands for 'Extra Coherent' (same orientation, or same position)
64 class GDCM_EXPORT SerieHelper : public RefCounter
66 gdcmTypeMacro(SerieHelper);
69 /// SingleSerieUIDFileSetmap replaces the former CoherentFileListmap
70 /// (List were actually std::vectors, and where no coherent at all :
71 /// They were only Single SeriesInstanceUID File sets)
72 typedef std::map<std::string, FileList *> SingleSerieUIDFileSetmap;
74 typedef std::vector<File* > FileVector;
76 /// \brief Constructs a SerieHelper with a RefCounter
77 static SerieHelper *New() {return new SerieHelper();}
79 virtual ~SerieHelper();
80 void Print(std::ostream &os = std::cout, std::string const &indent = "" );
82 /// \todo should return bool or throw error ?
83 void AddFileName(std::string const &filename);
84 bool AddFile(File *header);
85 // GDCM_LEGACY(bool AddGdcmFile(File* header))
87 void SetDirectory(std::string const &dir, bool recursive=false);
88 void SetDicomDirSerie(DicomDirSerie *se);
90 bool IsCoherent(FileList *fileSet);
91 void OrderFileList(FileList *fileSet);
92 void Clear() { ClearAll(); }
94 /// \brief Gets the FIRST Single SerieUID Fileset.
95 /// Deprecated; kept not to break the API
96 /// \note Caller must call OrderFileList first
97 /// @return the (first) Single SerieUID Fileset
98 const FileList &GetFileList()
99 { return *SingleSerieUIDFileSetHT.begin()->second; }
101 // GDCM_LEGACY( FileList *GetFirstCoherentFileList() )
102 // GDCM_LEGACY( FileList *GetNextCoherentFileList() )
103 // GDCM_LEGACY( FileList *GetCoherentFileList(std::string serieUID) )
105 FileList *GetFirstSingleSerieUIDFileSet();
106 FileList *GetNextSingleSerieUIDFileSet();
107 FileList *GetSingleSerieUIDFileSet(std::string serieUID);
108 /// brief returns the 'Series Instance UID' Single SerieUID FileSet
109 std::string GetCurrentSerieUIDFileSetUID()
110 { return (*ItFileSetHt).first; }
112 /// \brief returns the distance between the 2 first -adjacent- slices,
113 /// along the slice normal; -1.0 if process failed
114 /// Computed during ImagePositionPatientOrdering() process.
115 /// To be use *immediately after* ImagePositionPatientOrdering()
116 /// (it's a member of the FileHelper, *not* of the FileList !)
117 double GetZSpacing() { return ZSpacing; }
119 /// All the following allow user to restrict DICOM file to be part
120 /// of a particular serie
121 /// \todo : find a trick to allow user to say the restrictions are ored
123 /// ex : keep the images whose SerieNumber is 101 or 102 or 103.
124 void AddRestriction(TagKey const &key);
125 void AddRestriction(TagKey const &key, std::string const &value, int op);
126 void AddRestriction(uint16_t group, uint16_t elem, std::string const &value,
129 /// \brief Use additional series information such as ProtocolName
130 /// and SeriesName to identify when a single SeriesUID contains
131 /// multiple 3D volumes - as can occur with perfusion and DTI imaging
132 void SetUseSeriesDetails( bool useSeriesDetails )
134 m_UseSeriesDetails = useSeriesDetails;
136 bool GetUseSeriesDetails()
138 return m_UseSeriesDetails;
140 /// \brief This function will add the following DICOM tag as being part of a
141 /// 'fake' uid. This is usefull when the Serie UID is not enough to disseminate
142 /// into multiple sub serie when needed:
143 /// 0020 0011 Series Number
144 /// 0018 0024 Sequence Name
145 /// 0018 0050 Slice Thickness
147 /// 0028 0011 Columns
148 void CreateDefaultUniqueSeriesIdentifier();
150 void AddSeriesDetail(uint16_t group, uint16_t elem, bool convert);
152 std::string CreateUserDefinedFileIdentifier( File * inFile );
154 /// \brief Create a string that uniquely identifies a series. By default
155 // uses the SeriesUID. If UseSeriesDetails(true) has been called,
156 // then additional identifying information is used.
157 std::string CreateUniqueSeriesIdentifier( File * inFile );
160 * \brief Sets the LoadMode as a boolean string.
161 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
162 * ... (nothing more, right now)
163 * WARNING : before using LD_NOSHADOW, be sure *all* your files
164 * contain accurate values in the 0x0000 element (if any)
165 * of *each* Shadow Group. The parser will fail if the size is wrong !
166 * @param mode Load mode to be used
168 void SetLoadMode (int mode) { LoadMode = mode; }
171 * \brief Sets the DropDuplicatePositions as a boolean.
172 * @param drop DropDuplicatePositions mode to be used
174 void SetDropDuplicatePositions (bool drop) { DropDuplicatePositions = drop; }
176 /// Brief User wants the files to be sorted Direct Order (default value)
177 void SetSortOrderToDirect() { DirectOrder = true; }
179 /// Brief User wants the files to be sorted Reverse Order
180 void SetSortOrderToReverse() { DirectOrder = false; }
182 /// to allow user to give is own comparison function
183 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
184 { UserLessThanFunction = userFunc; }
186 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
187 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
188 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
189 uint16_t group, uint16_t element);
195 bool UserOrdering(FileList *fileSet);
196 bool ImagePositionPatientOrdering(FileList *fileSet);
197 bool ImageNumberOrdering(FileList *fileSet);
198 bool FileNameOrdering(FileList *fileSet);
200 static bool ImageNumberLessThan(File *file1, File *file2);
201 static bool ImageNumberGreaterThan(File *file1, File *file2);
202 static bool FileNameLessThan(File *file1, File *file2);
203 static bool FileNameGreaterThan(File *file1, File *file2);
207 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
208 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
210 #ifndef GDCM_LEGACY_REMOVE
211 typedef std::pair<TagKey, std::string> Rule;
212 typedef std::vector<Rule> SerieRestrictions;
213 SerieRestrictions Restrictions;
216 // New style for (extented) Rules
223 typedef std::vector<ExRule> SerieExRestrictions;
224 SerieExRestrictions ExRestrictions;
225 SerieExRestrictions ExRefine;
232 typedef std::vector<ExDetail> SeriesExDetails;
233 SeriesExDetails ExDetails;
236 /// \brief Bit string integer (each one considered as a boolean)
237 /// Bit 0 : Skip Sequences, if possible
238 /// Bit 1 : Skip Shadow Groups if possible
239 /// Probabely, some more to add
242 /// \brief whether we want to sort in direct order or not (reverse order).
243 /// To be used by aware user only
246 /// \brief If user knows more about his images than gdcm does,
247 /// he may supply his own comparison function.
248 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
250 bool DropDuplicatePositions;
252 void Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) );
254 bool m_UseSeriesDetails;
255 /// \brief distance between the 2 first -adjancent- slices, along the slice normal
256 /// Computed during ImagePositionPatientOrdering() process.
257 /// (we need to sort the whole image set to do that)
258 /// To be used *immediately after* ImagePositionPatientOrdering()
259 /// (it's a member of the FileHelper, *not* of the FileList !)
263 } // end namespace gdcm
265 //-----------------------------------------------------------------------------