18 #ifndef itkDCMTKFileReader_h
19 #define itkDCMTKFileReader_h
21 #include "ITKIODCMTKExport.h"
26 #include "vnl/vnl_vector.h"
27 #include "dcmtk/dcmdata/dcdict.h"
28 #include "dcmtk/dcmdata/dcdicent.h"
29 #include "dcmtk/dcmdata/dcxfer.h"
30 #include "dcmtk/dcmdata/dcvrds.h"
31 #include "dcmtk/dcmdata/dcstack.h"
32 #include "dcmtk/dcmdata/dcdatset.h"
33 #include "dcmtk/dcmdata/dcitem.h"
34 #include "dcmtk/dcmdata/dcvrobow.h"
35 #include "dcmtk/dcmdata/dcsequen.h"
39 class DcmSequenceOfItems;
46 #define DCMTKExceptionOrErrorReturn(body) \
50 itkGenericExceptionMacro(body); \
54 return EXIT_FAILURE; \
69 void SetDcmItem(DcmItem *item);
70 int GetElementSQ(
const unsigned short group,
71 const unsigned short entry,
73 const bool throwException =
true)
const;
83 void SetDcmSequenceOfItems(DcmSequenceOfItems *seq);
85 int GetSequence(
unsigned long index,
86 DCMTKSequence &target,
const bool throwException =
true)
const;
87 int GetStack(
const unsigned short group,
88 const unsigned short element,
89 DcmStack &resultStack,
const bool throwException =
true)
const;
90 int GetElementCS(
const unsigned short group,
91 const unsigned short element,
93 const bool throwException =
true)
const;
95 int GetElementOB(
const unsigned short group,
96 const unsigned short element,
98 const bool throwException =
true)
const;
100 int GetElementCSorOB(
const unsigned short group,
101 const unsigned short element,
103 const bool throwException =
true)
const;
105 template <
typename TType>
107 const unsigned short element,
109 const bool throwException =
true)
const
111 if(this->GetElementDS<TType>(group,element,1,&target,
false) == EXIT_SUCCESS)
116 if(this->GetElementOB(group,element,val,throwException) != EXIT_SUCCESS)
119 << group <<
" " << std::hex
120 << element << std::dec);
122 const char *data = val.c_str();
123 const TType *fptr =
reinterpret_cast<const TType *
>(data);
129 template <
typename TType>
131 const unsigned short element,
134 const bool throwException =
true)
const
136 if(this->GetElementDS<TType>(group,element,count,target,
false) == EXIT_SUCCESS)
141 if(this->GetElementOB(group,element,val,throwException) != EXIT_SUCCESS)
144 << group <<
" " << std::hex
145 << element << std::dec);
147 const char *data = val.c_str();
148 const TType *fptr =
reinterpret_cast<const TType *
>(data);
149 for(
int i = 0; i < count; ++i)
157 int GetElementFD(
const unsigned short group,
158 const unsigned short element,
161 const bool throwException =
true)
const;
162 int GetElementFD(
const unsigned short group,
163 const unsigned short element,
165 const bool throwException =
true)
const;
166 int GetElementDS(
const unsigned short group,
167 const unsigned short element,
169 const bool throwException =
true)
const;
170 int GetElementTM(
const unsigned short group,
171 const unsigned short element,
173 const bool throwException =
true)
const;
177 template <
typename TType>
179 const unsigned short element,
180 unsigned short count,
182 const bool throwException =
true)
const
184 DcmStack resultStack;
185 if(this->GetStack(group,element,resultStack,throwException) != EXIT_SUCCESS)
189 DcmDecimalString *dsItem =
190 dynamic_cast<DcmDecimalString *
>(resultStack.top());
191 if(dsItem == ITK_NULLPTR)
194 << std::hex << group <<
" "
195 << element << std::dec);
199 OFVector<Float64> doubleVals;
200 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
203 << group <<
" " << std::hex
204 << element << std::dec);
206 if(doubleVals.size() != count)
209 << group <<
" " << std::hex
210 << element <<
" expected "
211 << count <<
"items, but found "
212 << doubleVals.size() << std::dec);
215 for(
unsigned i = 0; i < count; i++)
217 target[i] =
static_cast<TType
>(doubleVals[i]);
221 int GetElementSQ(
const unsigned short group,
222 const unsigned short element,
224 const bool throwException =
true)
const;
225 int GetElementItem(
unsigned short itemIndex,
227 const bool throwException =
true)
const;
231 this->m_DcmSequenceOfItems->print(out);
243 m_Dataset(ITK_NULLPTR),
250 void SetFileName(
const std::string &fileName);
252 const std::string &GetFileName()
const;
256 int GetElementLO(
const unsigned short group,
257 const unsigned short element,
259 const bool throwException =
true)
const;
260 int GetElementLO(
const unsigned short group,
261 const unsigned short element,
262 std::vector<std::string> &target,
263 const bool throwException =
true)
const;
268 template <
typename TType>
270 const unsigned short element,
271 unsigned short count,
273 const bool throwException =
true)
const
275 DcmTagKey tagkey(group,element);
277 if(this->m_Dataset->findAndGetElement(tagkey,el) != EC_Normal)
280 << group <<
" " << std::hex
281 << element << std::dec);
283 DcmDecimalString *dsItem =
dynamic_cast<DcmDecimalString *
>(el);
284 if(dsItem == ITK_NULLPTR)
287 << group <<
" " << std::hex
288 << element << std::dec);
290 OFVector<Float64> doubleVals;
291 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
294 << group <<
" " << std::hex
295 << element << std::dec);
297 if(doubleVals.size() != count)
300 << group <<
" " << std::hex
301 << element <<
" expected "
302 << count <<
"items, but found "
303 << doubleVals.size() << std::dec);
307 for(
unsigned i = 0; i < count; i++)
309 target[i] =
static_cast<TType
>(doubleVals[i]);
314 template <
typename TType>
316 const unsigned short element,
318 const bool throwException =
true)
const
320 if(this->GetElementDS<TType>(group,element,1,&target,
false) == EXIT_SUCCESS)
325 if(this->GetElementOB(group,element,val) != EXIT_SUCCESS)
328 << group <<
" " << std::hex
329 << element << std::dec);
331 const char *data = val.c_str();
332 const TType *fptr =
reinterpret_cast<const TType *
>(data);
334 switch(this->GetTransferSyntax())
336 case EXS_LittleEndianImplicit:
337 case EXS_LittleEndianExplicit:
340 case EXS_BigEndianImplicit:
341 case EXS_BigEndianExplicit:
352 int GetElementDS(
const unsigned short group,
353 const unsigned short element,
355 const bool throwException =
true)
const;
356 int GetElementFD(
const unsigned short group,
357 const unsigned short element,
359 const bool throwException =
true)
const;
360 int GetElementFD(
const unsigned short group,
361 const unsigned short element,
364 const bool throwException =
true)
const;
365 int GetElementFL(
const unsigned short group,
366 const unsigned short element,
368 const bool throwException =
true)
const;
369 int GetElementFLorOB(
const unsigned short group,
370 const unsigned short element,
372 const bool throwException =
true)
const;
375 int GetElementUS(
const unsigned short group,
376 const unsigned short element,
377 unsigned short &target,
378 const bool throwException =
true)
const;
379 int GetElementUS(
const unsigned short group,
380 const unsigned short element,
381 unsigned short *&target,
382 const bool throwException =
true)
const;
385 int GetElementCS(
const unsigned short group,
386 const unsigned short element,
388 const bool throwException =
true)
const;
392 int GetElementPN(
const unsigned short group,
393 const unsigned short element,
395 const bool throwException =
true)
const;
399 int GetElementIS(
const unsigned short group,
400 const unsigned short element,
402 const bool throwException =
true)
const;
404 int GetElementSL(
const unsigned short group,
405 const unsigned short element,
407 const bool throwException =
true)
const;
409 int GetElementISorOB(
const unsigned short group,
410 const unsigned short element,
412 const bool throwException =
true)
const;
414 int GetElementCSorOB(
const unsigned short group,
415 const unsigned short element,
417 const bool throwException =
true)
const;
421 int GetElementOB(
const unsigned short group,
422 const unsigned short element,
424 const bool throwException =
true)
const;
426 int GetElementSQ(
const unsigned short group,
427 unsigned short entry,
429 const bool throwException =
true)
const;
431 int GetElementUI(
const unsigned short group,
432 unsigned short entry,
434 const bool throwException =
true)
const;
436 int GetElementDA(
const unsigned short group,
437 const unsigned short element,
439 const bool throwException =
true)
const;
441 int GetElementTM(
const unsigned short group,
442 const unsigned short element,
444 const bool throwException =
true)
const;
446 int GetDirCosines(vnl_vector<double> &dir1,
447 vnl_vector<double> &dir2,
448 vnl_vector<double> &dir3)
const;
450 int GetDirCosArray(
double *
const dircos)
const;
452 int GetFrameCount()
const;
454 int GetSlopeIntercept(
double &slope,
double &intercept)
const;
456 int GetDimensions(
unsigned short &rows,
unsigned short &columns)
const;
461 int GetSpacing(
double *
const spacing)
const;
462 int GetOrigin(
double *
const origin)
const;
464 bool HasPixelData()
const;
466 E_TransferSyntax GetTransferSyntax()
const;
468 long GetFileNumber()
const;
470 AddDictEntry(DcmDictEntry *entry);
472 static bool CanReadFile(
const std::string &filename);
473 static bool IsImageFile(
const std::string &filename);
488 #endif // itkDCMTKFileReader_h
static void SwapFromSystemToBigEndian(T *p)
int GetElementDSorOB(const unsigned short group, const unsigned short element, int count, TType *target, const bool throwException=true) const
int GetElementDSorOB(const unsigned short group, const unsigned short element, TType &target, const bool throwException=true) const
bool CompareDCMTKFileReaders(DCMTKFileReader *a, DCMTKFileReader *b)
int GetElementDS(const unsigned short group, const unsigned short element, unsigned short count, TType *target, const bool throwException=true) const
DcmSequenceOfItems * m_DcmSequenceOfItems
static void SwapFromSystemToLittleEndian(T *p)
int GetElementDSorOB(const unsigned short group, const unsigned short element, TType &target, const bool throwException=true) const
void print(std::ostream &out) const
KWIML_INT_int32_t int32_t
#define DCMTKExceptionOrErrorReturn(body)
int GetElementDS(const unsigned short group, const unsigned short element, unsigned short count, TType *target, const bool throwException=true) const