1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2005/12/16 13:48:46 $
7 Version: $Revision: 1.34 $
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;
36 /// \brief XCoherent stands for 'Extra Coherent',
37 /// (The name 'Coherent' would be enough but it was used before;
38 /// I don't want to put a bomb in the code)
39 /// Any 'better name' is welcome !
40 typedef std::map<std::string, FileList *> XCoherentFileSetmap;
42 typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
44 //-----------------------------------------------------------------------------
47 * This class should be used for a stack of 2D dicom images.
49 * - It allows to explore (recursively or not) a directory and
50 * makes a set of 'Single SerieUID Filesets'
52 * - - to sort any of the 'Single SerieUID Fileset' on the image position.
53 * - - to split any of the Single SerieUID Filesets (better use this name than
54 * 'CoherentFileList' : it's NOT a std::list, files are NOT coherent ...)
55 * into several XCoherent Filesets
56 * XCoherent stands for 'Extra Coherent' (same orientation, or same position)
58 class GDCM_EXPORT SerieHelper : public RefCounter
60 gdcmTypeMacro(SerieHelper);
63 /// SingleSerieUIDFileSetmap replaces the former CoherentFileListmap
64 /// ( List were actually std::vectors, and wher no coherent at all :
65 /// They were only Single SeriesInstanceUID File sets)
66 typedef std::map<std::string, FileList *> SingleSerieUIDFileSetmap;
68 typedef std::vector<File* > FileVector;
70 /// \brief Constructs a SerieHelper with a RefCounter
71 static SerieHelper *New() {return new SerieHelper();}
73 virtual ~SerieHelper();
74 void Print(std::ostream &os = std::cout, std::string const &indent = "" );
76 /// \todo should return bool or throw error ?
77 void AddFileName(std::string const &filename);
78 void AddGdcmFile(File *header);
80 void SetDirectory(std::string const &dir, bool recursive=false);
81 bool IsCoherent(FileList *fileSet);
82 void OrderFileList(FileList *fileSet);
84 /// \brief Gets the FIRST Single SerieUID Fileset.
85 /// Deprecated; kept not to break the API
86 /// \note Caller must call OrderFileList first
87 /// @return the (first) Single SerieUID Fileset
88 const FileList &GetFileList()
89 { return *SingleSerieUIDFileSetHT.begin()->second; }
91 GDCM_LEGACY( FileList *GetFirstCoherentFileList() );
92 GDCM_LEGACY( FileList *GetNextCoherentFileList() );
93 GDCM_LEGACY( FileList *GetCoherentFileList(std::string serieUID) );
95 FileList *GetFirstSingleSerieUIDFileSet();
96 FileList *GetNextSingleSerieUIDFileSet();
97 FileList *GetSingleSerieUIDFileSet(std::string serieUID);
98 /// brief returns the 'Series Instance UID' Single SerieUID FileSet
99 std::string GetCurrentSerieUIDFileSetUID()
100 { return (*ItFileSetHt).first; }
101 /// All the following allow user to restrict DICOM file to be part
102 /// of a particular serie
103 /// \todo : find a trick to allow user to say the retrictetons are ored
105 /// ex : keep the images whose SerieNumber is 101 or 102 or 103.
106 void AddRestriction(TagKey const &key, std::string const &value, int op);
107 void AddRestriction(uint16_t group, uint16_t elem, std::string const &value,
110 /// \brief Use additional series information such as ProtocolName
111 /// and SeriesName to identify when a single SeriesUID contains
112 /// multiple 3D volumes - as can occur with perfusion and DTI imaging
113 void SetUseSeriesDetails( bool useSeriesDetails )
114 { m_UseSeriesDetails = useSeriesDetails;}
115 bool GetUseSeriesDetails( ){ return m_UseSeriesDetails; }
117 void AddSeriesDetail(uint16_t group, uint16_t elem);
119 // \brief Create a string that uniquely identifies a series. By default
120 // uses the SeriesUID. If UseSeriesDetails(true) has been called,
121 // then additional identifying information is used.
122 std::string CreateUniqueSeriesIdentifier( File * inFile );
126 * \brief Sets the LoadMode as a boolean string.
127 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
128 * ... (nothing more, right now)
129 * WARNING : before using LD_NOSHADOW, be sure *all* your files
130 * contain accurate values in the 0x0000 element (if any)
131 * of *each* Shadow Group. The parser will fail if the size is wrong !
132 * @param mode Load mode to be used
134 void SetLoadMode (int mode) { LoadMode = mode; }
136 /// Brief User wants the files to be sorted Direct Order (default value)
137 void SetSortOrderToDirect() { DirectOrder = true; }
139 /// Brief User wants the files to be sorted Reverse Order
140 void SetSortOrderToReverse() { DirectOrder = false; }
142 /// to allow user to give is own comparison function
143 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
144 { UserLessThanFunction = userFunc; }
146 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
147 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
148 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
149 uint16_t group, uint16_t elem);
155 bool UserOrdering(FileList *fileSet);
156 bool ImagePositionPatientOrdering(FileList *fileSet);
157 bool ImageNumberOrdering(FileList *fileSet);
158 bool FileNameOrdering(FileList *fileSet);
160 static bool ImageNumberLessThan(File *file1, File *file2);
161 static bool ImageNumberGreaterThan(File *file1, File *file2);
162 static bool FileNameLessThan(File *file1, File *file2);
163 static bool FileNameGreaterThan(File *file1, File *file2);
167 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
168 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
170 typedef std::pair<TagKey, std::string> Rule;
171 typedef std::vector<Rule> SerieRestrictions;
172 SerieRestrictions Restrictions;
174 // New style for (extented) Rules
181 typedef std::vector<ExRule> SerieExRestrictions;
182 SerieExRestrictions ExRestrictions;
188 typedef std::vector<ExDetail> SeriesExDetails;
189 SeriesExDetails ExDetails;
191 bool m_UseSeriesDetails;
193 /// \brief Bit string integer (each one considered as a boolean)
194 /// Bit 0 : Skip Sequences, if possible
195 /// Bit 1 : Skip Shadow Groups if possible
196 /// Probabely, some more to add
199 /// \brief whether we want to sort in direct order or not (reverse order).
200 /// To be used by aware user only
203 /// \brief If user knows more about his images than gdcm does,
204 /// he may supply his own comparison function.
205 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
209 } // end namespace gdcm
211 //-----------------------------------------------------------------------------