1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2005/12/21 14:48:09 $
7 Version: $Revision: 1.35 $
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, bool convert);
119 std::string CreateUniqueSeriesIdentifier( File * inFile );
121 std::string CreateUserDefinedFileIdentifier( File * inFile );
124 * \brief Sets the LoadMode as a boolean string.
125 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
126 * ... (nothing more, right now)
127 * WARNING : before using LD_NOSHADOW, be sure *all* your files
128 * contain accurate values in the 0x0000 element (if any)
129 * of *each* Shadow Group. The parser will fail if the size is wrong !
130 * @param mode Load mode to be used
132 void SetLoadMode (int mode) { LoadMode = mode; }
134 /// Brief User wants the files to be sorted Direct Order (default value)
135 void SetSortOrderToDirect() { DirectOrder = true; }
137 /// Brief User wants the files to be sorted Reverse Order
138 void SetSortOrderToReverse() { DirectOrder = false; }
140 /// to allow user to give is own comparison function
141 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
142 { UserLessThanFunction = userFunc; }
144 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
145 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
146 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
147 uint16_t group, uint16_t elem);
153 bool UserOrdering(FileList *fileSet);
154 bool ImagePositionPatientOrdering(FileList *fileSet);
155 bool ImageNumberOrdering(FileList *fileSet);
156 bool FileNameOrdering(FileList *fileSet);
158 static bool ImageNumberLessThan(File *file1, File *file2);
159 static bool ImageNumberGreaterThan(File *file1, File *file2);
160 static bool FileNameLessThan(File *file1, File *file2);
161 static bool FileNameGreaterThan(File *file1, File *file2);
165 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
166 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
168 typedef std::pair<TagKey, std::string> Rule;
169 typedef std::vector<Rule> SerieRestrictions;
170 SerieRestrictions Restrictions;
172 // New style for (extented) Rules
179 typedef std::vector<ExRule> SerieExRestrictions;
180 SerieExRestrictions ExRestrictions;
187 typedef std::vector<ExDetail> SeriesExDetails;
188 SeriesExDetails ExDetails;
190 bool m_UseSeriesDetails;
192 /// \brief Bit string integer (each one considered as a boolean)
193 /// Bit 0 : Skip Sequences, if possible
194 /// Bit 1 : Skip Shadow Groups if possible
195 /// Probabely, some more to add
198 /// \brief whether we want to sort in direct order or not (reverse order).
199 /// To be used by aware user only
202 /// \brief If user knows more about his images than gdcm does,
203 /// he may supply his own comparison function.
204 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
208 } // end namespace gdcm
210 //-----------------------------------------------------------------------------