| 1 |
/*========================================================================= |
| 2 |
* |
| 3 |
* Copyright NumFOCUS |
| 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 |
* https://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 itkDCMTKSeriesFileNames_h |
| 19 |
#define itkDCMTKSeriesFileNames_h |
| 20 |
#include "ITKIODCMTKExport.h" |
| 21 |
|
| 22 |
#include "itkProcessObject.h" |
| 23 |
#include "itkObjectFactory.h" |
| 24 |
#include "itkMacro.h" |
| 25 |
#include <vector> |
| 26 |
|
| 27 |
namespace itk |
| 28 |
{ |
| 29 |
/** |
| 30 |
* \class DCMTKSeriesFileNames |
| 31 |
* \brief Generate a sequence of filenames from a DICOM series. |
| 32 |
* |
| 33 |
* This class generate a sequence of files whose filenames points to |
| 34 |
* a DICOM file. The ordering is based on the following strategy: |
| 35 |
* Read all images in the directory (assuming there is only one study/series) |
| 36 |
* |
| 37 |
* 1. Extract Image Orientation & Image Position from DICOM images, and then |
| 38 |
* calculate the ordering based on the 3D coordinate of the slice |
| 39 |
* 2. If for some reason this information is not found or failed, another |
| 40 |
* strategy is used: the ordering is based on 'Image Number' |
| 41 |
* 3. If this strategy also failed, then the filenames are ordered by |
| 42 |
* lexicographical order. |
| 43 |
* |
| 44 |
* If multiple volumes are being grouped as a single series for your |
| 45 |
* dicom objects, you may want to try calling ->SetUseSeriesDetails(true) |
| 46 |
* prior to calling SetDirectory(). |
| 47 |
* |
| 48 |
* \ingroup IOFilters |
| 49 |
* |
| 50 |
* \ingroup ITKIODCMTK |
| 51 |
*/ |
| 52 |
class ITKIODCMTK_EXPORT DCMTKSeriesFileNames : public ProcessObject |
| 53 |
{ |
| 54 |
public: |
| 55 |
ITK_DISALLOW_COPY_AND_MOVE(DCMTKSeriesFileNames); |
| 56 |
|
| 57 |
/** Standard class type aliases. */ |
| 58 |
using Self = DCMTKSeriesFileNames; |
| 59 |
using Superclass = ProcessObject; |
| 60 |
using Pointer = SmartPointer<Self>; |
| 61 |
|
| 62 |
/** Type of the container that holds the UID's for the series. */ |
| 63 |
using SeriesUIDContainerType = std::vector<std::string>; |
| 64 |
/** For backwards compatibility. */ |
| 65 |
using SeriesUIDContainer = SeriesUIDContainerType; |
| 66 |
|
| 67 |
/** Type of the container that holds the file names in the series. */ |
| 68 |
using FileNamesContainerType = std::vector<std::string>; |
| 69 |
/** For backwards compatibility */ |
| 70 |
using FilenamesContainer = FileNamesContainerType; |
| 71 |
|
| 72 |
/** Method for creation through the object factory. */ |
| 73 |
itkNewMacro(Self); |
| 74 |
|
| 75 |
/** \see LightObject::GetNameOfClass() */ |
| 76 |
itkOverrideGetNameOfClassMacro(DCMTKSeriesFileNames); |
| 77 |
|
| 78 |
/* -------- Define the API for DCMTKSeriesFileNames ----------- */ |
| 79 |
|
| 80 |
/** Set the directory that contains the DICOM series. */ |
| 81 |
void |
| 82 |
SetInputDirectory(const char * name); |
| 83 |
|
| 84 |
/** Set the directory that contains the DICOM series. */ |
| 85 |
void |
| 86 |
SetInputDirectory(std::string const & name); |
| 87 |
|
| 88 |
/** Set the directory that contains the DICOM series. */ |
| 89 |
void |
| 90 |
SetDirectory(std::string const & name) |
| 91 |
{ |
| 92 |
SetInputDirectory(name); |
| 93 |
} |
| 94 |
|
| 95 |
/** Returns a vector containing the series' file names. The file |
| 96 |
* names are ordered by the strategy define in header. |
| 97 |
* No sorting is done based on UID */ |
| 98 |
const FileNamesContainerType & |
| 99 |
GetInputFileNames(); |
| 100 |
|
| 101 |
/** Set the directory where the output DICOM series should be written. */ |
| 102 |
void |
| 103 |
SetOutputDirectory(std::string const & name) |
| 104 |
{ |
| 105 |
m_OutputDirectory = name; |
| 106 |
this->Modified(); |
| 107 |
} |
| 108 |
|
| 109 |
/** Returns a vector containing the series' file names. The file |
| 110 |
* names are ordered in the same exact order as the input one. |
| 111 |
* This could be dangerous if the writing has changed 3rd position |
| 112 |
* or some other DICOM tag in the header |
| 113 |
*/ |
| 114 |
const FileNamesContainerType & |
| 115 |
GetOutputFileNames(); |
| 116 |
|
| 117 |
/** Returns a vector containing the series' file names. The file |
| 118 |
* names are ordered by the strategy define in header. |
| 119 |
* All DICOM files have the same exact UID equal to the one user's |
| 120 |
* specified. An extended UID may be returned/used if |
| 121 |
* SetUseSeriesDetails(true) has been called. |
| 122 |
*/ |
| 123 |
const FileNamesContainerType & |
| 124 |
GetFileNames(const std::string serie); |
| 125 |
|
| 126 |
/** Returns a vector containing all the UIDs found when parsing the |
| 127 |
* directory specified via SetDirectory. If no directory is specified |
| 128 |
* return an empty vector. An extended UID may be returned/used if |
| 129 |
* SetUseSeriesDetails(true) has been called. |
| 130 |
*/ |
| 131 |
const SeriesUIDContainerType & |
| 132 |
GetSeriesUIDs(); |
| 133 |
|
| 134 |
/** Recursively parse the input directory */ |
| 135 |
itkSetMacro(Recursive, bool); |
| 136 |
itkGetConstMacro(Recursive, bool); |
| 137 |
itkBooleanMacro(Recursive); |
| 138 |
|
| 139 |
/** Use additional series information such as ProtocolName |
| 140 |
* and SeriesName to identify when a single SeriesUID contains |
| 141 |
* multiple 3D volumes - as can occur with perfusion and DTI imaging |
| 142 |
*/ |
| 143 |
void |
| 144 |
SetUseSeriesDetails(bool useSeriesDetails); |
| 145 |
|
| 146 |
/** Returns true if using additional series information such as ProtocolName |
| 147 |
* and SeriesName to identify when a single SeriesUID contains |
| 148 |
* multiple 3D volumes - as can occur with perfusion and DTI imaging |
| 149 |
*/ |
| 150 |
bool |
| 151 |
GetUseSeriesDetails() const |
| 152 |
{ |
| 153 |
return m_UseSeriesDetails; |
| 154 |
} |
| 155 |
|
| 156 |
/** Add more restriction on the selection of a Series. This follows the same |
| 157 |
* approach as SetUseSeriesDetails, but allows a user to add even more DICOM |
| 158 |
* tags to take into account for subrefining a set of DICOM files into multiple |
| 159 |
* series. The tag format is "group|element" of a DICOM tag. |
| 160 |
* \warning UseSeriesDetails needs to be set to true. |
| 161 |
*/ |
| 162 |
void |
| 163 |
AddSeriesRestriction(const std::string & /* tag */) |
| 164 |
{ |
| 165 |
// m_SeriesHelper->AddRestriction(tag); |
| 166 |
} |
| 167 |
|
| 168 |
/** Parse any sequences in the DICOM file. Defaults to false |
| 169 |
* to skip sequences. This makes loading DICOM files faster when |
| 170 |
* sequences are not needed. |
| 171 |
*/ |
| 172 |
itkSetMacro(LoadSequences, bool); |
| 173 |
itkGetConstMacro(LoadSequences, bool); |
| 174 |
itkBooleanMacro(LoadSequences); |
| 175 |
|
| 176 |
/** Parse any private tags in the DICOM file. Defaults to false |
| 177 |
* to skip private tags. This makes loading DICOM files faster when |
| 178 |
* private tags are not needed. |
| 179 |
*/ |
| 180 |
itkSetMacro(LoadPrivateTags, bool); |
| 181 |
itkGetConstMacro(LoadPrivateTags, bool); |
| 182 |
itkBooleanMacro(LoadPrivateTags); |
| 183 |
|
| 184 |
protected: |
| 185 |
DCMTKSeriesFileNames(); |
| 186 |
~DCMTKSeriesFileNames() override; |
| 187 |
void |
| 188 |
PrintSelf(std::ostream & os, Indent indent) const override; |
| 189 |
|
| 190 |
private: |
| 191 |
/** internal method for reading out filenames and UID lists */ |
| 192 |
void |
| 193 |
GetDicomData(const std::string & series, bool saveFileNames); |
| 194 |
/** Contains the input directory where the DICOM series is found */ |
| 195 |
std::string m_InputDirectory{}; |
| 196 |
|
| 197 |
/** Contains the output directory where the DICOM series should be written */ |
| 198 |
std::string m_OutputDirectory{}; |
| 199 |
|
| 200 |
/** Internal structure to keep the list of input/output filenames */ |
| 201 |
FileNamesContainerType m_InputFileNames{}; |
| 202 |
FileNamesContainerType m_OutputFileNames{}; |
| 203 |
|
| 204 |
/** Internal structure to order series from one directory */ |
| 205 |
|
| 206 |
/** Internal structure to keep the list of series UIDs */ |
| 207 |
SeriesUIDContainerType m_SeriesUIDs{}; |
| 208 |
|
| 209 |
bool m_UseSeriesDetails{}; |
| 210 |
bool m_Recursive{}; |
| 211 |
bool m_LoadSequences{}; |
| 212 |
bool m_LoadPrivateTags{}; |
| 213 |
}; |
| 214 |
} // namespace itk |
| 215 |
|
| 216 |
#endif // itkDCMTKSeriesFileNames_h |