]> Creatis software - gdcm.git/blob - src/gdcmSerieHelper.h
ENH: Try to commit conflicts (again)
[gdcm.git] / src / gdcmSerieHelper.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmSerieHelper.h,v $
5   Language:  C++
6   Date:      $Date: 2005/09/06 16:47:04 $
7   Version:   $Revision: 1.21 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #ifndef GDCMSERIEHELPER_H
20 #define GDCMSERIEHELPER_H
21
22 #include "gdcmCommon.h" 
23 #include "gdcmDebug.h"  // for LEGACY
24  
25 #include <vector>
26 #include <iostream>
27 #include <map>
28
29 namespace gdcm 
30 {
31 class File;
32 typedef std::vector<File* > FileList;
33
34 typedef bool (*BOOL_FUNCTION_PFILE_PFILE_POINTER)(File *, File *);
35
36 //-----------------------------------------------------------------------------
37 /**
38  * \brief  
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
43  */
44 class GDCM_EXPORT SerieHelper 
45 {
46 public:
47    typedef std::map<std::string, FileList *> CoherentFileListmap;
48    typedef std::vector<File* > FileVector;
49
50    SerieHelper();
51    ~SerieHelper();
52    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
53
54    /// \todo should return bool or throw error ?
55    void AddFileName(std::string const &filename);
56    void AddGdcmFile(File *header);
57
58    void SetDirectory(std::string const &dir, bool recursive=false);
59    bool IsCoherent(FileList *coherentFileList);
60    void OrderFileList(FileList *coherentFileList);
61    
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; }
67   
68    FileList *GetFirstCoherentFileList();
69    FileList *GetNextCoherentFileList();
70    FileList *GetCoherentFileList(std::string serieUID);
71
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);
77   
78 /**
79  * \brief Sets the LoadMode as a boolean string. 
80 <<<<<<< gdcmSerieHelper.h
81  *        LD_NOSEQ, LD_NOSHADOW, LD_NOSHADOWSEQ
82  ... (nothing more, right now)
83 =======
84  *        NO_SEQ, NO_SHADOW, NO_SHADOWSEQ
85  *        (nothing more, right now)
86 >>>>>>> 1.17
87  *        WARNING : before using NO_SHADOW, be sure *all* your files
88  *        contain accurate values in the 0x0000 element (if any) 
89  *        of *each* Shadow Group. The parser will fail if the size is wrong !
90  * @param   mode Load mode to be used    
91  */
92    void SetLoadMode (int mode) { LoadMode = mode; }
93
94 /// Brief User wants the files to be sorted Direct Order (default value)
95    void SetSortOrderToDirect()  { DirectOrder = true;  }
96
97 /// Brief User wants the files to be sorted Reverse Order 
98    void SetSortOrderToReverse() { DirectOrder = false; }
99
100    /// to allow user to give is own comparison function
101    void SetUserLessThanFunction( BOOL_FUNCTION_PFILE_PFILE_POINTER userFunc ) 
102                         { UserLessThanFunction = userFunc; }   
103 private:
104    bool UserOrdering(FileList *coherentFileList);
105    bool ImagePositionPatientOrdering(FileList *coherentFileList);
106    bool ImageNumberOrdering(FileList *coherentFileList);
107    bool FileNameOrdering(FileList *coherentFileList);
108    
109    static bool ImageNumberLessThan(File *file1, File *file2);
110    static bool ImageNumberGreaterThan(File *file1, File *file2);
111    static bool FileNameLessThan(File *file1, File *file2);
112    static bool FileNameGreaterThan(File *file1, File *file2);
113
114 //Attributes:
115    CoherentFileListmap CoherentFileListHT;
116    CoherentFileListmap::iterator ItListHt;
117
118    typedef std::pair<TagKey, std::string> Rule;
119    typedef std::vector<Rule> SerieRestrictions;
120    SerieRestrictions Restrictions;
121    
122    // New style for (extented) Rules (Moreover old one doesn't compile)
123    typedef struct {
124       uint16_t group;
125       uint16_t elem;
126       std::string value;
127       int op;
128    } ExRule;
129    typedef std::vector<ExRule> SerieExRestrictions;
130    SerieExRestrictions ExRestrictions;
131
132    /// \brief Bit string integer (each one considered as a boolean)
133    ///        Bit 0 : Skip Sequences,    if possible
134    ///        Bit 1 : Skip Shadow Groups if possible
135    ///        Probabely, some more to add
136    int LoadMode;
137
138    /// \brief whether we want to sort in direct order or not (reverse order).
139    ///        To be used by aware user only
140    bool DirectOrder;
141
142    /// \brief If user knows more about his images than gdcm does,
143    ///        he may supply his own comparison function.
144     BOOL_FUNCTION_PFILE_PFILE_POINTER UserLessThanFunction;
145
146 };
147
148 } // end namespace gdcm
149
150 //-----------------------------------------------------------------------------
151 #endif