1 // $Header: /cvs/public/gdcm/src/Attic/gdcmHeaderHelper.cxx,v 1.14 2003/10/27 14:01:12 jpr Exp $
3 #include "gdcmHeaderHelper.h"
5 #include "gdcmUtil.h" //for debug
8 #include <string.h> //for bzero
10 //directory manipulation (os indep).
11 //cygwin ???? -> _WIN32 ??
14 int GetDir(std::string dPath, std::list<std::string> &filenames)
16 //For now dPath should have an ending "\"
17 WIN32_FIND_DATA FileData;
19 hFile = FindFirstFile((dPath+"*").c_str(), &FileData);
20 if ( hFile == INVALID_HANDLE_VALUE )
26 if( strncmp(FileData.cFileName, ".", 1) != 0 )
27 filenames.push_back( dPath+FileData.cFileName );
28 while( FindNextFile(hFile, &FileData ) != 0)
30 if( strncmp(FileData.cFileName, ".", 1) != 0 )
31 filenames.push_back( dPath+FileData.cFileName );
39 int GetDir(std::string dPath, std::list<std::string> &filenames)
41 DIR *dir = opendir( dPath.c_str() );
43 while((entry = readdir(dir)) != NULL)
45 // if( strncmp(entry->d_name, ".", 1) != 0 && strncmp(entry->d_name, "..", 2) != 0)
46 if( strncmp(entry->d_name, ".", 1) != 0 )
48 filenames.push_back( dPath + "/" + entry->d_name );
57 //----------------------------------------------------------------------------
59 * \ingroup gdcmHeaderHelper
62 gdcmHeaderHelper::gdcmHeaderHelper() : gdcmHeader( )
65 //----------------------------------------------------------------------------
67 * \ingroup gdcmHeaderHelper
70 gdcmHeaderHelper::gdcmHeaderHelper(const char *InFilename,
71 bool exception_on_error) : gdcmHeader( InFilename , exception_on_error)
74 //----------------------------------------------------------------------------
76 * \ingroup gdcmHeaderHelper
77 * \brief Return the size (in bytes) of a single pixel of data.
78 * @return The size in bytes of a single pixel of data.
81 int gdcmHeaderHelper::GetPixelSize() {
82 std::string PixelType = GetPixelType();
83 if (PixelType == "8U" || PixelType == "8S")
85 if (PixelType == "16U" || PixelType == "16S")
87 if (PixelType == "32U" || PixelType == "32S")
89 dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
93 //----------------------------------------------------------------------------
95 * \ingroup gdcmHeaderHelper
96 * \brief gets the info from 0028,0004 : Photometric Interp
98 * @return 1 if Gray level, 3 if Color
100 int gdcmHeaderHelper::GetNumberOfScalarComponents() {
101 std::string PhotometricInterpretation =
102 gdcmHeader::GetPubElValByNumber(0x0028,0x0004);
105 // The compiler will optimze, if it feels like !
107 //beware of trailing space at end of string
108 if (PhotometricInterpretation.find(GDCM_UNFOUND) < PhotometricInterpretation.length() ||
109 PhotometricInterpretation.find("MONOCHROME1") < PhotometricInterpretation.length() ||
110 PhotometricInterpretation.find("MONOCHROME2") < PhotometricInterpretation.length() ) return 1;
112 // WARNING : quick and dirty trick to produce a single plane Grey image
113 // See also gdcmFile::GetImageDataIntoVector()
114 // if(GetPubElValVoidAreaByNumber(0x0028,0x1201)==NULL) return 1; // Lut Red
115 // end of dirty trick
119 //----------------------------------------------------------------------------
121 * \ingroup gdcmHeaderHelper
122 * \brief Build the Pixel Type of the image.
123 * Possible values are:
124 * - 8U unsigned 8 bit,
126 * - 16U unsigned 16 bit,
127 * - 16S signed 16 bit,
128 * - 32U unsigned 32 bit,
129 * - 32S signed 32 bit,
130 * \warning 12 bit images appear as 16 bit.
133 std::string gdcmHeaderHelper::GetPixelType() {
134 std::string BitsAlloc;
135 BitsAlloc = GetElValByName("Bits Allocated");
136 if (BitsAlloc == GDCM_UNFOUND) {
137 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Bits Allocated");
138 BitsAlloc = std::string("16");
140 if (BitsAlloc == "12")
141 BitsAlloc = std::string("16");
144 Signed = GetElValByName("Pixel Representation");
145 if (Signed == GDCM_UNFOUND) {
146 dbg.Verbose(0, "gdcmHeader::GetPixelType: unfound Pixel Representation");
147 BitsAlloc = std::string("0");
150 Signed = std::string("U");
152 Signed = std::string("S");
154 return( BitsAlloc + Signed);
156 //----------------------------------------------------------------------------
158 * \ingroup gdcmHeaderHelper
159 * \brief gets the info from 0028,0030 : Pixel Spacing
161 * @return X dimension of a pixel
163 float gdcmHeaderHelper::GetXSpacing() {
164 float xspacing, yspacing;
165 std::string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
167 if (StrSpacing == GDCM_UNFOUND) {
168 dbg.Verbose(0, "gdcmHeader::GetXSpacing: unfound Pixel Spacing (0028,0030)");
171 if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2)
173 if (xspacing == 0.) {
174 dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
175 // seems to be a bug in the header ...
176 sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
180 //----------------------------------------------------------------------------
182 * \ingroup gdcmHeaderHelper
183 * \brief gets the info from 0028,0030 : Pixel Spacing
185 * @return Y dimension of a pixel
187 float gdcmHeaderHelper::GetYSpacing() {
188 float xspacing, yspacing;
189 std::string StrSpacing = GetPubElValByNumber(0x0028,0x0030);
191 if (StrSpacing == GDCM_UNFOUND) {
192 dbg.Verbose(0, "gdcmHeader::GetYSpacing: unfound Pixel Spacing (0028,0030)");
195 if( sscanf( StrSpacing.c_str(), "%f\\%f", &yspacing, &xspacing) != 2)
197 if (xspacing == 0.) {
198 dbg.Verbose(0, "gdcmHeader::GetYSpacing: gdcmData/CT-MONO2-8-abdo.dcm problem");
199 // seems to be a bug in the header ...
200 sscanf( StrSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
205 //----------------------------------------------------------------------------
207 *\ingroup gdcmHeaderHelper
208 *\brief gets the info from 0018,0088 : Space Between Slices
209 *\ else from 0018,0050 : Slice Thickness
211 * @return Z dimension of a voxel-to be
213 float gdcmHeaderHelper::GetZSpacing() {
214 // TODO : translate into English
215 // Spacing Between Slices : distance entre le milieu de chaque coupe
216 // Les coupes peuvent etre :
217 // jointives (Spacing between Slices = Slice Thickness)
218 // chevauchantes (Spacing between Slices < Slice Thickness)
219 // disjointes (Spacing between Slices > Slice Thickness)
220 // Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
221 // ca interesse le physicien de l'IRM, pas le visualisateur de volumes ...
222 // Si le Spacing Between Slices est absent,
223 // on suppose que les coupes sont jointives
225 std::string StrSpacingBSlices = GetPubElValByNumber(0x0018,0x0088);
227 if (StrSpacingBSlices == GDCM_UNFOUND) {
228 dbg.Verbose(0, "gdcmHeader::GetZSpacing: unfound StrSpacingBSlices");
229 std::string StrSliceThickness = GetPubElValByNumber(0x0018,0x0050);
230 if (StrSliceThickness == GDCM_UNFOUND)
233 // if no 'Spacing Between Slices' is found,
234 // we assume slices join together
235 // (no overlapping, no interslice gap)
236 // if they don't, we're fucked up
237 return atof(StrSliceThickness.c_str());
239 return atof(StrSpacingBSlices.c_str());
243 //----------------------------------------------------------------------------
245 // Image Position Patient (0020,0032):
246 // If not found (ACR_NEMA) we try Image Position (0020,0030)
247 // If not found (ACR-NEMA), we consider Slice Location (0020,1041)
248 // or Location (0020,0050)
249 // as the Z coordinate,
250 // 0. for all the coordinates if nothing is found
252 // TODO : find a way to inform the caller nothing was found
253 // TODO : How to tell the caller a wrong number of values was found?
256 * \ingroup gdcmHeaderHelper
257 * \brief gets the info from 0020,0032 : Image Position Patient
258 *\ else from 0020,0030 : Image Position (RET)
260 * @return up-left image corner position
262 float gdcmHeaderHelper::GetXOrigin() {
263 float xImPos, yImPos, zImPos;
264 std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
266 if (StrImPos == GDCM_UNFOUND) {
267 dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position Patient (0020,0032)");
268 StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
269 if (StrImPos == GDCM_UNFOUND) {
270 dbg.Verbose(0, "gdcmHeader::GetXImagePosition: unfound Image Position (RET) (0020,0030)");
271 // How to tell the caller nothing was found ?
275 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
279 //----------------------------------------------------------------------------
281 * \ingroup gdcmHeaderHelper
282 * \brief gets the info from 0020,0032 : Image Position Patient
283 * \ else from 0020,0030 : Image Position (RET)
285 * @return up-left image corner position
287 float gdcmHeaderHelper::GetYOrigin() {
288 float xImPos, yImPos, zImPos;
289 std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
291 if (StrImPos == GDCM_UNFOUND) {
292 dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position Patient (0020,0032)");
293 StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
294 if (StrImPos == GDCM_UNFOUND) {
295 dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Image Position (RET) (0020,0030)");
296 // How to tell the caller nothing was found ?
300 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3)
304 //----------------------------------------------------------------------------
306 * \ingroup gdcmHeaderHelper
307 * \brief gets the info from 0020,0032 : Image Position Patient
308 * \ else from 0020,0030 : Image Position (RET)
309 * \ else from 0020,1041 : Slice Location
310 * \ else from 0020,0050 : Location
312 * @return up-left image corner position
314 float gdcmHeaderHelper::GetZOrigin() {
315 float xImPos, yImPos, zImPos;
316 std::string StrImPos = GetPubElValByNumber(0x0020,0x0032);
317 if (StrImPos != GDCM_UNFOUND) {
318 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
319 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position Patient (0020,0032)");
320 return 0.; // bug in the element 0x0020,0x0032
325 StrImPos = GetPubElValByNumber(0x0020,0x0030); // For ACR-NEMA images
326 if (StrImPos != GDCM_UNFOUND) {
327 if( sscanf( StrImPos.c_str(), "%f\\%f\\%f", &xImPos, &yImPos, &zImPos) != 3) {
328 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Image Position (RET) (0020,0030)");
329 return 0.; // bug in the element 0x0020,0x0032
334 std::string StrSliceLocation = GetPubElValByNumber(0x0020,0x1041);// for *very* old ACR-NEMA images
335 if (StrSliceLocation != GDCM_UNFOUND) {
336 if( sscanf( StrSliceLocation.c_str(), "%f", &zImPos) !=1) {
337 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Slice Location (0020,1041)");
338 return 0.; // bug in the element 0x0020,0x1041
343 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: unfound Slice Location (0020,1041)");
344 std::string StrLocation = GetPubElValByNumber(0x0020,0x0050);
345 if (StrLocation != GDCM_UNFOUND) {
346 if( sscanf( StrLocation.c_str(), "%f", &zImPos) !=1) {
347 dbg.Verbose(0, "gdcmHeader::GetZImagePosition: wrong Location (0020,0050)");
348 return 0.; // bug in the element 0x0020,0x0050
353 dbg.Verbose(0, "gdcmHeader::GetYImagePosition: unfound Location (0020,0050)");
354 return 0.; // Hopeless
356 //----------------------------------------------------------------------------
358 * \ingroup gdcmHeaderHelper
359 * \brief gets the info from 0020,0013 : Image Number
361 * @return image number
363 int gdcmHeaderHelper::GetImageNumber() {
364 //The function i atoi() takes the address of an area of memory as parameter and converts
365 //the string stored at that location to an integer using the external decimal to internal
366 //binary conversion rules. This may be preferable to sscanf() since atoi() is a much smaller,
367 // simpler and faster function. sscanf() can do all possible conversions whereas atoi() can
368 //only do single decimal integer conversions.
369 std::string StrImNumber = GetPubElValByNumber(0x0020,0x0013); //0020 0013 IS REL Image Number
370 if (StrImNumber != GDCM_UNFOUND) {
371 return atoi( StrImNumber.c_str() );
375 //----------------------------------------------------------------------------
377 * \ingroup gdcmHeaderHelper
378 * \brief gets the info from 0008,0060 : Modality
379 * @return ModalityType
381 ModalityType gdcmHeaderHelper::GetModality(void) {
382 std::string StrModality = GetPubElValByNumber(0x0008,0x0060); //0008 0060 CS ID Modality
383 if (StrModality != GDCM_UNFOUND) {
384 if ( StrModality.find("AU") < StrModality.length()) return AU;
385 else if ( StrModality.find("AS") < StrModality.length()) return AS;
386 else if ( StrModality.find("BI") < StrModality.length()) return BI;
387 else if ( StrModality.find("CF") < StrModality.length()) return CF;
388 else if ( StrModality.find("CP") < StrModality.length()) return CP;
389 else if ( StrModality.find("CR") < StrModality.length()) return CR;
390 else if ( StrModality.find("CT") < StrModality.length()) return CT;
391 else if ( StrModality.find("CS") < StrModality.length()) return CS;
392 else if ( StrModality.find("DD") < StrModality.length()) return DD;
393 else if ( StrModality.find("DF") < StrModality.length()) return DF;
394 else if ( StrModality.find("DG") < StrModality.length()) return DG;
395 else if ( StrModality.find("DM") < StrModality.length()) return DM;
396 else if ( StrModality.find("DS") < StrModality.length()) return DS;
397 else if ( StrModality.find("DX") < StrModality.length()) return DX;
398 else if ( StrModality.find("ECG") < StrModality.length()) return ECG;
399 else if ( StrModality.find("EPS") < StrModality.length()) return EPS;
400 else if ( StrModality.find("FA") < StrModality.length()) return FA;
401 else if ( StrModality.find("FS") < StrModality.length()) return FS;
402 else if ( StrModality.find("HC") < StrModality.length()) return HC;
403 else if ( StrModality.find("HD") < StrModality.length()) return HD;
404 else if ( StrModality.find("LP") < StrModality.length()) return LP;
405 else if ( StrModality.find("LS") < StrModality.length()) return LS;
406 else if ( StrModality.find("MA") < StrModality.length()) return MA;
407 else if ( StrModality.find("MR") < StrModality.length()) return MR;
408 else if ( StrModality.find("NM") < StrModality.length()) return NM;
409 else if ( StrModality.find("OT") < StrModality.length()) return OT;
410 else if ( StrModality.find("PT") < StrModality.length()) return PT;
411 else if ( StrModality.find("RF") < StrModality.length()) return RF;
412 else if ( StrModality.find("RG") < StrModality.length()) return RG;
413 else if ( StrModality.find("RTDOSE") < StrModality.length()) return RTDOSE;
414 else if ( StrModality.find("RTIMAGE") < StrModality.length()) return RTIMAGE;
415 else if ( StrModality.find("RTPLAN") < StrModality.length()) return RTPLAN;
416 else if ( StrModality.find("RTSTRUCT")< StrModality.length()) return RTSTRUCT;
417 else if ( StrModality.find("SM") < StrModality.length()) return SM;
418 else if ( StrModality.find("ST") < StrModality.length()) return ST;
419 else if ( StrModality.find("TG") < StrModality.length()) return TG;
420 else if ( StrModality.find("US") < StrModality.length()) return US;
421 else if ( StrModality.find("VF") < StrModality.length()) return VF;
422 else if ( StrModality.find("XA") < StrModality.length()) return XA;
423 else if ( StrModality.find("XC") < StrModality.length()) return XC;
427 //throw error return value ???
428 // specified <> unknow in our database
435 //----------------------------------------------------------------------------
436 std::string gdcmHeaderHelper::GetStudyUID()
438 return GetPubElValByNumber(0x0020,0x000d); //0020 000d UI REL Study Instance UID
440 //----------------------------------------------------------------------------
441 std::string gdcmHeaderHelper::GetSeriesUID()
443 return GetPubElValByNumber(0x0020,0x000e); //0020 000e UI REL Series Instance UID
445 //----------------------------------------------------------------------------
446 std::string gdcmHeaderHelper::GetClassUID()
448 return GetPubElValByNumber(0x0008,0x0016); //0008 0016 UI ID SOP Class UID
450 //----------------------------------------------------------------------------
451 std::string gdcmHeaderHelper::GetInstanceUID()
453 return GetPubElValByNumber(0x0008,0x0018); //0008 0018 UI ID SOP Instance UID
464 gdcmSerieHeaderHelper::~gdcmSerieHeaderHelper()
467 for (std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();
468 it != CoherentGdcmFileList.end(); it++)
472 CoherentGdcmFileList.clear();
474 //----------------------------------------------------------------------------
476 * \ingroup gdcmHeaderHelper
477 * \brief gets the info from 0020,0037 : Image Orientation Patient
478 * @return cosines of image orientation patient
480 void gdcmHeaderHelper::GetImageOrientationPatient( float* iop ) {
482 //iop is supposed to be float[6]
483 iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0;
485 std::string StrImOriPat = GetPubElValByNumber(0x0020,0x0037); // 0020 0037 DS REL Image Orientation (Patient)
486 if (StrImOriPat != GDCM_UNFOUND) {
487 if( sscanf( StrImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f",
488 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6) {
489 dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0037)");
490 return ; // bug in the element 0x0020,0x0037
497 StrImOriPat = GetPubElValByNumber(0x0020,0x0035); //0020 0035 DS REL Image Orientation (RET)
498 if (StrImOriPat != GDCM_UNFOUND) {
499 if( sscanf( StrImOriPat.c_str(), "%f\\%f\\%f\\%f\\%f\\%f",
500 &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6) {
501 dbg.Verbose(0, "gdcmHeader::GetImageOrientationPatient: wrong Image Orientation Patient (0020,0035)");
502 return ; // bug in the element 0x0020,0x0035
509 //----------------------------------------------------------------------------
511 * \ingroup gdcmHeaderHelper
512 * \brief add a gdcmFile to the list based on file name
514 void gdcmSerieHeaderHelper::AddFileName(std::string filename)
516 gdcmHeaderHelper *GdcmFile = new gdcmHeaderHelper( filename.c_str() );
517 this->CoherentGdcmFileList.push_back( GdcmFile );
519 //----------------------------------------------------------------------------
521 * \ingroup gdcmHeaderHelper
522 * \brief add a gdcmFile to the list
524 void gdcmSerieHeaderHelper::AddGdcmFile(gdcmHeaderHelper *file)
526 this->CoherentGdcmFileList.push_back( file );
528 //----------------------------------------------------------------------------
530 * \ingroup gdcmHeaderHelper
533 void gdcmSerieHeaderHelper::SetDirectory(std::string dir)
535 std::list<std::string> filenames_list;
536 GetDir(dir, filenames_list); //OS specific
538 for(std::list<std::string>::iterator it = filenames_list.begin(); it !=
539 filenames_list.end(); it++)
541 gdcmHeaderHelper *file = new gdcmHeaderHelper( it->c_str() );
542 this->CoherentGdcmFileList.push_back( file );
545 //----------------------------------------------------------------------------
546 //This could be implemented in a 'Strategy Pattern' approach
547 //But as I don't know how to do it, I leave it this way
548 //BTW, this is also a Strategy, I don't know this is the best approach :)
549 void gdcmSerieHeaderHelper::OrderGdcmFileList()
551 if( ImagePositionPatientOrdering() )
555 else if( ImageNumberOrdering() )
564 //----------------------------------------------------------------------------
566 * \ingroup gdcmHeaderHelper
568 We may order, considering :
570 -# Image Position Patient
573 //based on Jolinda's algorithm
574 bool gdcmSerieHeaderHelper::ImagePositionPatientOrdering()
576 //iop is calculated based on the file file
577 float *cosines = new float[6];
584 std::vector<float> distlist;
586 //!\todo rewrite this for loop.
587 for (std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();
588 it != CoherentGdcmFileList.end(); it++)
591 (*it)->GetImageOrientationPatient(cosines);
593 //You only have to do this once for all slices in the volume. Next, for
594 //each slice, calculate the distance along the slice normal using the IPP
595 //tag ("dist" is initialized to zero before reading the first slice) :
596 normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
597 normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
598 normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
600 ipp[0] = (*it)->GetXOrigin();
601 ipp[1] = (*it)->GetYOrigin();
602 ipp[2] = (*it)->GetZOrigin();
605 for (int i = 0; i < 3; ++i)
606 dist += normal[i]*ipp[i];
614 distlist.push_back( dist );
620 ipp[0] = (*it)->GetXOrigin();
621 ipp[1] = (*it)->GetYOrigin();
622 ipp[2] = (*it)->GetZOrigin();
625 for (int i = 0; i < 3; ++i)
626 dist += normal[i]*ipp[i];
635 distlist.push_back( dist );
637 min = (min < dist) ? min : dist;
638 max = (max > dist) ? max : dist;
643 //Then I order the slices according to the value "dist". Finally, once
644 //I've read in all the slices, I calculate the z-spacing as the difference
645 //between the "dist" values for the first two slices.
646 std::vector<gdcmHeaderHelper*> CoherentGdcmFileVector(n);
647 //CoherentGdcmFileVector.reserve( n );
648 CoherentGdcmFileVector.resize( n );
649 //assert( CoherentGdcmFileVector.capacity() >= n );
651 float step = (max - min)/(n - 1);
655 //VC++ don't understand what scope is !! it -> it2
656 for (std::list<gdcmHeaderHelper*>::iterator it2 = CoherentGdcmFileList.begin();
657 it2 != CoherentGdcmFileList.end(); it2++, n++)
660 //Assumption: all files are present (no one missing)
661 pos = (int)( fabs( (distlist[n]-min)/step) + .5 );
663 CoherentGdcmFileVector[pos] = *it2;
666 CoherentGdcmFileList.clear(); //this doesn't delete list's element, node only
668 //VC++ don't understand what scope is !! it -> it3
669 for (std::vector<gdcmHeaderHelper*>::iterator it3 = CoherentGdcmFileVector.begin();
670 it3 != CoherentGdcmFileVector.end(); it3++)
672 CoherentGdcmFileList.push_back( *it3 );
676 CoherentGdcmFileVector.clear();
681 //----------------------------------------------------------------------------
682 //Based on Image Number
683 bool gdcmSerieHeaderHelper::ImageNumberOrdering()
686 int n = 0;//CoherentGdcmFileList.size(); //O(N) operation !!
687 unsigned char *partition;
689 std::list<gdcmHeaderHelper*>::iterator it = CoherentGdcmFileList.begin();
690 min = max = (*it)->GetImageNumber();
692 for (; it != CoherentGdcmFileList.end(); it++, n++)
694 pos = (*it)->GetImageNumber();
697 min = (min < pos) ? min : pos;
700 //bzeros(partition, n); //Cette fonction est déconseillée, utilisez plutôt memset.
701 partition = new unsigned char[n];
702 memset(partition, 0, n);
704 std::vector<gdcmHeaderHelper*> CoherentGdcmFileVector(n);
706 //VC++ don't understand what scope is !! it -> it2
707 for (std::list<gdcmHeaderHelper*>::iterator it2 = CoherentGdcmFileList.begin();
708 it2 != CoherentGdcmFileList.end(); it2++)
710 pos = (*it2)->GetImageNumber();
711 CoherentGdcmFileVector[pos - min] = *it2;
712 partition[pos - min]++;
716 for(int i=0; i<n ; i++)
718 mult *= partition[i];
721 //VC++ don't understand what scope is !! it -> it3
722 CoherentGdcmFileList.clear(); //this doesn't delete list's element, node only
723 for (std::vector<gdcmHeaderHelper*>::iterator it3 = CoherentGdcmFileVector.begin();
724 it3 != CoherentGdcmFileVector.end(); it3++)
726 CoherentGdcmFileList.push_back( *it3 );
728 CoherentGdcmFileVector.clear();
733 //----------------------------------------------------------------------------
734 bool gdcmSerieHeaderHelper::FileNameOrdering()
737 //sort(CoherentGdcmFileList.begin(), CoherentGdcmFileList.end());
740 //----------------------------------------------------------------------------
741 std::list<gdcmHeaderHelper*> &gdcmSerieHeaderHelper::GetGdcmFileList()
743 return CoherentGdcmFileList;
745 //----------------------------------------------------------------------------