]> Creatis software - gdcm.git/blob - src/gdcmSerieHelper.h
Extend 'Restriction' syntax :
[gdcm.git] / src / gdcmSerieHelper.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmSerieHelper.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/21 05:00:30 $
7   Version:   $Revision: 1.14 $
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 private:
87    bool ImagePositionPatientOrdering(FileList *coherentFileList);
88    bool ImageNumberOrdering(FileList *coherentFileList);
89    bool FileNameOrdering(FileList *coherentFileList);
90    
91    static bool ImageNumberLessThan(File *file1, File *file2);
92    static bool FileNameLessThan(File *file1, File *file2);
93
94 //Attributes:
95    CoherentFileListmap CoherentFileListHT;
96    CoherentFileListmap::iterator ItListHt;
97
98    typedef std::pair<TagKey, std::string> Rule;
99    typedef std::vector<Rule> SerieRestrictions;
100    SerieRestrictions Restrictions;
101    
102    // New style for (extented) Rules (Moreover old one doesn't compile)
103    typedef struct {
104       uint16_t group;
105       uint16_t elem;
106       std::string value;
107       int op;
108    } ExRule;
109    typedef std::vector<ExRule> SerieExRestrictions;
110    SerieExRestrictions ExRestrictions;
111
112    /// \brief Bit string integer (each one considered as a boolean)
113    ///        Bit 0 : Skip Sequences,    if possible
114    ///        Bit 1 : Skip Shadow Groups if possible
115    ///        Probabely, some more to add
116    int LoadMode;
117 };
118
119 } // end namespace gdcm
120
121 //-----------------------------------------------------------------------------
122 #endif