18 #ifndef __itkDCMTKFileReader_h
20 #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(
unsigned short group,
72 bool throwException =
true);
82 void SetDcmSequenceOfItems(DcmSequenceOfItems *seq);
84 int GetSequence(
unsigned long index,
86 int GetStack(
unsigned short group,
87 unsigned short element,
88 DcmStack &resultStack,
bool throwException =
true);
89 int GetElementCS(
unsigned short group,
90 unsigned short element,
92 bool throwException =
true);
94 int GetElementOB(
unsigned short group,
95 unsigned short element,
97 bool throwException =
true);
99 int GetElementCSorOB(
unsigned short group,
100 unsigned short element,
102 bool throwException =
true);
104 template <
typename TType>
106 unsigned short element,
108 bool throwException =
true)
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 unsigned short element,
133 bool throwException =
true)
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(
unsigned short group,
157 unsigned short element,
160 bool throwException =
true);
161 int GetElementFD(
unsigned short group,
162 unsigned short element,
164 bool throwException =
true);
165 int GetElementDS(
unsigned short group,
166 unsigned short element,
168 bool throwException =
true);
169 int GetElementTM(
unsigned short group,
170 unsigned short element,
172 bool throwException =
true);
176 template <
typename TType>
178 unsigned short element,
179 unsigned short count,
181 bool throwException =
true)
183 DcmStack resultStack;
184 if(this->GetStack(group,element,resultStack,throwException) != EXIT_SUCCESS)
188 DcmDecimalString *dsItem =
189 dynamic_cast<DcmDecimalString *
>(resultStack.top());
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(
unsigned short group,
221 unsigned short element,
223 bool throwException =
true);
224 int GetElementItem(
unsigned short itemIndex,
226 bool throwException =
true);
230 this->m_DcmSequenceOfItems->print(out);
250 void SetFileName(
const std::string &fileName);
252 const std::string &GetFileName()
const;
256 int GetElementLO(
unsigned short group,
257 unsigned short element,
259 bool throwException =
true);
260 int GetElementLO(
unsigned short group,
261 unsigned short element,
262 std::vector<std::string> &target,
263 bool throwException =
true);
268 template <
typename TType>
270 unsigned short element,
271 unsigned short count,
273 bool throwException =
true)
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);
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 unsigned short element,
318 bool throwException =
true)
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(
unsigned short group,
353 unsigned short element,
355 bool throwException =
true);
356 int GetElementFD(
unsigned short group,
357 unsigned short element,
359 bool throwException =
true);
360 int GetElementFD(
unsigned short group,
361 unsigned short element,
364 bool throwException =
true);
365 int GetElementFL(
unsigned short group,
366 unsigned short element,
368 bool throwException =
true);
369 int GetElementFLorOB(
unsigned short group,
370 unsigned short element,
372 bool throwException =
true);
375 int GetElementUS(
unsigned short group,
376 unsigned short element,
377 unsigned short &target,
378 bool throwException =
true);
379 int GetElementUS(
unsigned short group,
380 unsigned short element,
381 unsigned short *&target,
382 bool throwException =
true);
385 int GetElementCS(
unsigned short group,
386 unsigned short element,
388 bool throwException =
true);
392 int GetElementPN(
unsigned short group,
393 unsigned short element,
395 bool throwException =
true);
399 int GetElementIS(
unsigned short group,
400 unsigned short element,
402 bool throwException =
true);
404 int GetElementSL(
unsigned short group,
405 unsigned short element,
407 bool throwException =
true);
409 int GetElementISorOB(
unsigned short group,
410 unsigned short element,
412 bool throwException =
true);
414 int GetElementCSorOB(
unsigned short group,
415 unsigned short element,
417 bool throwException =
true);
421 int GetElementOB(
unsigned short group,
422 unsigned short element,
424 bool throwException =
true);
426 int GetElementSQ(
unsigned short group,
427 unsigned short entry,
429 bool throwException =
true);
431 int GetElementUI(
unsigned short group,
432 unsigned short entry,
434 bool throwException =
true);
436 int GetElementDA(
unsigned short group,
437 unsigned short element,
439 bool throwException =
true);
441 int GetElementTM(
unsigned short group,
442 unsigned short element,
444 bool throwException =
true);
446 int GetDirCosines(vnl_vector<double> &dir1,
447 vnl_vector<double> &dir2,
448 vnl_vector<double> &dir3);
450 int GetDirCosArray(
double *dircos);
452 int GetFrameCount()
const;
454 int GetSlopeIntercept(
double &slope,
double &intercept);
456 int GetDimensions(
unsigned short &rows,
unsigned short &columns);
461 int GetSpacing(
double *spacing);
462 int GetOrigin(
double *origin);
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(unsigned short group, unsigned short element, TType &target, bool throwException=true)
int GetElementDSorOB(unsigned short group, unsigned short element, TType &target, bool throwException=true)
bool CompareDCMTKFileReaders(DCMTKFileReader *a, DCMTKFileReader *b)
int GetElementDS(unsigned short group, unsigned short element, unsigned short count, TType *target, bool throwException=true)
int GetElementDSorOB(unsigned short group, unsigned short element, int count, TType *target, bool throwException=true)
void print(std::ostream &out)
DcmSequenceOfItems * m_DcmSequenceOfItems
static void SwapFromSystemToLittleEndian(T *p)
typedef::itksysFundamentalType_Int32 int32_t
int GetElementDS(unsigned short group, unsigned short element, unsigned short count, TType *target, bool throwException=true)
#define DCMTKExceptionOrErrorReturn(body)