18#ifndef itkDCMTKFileReader_h
19#define itkDCMTKFileReader_h
25#ifndef ITKIODCMTK_EXPORT
26# define ITKIODCMTK_EXPORT
30#include "itkByteSwapper.h"
31#include "itkIntTypes.h"
32#include "vnl/vnl_vector.h"
33#include "dcmtk/dcmdata/dcdict.h"
34#include "dcmtk/dcmdata/dcdicent.h"
35#include "dcmtk/dcmdata/dcxfer.h"
36#include "dcmtk/dcmdata/dcvrds.h"
37#include "dcmtk/dcmdata/dcstack.h"
38#include "dcmtk/dcmdata/dcdatset.h"
39#include "dcmtk/dcmdata/dcitem.h"
40#include "dcmtk/dcmdata/dcvrobow.h"
41#include "dcmtk/dcmdata/dcsequen.h"
43#include "itkImageIOBase.h"
44#include "itkMetaDataDictionary.h"
46class DcmSequenceOfItems;
53#define DCMTKExceptionOrErrorReturn(body) \
57 itkGenericExceptionMacro(body); \
61 return EXIT_FAILURE; \
76 int GetElementSQ(
const unsigned short group,
const unsigned short entry,
DCMTKSequence& sequence,
const bool throwException =
true)
const;
79 DcmItem* m_DcmItem{
nullptr };
89 int GetStack(
const unsigned short group,
const unsigned short element, DcmStack& resultStack,
const bool throwException =
true)
const;
90 int GetElementCS(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
92 int GetElementOB(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
94 int GetElementCSorOB(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
96 template <
typename TType>
97 int GetElementDSorOB(
const unsigned short group,
const unsigned short element, TType& target,
const bool throwException =
true)
const
104 if (this->
GetElementOB(group, element, val, throwException) != EXIT_SUCCESS)
108 const char* data = val.c_str();
109 const auto* fptr =
reinterpret_cast<const TType*
>(data);
114 template <
typename TType>
115 int GetElementDSorOB(
const unsigned short group,
const unsigned short element,
int count, TType* target,
const bool throwException =
true)
const
122 if (this->
GetElementOB(group, element, val, throwException) != EXIT_SUCCESS)
126 const char* data = val.c_str();
127 const auto* fptr =
reinterpret_cast<const TType*
>(data);
128 for (
int i = 0; i < count; ++i)
135 int GetElementFD(
const unsigned short group,
const unsigned short element,
int count,
double* target,
const bool throwException =
true)
const;
136 int GetElementFD(
const unsigned short group,
const unsigned short element,
double& target,
const bool throwException =
true)
const;
137 int GetElementDS(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
138 int GetElementTM(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
142 template <
typename TType>
143 int GetElementDS(
const unsigned short group,
const unsigned short element,
unsigned short count, TType* target,
const bool throwException =
true)
const
145 DcmStack resultStack;
146 if (this->
GetStack(group, element, resultStack, throwException) != EXIT_SUCCESS)
150 auto* dsItem =
dynamic_cast<DcmDecimalString*
>(resultStack.top());
151 if (dsItem ==
nullptr)
156 OFVector<Float64> doubleVals;
157 if (dsItem->getFloat64Vector(doubleVals) != EC_Normal)
159 DCMTKExceptionOrErrorReturn(<<
"Cant extract Array from DecimalString " << std::hex << group <<
' ' << std::hex << element << std::dec);
161 if (doubleVals.size() != count)
163 DCMTKExceptionOrErrorReturn(<<
"DecimalString " << std::hex << group <<
' ' << std::hex << element <<
" expected " << count <<
"items, but found " << doubleVals.size()
166 for (
unsigned int i = 0; i < count; ++i)
168 target[i] =
static_cast<TType
>(doubleVals[i]);
172 int GetElementSQ(
const unsigned short group,
const unsigned short element,
DCMTKSequence& target,
const bool throwException =
true)
const;
175 void print(std::ostream& out)
const { this->m_DcmSequenceOfItems->print(out); }
178 DcmSequenceOfItems* m_DcmSequenceOfItems{
nullptr };
195 int GetElementLO(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
196 int GetElementLO(
const unsigned short group,
const unsigned short element, std::vector<std::string>& target,
const bool throwException =
true)
const;
201 template <
typename TType>
202 int GetElementDS(
const unsigned short group,
const unsigned short element,
unsigned short count, TType* target,
const bool throwException =
true)
const
204 DcmTagKey tagkey(group, element);
206 if (this->m_Dataset->findAndGetElement(tagkey, el) != EC_Normal)
210 auto* dsItem =
dynamic_cast<DcmDecimalString*
>(el);
211 if (dsItem ==
nullptr)
215 OFVector<Float64> doubleVals;
216 if (dsItem->getFloat64Vector(doubleVals) != EC_Normal)
218 DCMTKExceptionOrErrorReturn(<<
"Cant extract Array from DecimalString " << std::hex << group <<
' ' << std::hex << element << std::dec);
220 if (doubleVals.size() != count)
222 DCMTKExceptionOrErrorReturn(<<
"DecimalString " << std::hex << group <<
' ' << std::hex << element <<
" expected " << count <<
"items, but found " << doubleVals.size()
225 for (
unsigned int i = 0; i < count; ++i)
227 target[i] =
static_cast<TType
>(doubleVals[i]);
232 template <
typename TType>
233 int GetElementDSorOB(
const unsigned short group,
const unsigned short element, TType& target,
const bool throwException =
true)
const
240 if (this->
GetElementOB(group, element, val, throwException) != EXIT_SUCCESS)
244 const char* data = val.c_str();
245 const auto* fptr =
reinterpret_cast<const TType*
>(data);
249 case EXS_LittleEndianImplicit:
250 case EXS_LittleEndianExplicit: itk::ByteSwapper<TType>::SwapFromSystemToLittleEndian(&target);
break;
251 case EXS_BigEndianImplicit:
252 case EXS_BigEndianExplicit: itk::ByteSwapper<TType>::SwapFromSystemToBigEndian(&target);
break;
259 int GetElementDS(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
260 int GetElementFD(
const unsigned short group,
const unsigned short element,
double& target,
const bool throwException =
true)
const;
261 int GetElementFD(
const unsigned short group,
const unsigned short element,
int count,
double* target,
const bool throwException =
true)
const;
262 int GetElementFL(
const unsigned short group,
const unsigned short element,
float& target,
const bool throwException =
true)
const;
263 int GetElementFLorOB(
const unsigned short group,
const unsigned short element,
float& target,
const bool throwException =
true)
const;
265 int GetElementUS(
const unsigned short group,
const unsigned short element,
unsigned short& target,
const bool throwException =
true)
const;
266 int GetElementUS(
const unsigned short group,
const unsigned short element,
unsigned short*& target,
const bool throwException =
true)
const;
269 int GetElementCS(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
273 int GetElementPN(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
277 int GetElementIS(
const unsigned short group,
const unsigned short element, itk::int32_t& target,
const bool throwException =
true)
const;
279 int GetElementSL(
const unsigned short group,
const unsigned short element, itk::int32_t& target,
const bool throwException =
true)
const;
281 int GetElementISorOB(
const unsigned short group,
const unsigned short element, itk::int32_t& target,
const bool throwException =
true)
const;
283 int GetElementCSorOB(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
287 int GetElementOB(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
291 int GetElementUI(
const unsigned short group,
unsigned short entry, std::string& target,
const bool throwException =
true)
const;
294 int GetElementAsString(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
296 int GetElementDA(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
298 int GetElementTM(
const unsigned short group,
const unsigned short element, std::string& target,
const bool throwException =
true)
const;
300 int GetDirCosines(vnl_vector<double>& dir1, vnl_vector<double>& dir2, vnl_vector<double>& dir3)
const;
329 std::string m_FileName;
330 DcmFileFormat* m_DFile{
nullptr };
331 DcmDataset* m_Dataset{
nullptr };
332 E_TransferSyntax m_Xfer{ EXS_Unknown };
333 Sint32 m_FrameCount{ 0 };
334 long m_FileNumber{ -1L };
int GetFrameCount() const
static void AddDictEntry(DcmDictEntry *entry)
int GetElementSQ(const unsigned short group, unsigned short entry, DCMTKSequence &sequence, const bool throwException=true) const
int GetDirCosines(vnl_vector< double > &dir1, vnl_vector< double > &dir2, vnl_vector< double > &dir3) const
int GetElementIS(const unsigned short group, const unsigned short element, itk::int32_t &target, const bool throwException=true) const
int GetElementUI(const unsigned short group, unsigned short entry, std::string &target, const bool throwException=true) const
void SetFileName(const std::string &fileName)
int GetElementISorOB(const unsigned short group, const unsigned short element, itk::int32_t &target, const bool throwException=true) const
int GetDimensions(unsigned short &rows, unsigned short &columns) const
int GetElementDA(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
E_TransferSyntax GetTransferSyntax() const
int GetElementLO(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetElementUS(const unsigned short group, const unsigned short element, unsigned short &target, const bool throwException=true) const
int GetElementFD(const unsigned short group, const unsigned short element, double &target, const bool throwException=true) const
int GetElementFD(const unsigned short group, const unsigned short element, int count, double *target, const bool throwException=true) const
int GetElementSL(const unsigned short group, const unsigned short element, itk::int32_t &target, const bool throwException=true) const
int GetElementPN(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
DCMTKFileReader()=default
int GetElementCS(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
static bool CanReadFile(const std::string &filename)
int GetElementLO(const unsigned short group, const unsigned short element, std::vector< std::string > &target, const bool throwException=true) const
int GetOrigin(double *const origin) const
int GetElementFL(const unsigned short group, const unsigned short element, float &target, const bool throwException=true) const
int GetElementTM(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetDirCosArray(double *const dircos) const
int GetElementDSorOB(const unsigned short group, const unsigned short element, TType &target, const bool throwException=true) const
const std::string & GetFileName() const
static bool IsImageFile(const std::string &filename)
bool HasPixelData() const
int GetElementDS(const unsigned short group, const unsigned short element, unsigned short count, TType *target, const bool throwException=true) const
int GetSlopeIntercept(double &slope, double &intercept) const
int GetElementUS(const unsigned short group, const unsigned short element, unsigned short *&target, const bool throwException=true) const
int GetElementCSorOB(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetSpacing(double *const spacing) const
int GetElementFLorOB(const unsigned short group, const unsigned short element, float &target, const bool throwException=true) const
long GetFileNumber() const
void PopulateMetaDataDictionary(MetaDataDictionary &dict) const
int GetElementAsString(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetElementDS(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetElementOB(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
IOComponentEnum GetImageDataType() const
IOPixelEnum GetImagePixelType() const
int GetElementSQ(const unsigned short group, const unsigned short entry, DCMTKSequence &sequence, const bool throwException=true) const
void SetDcmItem(DcmItem *item)
int GetElementDS(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
void SetDcmSequenceOfItems(DcmSequenceOfItems *seq)
int GetElementCSorOB(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetElementFD(const unsigned short group, const unsigned short element, int count, double *target, const bool throwException=true) const
int GetElementCS(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetSequence(unsigned long index, DCMTKSequence &target, const bool throwException=true) const
int GetElementDSorOB(const unsigned short group, const unsigned short element, TType &target, const bool throwException=true) const
int GetElementItem(unsigned short itemIndex, DCMTKItem &target, const bool throwException=true) const
int GetElementTM(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
void print(std::ostream &out) const
int GetStack(const unsigned short group, const unsigned short element, DcmStack &resultStack, const bool throwException=true) const
int GetElementOB(const unsigned short group, const unsigned short element, std::string &target, const bool throwException=true) const
int GetElementDS(const unsigned short group, const unsigned short element, unsigned short count, TType *target, const bool throwException=true) const
int GetElementSQ(const unsigned short group, const unsigned short element, DCMTKSequence &target, const bool throwException=true) const
int GetElementDSorOB(const unsigned short group, const unsigned short element, int count, TType *target, const bool throwException=true) const
int GetElementFD(const unsigned short group, const unsigned short element, double &target, const bool throwException=true) const
#define ITKIODCMTK_EXPORT
#define DCMTKExceptionOrErrorReturn(body)
Simplified inverse ITK transforms.
bool CompareDCMTKFileReaders(DCMTKFileReader *a, DCMTKFileReader *b)