18 #ifndef itkDCMTKFileReader_h 19 #define itkDCMTKFileReader_h 29 #include "itkByteSwapper.h" 30 #include "itkIntTypes.h" 31 #include "vnl/vnl_vector.h" 32 #include "dcmtk/dcmdata/dcxfer.h" 33 #include "dcmtk/dcmdata/dcvrds.h" 34 #include "dcmtk/dcmdata/dcstack.h" 35 #include "dcmtk/dcmdata/dcdatset.h" 37 #include "itkImageIOBase.h" 39 class DcmSequenceOfItems;
46 #define DCMTKException(body) \ 50 itkGenericExceptionMacro(body); \ 54 return EXIT_FAILURE; \ 69 unsigned short element,
70 DcmStack *resultStack,
bool throwException =
true);
72 unsigned short element,
74 bool throwException =
true);
76 unsigned short element,
78 bool throwException =
true);
80 unsigned short element,
82 bool throwException =
true);
84 unsigned short element,
86 bool throwException =
true);
88 unsigned short element,
90 bool throwException =
true);
94 template <
typename TType>
96 unsigned short element,
101 DcmStack resultStack;
102 this->
GetStack(group,element,&resultStack);
103 DcmDecimalString *dsItem =
104 dynamic_cast<DcmDecimalString *
>(resultStack.top());
105 if(dsItem ==
nullptr)
108 << std::hex << group <<
" " 109 << element << std::dec);
112 OFVector<Float64> doubleVals;
113 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
115 DCMTKException(<<
"Can't extract Array from DecimalString " << std::hex
116 << group <<
" " << std::hex
117 << element << std::dec);
119 if(doubleVals.size() != count)
122 << group <<
" " << std::hex
123 << element <<
" expected " 124 << count <<
"items, but found " 125 << doubleVals.size() << std::dec);
128 for(
unsigned i = 0; i < count; i++)
130 target[i] =
static_cast<TType
>(doubleVals[i]);
135 unsigned short element,
137 bool throwException =
true);
139 DcmSequenceOfItems *m_DcmSequenceOfItems{
nullptr};
157 unsigned short element,
159 bool throwException =
true);
161 unsigned short element,
162 std::vector<std::string> &target,
163 bool throwException =
true);
168 template <
typename TType>
170 unsigned short element,
171 unsigned short count,
173 bool throwException =
true)
175 DcmTagKey tagkey(group,element);
177 if(this->m_Dataset->findAndGetElement(tagkey,el) != EC_Normal)
180 << group <<
" " << std::hex
181 << element << std::dec);
183 DcmDecimalString *dsItem =
dynamic_cast<DcmDecimalString *
>(el);
184 if(dsItem ==
nullptr)
187 << group <<
" " << std::hex
188 << element << std::dec);
190 OFVector<Float64> doubleVals;
191 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
193 DCMTKException(<<
"Can't extract Array from DecimalString " << std::hex
194 << group <<
" " << std::hex
195 << element << std::dec);
197 if(doubleVals.size() != count)
200 << group <<
" " << std::hex
201 << element <<
" expected " 202 << count <<
"items, but found " 203 << doubleVals.size() << std::dec);
206 for(
unsigned i = 0; i < count; i++)
208 target[i] =
static_cast<TType
>(doubleVals[i]);
213 template <
typename TType>
215 unsigned short element,
217 bool throwException =
true)
219 if(this->GetElementDS<TType>(group,element,1,&target,
false) == EXIT_SUCCESS)
224 if(this->
GetElementOB(group,element,val) != EXIT_SUCCESS)
227 << group <<
" " << std::hex
228 << element << std::dec);
230 const char *data = val.c_str();
231 const TType *fptr =
reinterpret_cast<const TType *
>(data);
235 case EXS_LittleEndianImplicit:
236 case EXS_LittleEndianExplicit:
237 itk::ByteSwapper<TType>::SwapFromSystemToLittleEndian(&target);
239 case EXS_BigEndianImplicit:
240 case EXS_BigEndianExplicit:
241 itk::ByteSwapper<TType>::SwapFromSystemToBigEndian(&target);
252 unsigned short element,
254 bool throwException =
true);
256 unsigned short element,
258 bool throwException =
true);
260 unsigned short element,
262 bool throwException =
true);
264 unsigned short element,
266 bool throwException =
true);
268 unsigned short element,
270 bool throwException =
true);
273 unsigned short element,
274 unsigned short &target,
275 bool throwException =
true);
277 unsigned short element,
278 unsigned short *&target,
279 bool throwException =
true);
283 unsigned short element,
285 bool throwException =
true);
290 unsigned short element,
292 bool throwException =
true);
297 unsigned short element,
298 ::itk::int32_t &target,
299 bool throwException =
true);
302 unsigned short element,
303 ::itk::int32_t &target,
304 bool throwException =
true);
308 unsigned short element,
310 bool throwException =
true);
313 unsigned short entry,
315 bool throwException =
true);
318 unsigned short entry,
320 bool throwException =
true);
323 unsigned short element,
325 bool throwException =
true);
328 unsigned short element,
330 bool throwException =
true);
333 vnl_vector<double> &dir2,
334 vnl_vector<double> &dir3);
340 int GetDimensions(
unsigned short &rows,
unsigned short &columns);
356 static unsigned ascii2hex(
char c);
358 static std::string ConvertFromOB(OFString &toConvert);
360 std::string m_FileName;
361 DcmFileFormat* m_DFile{
nullptr};
362 DcmDataset * m_Dataset{
nullptr};
363 E_TransferSyntax m_Xfer{EXS_Unknown};
364 Sint32 m_FrameCount{0};
365 long m_FileNumber{-1L};
371 #endif // itkDCMTKFileReader_h int GetDimensions(unsigned short &rows, unsigned short &columns)
int GetElementSQ(unsigned short group, unsigned short entry, DCMTKSequence &sequence, bool throwException=true)
int GetElementDSorOB(unsigned short group, unsigned short element, TType &target, bool throwException=true)
int GetSlopeIntercept(double &slope, double &intercept)
int GetElementOB(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetElementCS(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
ImageIOBase::IOComponentType GetImageDataType()
int GetElementIS(unsigned short group, unsigned short element, ::itk::int32_t &target, bool throwException=true)
int GetElementDA(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
Simplified inverse ITK transforms.
const std::string & GetFileName() const
long GetFileNumber() const
int GetElementDS(unsigned short group, unsigned short element, unsigned short count, TType *target, bool throwException)
static void AddDictEntry(DcmDictEntry *entry)
bool CompareDCMTKFileReaders(DCMTKFileReader *a, DCMTKFileReader *b)
#define DCMTKException(body)
int GetElementDS(unsigned short group, unsigned short element, unsigned short count, TType *target, bool throwException=true)
int GetElementFLorOB(unsigned short group, unsigned short element, float &target, bool throwException=true)
int GetSequence(unsigned long index, DCMTKSequence &target, bool throwException=true)
int GetElementFL(unsigned short group, unsigned short element, float &target, bool throwException=true)
int GetElementTM(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetElementUI(unsigned short group, unsigned short entry, std::string &target, bool throwException=true)
int GetElementSQ(unsigned short group, unsigned short element, DCMTKSequence &target, bool throwException=true)
void SetDcmSequenceOfItems(DcmSequenceOfItems *seq)
int GetElementTM(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetSpacing(double *spacing)
int GetDirCosines(vnl_vector< double > &dir1, vnl_vector< double > &dir2, vnl_vector< double > &dir3)
int GetFrameCount() const
int GetElementISorOB(unsigned short group, unsigned short element, ::itk::int32_t &target, bool throwException=true)
ImageIOBase::IOPixelType GetImagePixelType()
int GetElementPN(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetStack(unsigned short group, unsigned short element, DcmStack *resultStack, bool throwException=true)
int GetElementLO(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetElementFD(unsigned short group, unsigned short element, double &target, bool throwException=true)
int GetElementUS(unsigned short group, unsigned short element, unsigned short &target, bool throwException=true)
void SetFileName(const std::string &fileName)
DCMTKFileReader()=default
int GetElementDS(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
E_TransferSyntax GetTransferSyntax() const
int GetOrigin(double *origin)
int GetElementCS(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetElementFD(unsigned short group, unsigned short element, double *&target, bool throwException=true)