1 /*=========================================================================
4 Module: $RCSfile: gdcmSerieHelper.h,v $
6 Date: $Date: 2005/09/06 16:48:24 $
7 Version: $Revision: 1.22 $
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 "gdcmDebug.h" // for LEGACY
32 typedef std::vector<File* > FileList;
34 typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
36 //-----------------------------------------------------------------------------
39 * - This class should be used for a stack of 2D dicom images.
40 * It allows to explore (recursively or not) a directory and
41 * makes a set of 'Coherent Files' list (coherent : same Serie UID)
42 * It allows to sort any of the Coherent File list on the image position
44 class GDCM_EXPORT SerieHelper
47 typedef std::map<std::string, FileList *> CoherentFileListmap;
48 typedef std::vector<File* > FileVector;
52 void Print(std::ostream &os = std::cout, std::string const &indent = "" );
54 /// \todo should return bool or throw error ?
55 void AddFileName(std::string const &filename);
56 void AddGdcmFile(File *header);
58 void SetDirectory(std::string const &dir, bool recursive=false);
59 bool IsCoherent(FileList *coherentFileList);
60 void OrderFileList(FileList *coherentFileList);
62 /// \brief Gets the FIRST *coherent* File List.
63 /// Deprecated; kept not to break the API
64 /// \note Caller must call OrderFileList first
65 /// @return the (first) *coherent* File List
66 const FileList &GetFileList() { return *CoherentFileListHT.begin()->second; }
68 FileList *GetFirstCoherentFileList();
69 FileList *GetNextCoherentFileList();
70 FileList *GetCoherentFileList(std::string serieUID);
72 /// All the following allow user to restrict DICOM file to be part
73 /// of a particular serie
74 GDCM_LEGACY( void AddRestriction(TagKey const &key, std::string const &value) );
75 void AddRestriction(uint16_t group, uint16_t elem,
76 std::string const &value, int op);
79 * \brief Sets the LoadMode as a boolean string.
80 * LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
81 * ... (nothing more, right now)
82 * WARNING : before using LD_NOSHADOW, be sure *all* your files
83 * contain accurate values in the 0x0000 element (if any)
84 * of *each* Shadow Group. The parser will fail if the size is wrong !
85 * @param mode Load mode to be used
87 void SetLoadMode (int mode) { LoadMode = mode; }
89 /// Brief User wants the files to be sorted Direct Order (default value)
90 void SetSortOrderToDirect() { DirectOrder = true; }
92 /// Brief User wants the files to be sorted Reverse Order
93 void SetSortOrderToReverse() { DirectOrder = false; }
95 /// to allow user to give is own comparison function
96 void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc )
97 { UserLessThanFunction = userFunc; }
99 bool UserOrdering(FileList *coherentFileList);
100 bool ImagePositionPatientOrdering(FileList *coherentFileList);
101 bool ImageNumberOrdering(FileList *coherentFileList);
102 bool FileNameOrdering(FileList *coherentFileList);
104 static bool ImageNumberLessThan(File *file1, File *file2);
105 static bool ImageNumberGreaterThan(File *file1, File *file2);
106 static bool FileNameLessThan(File *file1, File *file2);
107 static bool FileNameGreaterThan(File *file1, File *file2);
110 CoherentFileListmap CoherentFileListHT;
111 CoherentFileListmap::iterator ItListHt;
113 typedef std::pair<TagKey, std::string> Rule;
114 typedef std::vector<Rule> SerieRestrictions;
115 SerieRestrictions Restrictions;
117 // New style for (extented) Rules (Moreover old one doesn't compile)
124 typedef std::vector<ExRule> SerieExRestrictions;
125 SerieExRestrictions ExRestrictions;
127 /// \brief Bit string integer (each one considered as a boolean)
128 /// Bit 0 : Skip Sequences, if possible
129 /// Bit 1 : Skip Shadow Groups if possible
130 /// Probabely, some more to add
133 /// \brief whether we want to sort in direct order or not (reverse order).
134 /// To be used by aware user only
137 /// \brief If user knows more about his images than gdcm does,
138 /// he may supply his own comparison function.
139 BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
143 } // end namespace gdcm
145 //-----------------------------------------------------------------------------