]> Creatis software - gdcm.git/blob - src/gdcmSerieHelper.h
Doxygenation
[gdcm.git] / src / gdcmSerieHelper.h
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmSerieHelper.h,v $
5   Language:  C++
6   Date:      $Date: 2005/07/17 04:26:57 $
7   Version:   $Revision: 1.12 $
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
24 #include <vector>
25 #include <iostream>
26 #include <map>
27
28 namespace gdcm 
29 {
30 class File;
31 typedef std::vector<File* > FileList;
32
33 //-----------------------------------------------------------------------------
34 /**
35  * \brief  
36  * - This class should be used for a stack of 2D dicom images.
37  *   It allows to explore (recursively or not) a directory and 
38  *   makes a set of 'Coherent Files' list (coherent : same Serie UID)
39  *   It allows to sort any of the Coherent File list on the image position
40  */
41 class GDCM_EXPORT SerieHelper 
42 {
43 public:
44    typedef std::map<std::string, FileList *> CoherentFileListmap;
45    typedef std::vector<File* > FileVector;
46
47    SerieHelper();
48    ~SerieHelper();
49    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
50
51    /// \todo should return bool or throw error ?
52    void AddFileName(std::string const &filename);
53    void SetDirectory(std::string const &dir, bool recursive=false);
54    void OrderFileList(FileList *coherentFileList);
55    
56    /// \brief Gets the FIRST *coherent* File List.
57    ///        Deprecated; kept not to break the API
58    /// \note Caller must call OrderFileList first
59    /// @return the (first) *coherent* File List
60    const FileList &GetFileList() { return *CoherentFileListHT.begin()->second; }
61   
62    FileList *GetFirstCoherentFileList();
63    FileList *GetNextCoherentFileList();
64    FileList *GetCoherentFileList(std::string serieUID);
65
66    /// All the following allow user to restrict DICOM file to be part
67    /// of a particular serie
68    void AddRestriction(TagKey const &key, std::string const &value);
69   
70 /**
71  * \brief Sets the LoadMode as a boolean string. 
72  *        NO_SEQ, NO_SHADOW, NO_SHADOWSEQ
73  ... (nothing more, right now)
74  *        WARNING : before using NO_SHADOW, be sure *all* your files
75  *        contain accurate values in the 0x0000 element (if any) 
76  *        of *each* Shadow Group. The parser will fail if the size is wrong !
77  * @param   mode Load mode to be used    
78  */
79    void SetLoadMode (int mode) { LoadMode = mode; }
80
81 private:
82    bool ImagePositionPatientOrdering(FileList *coherentFileList);
83    bool ImageNumberOrdering(FileList *coherentFileList);
84    bool FileNameOrdering(FileList *coherentFileList);
85    
86    static bool ImageNumberLessThan(File *file1, File *file2);
87    static bool FileNameLessThan(File *file1, File *file2);
88
89 //Attributes:
90    CoherentFileListmap CoherentFileListHT;
91    CoherentFileListmap::iterator ItListHt;
92
93    typedef std::pair<TagKey, std::string> Rule;
94    typedef std::vector<Rule> SerieRestrictions;
95    SerieRestrictions Restrictions;
96
97    /// \brief Bit string integer (each one considered as a boolean)
98    ///        Bit 0 : Skip Sequences,    if possible
99    ///        Bit 1 : Skip Shadow Groups if possible
100    ///        Probabely, some more to add
101    int LoadMode;
102 };
103
104 } // end namespace gdcm
105
106 //-----------------------------------------------------------------------------
107 #endif