ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDICOMSeriesFileNames.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkDICOMSeriesFileNames_h
00019 #define __itkDICOMSeriesFileNames_h
00020 
00021 
00022 #include "itkObject.h"
00023 #include "itkObjectFactory.h"
00024 #include "itkMacro.h"
00025 #include <vector>
00026 
00027 #include "DICOMParser.h"
00028 #include "DICOMAppHelper.h"
00029 
00030 namespace itk
00031 {
00046 class ITK_EXPORT DICOMSeriesFileNames:public Object
00047 {
00048 public:
00050   typedef DICOMSeriesFileNames Self;
00051   typedef Object               Superclass;
00052   typedef SmartPointer< Self > Pointer;
00053 
00055   itkNewMacro(Self);
00056 
00058   itkTypeMacro(DICOMSeriesFileNames, Object);
00059 
00060   /* -------- Define the API for DICOMSeriesFileNames ----------- */
00061 
00071   void SetDirectory(const std::string & dir)
00072   {
00073     if ( m_Directory != dir )
00074       {
00075       m_Directory = dir;
00076       this->Modified();
00078 
00079       // Clear the SeriesUIDs and FileNames
00080       m_SeriesUIDs.clear();
00081       m_FileNames.clear();
00082       m_AppHelper.Clear();
00083       }
00084 
00085     // Keep track of when the directory name was set so we can
00086     // compare it when the directory was last scanned. We set this
00087     // modified time each time SetDirectory() is called. This allows
00088     // a call to SetDirectory() to force a directory to be rescanned
00089     // the next time GetFileNames() or GetSeriesUIDs() is called.
00090     m_DirectorySetTime.Modified();
00091   }
00092 
00094   itkGetStringMacro(Directory);
00095 
00098   itkSetMacro(Ascending, bool);
00099   itkGetConstMacro(Ascending, bool);
00100   itkBooleanMacro(Ascending);
00102 
00104   typedef std::vector< std::string > FileNamesArrayType;
00105 
00109   const FileNamesArrayType & GetSeriesUIDs(bool recursive = false);
00110 
00113   const FileNamesArrayType & GetSeriesDescriptions(){ return m_SeriesDescriptions; }
00114   const FileNamesArrayType & GetSeriesBodyParts(){ return m_BodyParts; }
00115   const FileNamesArrayType & GetSeriesScanOptions(){ return m_ScanOptions; }
00117 
00121   const FileNamesArrayType & GetFileNames(bool recursive = false);
00122 
00127   const FileNamesArrayType & GetFileNames(const std::string & seriesUID,
00128                                           bool recursive = false);
00129 
00134   typedef enum { SortByImageNumber, SortBySliceLocation, SortByImagePositionPatient } FileNameSortingOrderType;
00135   itkSetEnumMacro(FileNameSortingOrder, FileNameSortingOrderType);
00136   itkGetEnumMacro(FileNameSortingOrder, FileNameSortingOrderType);
00137   void SetFileNameSortingOrderToSortByImageNumber()
00138   { this->SetFileNameSortingOrder(SortByImageNumber); }
00139   void SetFileNameSortingOrderToSortBySliceLocation()
00140   { this->SetFileNameSortingOrder(SortBySliceLocation); }
00141   void SetFileNameSortingOrderToSortByImagePositionPatient()
00142   { this->SetFileNameSortingOrder(SortByImagePositionPatient); }
00144 
00148   std::string GetFileName(const std::string & instanceUID);
00149 
00150 protected:
00151   DICOMSeriesFileNames();
00152   ~DICOMSeriesFileNames() {}
00153   void PrintSelf(std::ostream & os, Indent indent) const;
00154 
00155 private:
00156   DICOMSeriesFileNames(const Self &); //purposely not implemented
00157   void operator=(const Self &);       //purposely not implemented
00158 
00159   int CanReadFile(const char *fname);
00160 
00161   void RecurseDirectory(std::string directory, FileNamesArrayType & filenames);
00162 
00163   itkdicomparser::DICOMParser    m_Parser;
00164   itkdicomparser::DICOMAppHelper m_AppHelper;
00165 
00166   bool               m_Ascending;
00167   std::string        m_Directory;
00168   FileNamesArrayType m_FileNames;
00169   FileNamesArrayType m_SeriesUIDs;
00170   FileNamesArrayType m_SeriesDescriptions;
00171   FileNamesArrayType m_BodyParts;
00172   FileNamesArrayType m_ScanOptions;
00173 
00174   FileNameSortingOrderType m_FileNameSortingOrder;
00175 
00176   TimeStamp m_DirectorySetTime;
00177   TimeStamp m_DirectoryScanTime;
00178 };
00179 } //namespace ITK
00180 
00181 #endif // __itkDICOMSeriesFileNames_h
00182