1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2006/05/30 08:10:19 $
7 Version: $Revision: 1.41 $
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 where 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 // GDCM_LEGACY(bool AddGdcmFile(File* header))
84 void SetDirectory(std::string const &dir, bool recursive=false);
85 bool IsCoherent(FileList *fileSet);
86 void OrderFileList(FileList *fileSet);
87 void Clear() { ClearAll(); }
89 /// \brief Gets the FIRST Single SerieUID Fileset.
90 /// Deprecated; kept not to break the API
91 /// \note Caller must call OrderFileList first
92 /// @return the (first) Single SerieUID Fileset
93 const FileList &GetFileList()
94 { return *SingleSerieUIDFileSetHT.begin()->second; }
96 // GDCM_LEGACY( FileList *GetFirstCoherentFileList() )
97 // GDCM_LEGACY( FileList *GetNextCoherentFileList() )
98 // GDCM_LEGACY( FileList *GetCoherentFileList(std::string serieUID) )
100 FileList *GetFirstSingleSerieUIDFileSet();
101 FileList *GetNextSingleSerieUIDFileSet();
102 FileList *GetSingleSerieUIDFileSet(std::string serieUID);
103 /// brief returns the 'Series Instance UID' Single SerieUID FileSet
104 std::string GetCurrentSerieUIDFileSetUID()
105 { return (*ItFileSetHt).first; }
107 /// \brief returns the distance between the 2 first -adjacent- slices,
108 /// along the slice normal; -1.0 if process failed
109 /// Computed during ImagePositionPatientOrdering() process.
110 /// To be use *immediately after* ImagePositionPatientOrdering()
111 /// (it's a member of the FileHelper, *not* of the FileList !)
112 double GetZSpacing() { return ZSpacing; }
114 /// All the following allow user to restrict DICOM file to be part
115 /// of a particular serie
116 /// \todo : find a trick to allow user to say the restrictions are ored
118 /// ex : keep the images whose SerieNumber is 101 or 102 or 103.
119 void AddRestriction(TagKey const &key);
120 void AddRestriction(TagKey const &key, std::string const &value, int op);
121 void AddRestriction(uint16_t group, uint16_t elem, std::string const &value,
124 /// \brief Use additional series information such as ProtocolName
125 /// and SeriesName to identify when a single SeriesUID contains
126 /// multiple 3D volumes - as can occur with perfusion and DTI imaging
127 void SetUseSeriesDetails( bool useSeriesDetails )
129 m_UseSeriesDetails = useSeriesDetails;
131 bool GetUseSeriesDetails()
133 return m_UseSeriesDetails;
135 /// \brief This function will add the following DICOM tag as being part of a
136 /// 'fake' uid. This is usefull when the Serie UID is not enough to disseminate
137 /// into multiple sub serie when needed:
138 /// 0020 0011 Series Number
139 /// 0018 0024 Sequence Name
140 /// 0018 0050 Slice Thickness
142 /// 0028 0011 Columns
143 void CreateDefaultUniqueSeriesIdentifier();
145 void AddSeriesDetail(uint16_t group, uint16_t elem, bool convert);
147 std::string CreateUserDefinedFileIdentifier( File * inFile );
149 /// \brief Create a string that uniquely identifies a series. By default
150 // uses the SeriesUID. If UseSeriesDetails(true) has been called,
151 // then additional identifying information is used.
152 std::string CreateUniqueSeriesIdentifier( File * inFile );
155 * \brief Sets the LoadMode as a boolean string.
156 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
157 * ... (nothing more, right now)
158 * WARNING : before using LD_NOSHADOW, be sure *all* your files
159 * contain accurate values in the 0x0000 element (if any)
160 * of *each* Shadow Group. The parser will fail if the size is wrong !
161 * @param mode Load mode to be used
163 void SetLoadMode (int mode) { LoadMode = mode; }
165 /// Brief User wants the files to be sorted Direct Order (default value)
166 void SetSortOrderToDirect() { DirectOrder = true; }
168 /// Brief User wants the files to be sorted Reverse Order
169 void SetSortOrderToReverse() { DirectOrder = false; }
171 /// to allow user to give is own comparison function
172 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
173 { UserLessThanFunction = userFunc; }
175 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
176 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
177 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
178 uint16_t group, uint16_t element);
184 bool UserOrdering(FileList *fileSet);
185 bool ImagePositionPatientOrdering(FileList *fileSet);
186 bool ImageNumberOrdering(FileList *fileSet);
187 bool FileNameOrdering(FileList *fileSet);
189 static bool ImageNumberLessThan(File *file1, File *file2);
190 static bool ImageNumberGreaterThan(File *file1, File *file2);
191 static bool FileNameLessThan(File *file1, File *file2);
192 static bool FileNameGreaterThan(File *file1, File *file2);
196 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
197 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
199 #ifndef GDCM_LEGACY_REMOVE
200 typedef std::pair<TagKey, std::string> Rule;
201 typedef std::vector<Rule> SerieRestrictions;
202 SerieRestrictions Restrictions;
205 // New style for (extented) Rules
212 typedef std::vector<ExRule> SerieExRestrictions;
213 SerieExRestrictions ExRestrictions;
214 SerieExRestrictions ExRefine;
221 typedef std::vector<ExDetail> SeriesExDetails;
222 SeriesExDetails ExDetails;
225 /// \brief Bit string integer (each one considered as a boolean)
226 /// Bit 0 : Skip Sequences, if possible
227 /// Bit 1 : Skip Shadow Groups if possible
228 /// Probabely, some more to add
231 /// \brief whether we want to sort in direct order or not (reverse order).
232 /// To be used by aware user only
235 /// \brief If user knows more about his images than gdcm does,
236 /// he may supply his own comparison function.
237 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
239 void Sort(FileList *fileList, bool (*pt2Func)( File *file1, File *file2) );
241 bool m_UseSeriesDetails;
242 /// \brief distance between the 2 first -adjancent- slices, along the slice normal
243 /// Computed during ImagePositionPatientOrdering() process.
244 /// (we need to sort the whole image set to do that)
245 /// To be used *immediately after* ImagePositionPatientOrdering()
246 /// (it's a member of the FileHelper, *not* of the FileList !)
250 } // end namespace gdcm
252 //-----------------------------------------------------------------------------