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(<<
"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;
163 unsigned short element,
165 bool throwException =
true);
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(<<
"Can't 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);
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);
270 unsigned short element,
272 bool throwException =
true);
274 unsigned short element,
276 bool throwException =
true);
279 unsigned short element,
280 unsigned short &target,
281 bool throwException =
true);
283 unsigned short element,
284 unsigned short *&target,
285 bool throwException =
true);
289 unsigned short element,
291 bool throwException =
true);
296 unsigned short element,
298 bool throwException =
true);
303 unsigned short element,
304 ::itk::int32_t &target,
305 bool throwException =
true);
308 unsigned short element,
309 ::itk::int32_t &target,
310 bool throwException =
true);
314 unsigned short element,
316 bool throwException =
true);
319 unsigned short entry,
321 bool throwException =
true);
324 unsigned short entry,
326 bool throwException =
true);
329 unsigned short element,
331 bool throwException =
true);
334 unsigned short element,
336 bool throwException =
true);
339 vnl_vector<double> &dir2,
340 vnl_vector<double> &dir3);
346 int GetDimensions(
unsigned short &rows,
unsigned short &columns);
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 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)
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)