]> Creatis software - gdcm.git/blob - src/gdcmSerieHelper.h
Add SerieHelper::IsCoherent() method to allow checking that the files with same
[gdcm.git] / src / gdcmSerieHelper.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmSerieHelper.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/30 18:13:24 $
7   Version:   $Revision: 1.16 $
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 //-----------------------------------------------------------------------------
35 /**
36  * \brief  
37  * - This class should be used for a stack of 2D dicom images.
38  *   It allows to explore (recursively or not) a directory and 
39  *   makes a set of 'Coherent Files' list (coherent : same Serie UID)
40  *   It allows to sort any of the Coherent File list on the image position
41  */
42 class GDCM_EXPORT SerieHelper 
43 {
44 public:
45    typedef std::map<std::string, FileList *> CoherentFileListmap;
46    typedef std::vector<File* > FileVector;
47
48    SerieHelper();
49    ~SerieHelper();
50    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
51
52    /// \todo should return bool or throw error ?
53    void AddFileName(std::string const &filename);
54    void AddGdcmFile(File *header);
55
56    void SetDirectory(std::string const &dir, bool recursive=false);
57    bool IsCoherent(FileList *coherentFileList);
58    void OrderFileList(FileList *coherentFileList);
59    
60    /// \brief Gets the FIRST *coherent* File List.
61    ///        Deprecated; kept not to break the API
62    /// \note Caller must call OrderFileList first
63    /// @return the (first) *coherent* File List
64    const FileList &GetFileList() { return *CoherentFileListHT.begin()->second; }
65   
66    FileList *GetFirstCoherentFileList();
67    FileList *GetNextCoherentFileList();
68    FileList *GetCoherentFileList(std::string serieUID);
69
70    /// All the following allow user to restrict DICOM file to be part
71    /// of a particular serie
72    GDCM_LEGACY( void AddRestriction(TagKey const &key, std::string const &value) );
73    void AddRestriction(uint16_t group, uint16_t elem, 
74                        std::string const &value, int op);
75   
76 /**
77  * \brief Sets the LoadMode as a boolean string. 
78  *        NO_SEQ, NO_SHADOW, NO_SHADOWSEQ
79  ... (nothing more, right now)
80  *        WARNING : before using NO_SHADOW, be sure *all* your files
81  *        contain accurate values in the 0x0000 element (if any) 
82  *        of *each* Shadow Group. The parser will fail if the size is wrong !
83  * @param   mode Load mode to be used    
84  */
85    void SetLoadMode (int mode) { LoadMode = mode; }
86
87 /// Brief User wants the files to be sorted Direct Order (default value)
88    void SetSortOrderToDirect()  { DirectOrder = true;  }
89
90 /// Brief User wants the files to be sorted Reverse Order 
91    void SetSortOrderToReverse() { DirectOrder = false; }
92
93 private:
94    bool ImagePositionPatientOrdering(FileList *coherentFileList);
95    bool ImageNumberOrdering(FileList *coherentFileList);
96    bool FileNameOrdering(FileList *coherentFileList);
97    
98    static bool ImageNumberLessThan(File *file1, File *file2);
99    static bool ImageNumberGreaterThan(File *file1, File *file2);
100    static bool FileNameLessThan(File *file1, File *file2);
101    static bool FileNameGreaterThan(File *file1, File *file2);
102
103 //Attributes:
104    CoherentFileListmap CoherentFileListHT;
105    CoherentFileListmap::iterator ItListHt;
106
107    typedef std::pair<TagKey, std::string> Rule;
108    typedef std::vector<Rule> SerieRestrictions;
109    SerieRestrictions Restrictions;
110    
111    // New style for (extented) Rules (Moreover old one doesn't compile)
112    typedef struct {
113       uint16_t group;
114       uint16_t elem;
115       std::string value;
116       int op;
117    } ExRule;
118    typedef std::vector<ExRule> SerieExRestrictions;
119    SerieExRestrictions ExRestrictions;
120
121    /// \brief Bit string integer (each one considered as a boolean)
122    ///        Bit 0 : Skip Sequences,    if possible
123    ///        Bit 1 : Skip Shadow Groups if possible
124    ///        Probabely, some more to add
125    int LoadMode;
126
127    /// \brief whether we want to sort in direct order or not (reverse order).
128    ///        To be used by aware user only
129    bool DirectOrder;
130 };
131
132 } // end namespace gdcm
133
134 //-----------------------------------------------------------------------------
135 #endif