#include <gdcmHeaderHelper.h>
| Public Member Functions | |
| gdcmSerieHeaderHelper () | |
| ~gdcmSerieHeaderHelper () | |
| void | AddFileName (std::string filename) | 
| add a gdcmFile to the list based on file name | |
| void | AddGdcmFile (gdcmHeaderHelper *file) | 
| add a gdcmFile to the list | |
| void | SetDirectory (std::string dir) | 
| Sets the Directory. | |
| void | OrderGdcmFileList () | 
| Sorts the File List. | |
| gdcmHeaderHelper * | GetGdcmHeader () | 
| std::list< gdcmHeaderHelper * > & | GetGdcmFileList () | 
| Gets the *coherent* File List. | |
| Private Member Functions | |
| bool | ImagePositionPatientOrdering () | 
| sorts the images, according to their Patient Position We may order, considering : -Image Number -Image Position Patient -More to come :) | |
| bool | ImageNumberOrdering () | 
| sorts the images, according to their Image Number | |
| bool | FileNameOrdering () | 
| sorts the images, according to their File Name | |
| Private Attributes | |
| std::list< gdcmHeaderHelper * > | CoherentGdcmFileList | 
| 
 | 
| 
 Definition at line 121 of file gdcmHeaderHelper.h. 
 00121 {};
 | 
| 
 | 
| 
 Definition at line 584 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. 
 00584                                              {
00586   for (std::list<gdcmHeaderHelper*>::iterator it  = CoherentGdcmFileList.begin();
00587         it != CoherentGdcmFileList.end(); it++)
00588   {
00589     delete *it;
00590   }
00591   CoherentGdcmFileList.clear();
00592 }
 | 
| 
 | 
| add a gdcmFile to the list based on file name 
 
 Definition at line 604 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. 
 00604                                                           {
00605   gdcmHeaderHelper *GdcmFile = new gdcmHeaderHelper( filename.c_str() );
00606   this->CoherentGdcmFileList.push_back( GdcmFile );
00607 }
 | 
| 
 | 
| add a gdcmFile to the list 
 
 Definition at line 614 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. 
 00614                                                              {
00615   this->CoherentGdcmFileList.push_back( file );
00616 }
 | 
| 
 | 
| sorts the images, according to their File Name 
 
 Definition at line 845 of file gdcmHeaderHelper.cxx. Referenced by OrderGdcmFileList(). 
 00845                                               {
00846   //using the sort
00847   //sort(CoherentGdcmFileList.begin(), CoherentGdcmFileList.end());
00848   return true;
00849 }
 | 
| 
 | 
| Gets the *coherent* File List. 
 
 Definition at line 657 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. 
 00657                                                                    {
00658   return CoherentGdcmFileList;
00659 }
 | 
| 
 | 
| 
 Definition at line 129 of file gdcmHeaderHelper.h. 
 00130    {
00131       //Assume all element in the list have the same global infos
00132       return CoherentGdcmFileList.front();
00133    }
 | 
| 
 | 
| sorts the images, according to their Image Number 
 
 Definition at line 789 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. Referenced by OrderGdcmFileList(). 
 00789                                                 {
00790   int min, max, pos;
00791   int n = 0;//CoherentGdcmFileList.size(); //O(N) operation !!
00792   unsigned char *partition;
00793   
00794   std::list<gdcmHeaderHelper*>::iterator it  = CoherentGdcmFileList.begin();
00795   min = max = (*it)->GetImageNumber();
00796 
00797   for (; it != CoherentGdcmFileList.end(); it++, n++)
00798   {
00799     pos = (*it)->GetImageNumber();
00800 
00801     //else
00802     min = (min < pos) ? min : pos;
00803   }
00804 
00805   //bzeros(partition, n); //Cette fonction est déconseillée, utilisez plutôt memset.
00806   partition = new unsigned char[n];
00807   memset(partition, 0, n);
00808 
00809   std::vector<gdcmHeaderHelper*> CoherentGdcmFileVector(n);
00810 
00811   //VC++ don't understand what scope is !! it -> it2
00812   for (std::list<gdcmHeaderHelper*>::iterator it2  = CoherentGdcmFileList.begin();
00813         it2 != CoherentGdcmFileList.end(); it2++)
00814   {
00815     pos = (*it2)->GetImageNumber();
00816     CoherentGdcmFileVector[pos - min] = *it2;
00817     partition[pos - min]++;
00818   }
00819   
00820   unsigned char mult = 1;
00821   for(int i=0; i<n ; i++)
00822   {
00823     mult *= partition[i];
00824   }
00825 
00826   //VC++ don't understand what scope is !! it -> it3
00827   CoherentGdcmFileList.clear();  //this doesn't delete list's element, node only
00828   for (std::vector<gdcmHeaderHelper*>::iterator it3  = CoherentGdcmFileVector.begin();
00829         it3 != CoherentGdcmFileVector.end(); it3++)
00830   {
00831     CoherentGdcmFileList.push_back( *it3 );
00832   }
00833   CoherentGdcmFileVector.clear();
00834   
00835   delete[] partition;
00836   return (mult!=0);
00837 }
 | 
| 
 | 
| sorts the images, according to their Patient Position We may order, considering : -Image Number -Image Position Patient -More to come :) 
 
 
 
 Definition at line 675 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. Referenced by OrderGdcmFileList(). 
 00677 {
00678   //iop is calculated based on the file file
00679   float *cosines = new float[6];
00680   float normal[3];
00681   float ipp[3];
00682   float dist;
00683   float min, max;
00684   bool first = true;
00685   int n=0;
00686   std::vector<float> distlist;
00687 
00689   for (std::list<gdcmHeaderHelper*>::iterator it  = CoherentGdcmFileList.begin();
00690         it != CoherentGdcmFileList.end(); it++)
00691   {
00692     if(first) {
00693       (*it)->GetImageOrientationPatient(cosines);
00694       
00695       //You only have to do this once for all slices in the volume. Next, for
00696       //each slice, calculate the distance along the slice normal using the IPP
00697       //tag ("dist" is initialized to zero before reading the first slice) :
00698       normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
00699       normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
00700       normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
00701   
00702       ipp[0] = (*it)->GetXOrigin();
00703       ipp[1] = (*it)->GetYOrigin();
00704       ipp[2] = (*it)->GetZOrigin();
00705 
00706       dist = 0;
00707       for (int i = 0; i < 3; ++i)
00708           dist += normal[i]*ipp[i];
00709     
00710       if( dist == 0 )
00711       {
00712         delete[] cosines;
00713         return false;
00714       }
00715 
00716       distlist.push_back( dist );
00717 
00718       max = min = dist;
00719       first = false;
00720     }
00721     else {
00722       ipp[0] = (*it)->GetXOrigin();
00723       ipp[1] = (*it)->GetYOrigin();
00724       ipp[2] = (*it)->GetZOrigin();
00725   
00726       dist = 0;
00727       for (int i = 0; i < 3; ++i)
00728           dist += normal[i]*ipp[i];
00729 
00730       if( dist == 0 )
00731       {
00732         delete[] cosines;
00733         return false;
00734       }
00735       
00736       distlist.push_back( dist );
00737 
00738       min = (min < dist) ? min : dist;
00739       max = (max > dist) ? max : dist;
00740     }
00741     n++;
00742   }
00743 
00744     //Then I order the slices according to the value "dist". Finally, once
00745     //I've read in all the slices, I calculate the z-spacing as the difference
00746     //between the "dist" values for the first two slices.
00747     std::vector<gdcmHeaderHelper*> CoherentGdcmFileVector(n);
00748     //CoherentGdcmFileVector.reserve( n );
00749     CoherentGdcmFileVector.resize( n );
00750     //assert( CoherentGdcmFileVector.capacity() >= n );
00751 
00752     float step = (max - min)/(n - 1);
00753     int pos;
00754     n = 0;
00755     
00756     //VC++ don't understand what scope is !! it -> it2
00757     for (std::list<gdcmHeaderHelper*>::iterator it2  = CoherentGdcmFileList.begin();
00758         it2 != CoherentGdcmFileList.end(); it2++, n++)
00759     {
00760       //2*n sort algo !!
00761       //Assumption: all files are present (no one missing)
00762       pos = (int)( fabs( (distlist[n]-min)/step) + .5 );
00763             
00764       CoherentGdcmFileVector[pos] = *it2;
00765     }
00766 
00767   CoherentGdcmFileList.clear();  //this doesn't delete list's element, node only
00768   
00769   //VC++ don't understand what scope is !! it -> it3
00770   for (std::vector<gdcmHeaderHelper*>::iterator it3  = CoherentGdcmFileVector.begin();
00771         it3 != CoherentGdcmFileVector.end(); it3++)
00772   {
00773     CoherentGdcmFileList.push_back( *it3 );
00774   }
00775 
00776   distlist.clear();
00777   CoherentGdcmFileVector.clear();
00778   delete[] cosines;
00779   
00780   return true;
00781 }
 | 
| 
 | 
| Sorts the File List. 
 
 Definition at line 641 of file gdcmHeaderHelper.cxx. References FileNameOrdering(), ImageNumberOrdering(), and ImagePositionPatientOrdering(). 
 00641                                              {
00642   if( ImagePositionPatientOrdering() ) {
00643     return ;
00644   }
00645   else if( ImageNumberOrdering() ) {
00646     return ;
00647   } else  {
00648     FileNameOrdering();
00649   }
00650 }
 | 
| 
 | 
| Sets the Directory. 
 
 Definition at line 623 of file gdcmHeaderHelper.cxx. References CoherentGdcmFileList. 
 00623                                                      {
00624   gdcmDirList filenames_list(dir);  //OS specific
00625   
00626   for(gdcmDirList::iterator it = filenames_list.begin(); 
00627       it !=filenames_list.end(); it++)
00628   {
00629     gdcmHeaderHelper *file = new gdcmHeaderHelper( it->c_str() );
00630     this->CoherentGdcmFileList.push_back( file );
00631   }
00632 }
 | 
| 
 | 
| 
 Definition at line 142 of file gdcmHeaderHelper.h. Referenced by AddFileName(), AddGdcmFile(), GetGdcmFileList(), ImageNumberOrdering(), ImagePositionPatientOrdering(), SetDirectory(), and ~gdcmSerieHeaderHelper(). | 
 1.3.6
 
1.3.6