ITK  4.6.0
Insight Segmentation and Registration Toolkit
itkDICOMSeriesFileNames.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkDICOMSeriesFileNames_h
19 #define __itkDICOMSeriesFileNames_h
20 #if !defined( ITK_LEGACY_REMOVE )
21 
22 
23 #include "itkObject.h"
24 #include "itkObjectFactory.h"
25 #include "itkMacro.h"
26 #include <vector>
27 
28 #include "DICOMParser.h"
29 #include "DICOMAppHelper.h"
30 
31 namespace itk
32 {
46 class DICOMSeriesFileNames:public Object
47 {
48 public:
50  typedef DICOMSeriesFileNames Self;
51  typedef Object Superclass;
52  typedef SmartPointer< Self > Pointer;
53 
55  itkNewMacro(Self);
56 
58  itkTypeMacro(DICOMSeriesFileNames, Object);
59 
60  /* -------- Define the API for DICOMSeriesFileNames ----------- */
61 
71  void SetDirectory(const std::string & dir)
72  {
73  if ( m_Directory != dir )
74  {
75  m_Directory = dir;
76  this->Modified();
78 
79  // Clear the SeriesUIDs and FileNames
80  m_SeriesUIDs.clear();
81  m_FileNames.clear();
82  m_AppHelper.Clear();
83  }
84 
85  // Keep track of when the directory name was set so we can
86  // compare it when the directory was last scanned. We set this
87  // modified time each time SetDirectory() is called. This allows
88  // a call to SetDirectory() to force a directory to be rescanned
89  // the next time GetFileNames() or GetSeriesUIDs() is called.
90  m_DirectorySetTime.Modified();
91  }
92 
94  itkGetStringMacro(Directory);
95 
98  itkSetMacro(Ascending, bool);
99  itkGetConstMacro(Ascending, bool);
100  itkBooleanMacro(Ascending);
102 
104  typedef std::vector< std::string > FileNamesArrayType;
105 
109  const FileNamesArrayType & GetSeriesUIDs(bool recursive = false);
110 
113  const FileNamesArrayType & GetSeriesDescriptions(){ return m_SeriesDescriptions; }
114  const FileNamesArrayType & GetSeriesBodyParts(){ return m_BodyParts; }
115  const FileNamesArrayType & GetSeriesScanOptions(){ return m_ScanOptions; }
117 
121  const FileNamesArrayType & GetFileNames(bool recursive = false);
122 
127  const FileNamesArrayType & GetFileNames(const std::string & seriesUID,
128  bool recursive = false);
129 
134  typedef enum { SortByImageNumber, SortBySliceLocation, SortByImagePositionPatient } FileNameSortingOrderType;
135  itkSetEnumMacro(FileNameSortingOrder, FileNameSortingOrderType);
136  itkGetEnumMacro(FileNameSortingOrder, FileNameSortingOrderType);
137  void SetFileNameSortingOrderToSortByImageNumber()
138  { this->SetFileNameSortingOrder(SortByImageNumber); }
139  void SetFileNameSortingOrderToSortBySliceLocation()
140  { this->SetFileNameSortingOrder(SortBySliceLocation); }
141  void SetFileNameSortingOrderToSortByImagePositionPatient()
142  { this->SetFileNameSortingOrder(SortByImagePositionPatient); }
144 
148  std::string GetFileName(const std::string & instanceUID);
149 
150 protected:
151  DICOMSeriesFileNames();
152  ~DICOMSeriesFileNames() {}
153  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
154 
155 private:
156  DICOMSeriesFileNames(const Self &); //purposely not implemented
157  void operator=(const Self &); //purposely not implemented
158 
159  int CanReadFile(const char *fname);
160 
161  void RecurseDirectory(std::string directory, FileNamesArrayType & filenames);
162 
163  itkdicomparser::DICOMParser m_Parser;
164  itkdicomparser::DICOMAppHelper m_AppHelper;
165 
166  bool m_Ascending;
167  std::string m_Directory;
168  FileNamesArrayType m_FileNames;
169  FileNamesArrayType m_SeriesUIDs;
170  FileNamesArrayType m_SeriesDescriptions;
171  FileNamesArrayType m_BodyParts;
172  FileNamesArrayType m_ScanOptions;
173 
174  FileNameSortingOrderType m_FileNameSortingOrder;
175 
176  TimeStamp m_DirectorySetTime;
177  TimeStamp m_DirectoryScanTime;
178 };
179 } //namespace ITK
180 
181 #endif //#if !defined( ITK_LEGACY_REMOVE )
182 #endif // __itkDICOMSeriesFileNames_h