1 // gdcmHeaderHelper.cxx
2 //-----------------------------------------------------------------------------
3 #include "gdcmHeaderHelper.h"
5 #include "gdcmUtil.h" //for debug
12 int GetDir(std::string dPath, std::list<std::string> &filenames)
14 //For now dPath should have an ending "\"
15 WIN32_FIND_DATA FileData;
17 hFile = FindFirstFile((dPath+"*").c_str(), &FileData);
18 if ( hFile == INVALID_HANDLE_VALUE )
24 if( strncmp(FileData.cFileName, ".", 1) != 0 )
25 filenames.push_back( dPath+FileData.cFileName );
26 while( FindNextFile(hFile, &FileData ) != 0)
28 if( strncmp(FileData.cFileName, ".", 1) != 0 )
29 filenames.push_back( dPath+FileData.cFileName );
37 int GetDir(std::string dPath, std::list<std::string> &filenames)
39 DIR *dir = opendir( dPath.c_str() );
41 while((entry = readdir(dir)) != NULL)
43 // if( strncmp(entry->d_name, ".", 1) != 0 && strncmp(entry->d_name, "..", 2) != 0)
44 if( strncmp(entry->d_name, ".", 1) != 0 )
46 filenames.push_back( dPath + "/" + entry->d_name );
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
58 // Constructor / Destructor
60 * \ingroup gdcmHeaderHelper
63 gdcmHeaderHelper::gdcmHeaderHelper() : gdcmHeader( )
68 * \ingroup gdcmHeaderHelper
71 gdcmHeaderHelper::gdcmHeaderHelper(const char *InFilename,
72 bool exception_on_error) : gdcmHeader( InFilename , exception_on_error)
76 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
82 * \ingroup gdcmHeaderHelper
83 * \brief Return the size (in bytes) of a single pixel of data.
84 * @return The size in bytes of a single pixel of data.
87 int gdcmHeaderHelper::GetPixelSize() {
89 // 0028 0100 US IMG Bits Allocated
90 // (in order no to be messed up by old RGB images)
91 if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
94 std::string PixelType = GetPixelType();
95 if (PixelType == "8U" || PixelType == "8S")
97 if (PixelType == "16U" || PixelType == "16S")
99 if (PixelType == "32U" || PixelType == "32S")
101 dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
106 * \ingroup gdcmHeaderHelper
107 * \brief Build the Pixel Type of the image.
108 * Possible values are:
109 * - 8U unsigned 8 bit,
111 * - 16U unsigned 16 bit,
112 * - 16S signed 16 bit,
113 * - 32U unsigned 32 bit,
114 * - 32S signed 32 bit,
115 * \warning 12 bit images appear as 16 bit.
116 * \ 24 bit images appear as 8 bit
119 std::string gdcmHeaderHelper::GetPixelType() {
120 std::string BitsAlloc;
121 BitsAlloc = GetEntryByNumber(0x0028, 0x0100);
122 if (BitsAlloc == GDCM_UNFOUND) { // Bits Allocated
123 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
124 BitsAlloc = std::string("16");
126 if (BitsAlloc == "12") // It will be unpacked
127 BitsAlloc = std::string("16");
128 else if (BitsAlloc == "24") // (in order no to be messed up
129 BitsAlloc = std::string("8"); // by old RGB images)
132 Signed = GetEntryByNumber(0x0028, 0x0103);
133 if (Signed == GDCM_UNFOUND) { // "Pixel Representation"
134 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
135 BitsAlloc = std::string("0");
138 Signed = std::string("U");
140 Signed = std::string("S");
142 return( BitsAlloc + Signed);
146 * \ingroup gdcmHeaderHelper
147 * \brief gets the info from 0028,0030 : Pixel Spacing
149 * @return X dimension of a pixel
151 float gdcmHeaderHelper::GetXSpacing() {
152 float xspacing, yspacing;
153 std::string StrSpacing = GetEntryByNumber(0x0028,0x0030);
155 if (StrSpacing == GDCM_UNFOUND) {
156 dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
159 if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2)
161 if (xspacing == 0.) {
162 dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
163 // seems to be a bug in the header ...
164 sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
170 * \ingroup gdcmHeaderHelper
171 * \brief gets the info from 0028,0030 : Pixel Spacing
173 * @return Y dimension of a pixel
175 float gdcmHeaderHelper::GetYSpacing() {
176 float xspacing, yspacing;
177 std::string StrSpacing = GetEntryByNumber(0x0028,0x0030);
179 if (StrSpacing == GDCM_UNFOUND) {
180 dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
183 if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2)
185 if (xspacing == 0.) {
186 dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
187 // seems to be a bug in the header ...
188 sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
194 *\ingroup gdcmHeaderHelper
195 *\brief gets the info from 0018,0088 : Space Between Slices
196 *\ else from 0018,0050 : Slice Thickness
198 * @return Z dimension of a voxel-to be
200 float gdcmHeaderHelper::GetZSpacing() {
201 // Spacing Between Slices : distance entre le milieu de chaque coupe
202 // Les coupes peuvent etre :
203 // jointives (Spacing between Slices = Slice Thickness)
204 // chevauchantes (Spacing between Slices < Slice Thickness)
205 // disjointes (Spacing between Slices > Slice Thickness)
206 // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
207 // ca interesse le physicien de l'IRM, pas le visualisateur de volumes ...
208 // Si le Spacing Between Slices est absent,
209 // on suppose que les coupes sont jointives
211 std::string StrSpacingBSlices = GetEntryByNumber(0x0018,0x0088);
213 if (StrSpacingBSlices == GDCM_UNFOUND) {
214 dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
215 std::string StrSliceThickness = GetEntryByNumber(0x0018,0x0050);
216 if (StrSliceThickness == GDCM_UNFOUND)
219 // if no 'Spacing Between Slices' is found,
220 // we assume slices join together
221 // (no overlapping, no interslice gap)
222 // if they don't, we're fucked up
223 return atof(StrSliceThickness.c_str());
225 return atof(StrSpacingBSlices.c_str());
229 float gdcmHeaderHelper::GetRescaleIntercept()
232 std::string StrRescInter = GetEntryByNumber(0x0028,0x1052); //0028 1052 DS IMG Rescale Intercept
233 if (StrRescInter != GDCM_UNFOUND) {
234 if( sscanf( StrRescInter.c_str(), "%f", &resInter) != 1) {
235 dbg.Verbose(0, "gdcmHeader::GetRescaleIntercept: Rescale Slope is empty");
236 // bug in the element 0x0028,0x1052
242 float gdcmHeaderHelper::GetRescaleSlope()
245 std::string StrRescSlope = GetEntryByNumber(0x0028,0x1053); //0028 1053 DS IMG Rescale Slope
246 if (StrRescSlope != GDCM_UNFOUND) {
247 if( sscanf( StrRescSlope.c_str(), "%f", &resSlope) != 1) {
248 dbg.Verbose(0, "gdcmHeader::GetRescaleSlope: Rescale Slope is empty");
249 // bug in the element 0x0028,0x1053
256 * \ingroup gdcmHeaderHelper
257 * \brief This function is intended to user who doesn't whan
258 * \ to have to manage a LUT and expects to get an RBG Pixel image
259 * \ (or a monochrome one ...)
260 * \warning to be used with GetImagePixels()
261 * @return 1 if Gray level, 3 if Color (RGB, YBR or PALETTE COLOR)
263 int gdcmHeaderHelper::GetNumberOfScalarComponents() {
265 if (GetSamplesPerPixel() ==3)
268 // 0028 0100 US IMG Bits Allocated
269 // (in order no to be messed up by old RGB images)
270 if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
273 std::string PhotometricInterpretation =
274 gdcmHeader::GetEntryByNumber(0x0028,0x0004);
276 if ( ( PhotometricInterpretation == "PALETTE COLOR ") ) {
277 if (HasLUT()) // PALETTE COLOR is NOT enough
283 //beware of trailing space at end of string
284 if (PhotometricInterpretation.find(GDCM_UNFOUND) <
285 PhotometricInterpretation.length() ||
286 PhotometricInterpretation.find("MONOCHROME1") <
287 PhotometricInterpretation.length() ||
288 PhotometricInterpretation.find("MONOCHROME2") <
289 PhotometricInterpretation.length() )
292 // we assume that *all* kinds of YBR are dealt with
297 * \ingroup gdcmHeaderHelper
298 * \brief This function is intended to user that DOESN'T want
299 * \to get RGB pixels image when it's stored as a PALETTE COLOR image
300 * \ - the (vtk) user is supposed to know how deal with LUTs -
301 * \warning to be used with GetImagePixelsRaw()
302 * @return 1 if Gray level, 3 if Color (RGB or YBR - NOT 'PALETTE COLOR' -)
304 int gdcmHeaderHelper::GetNumberOfScalarComponentsRaw() {
306 // 0028 0100 US IMG Bits Allocated
307 // (in order no to be messed up by old RGB images)
308 if (gdcmHeader::GetEntryByNumber(0x0028,0x0100) == "24")
311 // we assume that *all* kinds of YBR are dealt with
312 return GetSamplesPerPixel();
315 std::string gdcmHeaderHelper::GetStudyUID()
317 return GetEntryByNumber(0x0020,0x000d); //0020 000d UI REL Study Instance UID
320 std::string gdcmHeaderHelper::GetSeriesUID()
322 return GetEntryByNumber(0x0020,0x000e); //0020 000e UI REL Series Instance UID
325 std::string gdcmHeaderHelper::GetClassUID()
327 return GetEntryByNumber(0x0008,0x0016); //0008 0016 UI ID SOP Class UID
330 std::string gdcmHeaderHelper::GetInstanceUID()
332 return GetEntryByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID
335 // Image Position Patient (0020,0032):
336 // If not found (ACR_NEMA) we try Image Position (0020,0030)
337 // If not found (ACR-NEMA), we consider Slice Location (0020,1041)
338 // or Location (0020,0050)
339 // as the Z coordinate,
340 // 0. for all the coordinates if nothing is found
342 // TODO : find a way to inform the caller nothing was found
343 // TODO : How to tell the caller a wrong number of values was found?
345 * \ingroup gdcmHeaderHelper
346 * \brief gets the info from 0020,0032 : Image Position Patient
347 *\ else from 0020,0030 : Image Position (RET)
349 * @return up-left image corner position
351 float gdcmHeaderHelper::GetXOrigin() {
352 float xImPos, yImPos, zImPos;
353 std::string StrImPos = GetEntryByNumber(0x0020,0x0032);
355 if (StrImPos == GDCM_UNFOUND) {
356 dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient (0020,0032)");
357 StrImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
358 if (StrImPos == GDCM_UNFOUND) {
359 dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
360 // How to tell the caller nothing was found ?
364 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
370 * \ingroup gdcmHeaderHelper
371 * \brief gets the info from 0020,0032 : Image Position Patient
372 * \ else from 0020,0030 : Image Position (RET)
374 * @return up-left image corner position
376 float gdcmHeaderHelper::GetYOrigin() {
377 float xImPos, yImPos, zImPos;
378 std::string StrImPos = GetEntryByNumber(0x0020,0x0032);
380 if (StrImPos == GDCM_UNFOUND) {
381 dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient (0020,0032)");
382 StrImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
383 if (StrImPos == GDCM_UNFOUND) {
384 dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
385 // How to tell the caller nothing was found ?
389 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
395 * \ingroup gdcmHeaderHelper
396 * \brief gets the info from 0020,0032 : Image Position Patient
397 * \ else from 0020,0030 : Image Position (RET)
398 * \ else from 0020,1041 : Slice Location
399 * \ else from 0020,0050 : Location
401 * @return up-left image corner position
403 float gdcmHeaderHelper::GetZOrigin() {
404 float xImPos, yImPos, zImPos;
405 std::string StrImPos = GetEntryByNumber(0x0020,0x0032);
406 if (StrImPos != GDCM_UNFOUND) {
407 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
408 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position Patient (0020,0032)");
409 return 0.; // bug in the element 0x0020,0x0032
414 StrImPos = GetEntryByNumber(0x0020,0x0030); // For ACR-NEMA images
415 if (StrImPos != GDCM_UNFOUND) {
416 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
417 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position (RET) (0020,0030)");
418 return 0.; // bug in the element 0x0020,0x0032
423 std::string StrSliceLocation = GetEntryByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
424 if (StrSliceLocation != GDCM_UNFOUND) {
425 if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
426 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location (0020,1041)");
427 return 0.; // bug in the element 0x0020,0x1041
432 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
433 std::string StrLocation = GetEntryByNumber(0x0020,0x0050);
434 if (StrLocation != GDCM_UNFOUND) {
435 if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
436 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location (0020,0050)");
437 return 0.; // bug in the element 0x0020,0x0050
442 dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Location (0020,0050)");
443 return 0.; // Hopeless
447 * \ingroup gdcmHeaderHelper
448 * \brief gets the info from 0020,0013 : Image Number
450 * @return image number
452 int gdcmHeaderHelper::GetImageNumber() {
453 //The function i atoi() takes the address of an area of memory as parameter and converts
454 //the string stored at that location to an integer using the external decimal to internal
455 //binary conversion rules. This may be preferable to sscanf() since atoi() is a much smaller,
456 // simpler and faster function. sscanf() can do all possible conversions whereas atoi() can
457 //only do single decimal integer conversions.
458 std::string StrImNumber = GetEntryByNumber(0x0020,0x0013); //0020 0013 IS REL Image Number
459 if (StrImNumber != GDCM_UNFOUND) {
460 return atoi( StrImNumber.c_str() );
466 * \ingroup gdcmHeaderHelper
467 * \brief gets the info from 0008,0060 : Modality
468 * @return ModalityType
470 ModalityType gdcmHeaderHelper::GetModality(void) {
471 std::string StrModality = GetEntryByNumber(0x0008,0x0060); //0008 0060 CS ID Modality
472 if (StrModality != GDCM_UNFOUND) {
473 if ( StrModality.find("AU") < StrModality.length()) return AU;
474 else if ( StrModality.find("AS") < StrModality.length()) return AS;
475 else if ( StrModality.find("BI") < StrModality.length()) return BI;
476 else if ( StrModality.find("CF") < StrModality.length()) return CF;
477 else if ( StrModality.find("CP") < StrModality.length()) return CP;
478 else if ( StrModality.find("CR") < StrModality.length()) return CR;
479 else if ( StrModality.find("CT") < StrModality.length()) return CT;
480 else if ( StrModality.find("CS") < StrModality.length()) return CS;
481 else if ( StrModality.find("DD") < StrModality.length()) return DD;
482 else if ( StrModality.find("DF") < StrModality.length()) return DF;
483 else if ( StrModality.find("DG") < StrModality.length()) return DG;
484 else if ( StrModality.find("DM") < StrModality.length()) return DM;
485 else if ( StrModality.find("DS") < StrModality.length()) return DS;
486 else if ( StrModality.find("DX") < StrModality.length()) return DX;
487 else if ( StrModality.find("ECG") < StrModality.length()) return ECG;
488 else if ( StrModality.find("EPS") < StrModality.length()) return EPS;
489 else if ( StrModality.find("FA") < StrModality.length()) return FA;
490 else if ( StrModality.find("FS") < StrModality.length()) return FS;
491 else if ( StrModality.find("HC") < StrModality.length()) return HC;
492 else if ( StrModality.find("HD") < StrModality.length()) return HD;
493 else if ( StrModality.find("LP") < StrModality.length()) return LP;
494 else if ( StrModality.find("LS") < StrModality.length()) return LS;
495 else if ( StrModality.find("MA") < StrModality.length()) return MA;
496 else if ( StrModality.find("MR") < StrModality.length()) return MR;
497 else if ( StrModality.find("NM") < StrModality.length()) return NM;
498 else if ( StrModality.find("OT") < StrModality.length()) return OT;
499 else if ( StrModality.find("PT") < StrModality.length()) return PT;
500 else if ( StrModality.find("RF") < StrModality.length()) return RF;
501 else if ( StrModality.find("RG") < StrModality.length()) return RG;
502 else if ( StrModality.find("RTDOSE") < StrModality.length()) return RTDOSE;
503 else if ( StrModality.find("RTIMAGE") < StrModality.length()) return RTIMAGE;
504 else if ( StrModality.find("RTPLAN") < StrModality.length()) return RTPLAN;
505 else if ( StrModality.find("RTSTRUCT")< StrModality.length()) return RTSTRUCT;
506 else if ( StrModality.find("SM") < StrModality.length()) return SM;
507 else if ( StrModality.find("ST") < StrModality.length()) return ST;
508 else if ( StrModality.find("TG") < StrModality.length()) return TG;
509 else if ( StrModality.find("US") < StrModality.length()) return US;
510 else if ( StrModality.find("VF") < StrModality.length()) return VF;
511 else if ( StrModality.find("XA") < StrModality.length()) return XA;
512 else if ( StrModality.find("XC") < StrModality.length()) return XC;
516 //throw error return value ???
517 // specified <> unknow in our database
525 * \ingroup gdcmHeaderHelper
526 * \brief gets the info from 0020,0037 : Image Orientation Patient
527 * @return cosines of image orientation patient
529 void gdcmHeaderHelper::GetImageOrientationPatient( float* iop ) {
531 //iop is supposed to be float[6]
532 iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0;
534 std::string StrImOriPat = GetEntryByNumber(0x0020,0x0037); // 0020 0037 DS REL Image Orientation (Patient)
535 if (StrImOriPat != GDCM_UNFOUND) {
536 if( sscanf( StrImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f",
537 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6) {
538 dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0037)");
539 return ; // bug in the element 0x0020,0x0037
546 StrImOriPat = GetEntryByNumber(0x0020,0x0035); //0020 0035 DS REL Image Orientation (RET)
547 if (StrImOriPat != GDCM_UNFOUND) {
548 if( sscanf( StrImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f",
549 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6) {
550 dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0035)");
551 return ; // bug in the element 0x0020,0x0035
558 //-----------------------------------------------------------------------------
561 //-----------------------------------------------------------------------------
564 //-----------------------------------------------------------------------------
568 //-----------------------------------------------------------------------------
569 // gdcmSerieHeaderHelper
570 //-----------------------------------------------------------------------------
571 // Constructor / Destructor
572 gdcmSerieHeaderHelper::~gdcmSerieHeaderHelper()
575 for (std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();
576 it != CoherentGdcmFileList.end(); it++)
580 CoherentGdcmFileList.clear();
583 //-----------------------------------------------------------------------------
586 //-----------------------------------------------------------------------------
589 * \ingroup gdcmHeaderHelper
590 * \brief add a gdcmFile to the list based on file name
592 void gdcmSerieHeaderHelper::AddFileName(std::string filename)
594 gdcmHeaderHelper *GdcmFile = new gdcmHeaderHelper( filename.c_str() );
595 this->CoherentGdcmFileList.push_back( GdcmFile );
599 * \ingroup gdcmHeaderHelper
600 * \brief add a gdcmFile to the list
602 void gdcmSerieHeaderHelper::AddGdcmFile(gdcmHeaderHelper *file)
604 this->CoherentGdcmFileList.push_back( file );
608 * \ingroup gdcmHeaderHelper
611 void gdcmSerieHeaderHelper::SetDirectory(std::string dir)
613 std::list<std::string> filenames_list;
614 GetDir(dir, filenames_list); //OS specific
616 for(std::list<std::string>::iterator it = filenames_list.begin(); it !=
617 filenames_list.end(); it++)
619 gdcmHeaderHelper *file = new gdcmHeaderHelper( it->c_str() );
620 this->CoherentGdcmFileList.push_back( file );
624 //This could be implemented in a 'Strategy Pattern' approach
625 //But as I don't know how to do it, I leave it this way
626 //BTW, this is also a Strategy, I don't know this is the best approach :)
627 void gdcmSerieHeaderHelper::OrderGdcmFileList()
629 if( ImagePositionPatientOrdering() )
633 else if( ImageNumberOrdering() )
643 std::list<gdcmHeaderHelper*> &gdcmSerieHeaderHelper::GetGdcmFileList()
645 return CoherentGdcmFileList;
648 //-----------------------------------------------------------------------------
651 //-----------------------------------------------------------------------------
654 * \ingroup gdcmHeaderHelper
656 * We may order, considering :
658 * -# Image Position Patient
661 bool gdcmSerieHeaderHelper::ImagePositionPatientOrdering()
662 //based on Jolinda's algorithm
664 //iop is calculated based on the file file
665 float *cosines = new float[6];
672 std::vector<float> distlist;
674 //!\todo rewrite this for loop.
675 for (std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();
676 it != CoherentGdcmFileList.end(); it++)
679 (*it)->GetImageOrientationPatient(cosines);
681 //You only have to do this once for all slices in the volume. Next, for
682 //each slice, calculate the distance along the slice normal using the IPP
683 //tag ("dist" is initialized to zero before reading the first slice) :
684 normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
685 normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
686 normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
688 ipp[0] = (*it)->GetXOrigin();
689 ipp[1] = (*it)->GetYOrigin();
690 ipp[2] = (*it)->GetZOrigin();
693 for (int i = 0; i < 3; ++i)
694 dist += normal[i]*ipp[i];
702 distlist.push_back( dist );
708 ipp[0] = (*it)->GetXOrigin();
709 ipp[1] = (*it)->GetYOrigin();
710 ipp[2] = (*it)->GetZOrigin();
713 for (int i = 0; i < 3; ++i)
714 dist += normal[i]*ipp[i];
723 distlist.push_back( dist );
725 min = (min < dist) ? min : dist;
726 max = (max > dist) ? max : dist;
731 //Then I order the slices according to the value "dist". Finally, once
732 //I've read in all the slices, I calculate the z-spacing as the difference
733 //between the "dist" values for the first two slices.
734 std::vector<gdcmHeaderHelper*> CoherentGdcmFileVector(n);
735 //CoherentGdcmFileVector.reserve( n );
736 CoherentGdcmFileVector.resize( n );
737 //assert( CoherentGdcmFileVector.capacity() >= n );
739 float step = (max - min)/(n - 1);
743 //VC++ don't understand what scope is !! it -> it2
744 for (std::list<gdcmHeaderHelper*>::iterator it2 = CoherentGdcmFileList.begin();
745 it2 != CoherentGdcmFileList.end(); it2++, n++)
748 //Assumption: all files are present (no one missing)
749 pos = (int)( fabs( (distlist[n]-min)/step) + .5 );
751 CoherentGdcmFileVector[pos] = *it2;
754 CoherentGdcmFileList.clear(); //this doesn't delete list's element, node only
756 //VC++ don't understand what scope is !! it -> it3
757 for (std::vector<gdcmHeaderHelper*>::iterator it3 = CoherentGdcmFileVector.begin();
758 it3 != CoherentGdcmFileVector.end(); it3++)
760 CoherentGdcmFileList.push_back( *it3 );
764 CoherentGdcmFileVector.clear();
770 //Based on Image Number
771 bool gdcmSerieHeaderHelper::ImageNumberOrdering()
774 int n = 0;//CoherentGdcmFileList.size(); //O(N) operation !!
775 unsigned char *partition;
777 std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();
778 min = max = (*it)->GetImageNumber();
780 for (; it != CoherentGdcmFileList.end(); it++, n++)
782 pos = (*it)->GetImageNumber();
785 min = (min < pos) ? min : pos;
788 //bzeros(partition, n); //Cette fonction est déconseillée, utilisez plutôt memset.
789 partition = new unsigned char[n];
790 memset(partition, 0, n);
792 std::vector<gdcmHeaderHelper*> CoherentGdcmFileVector(n);
794 //VC++ don't understand what scope is !! it -> it2
795 for (std::list<gdcmHeaderHelper*>::iterator it2 = CoherentGdcmFileList.begin();
796 it2 != CoherentGdcmFileList.end(); it2++)
798 pos = (*it2)->GetImageNumber();
799 CoherentGdcmFileVector[pos - min] = *it2;
800 partition[pos - min]++;
804 for(int i=0; i<n ; i++)
806 mult *= partition[i];
809 //VC++ don't understand what scope is !! it -> it3
810 CoherentGdcmFileList.clear(); //this doesn't delete list's element, node only
811 for (std::vector<gdcmHeaderHelper*>::iterator it3 = CoherentGdcmFileVector.begin();
812 it3 != CoherentGdcmFileVector.end(); it3++)
814 CoherentGdcmFileList.push_back( *it3 );
816 CoherentGdcmFileVector.clear();
822 bool gdcmSerieHeaderHelper::FileNameOrdering()
825 //sort(CoherentGdcmFileList.begin(), CoherentGdcmFileList.end());
829 //-----------------------------------------------------------------------------