ITK  4.2.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 
21 
22 #include "itkObject.h"
23 #include "itkObjectFactory.h"
24 #include "itkMacro.h"
25 #include <vector>
26 
27 #include "DICOMParser.h"
28 #include "DICOMAppHelper.h"
29 
30 namespace itk
31 {
46 class ITK_EXPORT DICOMSeriesFileNames:public Object
47 {
48 public:
51  typedef Object Superclass;
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:
153  void PrintSelf(std::ostream & os, Indent indent) const;
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 
167  std::string m_Directory;
173 
175 
178 };
179 } //namespace ITK
180 
181 #endif // __itkDICOMSeriesFileNames_h
182