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());
108 << std::hex << group <<
" " 109 << element << std::dec);
112 OFVector<Float64> doubleVals;
113 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
115 DCMTKException(<<
"Cant 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;
156 void SetFileName(
const std::string &fileName);
158 const std::string &GetFileName()
const;
162 int GetElementLO(
unsigned short group,
163 unsigned short element,
165 bool throwException =
true);
166 int GetElementLO(
unsigned short group,
167 unsigned short element,
168 std::vector<std::string> &target,
169 bool throwException =
true);
174 template <
typename TType>
176 unsigned short element,
177 unsigned short count,
179 bool throwException =
true)
181 DcmTagKey tagkey(group,element);
183 if(this->m_Dataset->findAndGetElement(tagkey,el) != EC_Normal)
186 << group <<
" " << std::hex
187 << element << std::dec);
189 DcmDecimalString *dsItem =
dynamic_cast<DcmDecimalString *
>(el);
193 << group <<
" " << std::hex
194 << element << std::dec);
196 OFVector<Float64> doubleVals;
197 if(dsItem->getFloat64Vector(doubleVals) != EC_Normal)
199 DCMTKException(<<
"Cant extract Array from DecimalString " << std::hex
200 << group <<
" " << std::hex
201 << element << std::dec);
203 if(doubleVals.size() != count)
206 << group <<
" " << std::hex
207 << element <<
" expected " 208 << count <<
"items, but found " 209 << doubleVals.size() << std::dec);
212 for(
unsigned i = 0; i < count; i++)
214 target[i] =
static_cast<TType
>(doubleVals[i]);
219 template <
typename TType>
221 unsigned short element,
223 bool throwException =
true)
225 if(this->GetElementDS<TType>(group,element,1,&target,
false) == EXIT_SUCCESS)
230 if(this->GetElementOB(group,element,val) != EXIT_SUCCESS)
233 << group <<
" " << std::hex
234 << element << std::dec);
236 const char *data = val.c_str();
237 const TType *fptr =
reinterpret_cast<const TType *
>(data);
239 switch(this->GetTransferSyntax())
241 case EXS_LittleEndianImplicit:
242 case EXS_LittleEndianExplicit:
243 itk::ByteSwapper<TType>::SwapFromSystemToLittleEndian(&target);
245 case EXS_BigEndianImplicit:
246 case EXS_BigEndianExplicit:
247 itk::ByteSwapper<TType>::SwapFromSystemToBigEndian(&target);
258 unsigned short element,
260 bool throwException =
true);
262 unsigned short element,
264 bool throwException =
true);
266 unsigned short element,
268 bool throwException =
true);
269 int GetElementFL(
unsigned short group,
270 unsigned short element,
272 bool throwException =
true);
273 int GetElementFLorOB(
unsigned short group,
274 unsigned short element,
276 bool throwException =
true);
278 int GetElementUS(
unsigned short group,
279 unsigned short element,
280 unsigned short &target,
281 bool throwException =
true);
282 int GetElementUS(
unsigned short group,
283 unsigned short element,
284 unsigned short *&target,
285 bool throwException =
true);
289 unsigned short element,
291 bool throwException =
true);
295 int GetElementPN(
unsigned short group,
296 unsigned short element,
298 bool throwException =
true);
302 int GetElementIS(
unsigned short group,
303 unsigned short element,
304 ::itk::int32_t &target,
305 bool throwException =
true);
307 int GetElementISorOB(
unsigned short group,
308 unsigned short element,
309 ::itk::int32_t &target,
310 bool throwException =
true);
313 int GetElementOB(
unsigned short group,
314 unsigned short element,
316 bool throwException =
true);
319 unsigned short entry,
321 bool throwException =
true);
323 int GetElementUI(
unsigned short group,
324 unsigned short entry,
326 bool throwException =
true);
328 int GetElementDA(
unsigned short group,
329 unsigned short element,
331 bool throwException =
true);
334 unsigned short element,
336 bool throwException =
true);
338 int GetDirCosines(vnl_vector<double> &dir1,
339 vnl_vector<double> &dir2,
340 vnl_vector<double> &dir3);
342 int GetFrameCount()
const;
344 int GetSlopeIntercept(
double &slope,
double &intercept);
346 int GetDimensions(
unsigned short &rows,
unsigned short &columns);
348 ImageIOBase::IOComponentType GetImageDataType();
349 ImageIOBase::IOPixelType GetImagePixelType();
351 int GetSpacing(
double *spacing);
352 int GetOrigin(
double *origin);
354 E_TransferSyntax GetTransferSyntax()
const;
356 long GetFileNumber()
const;
359 AddDictEntry(DcmDictEntry *entry);
362 static unsigned ascii2hex(
char c);
364 static std::string ConvertFromOB(OFString &toConvert);
366 std::string m_FileName;
367 DcmFileFormat* m_DFile;
368 DcmDataset * m_Dataset;
369 E_TransferSyntax m_Xfer;
377 #endif // itkDCMTKFileReader_h int GetElementDSorOB(unsigned short group, unsigned short element, TType &target, bool throwException=true)
Simplified inverse ITK transforms.
int GetElementDS(unsigned short group, unsigned short element, unsigned short count, TType *target, bool throwException)
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 GetSequence(unsigned long index, DCMTKSequence &target, bool throwException=true)
int GetElementTM(unsigned short group, unsigned short element, std::string &target, bool throwException=true)
int GetElementSQ(unsigned short group, unsigned short element, DCMTKSequence &target, bool throwException=true)
void SetDcmSequenceOfItems(DcmSequenceOfItems *seq)
int GetStack(unsigned short group, unsigned short element, DcmStack *resultStack, bool throwException=true)
int GetElementDS(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)
int GetElementFD(unsigned short group, unsigned short element, double *&target, bool throwException=true)