1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2005/12/09 12:23:38 $
7 Version: $Revision: 1.33 $
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 void AddRestriction(TagKey const &key, std::string const &value, int op);
105 /// \brief Use additional series information such as ProtocolName
106 /// and SeriesName to identify when a single SeriesUID contains
107 /// multiple 3D volumes - as can occur with perfusion and DTI imaging
108 void SetUseSeriesDetails( bool useSeriesDetails )
109 { m_UseSeriesDetails = useSeriesDetails;}
110 bool GetUseSeriesDetails( ){ return m_UseSeriesDetails; }
112 // \brief Create a string that uniquely identifies a series. By default
113 // uses the SeriesUID. If UseSeriesDetails(true) has been called,
114 // then additional identifying information is used.
115 std::string CreateUniqueSeriesIdentifier( File * inFile );
119 * \brief Sets the LoadMode as a boolean string.
120 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
121 * ... (nothing more, right now)
122 * WARNING : before using LD_NOSHADOW, be sure *all* your files
123 * contain accurate values in the 0x0000 element (if any)
124 * of *each* Shadow Group. The parser will fail if the size is wrong !
125 * @param mode Load mode to be used
127 void SetLoadMode (int mode) { LoadMode = mode; }
129 /// Brief User wants the files to be sorted Direct Order (default value)
130 void SetSortOrderToDirect() { DirectOrder = true; }
132 /// Brief User wants the files to be sorted Reverse Order
133 void SetSortOrderToReverse() { DirectOrder = false; }
135 /// to allow user to give is own comparison function
136 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
137 { UserLessThanFunction = userFunc; }
139 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
140 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
141 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
142 uint16_t group, uint16_t elem);
148 bool UserOrdering(FileList *fileSet);
149 bool ImagePositionPatientOrdering(FileList *fileSet);
150 bool ImageNumberOrdering(FileList *fileSet);
151 bool FileNameOrdering(FileList *fileSet);
153 static bool ImageNumberLessThan(File *file1, File *file2);
154 static bool ImageNumberGreaterThan(File *file1, File *file2);
155 static bool FileNameLessThan(File *file1, File *file2);
156 static bool FileNameGreaterThan(File *file1, File *file2);
160 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
161 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
163 typedef std::pair<TagKey, std::string> Rule;
164 typedef std::vector<Rule> SerieRestrictions;
165 SerieRestrictions Restrictions;
167 // New style for (extented) Rules
174 typedef std::vector<ExRule> SerieExRestrictions;
175 SerieExRestrictions ExRestrictions;
176 bool m_UseSeriesDetails;
178 /// \brief Bit string integer (each one considered as a boolean)
179 /// Bit 0 : Skip Sequences, if possible
180 /// Bit 1 : Skip Shadow Groups if possible
181 /// Probabely, some more to add
184 /// \brief whether we want to sort in direct order or not (reverse order).
185 /// To be used by aware user only
188 /// \brief If user knows more about his images than gdcm does,
189 /// he may supply his own comparison function.
190 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
194 } // end namespace gdcm
196 //-----------------------------------------------------------------------------