1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2005/10/19 13:17:05 $
7 Version: $Revision: 1.24 $
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 "gdcmCommon.h"
23 #include "gdcmTagKey.h"
24 #include "gdcmDebug.h" // for LEGACY
33 typedef std::vector<File* > FileList;
34 /// XCoherent stands for 'Extra Coherent',
35 /// (The name 'Coherent' would be enough but it was used before;
36 /// I don't want to put a bomb in the code)
37 /// Any 'better name' is welcome !
38 typedef std::map<std::string, FileList *> XCoherentFileSetmap;
40 typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
42 //-----------------------------------------------------------------------------
45 * - This class should be used for a stack of 2D dicom images.
46 * It allows to explore (recursively or not) a directory and
47 * makes a set of 'Coherent Files' lists (coherent : same SerieUID)
49 * - to sort any of the Coherent File list on the image position.
50 * - to split any of the Single SerieUID Filesets (better use this name than
51 * 'Coherent File List' : it's NOT a std::list, files are NOT coherent ...)
52 * into several XCoherent Filesets
53 * XCoherent stands for 'Extra Coherent' (same orientation, or same position)
55 class GDCM_EXPORT SerieHelper
58 // SingleSerieUIDFileSetmap replaces the former CoherentFileListmap
59 // ( List were actually std::vectors, and wher no coherent at all :
60 // They were only Single SeriesInstanceUID File sets)
61 typedef std::map<std::string, FileList *> SingleSerieUIDFileSetmap;
63 typedef std::vector<File* > FileVector;
67 void Print(std::ostream &os = std::cout, std::string const &indent = "" );
69 /// \todo should return bool or throw error ?
70 void AddFileName(std::string const &filename);
71 void AddGdcmFile(File *header);
73 void SetDirectory(std::string const &dir, bool recursive=false);
74 bool IsCoherent(FileList *fileSet);
75 void OrderFileList(FileList *fileSet);
77 /// \brief Gets the FIRST Single SerieUID Fileset.
78 /// Deprecated; kept not to break the API
79 /// \note Caller must call OrderFileList first
80 /// @return the (first) Single SerieUID Fileset
81 const FileList &GetFileList()
82 { return *SingleSerieUIDFileSetHT.begin()->second; }
84 GDCM_LEGACY( FileList *GetFirstCoherentFileList() );
85 GDCM_LEGACY( FileList *GetNextCoherentFileList() );
86 GDCM_LEGACY( FileList *GetCoherentFileList(std::string serieUID) );
88 FileList *GetFirstSingleSerieUIDFileSet();
89 FileList *GetNextSingleSerieUIDFileSet();
90 FileList *GetSingleSerieUIDFileSet(std::string serieUID);
92 /// All the following allow user to restrict DICOM file to be part
93 /// of a particular serie
94 GDCM_LEGACY( void AddRestriction(TagKey const &key, std::string const &value) );
95 void AddRestriction(uint16_t group, uint16_t elem,
96 std::string const &value, int op);
99 * \brief Sets the LoadMode as a boolean string.
100 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
101 * ... (nothing more, right now)
102 * WARNING : before using LD_NOSHADOW, be sure *all* your files
103 * contain accurate values in the 0x0000 element (if any)
104 * of *each* Shadow Group. The parser will fail if the size is wrong !
105 * @param mode Load mode to be used
107 void SetLoadMode (int mode) { LoadMode = mode; }
109 /// Brief User wants the files to be sorted Direct Order (default value)
110 void SetSortOrderToDirect() { DirectOrder = true; }
112 /// Brief User wants the files to be sorted Reverse Order
113 void SetSortOrderToReverse() { DirectOrder = false; }
115 /// to allow user to give is own comparison function
116 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
117 { UserLessThanFunction = userFunc; }
119 XCoherentFileSetmap SplitOnOrientation(FileList *fileSet);
120 XCoherentFileSetmap SplitOnPosition(FileList *fileSet);
121 XCoherentFileSetmap SplitOnTagValue(FileList *fileSet,
122 uint16_t group, uint16_t element);
125 bool UserOrdering(FileList *fileSet);
126 bool ImagePositionPatientOrdering(FileList *fileSet);
127 bool ImageNumberOrdering(FileList *fileSet);
128 bool FileNameOrdering(FileList *fileSet);
130 static bool ImageNumberLessThan(File *file1, File *file2);
131 static bool ImageNumberGreaterThan(File *file1, File *file2);
132 static bool FileNameLessThan(File *file1, File *file2);
133 static bool FileNameGreaterThan(File *file1, File *file2);
137 SingleSerieUIDFileSetmap SingleSerieUIDFileSetHT;
138 SingleSerieUIDFileSetmap::iterator ItFileSetHt;
140 typedef std::pair<TagKey, std::string> Rule;
141 typedef std::vector<Rule> SerieRestrictions;
142 SerieRestrictions Restrictions;
144 // New style for (extented) Rules (Moreover old one doesn't compile)
151 typedef std::vector<ExRule> SerieExRestrictions;
152 SerieExRestrictions ExRestrictions;
154 /// \brief Bit string integer (each one considered as a boolean)
155 /// Bit 0 : Skip Sequences, if possible
156 /// Bit 1 : Skip Shadow Groups if possible
157 /// Probabely, some more to add
160 /// \brief whether we want to sort in direct order or not (reverse order).
161 /// To be used by aware user only
164 /// \brief If user knows more about his images than gdcm does,
165 /// he may supply his own comparison function.
166 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
170 } // end namespace gdcm
172 //-----------------------------------------------------------------------------