1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2006/02/16 20:06:15 $
7 Version: $Revision: 1.37 $
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
34 typedef std::vector<File* > FileList;
35 #ifndef GDCM_LEGACY_REMOVE
36 typedef std::vector<File* > GdcmFileList;
39 /// \brief XCoherent stands for 'Extra Coherent',
40 /// (The name 'Coherent' would be enough but it was used before;
41 /// I don't want to put a bomb in the code)
42 /// Any 'better name' is welcome !
43 typedef std::map<std::string, FileList *> XCoherentFileSetmap;
45 typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
47 //-----------------------------------------------------------------------------
50 * This class should be used for a stack of 2D dicom images.
52 * - It allows to explore (recursively or not) a directory and
53 * makes a set of 'Single SerieUID Filesets'
55 * - - to sort any of the 'Single SerieUID Fileset' on the image position.
56 * - - to split any of the Single SerieUID Filesets (better use this name than
57 * 'CoherentFileList' : it's NOT a std::list, files are NOT coherent ...)
58 * into several XCoherent Filesets
59 * XCoherent stands for 'Extra Coherent' (same orientation, or same position)
61 class GDCM_EXPORT SerieHelper : public RefCounter
63 gdcmTypeMacro(SerieHelper);
66 /// SingleSerieUIDFileSetmap replaces the former CoherentFileListmap
67 /// ( List were actually std::vectors, and wher no coherent at all :
68 /// They were only Single SeriesInstanceUID File sets)
69 typedef std::map<std::string, FileList *> SingleSerieUIDFileSetmap;
71 typedef std::vector<File* > FileVector;
73 /// \brief Constructs a SerieHelper with a RefCounter
74 static SerieHelper *New() {return new SerieHelper();}
76 virtual ~SerieHelper();
77 void Print(std::ostream &os = std::cout, std::string const &indent = "" );
79 /// \todo should return bool or throw error ?
80 void AddFileName(std::string const &filename);
81 bool AddFile(File *header);
82 #ifndef GDCM_LEGACY_REMOVE
83 bool AddGdcmFile(File* header) { return AddFile(header); }
86 void SetDirectory(std::string const &dir, bool recursive=false);
87 bool IsCoherent(FileList *fileSet);
88 void OrderFileList(FileList *fileSet);
89 void Clear() { ClearAll(); }
91 /// \brief Gets the FIRST Single SerieUID Fileset.
92 /// Deprecated; kept not to break the API
93 /// \note Caller must call OrderFileList first
94 /// @return the (first) Single SerieUID Fileset
95 const FileList &GetFileList()
96 { return *SingleSerieUIDFileSetHT.begin()->second; }
98 GDCM_LEGACY( FileList *GetFirstCoherentFileList() );
99 GDCM_LEGACY( FileList *GetNextCoherentFileList() );
100 GDCM_LEGACY( FileList *GetCoherentFileList(std::string serieUID) );
102 FileList *GetFirstSingleSerieUIDFileSet();
103 FileList *GetNextSingleSerieUIDFileSet();
104 FileList *GetSingleSerieUIDFileSet(std::string serieUID);
105 /// brief returns the 'Series Instance UID' Single SerieUID FileSet
106 std::string GetCurrentSerieUIDFileSetUID()
107 { return (*ItFileSetHt).first; }
108 /// All the following allow user to restrict DICOM file to be part
109 /// of a particular serie
110 /// \todo : find a trick to allow user to say the retrictetons are ored
112 /// ex : keep the images whose SerieNumber is 101 or 102 or 103.
113 void AddRestriction(TagKey const &key);
114 void AddRestriction(TagKey const &key, std::string const &value, int op);
115 void AddRestriction(uint16_t group, uint16_t elem, std::string const &value,
118 /// \brief Use additional series information such as ProtocolName
119 /// and SeriesName to identify when a single SeriesUID contains
120 /// multiple 3D volumes - as can occur with perfusion and DTI imaging
121 void SetUseSeriesDetails( bool useSeriesDetails )
123 m_UseSeriesDetails = useSeriesDetails;
125 bool GetUseSeriesDetails()
127 return m_UseSeriesDetails;
129 /// \brief This function will add the following DICOM tag as being part of a
130 /// 'fake' uid. This is usefull when the Serie UID is not enough to disseminate
131 /// into multiple sub serie when needed:
132 /// 0020 0011 Series Number
133 /// 0018 0024 Sequence Name
134 /// 0018 0050 Slice Thickness
136 /// 0028 0011 Columns
137 void CreateDefaultUniqueSeriesIdentifier();
139 void AddSeriesDetail(uint16_t group, uint16_t elem, bool convert);
141 std::string CreateUserDefinedFileIdentifier( File * inFile );
143 /// \brief Create a string that uniquely identifies a series. By default
144 // uses the SeriesUID. If UseSeriesDetails(true) has been called,
145 // then additional identifying information is used.
146 std::string CreateUniqueSeriesIdentifier( File * inFile );
149 * \brief Sets the LoadMode as a boolean string.
150 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
151 * ... (nothing more, right now)
152 * WARNING : before using LD_NOSHADOW, be sure *all* your files
153 * contain accurate values in the 0x0000 element (if any)
154 * of *each* Shadow Group. The parser will fail if the size is wrong !
155 * @param mode Load mode to be used
157 void SetLoadMode (int mode) { LoadMode = mode; }
159 /// Brief User wants the files to be sorted Direct Order (default value)
160 void SetSortOrderToDirect() { DirectOrder = true; }
162 /// Brief User wants the files to be sorted Reverse Order
163 void SetSortOrderToReverse() { DirectOrder = false; }
165 /// to allow user to give is own comparison function
166 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
167 { UserLessThanFunction = userFunc; }
169 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
170 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
171 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
172 uint16_t group, uint16_t element);
178 bool UserOrdering(FileList *fileSet);
179 bool ImagePositionPatientOrdering(FileList *fileSet);
180 bool ImageNumberOrdering(FileList *fileSet);
181 bool FileNameOrdering(FileList *fileSet);
183 static bool ImageNumberLessThan(File *file1, File *file2);
184 static bool ImageNumberGreaterThan(File *file1, File *file2);
185 static bool FileNameLessThan(File *file1, File *file2);
186 static bool FileNameGreaterThan(File *file1, File *file2);
190 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
191 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
193 #ifndef GDCM_LEGACY_REMOVE
194 typedef std::pair<TagKey, std::string> Rule;
195 typedef std::vector<Rule> SerieRestrictions;
196 SerieRestrictions Restrictions;
199 // New style for (extented) Rules
206 typedef std::vector<ExRule> SerieExRestrictions;
207 SerieExRestrictions ExRestrictions;
208 SerieExRestrictions ExRefine;
215 typedef std::vector<ExDetail> SeriesExDetails;
216 SeriesExDetails ExDetails;
219 /// \brief Bit string integer (each one considered as a boolean)
220 /// Bit 0 : Skip Sequences, if possible
221 /// Bit 1 : Skip Shadow Groups if possible
222 /// Probabely, some more to add
225 /// \brief whether we want to sort in direct order or not (reverse order).
226 /// To be used by aware user only
229 /// \brief If user knows more about his images than gdcm does,
230 /// he may supply his own comparison function.
231 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
233 void Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) );
235 bool m_UseSeriesDetails;
238 } // end namespace gdcm
240 //-----------------------------------------------------------------------------