18 #ifndef itkDCMTKFileReader_h
19 #define itkDCMTKFileReader_h
21 #include "ITKIODCMTKExport.h"
26 #include "vnl/vnl_vector.h"
39 class DcmSequenceOfItems;
46 #define DCMTKExceptionOrErrorReturn(body) \
50 itkGenericExceptionMacro(body); \
54 return EXIT_FAILURE; \
68 void SetDcmItem(DcmItem *item);
69 int GetElementSQ(
const unsigned short group,
70 const unsigned short entry,
72 const bool throwException =
true)
const;
82 void SetDcmSequenceOfItems(DcmSequenceOfItems *seq);
84 int GetSequence(
unsigned long index,
85 DCMTKSequence &target,
const bool throwException =
true)
const;
86 int GetStack(
const unsigned short group,
87 const unsigned short element,
88 DcmStack &resultStack,
const bool throwException =
true)
const;
89 int GetElementCS(
const unsigned short group,
90 const unsigned short element,
92 const bool throwException =
true)
const;
94 int GetElementOB(
const unsigned short group,
95 const unsigned short element,
97 const bool throwException =
true)
const;
99 int GetElementCSorOB(
const unsigned short group,
100 const unsigned short element,
102 const bool throwException =
true)
const;
104 template <
typename TType>
106 const unsigned short element,
108 const bool throwException =
true)
const
110 if(this->GetElementDS<TType>(group,element,1,&target,
false) == EXIT_SUCCESS)
115 if(this->GetElementOB(group,element,val,throwException) != EXIT_SUCCESS)
118 << group <<
" " << std::hex
119 << element << std::dec);
121 const char *data = val.c_str();
122 const TType *fptr =
reinterpret_cast<const TType *
>(data);
128 template <
typename TType>
130 const unsigned short element,
133 const bool throwException =
true)
const
135 if(this->GetElementDS<TType>(group,element,count,target,
false) == EXIT_SUCCESS)
140 if(this->GetElementOB(group,element,val,throwException) != EXIT_SUCCESS)
143 << group <<
" " << std::hex
144 << element << std::dec);
146 const char *data = val.c_str();
147 const TType *fptr =
reinterpret_cast<const TType *
>(data);
148 for(
int i = 0; i < count; ++i)
156 int GetElementFD(
const unsigned short group,
157 const unsigned short element,
160 const bool throwException =
true)
const;
161 int GetElementFD(
const unsigned short group,
162 const unsigned short element,
164 const bool throwException =
true)
const;
165 int GetElementDS(
const unsigned short group,
166 const unsigned short element,
168 const bool throwException =
true)
const;
169 int GetElementTM(
const unsigned short group,
170 const unsigned short element,
172 const bool throwException =
true)
const;
176 template <
typename TType>
178 const unsigned short element,
179 unsigned short count,
181 const bool throwException =
true)
const
183 DcmStack resultStack;
184 if(this->GetStack(group,element,resultStack,throwException) != EXIT_SUCCESS)
188 DcmDecimalString *dsItem =
189 dynamic_cast<DcmDecimalString *
>(resultStack.top());
190 if(dsItem == ITK_NULLPTR)
193 << std::hex << group <<
" "
194 << element << std::dec);
198 OFVector<Float64> doubleVals;
199 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
202 << group <<
" " << std::hex
203 << element << std::dec);
205 if(doubleVals.size() != count)
208 << group <<
" " << std::hex
209 << element <<
" expected "
210 << count <<
"items, but found "
211 << doubleVals.size() << std::dec);
214 for(
unsigned i = 0; i < count; i++)
216 target[i] =
static_cast<TType
>(doubleVals[i]);
220 int GetElementSQ(
const unsigned short group,
221 const unsigned short element,
223 const bool throwException =
true)
const;
224 int GetElementItem(
unsigned short itemIndex,
226 const bool throwException =
true)
const;
230 this->m_DcmSequenceOfItems->print(out);
242 m_Dataset(ITK_NULLPTR),
249 void SetFileName(
const std::string &fileName);
251 const std::string &GetFileName()
const;
255 int GetElementLO(
const unsigned short group,
256 const unsigned short element,
258 const bool throwException =
true)
const;
259 int GetElementLO(
const unsigned short group,
260 const unsigned short element,
261 std::vector<std::string> &target,
262 const bool throwException =
true)
const;
267 template <
typename TType>
269 const unsigned short element,
270 unsigned short count,
272 const bool throwException =
true)
const
274 DcmTagKey tagkey(group,element);
276 if(this->m_Dataset->findAndGetElement(tagkey,el) != EC_Normal)
279 << group <<
" " << std::hex
280 << element << std::dec);
282 DcmDecimalString *dsItem =
dynamic_cast<DcmDecimalString *
>(el);
283 if(dsItem == ITK_NULLPTR)
286 << group <<
" " << std::hex
287 << element << std::dec);
289 OFVector<Float64> doubleVals;
290 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
293 << group <<
" " << std::hex
294 << element << std::dec);
296 if(doubleVals.size() != count)
299 << group <<
" " << std::hex
300 << element <<
" expected "
301 << count <<
"items, but found "
302 << doubleVals.size() << std::dec);
306 for(
unsigned i = 0; i < count; i++)
308 target[i] =
static_cast<TType
>(doubleVals[i]);
313 template <
typename TType>
315 const unsigned short element,
317 const bool throwException =
true)
const
319 if(this->GetElementDS<TType>(group,element,1,&target,
false) == EXIT_SUCCESS)
324 if(this->GetElementOB(group,element,val) != EXIT_SUCCESS)
327 << group <<
" " << std::hex
328 << element << std::dec);
330 const char *data = val.c_str();
331 const TType *fptr =
reinterpret_cast<const TType *
>(data);
333 switch(this->GetTransferSyntax())
335 case EXS_LittleEndianImplicit:
336 case EXS_LittleEndianExplicit:
339 case EXS_BigEndianImplicit:
340 case EXS_BigEndianExplicit:
351 int GetElementDS(
const unsigned short group,
352 const unsigned short element,
354 const bool throwException =
true)
const;
355 int GetElementFD(
const unsigned short group,
356 const unsigned short element,
358 const bool throwException =
true)
const;
359 int GetElementFD(
const unsigned short group,
360 const unsigned short element,
363 const bool throwException =
true)
const;
364 int GetElementFL(
const unsigned short group,
365 const unsigned short element,
367 const bool throwException =
true)
const;
368 int GetElementFLorOB(
const unsigned short group,
369 const unsigned short element,
371 const bool throwException =
true)
const;
374 int GetElementUS(
const unsigned short group,
375 const unsigned short element,
376 unsigned short &target,
377 const bool throwException =
true)
const;
378 int GetElementUS(
const unsigned short group,
379 const unsigned short element,
380 unsigned short *&target,
381 const bool throwException =
true)
const;
384 int GetElementCS(
const unsigned short group,
385 const unsigned short element,
387 const bool throwException =
true)
const;
391 int GetElementPN(
const unsigned short group,
392 const unsigned short element,
394 const bool throwException =
true)
const;
398 int GetElementIS(
const unsigned short group,
399 const unsigned short element,
401 const bool throwException =
true)
const;
403 int GetElementSL(
const unsigned short group,
404 const unsigned short element,
406 const bool throwException =
true)
const;
408 int GetElementISorOB(
const unsigned short group,
409 const unsigned short element,
411 const bool throwException =
true)
const;
413 int GetElementCSorOB(
const unsigned short group,
414 const unsigned short element,
416 const bool throwException =
true)
const;
420 int GetElementOB(
const unsigned short group,
421 const unsigned short element,
423 const bool throwException =
true)
const;
425 int GetElementSQ(
const unsigned short group,
426 unsigned short entry,
428 const bool throwException =
true)
const;
430 int GetElementUI(
const unsigned short group,
431 unsigned short entry,
433 const bool throwException =
true)
const;
435 int GetElementDA(
const unsigned short group,
436 const unsigned short element,
438 const bool throwException =
true)
const;
440 int GetElementTM(
const unsigned short group,
441 const unsigned short element,
443 const bool throwException =
true)
const;
445 int GetDirCosines(vnl_vector<double> &dir1,
446 vnl_vector<double> &dir2,
447 vnl_vector<double> &dir3)
const;
449 int GetDirCosArray(
double *
const dircos)
const;
451 int GetFrameCount()
const;
453 int GetSlopeIntercept(
double &slope,
double &intercept)
const;
455 int GetDimensions(
unsigned short &rows,
unsigned short &columns)
const;
460 int GetSpacing(
double *
const spacing)
const;
461 int GetOrigin(
double *
const origin)
const;
463 bool HasPixelData()
const;
465 E_TransferSyntax GetTransferSyntax()
const;
467 long GetFileNumber()
const;
469 AddDictEntry(DcmDictEntry *entry);
471 static bool CanReadFile(
const std::string &filename);
472 static bool IsImageFile(
const std::string &filename);
487 #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