]> Creatis software - gdcm.git/blob - src/gdcmSerieHelper.h
User may now use
[gdcm.git] / src / gdcmSerieHelper.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmSerieHelper.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/29 15:07:16 $
7   Version:   $Revision: 1.15 $
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    void OrderFileList(FileList *coherentFileList);
58    
59    /// \brief Gets the FIRST *coherent* File List.
60    ///        Deprecated; kept not to break the API
61    /// \note Caller must call OrderFileList first
62    /// @return the (first) *coherent* File List
63    const FileList &GetFileList() { return *CoherentFileListHT.begin()->second; }
64   
65    FileList *GetFirstCoherentFileList();
66    FileList *GetNextCoherentFileList();
67    FileList *GetCoherentFileList(std::string serieUID);
68
69    /// All the following allow user to restrict DICOM file to be part
70    /// of a particular serie
71    GDCM_LEGACY( void AddRestriction(TagKey const &key, std::string const &value) );
72    void AddRestriction(uint16_t group, uint16_t elem, 
73                        std::string const &value, int op);
74   
75 /**
76  * \brief Sets the LoadMode as a boolean string. 
77  *        NO_SEQ, NO_SHADOW, NO_SHADOWSEQ
78  ... (nothing more, right now)
79  *        WARNING : before using NO_SHADOW, be sure *all* your files
80  *        contain accurate values in the 0x0000 element (if any) 
81  *        of *each* Shadow Group. The parser will fail if the size is wrong !
82  * @param   mode Load mode to be used    
83  */
84    void SetLoadMode (int mode) { LoadMode = mode; }
85
86 /// Brief User wants the files to be sorted Direct Order (default value)
87    void SetSortOrderToDirect()  { DirectOrder = true;  }
88
89 /// Brief User wants the files to be sorted Reverse Order 
90    void SetSortOrderToReverse() { DirectOrder = false; }
91
92 private:
93    bool ImagePositionPatientOrdering(FileList *coherentFileList);
94    bool ImageNumberOrdering(FileList *coherentFileList);
95    bool FileNameOrdering(FileList *coherentFileList);
96    
97    static bool ImageNumberLessThan(File *file1, File *file2);
98    static bool ImageNumberGreaterThan(File *file1, File *file2);
99    static bool FileNameLessThan(File *file1, File *file2);
100    static bool FileNameGreaterThan(File *file1, File *file2);
101
102 //Attributes:
103    CoherentFileListmap CoherentFileListHT;
104    CoherentFileListmap::iterator ItListHt;
105
106    typedef std::pair<TagKey, std::string> Rule;
107    typedef std::vector<Rule> SerieRestrictions;
108    SerieRestrictions Restrictions;
109    
110    // New style for (extented) Rules (Moreover old one doesn't compile)
111    typedef struct {
112       uint16_t group;
113       uint16_t elem;
114       std::string value;
115       int op;
116    } ExRule;
117    typedef std::vector<ExRule> SerieExRestrictions;
118    SerieExRestrictions ExRestrictions;
119
120    /// \brief Bit string integer (each one considered as a boolean)
121    ///        Bit 0 : Skip Sequences,    if possible
122    ///        Bit 1 : Skip Shadow Groups if possible
123    ///        Probabely, some more to add
124    int LoadMode;
125
126    /// \brief whether we want to sort in direct order or not (reverse order).
127    ///        To be used by aware user only
128    bool DirectOrder;
129 };
130
131 } // end namespace gdcm
132
133 //-----------------------------------------------------------------------------
134 #endif