22 #include <sys/types.h> 43 #include "gdcmReader.h" 44 #include "gdcmImageReader.h" 45 #include "gdcmMediaStorage.h" 47 #include "gdcmDataSet.h" 49 #include "gdcmGlobal.h" 50 #include "gdcmModules.h" 52 #include "gdcmOrientation.h" 53 #include "gdcmVersion.h" 55 #include "gdcmSystem.h" 56 #include "gdcmDirectory.h" 57 #include "gdcmSorter.h" 58 #include "gdcmScanner.h" 59 #include "gdcmDataSet.h" 60 #include "gdcmAttribute.h" 63 #include "importDicom.h" 68 bool Import::LPS_ReorientImageVolume(ImgFormat *volData)
70 unsigned int ix, iy, iz, idx, idy, idz;
71 unsigned int dimx, dimy, dimz;
76 unsigned char *tmp =
new unsigned char[2*volData->dims[0]*volData->dims[1]];
78 std::cout <<
"Reorient the samples in LPS-reference ..." << std::endl;
85 if (fabs(volData->dircos[0][0]) > fabs(volData->dircos[0][1]) &&
86 fabs(volData->dircos[0][0]) > fabs(volData->dircos[0][2])) {
87 if (volData->dircos[0][0] < 0) {
89 volData->dircos[0][0] *= (-1);
92 }
else if (fabs(volData->dircos[0][1]) > fabs(volData->dircos[0][0])
93 && fabs(volData->dircos[0][1]) > fabs(volData->dircos[0][2])) {
94 if (volData->dircos[0][1] < 0) {
96 volData->dircos[0][1] *= (-1);
100 if (volData->dircos[0][2] < 0) {
102 volData->dircos[0][2] *= (-1);
107 switch (volData->nbitsalloc) {
109 for (idz = 0; idz < volData->dims[2]; idz++) {
110 for (idy = 0; idy < volData->dims[1]; idy++) {
111 for (ix=0,idx = volData->dims[0]-1; ix < idx; idx--,ix++) {
113 tmp[0]=volData->buffer[
114 idz * volData->dims[0] * volData->dims[1] +
115 idy * volData->dims[0] + idx];
116 volData->buffer[idz * volData->dims[0] * volData->dims[1] +
117 idy * volData->dims[0] + idx] =
118 volData->buffer[idz * volData->dims[0] * volData->dims[1] +
119 idy * volData->dims[0] + ix];
120 volData->buffer[idz * volData->dims[0] * volData->dims[1] +
121 idy * volData->dims[0] + ix] = tmp[0];
127 for (idz = 0; idz < volData->dims[2]; idz++) {
128 for (idy = 0; idy < volData->dims[1]; idy++) {
129 for (ix=0,idx = volData->dims[0]-1; ix < idx; idx=idx--,ix=ix++) {
132 &(volData->buffer[2*(idz * volData->dims[0] *
133 volData->dims[1] + idy * volData->dims[0] + idx)]),
134 sizeof(
unsigned char)*2);
135 memcpy (&(volData->buffer[
136 2*(idz * volData->dims[0] * volData->dims[1] +
137 idy * volData->dims[0] + idx)]),
139 2*(idz * volData->dims[0] * volData->dims[1] +
140 idy * volData->dims[0] + ix)]),
141 sizeof(
unsigned char)*2);
142 memcpy(&(volData->buffer[
143 2*(idz * volData->dims[0] * volData->dims[1] +
144 idy * volData->dims[1] + ix)]), tmp,
145 sizeof(
unsigned char)*2);
155 if (fabs(volData->dircos[1][0]) > fabs(volData->dircos[1][1])
157 fabs(volData->dircos[1][0]) > fabs(volData->dircos[1][2])) {
158 if (volData->dircos[1][0] < 0) {
160 volData->dircos[1][0] *= (-1);
163 }
else if (fabs(volData->dircos[1][1]) > fabs(volData->dircos[1][0])
165 fabs(volData->dircos[1][1]) > fabs(volData->dircos[1][2])) {
166 if (volData->dircos[1][1] < 0) {
168 volData->dircos[1][1] *= (-1);
172 if (volData->dircos[1][2] < 0) {
174 volData->dircos[1][2] *= (-1);
179 switch (volData->nbitsalloc) {
181 for (idz = 0; idz < volData->dims[2]; idz++) {
182 for (iy=0,idy = volData->dims[1]-1; iy < idy; idy--,iy++) {
183 memcpy (tmp, &(volData->buffer[idz * volData->dims[0] *
184 volData->dims[1] + idy * volData->dims[0]]),
185 sizeof(
unsigned char)*volData->dims[0]);
186 memcpy(&(volData->buffer[idz * volData->dims[0] *
187 volData->dims[1] + idy * volData->dims[0]]),
188 &(volData->buffer[idz * volData->dims[0] *
189 volData->dims[1] + iy * volData->dims[0]]),
190 sizeof(
unsigned char)*volData->dims[0]);
191 memcpy(&(volData->buffer[idz * volData->dims[0] *
192 volData->dims[1] + iy * volData->dims[0]]), tmp,
193 sizeof(
unsigned char)*volData->dims[0]);
198 for (idz = 0; idz < volData->dims[2]; idz++) {
199 for (iy=0,idy = volData->dims[1]-1; iy < idy; idy--,iy++) {
200 memcpy (tmp, &(volData->buffer[2*(idz*volData->dims[0] *
201 volData->dims[1] + idy*volData->dims[0])]),
202 sizeof(
unsigned char)*2*volData->dims[0]);
203 memcpy(&(volData->buffer[2*(idz * volData->dims[0] *
204 volData->dims[1] + idy * volData->dims[0])]),
205 &(volData->buffer[2*(idz * volData->dims[0] *
206 volData->dims[1] + iy * volData->dims[0])]),
207 sizeof(
unsigned char)*2*volData->dims[0]);
208 memcpy(&(volData->buffer[2*(idz * volData->dims[0] *
209 volData->dims[1] + iy * volData->dims[0])]), tmp,
210 sizeof(
unsigned char)*2*volData->dims[0]);
220 if (fabs(volData->dircos[2][0]) > fabs(volData->dircos[2][1])
222 fabs(volData->dircos[2][0]) > fabs(volData->dircos[2][2])) {
223 if (volData->dircos[2][0] < 0) {
225 volData->dircos[2][0] *= (-1);
228 }
else if (fabs(volData->dircos[2][1]) > fabs(volData->dircos[2][0])
230 fabs(volData->dircos[2][1]) > fabs(volData->dircos[2][2])) {
231 if (volData->dircos[2][1] < 0) {
233 volData->dircos[2][1] *= (-1);
237 if (volData->dircos[2][2] < 0) {
239 volData->dircos[2][2] *= (-1);
244 switch (volData->nbitsalloc) {
246 for (iz=0,idz = volData->dims[2]-1; iz < idz; idz-=1,iz+=1) {
247 memcpy (tmp, &(volData->buffer[idz * volData->dims[0] * volData->dims[1]]),
248 sizeof(
unsigned char)*(volData->dims[0] * volData->dims[1]));
249 memcpy (&(volData->buffer[idz * volData->dims[0] * volData->dims[1]]),
250 &(volData->buffer[iz * volData->dims[0] * volData->dims[1]]),
251 sizeof(
unsigned char)*(volData->dims[0] * volData->dims[1]));
252 memcpy(&(volData->buffer[iz * volData->dims[0] * volData->dims[1]]), tmp,
253 sizeof(
unsigned char)*(volData->dims[0] * volData->dims[1]));
257 for (iz=0,idz = volData->dims[2]-1; iz < idz; idz-=1,iz+=1) {
258 memcpy (tmp, &(volData->buffer[idz * 2 * volData->dims[0] * volData->dims[1]]),
259 sizeof(
unsigned char)*2*(volData->dims[0] * volData->dims[1]));
260 memcpy (&(volData->buffer[idz * 2 * volData->dims[0] * volData->dims[1]]),
261 &(volData->buffer[iz * 2* volData->dims[0] * volData->dims[1]]),
262 sizeof(
unsigned char)*2*(volData->dims[0] * volData->dims[1]));
263 memcpy (&(volData->buffer[iz * 2 * volData->dims[0] * volData->dims[1]]), tmp,
264 sizeof(
unsigned char)*2*(volData->dims[0] * volData->dims[1]));
272 std::cout <<
"code = " << (int)code << std::endl;
274 if (code == 6)
return true;
280 switch (volData->nbitsalloc) {
282 tmp =
new unsigned char[volData->dims[0]*volData->dims[1]*volData->dims[2]];
283 memcpy (tmp,volData->buffer,
284 sizeof(
unsigned char)*(volData->dims[0] * volData->dims[1] * volData->dims[2]));
285 memset(volData->buffer, 0x00, volData->dims[0]*volData->dims[1]*volData->dims[2]);
288 std::cout <<
"PSL" << std::endl;
289 for (ix = 0, idy = 0; idy < volData->dims[1]; idy++) {
290 for (idx = 0; idx < volData->dims[0]; idx++) {
291 for (idz=0; idz < volData->dims[2]; idz++) {
292 volData->buffer[ix++] =
293 tmp[idz * volData->dims[0] * volData->dims[1] +
294 idy * volData->dims[0] + idx];
298 sx = volData->space[2]; sy = volData->space[0]; sz = volData->space[1];
299 dimx = volData->dims[2]; dimy = volData->dims[0]; dimz = volData->dims[1];
300 dir[0][0] = volData->dircos[2][0];
301 dir[0][1] = volData->dircos[2][1];
302 dir[0][2] = volData->dircos[2][2];
303 dir[1][0] = volData->dircos[0][0];
304 dir[1][1] = volData->dircos[0][1];
305 dir[1][2] = volData->dircos[0][2];
306 dir[2][0] = volData->dircos[1][0];
307 dir[2][1] = volData->dircos[1][1];
308 dir[2][2] = volData->dircos[1][2];
309 }
else if (code == 33) {
310 std::cout <<
"SLP" << std::endl;
311 for (ix = 0, idx = 0; idx < volData->dims[0]; idx++) {
312 for (idz = 0; idz < volData->dims[2]; idz++) {
313 for (idy=0; idy < volData->dims[1]; idy++) {
314 volData->buffer[ix++] =
315 tmp[idz * volData->dims[0] * volData->dims[1] +
316 idy * volData->dims[0] + idx];
320 sx = volData->space[1]; sy = volData->space[2]; sz = volData->space[0];
321 dimx = volData->dims[1]; dimy = volData->dims[2]; dimz = volData->dims[0];
322 dir[0][0] = volData->dircos[1][0];
323 dir[0][1] = volData->dircos[1][1];
324 dir[0][2] = volData->dircos[1][2];
325 dir[1][0] = volData->dircos[2][0];
326 dir[1][1] = volData->dircos[2][1];
327 dir[1][2] = volData->dircos[2][2];
328 dir[2][0] = volData->dircos[0][0];
329 dir[2][1] = volData->dircos[0][1];
330 dir[2][2] = volData->dircos[0][2];
334 tmp =
new unsigned char[2*volData->dims[0]*volData->dims[1]*volData->dims[2]];
335 memcpy (tmp,volData->buffer,
336 sizeof(
unsigned char)*(2*volData->dims[0]*volData->dims[1]*volData->dims[2]));
337 memset(volData->buffer, 0x00, 2*volData->dims[0]*volData->dims[1]*volData->dims[2]);
339 std::cout <<
"PSL" << std::endl;
340 for (ix=0, idy = 0; idy < volData->dims[1]; idy++) {
341 for (idx = 0; idx < volData->dims[0]; idx++) {
342 for (idz = 0; idz < volData->dims[2]; idz++) {
343 memcpy(&(volData->buffer[2*ix]),&(tmp[2*(idz*volData->dims[0]*volData->dims[1]+idy*volData->dims[0]+idx)]),
sizeof(
unsigned short));
348 sx = volData->space[2]; sy = volData->space[0]; sz = volData->space[1];
349 dimx = volData->dims[2]; dimy = volData->dims[0]; dimz = volData->dims[1];
350 dir[0][0] = volData->dircos[2][0];
351 dir[0][1] = volData->dircos[2][1];
352 dir[0][2] = volData->dircos[2][2];
353 dir[1][0] = volData->dircos[0][0];
354 dir[1][1] = volData->dircos[0][1];
355 dir[1][2] = volData->dircos[0][2];
356 dir[2][0] = volData->dircos[1][0];
357 dir[2][1] = volData->dircos[1][1];
358 dir[2][2] = volData->dircos[1][2];
359 }
else if (code == 33) {
360 std::cout <<
"SLP" << std::endl;
361 for (ix = 0, idx = 0; idx < volData->dims[0]; idx++) {
362 for (idz = 0; idz < volData->dims[2]; idz++) {
363 for (idy=0; idy < volData->dims[1]; idy++) {
364 memcpy(&(volData->buffer[2*ix]),&(tmp[2*(idz*volData->dims[0]*volData->dims[1]+idy*volData->dims[0]+idx)]),
sizeof(
unsigned short));
369 sx = volData->space[1]; sy = volData->space[2]; sz = volData->space[0];
370 dimx = volData->dims[1]; dimy = volData->dims[2]; dimz = volData->dims[0];
371 dir[0][0] = volData->dircos[1][0];
372 dir[0][1] = volData->dircos[1][1];
373 dir[0][2] = volData->dircos[1][2];
374 dir[1][0] = volData->dircos[2][0];
375 dir[1][1] = volData->dircos[2][1];
376 dir[1][2] = volData->dircos[2][2];
377 dir[2][0] = volData->dircos[0][0];
378 dir[2][1] = volData->dircos[0][1];
379 dir[2][2] = volData->dircos[0][2];
385 volData->space[0]=sx; volData->space[1]=sy; volData->space[2]=sz;
386 volData->dims[0]=dimx; volData->dims[1]=dimy; volData->dims[2]=dimz;
387 volData->dircos[0][0] = dir[0][0]; volData->dircos[0][1] = dir[0][1]; volData->dircos[0][2] = dir[0][2];
388 volData->dircos[1][0] = dir[1][0]; volData->dircos[1][1] = dir[1][1]; volData->dircos[1][2] = dir[1][2];
389 volData->dircos[2][0] = dir[2][0]; volData->dircos[2][1] = dir[2][1]; volData->dircos[2][2] = dir[2][2];
397 bool Import::ReadPixelData(
const gdcm::Image &image,
const gdcm::DataSet &ds,
398 const gdcm::PixelFormat::ScalarType & stype,
399 unsigned short nbitsalloc,
unsigned short nbitsstored,
400 float slope,
float intercept,
401 unsigned int *len,
char **buf,
402 int *umin,
int *umax)
405 gdcm::Tag rawTag(0x7fe0, 0x0010);
406 const gdcm::DataElement& pixel_data = ds.GetDataElement(rawTag);
407 const gdcm::ByteValue *bv = pixel_data.GetByteValue();
408 *len = bv->GetLength();
411 int j, step, nShiftBits;
413 unsigned char mask, v1;
414 unsigned short ivalue;
417 unsigned short *tmpbuf16;
422 tmpbuf8 =
new char[*len];
423 bv->GetBuffer(tmpbuf8, *len);
424 for(
unsigned int di = 0; di < *len; di += 1)
427 value = (int)((reinterpret_cast<unsigned char*>(tmpbuf8))[di]);
429 value = (int)((reinterpret_cast<char*>(tmpbuf8))[di]);
431 if(*umax < value) *umax = value;
432 if(*umin > value) *umin = value;
443 nShiftBits = nbitsalloc - nbitsstored;
444 step = nbitsalloc / (
sizeof(char) * 8);
445 mask = (255 >> nShiftBits);
447 tmpbuf16 =
new unsigned short[length];
448 tmpbuf8 =
new char[*len];
449 bv->GetBuffer(reinterpret_cast<char*>(tmpbuf8), *len);
451 for(
unsigned int di = 0; di < *len; di += step)
456 v1 = mask & ((
unsigned char) tmpbuf8[di+step-1]);
458 for (j = step - 1; j > 0; j--) {
459 ivalue += (v1 * pow(256, j));
460 v1 = (
unsigned char) tmpbuf8[di + j - 1];
464 tmpbuf16[di/2] = ivalue;
469 value = (int)(*(reinterpret_cast<short *>(&ivalue)));
471 if(*umax < value) *umax = value;
472 if(*umin > value) *umin = value;
475 *buf =
reinterpret_cast<char*
>(tmpbuf16);
493 int Import::ProcessOneFile( std::string
const & filename,
494 gdcm::Defs
const & defs ,
495 std::string *series_desc_str,
496 std::string *patient_name_str,
497 std::string *patient_code_str,
499 gdcm::PixelFormat::ScalarType *stype,
502 gdcm::ImageReader reader;
503 reader.SetFileName( filename.c_str() );
506 std::cerr <<
"Could not read image from: " 507 << filename << std::endl;
510 const gdcm::File &file = reader.GetFile();
511 const gdcm::DataSet &ds = file.GetDataSet();
512 const gdcm::Image &image = reader.GetImage();
515 gdcm::Tag att(0x0008,0x103e);
516 if( ds.FindDataElement(att) ) {
517 const gdcm::DataElement& series_desc = ds.GetDataElement( att );
519 (*series_desc_str) += (series_desc.GetByteValue()->GetPointer());
520 (*series_desc_str).resize(series_desc.GetVL());
521 std::cout <<
"Serie Description: " << (*series_desc_str)
525 if( ds.FindDataElement(gdcm::Tag(0x0010, 0x0010)) ) {
526 const gdcm::DataElement& patient_name =
527 ds.GetDataElement( gdcm::Tag(0x0010, 0x0010) );
528 (*patient_name_str) += (patient_name.GetByteValue()->GetPointer());
529 (*patient_name_str).resize(patient_name.GetVL());
530 std::cout <<
"Patient Name: " << (*patient_name_str) << std::endl;
533 if( ds.FindDataElement(gdcm::Tag(0x0010, 0x0020)) ) {
534 const gdcm::DataElement& patient_code =
535 ds.GetDataElement(gdcm::Tag(0x0010, 0x0020) );
536 (*patient_code_str) += (patient_code.GetByteValue()->GetPointer());
537 (*patient_code_str).resize(patient_code.GetVL());
538 std::cout <<
"Patient Code: " << (*patient_code_str)
544 if(ds.FindDataElement(gdcm::Tag(0x0020, 0x1041)) ) {
545 const gdcm::DataElement& location_ptr=
546 ds.GetDataElement( gdcm::Tag(0x0020, 0x1041) );
547 std::string location_str
548 (location_ptr.GetByteValue()->GetPointer());
549 location_str.resize(location_ptr.GetVL());
550 const float location = atof(location_str.c_str());
551 std::cout <<
"Location : " << location << std::endl ;
554 const unsigned int ndim = image.GetNumberOfDimensions();
555 std::cout <<
"Number Of Dimensions: " << ndim << std::endl;
557 const unsigned int *dims=image.GetDimensions();
558 volData->dims[0] = dims[1];
559 volData->dims[1] = dims[0];
561 volData->dims[2] = dims[2];
563 volData->dims[2] = 0;
564 std::cout <<
"Dimensions: (" << volData->dims[0] <<
"," 565 << volData->dims[1] <<
"," 566 << volData->dims[2] <<
")" << std::endl ;
568 const double *origin = image.GetOrigin();
570 volData->origin[0] = origin[0];
571 volData->origin[1] = origin[1];
572 volData->origin[2] = origin[2];
573 std::cout <<
"Origin: (";
575 for(i = 0; i < 2; ++i)
577 std::cout << origin[i] <<
",";
579 std::cout << origin[i] <<
")" << std::endl;
581 volData->space[2] = 0.0;
582 const double *space = image.GetSpacing();
583 volData->space[0] = space[0];
584 volData->space[1] = space[1];
585 volData->space[2] = space[2];
587 if (fabs(volData->space[2]) < 1.e-7) {
588 const gdcm::DataElement& slice_thickness =
589 ds.GetDataElement(gdcm::Tag(0x0018, 0x0050));
590 const gdcm::DataElement& spacing_between_slices =
591 ds.GetDataElement(gdcm::Tag(0x0018, 0x0088));
592 if(!slice_thickness.IsEmpty()) {
593 std::string slice_thickness_str
594 (slice_thickness.GetByteValue()->GetPointer());
595 slice_thickness_str.resize(slice_thickness.GetVL());
596 volData->space[2] = atof(slice_thickness_str.c_str());
597 }
else if (spacing_between_slices.IsEmpty()) {
598 std::string spacing_between_slices_str
599 (spacing_between_slices.GetByteValue()->GetPointer());
600 spacing_between_slices_str.resize(spacing_between_slices.GetVL());
601 volData->space[2] = atof(spacing_between_slices_str.c_str());
604 std::cout <<
"Spacing: (" << volData->space[0] <<
"," 605 << volData->space[1] <<
"," 606 << volData->space[2] <<
")" << std::endl;
608 const gdcm::PixelFormat &ptype=image.GetPixelFormat();
610 volData->samples = ptype.GetSamplesPerPixel();
611 std::cout <<
"Samples per pixel: " << volData->samples << std::endl;
613 volData->nbitsalloc = ptype.GetBitsAllocated();
614 std::cout <<
"Bits Allocated: " << volData->nbitsalloc << std::endl;
616 volData->nbitsstored = ptype.GetBitsStored();
617 std::cout <<
"Bits Stored: " << volData->nbitsstored << std::endl;
619 volData->nhighbit = ptype.GetHighBit();
620 std::cout <<
"High Bit: " << volData->nhighbit << std::endl;
622 const unsigned short pixelRep = ptype.GetPixelRepresentation();
623 std::cout <<
"Pixel Representation: " << pixelRep << std::endl;
625 *stype = ptype.GetScalarType();
626 const char *stypestring = ptype.GetScalarTypeAsString();
627 *scalar += stypestring;
628 std::cout <<
"Scalar Type: " << *stype <<
", " << *scalar << std::endl;
630 const double *dircos = image.GetDirectionCosines();
631 volData->dircos[0][0] = dircos[0];
632 volData->dircos[0][1] = dircos[1];
633 volData->dircos[0][2] = dircos[2];
634 volData->dircos[1][0] = dircos[3];
635 volData->dircos[1][1] = dircos[4];
636 volData->dircos[1][2] = dircos[5];
637 volData->dircos[2][0] = dircos[1]*dircos[5]-dircos[2]*dircos[4];
638 volData->dircos[2][1] = dircos[2]*dircos[3]-dircos[0]*dircos[5];
639 volData->dircos[2][2] = dircos[0]*dircos[4]-dircos[1]*dircos[3];
640 std::cout <<
"X: (" << volData->dircos[0][0] <<
"," << volData->dircos[0][1] <<
"," << volData->dircos[0][2] <<
")" << std::endl;
641 std::cout <<
"Y: (" << volData->dircos[1][0] <<
"," << volData->dircos[1][1] <<
"," << volData->dircos[1][2] <<
")" << std::endl;
642 std::cout <<
"Z: (" << volData->dircos[2][0] <<
"," << volData->dircos[2][1] <<
"," << volData->dircos[2][2] <<
")" << std::endl;
644 gdcm::Orientation::OrientationType type =
645 gdcm::Orientation::GetType(dircos);
646 std::cout <<
"Type : " << type << std::endl;
647 const char *label = gdcm::Orientation::GetLabel( type );
648 std::cout <<
"Orientation Label: " << label << std::endl;
650 const gdcm::PhotometricInterpretation &pi =
651 image.GetPhotometricInterpretation();
652 std::cout <<
"PhotometricInterpretation: " << pi << std::endl;
655 float slope, intercept;
657 if(ds.FindDataElement(gdcm::Tag(0x0028, 0x1053)) ) {
658 const gdcm::DataElement& slope_ptr=
659 ds.GetDataElement( gdcm::Tag(0x0028, 0x1053) );
660 std::string slope_str (slope_ptr.GetByteValue()->GetPointer());
661 slope_str.resize(slope_ptr.GetVL());
662 volData->slope = atof(slope_str.c_str());
664 volData->slope = image.GetSlope();
667 if(ds.FindDataElement(gdcm::Tag(0x0028, 0x1052)) ) {
668 const gdcm::DataElement& intercept_ptr=
669 ds.GetDataElement( gdcm::Tag(0x0028, 0x1052) );
670 std::string intercept_str
671 (intercept_ptr.GetByteValue()->GetPointer());
672 intercept_str.resize(intercept_ptr.GetVL());
673 volData->intercept = atof(intercept_str.c_str());
675 volData->intercept = image.GetIntercept();
677 ReadPixelData(image, ds, *stype, volData->nbitsalloc,
678 volData->nbitsstored, volData->slope,
679 volData->intercept, &volData->length, &volData->buffer,
686 bool Import::ValidateMediaStorageIsImage (std::string
const & filename,
687 gdcm::Defs
const & defs )
690 reader.SetFileName( filename.c_str() );
693 std::cerr <<
"Failed to read: " << filename << std::endl;
696 const gdcm::File &file = reader.GetFile();
697 const gdcm::DataSet &ds = file.GetDataSet();
699 gdcm::MediaStorage ms;
700 ms.SetFromFile(file);
707 if( ms.IsUndefined() )
709 std::cerr <<
"Unknown MediaStorage" << std::endl;
714 uid.SetFromUID( ms.GetString() );
717 const gdcm::TransferSyntax &ts =
718 file.GetHeader().GetDataSetTransferSyntax();
719 uid.SetFromUID( ts.GetString() );
723 return gdcm::MediaStorage::IsImage( ms );
726 int Import::ImportFile(std::string &filename,
const gdcm::Defs &defs,
727 ImgFormat *volData) {
728 std::cout <<
"A file is processed ..." << std::endl;
730 std::string series_desc_str=
"";
731 std::string patient_name_str=
"";
732 std::string patient_code_str=
"";
733 std::string type =
"";
735 series_desc_str.clear();
736 patient_name_str.clear();
737 patient_code_str.clear();
739 gdcm::PixelFormat::ScalarType stype;
741 if (ValidateMediaStorageIsImage (filename, defs)) {
743 reader.SetFileName( filename.c_str() );
744 if( reader.Read() ) {
745 const gdcm::File &file = reader.GetFile();
746 const gdcm::DataSet &ds = file.GetDataSet();
748 gdcm::Tag att(0x0020,0x000e);
749 const gdcm::DataElement& series_value= ds.GetDataElement( att );
750 if( ds.FindDataElement(att) ) {
751 const gdcm::ByteValue *bv = series_value.GetByteValue();
754 if( ds.FindDataElement(gdcm::Tag(0x0008,0x103e)) ) {
755 const gdcm::DataElement& series_desc =
756 ds.GetDataElement(gdcm::Tag(0x0008,0x103e));
758 (series_desc.GetByteValue()->GetPointer());
759 (series_desc_str).resize(series_desc.GetVL());
760 std::cout <<
"Serie Description: " <<
761 (series_desc_str) << std::endl;
764 series_desc_str.clear();
766 if (ProcessOneFile(filename, defs, &series_desc_str,
767 &patient_name_str, &patient_code_str,
768 &type, &stype, volData)) {
784 if( !gdcm::System::FileExists(filename.c_str()) )
786 std::cerr << filename <<
" does not exist on the system" 792 gdcm::Global& g = gdcm::Global::GetInstance();
796 const char *xmlpathenv = getenv(
"GDCM_RESOURCES_PATH");
801 xmlpath = xmlpathenv;
803 if( !g.Prepend( xmlpath.c_str() ) )
805 std::cerr <<
"specified Resources Path is not valid: " 806 << xmlpath << std::endl;
813 const gdcm::Defs &defs = g.GetDefs();
817 if(gdcm::System::FileIsDirectory(filename.c_str()) ) {
818 std::cout <<
"Reading file directory is not supported ..." << std::endl;
820 res = ImportFile (filename, defs, volData);
821 LPS_ReorientImageVolume(volData);
int DICOMImage(std::string &filename, ImgFormat *imgformat)
Destructor.